Changeset 142705 in webkit
- Timestamp:
- Feb 12, 2013 6:39:22 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r142701 r142705 1 2013-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 1 27 2013-02-12 Joseph Pecoraro <pecoraro@apple.com> 2 28 -
trunk/Source/WebCore/editing/EditCommand.cpp
r142533 r142705 28 28 29 29 #include "CompositeEditCommand.h" 30 #if ENABLE(DELETION_UI)31 #include "DeleteButtonController.h"32 #endif33 30 #include "Document.h" 34 31 #include "Editor.h" … … 49 46 ASSERT(m_document); 50 47 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())); 56 49 setEndingSelection(m_startingSelection); 57 50 } -
trunk/Source/WebCore/editing/Editor.cpp
r142576 r142705 105 105 using namespace Unicode; 106 106 107 #if ENABLE(DELETION_UI) 108 PassRefPtr<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 141 VisibleSelection 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 107 166 // When an event handler has moved the selection outside of a text control 108 167 // we should use the target control's selection for this editing operation. … … 2388 2447 IntPoint framePoint = frameView->windowToContents(windowPoint); 2389 2448 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()); 2395 2451 } 2396 2452 -
trunk/Source/WebCore/editing/Editor.h
r142576 r142705 97 97 98 98 Frame* frame() const { return m_frame; } 99 99 100 #if ENABLE(DELETION_UI) 100 101 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 102 108 CompositeEditCommand* lastEditCommand() { return m_lastEditCommand.get(); } 103 109 -
trunk/Source/WebCore/editing/htmlediting.cpp
r142533 r142705 1183 1183 || node->hasTagName(h5Tag); 1184 1184 } 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 #endif1242 1185 1243 1186 Position adjustedSelectionStartForStyleComputation(const VisibleSelection& selection) -
trunk/Source/WebCore/editing/htmlediting.h
r142533 r142705 193 193 PassRefPtr<Range> createRange(PassRefPtr<Document>, const VisiblePosition& start, const VisiblePosition& end, ExceptionCode&); 194 194 PassRefPtr<Range> extendRangeToWrappingNodes(PassRefPtr<Range> rangeToExtend, const Range* maximumRange, const Node* rootNode); 195 #if ENABLE(DELETION_UI)196 PassRefPtr<Range> avoidIntersectionWithNode(const Range*, Node*);197 #endif198 195 199 196 // ------------------------------------------------------------------------- … … 238 235 239 236 // Functions returning VisibleSelection 240 #if ENABLE(DELETION_UI)241 VisibleSelection avoidIntersectionWithNode(const VisibleSelection&, Node*);242 #endif243 237 VisibleSelection selectionForParagraphIteration(const VisibleSelection&); 244 238 -
trunk/Source/WebCore/editing/markup.cpp
r142533 r142705 545 545 // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForInterchange? 546 546 // 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 { 547 static 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); 549 553 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 #else570 updatedRange = Range::create(range->ownerDocument(), range->startContainer(), range->startOffset(), range->endContainer(), range->endOffset());571 #endif572 554 573 555 bool collapsed = updatedRange->collapsed(ASSERT_NO_EXCEPTION); 574 556 if (collapsed) 575 return "";557 return emptyString(); 576 558 Node* commonAncestor = updatedRange->commonAncestorContainer(ASSERT_NO_EXCEPTION); 577 559 if (!commonAncestor) 578 return "";560 return emptyString(); 579 561 580 562 document->updateLayoutIgnorePendingStylesheets(); … … 585 567 if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(body).toNormalizedRange().get(), range)) 586 568 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); 589 571 Node* pastEnd = updatedRange->pastLastNode(); 590 572 … … 593 575 VisiblePosition visibleEnd(updatedRange->endPosition(), VP_DEFAULT_AFFINITY); 594 576 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()) 600 578 return interchangeNewlineString; 601 }602 579 603 580 accumulator.appendString(interchangeNewlineString); 604 581 startNode = visibleStart.next().deepEquivalent().deprecatedNode(); 605 582 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) 611 584 return interchangeNewlineString; 612 }613 585 } 614 586 … … 656 628 accumulator.appendString(interchangeNewlineString); 657 629 630 return accumulator.takeResults(); 631 } 632 633 String 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. 658 644 #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 660 655 deleteButton->enable(); 656 657 return result; 658 } 661 659 #endif 662 return accumulator.takeResults();660 return createMarkupInternal(document, range, range, nodes, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs); 663 661 } 664 662
Note: See TracChangeset
for help on using the changeset viewer.