OLD | NEW |
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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 LayoutStyle* layoutStyleOfEnclosingTextNode(const Position& position) | 176 static const LayoutStyle* layoutStyleOfEnclosingTextNode(const Position& positio
n) |
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()->layoutStyle(); |
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 (LayoutStyle* startStyle = layoutStyleOfEnclosingTextNode(start)) { | 191 if (const LayoutStyle* startStyle = layoutStyleOfEnclosingTextNode(start)) { |
192 isStartAndEndOnSameNode = layoutStyleOfEnclosingTextNode(end) && start.c
ontainerNode() == end.containerNode(); | 192 isStartAndEndOnSameNode = layoutStyleOfEnclosingTextNode(end) && start.c
ontainerNode() == end.containerNode(); |
193 bool isStartAndEndOfLastParagraphOnSameNode = layoutStyleOfEnclosingText
Node(m_endOfLastParagraph) && start.containerNode() == m_endOfLastParagraph.cont
ainerNode(); | 193 bool isStartAndEndOfLastParagraphOnSameNode = layoutStyleOfEnclosingText
Node(m_endOfLastParagraph) && start.containerNode() == m_endOfLastParagraph.cont
ainerNode(); |
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 (LayoutStyle* endStyle = layoutStyleOfEnclosingTextNode(end)) { | 218 if (const LayoutStyle* endStyle = layoutStyleOfEnclosingTextNode(end)) { |
219 bool isEndAndEndOfLastParagraphOnSameNode = layoutStyleOfEnclosingTextNo
de(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.depreca
tedNode(); | 219 bool isEndAndEndOfLastParagraphOnSameNode = layoutStyleOfEnclosingTextNo
de(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.depreca
tedNode(); |
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 |
(...skipping 11 matching lines...) Expand all Loading... |
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 LayoutStyle* style = layoutStyleOfEnclosingTextNode(position); | 250 const LayoutStyle* style = layoutStyleOfEnclosingTextNode(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 Loading... |
289 return element.release(); | 289 return element.release(); |
290 } | 290 } |
291 | 291 |
292 void ApplyBlockElementCommand::trace(Visitor* visitor) | 292 void ApplyBlockElementCommand::trace(Visitor* visitor) |
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 } |
OLD | NEW |