+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
- (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;
- (void)applyEditingStyleToElement:(DOMElement *)element;
- (void)removeEditingStyleFromElement:(DOMElement *)element;
-- (void)ensureSelectionVisible;
-
- (WebScriptObject *)windowScriptObject;
- (NPObject *)windowScriptNPObject;
- (void)centerSelectionInVisibleArea
{
- m_frame->centerSelectionInVisibleArea();
+ m_frame->revealSelection(RenderLayer::gAlignCenterAlways);
}
- (NSRect)caretRectAtNode:(DOMNode *)node offset:(int)offset affinity:(NSSelectionAffinity)affinity
{
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));
{
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());
{
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
if ([text length] > 0)
TypingCommand::insertText(m_frame->document(), text, YES);
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
- (BOOL)canDeleteRange:(DOMRange *)range
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
return nil;
Node* newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevel(m_frame->document());
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
return [DOMNode _nodeWith:newList];
}
return nil;
Node* newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevelOrdered(m_frame->document());
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
return [DOMNode _nodeWith:newList];
}
return nil;
Node* newList = IncreaseSelectionListLevelCommand::increaseSelectionListLevelUnordered(m_frame->document());
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
return [DOMNode _nodeWith:newList];
}
return;
DecreaseSelectionListLevelCommand::decreaseSelectionListLevel(m_frame->document());
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
- (void)insertLineBreak
return;
TypingCommand::insertLineBreak(m_frame->document());
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
- (void)insertParagraphSeparator
return;
TypingCommand::insertParagraphSeparator(m_frame->document());
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
- (void)insertParagraphSeparatorInQuotedContent
return;
TypingCommand::insertParagraphSeparatorInQuotedContent(m_frame->document());
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
- (void)insertText:(NSString *)text selectInsertedText:(BOOL)selectInsertedText
return;
TypingCommand::insertText(m_frame->document(), text, selectInsertedText);
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
- (void)setSelectionToDragCaret
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
return;
TypingCommand::forwardDeleteKeyPressed(m_frame->document(), smartDelete, static_cast<TextGranularity>(granularity));
- [self ensureSelectionVisible];
+ m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
}
- (DOMCSSStyleDeclaration *)typingStyle
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;
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);
}
{
}
-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();
// 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)
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;
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);
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;
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;
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;
}
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)
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(); }
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,
}
// FIXME: should this go in SelectionController?
-void Frame::revealSelection()
+void Frame::revealSelection(const RenderLayer::ScrollAlignment& alignment) const
{
IntRect rect;
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)
{
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;
#include "FrameView.h"
#include "Node.h"
#include "RenderObject.h"
+#include "RenderLayer.h"
#include "ScrollBar.h"
#include "TextAffinity.h"
#include "TextGranularity.h"
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);
+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.
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 */,
);
[[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
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