Changeset 142705 in webkit


Ignore:
Timestamp:
Feb 12, 2013 6:39:22 PM (11 years ago)
Author:
rniwa@webkit.org
Message:

Turn avoidIntersectionWithNode into Editor member functions to encapsulate delete button controller
https://bugs.webkit.org/show_bug.cgi?id=109549

Reviewed by Tony Chang.

Renamed avoidIntersectionWithNode to Editor::avoidIntersectionWithDeleteButtonController and added trivial
implementations when delete button controllers are disabled (ENABLE_DELETION_UI is 0).

  • editing/DeleteButtonController.cpp:
  • editing/EditCommand.cpp:

(WebCore::EditCommand::EditCommand):

  • editing/Editor.cpp:

(WebCore::Editor::avoidIntersectionWithDeleteButtonController): Moved from htmlediting.cpp and renamed.
The version that takes VisibleSelection has been updated to use updatePositionForNodeRemoval to share
mode code with that function.
(WebCore::Editor::rangeForPoint):

  • editing/Editor.h:

(WebCore::Editor::avoidIntersectionWithDeleteButtonController): Added; trivial implementations.

  • editing/htmlediting.cpp:
  • editing/htmlediting.h:
  • editing/markup.cpp:

(WebCore::createMarkupInternal): Extracted from createMarkup.
(WebCore::createMarkup):

Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142701 r142705  
     12013-02-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Turn avoidIntersectionWithNode into Editor member functions to encapsulate delete button controller
     4        https://bugs.webkit.org/show_bug.cgi?id=109549
     5
     6        Reviewed by Tony Chang.
     7
     8        Renamed avoidIntersectionWithNode to Editor::avoidIntersectionWithDeleteButtonController and added trivial
     9        implementations when delete button controllers are disabled (ENABLE_DELETION_UI is 0).
     10
     11        * editing/DeleteButtonController.cpp:
     12        * editing/EditCommand.cpp:
     13        (WebCore::EditCommand::EditCommand):
     14        * editing/Editor.cpp:
     15        (WebCore::Editor::avoidIntersectionWithDeleteButtonController): Moved from htmlediting.cpp and renamed.
     16        The version that takes VisibleSelection has been updated to use updatePositionForNodeRemoval to share
     17        mode code with that function.
     18        (WebCore::Editor::rangeForPoint):
     19        * editing/Editor.h:
     20        (WebCore::Editor::avoidIntersectionWithDeleteButtonController): Added; trivial implementations.
     21        * editing/htmlediting.cpp:
     22        * editing/htmlediting.h:
     23        * editing/markup.cpp:
     24        (WebCore::createMarkupInternal): Extracted from createMarkup.
     25        (WebCore::createMarkup):
     26
    1272013-02-12  Joseph Pecoraro  <pecoraro@apple.com>
    228
  • trunk/Source/WebCore/editing/EditCommand.cpp

    r142533 r142705  
    2828
    2929#include "CompositeEditCommand.h"
    30 #if ENABLE(DELETION_UI)
    31 #include "DeleteButtonController.h"
    32 #endif
    3330#include "Document.h"
    3431#include "Editor.h"
     
    4946    ASSERT(m_document);
    5047    ASSERT(m_document->frame());
    51 #if ENABLE(DELETION_UI)
    52     setStartingSelection(avoidIntersectionWithNode(m_document->frame()->selection()->selection(), m_document->frame()->editor()->deleteButtonController()->containerElement()));
    53 #else
    54     setStartingSelection(m_document->frame()->selection()->selection());
    55 #endif
     48    setStartingSelection(m_document->frame()->editor()->avoidIntersectionWithDeleteButtonController(m_document->frame()->selection()->selection()));
    5649    setEndingSelection(m_startingSelection);
    5750}
  • trunk/Source/WebCore/editing/Editor.cpp

    r142576 r142705  
    105105using namespace Unicode;
    106106
     107#if ENABLE(DELETION_UI)
     108PassRefPtr<Range> Editor::avoidIntersectionWithDeleteButtonController(const Range* range) const
     109{
     110    DeleteButtonController* controller = deleteButtonController();
     111    if (!range || !controller)
     112        return 0;
     113
     114    Document* document = range->ownerDocument();
     115
     116    Node* startContainer = range->startContainer();
     117    int startOffset = range->startOffset();
     118    Node* endContainer = range->endContainer();
     119    int endOffset = range->endOffset();
     120
     121    if (!startContainer)
     122        return 0;
     123
     124    ASSERT(endContainer);
     125
     126    Element* element = controller->containerElement();
     127    if (startContainer == element || startContainer->isDescendantOf(element)) {
     128        ASSERT(element->parentNode());
     129        startContainer = element->parentNode();
     130        startOffset = element->nodeIndex();
     131    }
     132    if (endContainer == element || endContainer->isDescendantOf(element)) {
     133        ASSERT(element->parentNode());
     134        endContainer = element->parentNode();
     135        endOffset = element->nodeIndex();
     136    }
     137
     138    return Range::create(document, startContainer, startOffset, endContainer, endOffset);
     139}
     140
     141VisibleSelection Editor::avoidIntersectionWithDeleteButtonController(const VisibleSelection& selection) const
     142{
     143    DeleteButtonController* controller = deleteButtonController();
     144    if (selection.isNone() || !controller)
     145        return selection;
     146
     147    Element* element = controller->containerElement();
     148    if (!element)
     149        return selection;
     150    VisibleSelection updatedSelection = selection;
     151
     152    Position updatedBase = selection.base();
     153    updatePositionForNodeRemoval(updatedBase, element);
     154    if (updatedBase != selection.base())
     155        updatedSelection.setBase(updatedBase);
     156
     157    Position updatedExtent = selection.base();
     158    updatePositionForNodeRemoval(updatedExtent, element);
     159    if (updatedExtent != selection.extent())
     160        updatedSelection.setExtent(updatedExtent);
     161
     162    return updatedSelection;
     163}
     164#endif
     165
    107166// When an event handler has moved the selection outside of a text control
    108167// we should use the target control's selection for this editing operation.
     
    23882447    IntPoint framePoint = frameView->windowToContents(windowPoint);
    23892448    VisibleSelection selection(frame->visiblePositionForPoint(framePoint));
    2390 #if ENABLE(DELETION_UI)
    2391     return avoidIntersectionWithNode(selection.toNormalizedRange().get(), m_deleteButtonController->containerElement());
    2392 #else
    2393     return selection.toNormalizedRange();
    2394 #endif
     2449
     2450    return avoidIntersectionWithDeleteButtonController(selection.toNormalizedRange().get());
    23952451}
    23962452
  • trunk/Source/WebCore/editing/Editor.h

    r142576 r142705  
    9797
    9898    Frame* frame() const { return m_frame; }
     99
    99100#if ENABLE(DELETION_UI)
    100101    DeleteButtonController* deleteButtonController() const { return m_deleteButtonController.get(); }
    101 #endif
     102    PassRefPtr<Range> avoidIntersectionWithDeleteButtonController(const Range*) const;
     103    VisibleSelection avoidIntersectionWithDeleteButtonController(const VisibleSelection&) const;
     104#else
     105    VisibleSelection avoidIntersectionWithDeleteButtonController(const VisibleSelection& selection) const { return selection; }
     106#endif
     107
    102108    CompositeEditCommand* lastEditCommand() { return m_lastEditCommand.get(); }
    103109
  • trunk/Source/WebCore/editing/htmlediting.cpp

    r142533 r142705  
    11831183        || node->hasTagName(h5Tag);
    11841184}
    1185 
    1186 #if ENABLE(DELETION_UI)
    1187 PassRefPtr<Range> avoidIntersectionWithNode(const Range* range, Node* node)
    1188 {
    1189     if (!range)
    1190         return 0;
    1191 
    1192     Document* document = range->ownerDocument();
    1193 
    1194     Node* startContainer = range->startContainer();
    1195     int startOffset = range->startOffset();
    1196     Node* endContainer = range->endContainer();
    1197     int endOffset = range->endOffset();
    1198 
    1199     if (!startContainer)
    1200         return 0;
    1201 
    1202     ASSERT(endContainer);
    1203 
    1204     if (startContainer == node || startContainer->isDescendantOf(node)) {
    1205         ASSERT(node->parentNode());
    1206         startContainer = node->parentNode();
    1207         startOffset = node->nodeIndex();
    1208     }
    1209     if (endContainer == node || endContainer->isDescendantOf(node)) {
    1210         ASSERT(node->parentNode());
    1211         endContainer = node->parentNode();
    1212         endOffset = node->nodeIndex();
    1213     }
    1214 
    1215     return Range::create(document, startContainer, startOffset, endContainer, endOffset);
    1216 }
    1217 
    1218 VisibleSelection avoidIntersectionWithNode(const VisibleSelection& selection, Node* node)
    1219 {
    1220     if (selection.isNone())
    1221         return VisibleSelection(selection);
    1222 
    1223     VisibleSelection updatedSelection(selection);
    1224     Node* base = selection.base().deprecatedNode();
    1225     Node* extent = selection.extent().deprecatedNode();
    1226     ASSERT(base);
    1227     ASSERT(extent);
    1228 
    1229     if (base == node || base->isDescendantOf(node)) {
    1230         ASSERT(node->parentNode());
    1231         updatedSelection.setBase(positionInParentBeforeNode(node));
    1232     }
    1233 
    1234     if (extent == node || extent->isDescendantOf(node)) {
    1235         ASSERT(node->parentNode());
    1236         updatedSelection.setExtent(positionInParentBeforeNode(node));
    1237     }
    1238 
    1239     return updatedSelection;
    1240 }
    1241 #endif
    12421185   
    12431186Position adjustedSelectionStartForStyleComputation(const VisibleSelection& selection)
  • trunk/Source/WebCore/editing/htmlediting.h

    r142533 r142705  
    193193PassRefPtr<Range> createRange(PassRefPtr<Document>, const VisiblePosition& start, const VisiblePosition& end, ExceptionCode&);
    194194PassRefPtr<Range> extendRangeToWrappingNodes(PassRefPtr<Range> rangeToExtend, const Range* maximumRange, const Node* rootNode);
    195 #if ENABLE(DELETION_UI)
    196 PassRefPtr<Range> avoidIntersectionWithNode(const Range*, Node*);
    197 #endif
    198195
    199196// -------------------------------------------------------------------------
     
    238235
    239236// Functions returning VisibleSelection
    240 #if ENABLE(DELETION_UI)
    241 VisibleSelection avoidIntersectionWithNode(const VisibleSelection&, Node*);
    242 #endif
    243237VisibleSelection selectionForParagraphIteration(const VisibleSelection&);
    244238
  • trunk/Source/WebCore/editing/markup.cpp

    r142533 r142705  
    545545// FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForInterchange?
    546546// FIXME: At least, annotation and style info should probably not be included in range.markupString()
    547 String createMarkup(const Range* range, Vector<Node*>* nodes, EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsoluteURLs shouldResolveURLs)
    548 {
     547static String createMarkupInternal(Document* document, const Range* range, const Range* updatedRange, Vector<Node*>* nodes,
     548    EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsoluteURLs shouldResolveURLs)
     549{
     550    ASSERT(document);
     551    ASSERT(range);
     552    ASSERT(updatedRange);
    549553    DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, (ASCIILiteral("<br class=\"" AppleInterchangeNewline "\">")));
    550 
    551     if (!range)
    552         return "";
    553 
    554     Document* document = range->ownerDocument();
    555     if (!document)
    556         return "";
    557 
    558     // Disable the delete button so it's elements are not serialized into the markup,
    559     // but make sure neither endpoint is inside the delete user interface.
    560     RefPtr<Range> updatedRange;
    561 #if ENABLE(DELETION_UI)
    562     Frame* frame = document->frame();
    563     DeleteButtonController* deleteButton = frame ? frame->editor()->deleteButtonController() : 0;
    564     updatedRange = avoidIntersectionWithNode(range, deleteButton ? deleteButton->containerElement() : 0);
    565     if (!updatedRange)
    566         return "";
    567     if (deleteButton)
    568         deleteButton->disable();
    569 #else
    570     updatedRange = Range::create(range->ownerDocument(), range->startContainer(), range->startOffset(), range->endContainer(), range->endOffset());
    571 #endif
    572554
    573555    bool collapsed = updatedRange->collapsed(ASSERT_NO_EXCEPTION);
    574556    if (collapsed)
    575         return "";
     557        return emptyString();
    576558    Node* commonAncestor = updatedRange->commonAncestorContainer(ASSERT_NO_EXCEPTION);
    577559    if (!commonAncestor)
    578         return "";
     560        return emptyString();
    579561
    580562    document->updateLayoutIgnorePendingStylesheets();
     
    585567    if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(body).toNormalizedRange().get(), range))
    586568        fullySelectedRoot = body;
    587     Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange.get(), shouldAnnotate);
    588     StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate, updatedRange.get(), specialCommonAncestor);
     569    Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange, shouldAnnotate);
     570    StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate, updatedRange, specialCommonAncestor);
    589571    Node* pastEnd = updatedRange->pastLastNode();
    590572
     
    593575    VisiblePosition visibleEnd(updatedRange->endPosition(), VP_DEFAULT_AFFINITY);
    594576    if (shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfter(visibleStart)) {
    595         if (visibleStart == visibleEnd.previous()) {
    596 #if ENABLE(DELETION_UI)
    597             if (deleteButton)
    598                 deleteButton->enable();
    599 #endif
     577        if (visibleStart == visibleEnd.previous())
    600578            return interchangeNewlineString;
    601         }
    602579
    603580        accumulator.appendString(interchangeNewlineString);
    604581        startNode = visibleStart.next().deepEquivalent().deprecatedNode();
    605582
    606         if (pastEnd && Range::compareBoundaryPoints(startNode, 0, pastEnd, 0, ASSERT_NO_EXCEPTION) >= 0) {
    607 #if ENABLE(DELETION_UI)
    608             if (deleteButton)
    609                 deleteButton->enable();
    610 #endif
     583        if (pastEnd && Range::compareBoundaryPoints(startNode, 0, pastEnd, 0, ASSERT_NO_EXCEPTION) >= 0)
    611584            return interchangeNewlineString;
    612         }
    613585    }
    614586
     
    656628        accumulator.appendString(interchangeNewlineString);
    657629
     630    return accumulator.takeResults();
     631}
     632
     633String createMarkup(const Range* range, Vector<Node*>* nodes, EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsoluteURLs shouldResolveURLs)
     634{
     635    if (!range)
     636        return emptyString();
     637
     638    Document* document = range->ownerDocument();
     639    if (!document)
     640        return emptyString();
     641
     642    // Disable the delete button so it's elements are not serialized into the markup,
     643    // but make sure neither endpoint is inside the delete user interface.
    658644#if ENABLE(DELETION_UI)
    659     if (deleteButton)
     645    Frame* frame = document->frame();
     646    if (DeleteButtonController* deleteButton = frame ? frame->editor()->deleteButtonController() : 0) {
     647        RefPtr<Range> updatedRange = frame->editor()->avoidIntersectionWithDeleteButtonController(range);
     648        if (!updatedRange)
     649            return emptyString();
     650
     651        deleteButton->disable();
     652
     653        String result = createMarkupInternal(document, range, updatedRange.get(), nodes, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs);
     654
    660655        deleteButton->enable();
     656
     657        return result;
     658    }
    661659#endif
    662     return accumulator.takeResults();
     660    return createMarkupInternal(document, range, range, nodes, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs);
    663661}
    664662
Note: See TracChangeset for help on using the changeset viewer.