| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 VisiblePosition endAfterSelection = endOfParagraph(nextPositionOf(endOfLastP
aragraph)); | 126 VisiblePosition endAfterSelection = endOfParagraph(nextPositionOf(endOfLastP
aragraph)); |
| 127 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent(); | 127 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent(); |
| 128 | 128 |
| 129 bool atEnd = false; | 129 bool atEnd = false; |
| 130 Position end; | 130 Position end; |
| 131 while (endOfCurrentParagraph.deepEquivalent() != endAfterSelection.deepEquiv
alent() && !atEnd) { | 131 while (endOfCurrentParagraph.deepEquivalent() != endAfterSelection.deepEquiv
alent() && !atEnd) { |
| 132 if (endOfCurrentParagraph.deepEquivalent() == m_endOfLastParagraph) | 132 if (endOfCurrentParagraph.deepEquivalent() == m_endOfLastParagraph) |
| 133 atEnd = true; | 133 atEnd = true; |
| 134 | 134 |
| 135 rangeForParagraphSplittingTextNodesIfNeeded(endOfCurrentParagraph, start
, end); | 135 rangeForParagraphSplittingTextNodesIfNeeded(endOfCurrentParagraph, start
, end); |
| 136 endOfCurrentParagraph = VisiblePosition(end); | 136 endOfCurrentParagraph = createVisiblePosition(end); |
| 137 | 137 |
| 138 Node* enclosingCell = enclosingNodeOfType(start, &isTableCell); | 138 Node* enclosingCell = enclosingNodeOfType(start, &isTableCell); |
| 139 VisiblePosition endOfNextParagraph = endOfNextParagrahSplittingTextNodes
IfNeeded(endOfCurrentParagraph, start, end); | 139 VisiblePosition endOfNextParagraph = endOfNextParagrahSplittingTextNodes
IfNeeded(endOfCurrentParagraph, start, end); |
| 140 | 140 |
| 141 formatRange(start, end, m_endOfLastParagraph, blockquoteForNextIndent); | 141 formatRange(start, end, m_endOfLastParagraph, blockquoteForNextIndent); |
| 142 | 142 |
| 143 // Don't put the next paragraph in the blockquote we just created for th
is paragraph unless | 143 // Don't put the next paragraph in the blockquote we just created for th
is paragraph unless |
| 144 // the next paragraph is in the same cell. | 144 // the next paragraph is in the same cell. |
| 145 if (enclosingCell && enclosingCell != enclosingNodeOfType(endOfNextParag
raph.deepEquivalent(), &isTableCell)) | 145 if (enclosingCell && enclosingCell != enclosingNodeOfType(endOfNextParag
raph.deepEquivalent(), &isTableCell)) |
| 146 blockquoteForNextIndent = nullptr; | 146 blockquoteForNextIndent = nullptr; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 bool isStartAndEndOnSameNode = false; | 190 bool isStartAndEndOnSameNode = false; |
| 191 if (const ComputedStyle* startStyle = computedStyleOfEnclosingTextNode(start
)) { | 191 if (const ComputedStyle* startStyle = computedStyleOfEnclosingTextNode(start
)) { |
| 192 isStartAndEndOnSameNode = computedStyleOfEnclosingTextNode(end) && start
.computeContainerNode() == end.computeContainerNode(); | 192 isStartAndEndOnSameNode = computedStyleOfEnclosingTextNode(end) && start
.computeContainerNode() == end.computeContainerNode(); |
| 193 bool isStartAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingTe
xtNode(m_endOfLastParagraph) && start.computeContainerNode() == m_endOfLastParag
raph.computeContainerNode(); | 193 bool isStartAndEndOfLastParagraphOnSameNode = computedStyleOfEnclosingTe
xtNode(m_endOfLastParagraph) && start.computeContainerNode() == m_endOfLastParag
raph.computeContainerNode(); |
| 194 | 194 |
| 195 // Avoid obtanining the start of next paragraph for start | 195 // Avoid obtanining the start of next paragraph for start |
| 196 // TODO(yosin) We should use |PositionMoveType::Character| for | 196 // TODO(yosin) We should use |PositionMoveType::Character| for |
| 197 // |previousPositionOf()|. | 197 // |previousPositionOf()|. |
| 198 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe
wLineAtPosition(previousPositionOf(start, PositionMoveType::CodePoint)) && start
.offsetInContainerNode() > 0) | 198 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe
wLineAtPosition(previousPositionOf(start, PositionMoveType::CodePoint)) && start
.offsetInContainerNode() > 0) |
| 199 start = startOfParagraph(VisiblePosition(previousPositionOf(end, Pos
itionMoveType::CodePoint))).deepEquivalent(); | 199 start = startOfParagraph(createVisiblePosition(previousPositionOf(en
d, PositionMoveType::CodePoint))).deepEquivalent(); |
| 200 | 200 |
| 201 // If start is in the middle of a text node, split. | 201 // If start is in the middle of a text node, split. |
| 202 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() >
0) { | 202 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() >
0) { |
| 203 int startOffset = start.offsetInContainerNode(); | 203 int startOffset = start.offsetInContainerNode(); |
| 204 Text* startText = toText(start.computeContainerNode()); | 204 Text* startText = toText(start.computeContainerNode()); |
| 205 splitTextNode(startText, startOffset); | 205 splitTextNode(startText, startOffset); |
| 206 start = firstPositionInNode(startText); | 206 start = firstPositionInNode(startText); |
| 207 if (isStartAndEndOnSameNode) { | 207 if (isStartAndEndOnSameNode) { |
| 208 ASSERT(end.offsetInContainerNode() >= startOffset); | 208 ASSERT(end.offsetInContainerNode() >= startOffset); |
| 209 end = Position(startText, end.offsetInContainerNode() - startOff
set); | 209 end = Position(startText, end.offsetInContainerNode() - startOff
set); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInCont
ainerNode()) { | 276 if (m_endOfLastParagraph.offsetInContainerNode() < position.offsetInCont
ainerNode()) { |
| 277 // We can only fix endOfLastParagraph if the previous node was still
text and hasn't been modified by script. | 277 // We can only fix endOfLastParagraph if the previous node was still
text and hasn't been modified by script. |
| 278 if (text->previousSibling()->isTextNode() | 278 if (text->previousSibling()->isTextNode() |
| 279 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerN
ode()) <= toText(text->previousSibling())->length()) | 279 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerN
ode()) <= toText(text->previousSibling())->length()) |
| 280 m_endOfLastParagraph = Position(toText(text->previousSibling()),
m_endOfLastParagraph.offsetInContainerNode()); | 280 m_endOfLastParagraph = Position(toText(text->previousSibling()),
m_endOfLastParagraph.offsetInContainerNode()); |
| 281 } else { | 281 } else { |
| 282 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.off
setInContainerNode() - 1); | 282 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.off
setInContainerNode() - 1); |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| 286 return VisiblePosition(Position(text.get(), position.offsetInContainerNode()
- 1)); | 286 return createVisiblePosition(Position(text.get(), position.offsetInContainer
Node() - 1)); |
| 287 } | 287 } |
| 288 | 288 |
| 289 PassRefPtrWillBeRawPtr<HTMLElement> ApplyBlockElementCommand::createBlockElement
() const | 289 PassRefPtrWillBeRawPtr<HTMLElement> ApplyBlockElementCommand::createBlockElement
() const |
| 290 { | 290 { |
| 291 RefPtrWillBeRawPtr<HTMLElement> element = createHTMLElement(document(), m_ta
gName); | 291 RefPtrWillBeRawPtr<HTMLElement> element = createHTMLElement(document(), m_ta
gName); |
| 292 if (m_inlineStyle.length()) | 292 if (m_inlineStyle.length()) |
| 293 element->setAttribute(styleAttr, m_inlineStyle); | 293 element->setAttribute(styleAttr, m_inlineStyle); |
| 294 return element.release(); | 294 return element.release(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 DEFINE_TRACE(ApplyBlockElementCommand) | 297 DEFINE_TRACE(ApplyBlockElementCommand) |
| 298 { | 298 { |
| 299 visitor->trace(m_endOfLastParagraph); | 299 visitor->trace(m_endOfLastParagraph); |
| 300 CompositeEditCommand::trace(visitor); | 300 CompositeEditCommand::trace(visitor); |
| 301 } | 301 } |
| 302 | 302 |
| 303 } | 303 } |
| OLD | NEW |