Whitespace action menus should focus the HitTestResult and create an insertion
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Nov 2014 20:09:50 +0000 (20:09 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 17 Nov 2014 20:09:50 +0000 (20:09 +0000)
point
https://bugs.webkit.org/show_bug.cgi?id=138786
-and corresponding-
rdar://problem/18944893

Reviewed by Tim Horton.

Whitespace menus should cause the HitTestResult to be focused, and they should set
the selection based on the HitTest location.
Source/WebKit/mac:

* WebView/WebActionMenuController.mm:
(-[WebActionMenuController isMenuForTextContent]):
(-[WebActionMenuController focusAndSelectHitTestResult]):
(-[WebActionMenuController willOpenMenu:withEvent:]):

Source/WebKit2:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::focusAndSelectLastActionMenuHitTestResult):
* UIProcess/WebPageProxy.h:
* UIProcess/mac/WKActionMenuController.mm:
(-[WKActionMenuController isMenuForTextContent]):
(-[WKActionMenuController willOpenMenu:withEvent:]):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performActionMenuHitTestAtLocation):
(WebKit::WebPage::focusAndSelectLastActionMenuHitTestResult):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@176220 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebActionMenuController.mm
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/mac/WKActionMenuController.mm
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm

index 0bf6175..61072a2 100644 (file)
@@ -1,3 +1,21 @@
+2014-11-17  Beth Dakin  <bdakin@apple.com>
+
+        Whitespace action menus should focus the HitTestResult and create an insertion 
+        point
+        https://bugs.webkit.org/show_bug.cgi?id=138786
+        -and corresponding-
+        rdar://problem/18944893
+
+        Reviewed by Tim Horton.
+
+        Whitespace menus should cause the HitTestResult to be focused, and they should set 
+        the selection based on the HitTest location.
+
+        * WebView/WebActionMenuController.mm:
+        (-[WebActionMenuController isMenuForTextContent]):
+        (-[WebActionMenuController focusAndSelectHitTestResult]):
+        (-[WebActionMenuController willOpenMenu:withEvent:]):
+
 2014-11-17  Daniel Bates  <dabates@apple.com>
 
         [iOS] QuartzCore SPI not available in public SDK
index 6514d0e..af47a40 100644 (file)
@@ -44,6 +44,7 @@
 #import <WebCore/Editor.h>
 #import <WebCore/Element.h>
 #import <WebCore/EventHandler.h>
+#import <WebCore/FocusController.h>
 #import <WebCore/Frame.h>
 #import <WebCore/FrameView.h>
 #import <WebCore/HTMLConverter.h>
@@ -150,7 +151,27 @@ struct DictionaryPopupInfo {
 
 - (BOOL)isMenuForTextContent
 {
-    return _type == WebActionMenuReadOnlyText || _type == WebActionMenuEditableText || _type == WebActionMenuEditableTextWithSuggestions || _type == WebActionMenuWhitespaceInEditableArea;
+    return _type == WebActionMenuReadOnlyText || _type == WebActionMenuEditableText || _type == WebActionMenuEditableTextWithSuggestions;
+}
+
+- (void)focusAndSelectHitTestResult
+{
+    if (!_hitTestResult.isContentEditable())
+        return;
+
+    Element* element = _hitTestResult.innerElement();
+    if (!element)
+        return;
+
+    auto renderer = element->renderer();
+    if (!renderer)
+        return;
+
+    Frame& frame = renderer->frame();
+
+    frame.page()->focusController().setFocusedElement(element, element->document().frame());
+    VisiblePosition position = renderer->positionForPoint(_hitTestResult.localPoint(), nullptr);
+    frame.selection().setSelection(position);
 }
 
 - (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event
@@ -171,6 +192,11 @@ struct DictionaryPopupInfo {
         return;
     }
 
+    if (_type == WebActionMenuWhitespaceInEditableArea) {
+        [self focusAndSelectHitTestResult];
+        return;
+    }
+
     if (![self isMenuForTextContent]) {
         [[_webView _selectedOrMainFrame] _clearSelection];
         return;
index 0436551..992c70b 100644 (file)
@@ -1,3 +1,27 @@
+2014-11-17  Beth Dakin  <bdakin@apple.com>
+
+        Whitespace action menus should focus the HitTestResult and create an insertion 
+        point
+        https://bugs.webkit.org/show_bug.cgi?id=138786
+        -and corresponding-
+        rdar://problem/18944893
+
+        Reviewed by Tim Horton.
+
+        Whitespace menus should cause the HitTestResult to be focused, and they should set 
+        the selection based on the HitTest location.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::focusAndSelectLastActionMenuHitTestResult):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/mac/WKActionMenuController.mm:
+        (-[WKActionMenuController isMenuForTextContent]):
+        (-[WKActionMenuController willOpenMenu:withEvent:]):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::performActionMenuHitTestAtLocation):
+        (WebKit::WebPage::focusAndSelectLastActionMenuHitTestResult):
+
 2014-11-17  Daniel Bates  <dabates@apple.com>
 
         [iOS] AVKit and MediaPlayer SPI are not available in public SDK
index de01ca8..25b5565 100644 (file)
@@ -5323,6 +5323,11 @@ void WebPageProxy::selectLastActionMenuRange()
     m_process->send(Messages::WebPage::SelectLastActionMenuRange(), m_pageID);
 }
 
+void WebPageProxy::focusAndSelectLastActionMenuHitTestResult()
+{
+    m_process->send(Messages::WebPage::FocusAndSelectLastActionMenuHitTestResult(), m_pageID);
+}
+
 void WebPageProxy::didPerformActionMenuHitTest(const ActionMenuHitTestResult& result, IPC::MessageDecoder& decoder)
 {
     RefPtr<API::Object> userData;
index 329cdd2..da29579 100644 (file)
@@ -932,6 +932,7 @@ public:
     WebHitTestResult* lastMouseMoveHitTestResult() const { return m_lastMouseMoveHitTestResult.get(); }
     void performActionMenuHitTestAtLocation(WebCore::FloatPoint);
     void selectLastActionMenuRange();
+    void focusAndSelectLastActionMenuHitTestResult();
 #endif
 
 #if PLATFORM(EFL) && HAVE(ACCESSIBILITY) && defined(HAVE_ECORE_X)
index 27d8089..843617b 100644 (file)
@@ -184,7 +184,7 @@ using namespace WebKit;
 
 - (BOOL)isMenuForTextContent
 {
-    return _type == kWKActionMenuReadOnlyText || _type == kWKActionMenuEditableText || _type == kWKActionMenuEditableTextWithSuggestions || _type == kWKActionMenuWhitespaceInEditableArea;
+    return _type == kWKActionMenuReadOnlyText || _type == kWKActionMenuEditableText || _type == kWKActionMenuEditableTextWithSuggestions;
 }
 
 - (void)willOpenMenu:(NSMenu *)menu withEvent:(NSEvent *)event
@@ -204,6 +204,11 @@ using namespace WebKit;
         return;
     }
 
+    if (_type == kWKActionMenuWhitespaceInEditableArea) {
+        _page->focusAndSelectLastActionMenuHitTestResult();
+        return;
+    }
+
     if (![self isMenuForTextContent]) {
         _page->clearSelection();
         return;
index 13524d6..0c5aaa9 100644 (file)
@@ -49,6 +49,7 @@
 #include <WebCore/DragData.h>
 #include <WebCore/Editor.h>
 #include <WebCore/FrameLoaderTypes.h>
+#include <WebCore/HitTestResult.h>
 #include <WebCore/IntRect.h>
 #include <WebCore/IntSizeHash.h>
 #include <WebCore/Page.h>
@@ -1057,6 +1058,7 @@ private:
     void performActionMenuHitTestAtLocation(WebCore::FloatPoint);
     PassRefPtr<WebCore::Range> lookupTextAtLocation(WebCore::FloatPoint);
     void selectLastActionMenuRange();
+    void focusAndSelectLastActionMenuHitTestResult();
 
     void dataDetectorsDidPresentUI();
     void dataDetectorsDidChangeUI();
@@ -1292,6 +1294,7 @@ private:
 
 #if PLATFORM(MAC)
     RefPtr<WebCore::Range> m_lastActionMenuRangeForSelection;
+    WebCore::HitTestResult m_lastActionMenuHitTestResult;
     RefPtr<WebPageOverlay> m_lastActionMenuHitPageOverlay;
 #endif
 };
index 4e972f1..34f8e52 100644 (file)
@@ -400,6 +400,7 @@ messages -> WebPage LegacyReceiver {
 #if PLATFORM(MAC)
     PerformActionMenuHitTestAtLocation(WebCore::FloatPoint location)
     SelectLastActionMenuRange()
+    FocusAndSelectLastActionMenuHitTestResult()
     DataDetectorsDidPresentUI()
     DataDetectorsDidChangeUI()
     DataDetectorsDidHideUI()
index d364c1c..bca5d9c 100644 (file)
@@ -1008,6 +1008,7 @@ void WebPage::performActionMenuHitTestAtLocation(WebCore::FloatPoint locationInV
     RefPtr<WebCore::Range> lookupRange = lookupTextAtLocation(locationInViewCooordinates);
     actionMenuResult.lookupText = lookupRange ? lookupRange->text() : String();
     m_lastActionMenuRangeForSelection = lookupRange;
+    m_lastActionMenuHitTestResult = hitTestResult;
 
     if (Image* image = hitTestResult.image()) {
         actionMenuResult.image = ShareableBitmap::createShareable(IntSize(image->size()), ShareableBitmap::SupportsAlpha);
@@ -1081,6 +1082,24 @@ void WebPage::selectLastActionMenuRange()
         corePage()->mainFrame().selection().setSelectedRange(m_lastActionMenuRangeForSelection.get(), DOWNSTREAM, true);
 }
 
+void WebPage::focusAndSelectLastActionMenuHitTestResult()
+{
+    if (!m_lastActionMenuHitTestResult.isContentEditable())
+        return;
+
+    Element* element = m_lastActionMenuHitTestResult.innerElement();
+    if (!element)
+        return;
+
+    auto renderer = element->renderer();
+    if (!renderer)
+        return;
+
+    m_page->focusController().setFocusedElement(element, element->document().frame());
+    VisiblePosition position = renderer->positionForPoint(m_lastActionMenuHitTestResult.localPoint(), nullptr);
+    element->document().frame()->selection().setSelection(position);
+}
+
 void WebPage::dataDetectorsDidPresentUI()
 {
     if (m_lastActionMenuHitPageOverlay)