Title: [176766] trunk/Source
Revision
176766
Author
[email protected]
Date
2014-12-03 17:06:52 -0800 (Wed, 03 Dec 2014)

Log Message

<input> elements get whitespace action menu instead of editable text menu
https://bugs.webkit.org/show_bug.cgi?id=139241
-and corresponding-
rdar://problem/19072083

Reviewed by Sam Weinig.

Source/WebCore:

Since we will hit test form controls as form controls, we need a new function to 
determine if the hit point is over text inside that form control or not.
* WebCore.exp.in:
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::isOverTextInsideFormControlElement):
* rendering/HitTestResult.h:

Source/WebKit/mac:

We should disallow shadow content in the hit test. This is the default and it is 
how context menus behave. We originally wanted to text inside shadow content so 
that we could find the text, but the new function I added to HitTestResult will 
allow that.
* WebView/WebActionMenuController.mm:
(-[WebActionMenuController performHitTestAtPoint:]):

Adjust to the fact that we don’t hit test shadow content any more.
(-[WebActionMenuController focusAndSelectHitTestResult]):

Offer the text menus for text inside form controls.
(-[WebActionMenuController _defaultMenuItems]):

Source/WebKit2:

Add isOverTextInsideFormControlElement to WebHitTestResult.
* Shared/WebHitTestResult.cpp:
(WebKit::WebHitTestResult::Data::Data):
(WebKit::WebHitTestResult::Data::encode):
(WebKit::WebHitTestResult::Data::decode):
* Shared/WebHitTestResult.h:
(WebKit::WebHitTestResult::isOverTextInsideFormControlElement):

Offer the text menus for text inside form controls.
* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController _defaultMenuItems]):

We should disallow shadow content in the hit test. This is the default and it is 
how context menus behave. We originally wanted to text inside shadow content so 
that we could find the text, but the new function I added to HitTestResult will 
allow that.
* WebProcess/WebPage/mac/WebPageMac.mm:

Adjust to the fact that we don’t hit test shadow content any more.
(WebKit::WebPage::performActionMenuHitTestAtLocation):
(WebKit::WebPage::lookupTextAtLocation):
(WebKit::WebPage::focusAndSelectLastActionMenuHitTestResult):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (176765 => 176766)


--- trunk/Source/WebCore/ChangeLog	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebCore/ChangeLog	2014-12-04 01:06:52 UTC (rev 176766)
@@ -1,3 +1,19 @@
+2014-12-03  Beth Dakin  <[email protected]>
+
+        <input> elements get whitespace action menu instead of editable text menu
+        https://bugs.webkit.org/show_bug.cgi?id=139241
+        -and corresponding-
+        rdar://problem/19072083
+
+        Reviewed by Sam Weinig.
+
+        Since we will hit test form controls as form controls, we need a new function to 
+        determine if the hit point is over text inside that form control or not.
+        * WebCore.exp.in:
+        * rendering/HitTestResult.cpp:
+        (WebCore::HitTestResult::isOverTextInsideFormControlElement):
+        * rendering/HitTestResult.h:
+
 2014-12-03  Tim Horton  <[email protected]>
 
         Keyboard input should be disabled in the preview popover

Modified: trunk/Source/WebCore/WebCore.exp.in (176765 => 176766)


--- trunk/Source/WebCore/WebCore.exp.in	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-12-04 01:06:52 UTC (rev 176766)
@@ -1091,6 +1091,7 @@
 __ZN7WebCore29cookieRequestHeaderFieldValueERKNS_21NetworkStorageSessionERKNS_3URLES5_
 __ZN7WebCore29createDefaultParagraphElementERNS_8DocumentE
 __ZN7WebCore29isCharacterSmartReplaceExemptEib
+__ZN7WebCore30enclosingTextUnitOfGranularityERKNS_15VisiblePositionENS_15TextGranularityENS_18SelectionDirectionE
 __ZN7WebCore30hostNameNeedsDecodingWithRangeEP8NSString8_NSRange
 __ZN7WebCore30hostNameNeedsEncodingWithRangeEP8NSString8_NSRange
 __ZN7WebCore30overrideUserPreferredLanguagesERKN3WTF6VectorINS0_6StringELj0ENS0_15CrashOnOverflowEEE
@@ -1693,6 +1694,7 @@
 __ZNK7WebCore13HitTestResult19mediaIsInFullscreenEv
 __ZNK7WebCore13HitTestResult19rectBasedTestResultEv
 __ZNK7WebCore13HitTestResult21innerNonSharedElementEv
+__ZNK7WebCore13HitTestResult34isOverTextInsideFormControlElementEv
 __ZNK7WebCore13HitTestResult5imageEv
 __ZNK7WebCore13HitTestResult5titleERNS_13TextDirectionE
 __ZNK7WebCore13HitTestResult9imageRectEv
@@ -2720,7 +2722,6 @@
 __ZN7WebCore27tileControllerMemoryHandlerEv
 __ZN7WebCore27withinTextUnitOfGranularityERKNS_15VisiblePositionENS_15TextGranularityENS_18SelectionDirectionE
 __ZN7WebCore30closestWordBoundaryForPositionERKNS_15VisiblePositionE
-__ZN7WebCore30enclosingTextUnitOfGranularityERKNS_15VisiblePositionENS_15TextGranularityENS_18SelectionDirectionE
 __ZN7WebCore30plainTextReplacingNoBreakSpaceEPKNS_5RangeEtb
 __ZN7WebCore31NonSharedCharacterBreakIteratorC1EN3WTF10StringViewE
 __ZN7WebCore31NonSharedCharacterBreakIteratorD1Ev

Modified: trunk/Source/WebCore/rendering/HitTestResult.cpp (176765 => 176766)


--- trunk/Source/WebCore/rendering/HitTestResult.cpp	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebCore/rendering/HitTestResult.cpp	2014-12-04 01:06:52 UTC (rev 176766)
@@ -50,6 +50,7 @@
 #include "Scrollbar.h"
 #include "ShadowRoot.h"
 #include "UserGestureIndicator.h"
+#include "VisibleUnits.h"
 #include "XLinkNames.h"
 
 namespace WebCore {
@@ -515,6 +516,34 @@
     return false;
 }
 
+bool HitTestResult::isOverTextInsideFormControlElement() const
+{
+    Node* node = innerNode();
+    if (!node)
+        return false;
+
+    if (!is<HTMLTextFormControlElement>(*node))
+        return false;
+
+    Frame* frame = node->document().frame();
+    if (!frame)
+        return false;
+
+    IntPoint framePoint = roundedPointInInnerNodeFrame();
+    if (!frame->rangeForPoint(framePoint))
+        return false;
+
+    VisiblePosition position = frame->visiblePositionForPoint(framePoint);
+    if (position.isNull())
+        return false;
+
+    RefPtr<Range> wordRange = enclosingTextUnitOfGranularity(position, WordGranularity, DirectionForward);
+    if (!wordRange)
+        return false;
+
+    return !wordRange->text().isEmpty();
+}
+
 URL HitTestResult::absoluteLinkURL() const
 {
     if (m_innerURLElement)

Modified: trunk/Source/WebCore/rendering/HitTestResult.h (176765 => 176766)


--- trunk/Source/WebCore/rendering/HitTestResult.h	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebCore/rendering/HitTestResult.h	2014-12-04 01:06:52 UTC (rev 176766)
@@ -125,6 +125,7 @@
     bool mediaMuted() const;
     void toggleMediaMuteState() const;
     bool isDownloadableMedia() const;
+    bool isOverTextInsideFormControlElement() const;
 
     // Returns true if it is rect-based hit test and needs to continue until the rect is fully
     // enclosed by the boundaries of a node.

Modified: trunk/Source/WebKit/mac/ChangeLog (176765 => 176766)


--- trunk/Source/WebKit/mac/ChangeLog	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebKit/mac/ChangeLog	2014-12-04 01:06:52 UTC (rev 176766)
@@ -1,3 +1,25 @@
+2014-12-03  Beth Dakin  <[email protected]>
+
+        <input> elements get whitespace action menu instead of editable text menu
+        https://bugs.webkit.org/show_bug.cgi?id=139241
+        -and corresponding-
+        rdar://problem/19072083
+
+        Reviewed by Sam Weinig.
+
+        We should disallow shadow content in the hit test. This is the default and it is 
+        how context menus behave. We originally wanted to text inside shadow content so 
+        that we could find the text, but the new function I added to HitTestResult will 
+        allow that.
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController performHitTestAtPoint:]):
+
+        Adjust to the fact that we don’t hit test shadow content any more.
+        (-[WebActionMenuController focusAndSelectHitTestResult]):
+
+        Offer the text menus for text inside form controls.
+        (-[WebActionMenuController _defaultMenuItems]):
+
 2014-12-03  Tim Horton  <[email protected]>
 
         Implement action menus for tel: URLs

Modified: trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm (176765 => 176766)


--- trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebKit/mac/WebView/WebActionMenuController.mm	2014-12-04 01:06:52 UTC (rev 176766)
@@ -108,18 +108,8 @@
     Frame* coreFrame = core([documentView _frame]);
     if (!coreFrame)
         return nil;
-    HitTestRequest::HitTestRequestType hitType = HitTestRequest::ReadOnly | HitTestRequest::Active;
-    _hitTestResult = coreFrame->eventHandler().hitTestResultAtPoint(IntPoint(point), hitType);
+    _hitTestResult = coreFrame->eventHandler().hitTestResultAtPoint(IntPoint(point));
 
-    // We hit test including shadow content to get the desired result for editable text regions.
-    // But for media, we want to re-set to the shadow root.
-    if (Node* node = _hitTestResult.innerNode()) {
-        if (Element* shadowHost = node->shadowHost()) {
-            if (shadowHost->isMediaElement())
-                _hitTestResult.setToNonShadowAncestor();
-        }
-    }
-
     return [[[WebElementDictionary alloc] initWithHitTestResult:_hitTestResult] autorelease];
 }
 
@@ -181,15 +171,13 @@
     if (!element)
         return;
 
-    auto renderer = element->renderer();
-    if (!renderer)
+    Frame* frame = element->document().frame();
+    if (!frame)
         return;
 
-    Frame& frame = renderer->frame();
-
-    frame.page()->focusController().setFocusedElement(element, element->document().frame());
-    VisiblePosition position = renderer->positionForPoint(_hitTestResult.localPoint(), nullptr);
-    frame.selection().setSelection(position);
+    frame->page()->focusController().setFocusedElement(element, frame);
+    VisiblePosition position = frame->visiblePositionForPoint(_hitTestResult.roundedPointInInnerNodeFrame());
+    frame->selection().setSelection(position);
 }
 
 - (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event
@@ -879,7 +867,7 @@
     }
 
     Node* node = _hitTestResult.innerNode();
-    if (node && node->isTextNode()) {
+    if ((node && node->isTextNode()) || _hitTestResult.isOverTextInsideFormControlElement()) {
         NSArray *dataDetectorMenuItems = [self _defaultMenuItemsForDataDetectedText];
         if (_currentActionContext) {
             // If this is a data detected item with no menu items, we should not fall back to regular text options.

Modified: trunk/Source/WebKit2/ChangeLog (176765 => 176766)


--- trunk/Source/WebKit2/ChangeLog	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebKit2/ChangeLog	2014-12-04 01:06:52 UTC (rev 176766)
@@ -1,3 +1,35 @@
+2014-12-03  Beth Dakin  <[email protected]>
+
+        <input> elements get whitespace action menu instead of editable text menu
+        https://bugs.webkit.org/show_bug.cgi?id=139241
+        -and corresponding-
+        rdar://problem/19072083
+
+        Reviewed by Sam Weinig.
+
+        Add isOverTextInsideFormControlElement to WebHitTestResult.
+        * Shared/WebHitTestResult.cpp:
+        (WebKit::WebHitTestResult::Data::Data):
+        (WebKit::WebHitTestResult::Data::encode):
+        (WebKit::WebHitTestResult::Data::decode):
+        * Shared/WebHitTestResult.h:
+        (WebKit::WebHitTestResult::isOverTextInsideFormControlElement):
+
+        Offer the text menus for text inside form controls.
+        * UIProcess/mac/WKActionMenuController.mm:
+        (-[WKActionMenuController _defaultMenuItems]):
+
+        We should disallow shadow content in the hit test. This is the default and it is 
+        how context menus behave. We originally wanted to text inside shadow content so 
+        that we could find the text, but the new function I added to HitTestResult will 
+        allow that.
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+
+        Adjust to the fact that we don’t hit test shadow content any more.
+        (WebKit::WebPage::performActionMenuHitTestAtLocation):
+        (WebKit::WebPage::lookupTextAtLocation):
+        (WebKit::WebPage::focusAndSelectLastActionMenuHitTestResult):
+
 2014-12-03  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r176489.

Modified: trunk/Source/WebKit2/Shared/WebHitTestResult.cpp (176765 => 176766)


--- trunk/Source/WebKit2/Shared/WebHitTestResult.cpp	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebKit2/Shared/WebHitTestResult.cpp	2014-12-04 01:06:52 UTC (rev 176766)
@@ -54,6 +54,7 @@
     , isScrollbar(hitTestResult.scrollbar())
     , isSelected(hitTestResult.isSelected())
     , isTextNode(hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode())
+    , isOverTextInsideFormControlElement(hitTestResult.isOverTextInsideFormControlElement())
     , isDownloadableMedia(hitTestResult.isDownloadableMedia())
 {
 }
@@ -75,6 +76,7 @@
     encoder << isScrollbar;
     encoder << isSelected;
     encoder << isTextNode;
+    encoder << isOverTextInsideFormControlElement;
     encoder << isDownloadableMedia;
 }
 
@@ -91,6 +93,7 @@
         || !decoder.decode(hitTestResultData.isScrollbar)
         || !decoder.decode(hitTestResultData.isSelected)
         || !decoder.decode(hitTestResultData.isTextNode)
+        || !decoder.decode(hitTestResultData.isOverTextInsideFormControlElement)
         || !decoder.decode(hitTestResultData.isDownloadableMedia))
         return false;
 

Modified: trunk/Source/WebKit2/Shared/WebHitTestResult.h (176765 => 176766)


--- trunk/Source/WebKit2/Shared/WebHitTestResult.h	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebKit2/Shared/WebHitTestResult.h	2014-12-04 01:06:52 UTC (rev 176766)
@@ -54,6 +54,7 @@
         bool isScrollbar;
         bool isSelected;
         bool isTextNode;
+        bool isOverTextInsideFormControlElement;
         bool isDownloadableMedia;
 
         Data();
@@ -86,6 +87,8 @@
 
     bool isTextNode() const { return m_data.isTextNode; }
 
+    bool isOverTextInsideFormControlElement() const { return m_data.isOverTextInsideFormControlElement; }
+
     bool isDownloadableMedia() const { return m_data.isDownloadableMedia; }
 
 private:

Modified: trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm (176765 => 176766)


--- trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebKit2/UIProcess/mac/WKActionMenuController.mm	2014-12-04 01:06:52 UTC (rev 176766)
@@ -1124,7 +1124,7 @@
         return [self _defaultMenuItemsForImage];
     }
 
-    if (hitTestResult->isTextNode()) {
+    if (hitTestResult->isTextNode() || hitTestResult->isOverTextInsideFormControlElement()) {
         NSArray *dataDetectorMenuItems = [self _defaultMenuItemsForDataDetectedText];
         if (_currentActionContext) {
             // If this is a data detected item with no menu items, we should not fall back to regular text options.

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (176765 => 176766)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-12-04 01:04:31 UTC (rev 176765)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2014-12-04 01:06:52 UTC (rev 176766)
@@ -982,23 +982,9 @@
         return;
     }
 
-    RenderView& mainRenderView = *mainFrame.view()->renderView();
-
-    HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AllowChildFrameContent | HitTestRequest::IgnoreClipping);
-
     IntPoint locationInContentCoordinates = mainFrame.view()->rootViewToContents(roundedIntPoint(locationInViewCooordinates));
-    HitTestResult hitTestResult(locationInContentCoordinates);
-    mainRenderView.hitTest(request, hitTestResult);
+    HitTestResult hitTestResult = mainFrame.eventHandler().hitTestResultAtPoint(locationInContentCoordinates);
 
-    // We hit test including shadow content to get the desired result for editable text regions.
-    // But for media, we want to re-set to the shadow root.
-    if (Node* node = hitTestResult.innerNode()) {
-        if (Element* shadowHost = node->shadowHost()) {
-            if (shadowHost->isMediaElement())
-                hitTestResult.setToNonShadowAncestor();
-        }
-    }
-
     ActionMenuHitTestResult actionMenuResult;
     actionMenuResult.hitTestLocationInViewCooordinates = locationInViewCooordinates;
     actionMenuResult.hitTestResult = WebHitTestResult::Data(hitTestResult);
@@ -1073,7 +1059,7 @@
         return nullptr;
 
     IntPoint point = roundedIntPoint(locationInViewCooordinates);
-    HitTestResult result = mainFrame.eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::AllowChildFrameContent | HitTestRequest::IgnoreClipping);
+    HitTestResult result = mainFrame.eventHandler().hitTestResultAtPoint(m_page->mainFrame().view()->windowToContents(point));
     NSDictionary *options = nil;
     return rangeForDictionaryLookupAtHitTestResult(result, &options);
 }
@@ -1093,13 +1079,13 @@
     if (!element)
         return;
 
-    auto renderer = element->renderer();
-    if (!renderer)
+    Frame* frame = element->document().frame();
+    if (!frame)
         return;
 
-    m_page->focusController().setFocusedElement(element, element->document().frame());
-    VisiblePosition position = renderer->positionForPoint(m_lastActionMenuHitTestResult.localPoint(), nullptr);
-    element->document().frame()->selection().setSelection(position);
+    m_page->focusController().setFocusedElement(element, frame);
+    VisiblePosition position = frame->visiblePositionForPoint(m_lastActionMenuHitTestResult.roundedPointInInnerNodeFrame());
+    frame->selection().setSelection(position);
 }
 
 void WebPage::dataDetectorsDidPresentUI(PageOverlay::PageOverlayID overlayID)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to