WebCore:
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Sep 2006 02:24:00 +0000 (02:24 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 16 Sep 2006 02:24:00 +0000 (02:24 +0000)
        Reviewed by Justin.

        Removed alter selection logic from WebCoreFrameBridge and moved to SelectionController.

        * bridge/mac/WebCoreFrameBridge.h:
        * bridge/mac/WebCoreFrameBridge.mm:
        (-[WebCoreFrameBridge centerSelectionInVisibleArea]):
        (-[WebCoreFrameBridge rangeByExpandingSelectionWithGranularity:]):
        (-[WebCoreFrameBridge rangeByAlteringCurrentSelection:direction:granularity:]):
        (-[WebCoreFrameBridge alterCurrentSelection:direction:granularity:]):
        (-[WebCoreFrameBridge alterCurrentSelection:verticalDistance:]):
        (-[WebCoreFrameBridge replaceMarkedTextWithText:]):
        (-[WebCoreFrameBridge replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]):
        (-[WebCoreFrameBridge increaseSelectionListLevel]):
        (-[WebCoreFrameBridge increaseSelectionListLevelOrdered]):
        (-[WebCoreFrameBridge increaseSelectionListLevelUnordered]):
        (-[WebCoreFrameBridge decreaseSelectionListLevel]):
        (-[WebCoreFrameBridge insertLineBreak]):
        (-[WebCoreFrameBridge insertParagraphSeparator]):
        (-[WebCoreFrameBridge insertParagraphSeparatorInQuotedContent]):
        (-[WebCoreFrameBridge insertText:selectInsertedText:]):
        (-[WebCoreFrameBridge deleteKeyPressedWithSmartDelete:granularity:]):
        (-[WebCoreFrameBridge forwardDeleteKeyPressedWithSmartDelete:granularity:]):
        (createMouseEventFromDraggingInfo):
        * editing/SelectionController.cpp:
        (WebCore::SelectionController::moveTo):
        (WebCore::SelectionController::setSelection):
        (WebCore::SelectionController::modify):
        (WebCore::SelectionController::setBase):
        (WebCore::SelectionController::setExtent):
        * editing/SelectionController.h:
        * page/Frame.cpp:
        (WebCore::Frame::revealSelection):
        (WebCore::Frame::revealCaret):
        * page/Frame.h:

WebKit:

        Reviewed by Justin.

        Call the bridge directly for alter selection calls. All of this logic is now
        in WebCore's SelectionController.

        * WebView/WebHTMLView.m:
        (-[NSArray moveBackward:]):
        (-[NSArray moveBackwardAndModifySelection:]):
        (-[NSArray moveDown:]):
        (-[NSArray moveDownAndModifySelection:]):
        (-[NSArray moveForward:]):
        (-[NSArray moveForwardAndModifySelection:]):
        (-[NSArray moveLeft:]):
        (-[NSArray moveLeftAndModifySelection:]):
        (-[NSArray moveRight:]):
        (-[NSArray moveRightAndModifySelection:]):
        (-[NSArray moveToBeginningOfDocument:]):
        (-[NSArray moveToBeginningOfDocumentAndModifySelection:]):
        (-[NSArray moveToBeginningOfSentence:]):
        (-[NSArray moveToBeginningOfSentenceAndModifySelection:]):
        (-[NSArray moveToBeginningOfLine:]):
        (-[NSArray moveToBeginningOfLineAndModifySelection:]):
        (-[NSArray moveToBeginningOfParagraph:]):
        (-[NSArray moveToBeginningOfParagraphAndModifySelection:]):
        (-[NSArray moveToEndOfDocument:]):
        (-[NSArray moveToEndOfDocumentAndModifySelection:]):
        (-[NSArray moveToEndOfSentence:]):
        (-[NSArray moveToEndOfSentenceAndModifySelection:]):
        (-[NSArray moveToEndOfLine:]):
        (-[NSArray moveToEndOfLineAndModifySelection:]):
        (-[NSArray moveToEndOfParagraph:]):
        (-[NSArray moveToEndOfParagraphAndModifySelection:]):
        (-[NSArray moveParagraphBackwardAndModifySelection:]):
        (-[NSArray moveParagraphForwardAndModifySelection:]):
        (-[NSArray moveUp:]):
        (-[NSArray moveUpAndModifySelection:]):
        (-[NSArray moveWordBackward:]):
        (-[NSArray moveWordBackwardAndModifySelection:]):
        (-[NSArray moveWordForward:]):
        (-[NSArray moveWordForwardAndModifySelection:]):
        (-[NSArray moveWordLeft:]):
        (-[NSArray moveWordLeftAndModifySelection:]):
        (-[NSArray moveWordRight:]):
        (-[NSArray moveWordRightAndModifySelection:]):
        (-[NSArray pageUp:]):
        (-[NSArray pageDown:]):
        (-[NSArray pageUpAndModifySelection:]):
        (-[NSArray pageDownAndModifySelection:]):

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

WebCore/ChangeLog
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/editing/SelectionController.cpp
WebCore/editing/SelectionController.h
WebCore/page/Frame.cpp
WebCore/page/Frame.h
WebKit/ChangeLog
WebKit/WebKit.xcodeproj/project.pbxproj
WebKit/WebView/WebHTMLView.m

index e3239a8407bbfcf9a5ec6acb5ff40f67ac144ab9..76db5c77ed78bbe9d3e05c3d14d6bac1be1de157 100644 (file)
@@ -1,3 +1,41 @@
+2006-09-15  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Justin.
+
+        Removed alter selection logic from WebCoreFrameBridge and moved to SelectionController.
+
+        * bridge/mac/WebCoreFrameBridge.h:
+        * bridge/mac/WebCoreFrameBridge.mm:
+        (-[WebCoreFrameBridge centerSelectionInVisibleArea]):
+        (-[WebCoreFrameBridge rangeByExpandingSelectionWithGranularity:]):
+        (-[WebCoreFrameBridge rangeByAlteringCurrentSelection:direction:granularity:]):
+        (-[WebCoreFrameBridge alterCurrentSelection:direction:granularity:]):
+        (-[WebCoreFrameBridge alterCurrentSelection:verticalDistance:]):
+        (-[WebCoreFrameBridge replaceMarkedTextWithText:]):
+        (-[WebCoreFrameBridge replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]):
+        (-[WebCoreFrameBridge increaseSelectionListLevel]):
+        (-[WebCoreFrameBridge increaseSelectionListLevelOrdered]):
+        (-[WebCoreFrameBridge increaseSelectionListLevelUnordered]):
+        (-[WebCoreFrameBridge decreaseSelectionListLevel]):
+        (-[WebCoreFrameBridge insertLineBreak]):
+        (-[WebCoreFrameBridge insertParagraphSeparator]):
+        (-[WebCoreFrameBridge insertParagraphSeparatorInQuotedContent]):
+        (-[WebCoreFrameBridge insertText:selectInsertedText:]):
+        (-[WebCoreFrameBridge deleteKeyPressedWithSmartDelete:granularity:]):
+        (-[WebCoreFrameBridge forwardDeleteKeyPressedWithSmartDelete:granularity:]):
+        (createMouseEventFromDraggingInfo):
+        * editing/SelectionController.cpp:
+        (WebCore::SelectionController::moveTo):
+        (WebCore::SelectionController::setSelection):
+        (WebCore::SelectionController::modify):
+        (WebCore::SelectionController::setBase):
+        (WebCore::SelectionController::setExtent):
+        * editing/SelectionController.h:
+        * page/Frame.cpp:
+        (WebCore::Frame::revealSelection):
+        (WebCore::Frame::revealCaret):
+        * page/Frame.h:
+
 2006-09-15  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Anders
index 5919a444ef7ac86e94302ec3d9b860faf3b2af44..551b243bee31df8c799fcd76e2cc6107a8d39fae 100644 (file)
@@ -407,7 +407,6 @@ typedef enum {
 - (DOMRange *)rangeOfCharactersAroundCaret;
 - (DOMRange *)rangeByAlteringCurrentSelection:(WebSelectionAlteration)alteration direction:(WebBridgeSelectionDirection)direction granularity:(WebBridgeSelectionGranularity)granularity;
 - (void)alterCurrentSelection:(WebSelectionAlteration)alteration direction:(WebBridgeSelectionDirection)direction granularity:(WebBridgeSelectionGranularity)granularity;
-- (DOMRange *)rangeByAlteringCurrentSelection:(WebSelectionAlteration)alteration verticalDistance:(float)distance;
 - (void)alterCurrentSelection:(WebSelectionAlteration)alteration verticalDistance:(float)distance;
 - (WebBridgeSelectionGranularity)selectionGranularity;
 - (DOMRange *)smartDeleteRangeForProposedRange:(DOMRange *)proposedCharRange;
@@ -464,8 +463,6 @@ typedef enum {
 - (void)applyEditingStyleToElement:(DOMElement *)element;
 - (void)removeEditingStyleFromElement:(DOMElement *)element;
 
-- (void)ensureSelectionVisible;
-
 - (WebScriptObject *)windowScriptObject;
 - (NPObject *)windowScriptNPObject;
 
index a77ab60975b694df1550e34dbce52cffc6deb8dc..6d2b8a0b0f23a6c5c79868e4406cc3555311756b 100644 (file)
@@ -1401,7 +1401,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
 
 - (void)centerSelectionInVisibleArea
 {
-    m_frame->centerSelectionInVisibleArea(); 
+    m_frame->revealSelection(RenderLayer::gAlignCenterAlways);
 }
 
 - (NSRect)caretRectAtNode:(DOMNode *)node offset:(int)offset affinity:(NSSelectionAffinity)affinity
@@ -1627,7 +1627,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
 {
     if (!m_frame->hasSelection())
         return nil;
-        
+
     // NOTE: The enums *must* match the very similar ones declared in SelectionController.h
     Selection selection(m_frame->selectionController()->selection());
     selection.expandUsingGranularity(static_cast<TextGranularity>(granularity));
@@ -1638,7 +1638,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
 {
     if (!m_frame->hasSelection())
         return nil;
-        
+
     // NOTE: The enums *must* match the very similar ones declared in SelectionController.h
     SelectionController selectionController;
     selectionController.setSelection(m_frame->selectionController()->selection());
@@ -1652,76 +1652,20 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
 {
     if (!m_frame->hasSelection())
         return;
-    
-    
-    // save vertical navigation x position if necessary; many types of motion blow it away
-    int xPos = Frame::NoXPosForVerticalArrowNavigation;
-    switch (granularity) {
-        case WebBridgeSelectByLine:
-        case WebBridgeSelectByParagraph:
-            xPos = m_frame->xPosForVerticalArrowNavigation();
-            break;
-        case WebBridgeSelectByCharacter:
-        case WebBridgeSelectByWord:
-        case WebBridgeSelectBySentence:
-        case WebBridgeSelectToLineBoundary:
-        case WebBridgeSelectToParagraphBoundary:
-        case WebBridgeSelectToSentenceBoundary:
-        case WebBridgeSelectToDocumentBoundary:
-            break;
-    }
-        
+
     // NOTE: The enums *must* match the very similar ones declared in SelectionController.h
     SelectionController* selectionController = m_frame->selectionController();
     selectionController->modify(static_cast<SelectionController::EAlter>(alteration), 
                                 static_cast<SelectionController::EDirection>(direction), 
-                                static_cast<TextGranularity>(granularity));
-    
-    // altering the selection also sets the granularity back to character
-    // NOTE: The one exception is that we need to keep word granularity
-    // to preserve smart delete behavior when extending by word.  e.g. double-click,
-    // then shift-option-rightarrow, then delete needs to smart delete, per TextEdit.
-    if (!((alteration == WebSelectByExtending) &&
-          (granularity == WebBridgeSelectByWord) && (m_frame->selectionGranularity() == WordGranularity)))
-        m_frame->setSelectionGranularity(static_cast<TextGranularity>(WebBridgeSelectByCharacter));
-    
-    // restore vertical navigation x position if necessary
-    if (xPos != Frame::NoXPosForVerticalArrowNavigation)
-        m_frame->setXPosForVerticalArrowNavigation(xPos);
-
-    m_frame->selectFrameElementInParentIfFullySelected();
-    
-    m_frame->notifyRendererOfSelectionChange(true);
-
-    [self ensureSelectionVisible];
-}
-
-- (DOMRange *)rangeByAlteringCurrentSelection:(WebSelectionAlteration)alteration verticalDistance:(float)verticalDistance
-{
-    if (!m_frame->hasSelection())
-        return nil;
-        
-    SelectionController selectionController;
-    selectionController.setSelection(m_frame->selectionController()->selection());
-    selectionController.modify(static_cast<SelectionController::EAlter>(alteration), static_cast<int>(verticalDistance));
-    return [DOMRange _rangeWith:selectionController.toRange().get()];
+                                static_cast<TextGranularity>(granularity), true);
 }
 
 - (void)alterCurrentSelection:(WebSelectionAlteration)alteration verticalDistance:(float)verticalDistance
 {
     if (!m_frame->hasSelection())
         return;
-        
-    // setting the selection always clears saved vertical navigation x position, so preserve it
-    int xPos = m_frame->xPosForVerticalArrowNavigation();    
-    
-    m_frame->selectionController()->modify(static_cast<SelectionController::EAlter>(alteration), static_cast<int>(verticalDistance));
-    m_frame->setSelectionGranularity(static_cast<TextGranularity>(WebBridgeSelectByCharacter));
-    m_frame->setXPosForVerticalArrowNavigation(xPos);
-    m_frame->selectFrameElementInParentIfFullySelected();
-    m_frame->notifyRendererOfSelectionChange(true);
-
-    [self ensureSelectionVisible];
+    SelectionController* selectionController = m_frame->selectionController();
+    selectionController->modify(static_cast<SelectionController::EAlter>(alteration), static_cast<int>(verticalDistance), true);
 }
 
 - (WebBridgeSelectionGranularity)selectionGranularity
@@ -1852,7 +1796,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
     if ([text length] > 0)
         TypingCommand::insertText(m_frame->document(), text, YES);
     
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (BOOL)canDeleteRange:(DOMRange *)range
@@ -1997,7 +1941,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return;
     
     applyCommand(new ReplaceSelectionCommand(m_frame->document(), [fragment _documentFragment], selectReplacement, smartReplace, matchStyle));
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (void)replaceSelectionWithNode:(DOMNode *)node selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle
@@ -2036,7 +1980,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return nil;
     
     Node* newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevel(m_frame->document());
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
     return [DOMNode _nodeWith:newList];
 }
 
@@ -2046,7 +1990,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return nil;
     
     Node* newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevelOrdered(m_frame->document());
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
     return [DOMNode _nodeWith:newList];
 }
 
@@ -2056,7 +2000,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return nil;
     
     Node* newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevelUnordered(m_frame->document());
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
     return [DOMNode _nodeWith:newList];
 }
 
@@ -2066,7 +2010,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return;
     
     DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(m_frame->document());
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (void)insertLineBreak
@@ -2075,7 +2019,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return;
     
     TypingCommand::insertLineBreak(m_frame->document());
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (void)insertParagraphSeparator
@@ -2084,7 +2028,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return;
     
     TypingCommand::insertParagraphSeparator(m_frame->document());
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (void)insertParagraphSeparatorInQuotedContent
@@ -2093,7 +2037,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return;
     
     TypingCommand::insertParagraphSeparatorInQuotedContent(m_frame->document());
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (void)insertText:(NSString *)text selectInsertedText:(BOOL)selectInsertedText
@@ -2102,7 +2046,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return;
     
     TypingCommand::insertText(m_frame->document(), text, selectInsertedText);
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (void)setSelectionToDragCaret
@@ -2196,7 +2140,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return;
     
     TypingCommand::deleteKeyPressed(m_frame->document(), smartDelete, static_cast<TextGranularity>(granularity));
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (void)forwardDeleteKeyPressedWithSmartDelete:(BOOL)smartDelete granularity:(WebBridgeSelectionGranularity)granularity
@@ -2205,7 +2149,7 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
         return;
     
     TypingCommand::forwardDeleteKeyPressed(m_frame->document(), smartDelete, static_cast<TextGranularity>(granularity));
-    [self ensureSelectionVisible];
+    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 - (DOMCSSStyleDeclaration *)typingStyle
@@ -2308,35 +2252,6 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
     return m_frame ? m_frame->baseWritingDirectionForSelectionStart() : (NSWritingDirection)NSWritingDirectionLeftToRight;
 }
 
-- (void)ensureSelectionVisible
-{
-    if (!m_frame->hasSelection())
-        return;
-    
-    FrameView *v = m_frame->view();
-    if (!v)
-        return;
-
-    Position extent = m_frame->selectionController()->extent();
-    if (extent.isNull())
-        return;
-    
-    RenderObject *renderer = extent.node()->renderer();
-    if (!renderer)
-        return;
-    
-    NSView *documentView = v->getDocumentView();
-    if (!documentView)
-        return;
-    
-    IntRect extentRect = VisiblePosition(extent).caretRect();
-    RenderLayer *layer = renderer->enclosingLayer();
-    if (layer)
-        layer->scrollRectToVisible(extentRect, RenderLayer::gAlignToEdgeIfNeeded, RenderLayer::gAlignToEdgeIfNeeded);
-}
-
-// [info draggingLocation] is in window coords
-
 - (BOOL)eventMayStartDrag:(NSEvent *)event
 {
     return m_frame ? m_frame->eventMayStartDrag(event) : NO;
@@ -2350,6 +2265,7 @@ static IntPoint globalPoint(NSWindow* window, NSPoint windowPoint)
 static PlatformMouseEvent createMouseEventFromDraggingInfo(NSWindow* window, id <NSDraggingInfo> info)
 {
     // FIXME: Fake modifier keys here.
+    // [info draggingLocation] is in window coords
     return PlatformMouseEvent(IntPoint([info draggingLocation]), globalPoint(window, [info draggingLocation]),
         LeftButton, 0, false, false, false, false);
 }
index 380bc7c29831ef853ca3fac30d58a7d47e1c06bc..b67c975e765e308373471bee125337890de5c2b4 100644 (file)
@@ -50,37 +50,37 @@ SelectionController::SelectionController(Frame* frame, bool isDragCaretControlle
 {
 }
 
-void SelectionController::moveTo(const VisiblePosition &pos)
+void SelectionController::moveTo(const VisiblePosition &pos, bool userTriggered)
 {
-    setSelection(Selection(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity()));
+    setSelection(Selection(pos.deepEquivalent(), pos.deepEquivalent(), pos.affinity()), true, true, userTriggered);
 }
 
-void SelectionController::moveTo(const VisiblePosition &base, const VisiblePosition &extent)
+void SelectionController::moveTo(const VisiblePosition &base, const VisiblePosition &extent, bool userTriggered)
 {
-    setSelection(Selection(base.deepEquivalent(), extent.deepEquivalent(), base.affinity()));
+    setSelection(Selection(base.deepEquivalent(), extent.deepEquivalent(), base.affinity()), true, true, userTriggered);
 }
 
-void SelectionController::moveTo(const SelectionController &o)
+void SelectionController::moveTo(const SelectionController &o, bool userTriggered)
 {
-    setSelection(o.m_sel);
+    setSelection(o.m_sel, true, true, userTriggered);
 }
 
-void SelectionController::moveTo(const Position &pos, EAffinity affinity)
+void SelectionController::moveTo(const Position &pos, EAffinity affinity, bool userTriggered)
 {
-    setSelection(Selection(pos, affinity));
+    setSelection(Selection(pos, affinity), true, true, userTriggered);
 }
 
-void SelectionController::moveTo(const Range *r, EAffinity affinity)
+void SelectionController::moveTo(const Range *r, EAffinity affinity, bool userTriggered)
 {
-    setSelection(Selection(startPosition(r), endPosition(r), affinity));
+    setSelection(Selection(startPosition(r), endPosition(r), affinity), true, true, userTriggered);
 }
 
-void SelectionController::moveTo(const Position &base, const Position &extent, EAffinity affinity)
+void SelectionController::moveTo(const Position &base, const Position &extent, EAffinity affinity, bool userTriggered)
 {
-    setSelection(Selection(base, extent, affinity));
+    setSelection(Selection(base, extent, affinity), true, true, userTriggered);
 }
 
-void SelectionController::setSelection(const Selection& s, bool closeTyping, bool clearTypingStyle)
+void SelectionController::setSelection(const Selection& s, bool closeTyping, bool clearTypingStyle, bool userTriggered)
 {
     if (m_isDragCaretController) {
         needsCaretRepaint();
@@ -123,8 +123,11 @@ void SelectionController::setSelection(const Selection& s, bool closeTyping, boo
     // Always clear the x position used for vertical arrow navigation.
     // It will be restored by the vertical arrow navigation code if necessary.
     m_frame->setXPosForVerticalArrowNavigation(Frame::NoXPosForVerticalArrowNavigation);
-    m_frame->notifyRendererOfSelectionChange(false);
+    m_frame->selectFrameElementInParentIfFullySelected();
+    m_frame->notifyRendererOfSelectionChange(userTriggered);
     m_frame->respondToChangedSelection(oldSelection, closeTyping);
+    if (userTriggered)
+        m_frame->revealCaret(RenderLayer::gAlignToEdgeIfNeeded);
 }
 
 void SelectionController::nodeWillBeRemoved(Node *node)
@@ -394,7 +397,7 @@ VisiblePosition SelectionController::modifyMovingLeftBackward(TextGranularity gr
     return pos;
 }
 
-bool SelectionController::modify(const String &alterString, const String &directionString, const String &granularityString)
+bool SelectionController::modify(const String &alterString, const String &directionString, const String &granularityString, bool userTriggered)
 {
     String alterStringLower = alterString.lower();
     EAlter alter;
@@ -437,11 +440,21 @@ bool SelectionController::modify(const String &alterString, const String &direct
     else
         return false;
                 
-    return modify(alter, direction, granularity);
+    return modify(alter, direction, granularity, userTriggered);
 }
 
-bool SelectionController::modify(EAlter alter, EDirection dir, TextGranularity granularity)
+bool SelectionController::modify(EAlter alter, EDirection dir, TextGranularity granularity, bool userTriggered)
 {
+    if (userTriggered) {
+        SelectionController trialSelectionController;
+        trialSelectionController.setSelection(m_sel);
+        trialSelectionController.modify(alter, dir, granularity, false);
+
+        bool change = m_frame->shouldChangeSelection(trialSelectionController.selection());
+        if (!change)
+            return false;
+    }
+
     if (m_frame)
         m_frame->setSelectionGranularity(granularity);
     
@@ -471,13 +484,22 @@ bool SelectionController::modify(EAlter alter, EDirection dir, TextGranularity g
 
     switch (alter) {
         case MOVE:
-            moveTo(pos);
+            moveTo(pos, userTriggered);
             break;
         case EXTEND:
-            setExtent(pos);
+            setExtent(pos, userTriggered);
             break;
     }
 
+    if (userTriggered) {
+        // User modified selection change also sets the granularity back to character.
+        // NOTE: The one exception is that we need to keep word granularity to
+        // preserve smart delete behavior when extending by word (e.g. double-click),
+        // then shift-option-right arrow, then delete needs to smart delete, per TextEdit.
+        if (!(alter == EXTEND && granularity == WordGranularity && m_frame->selectionGranularity() == WordGranularity))
+            m_frame->setSelectionGranularity(CharacterGranularity);
+    }
+
     setNeedsLayout();
 
     return true;
@@ -500,11 +522,21 @@ static bool caretY(const VisiblePosition &c, int &y)
     return true;
 }
 
-bool SelectionController::modify(EAlter alter, int verticalDistance)
+bool SelectionController::modify(EAlter alter, int verticalDistance, bool userTriggered)
 {
     if (verticalDistance == 0)
         return false;
 
+    if (userTriggered) {
+        SelectionController trialSelectionController;
+        trialSelectionController.setSelection(m_sel);
+        trialSelectionController.modify(alter, verticalDistance, false);
+
+        bool change = m_frame->shouldChangeSelection(trialSelectionController.selection());
+        if (!change)
+            return false;
+    }
+
     bool up = verticalDistance < 0;
     if (up)
         verticalDistance = -verticalDistance;
@@ -557,13 +589,16 @@ bool SelectionController::modify(EAlter alter, int verticalDistance)
 
     switch (alter) {
         case MOVE:
-            moveTo(result);
+            moveTo(result, userTriggered);
             break;
         case EXTEND:
-            setExtent(result);
+            setExtent(result, userTriggered);
             break;
     }
 
+    if (userTriggered)
+        m_frame->setSelectionGranularity(CharacterGranularity);
+
     return true;
 }
 
@@ -620,24 +655,24 @@ void SelectionController::clear()
     setSelection(Selection());
 }
 
-void SelectionController::setBase(const VisiblePosition &pos)
+void SelectionController::setBase(const VisiblePosition &pos, bool userTriggered)
 {
-    setSelection(Selection(pos.deepEquivalent(), m_sel.extent(), pos.affinity()));
+    setSelection(Selection(pos.deepEquivalent(), m_sel.extent(), pos.affinity()), true, true, userTriggered);
 }
 
-void SelectionController::setExtent(const VisiblePosition &pos)
+void SelectionController::setExtent(const VisiblePosition &pos, bool userTriggered)
 {
-    setSelection(Selection(m_sel.base(), pos.deepEquivalent(), pos.affinity()));
+    setSelection(Selection(m_sel.base(), pos.deepEquivalent(), pos.affinity()), true, true, userTriggered);
 }
 
-void SelectionController::setBase(const Position &pos, EAffinity affinity)
+void SelectionController::setBase(const Position &pos, EAffinity affinity, bool userTriggered)
 {
-    setSelection(Selection(pos, m_sel.extent(), affinity));
+    setSelection(Selection(pos, m_sel.extent(), affinity), true, true, userTriggered);
 }
 
-void SelectionController::setExtent(const Position &pos, EAffinity affinity)
+void SelectionController::setExtent(const Position &pos, EAffinity affinity, bool userTriggered)
 {
-    setSelection(Selection(m_sel.base(), pos, affinity));
+    setSelection(Selection(m_sel.base(), pos, affinity), true, true, userTriggered);
 }
 
 void SelectionController::setNeedsLayout(bool flag)
index 76519d7dce2e0d5f07bd4c73c3fe1347488f724f..c7e8373df6d6d8a5039bbce88c61b328bcb503dc 100644 (file)
@@ -50,30 +50,30 @@ public:
     bool isContentEditable() const { return selection().isContentEditable(); }
     bool isContentRichlyEditable() const { return selection().isContentRichlyEditable(); }
 
-    void moveTo(const Range*, EAffinity);
-    void moveTo(const VisiblePosition&);
-    void moveTo(const VisiblePosition&, const VisiblePosition&);
-    void moveTo(const Position&, EAffinity);
-    void moveTo(const Position&, const Position&, EAffinity);
-    void moveTo(const SelectionController&);
+    void moveTo(const Range*, EAffinity, bool userTriggered = false);
+    void moveTo(const VisiblePosition&, bool userTriggered = false);
+    void moveTo(const VisiblePosition&, const VisiblePosition&, bool userTriggered = false);
+    void moveTo(const Position&, EAffinity, bool userTriggered = false);
+    void moveTo(const Position&, const Position&, EAffinity, bool userTriggered = false);
+    void moveTo(const SelectionController&, bool userTriggered = false);
 
     const Selection& selection() const { return m_sel; }
-    void setSelection(const Selection&, bool closeTyping = true, bool clearTypingStyle = true);
+    void setSelection(const Selection&, bool closeTyping = true, bool clearTypingStyle = true, bool userTriggered = false);
 
     Selection::EState state() const { return m_sel.state(); }
 
     EAffinity affinity() const { return m_sel.affinity(); }
 
-    bool modify(EAlter, EDirection, TextGranularity);
-    bool modify(EAlter, int verticalDistance);
+    bool modify(EAlter, EDirection, TextGranularity, bool userTriggered = false);
+    bool modify(EAlter, int verticalDistance, bool userTriggered = false);
     bool expandUsingGranularity(TextGranularity);
 
     void clear();
 
-    void setBase(const VisiblePosition& );
-    void setBase(const Position&, EAffinity);
-    void setExtent(const VisiblePosition&);
-    void setExtent(const Position&, EAffinity);
+    void setBase(const VisiblePosition&, bool userTriggered = false);
+    void setBase(const Position&, EAffinity, bool userTriggered = false);
+    void setExtent(const VisiblePosition&, bool userTriggered = false);
+    void setExtent(const Position&, EAffinity, bool userTriggered = false);
 
     Position base() const { return m_sel.base(); }
     Position extent() const { return m_sel.extent(); }
@@ -105,7 +105,7 @@ public:
     String type() const;
     void setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset);
     void setPosition(Node*, int offset);
-    bool modify(const String& alterString, const String& directionString, const String& granularityString);
+    bool modify(const String& alterString, const String& directionString, const String& granularityString, bool userTriggered = false);
     
     // Mozilla Selection Object API
     // In FireFox, anchor/focus are the equal to the start/end of the selection,
index 402d00325d8f8921c28c55b1763e839c96d97471..b1bcab7db2c1d1824f8c0c004d1fbf97cc4769cf 100644 (file)
@@ -2756,7 +2756,7 @@ void Frame::addData(const char *bytes, int length)
 }
 
 // FIXME: should this go in SelectionController?
-void Frame::revealSelection()
+void Frame::revealSelection(const RenderLayer::ScrollAlignment& alignment) const
 {
     IntRect rect;
     
@@ -2772,20 +2772,35 @@ void Frame::revealSelection()
             rect = selectionRect();
             break;
     }
-    
+
     Position start = selectionController()->start();
     Position end = selectionController()->end();
+
     ASSERT(start.node());
     if (start.node() && start.node()->renderer()) {
         RenderLayer *layer = start.node()->renderer()->enclosingLayer();
         if (layer) {
             ASSERT(!end.node() || !end.node()->renderer() 
                    || (end.node()->renderer()->enclosingLayer() == layer));
-            layer->scrollRectToVisible(rect);
+            layer->scrollRectToVisible(rect, alignment, alignment);
         }
     }
 }
 
+void Frame::revealCaret(const RenderLayer::ScrollAlignment& alignment) const
+{
+    if (!hasSelection())
+        return;
+
+    Position extent = selectionController()->extent();
+    if (extent.node() && extent.node()->renderer()) {
+        IntRect extentRect = VisiblePosition(extent).caretRect();
+        RenderLayer* layer = extent.node()->renderer()->enclosingLayer();
+        if (layer)
+            layer->scrollRectToVisible(extentRect, alignment, alignment);
+    }
+}
+
 // FIXME: should this be here?
 bool Frame::scrollOverflow(ScrollDirection direction, ScrollGranularity granularity)
 {
@@ -3257,37 +3272,6 @@ void Frame::clearTimers()
     clearTimers(d->m_view.get());
 }
 
-// FIXME: selection controller?
-void Frame::centerSelectionInVisibleArea() const
-{
-    IntRect rect;
-    
-    switch (selectionController()->state()) {
-        case Selection::NONE:
-            return;
-            
-        case Selection::CARET:
-            rect = selectionController()->caretRect();
-            break;
-            
-        case Selection::RANGE:
-            rect = selectionRect();
-            break;
-    }
-    
-    Position start = selectionController()->start();
-    Position end = selectionController()->end();
-    ASSERT(start.node());
-    if (start.node() && start.node()->renderer()) {
-        RenderLayer *layer = start.node()->renderer()->enclosingLayer();
-        if (layer) {
-            ASSERT(!end.node() || !end.node()->renderer() 
-                   || (end.node()->renderer()->enclosingLayer() == layer));
-            layer->scrollRectToVisible(rect, RenderLayer::gAlignCenterAlways, RenderLayer::gAlignCenterAlways);
-        }
-    }
-}
-
 RenderStyle *Frame::styleForSelectionStart(Node *&nodeToRemove) const
 {
     nodeToRemove = 0;
index 6091f40dd8269856d91010a993a2f2492cf685fc..adf19404f8e632191d238eade35bd955409b7060 100644 (file)
@@ -35,6 +35,7 @@
 #include "FrameView.h"
 #include "Node.h"
 #include "RenderObject.h"
+#include "RenderLayer.h"
 #include "ScrollBar.h"
 #include "TextAffinity.h"
 #include "TextGranularity.h"
@@ -677,10 +678,8 @@ private:
 
   RenderStyle* styleForSelectionStart(Node* &nodeToRemove) const;
 
-  // Scrolls as necessary to reveal the selection
-  void revealSelection();
-  // Centers the selection regardless of whether it was already visible
-  void centerSelectionInVisibleArea() const;
+  void revealSelection(const RenderLayer::ScrollAlignment& alignment = RenderLayer::gAlignCenterIfNeeded) const;
+  void revealCaret(const RenderLayer::ScrollAlignment& alignment = RenderLayer::gAlignCenterIfNeeded) const;
   void setSelectionFromNone();
 
   bool scrollOverflow(ScrollDirection direction, ScrollGranularity granularity);
index 12d971e8a141b0db039ebf3a96021da133347d9b..64c87ff188454750ff4305b0b424667702021c3d 100644 (file)
@@ -1,3 +1,54 @@
+2006-09-15  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Justin.
+
+        Call the bridge directly for alter selection calls. All of this logic is now
+        in WebCore's SelectionController.
+
+        * WebView/WebHTMLView.m:
+        (-[NSArray moveBackward:]):
+        (-[NSArray moveBackwardAndModifySelection:]):
+        (-[NSArray moveDown:]):
+        (-[NSArray moveDownAndModifySelection:]):
+        (-[NSArray moveForward:]):
+        (-[NSArray moveForwardAndModifySelection:]):
+        (-[NSArray moveLeft:]):
+        (-[NSArray moveLeftAndModifySelection:]):
+        (-[NSArray moveRight:]):
+        (-[NSArray moveRightAndModifySelection:]):
+        (-[NSArray moveToBeginningOfDocument:]):
+        (-[NSArray moveToBeginningOfDocumentAndModifySelection:]):
+        (-[NSArray moveToBeginningOfSentence:]):
+        (-[NSArray moveToBeginningOfSentenceAndModifySelection:]):
+        (-[NSArray moveToBeginningOfLine:]):
+        (-[NSArray moveToBeginningOfLineAndModifySelection:]):
+        (-[NSArray moveToBeginningOfParagraph:]):
+        (-[NSArray moveToBeginningOfParagraphAndModifySelection:]):
+        (-[NSArray moveToEndOfDocument:]):
+        (-[NSArray moveToEndOfDocumentAndModifySelection:]):
+        (-[NSArray moveToEndOfSentence:]):
+        (-[NSArray moveToEndOfSentenceAndModifySelection:]):
+        (-[NSArray moveToEndOfLine:]):
+        (-[NSArray moveToEndOfLineAndModifySelection:]):
+        (-[NSArray moveToEndOfParagraph:]):
+        (-[NSArray moveToEndOfParagraphAndModifySelection:]):
+        (-[NSArray moveParagraphBackwardAndModifySelection:]):
+        (-[NSArray moveParagraphForwardAndModifySelection:]):
+        (-[NSArray moveUp:]):
+        (-[NSArray moveUpAndModifySelection:]):
+        (-[NSArray moveWordBackward:]):
+        (-[NSArray moveWordBackwardAndModifySelection:]):
+        (-[NSArray moveWordForward:]):
+        (-[NSArray moveWordForwardAndModifySelection:]):
+        (-[NSArray moveWordLeft:]):
+        (-[NSArray moveWordLeftAndModifySelection:]):
+        (-[NSArray moveWordRight:]):
+        (-[NSArray moveWordRightAndModifySelection:]):
+        (-[NSArray pageUp:]):
+        (-[NSArray pageDown:]):
+        (-[NSArray pageUpAndModifySelection:]):
+        (-[NSArray pageDownAndModifySelection:]):
+
 2006-09-15  Adam Roben  <aroben@apple.com>
 
         Reviewed by eseidel.
index 5ada32bd4295b5f135442b909b3f67a89d6bec53..c355207109b376b5450943880a50e5f4c2889754 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C283208902B0F008A9EFC /* Build configuration list for PBXProject "WebKit" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
                        projectRoot = "";
+                       shouldCheckCompatibility = 1;
                        targets = (
                                9398100A0824BF01008DF038 /* WebKit */,
                        );
index 58c3f108241596fecdeb3bcf2e6bfdea22eb5d7f..d10ff42da9f401adcc220f22d2a82f9dd0bd62e1 100644 (file)
@@ -3383,244 +3383,259 @@ done:
     [[self _bridge] centerSelectionInVisibleArea];
 }
 
-- (void)_alterCurrentSelection:(WebSelectionAlteration)alteration direction:(WebBridgeSelectionDirection)direction granularity:(WebBridgeSelectionGranularity)granularity
-{
-    if (![self _canAlterCurrentSelection])
-        return;
-        
-    WebFrameBridge *bridge = [self _bridge];
-    DOMRange *proposedRange = [bridge rangeByAlteringCurrentSelection:alteration direction:direction granularity:granularity];
-    WebView *webView = [self _webView];
-    if ([[webView _editingDelegateForwarder] webView:webView shouldChangeSelectedDOMRange:[self _selectedRange] toDOMRange:proposedRange affinity:[bridge selectionAffinity] stillSelecting:NO]) {
-        [bridge alterCurrentSelection:alteration direction:direction granularity:granularity];
-    }
-}
-
-- (void)_alterCurrentSelection:(WebSelectionAlteration)alteration verticalDistance:(float)verticalDistance
-{
-    if (![self _canAlterCurrentSelection])
-        return;
-        
-    WebFrameBridge *bridge = [self _bridge];
-    DOMRange *proposedRange = [bridge rangeByAlteringCurrentSelection:alteration verticalDistance:verticalDistance];
-    WebView *webView = [self _webView];
-    if ([[webView _editingDelegateForwarder] webView:webView shouldChangeSelectedDOMRange:[self _selectedRange] toDOMRange:proposedRange affinity:[bridge selectionAffinity] stillSelecting:NO]) {
-        [bridge alterCurrentSelection:alteration verticalDistance:verticalDistance];
-    }
-}
-
 - (void)moveBackward:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectByCharacter];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectByCharacter];
 }
 
 - (void)moveBackwardAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectByCharacter];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectByCharacter];
 }
 
 - (void)moveDown:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectByLine];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectByLine];
 }
 
 - (void)moveDownAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectByLine];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectByLine];
 }
 
 - (void)moveForward:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectByCharacter];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectByCharacter];
 }
 
 - (void)moveForwardAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectByCharacter];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectByCharacter];
 }
 
 - (void)moveLeft:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectLeft granularity:WebBridgeSelectByCharacter];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectLeft granularity:WebBridgeSelectByCharacter];
 }
 
 - (void)moveLeftAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectLeft granularity:WebBridgeSelectByCharacter];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectLeft granularity:WebBridgeSelectByCharacter];
 }
 
 - (void)moveRight:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectRight granularity:WebBridgeSelectByCharacter];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectRight granularity:WebBridgeSelectByCharacter];
 }
 
 - (void)moveRightAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectRight granularity:WebBridgeSelectByCharacter];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectRight granularity:WebBridgeSelectByCharacter];
 }
 
 - (void)moveToBeginningOfDocument:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectToDocumentBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectToDocumentBoundary];
 }
 
 - (void)moveToBeginningOfDocumentAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectToDocumentBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectToDocumentBoundary];
 }
 
 - (void)moveToBeginningOfSentence:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectToSentenceBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectToSentenceBoundary];
 }
 
 - (void)moveToBeginningOfSentenceAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectToSentenceBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectToSentenceBoundary];
 }
 
 - (void)moveToBeginningOfLine:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectToLineBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectToLineBoundary];
 }
 
 - (void)moveToBeginningOfLineAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectToLineBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectToLineBoundary];
 }
 
 - (void)moveToBeginningOfParagraph:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectToParagraphBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectToParagraphBoundary];
 }
 
 - (void)moveToBeginningOfParagraphAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectToParagraphBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectToParagraphBoundary];
 }
 
 - (void)moveToEndOfDocument:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectToDocumentBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectToDocumentBoundary];
 }
 
 - (void)moveToEndOfDocumentAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectToDocumentBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectToDocumentBoundary];
 }
 
 - (void)moveToEndOfSentence:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectToSentenceBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectToSentenceBoundary];
 }
 
 - (void)moveToEndOfSentenceAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectToSentenceBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectToSentenceBoundary];
 }
 
 - (void)moveToEndOfLine:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectToLineBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectToLineBoundary];
 }
 
 - (void)moveToEndOfLineAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectToLineBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectToLineBoundary];
 }
 
 - (void)moveToEndOfParagraph:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectToParagraphBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectToParagraphBoundary];
 }
 
 - (void)moveToEndOfParagraphAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectToParagraphBoundary];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectToParagraphBoundary];
 }
 
 - (void)moveParagraphBackwardAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectByParagraph];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectByParagraph];
 }
 
 - (void)moveParagraphForwardAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectByParagraph];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectByParagraph];
 }
 
 - (void)moveUp:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectByLine];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectByLine];
 }
 
 - (void)moveUpAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectByLine];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectByLine];
 }
 
 - (void)moveWordBackward:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectByWord];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectBackward granularity:WebBridgeSelectByWord];
 }
 
 - (void)moveWordBackwardAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectByWord];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectBackward granularity:WebBridgeSelectByWord];
 }
 
 - (void)moveWordForward:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectByWord];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectForward granularity:WebBridgeSelectByWord];
 }
 
 - (void)moveWordForwardAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectByWord];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectForward granularity:WebBridgeSelectByWord];
 }
 
 - (void)moveWordLeft:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectLeft granularity:WebBridgeSelectByWord];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectLeft granularity:WebBridgeSelectByWord];
 }
 
 - (void)moveWordLeftAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectLeft granularity:WebBridgeSelectByWord];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectLeft granularity:WebBridgeSelectByWord];
 }
 
 - (void)moveWordRight:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectRight granularity:WebBridgeSelectByWord];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving direction:WebBridgeSelectRight granularity:WebBridgeSelectByWord];
 }
 
 - (void)moveWordRightAndModifySelection:(id)sender
 {
-    [self _alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectRight granularity:WebBridgeSelectByWord];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending direction:WebBridgeSelectRight granularity:WebBridgeSelectByWord];
 }
 
 - (void)pageUp:(id)sender
 {
     WebFrameView *frameView = [self _frameView];
-    if (frameView == nil)
+    if (!frameView)
         return;
-    [self _alterCurrentSelection:WebSelectByMoving verticalDistance:-[frameView _verticalPageScrollDistance]];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving verticalDistance:-[frameView _verticalPageScrollDistance]];
 }
 
 - (void)pageDown:(id)sender
 {
     WebFrameView *frameView = [self _frameView];
-    if (frameView == nil)
+    if (!frameView)
         return;
-    [self _alterCurrentSelection:WebSelectByMoving verticalDistance:[frameView _verticalPageScrollDistance]];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByMoving verticalDistance:[frameView _verticalPageScrollDistance]];
 }
 
 - (void)pageUpAndModifySelection:(id)sender
 {
     WebFrameView *frameView = [self _frameView];
-    if (frameView == nil)
+    if (!frameView)
         return;
-    [self _alterCurrentSelection:WebSelectByExtending verticalDistance:-[frameView _verticalPageScrollDistance]];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending verticalDistance:-[frameView _verticalPageScrollDistance]];
 }
 
 - (void)pageDownAndModifySelection:(id)sender
@@ -3628,7 +3643,8 @@ done:
     WebFrameView *frameView = [self _frameView];
     if (frameView == nil)
         return;
-    [self _alterCurrentSelection:WebSelectByExtending verticalDistance:[frameView _verticalPageScrollDistance]];
+    if ([self _canAlterCurrentSelection])
+        [[self _bridge] alterCurrentSelection:WebSelectByExtending verticalDistance:[frameView _verticalPageScrollDistance]];
 }
 
 - (void)_expandSelectionToGranularity:(WebBridgeSelectionGranularity)granularity