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

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

Issue 1033943002: Rename LayoutStyle to papayawhip (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: ensureComputedStyle Created 5 years, 8 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
« no previous file with comments | « Source/core/dom/shadow/InsertionPoint.cpp ('k') | Source/core/editing/EditingStyle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 11 matching lines...) Expand all
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/editing/ApplyBlockElementCommand.h" 28 #include "core/editing/ApplyBlockElementCommand.h"
29 29
30 #include "bindings/core/v8/ExceptionState.h" 30 #include "bindings/core/v8/ExceptionState.h"
31 #include "core/HTMLNames.h" 31 #include "core/HTMLNames.h"
32 #include "core/dom/NodeLayoutStyle.h" 32 #include "core/dom/NodeComputedStyle.h"
33 #include "core/dom/Text.h" 33 #include "core/dom/Text.h"
34 #include "core/editing/VisiblePosition.h" 34 #include "core/editing/VisiblePosition.h"
35 #include "core/editing/VisibleUnits.h" 35 #include "core/editing/VisibleUnits.h"
36 #include "core/editing/htmlediting.h" 36 #include "core/editing/htmlediting.h"
37 #include "core/html/HTMLBRElement.h" 37 #include "core/html/HTMLBRElement.h"
38 #include "core/html/HTMLElement.h" 38 #include "core/html/HTMLElement.h"
39 #include "core/layout/LayoutObject.h" 39 #include "core/layout/LayoutObject.h"
40 #include "core/layout/style/LayoutStyle.h" 40 #include "core/layout/style/ComputedStyle.h"
41 41
42 namespace blink { 42 namespace blink {
43 43
44 using namespace HTMLNames; 44 using namespace HTMLNames;
45 45
46 ApplyBlockElementCommand::ApplyBlockElementCommand(Document& document, const Qua lifiedName& tagName, const AtomicString& inlineStyle) 46 ApplyBlockElementCommand::ApplyBlockElementCommand(Document& document, const Qua lifiedName& tagName, const AtomicString& inlineStyle)
47 : CompositeEditCommand(document) 47 : CompositeEditCommand(document)
48 , m_tagName(tagName) 48 , m_tagName(tagName)
49 , m_inlineStyle(inlineStyle) 49 , m_inlineStyle(inlineStyle)
50 { 50 {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return false; 166 return false;
167 167
168 TrackExceptionState exceptionState; 168 TrackExceptionState exceptionState;
169 String textAtPosition = toText(textNode)->substringData(offset, 1, exception State); 169 String textAtPosition = toText(textNode)->substringData(offset, 1, exception State);
170 if (exceptionState.hadException()) 170 if (exceptionState.hadException())
171 return false; 171 return false;
172 172
173 return textAtPosition[0] == '\n'; 173 return textAtPosition[0] == '\n';
174 } 174 }
175 175
176 static const LayoutStyle* layoutStyleOfEnclosingTextNode(const Position& positio n) 176 static const ComputedStyle* computedStyleOfEnclosingTextNode(const Position& pos ition)
177 { 177 {
178 if (position.anchorType() != Position::PositionIsOffsetInAnchor || !position .containerNode() || !position.containerNode()->isTextNode()) 178 if (position.anchorType() != Position::PositionIsOffsetInAnchor || !position .containerNode() || !position.containerNode()->isTextNode())
179 return 0; 179 return 0;
180 return position.containerNode()->layoutStyle(); 180 return position.containerNode()->computedStyle();
181 } 181 }
182 182
183 void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const VisiblePosition& endOfCurrentParagraph, Position& start, Position& end) 183 void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const VisiblePosition& endOfCurrentParagraph, Position& start, Position& end)
184 { 184 {
185 start = startOfParagraph(endOfCurrentParagraph).deepEquivalent(); 185 start = startOfParagraph(endOfCurrentParagraph).deepEquivalent();
186 end = endOfCurrentParagraph.deepEquivalent(); 186 end = endOfCurrentParagraph.deepEquivalent();
187 187
188 document().updateRenderTreeIfNeeded(); 188 document().updateRenderTreeIfNeeded();
189 189
190 bool isStartAndEndOnSameNode = false; 190 bool isStartAndEndOnSameNode = false;
191 if (const LayoutStyle* startStyle = layoutStyleOfEnclosingTextNode(start)) { 191 if (const ComputedStyle* startStyle = computedStyleOfEnclosingTextNode(start )) {
192 isStartAndEndOnSameNode = layoutStyleOfEnclosingTextNode(end) && start.c ontainerNode() == end.containerNode(); 192 isStartAndEndOnSameNode = computedStyleOfEnclosingTextNode(end) && start .containerNode() == end.containerNode();
193 bool isStartAndEndOfLastParagraphOnSameNode = layoutStyleOfEnclosingText Node(m_endOfLastParagraph) && start.containerNode() == m_endOfLastParagraph.cont ainerNode(); 193 bool isStartAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingTe xtNode(m_endOfLastParagraph) && start.containerNode() == m_endOfLastParagraph.co ntainerNode();
194 194
195 // Avoid obtanining the start of next paragraph for start 195 // Avoid obtanining the start of next paragraph for start
196 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe wLineAtPosition(start.previous()) && start.offsetInContainerNode() > 0) 196 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe wLineAtPosition(start.previous()) && start.offsetInContainerNode() > 0)
197 start = startOfParagraph(VisiblePosition(end.previous())).deepEquiva lent(); 197 start = startOfParagraph(VisiblePosition(end.previous())).deepEquiva lent();
198 198
199 // If start is in the middle of a text node, split. 199 // If start is in the middle of a text node, split.
200 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) { 200 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() > 0) {
201 int startOffset = start.offsetInContainerNode(); 201 int startOffset = start.offsetInContainerNode();
202 Text* startText = start.containerText(); 202 Text* startText = start.containerText();
203 splitTextNode(startText, startOffset); 203 splitTextNode(startText, startOffset);
204 start = firstPositionInNode(startText); 204 start = firstPositionInNode(startText);
205 if (isStartAndEndOnSameNode) { 205 if (isStartAndEndOnSameNode) {
206 ASSERT(end.offsetInContainerNode() >= startOffset); 206 ASSERT(end.offsetInContainerNode() >= startOffset);
207 end = Position(startText, end.offsetInContainerNode() - startOff set); 207 end = Position(startText, end.offsetInContainerNode() - startOff set);
208 } 208 }
209 if (isStartAndEndOfLastParagraphOnSameNode) { 209 if (isStartAndEndOfLastParagraphOnSameNode) {
210 ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffs et); 210 ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffs et);
211 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph. offsetInContainerNode() - startOffset); 211 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph. offsetInContainerNode() - startOffset);
212 } 212 }
213 } 213 }
214 } 214 }
215 215
216 document().updateRenderTreeIfNeeded(); 216 document().updateRenderTreeIfNeeded();
217 217
218 if (const LayoutStyle* endStyle = layoutStyleOfEnclosingTextNode(end)) { 218 if (const ComputedStyle* endStyle = computedStyleOfEnclosingTextNode(end)) {
219 bool isEndAndEndOfLastParagraphOnSameNode = layoutStyleOfEnclosingTextNo de(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.depreca tedNode(); 219 bool isEndAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingText Node(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.depre catedNode();
220 // Include \n at the end of line if we're at an empty paragraph 220 // Include \n at the end of line if we're at an empty paragraph
221 if (endStyle->preserveNewline() && start == end && end.offsetInContainer Node() < end.containerNode()->maxCharacterOffset()) { 221 if (endStyle->preserveNewline() && start == end && end.offsetInContainer Node() < end.containerNode()->maxCharacterOffset()) {
222 int endOffset = end.offsetInContainerNode(); 222 int endOffset = end.offsetInContainerNode();
223 if (!isNewLineAtPosition(end.previous()) && isNewLineAtPosition(end) ) 223 if (!isNewLineAtPosition(end.previous()) && isNewLineAtPosition(end) )
224 end = Position(end.containerText(), endOffset + 1); 224 end = Position(end.containerText(), endOffset + 1);
225 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNod e() >= m_endOfLastParagraph.offsetInContainerNode()) 225 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNod e() >= m_endOfLastParagraph.offsetInContainerNode())
226 m_endOfLastParagraph = end; 226 m_endOfLastParagraph = end;
227 } 227 }
228 228
229 // If end is in the middle of a text node, split. 229 // If end is in the middle of a text node, split.
(...skipping 10 matching lines...) Expand all
240 } 240 }
241 end = lastPositionInNode(endContainer->previousSibling()); 241 end = lastPositionInNode(endContainer->previousSibling());
242 } 242 }
243 } 243 }
244 } 244 }
245 245
246 VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN eeded(VisiblePosition& endOfCurrentParagraph, Position& start, Position& end) 246 VisiblePosition ApplyBlockElementCommand::endOfNextParagrahSplittingTextNodesIfN eeded(VisiblePosition& endOfCurrentParagraph, Position& start, Position& end)
247 { 247 {
248 VisiblePosition endOfNextParagraph = endOfParagraph(endOfCurrentParagraph.ne xt()); 248 VisiblePosition endOfNextParagraph = endOfParagraph(endOfCurrentParagraph.ne xt());
249 Position position = endOfNextParagraph.deepEquivalent(); 249 Position position = endOfNextParagraph.deepEquivalent();
250 const LayoutStyle* style = layoutStyleOfEnclosingTextNode(position); 250 const ComputedStyle* style = computedStyleOfEnclosingTextNode(position);
251 if (!style) 251 if (!style)
252 return endOfNextParagraph; 252 return endOfNextParagraph;
253 253
254 RefPtrWillBeRawPtr<Text> text = position.containerText(); 254 RefPtrWillBeRawPtr<Text> text = position.containerText();
255 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNew LineAtPosition(firstPositionInNode(text.get()))) 255 if (!style->preserveNewline() || !position.offsetInContainerNode() || !isNew LineAtPosition(firstPositionInNode(text.get())))
256 return endOfNextParagraph; 256 return endOfNextParagraph;
257 257
258 // \n at the beginning of the text node immediately following the current pa ragraph is trimmed by moveParagraphWithClones. 258 // \n at the beginning of the text node immediately following the current pa ragraph is trimmed by moveParagraphWithClones.
259 // If endOfNextParagraph was pointing at this same text node, endOfNextParag raph will be shifted by one paragraph. 259 // If endOfNextParagraph was pointing at this same text node, endOfNextParag raph will be shifted by one paragraph.
260 // Avoid this by splitting "\n" 260 // Avoid this by splitting "\n"
(...skipping 28 matching lines...) Expand all
289 return element.release(); 289 return element.release();
290 } 290 }
291 291
292 DEFINE_TRACE(ApplyBlockElementCommand) 292 DEFINE_TRACE(ApplyBlockElementCommand)
293 { 293 {
294 visitor->trace(m_endOfLastParagraph); 294 visitor->trace(m_endOfLastParagraph);
295 CompositeEditCommand::trace(visitor); 295 CompositeEditCommand::trace(visitor);
296 } 296 }
297 297
298 } 298 }
OLDNEW
« no previous file with comments | « Source/core/dom/shadow/InsertionPoint.cpp ('k') | Source/core/editing/EditingStyle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698