| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (position.anchorType() != Position::PositionIsOffsetInAnchor || !position
.containerNode() || !position.containerNode()->isTextNode()) | 173 if (position.anchorType() != Position::PositionIsOffsetInAnchor || !position
.containerNode() || !position.containerNode()->isTextNode()) |
| 174 return 0; | 174 return 0; |
| 175 return position.containerNode()->renderStyle(); | 175 return position.containerNode()->renderStyle(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const
VisiblePosition& endOfCurrentParagraph, Position& start, Position& end) | 178 void ApplyBlockElementCommand::rangeForParagraphSplittingTextNodesIfNeeded(const
VisiblePosition& endOfCurrentParagraph, Position& start, Position& end) |
| 179 { | 179 { |
| 180 start = startOfParagraph(endOfCurrentParagraph).deepEquivalent(); | 180 start = startOfParagraph(endOfCurrentParagraph).deepEquivalent(); |
| 181 end = endOfCurrentParagraph.deepEquivalent(); | 181 end = endOfCurrentParagraph.deepEquivalent(); |
| 182 | 182 |
| 183 document().updateStyleIfNeeded(); | 183 document().updateRenderTreeIfNeeded(); |
| 184 | 184 |
| 185 bool isStartAndEndOnSameNode = false; | 185 bool isStartAndEndOnSameNode = false; |
| 186 if (RenderStyle* startStyle = renderStyleOfEnclosingTextNode(start)) { | 186 if (RenderStyle* startStyle = renderStyleOfEnclosingTextNode(start)) { |
| 187 isStartAndEndOnSameNode = renderStyleOfEnclosingTextNode(end) && start.c
ontainerNode() == end.containerNode(); | 187 isStartAndEndOnSameNode = renderStyleOfEnclosingTextNode(end) && start.c
ontainerNode() == end.containerNode(); |
| 188 bool isStartAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingText
Node(m_endOfLastParagraph) && start.containerNode() == m_endOfLastParagraph.cont
ainerNode(); | 188 bool isStartAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingText
Node(m_endOfLastParagraph) && start.containerNode() == m_endOfLastParagraph.cont
ainerNode(); |
| 189 | 189 |
| 190 // Avoid obtanining the start of next paragraph for start | 190 // Avoid obtanining the start of next paragraph for start |
| 191 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe
wLineAtPosition(start.previous()) && start.offsetInContainerNode() > 0) | 191 if (startStyle->preserveNewline() && isNewLineAtPosition(start) && !isNe
wLineAtPosition(start.previous()) && start.offsetInContainerNode() > 0) |
| 192 start = startOfParagraph(VisiblePosition(end.previous())).deepEquiva
lent(); | 192 start = startOfParagraph(VisiblePosition(end.previous())).deepEquiva
lent(); |
| 193 | 193 |
| 194 // If start is in the middle of a text node, split. | 194 // If start is in the middle of a text node, split. |
| 195 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() >
0) { | 195 if (!startStyle->collapseWhiteSpace() && start.offsetInContainerNode() >
0) { |
| 196 int startOffset = start.offsetInContainerNode(); | 196 int startOffset = start.offsetInContainerNode(); |
| 197 Text* startText = start.containerText(); | 197 Text* startText = start.containerText(); |
| 198 splitTextNode(startText, startOffset); | 198 splitTextNode(startText, startOffset); |
| 199 start = firstPositionInNode(startText); | 199 start = firstPositionInNode(startText); |
| 200 if (isStartAndEndOnSameNode) { | 200 if (isStartAndEndOnSameNode) { |
| 201 ASSERT(end.offsetInContainerNode() >= startOffset); | 201 ASSERT(end.offsetInContainerNode() >= startOffset); |
| 202 end = Position(startText, end.offsetInContainerNode() - startOff
set); | 202 end = Position(startText, end.offsetInContainerNode() - startOff
set); |
| 203 } | 203 } |
| 204 if (isStartAndEndOfLastParagraphOnSameNode) { | 204 if (isStartAndEndOfLastParagraphOnSameNode) { |
| 205 ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffs
et); | 205 ASSERT(m_endOfLastParagraph.offsetInContainerNode() >= startOffs
et); |
| 206 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph.
offsetInContainerNode() - startOffset); | 206 m_endOfLastParagraph = Position(startText, m_endOfLastParagraph.
offsetInContainerNode() - startOffset); |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 document().updateStyleIfNeeded(); | 211 document().updateRenderTreeIfNeeded(); |
| 212 | 212 |
| 213 if (RenderStyle* endStyle = renderStyleOfEnclosingTextNode(end)) { | 213 if (RenderStyle* endStyle = renderStyleOfEnclosingTextNode(end)) { |
| 214 bool isEndAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNo
de(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.depreca
tedNode(); | 214 bool isEndAndEndOfLastParagraphOnSameNode = renderStyleOfEnclosingTextNo
de(m_endOfLastParagraph) && end.deprecatedNode() == m_endOfLastParagraph.depreca
tedNode(); |
| 215 // Include \n at the end of line if we're at an empty paragraph | 215 // Include \n at the end of line if we're at an empty paragraph |
| 216 if (endStyle->preserveNewline() && start == end && end.offsetInContainer
Node() < end.containerNode()->maxCharacterOffset()) { | 216 if (endStyle->preserveNewline() && start == end && end.offsetInContainer
Node() < end.containerNode()->maxCharacterOffset()) { |
| 217 int endOffset = end.offsetInContainerNode(); | 217 int endOffset = end.offsetInContainerNode(); |
| 218 if (!isNewLineAtPosition(end.previous()) && isNewLineAtPosition(end)
) | 218 if (!isNewLineAtPosition(end.previous()) && isNewLineAtPosition(end)
) |
| 219 end = Position(end.containerText(), endOffset + 1); | 219 end = Position(end.containerText(), endOffset + 1); |
| 220 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNod
e() >= m_endOfLastParagraph.offsetInContainerNode()) | 220 if (isEndAndEndOfLastParagraphOnSameNode && end.offsetInContainerNod
e() >= m_endOfLastParagraph.offsetInContainerNode()) |
| 221 m_endOfLastParagraph = end; | 221 m_endOfLastParagraph = end; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 PassRefPtr<Element> ApplyBlockElementCommand::createBlockElement() const | 279 PassRefPtr<Element> ApplyBlockElementCommand::createBlockElement() const |
| 280 { | 280 { |
| 281 RefPtr<Element> element = createHTMLElement(document(), m_tagName); | 281 RefPtr<Element> element = createHTMLElement(document(), m_tagName); |
| 282 if (m_inlineStyle.length()) | 282 if (m_inlineStyle.length()) |
| 283 element->setAttribute(styleAttr, m_inlineStyle); | 283 element->setAttribute(styleAttr, m_inlineStyle); |
| 284 return element.release(); | 284 return element.release(); |
| 285 } | 285 } |
| 286 | 286 |
| 287 } | 287 } |
| OLD | NEW |