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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 249 |
250 // get positions we want to use for applying style | 250 // get positions we want to use for applying style |
251 Position start = startPosition(); | 251 Position start = startPosition(); |
252 Position end = endPosition(); | 252 Position end = endPosition(); |
253 if (comparePositions(end, start) < 0) { | 253 if (comparePositions(end, start) < 0) { |
254 Position swap = start; | 254 Position swap = start; |
255 start = end; | 255 start = end; |
256 end = swap; | 256 end = swap; |
257 } | 257 } |
258 | 258 |
259 VisiblePosition visibleStart = createVisiblePosition(start); | 259 VisiblePosition visibleStart = createVisiblePositionDeprecated(start); |
260 VisiblePosition visibleEnd = createVisiblePosition(end); | 260 VisiblePosition visibleEnd = createVisiblePositionDeprecated(end); |
261 | 261 |
262 if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull()
|| visibleEnd.isOrphan()) | 262 if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull()
|| visibleEnd.isOrphan()) |
263 return; | 263 return; |
264 | 264 |
265 // Save and restore the selection endpoints using their indices in the docum
ent, since | 265 // Save and restore the selection endpoints using their indices in the docum
ent, since |
266 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoint
s. | 266 // addBlockStyleIfNeeded may moveParagraphs, which can remove these endpoint
s. |
267 // Calculate start and end indices from the start of the tree that they're i
n. | 267 // Calculate start and end indices from the start of the tree that they're i
n. |
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 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; |
279 StyleChange styleChange(style, paragraphStart.deepEquivalent()); | 279 StyleChange styleChange(style, paragraphStart.deepEquivalent()); |
280 if (styleChange.cssStyle().length() || m_removeOnly) { | 280 if (styleChange.cssStyle().length() || m_removeOnly) { |
281 Element* block = enclosingBlock(paragraphStart.deepEquivalent().anch
orNode()); | 281 Element* block = enclosingBlock(paragraphStart.deepEquivalent().anch
orNode()); |
282 const Position& paragraphStartToMove = paragraphStart.deepEquivalent
(); | 282 const Position& paragraphStartToMove = paragraphStart.deepEquivalent
(); |
283 if (!m_removeOnly && isEditablePosition(paragraphStartToMove)) { | 283 if (!m_removeOnly && isEditablePosition(paragraphStartToMove)) { |
284 HTMLElement* newBlock = moveParagraphContentsToNewBlockIfNecessa
ry(paragraphStartToMove, editingState); | 284 HTMLElement* newBlock = moveParagraphContentsToNewBlockIfNecessa
ry(paragraphStartToMove, editingState); |
285 if (editingState->isAborted()) | 285 if (editingState->isAborted()) |
286 return; | 286 return; |
287 if (newBlock) { | 287 if (newBlock) { |
288 block = newBlock; | 288 block = newBlock; |
289 if (paragraphStart.isOrphan()) | 289 if (paragraphStart.isOrphan()) |
290 paragraphStart = createVisiblePosition(Position::firstPo
sitionInNode(newBlock)); | 290 paragraphStart = createVisiblePositionDeprecated(Positio
n::firstPositionInNode(newBlock)); |
291 } | 291 } |
292 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; | 292 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; |
293 } | 293 } |
294 if (block && block->isHTMLElement()) { | 294 if (block && block->isHTMLElement()) { |
295 removeCSSStyle(style, toHTMLElement(block), editingState); | 295 removeCSSStyle(style, toHTMLElement(block), editingState); |
296 if (editingState->isAborted()) | 296 if (editingState->isAborted()) |
297 return; | 297 return; |
298 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; | 298 DCHECK(!paragraphStart.isOrphan()) << paragraphStart; |
299 if (!m_removeOnly) { | 299 if (!m_removeOnly) { |
300 addBlockStyle(styleChange, toHTMLElement(block)); | 300 addBlockStyle(styleChange, toHTMLElement(block)); |
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 DEFINE_TRACE(ApplyStyleCommand) | 1756 DEFINE_TRACE(ApplyStyleCommand) |
1757 { | 1757 { |
1758 visitor->trace(m_style); | 1758 visitor->trace(m_style); |
1759 visitor->trace(m_start); | 1759 visitor->trace(m_start); |
1760 visitor->trace(m_end); | 1760 visitor->trace(m_end); |
1761 visitor->trace(m_styledInlineElement); | 1761 visitor->trace(m_styledInlineElement); |
1762 CompositeEditCommand::trace(visitor); | 1762 CompositeEditCommand::trace(visitor); |
1763 } | 1763 } |
1764 | 1764 |
1765 } // namespace blink | 1765 } // namespace blink |
OLD | NEW |