Commit b17ec2f7 authored by darin@apple.com's avatar darin@apple.com

2010-09-09 Darin Adler <darin@apple.com>

        Reviewed by Adam Barth.

        Move functions from Frame to SelectionController as planned
        https://bugs.webkit.org/show_bug.cgi?id=45508

        * src/WebFrameImpl.cpp:
        (WebKit::WebFrameImpl::selectionBoundsRect):
        Call functions on selection().
2010-09-09  Darin Adler  <darin@apple.com>

        Reviewed by Adam Barth.

        Move functions from Frame to SelectionController as planned
        https://bugs.webkit.org/show_bug.cgi?id=45508

        * WebView.cpp:
        (WebView::selectionRect):
        (WebView::centerSelectionInVisibleArea):
        Call functions on selection().
2010-09-09  Darin Adler  <darin@apple.com>

        Reviewed by Adam Barth.

        Move functions from Frame to SelectionController as planned
        https://bugs.webkit.org/show_bug.cgi?id=45508

        * WebView/WebFrame.mm:
        (-[WebFrame _selectionGranularity]):
        (-[WebFrame _insertParagraphSeparatorInQuotedContent]):
        (-[WebFrame _typingStyle]):
        (-[WebFrame _replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:]):
        * WebView/WebHTMLRepresentation.mm:
        (-[WebHTMLRepresentation currentForm]):
        * WebView/WebHTMLView.mm:
        (-[WebHTMLView jumpToSelection:]):
        (-[WebHTMLView centerSelectionInVisibleArea:]):
        (-[WebHTMLView _canSmartCopyOrDelete]):
        (-[WebHTMLView _lookUpInDictionaryFromMenu:]):
        (-[WebHTMLView selectionRect]):
        (-[WebHTMLView selectionTextRects]):
        (-[WebHTMLView selectionImageRect]):
        * WebView/WebView.mm:
        (-[WebView setEditable:]):
        Call functions on selection().
2010-09-09  Darin Adler  <darin@apple.com>

        Reviewed by Adam Barth.

        Move functions from Frame to SelectionController as planned
        https://bugs.webkit.org/show_bug.cgi?id=45508

        Also removed Frame::dragCaretController since it just called Page::dragCaretController.

        * editing/SelectionController.cpp:
        (WebCore::SelectionController::setSelection):
        (WebCore::SelectionController::modify):
        (WebCore::SelectionController::selectFrameElementInParentIfFullySelected):
        (WebCore::SelectionController::selectAll):
        (WebCore::SelectionController::focusedOrActiveStateChanged):
        (WebCore::SelectionController::notifyRendererOfSelectionChange):
        (WebCore::isFrameElement):
        (WebCore::SelectionController::setFocusedNodeIfNeeded):
        (WebCore::SelectionController::paintDragCaret):
        (WebCore::SelectionController::shouldDeleteSelection):
        (WebCore::SelectionController::selectionBounds):
        (WebCore::SelectionController::selectionTextRects):
        (WebCore::scanForForm):
        (WebCore::SelectionController::currentForm):
        (WebCore::SelectionController::revealSelection):
        (WebCore::SelectionController::setSelectionFromNone):
        (WebCore::SelectionController::shouldChangeSelection):
        * editing/SelectionController.h:
        Moved functions here from Frame.

        * page/Frame.cpp:
        * page/Frame.h:
        Moved functions to SelectionController.
        Reorganized header to be easier to read and a bit more logical.

        * WebCore.exp.in: Updated.

        * dom/Document.cpp:
        (WebCore::Document::nodeChildrenWillBeRemoved):
        (WebCore::Document::nodeWillBeRemoved):
        Call Page::dragCaretController directly.

        * dom/Element.cpp:
        (WebCore::Element::updateFocusAppearance):
        * dom/InputElement.cpp:
        (WebCore::InputElement::updateFocusAppearance):
        * editing/ApplyStyleCommand.cpp:
        (WebCore::ApplyStyleCommand::editingStyleAtPosition):
        * editing/DeleteSelectionCommand.cpp:
        (WebCore::DeleteSelectionCommand::calculateTypingStyleAfterDelete):
        * editing/Editor.cpp:
        (WebCore::Editor::canSmartCopyOrDelete):
        (WebCore::Editor::textDirectionForSelection):
        (WebCore::Editor::appliedEditing):
        (WebCore::Editor::insertTextWithoutSendingTextEvent):
        (WebCore::Editor::advanceToNextMisspelling):
        (WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
        (WebCore::Editor::revealSelectionAfterEditingOperation):
        (WebCore::Editor::transpose):
        (WebCore::Editor::changeSelectionAfterCommand):
        (WebCore::Editor::computeAndSetTypingStyle):
        (WebCore::Editor::selectionComputedStyle):
        (WebCore::Editor::styleForSelectionStart):
        (WebCore::Editor::findString):
        * editing/EditorCommand.cpp:
        (WebCore::executeDelete):
        * editing/InsertLineBreakCommand.cpp:
        (WebCore::InsertLineBreakCommand::doApply):
        * editing/InsertTextCommand.cpp:
        (WebCore::InsertTextCommand::input):
        * editing/RemoveFormatCommand.cpp:
        (WebCore::RemoveFormatCommand::doApply):
        * editing/ReplaceSelectionCommand.cpp:
        (WebCore::ReplaceSelectionCommand::doApply):
        * editing/TypingCommand.cpp:
        (WebCore::TypingCommand::insertTextRunWithoutNewlines):
        (WebCore::TypingCommand::deleteKeyPressed):
        (WebCore::TypingCommand::forwardDeleteKeyPressed):
        * html/HTMLTextAreaElement.cpp:
        (WebCore::HTMLTextAreaElement::updateFocusAppearance):
        * page/ContextMenuController.cpp:
        (WebCore::ContextMenuController::contextMenuItemSelected):
        * page/DragController.cpp:
        (WebCore::DragController::concludeEditDrag):
        (WebCore::dragLocForSelectionDrag):
        * page/EventHandler.cpp:
        (WebCore::EventHandler::selectClosestWordFromMouseEvent):
        (WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent):
        (WebCore::EventHandler::handleMousePressEventTripleClick):
        (WebCore::EventHandler::handleMousePressEventSingleClick):
        (WebCore::EventHandler::updateSelectionForMouseDrag):
        (WebCore::EventHandler::handleMouseReleaseEvent):
        * page/FocusController.cpp:
        (WebCore::FocusController::advanceFocusInDocumentOrder):
        * page/chromium/EventHandlerChromium.cpp:
        (WebCore::EventHandler::passMousePressEventToSubframe):
        * page/chromium/FrameChromium.cpp:
        (WebCore::Frame::dragImageForSelection):
        * page/mac/FrameMac.mm:
        (WebCore::Frame::selectionImage):
        * platform/mac/ClipboardMac.mm:
        (WebCore::ClipboardMac::writeRange):
        * rendering/RenderBlock.cpp:
        (WebCore::RenderBlock::paintCaret):
        Call functions on selection().


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@67238 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c38d6941
2010-09-09 Darin Adler <darin@apple.com>
Reviewed by Adam Barth.
Move functions from Frame to SelectionController as planned
https://bugs.webkit.org/show_bug.cgi?id=45508
Also removed Frame::dragCaretController since it just called Page::dragCaretController.
* editing/SelectionController.cpp:
(WebCore::SelectionController::setSelection):
(WebCore::SelectionController::modify):
(WebCore::SelectionController::selectFrameElementInParentIfFullySelected):
(WebCore::SelectionController::selectAll):
(WebCore::SelectionController::focusedOrActiveStateChanged):
(WebCore::SelectionController::notifyRendererOfSelectionChange):
(WebCore::isFrameElement):
(WebCore::SelectionController::setFocusedNodeIfNeeded):
(WebCore::SelectionController::paintDragCaret):
(WebCore::SelectionController::shouldDeleteSelection):
(WebCore::SelectionController::selectionBounds):
(WebCore::SelectionController::selectionTextRects):
(WebCore::scanForForm):
(WebCore::SelectionController::currentForm):
(WebCore::SelectionController::revealSelection):
(WebCore::SelectionController::setSelectionFromNone):
(WebCore::SelectionController::shouldChangeSelection):
* editing/SelectionController.h:
Moved functions here from Frame.
* page/Frame.cpp:
* page/Frame.h:
Moved functions to SelectionController.
Reorganized header to be easier to read and a bit more logical.
* WebCore.exp.in: Updated.
* dom/Document.cpp:
(WebCore::Document::nodeChildrenWillBeRemoved):
(WebCore::Document::nodeWillBeRemoved):
Call Page::dragCaretController directly.
* dom/Element.cpp:
(WebCore::Element::updateFocusAppearance):
* dom/InputElement.cpp:
(WebCore::InputElement::updateFocusAppearance):
* editing/ApplyStyleCommand.cpp:
(WebCore::ApplyStyleCommand::editingStyleAtPosition):
* editing/DeleteSelectionCommand.cpp:
(WebCore::DeleteSelectionCommand::calculateTypingStyleAfterDelete):
* editing/Editor.cpp:
(WebCore::Editor::canSmartCopyOrDelete):
(WebCore::Editor::textDirectionForSelection):
(WebCore::Editor::appliedEditing):
(WebCore::Editor::insertTextWithoutSendingTextEvent):
(WebCore::Editor::advanceToNextMisspelling):
(WebCore::Editor::markAllMisspellingsAndBadGrammarInRanges):
(WebCore::Editor::revealSelectionAfterEditingOperation):
(WebCore::Editor::transpose):
(WebCore::Editor::changeSelectionAfterCommand):
(WebCore::Editor::computeAndSetTypingStyle):
(WebCore::Editor::selectionComputedStyle):
(WebCore::Editor::styleForSelectionStart):
(WebCore::Editor::findString):
* editing/EditorCommand.cpp:
(WebCore::executeDelete):
* editing/InsertLineBreakCommand.cpp:
(WebCore::InsertLineBreakCommand::doApply):
* editing/InsertTextCommand.cpp:
(WebCore::InsertTextCommand::input):
* editing/RemoveFormatCommand.cpp:
(WebCore::RemoveFormatCommand::doApply):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::doApply):
* editing/TypingCommand.cpp:
(WebCore::TypingCommand::insertTextRunWithoutNewlines):
(WebCore::TypingCommand::deleteKeyPressed):
(WebCore::TypingCommand::forwardDeleteKeyPressed):
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::updateFocusAppearance):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
* page/DragController.cpp:
(WebCore::DragController::concludeEditDrag):
(WebCore::dragLocForSelectionDrag):
* page/EventHandler.cpp:
(WebCore::EventHandler::selectClosestWordFromMouseEvent):
(WebCore::EventHandler::selectClosestWordOrLinkFromMouseEvent):
(WebCore::EventHandler::handleMousePressEventTripleClick):
(WebCore::EventHandler::handleMousePressEventSingleClick):
(WebCore::EventHandler::updateSelectionForMouseDrag):
(WebCore::EventHandler::handleMouseReleaseEvent):
* page/FocusController.cpp:
(WebCore::FocusController::advanceFocusInDocumentOrder):
* page/chromium/EventHandlerChromium.cpp:
(WebCore::EventHandler::passMousePressEventToSubframe):
* page/chromium/FrameChromium.cpp:
(WebCore::Frame::dragImageForSelection):
* page/mac/FrameMac.mm:
(WebCore::Frame::selectionImage):
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::writeRange):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::paintCaret):
Call functions on selection().
2010-09-10 Justin Schuh <jschuh@chromium.org>
Reviewed by Darin Adler.
......@@ -341,7 +341,6 @@ __ZN7WebCore15DatabaseTracker9setClientEPNS_21DatabaseTrackerClientE
__ZN7WebCore15FocusController10setFocusedEb
__ZN7WebCore15FocusController15setFocusedFrameEN3WTF10PassRefPtrINS_5FrameEEE
__ZN7WebCore15FocusController15setInitialFocusENS_14FocusDirectionEPNS_13KeyboardEventE
__ZNK7WebCore15FocusController18focusedOrMainFrameEv
__ZN7WebCore15FocusController9setActiveEb
__ZN7WebCore15GraphicsContext12setFillColorERKNS_5ColorENS_10ColorSpaceE
__ZN7WebCore15GraphicsContext4clipERKNS_9FloatRectE
......@@ -423,7 +422,9 @@ __ZN7WebCore19ResourceRequestBase19addHTTPHeaderFieldsERKNS_13HTTPHeaderMapE
__ZN7WebCore19ResourceRequestBase6setURLERKNS_4KURLE
__ZN7WebCore19SelectionController10setFocusedEb
__ZN7WebCore19SelectionController12setSelectionERKNS_16VisibleSelectionEbbbNS0_19CursorAlignOnScrollENS_15TextGranularityENS_20DirectionalityPolicyE
__ZN7WebCore19SelectionController15revealSelectionERKNS_15ScrollAlignmentEb
__ZN7WebCore19SelectionController16setSelectedRangeEPNS_5RangeENS_9EAffinityEb
__ZN7WebCore19SelectionController20setSelectionFromNoneEv
__ZN7WebCore19SelectionController5clearEv
__ZN7WebCore19SelectionController6modifyENS0_11EAlterationENS0_10EDirectionENS_15TextGranularityEb
__ZN7WebCore19SelectionController9selectAllEv
......@@ -580,8 +581,6 @@ __ZN7WebCore5Cache13getStatisticsEv
__ZN7WebCore5Cache13setCapacitiesEjjj
__ZN7WebCore5Frame10createViewERKNS_7IntSizeERKNS_5ColorEbS3_bNS_13ScrollbarModeEbS7_b
__ZN7WebCore5Frame14frameForWidgetEPKNS_6WidgetE
__ZN7WebCore5Frame15revealSelectionERKNS_15ScrollAlignmentEb
__ZN7WebCore5Frame20setSelectionFromNoneEv
__ZN7WebCore5Frame23visiblePositionForPointERKNS_8IntPointE
__ZN7WebCore5Frame25matchLabelsAgainstElementEP7NSArrayPNS_7ElementE
__ZN7WebCore5Frame28searchForLabelsBeforeElementEP7NSArrayPNS_7ElementEPmPb
......@@ -934,6 +933,7 @@ __ZNK7WebCore14RenderListItem10markerTextEv
__ZNK7WebCore14ResourceHandle10connectionEv
__ZNK7WebCore14ResourceLoader11frameLoaderEv
__ZNK7WebCore14SecurityOrigin5equalEPKS0_
__ZNK7WebCore15FocusController18focusedOrMainFrameEv
__ZNK7WebCore15GraphicsContext15platformContextEv
__ZNK7WebCore15GraphicsContext16paintingDisabledEv
__ZNK7WebCore15ProgressTracker17estimatedProgressEv
......@@ -956,8 +956,11 @@ __ZNK7WebCore19AnimationController24numberOfActiveAnimationsEv
__ZNK7WebCore19ResourceRequestBase10httpMethodEv
__ZNK7WebCore19ResourceRequestBase3urlEv
__ZNK7WebCore19ResourceRequestBase7isEmptyEv
__ZNK7WebCore19SelectionController11currentFormEv
__ZNK7WebCore19SelectionController17isInPasswordFieldEv
__ZNK7WebCore19SelectionController18isFocusedAndActiveEv
__ZNK7WebCore19SelectionController31getClippedVisibleTextRectanglesERN3WTF6VectorINS_9FloatRectELm0EEE
__ZNK7WebCore19SelectionController6boundsEb
__ZNK7WebCore20ResourceResponseBase14httpStatusCodeEv
__ZNK7WebCore20ResourceResponseBase14httpStatusTextEv
__ZNK7WebCore20ResourceResponseBase15httpHeaderFieldEPKc
......@@ -988,15 +991,11 @@ __ZNK7WebCore4Page10pluginDataEv
__ZNK7WebCore4Page15backForwardListEv
__ZNK7WebCore4Page34inLowQualityImageInterpolationModeEv
__ZNK7WebCore4Page9groupNameEv
__ZNK7WebCore5Frame11currentFormEv
__ZNK7WebCore5Frame13ownerRendererEv
__ZNK7WebCore5Frame14selectionImageEb
__ZNK7WebCore5Frame15contentRendererEv
__ZNK7WebCore5Frame15layerTreeAsTextEv
__ZNK7WebCore5Frame15selectionBoundsEb
__ZNK7WebCore5Frame18documentTypeStringEv
__ZNK7WebCore5Frame18selectionTextRectsERN3WTF6VectorINS_9FloatRectELm0EEENS0_30SelectionRectRespectTransformsEb
__ZNK7WebCore5Frame20selectionGranularityEv
__ZNK7WebCore5Frame8settingsEv
__ZNK7WebCore5Frame9domWindowEv
__ZNK7WebCore5Range11startOffsetERi
......
......@@ -3262,7 +3262,7 @@ void Document::nodeChildrenWillBeRemoved(ContainerNode* container)
if (Frame* frame = this->frame()) {
for (Node* n = container->firstChild(); n; n = n->nextSibling()) {
frame->selection()->nodeWillBeRemoved(n);
frame->dragCaretController()->nodeWillBeRemoved(n);
frame->page()->dragCaretController()->nodeWillBeRemoved(n);
}
}
}
......@@ -3281,7 +3281,7 @@ void Document::nodeWillBeRemoved(Node* n)
if (Frame* frame = this->frame()) {
frame->selection()->nodeWillBeRemoved(n);
frame->dragCaretController()->nodeWillBeRemoved(n);
frame->page()->dragCaretController()->nodeWillBeRemoved(n);
}
#if ENABLE(FULLSCREEN_API)
......
......@@ -1347,9 +1347,9 @@ void Element::updateFocusAppearance(bool /*restorePreviousSelection*/)
// FIXME: We should restore the previous selection if there is one.
VisibleSelection newSelection = VisibleSelection(Position(this, 0), DOWNSTREAM);
if (frame->shouldChangeSelection(newSelection)) {
if (frame->selection()->shouldChangeSelection(newSelection)) {
frame->selection()->setSelection(newSelection);
frame->revealSelection();
frame->selection()->revealSelection();
}
} else if (renderer() && !renderer()->isWidget())
renderer()->enclosingLayer()->scrollRectToVisible(getRect());
......
......@@ -99,7 +99,7 @@ void InputElement::updateFocusAppearance(InputElementData& data, InputElement* i
Document* document = element->document();
if (document && document->frame())
document->frame()->revealSelection();
document->frame()->selection()->revealSelection();
}
void InputElement::updateSelectionRange(InputElement* inputElement, Element* element, int start, int end)
......
......@@ -464,7 +464,7 @@ PassRefPtr<CSSMutableStyleDeclaration> ApplyStyleCommand::editingStyleAtPosition
}
if (shouldIncludeTypingStyle == IncludeTypingStyle) {
CSSMutableStyleDeclaration* typingStyle = pos.node()->document()->frame()->typingStyle();
CSSMutableStyleDeclaration* typingStyle = pos.node()->document()->frame()->selection()->typingStyle();
if (typingStyle)
style->merge(typingStyle);
}
......
......@@ -714,7 +714,7 @@ void DeleteSelectionCommand::calculateTypingStyleAfterDelete()
// In this case if we start typing, the new characters should have the same style as the just deleted ones,
// but, if we change the selection, come back and start typing that style should be lost. Also see
// preserveTypingStyle() below.
document()->frame()->setTypingStyle(m_typingStyle.get());
document()->frame()->selection()->setTypingStyle(m_typingStyle);
}
void DeleteSelectionCommand::clearTransientState()
......
......@@ -257,7 +257,7 @@ bool Editor::smartInsertDeleteEnabled()
bool Editor::canSmartCopyOrDelete()
{
return client() && client()->smartInsertDeleteEnabled() && m_frame->selectionGranularity() == WordGranularity;
return client() && client()->smartInsertDeleteEnabled() && m_frame->selection()->granularity() == WordGranularity;
}
bool Editor::isSelectTrailingWhitespaceEnabled()
......@@ -551,7 +551,7 @@ WritingDirection Editor::textDirectionForSelection(bool& hasNestedOrMultipleEmbe
}
if (m_frame->selection()->isCaret()) {
if (CSSMutableStyleDeclaration* typingStyle = m_frame->typingStyle()) {
if (CSSMutableStyleDeclaration* typingStyle = m_frame->selection()->typingStyle()) {
RefPtr<CSSValue> unicodeBidi = typingStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
if (unicodeBidi) {
ASSERT(unicodeBidi->isPrimitiveValue());
......@@ -1011,7 +1011,7 @@ void Editor::appliedEditing(PassRefPtr<EditCommand> cmd)
changeSelectionAfterCommand(newSelection, false, false);
if (!cmd->preservesTypingStyle())
m_frame->setTypingStyle(0);
m_frame->selection()->clearTypingStyle();
// Command will be equal to last edit command only in the case of typing
if (m_lastEditCommand.get() == cmd)
......@@ -1116,7 +1116,7 @@ bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn
// Reveal the current selection
if (Frame* editedFrame = document->frame())
if (Page* page = editedFrame->page())
page->focusController()->focusedOrMainFrame()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
page->focusController()->focusedOrMainFrame()->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
}
}
......@@ -2132,7 +2132,7 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
// FIXME 4859190: This gets confused with doubled punctuation at the end of a paragraph
RefPtr<Range> badGrammarRange = TextIterator::subrange(grammarSearchRange.get(), grammarPhraseOffset + grammarDetail.location, grammarDetail.length);
frame()->selection()->setSelection(VisibleSelection(badGrammarRange.get(), SEL_DEFAULT_AFFINITY));
frame()->revealSelection();
frame()->selection()->revealSelection();
client()->updateSpellingUIWithGrammarString(badGrammarPhrase, grammarDetail);
frame()->document()->markers()->addMarker(badGrammarRange.get(), DocumentMarker::Grammar, grammarDetail.userDescription);
......@@ -2143,7 +2143,7 @@ void Editor::advanceToNextMisspelling(bool startBeforeSelection)
RefPtr<Range> misspellingRange = TextIterator::subrange(spellingSearchRange.get(), misspellingOffset, misspelledWord.length());
frame()->selection()->setSelection(VisibleSelection(misspellingRange.get(), DOWNSTREAM));
frame()->revealSelection();
frame()->selection()->revealSelection();
client()->updateSpellingUIWithMisspelledWord(misspelledWord);
frame()->document()->markers()->addMarker(misspellingRange.get(), DocumentMarker::Spelling);
......@@ -2435,7 +2435,7 @@ void Editor::markMisspellingsAfterTypingToPosition(const VisiblePosition &p)
if (!autocorrectedString.isEmpty()) {
VisibleSelection newSelection(misspellingRange.get(), DOWNSTREAM);
if (newSelection != frame()->selection()->selection()) {
if (!frame()->shouldChangeSelection(newSelection))
if (!frame()->selection()->shouldChangeSelection(newSelection))
return;
frame()->selection()->setSelection(newSelection);
}
......@@ -2709,7 +2709,7 @@ void Editor::markAllMisspellingsAndBadGrammarInRanges(TextCheckingOptions textCh
}
}
if (doReplacement && !shouldShowCorrectionPanel && selectionToReplace != m_frame->selection()->selection()) {
if (m_frame->shouldChangeSelection(selectionToReplace)) {
if (m_frame->selection()->shouldChangeSelection(selectionToReplace)) {
m_frame->selection()->setSelection(selectionToReplace);
selectionChanged = true;
} else {
......@@ -2875,7 +2875,7 @@ void Editor::revealSelectionAfterEditingOperation()
if (m_ignoreCompositionSelectionChange)
return;
m_frame->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
m_frame->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
}
void Editor::setIgnoreCompositionSelectionChange(bool ignore)
......@@ -2952,7 +2952,7 @@ void Editor::transpose()
// Select the two characters.
if (newSelection != m_frame->selection()->selection()) {
if (!m_frame->shouldChangeSelection(newSelection))
if (!m_frame->selection()->shouldChangeSelection(newSelection))
return;
m_frame->selection()->setSelection(newSelection);
}
......@@ -3125,7 +3125,7 @@ void Editor::changeSelectionAfterCommand(const VisibleSelection& newSelection, b
// The old selection can be invalid here and calling shouldChangeSelection can produce some strange calls.
// See <rdar://problem/5729315> Some shouldChangeSelectedDOMRange contain Ranges for selections that are no longer valid
bool selectionDidNotChangeDOMPosition = newSelection == m_frame->selection()->selection();
if (selectionDidNotChangeDOMPosition || m_frame->shouldChangeSelection(newSelection))
if (selectionDidNotChangeDOMPosition || m_frame->selection()->shouldChangeSelection(newSelection))
m_frame->selection()->setSelection(newSelection, closeTyping, clearTypingStyle);
// Some editing operations change the selection visually without affecting its position within the DOM.
......@@ -3196,18 +3196,18 @@ bool Editor::shouldChangeSelection(const VisibleSelection& oldSelection, const V
return client()->shouldChangeSelectedRange(oldSelection.toNormalizedRange().get(), newSelection.toNormalizedRange().get(), affinity, stillSelecting);
}
void Editor::computeAndSetTypingStyle(CSSStyleDeclaration *style, EditAction editingAction)
void Editor::computeAndSetTypingStyle(CSSStyleDeclaration* style, EditAction editingAction)
{
if (!style || !style->length()) {
m_frame->clearTypingStyle();
m_frame->selection()->clearTypingStyle();
return;
}
// Calculate the current typing style.
RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable();
if (m_frame->typingStyle()) {
m_frame->typingStyle()->merge(mutableStyle.get());
mutableStyle = m_frame->typingStyle();
if (m_frame->selection()->typingStyle()) {
m_frame->selection()->typingStyle()->merge(mutableStyle.get());
mutableStyle = m_frame->selection()->typingStyle();
}
RefPtr<CSSValue> unicodeBidi;
......@@ -3236,7 +3236,7 @@ void Editor::computeAndSetTypingStyle(CSSStyleDeclaration *style, EditAction edi
applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.get(), editingAction));
// Set the remaining style as the typing style.
m_frame->setTypingStyle(mutableStyle.get());
m_frame->selection()->setTypingStyle(mutableStyle.release());
}
PassRefPtr<CSSComputedStyleDeclaration> Editor::selectionComputedStyle(Node*& nodeToRemove) const
......@@ -3264,10 +3264,10 @@ PassRefPtr<CSSComputedStyleDeclaration> Editor::selectionComputedStyle(Node*& no
RefPtr<Element> styleElement = element;
ExceptionCode ec = 0;
if (m_frame->typingStyle()) {
if (m_frame->selection()->typingStyle()) {
styleElement = m_frame->document()->createElement(spanTag, false);
styleElement->setAttribute(styleAttr, m_frame->typingStyle()->cssText().impl(), ec);
styleElement->setAttribute(styleAttr, m_frame->selection()->typingStyle()->cssText(), ec);
ASSERT(!ec);
styleElement->appendChild(m_frame->document()->createEditingTextNode(""), ec);
......@@ -3368,13 +3368,13 @@ RenderStyle* Editor::styleForSelectionStart(Node *&nodeToRemove) const
if (!position.node())
return 0;
if (!m_frame->typingStyle())
if (!m_frame->selection()->typingStyle())
return position.node()->renderer()->style();
RefPtr<Element> styleElement = m_frame->document()->createElement(spanTag, false);
ExceptionCode ec = 0;
String styleText = m_frame->typingStyle()->cssText() + " display: inline";
String styleText = m_frame->selection()->typingStyle()->cssText() + " display: inline";
styleElement->setAttribute(styleAttr, styleText.impl(), ec);
ASSERT(!ec);
......@@ -3471,7 +3471,7 @@ bool Editor::findString(const String& target, bool forward, bool caseFlag, bool
return false;
m_frame->selection()->setSelection(VisibleSelection(resultRange.get(), DOWNSTREAM));
m_frame->revealSelection();
m_frame->selection()->revealSelection();
return true;
}
......
......@@ -322,7 +322,7 @@ static bool executeDelete(Frame* frame, Event*, EditorCommandSource source, cons
case CommandFromDOMWithUserInterface:
// If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
// Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox).
TypingCommand::deleteKeyPressed(frame->document(), frame->selectionGranularity() == WordGranularity);
TypingCommand::deleteKeyPressed(frame->document(), frame->selection()->granularity() == WordGranularity);
return true;
}
ASSERT_NOT_REACHED();
......
......@@ -165,7 +165,7 @@ void InsertLineBreakCommand::doApply()
// Handle the case where there is a typing style.
CSSMutableStyleDeclaration* typingStyle = document()->frame()->typingStyle();
CSSMutableStyleDeclaration* typingStyle = document()->frame()->selection()->typingStyle();
if (typingStyle && typingStyle->length() > 0) {
// Apply the typing style to the inserted line break, so that if the selection
......
......@@ -190,7 +190,7 @@ void InsertTextCommand::input(const String& text, bool selectInsertedText)
setEndingSelection(forcedEndingSelection);
// Handle the case where there is a typing style.
CSSMutableStyleDeclaration* typingStyle = document()->frame()->typingStyle();
CSSMutableStyleDeclaration* typingStyle = document()->frame()->selection()->typingStyle();
RefPtr<CSSComputedStyleDeclaration> endingStyle = endPosition.computedStyle();
RefPtr<CSSValue> unicodeBidi;
RefPtr<CSSValue> direction;
......
......@@ -78,7 +78,7 @@ void RemoveFormatCommand::doApply()
// Insert the content with the default style.
// See <rdar://problem/5794382> RemoveFormat doesn't always reset text alignment
frame->setTypingStyle(defaultStyle.get());
frame->selection()->setTypingStyle(defaultStyle.release());
inputText(string, true);
}
......
......@@ -898,7 +898,7 @@ void ReplaceSelectionCommand::doApply()
// FIXME: Can this wait until after the operation has been performed? There doesn't seem to be
// any work performed after this that queries or uses the typing style.
if (Frame* frame = document()->frame())
frame->clearTypingStyle();
frame->selection()->clearTypingStyle();
bool handledStyleSpans = handleStyleSpansBeforeInsertion(fragment, insertionPos);
......
......@@ -29,6 +29,7 @@
#include "DeleteSelectionCommand.h"
#include "Document.h"
#include "Editor.h"
#include "EditorClient.h"
#include "Element.h"
#include "EventHandler.h"
#include "ExceptionCode.h"
......@@ -38,7 +39,8 @@
#include "FrameTree.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLFormElement.h"
#include "HTMLFrameElementBase.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "HitTestRequest.h"
......@@ -46,8 +48,10 @@
#include "Page.h"
#include "Range.h"
#include "RenderLayer.h"
#include "RenderTextControl.h"
#include "RenderTheme.h"
#include "RenderView.h"
#include "RenderWidget.h"
#include "SecureTextInput.h"
#include "Settings.h"
#include "TextIterator.h"
......@@ -107,7 +111,7 @@ void SelectionController::moveTo(const Position &base, const Position &extent, E
setSelection(VisibleSelection(base, extent, affinity), true, true, userTriggered);
}
void SelectionController::setSelection(const VisibleSelection& s, bool closeTyping, bool clearTypingStyle, bool userTriggered, CursorAlignOnScroll align, TextGranularity granularity, DirectionalityPolicy directionalityPolicy)
void SelectionController::setSelection(const VisibleSelection& s, bool closeTyping, bool shouldClearTypingStyle, bool userTriggered, CursorAlignOnScroll align, TextGranularity granularity, DirectionalityPolicy directionalityPolicy)
{
m_granularity = granularity;
......@@ -134,15 +138,15 @@ void SelectionController::setSelection(const VisibleSelection& s, bool closeTypi
// <http://bugs.webkit.org/show_bug.cgi?id=23464>: Infinite recursion at SelectionController::setSelection
// if document->frame() == m_frame we can get into an infinite loop
if (document && document->frame() && document->frame() != m_frame && document != m_frame->document()) {
document->frame()->selection()->setSelection(s, closeTyping, clearTypingStyle, userTriggered);
document->frame()->selection()->setSelection(s, closeTyping, shouldClearTypingStyle, userTriggered);
return;
}
if (closeTyping)
TypingCommand::closeTyping(m_frame->editor()->lastEditCommand());
if (clearTypingStyle)
m_frame->clearTypingStyle();
if (shouldClearTypingStyle)
clearTypingStyle();
if (m_selection == s)
return;
......@@ -154,7 +158,7 @@ void SelectionController::setSelection(const VisibleSelection& s, bool closeTypi
m_caretRectNeedsUpdate = true;
if (!s.isNone())
m_frame->setFocusedNodeIfNeeded();
setFocusedNodeIfNeeded();
updateAppearance();
......@@ -162,7 +166,7 @@ void SelectionController::setSelection(const VisibleSelection& s, bool closeTypi
// It will be restored by the vertical arrow navigation code if necessary.
m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation;
selectFrameElementInParentIfFullySelected();
m_frame->notifyRendererOfSelectionChange(userTriggered);
notifyRendererOfSelectionChange(userTriggered);
m_frame->editor()->respondToChangedSelection(oldSelection, closeTyping);
if (userTriggered) {
ScrollAlignment alignment;
......@@ -172,7 +176,7 @@ void SelectionController::setSelection(const VisibleSelection& s, bool closeTypi
else
alignment = (align == AlignCursorOnScrollAlways) ? ScrollAlignment::alignTopAlways : ScrollAlignment::alignToEdgeIfNeeded;
m_frame->revealSelection(alignment, true);
revealSelection(alignment, true);
}
notifyAccessibilityForSelectionChange();
......@@ -287,8 +291,7 @@ void SelectionController::willBeModified(EAlteration alter, EDirection direction
TextDirection SelectionController::directionOfEnclosingBlock()
{
Node* n = m_selection.extent().node();
Node* enclosingBlockNode = enclosingBlock(n);
Node* enclosingBlockNode = enclosingBlock(m_selection.extent().node());
if (!enclosingBlockNode)
return LTR;
RenderObject* renderer = enclosingBlockNode->renderer();
......@@ -638,7 +641,7 @@ bool SelectionController::modify(EAlteration alter, EDirection direction, TextGr
trialSelectionController.setIsDirectional(m_isDirectional);
trialSelectionController.modify(alter, direction, granularity, false, settings);
bool change = m_frame->shouldChangeSelection(trialSelectionController.selection());
bool change = shouldChangeSelection(trialSelectionController.selection());
if (!change)
return false;
}
......@@ -734,7 +737,7 @@ bool SelectionController::modify(EAlteration alter, int verticalDistance, bool u
trialSelectionController.setIsDirectional(m_isDirectional);
trialSelectionController.modify(alter, verticalDistance, false);
bool change = m_frame->shouldChangeSelection(trialSelectionController.selection());
bool change = shouldChangeSelection(trialSelectionController.selection());
if (!change)
return false;
}
......@@ -1243,7 +1246,7 @@ void SelectionController::selectFrameElementInParentIfFullySelected()
// Focus on the parent frame, and then select from before this element to after.
VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement);
if (parent->shouldChangeSelection(newSelection)) {
if (parent->selection()->shouldChangeSelection(newSelection)) {
page->focusController()->setFocusedFrame(parent);
parent->selection()->setSelection(newSelection);
}
......@@ -1269,10 +1272,10 @@ void SelectionController::selectAll()
if (!root)
return;
VisibleSelection newSelection(VisibleSelection::selectionFromContentsOfNode(root));
if (m_frame->shouldChangeSelection(newSelection))
if (shouldChangeSelection(newSelection))
setSelection(newSelection);
selectFrameElementInParentIfFullySelected();
m_frame->notifyRendererOfSelectionChange(true);
notifyRendererOfSelectionChange(true);
}
bool SelectionController::setSelectedRange(Range* range, EAffinity affinity, bool closeTyping)
......@@ -1347,11 +1350,11 @@ void SelectionController::focusedOrActiveStateChanged()
// RenderObject::selectionForegroundColor() check if the frame is active,
// we have to update places those colors were painted.
if (RenderView* view = toRenderView(m_frame->document()->renderer()))
view->repaintRectangleInViewAndCompositedLayers(enclosingIntRect(m_frame->selectionBounds()));
view->repaintRectangleInViewAndCompositedLayers(enclosingIntRect(bounds()));
// Caret appears in the active frame.
if (activeAndFocused)
m_frame->setSelectionFromNone();
setSelectionFromNone();
setCaretVisible(activeAndFocused);
// Update for caps lock state
......@@ -1502,6 +1505,207 @@ void SelectionController::caretBlinkTimerFired(Timer<SelectionController>*)
#endif
}
void SelectionController::notifyRendererOfSelectionChange(bool userTriggered)
{
m_frame->document()->updateStyleIfNeeded();
if (!rootEditableElement())
return;
RenderObject* renderer = rootEditableElement()->shadowAncestorNode()->renderer();
if (!renderer || !renderer->isTextControl())
return;
toRenderTextControl(renderer)->selectionChanged(userTriggered);
}
// Helper function that tells whether a particular node is an element that has an entire
// Frame and FrameView, a <frame>, <iframe>, or <object>.
static bool isFrameElement(const Node* n)
{
if (!n)
return false;
RenderObject* renderer = n->renderer();
if (!renderer || !renderer->isWidget())
return false;
Widget* widget = toRenderWidget(renderer)->widget();
return widget && widget->isFrameView();
}
void SelectionController::setFocusedNodeIfNeeded()
{
if (isNone() || !isFocused())
return;
bool caretBrowsing = m_frame->settings() && m_frame->settings()->caretBrowsingEnabled();
</