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

Side by Side Diff: Source/core/editing/commands/FormatBlockCommand.cpp

Issue 1317053004: Make VisiblePosition constructor private (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-02T12:44:47 Rebase Created 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 void FormatBlockCommand::formatSelection(const VisiblePosition& startOfSelection , const VisiblePosition& endOfSelection) 62 void FormatBlockCommand::formatSelection(const VisiblePosition& startOfSelection , const VisiblePosition& endOfSelection)
63 { 63 {
64 if (!isElementForFormatBlock(tagName())) 64 if (!isElementForFormatBlock(tagName()))
65 return; 65 return;
66 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelection); 66 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelection);
67 m_didApply = true; 67 m_didApply = true;
68 } 68 }
69 69
70 void FormatBlockCommand::formatRange(const Position& start, const Position& end, const Position& endOfSelection, RefPtrWillBeRawPtr<HTMLElement>& blockElement) 70 void FormatBlockCommand::formatRange(const Position& start, const Position& end, const Position& endOfSelection, RefPtrWillBeRawPtr<HTMLElement>& blockElement)
71 { 71 {
72 Element* refElement = enclosingBlockFlowElement(VisiblePosition(end)); 72 Element* refElement = enclosingBlockFlowElement(createVisiblePosition(end));
73 Element* root = editableRootForPosition(start); 73 Element* root = editableRootForPosition(start);
74 // Root is null for elements with contenteditable=false. 74 // Root is null for elements with contenteditable=false.
75 if (!root || !refElement) 75 if (!root || !refElement)
76 return; 76 return;
77 77
78 Node* nodeToSplitTo = enclosingBlockToSplitTreeTo(start.anchorNode()); 78 Node* nodeToSplitTo = enclosingBlockToSplitTreeTo(start.anchorNode());
79 RefPtrWillBeRawPtr<Node> outerBlock = (start.anchorNode() == nodeToSplitTo) ? start.anchorNode() : splitTreeToNode(start.anchorNode(), nodeToSplitTo).get(); 79 RefPtrWillBeRawPtr<Node> outerBlock = (start.anchorNode() == nodeToSplitTo) ? start.anchorNode() : splitTreeToNode(start.anchorNode(), nodeToSplitTo).get();
80 RefPtrWillBeRawPtr<Node> nodeAfterInsertionPosition = outerBlock; 80 RefPtrWillBeRawPtr<Node> nodeAfterInsertionPosition = outerBlock;
81 RefPtrWillBeRawPtr<Range> range = Range::create(document(), start, endOfSele ction); 81 RefPtrWillBeRawPtr<Range> range = Range::create(document(), start, endOfSele ction);
82 82
83 if (isElementForFormatBlock(refElement->tagQName()) && VisiblePosition(start ).deepEquivalent() == startOfBlock(VisiblePosition(start)).deepEquivalent() 83 if (isElementForFormatBlock(refElement->tagQName()) && createVisiblePosition (start).deepEquivalent() == startOfBlock(createVisiblePosition(start)).deepEquiv alent()
84 && (VisiblePosition(end).deepEquivalent() == endOfBlock(VisiblePosition( end)).deepEquivalent() || isNodeVisiblyContainedWithin(*refElement, *range)) 84 && (createVisiblePosition(end).deepEquivalent() == endOfBlock(createVisi blePosition(end)).deepEquivalent() || isNodeVisiblyContainedWithin(*refElement, *range))
85 && refElement != root && !root->isDescendantOf(refElement)) { 85 && refElement != root && !root->isDescendantOf(refElement)) {
86 // Already in a block element that only contains the current paragraph 86 // Already in a block element that only contains the current paragraph
87 if (refElement->hasTagName(tagName())) 87 if (refElement->hasTagName(tagName()))
88 return; 88 return;
89 nodeAfterInsertionPosition = refElement; 89 nodeAfterInsertionPosition = refElement;
90 } 90 }
91 91
92 if (!blockElement) { 92 if (!blockElement) {
93 // Create a new blockquote and insert it as a child of the root editable element. We accomplish 93 // Create a new blockquote and insert it as a child of the root editable element. We accomplish
94 // this by splitting all parents of the current paragraph up to that poi nt. 94 // this by splitting all parents of the current paragraph up to that poi nt.
95 blockElement = createBlockElement(); 95 blockElement = createBlockElement();
96 insertNodeBefore(blockElement, nodeAfterInsertionPosition); 96 insertNodeBefore(blockElement, nodeAfterInsertionPosition);
97 } 97 }
98 98
99 Position lastParagraphInBlockNode = blockElement->lastChild() ? positionAfte rNode(blockElement->lastChild()) : Position(); 99 Position lastParagraphInBlockNode = blockElement->lastChild() ? positionAfte rNode(blockElement->lastChild()) : Position();
100 bool wasEndOfParagraph = isEndOfParagraph(VisiblePosition(lastParagraphInBlo ckNode)); 100 bool wasEndOfParagraph = isEndOfParagraph(createVisiblePosition(lastParagrap hInBlockNode));
101 101
102 moveParagraphWithClones(VisiblePosition(start), VisiblePosition(end), blockE lement.get(), outerBlock.get()); 102 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosition( end), blockElement.get(), outerBlock.get());
103 103
104 // Copy the inline style of the original block element to the newly created block-style element. 104 // Copy the inline style of the original block element to the newly created block-style element.
105 if (outerBlock.get() != nodeAfterInsertionPosition.get() && toHTMLElement(no deAfterInsertionPosition.get())->hasAttribute(styleAttr)) 105 if (outerBlock.get() != nodeAfterInsertionPosition.get() && toHTMLElement(no deAfterInsertionPosition.get())->hasAttribute(styleAttr))
106 blockElement->setAttribute(styleAttr, toHTMLElement(nodeAfterInsertionPo sition.get())->getAttribute(styleAttr)); 106 blockElement->setAttribute(styleAttr, toHTMLElement(nodeAfterInsertionPo sition.get())->getAttribute(styleAttr));
107 107
108 if (wasEndOfParagraph && !isEndOfParagraph(VisiblePosition(lastParagraphInBl ockNode)) && !isStartOfParagraph(VisiblePosition(lastParagraphInBlockNode))) 108 if (wasEndOfParagraph && !isEndOfParagraph(createVisiblePosition(lastParagra phInBlockNode)) && !isStartOfParagraph(createVisiblePosition(lastParagraphInBloc kNode)))
109 insertBlockPlaceholder(lastParagraphInBlockNode); 109 insertBlockPlaceholder(lastParagraphInBlockNode);
110 } 110 }
111 111
112 Element* FormatBlockCommand::elementForFormatBlockCommand(Range* range) 112 Element* FormatBlockCommand::elementForFormatBlockCommand(Range* range)
113 { 113 {
114 if (!range) 114 if (!range)
115 return 0; 115 return 0;
116 116
117 Node* commonAncestor = range->commonAncestorContainer(); 117 Node* commonAncestor = range->commonAncestorContainer();
118 while (commonAncestor && !isElementForFormatBlock(commonAncestor)) 118 while (commonAncestor && !isElementForFormatBlock(commonAncestor))
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 return n; 168 return n;
169 if (isEnclosingBlock(n)) 169 if (isEnclosingBlock(n))
170 lastBlock = n; 170 lastBlock = n;
171 if (isHTMLListElement(n)) 171 if (isHTMLListElement(n))
172 return n->parentNode()->hasEditableStyle() ? n->parentNode() : n; 172 return n->parentNode()->hasEditableStyle() ? n->parentNode() : n;
173 } 173 }
174 return lastBlock; 174 return lastBlock;
175 } 175 }
176 176
177 } 177 }
OLDNEW
« no previous file with comments | « Source/core/editing/commands/DeleteSelectionCommand.cpp ('k') | Source/core/editing/commands/IndentOutdentCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698