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);
......
This diff is collapsed.
......@@ -26,8 +26,10 @@
#ifndef SelectionController_h
#define SelectionController_h
#include "CSSMutableStyleDeclaration.h"
#include "IntRect.h"
#include "Range.h"
#include "ScrollBehavior.h"
#include "Timer.h"
#include "VisibleSelection.h"
#include <wtf/Noncopyable.h>
......@@ -36,6 +38,7 @@ namespace WebCore {
class Frame;
class GraphicsContext;
class HTMLFormElement;
class RenderObject;
class RenderView;
class Settings;
......@@ -149,6 +152,26 @@ public:
void showTreeForThis() const;
#endif
bool shouldChangeSelection(const VisibleSelection&) const;
bool shouldDeleteSelection(const VisibleSelection&) const;
void setFocusedNodeIfNeeded();
void notifyRendererOfSelectionChange(bool userTriggered);
void paintDragCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
CSSMutableStyleDeclaration* typingStyle() const;
void setTypingStyle(PassRefPtr<CSSMutableStyleDeclaration>);
void clearTypingStyle();
FloatRect bounds(bool clipToVisibleContent = true) const;
void getClippedVisibleTextRectangles(Vector<FloatRect>&) const;
HTMLFormElement* currentForm() const;
void revealSelection(const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded, bool revealExtent = false);
void setSelectionFromNone();
private:
enum EPositionType { START, END, BASE, EXTENT };
......@@ -193,6 +216,8 @@ private:
VisibleSelection m_selection;
TextGranularity m_granularity;
RefPtr<CSSMutableStyleDeclaration> m_typingStyle;
Timer<SelectionController> m_caretBlinkTimer;
IntRect m_caretRect; // caret rect in coords local to the renderer responsible for painting the caret
......@@ -209,6 +234,21 @@ private:
bool m_caretPaint;
};
inline CSSMutableStyleDeclaration* SelectionController::typingStyle() const
{
return m_typingStyle.get();
}
inline void SelectionController::clearTypingStyle()
{
m_typingStyle.clear();
}
inline void SelectionController::setTypingStyle(PassRefPtr<CSSMutableStyleDeclaration> style)
{
m_typingStyle = style;
}
#if !(PLATFORM(MAC) || PLATFORM(GTK))
inline void SelectionController::notifyAccessibilityForSelectionChange()
{
......
......@@ -356,7 +356,7 @@ void TypingCommand::insertText(const String &text, bool selectInsertedText)
void TypingCommand::insertTextRunWithoutNewlines(const String &text, bool selectInsertedText)
{
RefPtr<InsertTextCommand> command;
if (!document()->frame()->typingStyle() && !m_commands.isEmpty()) {
if (!document()->frame()->selection()->typingStyle() && !m_commands.isEmpty()) {
EditCommand* lastCommand = m_commands.last().get();
if (lastCommand->isInsertTextCommand())
command = static_cast<InsertTextCommand*>(lastCommand);
......@@ -496,7 +496,7 @@ void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing)
if (selectionToDelete.isNone())
return;
if (selectionToDelete.isCaret() || !document()->frame()->shouldDeleteSelection(selectionToDelete))
if (selectionToDelete.isCaret() || !document()->frame()->selection()->shouldDeleteSelection(selectionToDelete))
return;
if (killRing)
......@@ -579,7 +579,7 @@ void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool ki
if (selectionToDelete.isNone())
return;
if (selectionToDelete.isCaret() || !document()->frame()->shouldDeleteSelection(selectionToDelete))
if (selectionToDelete.isCaret() || !document()->frame()->selection()->shouldDeleteSelection(selectionToDelete))
return;
if (killRing)
......
......@@ -222,7 +222,7 @@ void HTMLTextAreaElement::updateFocusAppearance(bool restorePreviousSelection)
}
if (document()->frame())
document()->frame()->revealSelection();
document()->frame()->selection()->revealSelection();
}
void HTMLTextAreaElement::defaultEventHandler(Event* event)
......
......@@ -231,7 +231,7 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
Document* document = frame->document();
RefPtr<ReplaceSelectionCommand> command = ReplaceSelectionCommand::create(document, createFragmentFromMarkup(document, item->title(), ""), true, false, true);
applyCommand(command);
frame->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
frame->selection()->revealSelection(ScrollAlignment::alignToEdgeIfNeeded);
}
break;
case ContextMenuItemTagIgnoreSpelling:
......
......@@ -455,7 +455,7 @@ bool DragController::concludeEditDrag(DragData* dragData)
// NSTextView behavior is to always smart delete on moving a selection,
// but only to smart insert if the selection granularity is word granularity.
bool smartDelete = innerFrame->editor()->smartInsertDeleteEnabled();
bool smartInsert = smartDelete && innerFrame->selectionGranularity() == WordGranularity && dragData->canSmartReplace();
bool smartInsert = smartDelete && innerFrame->selection()->granularity() == WordGranularity && dragData->canSmartReplace();
applyCommand(MoveSelectionCommand::create(fragment, dragCaret.base(), smartInsert, smartDelete));
} else {
if (setSelectionToDragCaret(innerFrame, dragCaret, range, point))
......@@ -636,7 +636,7 @@ static IntPoint dragLocForDHTMLDrag(const IntPoint& mouseDraggedPoint, const Int
static IntPoint dragLocForSelectionDrag(Frame* src)
{
IntRect draggingRect = enclosingIntRect(src->selectionBounds());
IntRect draggingRect = enclosingIntRect(src->selection()->bounds());
int xpos = draggingRect.right();
xpos = draggingRect.x() < xpos ? draggingRect.x() : xpos;
int ypos = draggingRect.bottom();
......
......@@ -263,7 +263,7 @@ void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestRe
newSelection.appendTrailingWhitespace();
}
if (m_frame->shouldChangeSelection(newSelection))
if (m_frame->selection()->shouldChangeSelection(newSelection))
m_frame->selection()->setSelection(newSelection, granularity, MakeNonDirectionalSelection);
}
}
......@@ -288,7 +288,7 @@ void EventHandler::selectClosestWordOrLinkFromMouseEvent(const MouseEventWithHit
m_beganSelectingText = true;
}
if (m_frame->shouldChangeSelection(newSelection))
if (m_frame->selection()->shouldChangeSelection(newSelection))
m_frame->selection()->setSelection(newSelection, granularity, MakeNonDirectionalSelection);
}
}
......@@ -333,7 +333,7 @@ bool EventHandler::handleMousePressEventTripleClick(const MouseEventWithHitTestR
m_beganSelectingText = true;
}
if (m_frame->shouldChangeSelection(newSelection))
if (m_frame->selection()->shouldChangeSelection(newSelection))
m_frame->selection()->setSelection(newSelection, granularity, MakeNonDirectionalSelection);
return true;
......@@ -391,16 +391,16 @@ bool EventHandler::handleMousePressEventSingleClick(const MouseEventWithHitTestR
newSelection.setExtent(pos);
}
if (m_frame->selectionGranularity() != CharacterGranularity) {
granularity = m_frame->selectionGranularity();
newSelection.expandUsingGranularity(m_frame->selectionGranularity());
if (m_frame->selection()->granularity() != CharacterGranularity) {
granularity = m_frame->selection()->granularity();
newSelection.expandUsingGranularity(m_frame->selection()->granularity());
}
m_beganSelectingText = true;
} else
newSelection = VisibleSelection(visiblePos);
if (m_frame->shouldChangeSelection(newSelection))
if (m_frame->selection()->shouldChangeSelection(newSelection))
m_frame->selection()->setSelection(newSelection, granularity, MakeNonDirectionalSelection);
return true;
......@@ -633,12 +633,12 @@ void EventHandler::updateSelectionForMouseDrag(Node* targetNode, const IntPoint&
}
newSelection.setExtent(targetPosition);
if (m_frame->selectionGranularity() != CharacterGranularity)
newSelection.expandUsingGranularity(m_frame->selectionGranularity());
if (m_frame->selection()->granularity() != CharacterGranularity)
newSelection.expandUsingGranularity(m_frame->selection()->granularity());
if (m_frame->shouldChangeSelection(newSelection)) {
if (m_frame->selection()->shouldChangeSelection(newSelection)) {
m_frame->selection()->setIsDirectional(false);
m_frame->selection()->setSelection(newSelection, m_frame->selectionGranularity(), MakeNonDirectionalSelection);
m_frame->selection()->setSelection(newSelection, m_frame->selection()->granularity(), MakeNonDirectionalSelection);
}
}
#endif // ENABLE(DRAG_SUPPORT)
......@@ -700,13 +700,13 @@ bool EventHandler::handleMouseReleaseEvent(const MouseEventWithHitTestResults& e
VisiblePosition pos = node->renderer()->positionForPoint(event.localPoint());
newSelection = VisibleSelection(pos);
}
if (m_frame->shouldChangeSelection(newSelection))
if (m_frame->selection()->shouldChangeSelection(newSelection))
m_frame->selection()->setSelection(newSelection);
handled = true;
}
m_frame->notifyRendererOfSelectionChange(true);