| 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 PositionWithAffinity endOfNextParagraph = | 166 PositionWithAffinity endOfNextParagraph = |
| 167 endOfNextParagrahSplittingTextNodesIfNeeded(endOfCurrentParagraph, | 167 endOfNextParagrahSplittingTextNodesIfNeeded(endOfCurrentParagraph, |
| 168 start, end) | 168 start, end) |
| 169 .toPositionWithAffinity(); | 169 .toPositionWithAffinity(); |
| 170 | 170 |
| 171 formatRange(start, end, m_endOfLastParagraph, blockquoteForNextIndent, | 171 formatRange(start, end, m_endOfLastParagraph, blockquoteForNextIndent, |
| 172 editingState); | 172 editingState); |
| 173 if (editingState->isAborted()) | 173 if (editingState->isAborted()) |
| 174 return; | 174 return; |
| 175 | 175 |
| 176 // Don't put the next paragraph in the blockquote we just created for this p
aragraph unless | 176 // Don't put the next paragraph in the blockquote we just created for this |
| 177 // the next paragraph is in the same cell. | 177 // paragraph unless the next paragraph is in the same cell. |
| 178 if (enclosingCell && | 178 if (enclosingCell && |
| 179 enclosingCell != | 179 enclosingCell != |
| 180 enclosingNodeOfType(endOfNextParagraph.position(), &isTableCell)) | 180 enclosingNodeOfType(endOfNextParagraph.position(), &isTableCell)) |
| 181 blockquoteForNextIndent = nullptr; | 181 blockquoteForNextIndent = nullptr; |
| 182 | 182 |
| 183 // indentIntoBlockquote could move more than one paragraph if the paragraph | 183 // indentIntoBlockquote could move more than one paragraph if the paragraph |
| 184 // is in a list item or a table. As a result, endAfterSelection could refer
to a position | 184 // is in a list item or a table. As a result, endAfterSelection could refer |
| 185 // no longer in the document. | 185 // to a position no longer in the document. |
| 186 if (endAfterSelection.isNotNull() && !endAfterSelection.isConnected()) | 186 if (endAfterSelection.isNotNull() && !endAfterSelection.isConnected()) |
| 187 break; | 187 break; |
| 188 // Sanity check: Make sure our moveParagraph calls didn't remove endOfNextPa
ragraph.position().anchorNode() | 188 // Sanity check: Make sure our moveParagraph calls didn't remove |
| 189 // If somehow, e.g. mutation event handler, we did, return to prevent crashe
s. | 189 // endOfNextParagraph.position().anchorNode() If somehow, e.g. mutation |
| 190 // event handler, we did, return to prevent crashes. |
| 190 if (endOfNextParagraph.isNotNull() && | 191 if (endOfNextParagraph.isNotNull() && |
| 191 !endOfNextParagraph.position().isConnected()) | 192 !endOfNextParagraph.position().isConnected()) |
| 192 return; | 193 return; |
| 193 | 194 |
| 194 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 195 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 195 endOfCurrentParagraph = createVisiblePosition(endOfNextParagraph); | 196 endOfCurrentParagraph = createVisiblePosition(endOfNextParagraph); |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 | 199 |
| 199 static bool isNewLineAtPosition(const Position& position) { | 200 static bool isNewLineAtPosition(const Position& position) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 Position position = endOfNextParagraph.deepEquivalent(); | 329 Position position = endOfNextParagraph.deepEquivalent(); |
| 329 const ComputedStyle* style = computedStyleOfEnclosingTextNode(position); | 330 const ComputedStyle* style = computedStyleOfEnclosingTextNode(position); |
| 330 if (!style) | 331 if (!style) |
| 331 return endOfNextParagraph; | 332 return endOfNextParagraph; |
| 332 | 333 |
| 333 Text* text = toText(position.computeContainerNode()); | 334 Text* text = toText(position.computeContainerNode()); |
| 334 if (!style->preserveNewline() || !position.offsetInContainerNode() || | 335 if (!style->preserveNewline() || !position.offsetInContainerNode() || |
| 335 !isNewLineAtPosition(Position::firstPositionInNode(text))) | 336 !isNewLineAtPosition(Position::firstPositionInNode(text))) |
| 336 return endOfNextParagraph; | 337 return endOfNextParagraph; |
| 337 | 338 |
| 338 // \n at the beginning of the text node immediately following the current para
graph is trimmed by moveParagraphWithClones. | 339 // \n at the beginning of the text node immediately following the current |
| 339 // If endOfNextParagraph was pointing at this same text node, endOfNextParagra
ph will be shifted by one paragraph. | 340 // paragraph is trimmed by moveParagraphWithClones. If endOfNextParagraph was |
| 340 // Avoid this by splitting "\n" | 341 // pointing at this same text node, endOfNextParagraph will be shifted by one |
| 342 // paragraph. Avoid this by splitting "\n" |
| 341 splitTextNode(text, 1); | 343 splitTextNode(text, 1); |
| 342 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 344 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 343 | 345 |
| 344 if (text == start.computeContainerNode() && text->previousSibling() && | 346 if (text == start.computeContainerNode() && text->previousSibling() && |
| 345 text->previousSibling()->isTextNode()) { | 347 text->previousSibling()->isTextNode()) { |
| 346 DCHECK_LT(start.offsetInContainerNode(), position.offsetInContainerNode()); | 348 DCHECK_LT(start.offsetInContainerNode(), position.offsetInContainerNode()); |
| 347 start = Position(toText(text->previousSibling()), | 349 start = Position(toText(text->previousSibling()), |
| 348 start.offsetInContainerNode()); | 350 start.offsetInContainerNode()); |
| 349 } | 351 } |
| 350 if (text == end.computeContainerNode() && text->previousSibling() && | 352 if (text == end.computeContainerNode() && text->previousSibling() && |
| 351 text->previousSibling()->isTextNode()) { | 353 text->previousSibling()->isTextNode()) { |
| 352 DCHECK_LT(end.offsetInContainerNode(), position.offsetInContainerNode()); | 354 DCHECK_LT(end.offsetInContainerNode(), position.offsetInContainerNode()); |
| 353 end = | 355 end = |
| 354 Position(toText(text->previousSibling()), end.offsetInContainerNode()); | 356 Position(toText(text->previousSibling()), end.offsetInContainerNode()); |
| 355 } | 357 } |
| 356 if (text == m_endOfLastParagraph.computeContainerNode()) { | 358 if (text == m_endOfLastParagraph.computeContainerNode()) { |
| 357 if (m_endOfLastParagraph.offsetInContainerNode() < | 359 if (m_endOfLastParagraph.offsetInContainerNode() < |
| 358 position.offsetInContainerNode()) { | 360 position.offsetInContainerNode()) { |
| 359 // We can only fix endOfLastParagraph if the previous node was still text
and hasn't been modified by script. | 361 // We can only fix endOfLastParagraph if the previous node was still text |
| 362 // and hasn't been modified by script. |
| 360 if (text->previousSibling()->isTextNode() && | 363 if (text->previousSibling()->isTextNode() && |
| 361 static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerNode()) <= | 364 static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerNode()) <= |
| 362 toText(text->previousSibling())->length()) | 365 toText(text->previousSibling())->length()) |
| 363 m_endOfLastParagraph = | 366 m_endOfLastParagraph = |
| 364 Position(toText(text->previousSibling()), | 367 Position(toText(text->previousSibling()), |
| 365 m_endOfLastParagraph.offsetInContainerNode()); | 368 m_endOfLastParagraph.offsetInContainerNode()); |
| 366 } else { | 369 } else { |
| 367 m_endOfLastParagraph = | 370 m_endOfLastParagraph = |
| 368 Position(text, m_endOfLastParagraph.offsetInContainerNode() - 1); | 371 Position(text, m_endOfLastParagraph.offsetInContainerNode() - 1); |
| 369 } | 372 } |
| 370 } | 373 } |
| 371 | 374 |
| 372 return createVisiblePosition( | 375 return createVisiblePosition( |
| 373 Position(text, position.offsetInContainerNode() - 1)); | 376 Position(text, position.offsetInContainerNode() - 1)); |
| 374 } | 377 } |
| 375 | 378 |
| 376 HTMLElement* ApplyBlockElementCommand::createBlockElement() const { | 379 HTMLElement* ApplyBlockElementCommand::createBlockElement() const { |
| 377 HTMLElement* element = createHTMLElement(document(), m_tagName); | 380 HTMLElement* element = createHTMLElement(document(), m_tagName); |
| 378 if (m_inlineStyle.length()) | 381 if (m_inlineStyle.length()) |
| 379 element->setAttribute(styleAttr, m_inlineStyle); | 382 element->setAttribute(styleAttr, m_inlineStyle); |
| 380 return element; | 383 return element; |
| 381 } | 384 } |
| 382 | 385 |
| 383 DEFINE_TRACE(ApplyBlockElementCommand) { | 386 DEFINE_TRACE(ApplyBlockElementCommand) { |
| 384 visitor->trace(m_endOfLastParagraph); | 387 visitor->trace(m_endOfLastParagraph); |
| 385 CompositeEditCommand::trace(visitor); | 388 CompositeEditCommand::trace(visitor); |
| 386 } | 389 } |
| 387 | 390 |
| 388 } // namespace blink | 391 } // namespace blink |
| OLD | NEW |