Changeset 69640 in webkit
- Timestamp:
- Oct 12, 2010 11:34:18 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 4 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r69639 r69640 1 2010-10-12 Sheriff Bot <webkit.review.bot@gmail.com> 2 3 Unreviewed, rolling out r69639. 4 http://trac.webkit.org/changeset/69639 5 https://bugs.webkit.org/show_bug.cgi?id=47575 6 7 "regressed nav-element.html" (Requested by rniwa on #webkit). 8 9 * editing/execCommand/format-block-expected.txt: 10 * editing/execCommand/format-block-from-range-selection-expected.txt: 11 * editing/execCommand/format-block-multiple-paragraphs-expected.txt: Removed. 12 * editing/execCommand/format-block-multiple-paragraphs.html: Removed. 13 * editing/execCommand/format-block-table-expected.txt: Removed. 14 * editing/execCommand/format-block-table.html: Removed. 15 * editing/execCommand/format-block-with-braces-expected.txt: 16 1 17 2010-10-12 Ryosuke Niwa <rniwa@webkit.org> 2 18 -
trunk/LayoutTests/editing/execCommand/format-block-expected.txt
r69639 r69640 53 53 | <pre> 54 54 | "Make Pre" 55 | <br> 55 56 | " 56 57 " … … 62 63 | <br> 63 64 | <h1> 64 | <span> 65 | id="item2" 66 | "Make h1" 65 | "Make h1" 66 | <br> 67 67 | "baz" 68 68 | " -
trunk/LayoutTests/editing/execCommand/format-block-from-range-selection-expected.txt
r69639 r69640 33 33 | <dl> 34 34 | "Fo<#selection-anchor>o" 35 | <br>36 | "bar"37 | <br>38 | <span>39 | "baz"40 | <br>41 | "raz"42 | <br>43 | "44 dar"45 | <br>46 | "47 "48 | "yar<#selection-focus>"49 35 | " 50 36 " 37 | <div> 38 | <dl> 39 | "bar" 40 | <span> 41 | <dl> 42 | "baz" 43 | <dl> 44 | "raz" 45 | <dl> 46 | "dar" 47 | " " 51 48 | " 52 49 " 50 | <dl> 51 | "ya<#selection-focus>r" 53 52 | " 54 53 " -
trunk/LayoutTests/editing/execCommand/format-block-with-braces-expected.txt
r69639 r69640 17 17 After FormatBlock with <h1>: 18 18 | <h1> 19 | " 20 <#selection-caret>Format Me 21 " 19 | "<#selection-caret>Format Me" 20 | <br> -
trunk/WebCore/ChangeLog
r69639 r69640 1 2010-10-12 Sheriff Bot <webkit.review.bot@gmail.com> 2 3 Unreviewed, rolling out r69639. 4 http://trac.webkit.org/changeset/69639 5 https://bugs.webkit.org/show_bug.cgi?id=47575 6 7 "regressed nav-element.html" (Requested by rniwa on #webkit). 8 9 * editing/ApplyBlockElementCommand.cpp: 10 (WebCore::ApplyBlockElementCommand::formatSelection): 11 * editing/EditorCommand.cpp: 12 (WebCore::executeFormatBlock): 13 * editing/FormatBlockCommand.cpp: 14 (WebCore::FormatBlockCommand::formatRange): 15 * editing/FormatBlockCommand.h: 16 (WebCore::FormatBlockCommand::editingAction): 17 * editing/VisiblePosition.cpp: 18 (WebCore::enclosingBlockFlowElement): 19 * editing/VisiblePosition.h: 20 * editing/htmlediting.cpp: 21 (WebCore::validBlockTag): 22 * editing/htmlediting.h: 23 1 24 2010-10-12 Ryosuke Niwa <rniwa@webkit.org> 2 25 -
trunk/WebCore/editing/ApplyBlockElementCommand.cpp
r69639 r69640 113 113 114 114 bool atEnd = false; 115 Position end;116 115 while (endOfCurrentParagraph != endAfterSelection && !atEnd) { 116 Position start; 117 Position end; 118 117 119 if (endOfCurrentParagraph == endOfLastParagraph) 118 120 atEnd = true; -
trunk/WebCore/editing/EditorCommand.cpp
r69639 r69640 433 433 if (tagName[0] == '<' && tagName[tagName.length() - 1] == '>') 434 434 tagName = tagName.substring(1, tagName.length() - 2); 435 if (!validBlockTag(tagName)) 436 return false; 435 437 436 438 ExceptionCode ec; … … 439 441 return false; 440 442 QualifiedName qualifiedTagName(prefix, localName, xhtmlNamespaceURI); 441 442 if (!FormatBlockCommand::isElementToApplyInFormatBlockCommand(qualifiedTagName))443 return false;444 443 445 444 applyCommand(FormatBlockCommand::create(frame->document(), qualifiedTagName)); -
trunk/WebCore/editing/FormatBlockCommand.cpp
r69639 r69640 37 37 using namespace HTMLNames; 38 38 39 static Node* enclosingBlockToSplitTreeTo(Node* startNode);40 41 39 FormatBlockCommand::FormatBlockCommand(Document* document, const QualifiedName& tagName) 42 40 : ApplyBlockElementCommand(document, tagName) … … 44 42 } 45 43 46 void FormatBlockCommand::formatRange(const Position& start, const Position& end, RefPtr<Element>& blockNode)44 void FormatBlockCommand::formatRange(const Position&, const Position& end, RefPtr<Element>&) 47 45 { 48 Node* nodeToSplitTo = enclosingBlockToSplitTreeTo(start.node()); 49 RefPtr<Node> outerBlock = (start.node() == nodeToSplitTo) ? start.node() : splitTreeToNode(start.node(), nodeToSplitTo); 50 RefPtr<Node> nodeAfterInsertionPosition = outerBlock; 46 setEndingSelection(VisiblePosition(end)); 51 47 52 Element* refNode = enclosingBlockFlowElement(end); 53 Element* root = editableRootForPosition(start); 54 if (isElementToApplyInFormatBlockCommand(refNode->tagQName()) && start == startOfBlock(start) && end == endOfBlock(end) 55 && refNode != root && !root->isDescendantOf(refNode)) { 56 // Already in a block element that only contains the current paragraph 57 if (refNode->hasTagName(tagName())) 58 return; 59 nodeAfterInsertionPosition = refNode; 48 Node* refNode = enclosingBlockFlowElement(endingSelection().visibleStart()); 49 if (refNode->hasTagName(tagName())) 50 // We're already in a block with the format we want, so we don't have to do anything 51 return; 52 53 VisiblePosition paragraphStart = startOfParagraph(end); 54 VisiblePosition paragraphEnd = endOfParagraph(end); 55 VisiblePosition blockStart = startOfBlock(endingSelection().visibleStart()); 56 VisiblePosition blockEnd = endOfBlock(endingSelection().visibleStart()); 57 RefPtr<Element> blockNode = createBlockElement(); 58 RefPtr<Element> placeholder = createBreakElement(document()); 59 60 Node* root = endingSelection().start().node()->rootEditableElement(); 61 if (validBlockTag(refNode->nodeName().lower()) && 62 paragraphStart == blockStart && paragraphEnd == blockEnd && 63 refNode != root && !root->isDescendantOf(refNode)) 64 // Already in a valid block tag that only contains the current paragraph, so we can swap with the new tag 65 insertNodeBefore(blockNode, refNode); 66 else { 67 // Avoid inserting inside inline elements that surround paragraphStart with upstream(). 68 // This is only to avoid creating bloated markup. 69 insertNodeAt(blockNode, paragraphStart.deepEquivalent().upstream()); 60 70 } 71 appendNode(placeholder, blockNode); 61 72 62 if (!blockNode) { 63 // Create a new blockquote and insert it as a child of the root editable element. We accomplish 64 // this by splitting all parents of the current paragraph up to that point. 65 blockNode = createBlockElement(); 66 insertNodeBefore(blockNode, nodeAfterInsertionPosition); 73 VisiblePosition destination(Position(placeholder.get(), 0)); 74 if (paragraphStart == paragraphEnd && !lineBreakExistsAtVisiblePosition(paragraphStart)) { 75 setEndingSelection(destination); 76 return; 67 77 } 68 69 Position lastParagraphInBlockNode = lastPositionInNode(blockNode.get()); 70 bool wasEndOfParagraph = isEndOfParagraph(lastParagraphInBlockNode); 71 72 moveParagraphWithClones(start, end, blockNode.get(), outerBlock.get()); 73 74 if (wasEndOfParagraph && !isEndOfParagraph(lastParagraphInBlockNode) && !isStartOfParagraph(lastParagraphInBlockNode)) 75 insertBlockPlaceholder(lastParagraphInBlockNode); 76 } 77 78 // FIXME: We should consider mering this function with isElementForFormatBlockCommand in Editor.cpp 79 // Checks if a tag name is valid for execCommand('FormatBlock'). 80 bool FormatBlockCommand::isElementToApplyInFormatBlockCommand(const QualifiedName& tagName) 81 { 82 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, blockTags, ()); 83 if (blockTags.isEmpty()) { 84 blockTags.add(addressTag); 85 blockTags.add(articleTag); 86 blockTags.add(asideTag); 87 blockTags.add(blockquoteTag); 88 blockTags.add(ddTag); 89 blockTags.add(divTag); 90 blockTags.add(dlTag); 91 blockTags.add(dtTag); 92 blockTags.add(footerTag); 93 blockTags.add(h1Tag); 94 blockTags.add(h2Tag); 95 blockTags.add(h3Tag); 96 blockTags.add(h4Tag); 97 blockTags.add(h5Tag); 98 blockTags.add(h6Tag); 99 blockTags.add(headerTag); 100 blockTags.add(hgroupTag); 101 blockTags.add(navTag); 102 blockTags.add(pTag); 103 blockTags.add(preTag); 104 blockTags.add(sectionTag); 105 } 106 return blockTags.contains(tagName); 107 } 108 109 Node* enclosingBlockToSplitTreeTo(Node* startNode) 110 { 111 Node* lastBlock = startNode; 112 for (Node* n = startNode; n; n = n->parentNode()) { 113 if (!n->isContentEditable()) 114 return lastBlock; 115 if (isTableCell(n) || n->hasTagName(bodyTag) || !n->parentNode() || !n->parentNode()->isContentEditable() 116 || (n->isElementNode() && FormatBlockCommand::isElementToApplyInFormatBlockCommand(static_cast<Element*>(n)->tagQName()))) 117 return n; 118 if (isBlock(n)) 119 lastBlock = n; 120 if (isListElement(n)) 121 return n->parentNode()->isContentEditable() ? n->parentNode() : n; 122 } 123 return lastBlock; 78 moveParagraph(paragraphStart, paragraphEnd, destination, true, false); 124 79 } 125 80 -
trunk/WebCore/editing/FormatBlockCommand.h
r69639 r69640 39 39 } 40 40 41 static bool isElementToApplyInFormatBlockCommand(const QualifiedName& tagName);42 43 41 private: 44 42 FormatBlockCommand(Document*, const QualifiedName& tagName); 45 43 46 v oid formatRange(const Position&, const Position&, RefPtr<Element>&);47 EditAction editingAction() const { return EditActionFormatBlock; }44 virtual void formatRange(const Position&, const Position&, RefPtr<Element>&); 45 virtual EditAction editingAction() const { return EditActionFormatBlock; } 48 46 }; 49 47 -
trunk/WebCore/editing/VisiblePosition.cpp
r69639 r69640 635 635 } 636 636 637 Element*enclosingBlockFlowElement(const VisiblePosition &visiblePosition)637 Node *enclosingBlockFlowElement(const VisiblePosition &visiblePosition) 638 638 { 639 639 if (visiblePosition.isNull()) -
trunk/WebCore/editing/VisiblePosition.h
r69639 r69640 137 137 VisiblePosition endVisiblePosition(const Range*, EAffinity); 138 138 139 Element*enclosingBlockFlowElement(const VisiblePosition&);139 Node *enclosingBlockFlowElement(const VisiblePosition&); 140 140 141 141 bool isFirstVisiblePositionInNode(const VisiblePosition&, const Node*); -
trunk/WebCore/editing/htmlediting.cpp
r69639 r69640 466 466 } 467 467 468 // Checks if a string is a valid tag for the FormatBlockCommand function of execCommand. Expects lower case strings. 469 bool validBlockTag(const AtomicString& blockTag) 470 { 471 if (blockTag.isEmpty()) 472 return false; 473 474 DEFINE_STATIC_LOCAL(HashSet<AtomicString>, blockTags, ()); 475 if (blockTags.isEmpty()) { 476 blockTags.add(addressTag.localName()); 477 blockTags.add(articleTag.localName()); 478 blockTags.add(asideTag.localName()); 479 blockTags.add(blockquoteTag.localName()); 480 blockTags.add(ddTag.localName()); 481 blockTags.add(divTag.localName()); 482 blockTags.add(dlTag.localName()); 483 blockTags.add(dtTag.localName()); 484 blockTags.add(footerTag.localName()); 485 blockTags.add(h1Tag.localName()); 486 blockTags.add(h2Tag.localName()); 487 blockTags.add(h3Tag.localName()); 488 blockTags.add(h4Tag.localName()); 489 blockTags.add(h5Tag.localName()); 490 blockTags.add(h6Tag.localName()); 491 blockTags.add(headerTag.localName()); 492 blockTags.add(hgroupTag.localName()); 493 blockTags.add(navTag.localName()); 494 blockTags.add(pTag.localName()); 495 blockTags.add(preTag.localName()); 496 blockTags.add(sectionTag.localName()); 497 } 498 return blockTags.contains(blockTag); 499 } 500 468 501 static Node* firstInSpecialElement(const Position& pos) 469 502 { -
trunk/WebCore/editing/htmlediting.h
r69639 r69640 229 229 String stringWithRebalancedWhitespace(const String&, bool, bool); 230 230 const String& nonBreakingSpaceString(); 231 bool validBlockTag(const AtomicString&); 232 231 233 232 234 }
Note: See TracChangeset
for help on using the changeset viewer.