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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 setEndingSelection(VisibleSelection(start, end, endingSelection().is
Directional())); | 104 setEndingSelection(VisibleSelection(start, end, endingSelection().is
Directional())); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel
ection, const VisiblePosition& endOfSelection) | 108 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel
ection, const VisiblePosition& endOfSelection) |
109 { | 109 { |
110 // Special case empty unsplittable elements because there's nothing to split | 110 // Special case empty unsplittable elements because there's nothing to split |
111 // and there's nothing to move. | 111 // and there's nothing to move. |
112 Position start = startOfSelection.deepEquivalent().downstream(); | 112 Position start = startOfSelection.deepEquivalent().downstream(); |
113 if (isAtUnsplittableElement(start)) { | 113 if (isAtUnsplittableElement(start)) { |
114 RefPtrWillBeRawPtr<Element> blockquote = createBlockElement(); | 114 RefPtrWillBeRawPtr<HTMLElement> blockquote = createBlockElement(); |
115 insertNodeAt(blockquote, start); | 115 insertNodeAt(blockquote, start); |
116 RefPtrWillBeRawPtr<Element> placeholder = createBreakElement(document())
; | 116 RefPtrWillBeRawPtr<Element> placeholder = createBreakElement(document())
; |
117 appendNode(placeholder, blockquote); | 117 appendNode(placeholder, blockquote); |
118 setEndingSelection(VisibleSelection(positionBeforeNode(placeholder.get()
), DOWNSTREAM, endingSelection().isDirectional())); | 118 setEndingSelection(VisibleSelection(positionBeforeNode(placeholder.get()
), DOWNSTREAM, endingSelection().isDirectional())); |
119 return; | 119 return; |
120 } | 120 } |
121 | 121 |
122 RefPtrWillBeRawPtr<Element> blockquoteForNextIndent = nullptr; | 122 RefPtrWillBeRawPtr<HTMLElement> blockquoteForNextIndent = nullptr; |
123 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); | 123 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); |
124 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection); | 124 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection); |
125 VisiblePosition endAfterSelection = endOfParagraph(endOfLastParagraph.next()
); | 125 VisiblePosition endAfterSelection = endOfParagraph(endOfLastParagraph.next()
); |
126 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent(); | 126 m_endOfLastParagraph = endOfLastParagraph.deepEquivalent(); |
127 | 127 |
128 bool atEnd = false; | 128 bool atEnd = false; |
129 Position end; | 129 Position end; |
130 while (endOfCurrentParagraph != endAfterSelection && !atEnd) { | 130 while (endOfCurrentParagraph != endAfterSelection && !atEnd) { |
131 if (endOfCurrentParagraph.deepEquivalent() == m_endOfLastParagraph) | 131 if (endOfCurrentParagraph.deepEquivalent() == m_endOfLastParagraph) |
132 atEnd = true; | 132 atEnd = true; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (text->previousSibling()->isTextNode() | 273 if (text->previousSibling()->isTextNode() |
274 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerN
ode()) <= toText(text->previousSibling())->length()) | 274 && static_cast<unsigned>(m_endOfLastParagraph.offsetInContainerN
ode()) <= toText(text->previousSibling())->length()) |
275 m_endOfLastParagraph = Position(toText(text->previousSibling()),
m_endOfLastParagraph.offsetInContainerNode()); | 275 m_endOfLastParagraph = Position(toText(text->previousSibling()),
m_endOfLastParagraph.offsetInContainerNode()); |
276 } else | 276 } else |
277 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.off
setInContainerNode() - 1); | 277 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.off
setInContainerNode() - 1); |
278 } | 278 } |
279 | 279 |
280 return VisiblePosition(Position(text.get(), position.offsetInContainerNode()
- 1)); | 280 return VisiblePosition(Position(text.get(), position.offsetInContainerNode()
- 1)); |
281 } | 281 } |
282 | 282 |
283 PassRefPtrWillBeRawPtr<Element> ApplyBlockElementCommand::createBlockElement() c
onst | 283 PassRefPtrWillBeRawPtr<HTMLElement> ApplyBlockElementCommand::createBlockElement
() const |
284 { | 284 { |
285 RefPtrWillBeRawPtr<Element> element = createHTMLElement(document(), m_tagNam
e); | 285 RefPtrWillBeRawPtr<HTMLElement> element = createHTMLElement(document(), m_ta
gName); |
286 if (m_inlineStyle.length()) | 286 if (m_inlineStyle.length()) |
287 element->setAttribute(styleAttr, m_inlineStyle); | 287 element->setAttribute(styleAttr, m_inlineStyle); |
288 return element.release(); | 288 return element.release(); |
289 } | 289 } |
290 | 290 |
291 void ApplyBlockElementCommand::trace(Visitor* visitor) | 291 void ApplyBlockElementCommand::trace(Visitor* visitor) |
292 { | 292 { |
293 visitor->trace(m_endOfLastParagraph); | 293 visitor->trace(m_endOfLastParagraph); |
294 CompositeEditCommand::trace(visitor); | 294 CompositeEditCommand::trace(visitor); |
295 } | 295 } |
296 | 296 |
297 } | 297 } |
OLD | NEW |