Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: Source/core/editing/ApplyStyleCommand.cpp

Issue 23467007: Have Range constructor take a Document reference in argument (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 VisiblePosition visibleStart(start); 246 VisiblePosition visibleStart(start);
247 VisiblePosition visibleEnd(end); 247 VisiblePosition visibleEnd(end);
248 248
249 if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull() || visibleEnd.isOrphan()) 249 if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull() || visibleEnd.isOrphan())
250 return; 250 return;
251 251
252 // Save and restore the selection endpoints using their indices in the docum ent, since 252 // Save and restore the selection endpoints using their indices in the docum ent, since
253 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoint s. 253 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoint s.
254 // Calculate start and end indices from the start of the tree that they're i n. 254 // Calculate start and end indices from the start of the tree that they're i n.
255 Node* scope = highestAncestor(visibleStart.deepEquivalent().deprecatedNode() ); 255 Node* scope = highestAncestor(visibleStart.deepEquivalent().deprecatedNode() );
256 RefPtr<Range> startRange = Range::create(&document(), firstPositionInNode(sc ope), visibleStart.deepEquivalent().parentAnchoredEquivalent()); 256 RefPtr<Range> startRange = Range::create(document(), firstPositionInNode(sco pe), visibleStart.deepEquivalent().parentAnchoredEquivalent());
257 RefPtr<Range> endRange = Range::create(&document(), firstPositionInNode(scop e), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); 257 RefPtr<Range> endRange = Range::create(document(), firstPositionInNode(scope ), visibleEnd.deepEquivalent().parentAnchoredEquivalent());
258 int startIndex = TextIterator::rangeLength(startRange.get(), true); 258 int startIndex = TextIterator::rangeLength(startRange.get(), true);
259 int endIndex = TextIterator::rangeLength(endRange.get(), true); 259 int endIndex = TextIterator::rangeLength(endRange.get(), true);
260 260
261 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); 261 VisiblePosition paragraphStart(startOfParagraph(visibleStart));
262 VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next()); 262 VisiblePosition nextParagraphStart(endOfParagraph(paragraphStart).next());
263 VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next()); 263 VisiblePosition beyondEnd(endOfParagraph(visibleEnd).next());
264 while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) { 264 while (paragraphStart.isNotNull() && paragraphStart != beyondEnd) {
265 StyleChange styleChange(style, paragraphStart.deepEquivalent()); 265 StyleChange styleChange(style, paragraphStart.deepEquivalent());
266 if (styleChange.cssStyle().length() || m_removeOnly) { 266 if (styleChange.cssStyle().length() || m_removeOnly) {
267 RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent(). deprecatedNode()); 267 RefPtr<Node> block = enclosingBlock(paragraphStart.deepEquivalent(). deprecatedNode());
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 pastEndNode = NodeTraversal::nextSkippingChildren(end.deprecatedNode()); 683 pastEndNode = NodeTraversal::nextSkippingChildren(end.deprecatedNode());
684 684
685 // FIXME: Callers should perform this operation on a Range that includes the br 685 // FIXME: Callers should perform this operation on a Range that includes the br
686 // if they want style applied to the empty line. 686 // if they want style applied to the empty line.
687 if (start == end && start.deprecatedNode()->hasTagName(brTag)) 687 if (start == end && start.deprecatedNode()->hasTagName(brTag))
688 pastEndNode = NodeTraversal::next(start.deprecatedNode()); 688 pastEndNode = NodeTraversal::next(start.deprecatedNode());
689 689
690 // Start from the highest fully selected ancestor so that we can modify the fully selected node. 690 // Start from the highest fully selected ancestor so that we can modify the fully selected node.
691 // e.g. When applying font-size: large on <font color="blue">hello</font>, w e need to include the font element in our run 691 // e.g. When applying font-size: large on <font color="blue">hello</font>, w e need to include the font element in our run
692 // to generate <font color="blue" size="4">hello</font> instead of <font col or="blue"><font size="4">hello</font></font> 692 // to generate <font color="blue" size="4">hello</font> instead of <font col or="blue"><font size="4">hello</font></font>
693 RefPtr<Range> range = Range::create(&startNode->document(), start, end); 693 RefPtr<Range> range = Range::create(startNode->document(), start, end);
694 Element* editableRoot = startNode->rootEditableElement(); 694 Element* editableRoot = startNode->rootEditableElement();
695 if (startNode != editableRoot) { 695 if (startNode != editableRoot) {
696 while (editableRoot && startNode->parentNode() != editableRoot && isNode VisiblyContainedWithin(startNode->parentNode(), range.get())) 696 while (editableRoot && startNode->parentNode() != editableRoot && isNode VisiblyContainedWithin(startNode->parentNode(), range.get()))
697 startNode = startNode->parentNode(); 697 startNode = startNode->parentNode();
698 } 698 }
699 699
700 applyInlineStyleToNodeRange(style, startNode, pastEndNode); 700 applyInlineStyleToNodeRange(style, startNode, pastEndNode);
701 } 701 }
702 702
703 static bool containsNonEditableRegion(Node* node) 703 static bool containsNonEditableRegion(Node* node)
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 String textToMove = nextText->data(); 1541 String textToMove = nextText->data();
1542 insertTextIntoNode(childText, childText->length(), textToMove); 1542 insertTextIntoNode(childText, childText->length(), textToMove);
1543 removeNode(next); 1543 removeNode(next);
1544 // don't move child node pointer. it may want to merge with more text no des. 1544 // don't move child node pointer. it may want to merge with more text no des.
1545 } 1545 }
1546 1546
1547 updateStartEnd(newStart, newEnd); 1547 updateStartEnd(newStart, newEnd);
1548 } 1548 }
1549 1549
1550 } 1550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698