Changeset 68337 in webkit
- Timestamp:
- Sep 25, 2010 1:42:46 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r68335 r68337 1 2010-09-25 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Tony Chang. 4 5 FormatBlockCommand's modifyRange and doApply should be merged 6 https://bugs.webkit.org/show_bug.cgi?id=46504 7 8 Isolated the code in doApply to insert and remove lists for single paragraph into doApplyForSingleParagraph. 9 Merged the code in modifyRange into doApply and cleaned up. 10 11 No new tests are added since this is a cleanup. 12 13 * editing/FormatBlockCommand.cpp: 14 (WebCore::FormatBlockCommand::doApply): Merged with modifyRange; calls doApplyForSingleParagraph. 15 (WebCore::FormatBlockCommand::doApplyForSingleParagraph): Added. 16 * editing/FormatBlockCommand.h: 17 1 18 2010-09-25 Dan Bernstein <mitz@apple.com> 2 19 -
trunk/WebCore/editing/FormatBlockCommand.cpp
r66032 r68337 42 42 } 43 43 44 bool FormatBlockCommand::modifyRange()45 {46 ASSERT(endingSelection().isRange());47 VisiblePosition visibleStart = endingSelection().visibleStart();48 VisiblePosition visibleEnd = endingSelection().visibleEnd();49 VisiblePosition startOfLastParagraph = startOfParagraph(visibleEnd);50 51 if (startOfParagraph(visibleStart) == startOfLastParagraph)52 return false;53 54 setEndingSelection(visibleStart);55 doApply();56 visibleStart = endingSelection().visibleStart();57 VisiblePosition nextParagraph = endOfParagraph(visibleStart).next();58 while (nextParagraph.isNotNull() && nextParagraph != startOfLastParagraph) {59 setEndingSelection(nextParagraph);60 doApply();61 nextParagraph = endOfParagraph(endingSelection().visibleStart()).next();62 }63 setEndingSelection(visibleEnd);64 doApply();65 visibleEnd = endingSelection().visibleEnd();66 setEndingSelection(VisibleSelection(visibleStart.deepEquivalent(), visibleEnd.deepEquivalent(), DOWNSTREAM));67 68 return true;69 }70 71 44 void FormatBlockCommand::doApply() 72 45 { … … 87 60 // margin/padding, but not others. We should make the gap painting more consistent and 88 61 // then use a left margin/padding rule here. 89 if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd)) 62 if (visibleEnd != visibleStart && isStartOfParagraph(visibleEnd)) { 90 63 setEndingSelection(VisibleSelection(visibleStart, visibleEnd.previous(true))); 64 visibleEnd = endingSelection().visibleEnd(); 65 } 91 66 92 if (endingSelection().isRange() && modifyRange()) 67 VisiblePosition startOfLastParagraph = startOfParagraph(visibleEnd); 68 if (endingSelection().isCaret() || startOfParagraph(visibleStart) == startOfLastParagraph) { 69 doApplyForSingleParagraph(); 93 70 return; 71 } 94 72 73 setEndingSelection(visibleStart); 74 doApplyForSingleParagraph(); 75 visibleStart = endingSelection().visibleStart(); 76 VisiblePosition nextParagraph = endOfParagraph(visibleStart).next(); 77 while (nextParagraph.isNotNull() && nextParagraph != startOfLastParagraph) { 78 setEndingSelection(nextParagraph); 79 doApplyForSingleParagraph(); 80 nextParagraph = endOfParagraph(endingSelection().visibleStart()).next(); 81 } 82 setEndingSelection(visibleEnd); 83 doApplyForSingleParagraph(); 84 visibleEnd = endingSelection().visibleEnd(); 85 86 setEndingSelection(VisibleSelection(visibleStart.deepEquivalent(), visibleEnd.deepEquivalent(), DOWNSTREAM)); 87 } 88 89 void FormatBlockCommand::doApplyForSingleParagraph() 90 { 95 91 ExceptionCode ec; 96 92 String localName, prefix; … … 103 99 // We're already in a block with the format we want, so we don't have to do anything 104 100 return; 105 101 106 102 VisiblePosition paragraphStart = startOfParagraph(endingSelection().visibleStart()); 107 103 VisiblePosition paragraphEnd = endOfParagraph(endingSelection().visibleStart()); … … 110 106 RefPtr<Element> blockNode = createHTMLElement(document(), m_tagName); 111 107 RefPtr<Element> placeholder = createBreakElement(document()); 112 108 113 109 Node* root = endingSelection().start().node()->rootEditableElement(); 114 110 if (validBlockTag(refNode->nodeName().lower()) && … … 123 119 } 124 120 appendNode(placeholder, blockNode); 125 121 126 122 VisiblePosition destination(Position(placeholder.get(), 0)); 127 123 if (paragraphStart == paragraphEnd && !lineBreakExistsAtVisiblePosition(paragraphStart)) { -
trunk/WebCore/editing/FormatBlockCommand.h
r39456 r68337 42 42 43 43 virtual void doApply(); 44 void doApplyForSingleParagraph(); 44 45 virtual EditAction editingAction() const { return EditActionFormatBlock; } 45 46 46 bool modifyRange();47 47 AtomicString m_tagName; 48 48 };
Note: See TracChangeset
for help on using the changeset viewer.