Changeset 252254 in webkit
- Timestamp:
- Nov 8, 2019 12:50:02 PM (4 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252253 r252254 1 2019-11-08 Daniel Bates <dabates@apple.com> 2 3 Add WebKit Legacy SPI to retrieve editable elements in rect 4 https://bugs.webkit.org/show_bug.cgi?id=204006 5 <rdar://problem/57024093> 6 7 Reviewed by Wenson Hsieh. 8 9 Extract code to retrieve the editable elements inside a specified rect from WebKit 10 to WebCore so that it can be shared by both Modern WebKit and Legacy WebKit. 11 12 * page/Page.cpp: 13 (WebCore::isEditableTextInputElement): 14 (WebCore::Page::editableElementsInRect const): 15 * page/Page.h: 16 1 17 2019-11-08 Antoine Quint <graouts@apple.com> 2 18 -
trunk/Source/WebCore/page/Page.cpp
r252208 r252254 63 63 #include "HTMLElement.h" 64 64 #include "HTMLMediaElement.h" 65 #include "HTMLTextAreaElement.h" 66 #include "HTMLTextFormControlElement.h" 65 67 #include "HistoryController.h" 66 68 #include "HistoryItem.h" … … 125 127 #include "WheelEventDeltaFilter.h" 126 128 #include "Widget.h" 129 #include <wtf/Deque.h> 127 130 #include <wtf/FileSystem.h> 128 131 #include <wtf/RefCountedLeakCounter.h> … … 911 914 frame = incrementFrame(frame, true, CanWrap::No); 912 915 } while (frame); 916 } 917 918 static bool isEditableTextInputElement(const Element& element) 919 { 920 if (is<HTMLTextFormControlElement>(element)) { 921 if (!element.isTextField() && !is<HTMLTextAreaElement>(element)) 922 return false; 923 return downcast<HTMLTextFormControlElement>(element).isInnerTextElementEditable(); 924 } 925 return element.isRootEditableElement(); 926 } 927 928 Vector<Ref<Element>> Page::editableElementsInRect(const FloatRect& searchRectInRootViewCoordinates) const 929 { 930 Vector<Ref<Element>> result; 931 for (auto* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) { 932 auto* document = frame->document(); 933 if (!document) 934 continue; 935 936 Deque<Node*> nodesToSearch; 937 nodesToSearch.append(document); 938 while (!nodesToSearch.isEmpty()) { 939 auto* node = nodesToSearch.takeFirst(); 940 941 // It is possible to have nested text input contexts (e.g. <input type='text'> inside contenteditable) but 942 // in this case we just take the outermost context and skip the rest. 943 if (!is<Element>(node) || !isEditableTextInputElement(downcast<Element>(*node))) { 944 for (auto* child = node->firstChild(); child; child = child->nextSibling()) 945 nodesToSearch.append(child); 946 continue; 947 } 948 949 auto& element = downcast<Element>(*node); 950 if (searchRectInRootViewCoordinates.intersects(element.clientRect())) 951 result.append(element); 952 } 953 } 954 return result; 913 955 } 914 956 -
trunk/Source/WebCore/page/Page.h
r251737 r252254 718 718 void configureLoggingChannel(const String&, WTFLogChannelState, WTFLogLevel); 719 719 720 WEBCORE_EXPORT Vector<Ref<Element>> editableElementsInRect(const FloatRect&) const; 721 720 722 private: 721 723 struct Navigation { -
trunk/Source/WebKit/ChangeLog
r252248 r252254 1 2019-11-08 Daniel Bates <dabates@apple.com> 2 3 Add WebKit Legacy SPI to retrieve editable elements in rect 4 https://bugs.webkit.org/show_bug.cgi?id=204006 5 <rdar://problem/57024093> 6 7 Reviewed by Wenson Hsieh. 8 9 Write WebPage::textInputContextsInRect() in terms of Page::editableElementsInRect(). 10 Also make use of Element::clientRect() instead of elementRectInRootViewCoordinates(), 11 which duplicates what the former does. 12 13 * WebProcess/WebPage/WebPage.cpp: 14 (WebKit::WebPage::textInputContextsInRect): Write in terms of Page::editableElementsInRect(). 15 (WebKit::WebPage::contextForElement const): Use Element::clientRect() which does what 16 elementRectInRootViewCoordinates() does. 17 (WebKit::elementRectInRootViewCoordinates): Deleted. 18 (WebKit::isEditableTextInputElement): Deleted. 19 1 20 2019-11-06 Jiewen Tan <jiewen_tan@apple.com> 2 21 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r251650 r252254 179 179 #include <WebCore/HTMLPlugInImageElement.h> 180 180 #include <WebCore/HTMLSelectElement.h> 181 #include <WebCore/HTMLTextAreaElement.h>182 181 #include <WebCore/HTMLTextFormControlElement.h> 183 182 #include <WebCore/HTMLUListElement.h> … … 6692 6691 #endif // !PLATFORM(IOS_FAMILY) 6693 6692 6694 static IntRect elementRectInRootViewCoordinates(const Element& element, const Frame& frame)6695 {6696 auto* view = frame.view();6697 if (!view)6698 return { };6699 6700 auto* renderer = element.renderer();6701 if (!renderer)6702 return { };6703 6704 return view->contentsToRootView(renderer->absoluteBoundingBoxRect());6705 }6706 6707 static bool isEditableTextInputElement(Element& element)6708 {6709 if (is<HTMLTextFormControlElement>(element)) {6710 if (!element.isTextField() && !is<HTMLTextAreaElement>(element))6711 return false;6712 return downcast<HTMLTextFormControlElement>(element).isInnerTextElementEditable();6713 }6714 6715 return element.isRootEditableElement();6716 }6717 6718 6693 void WebPage::textInputContextsInRect(WebCore::FloatRect searchRect, CompletionHandler<void(const Vector<WebCore::ElementContext>&)>&& completionHandler) 6719 6694 { 6720 Vector<WebCore::ElementContext> textInputContexts; 6721 6722 for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) { 6723 Document* document = frame->document(); 6724 if (!document) 6725 continue; 6726 6727 Deque<Node*> nodesToSearch; 6728 nodesToSearch.append(document); 6729 while (!nodesToSearch.isEmpty()) { 6730 auto node = nodesToSearch.takeFirst(); 6731 6732 // It is possible to have nested text input contexts (e.g. <input type='text'> inside contenteditable) but 6733 // in this case we just take the outermost context and skip the rest. 6734 if (!is<Element>(*node) || !isEditableTextInputElement(downcast<Element>(*node))) { 6735 for (auto* child = node->firstChild(); child; child = child->nextSibling()) 6736 nodesToSearch.append(child); 6737 continue; 6738 } 6739 6740 auto& element = downcast<Element>(*node); 6741 6742 IntRect elementRect = elementRectInRootViewCoordinates(element, *frame); 6743 if (!searchRect.intersects(elementRect)) 6744 continue; 6745 6746 WebCore::ElementContext context; 6747 context.webPageIdentifier = m_identifier; 6748 context.documentIdentifier = document->identifier(); 6749 context.elementIdentifier = document->identifierForElement(element); 6750 context.boundingRect = elementRect; 6751 6752 textInputContexts.append(context); 6753 } 6754 } 6755 6756 completionHandler(textInputContexts); 6695 auto contexts = m_page->editableElementsInRect(searchRect).map([&] (const auto& element) { 6696 auto& document = element->document(); 6697 6698 WebCore::ElementContext context; 6699 context.webPageIdentifier = m_identifier; 6700 context.documentIdentifier = document.identifier(); 6701 context.elementIdentifier = document.identifierForElement(element); 6702 context.boundingRect = element->clientRect(); 6703 return context; 6704 }); 6705 completionHandler(contexts); 6757 6706 } 6758 6707 … … 6792 6741 return WTF::nullopt; 6793 6742 6794 return WebCore::ElementContext { element RectInRootViewCoordinates(element, *frame), m_identifier, document.identifier(), document.identifierForElement(element) };6743 return WebCore::ElementContext { element.clientRect(), m_identifier, document.identifier(), document.identifierForElement(element) }; 6795 6744 } 6796 6745 -
trunk/Source/WebKitLegacy/mac/ChangeLog
r252000 r252254 1 2019-11-08 Daniel Bates <dabates@apple.com> 2 3 Add WebKit Legacy SPI to retrieve editable elements in rect 4 https://bugs.webkit.org/show_bug.cgi?id=204006 5 <rdar://problem/57024093> 6 7 Reviewed by Wenson Hsieh. 8 9 Add SPI to retrieve all the editable elements in a rect. 10 11 * WebView/WebView.mm: 12 (-[WebView _editableElementsInRect:]): Added. 13 * WebView/WebViewPrivate.h: 14 1 15 2019-11-04 Alex Christensen <achristensen@webkit.org> 2 16 -
trunk/Source/WebKitLegacy/mac/WebView/WebView.mm
r251950 r252254 10132 10132 10133 10133 #if PLATFORM(IOS_FAMILY) 10134 10134 10135 @implementation WebView (WebViewIOSPDF) 10135 10136 … … 10159 10160 10160 10161 @end 10162 10163 @implementation WebView (WebViewIOSAdditions) 10164 10165 - (NSArray<DOMElement *> *)_editableElementsInRect:(CGRect)rect 10166 { 10167 auto* page = core(self); 10168 if (!page) 10169 return @[]; 10170 auto coreElements = page->editableElementsInRect(rect); 10171 if (coreElements.isEmpty()) 10172 return @[]; 10173 auto result = adoptNS([[NSMutableArray alloc] initWithCapacity:coreElements.size()]); 10174 for (auto& coreElement : coreElements) 10175 [result addObject:kit(coreElement.ptr())]; 10176 return result.autorelease(); 10177 } 10178 10179 @end 10180 10161 10181 #endif 10162 10182 -
trunk/Source/WebKitLegacy/mac/WebView/WebViewPrivate.h
r250066 r252254 1076 1076 1077 1077 #if TARGET_OS_IPHONE 1078 1078 1079 @interface WebView (WebViewIOSPDF) 1079 1080 + (Class)_getPDFRepresentationClass; … … 1083 1084 + (void)_setPDFViewClass:(Class)pdfViewClass; 1084 1085 @end 1086 1087 @interface WebView (WebViewIOSAdditions) 1088 - (NSArray<DOMElement *> *)_editableElementsInRect:(CGRect)rect; 1089 @end 1090 1085 1091 #endif 1086 1092
Note: See TracChangeset
for help on using the changeset viewer.