- Revision
- 252254
- Author
- [email protected]
- Date
- 2019-11-08 12:50:02 -0800 (Fri, 08 Nov 2019)
Log Message
Add WebKit Legacy SPI to retrieve editable elements in rect
https://bugs.webkit.org/show_bug.cgi?id=204006
<rdar://problem/57024093>
Reviewed by Wenson Hsieh.
Source/WebCore:
Extract code to retrieve the editable elements inside a specified rect from WebKit
to WebCore so that it can be shared by both Modern WebKit and Legacy WebKit.
* page/Page.cpp:
(WebCore::isEditableTextInputElement):
(WebCore::Page::editableElementsInRect const):
* page/Page.h:
Source/WebKit:
Write WebPage::textInputContextsInRect() in terms of Page::editableElementsInRect().
Also make use of Element::clientRect() instead of elementRectInRootViewCoordinates(),
which duplicates what the former does.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::textInputContextsInRect): Write in terms of Page::editableElementsInRect().
(WebKit::WebPage::contextForElement const): Use Element::clientRect() which does what
elementRectInRootViewCoordinates() does.
(WebKit::elementRectInRootViewCoordinates): Deleted.
(WebKit::isEditableTextInputElement): Deleted.
Source/WebKitLegacy/mac:
Add SPI to retrieve all the editable elements in a rect.
* WebView/WebView.mm:
(-[WebView _editableElementsInRect:]): Added.
* WebView/WebViewPrivate.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (252253 => 252254)
--- trunk/Source/WebCore/ChangeLog 2019-11-08 20:40:57 UTC (rev 252253)
+++ trunk/Source/WebCore/ChangeLog 2019-11-08 20:50:02 UTC (rev 252254)
@@ -1,3 +1,19 @@
+2019-11-08 Daniel Bates <[email protected]>
+
+ Add WebKit Legacy SPI to retrieve editable elements in rect
+ https://bugs.webkit.org/show_bug.cgi?id=204006
+ <rdar://problem/57024093>
+
+ Reviewed by Wenson Hsieh.
+
+ Extract code to retrieve the editable elements inside a specified rect from WebKit
+ to WebCore so that it can be shared by both Modern WebKit and Legacy WebKit.
+
+ * page/Page.cpp:
+ (WebCore::isEditableTextInputElement):
+ (WebCore::Page::editableElementsInRect const):
+ * page/Page.h:
+
2019-11-08 Antoine Quint <[email protected]>
[Web Animations] Use a keyframe effect stack to resolve animations on an element
Modified: trunk/Source/WebCore/page/Page.cpp (252253 => 252254)
--- trunk/Source/WebCore/page/Page.cpp 2019-11-08 20:40:57 UTC (rev 252253)
+++ trunk/Source/WebCore/page/Page.cpp 2019-11-08 20:50:02 UTC (rev 252254)
@@ -62,6 +62,8 @@
#include "FullscreenManager.h"
#include "HTMLElement.h"
#include "HTMLMediaElement.h"
+#include "HTMLTextAreaElement.h"
+#include "HTMLTextFormControlElement.h"
#include "HistoryController.h"
#include "HistoryItem.h"
#include "InspectorClient.h"
@@ -124,6 +126,7 @@
#include "VoidCallback.h"
#include "WheelEventDeltaFilter.h"
#include "Widget.h"
+#include <wtf/Deque.h>
#include <wtf/FileSystem.h>
#include <wtf/RefCountedLeakCounter.h>
#include <wtf/StdLibExtras.h>
@@ -912,6 +915,45 @@
} while (frame);
}
+static bool isEditableTextInputElement(const Element& element)
+{
+ if (is<HTMLTextFormControlElement>(element)) {
+ if (!element.isTextField() && !is<HTMLTextAreaElement>(element))
+ return false;
+ return downcast<HTMLTextFormControlElement>(element).isInnerTextElementEditable();
+ }
+ return element.isRootEditableElement();
+}
+
+Vector<Ref<Element>> Page::editableElementsInRect(const FloatRect& searchRectInRootViewCoordinates) const
+{
+ Vector<Ref<Element>> result;
+ for (auto* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ auto* document = frame->document();
+ if (!document)
+ continue;
+
+ Deque<Node*> nodesToSearch;
+ nodesToSearch.append(document);
+ while (!nodesToSearch.isEmpty()) {
+ auto* node = nodesToSearch.takeFirst();
+
+ // It is possible to have nested text input contexts (e.g. <input type='text'> inside contenteditable) but
+ // in this case we just take the outermost context and skip the rest.
+ if (!is<Element>(node) || !isEditableTextInputElement(downcast<Element>(*node))) {
+ for (auto* child = node->firstChild(); child; child = child->nextSibling())
+ nodesToSearch.append(child);
+ continue;
+ }
+
+ auto& element = downcast<Element>(*node);
+ if (searchRectInRootViewCoordinates.intersects(element.clientRect()))
+ result.append(element);
+ }
+ }
+ return result;
+}
+
const VisibleSelection& Page::selection() const
{
return focusController().focusedOrMainFrame().selection().selection();
Modified: trunk/Source/WebCore/page/Page.h (252253 => 252254)
--- trunk/Source/WebCore/page/Page.h 2019-11-08 20:40:57 UTC (rev 252253)
+++ trunk/Source/WebCore/page/Page.h 2019-11-08 20:50:02 UTC (rev 252254)
@@ -717,6 +717,8 @@
void configureLoggingChannel(const String&, WTFLogChannelState, WTFLogLevel);
+ WEBCORE_EXPORT Vector<Ref<Element>> editableElementsInRect(const FloatRect&) const;
+
private:
struct Navigation {
RegistrableDomain domain;
Modified: trunk/Source/WebKit/ChangeLog (252253 => 252254)
--- trunk/Source/WebKit/ChangeLog 2019-11-08 20:40:57 UTC (rev 252253)
+++ trunk/Source/WebKit/ChangeLog 2019-11-08 20:50:02 UTC (rev 252254)
@@ -1,3 +1,22 @@
+2019-11-08 Daniel Bates <[email protected]>
+
+ Add WebKit Legacy SPI to retrieve editable elements in rect
+ https://bugs.webkit.org/show_bug.cgi?id=204006
+ <rdar://problem/57024093>
+
+ Reviewed by Wenson Hsieh.
+
+ Write WebPage::textInputContextsInRect() in terms of Page::editableElementsInRect().
+ Also make use of Element::clientRect() instead of elementRectInRootViewCoordinates(),
+ which duplicates what the former does.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::textInputContextsInRect): Write in terms of Page::editableElementsInRect().
+ (WebKit::WebPage::contextForElement const): Use Element::clientRect() which does what
+ elementRectInRootViewCoordinates() does.
+ (WebKit::elementRectInRootViewCoordinates): Deleted.
+ (WebKit::isEditableTextInputElement): Deleted.
+
2019-11-06 Jiewen Tan <[email protected]>
[WebAuthn] Return NotAllowedError immediately for UI cancellations
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (252253 => 252254)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-11-08 20:40:57 UTC (rev 252253)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp 2019-11-08 20:50:02 UTC (rev 252254)
@@ -178,7 +178,6 @@
#include <WebCore/HTMLPlugInElement.h>
#include <WebCore/HTMLPlugInImageElement.h>
#include <WebCore/HTMLSelectElement.h>
-#include <WebCore/HTMLTextAreaElement.h>
#include <WebCore/HTMLTextFormControlElement.h>
#include <WebCore/HTMLUListElement.h>
#include <WebCore/HistoryController.h>
@@ -6691,69 +6690,19 @@
#endif // !PLATFORM(IOS_FAMILY)
-static IntRect elementRectInRootViewCoordinates(const Element& element, const Frame& frame)
-{
- auto* view = frame.view();
- if (!view)
- return { };
-
- auto* renderer = element.renderer();
- if (!renderer)
- return { };
-
- return view->contentsToRootView(renderer->absoluteBoundingBoxRect());
-}
-
-static bool isEditableTextInputElement(Element& element)
-{
- if (is<HTMLTextFormControlElement>(element)) {
- if (!element.isTextField() && !is<HTMLTextAreaElement>(element))
- return false;
- return downcast<HTMLTextFormControlElement>(element).isInnerTextElementEditable();
- }
-
- return element.isRootEditableElement();
-}
-
void WebPage::textInputContextsInRect(WebCore::FloatRect searchRect, CompletionHandler<void(const Vector<WebCore::ElementContext>&)>&& completionHandler)
{
- Vector<WebCore::ElementContext> textInputContexts;
+ auto contexts = m_page->editableElementsInRect(searchRect).map([&] (const auto& element) {
+ auto& document = element->document();
- for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
- Document* document = frame->document();
- if (!document)
- continue;
-
- Deque<Node*> nodesToSearch;
- nodesToSearch.append(document);
- while (!nodesToSearch.isEmpty()) {
- auto node = nodesToSearch.takeFirst();
-
- // It is possible to have nested text input contexts (e.g. <input type='text'> inside contenteditable) but
- // in this case we just take the outermost context and skip the rest.
- if (!is<Element>(*node) || !isEditableTextInputElement(downcast<Element>(*node))) {
- for (auto* child = node->firstChild(); child; child = child->nextSibling())
- nodesToSearch.append(child);
- continue;
- }
-
- auto& element = downcast<Element>(*node);
-
- IntRect elementRect = elementRectInRootViewCoordinates(element, *frame);
- if (!searchRect.intersects(elementRect))
- continue;
-
- WebCore::ElementContext context;
- context.webPageIdentifier = m_identifier;
- context.documentIdentifier = document->identifier();
- context.elementIdentifier = document->identifierForElement(element);
- context.boundingRect = elementRect;
-
- textInputContexts.append(context);
- }
- }
-
- completionHandler(textInputContexts);
+ WebCore::ElementContext context;
+ context.webPageIdentifier = m_identifier;
+ context.documentIdentifier = document.identifier();
+ context.elementIdentifier = document.identifierForElement(element);
+ context.boundingRect = element->clientRect();
+ return context;
+ });
+ completionHandler(contexts);
}
void WebPage::focusTextInputContext(const WebCore::ElementContext& textInputContext, CompletionHandler<void(bool)>&& completionHandler)
@@ -6791,7 +6740,7 @@
if (!frame)
return WTF::nullopt;
- return WebCore::ElementContext { elementRectInRootViewCoordinates(element, *frame), m_identifier, document.identifier(), document.identifierForElement(element) };
+ return WebCore::ElementContext { element.clientRect(), m_identifier, document.identifier(), document.identifierForElement(element) };
}
void WebPage::startTextManipulations(Vector<WebCore::TextManipulationController::ExclusionRule>&& exclusionRules, CompletionHandler<void()>&& completionHandler)
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (252253 => 252254)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2019-11-08 20:40:57 UTC (rev 252253)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2019-11-08 20:50:02 UTC (rev 252254)
@@ -1,3 +1,17 @@
+2019-11-08 Daniel Bates <[email protected]>
+
+ Add WebKit Legacy SPI to retrieve editable elements in rect
+ https://bugs.webkit.org/show_bug.cgi?id=204006
+ <rdar://problem/57024093>
+
+ Reviewed by Wenson Hsieh.
+
+ Add SPI to retrieve all the editable elements in a rect.
+
+ * WebView/WebView.mm:
+ (-[WebView _editableElementsInRect:]): Added.
+ * WebView/WebViewPrivate.h:
+
2019-11-04 Alex Christensen <[email protected]>
REGRESSION(r243947) Epson software updater fails to install new version
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (252253 => 252254)
--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm 2019-11-08 20:40:57 UTC (rev 252253)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm 2019-11-08 20:50:02 UTC (rev 252254)
@@ -10131,6 +10131,7 @@
@end
#if PLATFORM(IOS_FAMILY)
+
@implementation WebView (WebViewIOSPDF)
+ (Class)_getPDFRepresentationClass
@@ -10158,6 +10159,25 @@
}
@end
+
+@implementation WebView (WebViewIOSAdditions)
+
+- (NSArray<DOMElement *> *)_editableElementsInRect:(CGRect)rect
+{
+ auto* page = core(self);
+ if (!page)
+ return @[];
+ auto coreElements = page->editableElementsInRect(rect);
+ if (coreElements.isEmpty())
+ return @[];
+ auto result = adoptNS([[NSMutableArray alloc] initWithCapacity:coreElements.size()]);
+ for (auto& coreElement : coreElements)
+ [result addObject:kit(coreElement.ptr())];
+ return result.autorelease();
+}
+
+@end
+
#endif
@implementation WebView (WebViewFullScreen)
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebViewPrivate.h (252253 => 252254)
--- trunk/Source/WebKitLegacy/mac/WebView/WebViewPrivate.h 2019-11-08 20:40:57 UTC (rev 252253)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebViewPrivate.h 2019-11-08 20:50:02 UTC (rev 252254)
@@ -1075,6 +1075,7 @@
@end
#if TARGET_OS_IPHONE
+
@interface WebView (WebViewIOSPDF)
+ (Class)_getPDFRepresentationClass;
+ (void)_setPDFRepresentationClass:(Class)pdfRepresentationClass;
@@ -1082,6 +1083,11 @@
+ (Class)_getPDFViewClass;
+ (void)_setPDFViewClass:(Class)pdfViewClass;
@end
+
+@interface WebView (WebViewIOSAdditions)
+- (NSArray<DOMElement *> *)_editableElementsInRect:(CGRect)rect;
+@end
+
#endif
@interface NSObject (WebViewFrameLoadDelegatePrivate)