Reviewed by Darin Adler.
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Nov 2007 21:12:44 +0000 (21:12 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 10 Nov 2007 21:12:44 +0000 (21:12 +0000)
        - fix <rdar://problem/5450655> Control-clicking text in a link can surprisingly select only part of the link, should select entire link

        No test because context menu events cannot be tested in DumpRenderTree.

        * page/EventHandler.cpp:
        (WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent): Added.
        If the click occurred in an active link, selects the entire link
        element. Otherwise selects the closest word.
        (WebCore::EventHandler::sendContextMenuEvent): Call
        selectClosestWordOrLinkFromMouseEvent().
        * page/EventHandler.h:

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

WebCore/ChangeLog
WebCore/page/EventHandler.cpp
WebCore/page/EventHandler.h

index 4e0b8eb9d6739a035d1359b16545bc9eae2172d4..ea91d524951fd0a34228d3f90866dae835f1fc6e 100644 (file)
@@ -1,3 +1,19 @@
+2007-11-10  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Darin Adler.
+
+        - fix <rdar://problem/5450655> Control-clicking text in a link can surprisingly select only part of the link, should select entire link
+
+        No test because context menu events cannot be tested in DumpRenderTree.
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent): Added.
+        If the click occurred in an active link, selects the entire link
+        element. Otherwise selects the closest word.
+        (WebCore::EventHandler::sendContextMenuEvent): Call
+        selectClosestWordOrLinkFromMouseEvent().
+        * page/EventHandler.h:
+
 2007-11-10  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Tim Hatcher
index c4dbba6b0f2f4227d90a445b9c1827ee9d088752..d6c8ce961d898111c4a9d145f23c51d19cd865f6 100644 (file)
@@ -169,6 +169,30 @@ void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestRe
     }
 }
 
+void EventHandler::selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults& result)
+{
+    if (!result.hitTestResult().isLiveLink())
+        return selectClosestWordFromMouseEvent(result);
+
+    Node* innerNode = result.targetNode();
+
+    if (innerNode && innerNode->renderer() && m_mouseDownMayStartSelect) {
+        Selection newSelection;
+        Element* URLElement = result.hitTestResult().URLElement();
+        VisiblePosition pos(innerNode->renderer()->positionForPoint(result.localPoint()));
+        if (pos.isNotNull() && pos.deepEquivalent().node()->isDescendantOf(URLElement))
+            newSelection = Selection::selectionFromContentsOfNode(URLElement);
+    
+        if (newSelection.isRange()) {
+            m_frame->setSelectionGranularity(WordGranularity);
+            m_beganSelectingText = true;
+        }
+
+        if (m_frame->shouldChangeSelection(newSelection))
+            m_frame->selectionController()->setSelection(newSelection);
+    }
+}
+
 bool EventHandler::handleMousePressEventDoubleClick(const MouseEventWithHitTestResults& event)
 {
     if (event.event().button() != LeftButton)
@@ -1348,7 +1372,7 @@ bool EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event)
         // available for text selections.  But only if we're above text.
         (m_frame->selectionController()->isContentEditable() || mev.targetNode() && mev.targetNode()->isTextNode())) {
         m_mouseDownMayStartSelect = true; // context menu events are always allowed to perform a selection
-        selectClosestWordFromMouseEvent(mev);
+        selectClosestWordOrLinkFromMouseEvent(mev);
     }
 
     swallowEvent = dispatchMouseEvent(contextmenuEvent, mev.targetNode(), true, 0, event, true);
index ec74d5301c80cfc296df501d288f978808819880..72277f6fe8cc349ac27b9d4249c6375fccec67d5 100644 (file)
@@ -182,6 +182,7 @@ private:
     
     bool eventActivatedView(const PlatformMouseEvent&) const;
     void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& event);
+    void selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHitTestResults& event);
 
     bool handleMouseDoubleClickEvent(const PlatformMouseEvent&);