OLD | NEW |
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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 Node& scope = NodeTraversal::highestAncestorOrSelf(*visibleStart.deepEquival
ent().anchorNode()); | 268 Node& scope = NodeTraversal::highestAncestorOrSelf(*visibleStart.deepEquival
ent().anchorNode()); |
269 Range* startRange = Range::create(document(), Position::firstPositionInNode(
&scope), visibleStart.deepEquivalent().parentAnchoredEquivalent()); | 269 Range* startRange = Range::create(document(), Position::firstPositionInNode(
&scope), visibleStart.deepEquivalent().parentAnchoredEquivalent()); |
270 Range* endRange = Range::create(document(), Position::firstPositionInNode(&s
cope), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); | 270 Range* endRange = Range::create(document(), Position::firstPositionInNode(&s
cope), visibleEnd.deepEquivalent().parentAnchoredEquivalent()); |
271 int startIndex = TextIterator::rangeLength(startRange->startPosition(), star
tRange->endPosition(), true); | 271 int startIndex = TextIterator::rangeLength(startRange->startPosition(), star
tRange->endPosition(), true); |
272 int endIndex = TextIterator::rangeLength(endRange->startPosition(), endRange
->endPosition(), true); | 272 int endIndex = TextIterator::rangeLength(endRange->startPosition(), endRange
->endPosition(), true); |
273 | 273 |
274 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); | 274 VisiblePosition paragraphStart(startOfParagraph(visibleStart)); |
275 VisiblePosition nextParagraphStart(nextPositionOf(endOfParagraph(paragraphSt
art))); | 275 VisiblePosition nextParagraphStart(nextPositionOf(endOfParagraph(paragraphSt
art))); |
276 VisiblePosition beyondEnd(nextPositionOf(endOfParagraph(visibleEnd))); | 276 VisiblePosition beyondEnd(nextPositionOf(endOfParagraph(visibleEnd))); |
277 while (paragraphStart.isNotNull() && paragraphStart.deepEquivalent() != beyo
ndEnd.deepEquivalent()) { | 277 while (paragraphStart.isNotNull() && paragraphStart.deepEquivalent() != beyo
ndEnd.deepEquivalent()) { |
| 278 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; |
278 StyleChange styleChange(style, paragraphStart.deepEquivalent()); | 279 StyleChange styleChange(style, paragraphStart.deepEquivalent()); |
279 if (styleChange.cssStyle().length() || m_removeOnly) { | 280 if (styleChange.cssStyle().length() || m_removeOnly) { |
280 Element* block = enclosingBlock(paragraphStart.deepEquivalent().anch
orNode()); | 281 Element* block = enclosingBlock(paragraphStart.deepEquivalent().anch
orNode()); |
281 const Position& paragraphStartToMove = paragraphStart.deepEquivalent
(); | 282 const Position& paragraphStartToMove = paragraphStart.deepEquivalent
(); |
282 if (!m_removeOnly && isEditablePosition(paragraphStartToMove)) { | 283 if (!m_removeOnly && isEditablePosition(paragraphStartToMove)) { |
283 HTMLElement* newBlock = moveParagraphContentsToNewBlockIfNecessa
ry(paragraphStartToMove, editingState); | 284 HTMLElement* newBlock = moveParagraphContentsToNewBlockIfNecessa
ry(paragraphStartToMove, editingState); |
284 if (editingState->isAborted()) | 285 if (editingState->isAborted()) |
285 return; | 286 return; |
286 if (newBlock) | 287 if (newBlock) { |
287 block = newBlock; | 288 block = newBlock; |
| 289 if (paragraphStart.isOrphan()) |
| 290 paragraphStart = createVisiblePosition(Position::firstPo
sitionInNode(newBlock)); |
| 291 } |
| 292 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; |
288 } | 293 } |
289 if (block && block->isHTMLElement()) { | 294 if (block && block->isHTMLElement()) { |
290 removeCSSStyle(style, toHTMLElement(block), editingState); | 295 removeCSSStyle(style, toHTMLElement(block), editingState); |
291 if (editingState->isAborted()) | 296 if (editingState->isAborted()) |
292 return; | 297 return; |
293 if (!m_removeOnly) | 298 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; |
| 299 if (!m_removeOnly) { |
294 addBlockStyle(styleChange, toHTMLElement(block)); | 300 addBlockStyle(styleChange, toHTMLElement(block)); |
| 301 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; |
| 302 } |
295 } | 303 } |
296 | 304 |
| 305 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; |
297 if (nextParagraphStart.isOrphan()) | 306 if (nextParagraphStart.isOrphan()) |
298 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStar
t)); | 307 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStar
t)); |
299 } | 308 } |
300 | 309 |
| 310 DCHECK(!nextParagraphStart.isOrphan()) << nextParagraphStart; |
301 paragraphStart = nextParagraphStart; | 311 paragraphStart = nextParagraphStart; |
302 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStart)); | 312 nextParagraphStart = nextPositionOf(endOfParagraph(paragraphStart)); |
303 } | 313 } |
304 | 314 |
305 // Update style and layout again, since added or removed styles could have | 315 // Update style and layout again, since added or removed styles could have |
306 // affected the layout. We need clean layout in order to compute | 316 // affected the layout. We need clean layout in order to compute |
307 // plain-text ranges below. | 317 // plain-text ranges below. |
308 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 318 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
309 | 319 |
310 EphemeralRange startEphemeralRange = PlainTextRange(startIndex).createRangeF
orSelection(toContainerNode(scope)); | 320 EphemeralRange startEphemeralRange = PlainTextRange(startIndex).createRangeF
orSelection(toContainerNode(scope)); |
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 DEFINE_TRACE(ApplyStyleCommand) | 1741 DEFINE_TRACE(ApplyStyleCommand) |
1732 { | 1742 { |
1733 visitor->trace(m_style); | 1743 visitor->trace(m_style); |
1734 visitor->trace(m_start); | 1744 visitor->trace(m_start); |
1735 visitor->trace(m_end); | 1745 visitor->trace(m_end); |
1736 visitor->trace(m_styledInlineElement); | 1746 visitor->trace(m_styledInlineElement); |
1737 CompositeEditCommand::trace(visitor); | 1747 CompositeEditCommand::trace(visitor); |
1738 } | 1748 } |
1739 | 1749 |
1740 } // namespace blink | 1750 } // namespace blink |
OLD | NEW |