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 23 matching lines...) Expand all Loading... |
34 #include "core/editing/VisibleUnits.h" | 34 #include "core/editing/VisibleUnits.h" |
35 #include "core/editing/htmlediting.h" | 35 #include "core/editing/htmlediting.h" |
36 #include "core/html/HTMLElement.h" | 36 #include "core/html/HTMLElement.h" |
37 #include "core/rendering/RenderObject.h" | 37 #include "core/rendering/RenderObject.h" |
38 #include "core/rendering/style/RenderStyle.h" | 38 #include "core/rendering/style/RenderStyle.h" |
39 | 39 |
40 namespace WebCore { | 40 namespace WebCore { |
41 | 41 |
42 using namespace HTMLNames; | 42 using namespace HTMLNames; |
43 | 43 |
44 ApplyBlockElementCommand::ApplyBlockElementCommand(Document* document, const Qua
lifiedName& tagName, const AtomicString& inlineStyle) | 44 ApplyBlockElementCommand::ApplyBlockElementCommand(Document& document, const Qua
lifiedName& tagName, const AtomicString& inlineStyle) |
45 : CompositeEditCommand(document) | 45 : CompositeEditCommand(document) |
46 , m_tagName(tagName) | 46 , m_tagName(tagName) |
47 , m_inlineStyle(inlineStyle) | 47 , m_inlineStyle(inlineStyle) |
48 { | 48 { |
49 } | 49 } |
50 | 50 |
51 ApplyBlockElementCommand::ApplyBlockElementCommand(Document* document, const Qua
lifiedName& tagName) | 51 ApplyBlockElementCommand::ApplyBlockElementCommand(Document& document, const Qua
lifiedName& tagName) |
52 : CompositeEditCommand(document) | 52 : CompositeEditCommand(document) |
53 , m_tagName(tagName) | 53 , m_tagName(tagName) |
54 { | 54 { |
55 } | 55 } |
56 | 56 |
57 void ApplyBlockElementCommand::doApply() | 57 void ApplyBlockElementCommand::doApply() |
58 { | 58 { |
59 if (!endingSelection().rootEditableElement()) | 59 if (!endingSelection().rootEditableElement()) |
60 return; | 60 return; |
61 | 61 |
(...skipping 18 matching lines...) Expand all Loading... |
80 VisiblePosition endOfSelection = selection.visibleEnd(); | 80 VisiblePosition endOfSelection = selection.visibleEnd(); |
81 ASSERT(!startOfSelection.isNull()); | 81 ASSERT(!startOfSelection.isNull()); |
82 ASSERT(!endOfSelection.isNull()); | 82 ASSERT(!endOfSelection.isNull()); |
83 RefPtr<ContainerNode> startScope; | 83 RefPtr<ContainerNode> startScope; |
84 int startIndex = indexForVisiblePosition(startOfSelection, startScope); | 84 int startIndex = indexForVisiblePosition(startOfSelection, startScope); |
85 RefPtr<ContainerNode> endScope; | 85 RefPtr<ContainerNode> endScope; |
86 int endIndex = indexForVisiblePosition(endOfSelection, endScope); | 86 int endIndex = indexForVisiblePosition(endOfSelection, endScope); |
87 | 87 |
88 formatSelection(startOfSelection, endOfSelection); | 88 formatSelection(startOfSelection, endOfSelection); |
89 | 89 |
90 document()->updateLayoutIgnorePendingStylesheets(); | 90 document().updateLayoutIgnorePendingStylesheets(); |
91 | 91 |
92 ASSERT(startScope == endScope); | 92 ASSERT(startScope == endScope); |
93 ASSERT(startIndex >= 0); | 93 ASSERT(startIndex >= 0); |
94 ASSERT(startIndex <= endIndex); | 94 ASSERT(startIndex <= endIndex); |
95 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { | 95 if (startScope == endScope && startIndex >= 0 && startIndex <= endIndex) { |
96 VisiblePosition start(visiblePositionForIndex(startIndex, startScope.get
())); | 96 VisiblePosition start(visiblePositionForIndex(startIndex, startScope.get
())); |
97 VisiblePosition end(visiblePositionForIndex(endIndex, endScope.get())); | 97 VisiblePosition end(visiblePositionForIndex(endIndex, endScope.get())); |
98 if (start.isNotNull() && end.isNotNull()) | 98 if (start.isNotNull() && end.isNotNull()) |
99 setEndingSelection(VisibleSelection(start, end, endingSelection().is
Directional())); | 99 setEndingSelection(VisibleSelection(start, end, endingSelection().is
Directional())); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel
ection, const VisiblePosition& endOfSelection) | 103 void ApplyBlockElementCommand::formatSelection(const VisiblePosition& startOfSel
ection, const VisiblePosition& endOfSelection) |
104 { | 104 { |
105 // Special case empty unsplittable elements because there's nothing to split | 105 // Special case empty unsplittable elements because there's nothing to split |
106 // and there's nothing to move. | 106 // and there's nothing to move. |
107 Position start = startOfSelection.deepEquivalent().downstream(); | 107 Position start = startOfSelection.deepEquivalent().downstream(); |
108 if (isAtUnsplittableElement(start)) { | 108 if (isAtUnsplittableElement(start)) { |
109 RefPtr<Element> blockquote = createBlockElement(); | 109 RefPtr<Element> blockquote = createBlockElement(); |
110 insertNodeAt(blockquote, start); | 110 insertNodeAt(blockquote, start); |
111 RefPtr<Element> placeholder = createBreakElement(document()); | 111 RefPtr<Element> placeholder = createBreakElement(&document()); |
112 appendNode(placeholder, blockquote); | 112 appendNode(placeholder, blockquote); |
113 setEndingSelection(VisibleSelection(positionBeforeNode(placeholder.get()
), DOWNSTREAM, endingSelection().isDirectional())); | 113 setEndingSelection(VisibleSelection(positionBeforeNode(placeholder.get()
), DOWNSTREAM, endingSelection().isDirectional())); |
114 return; | 114 return; |
115 } | 115 } |
116 | 116 |
117 RefPtr<Element> blockquoteForNextIndent; | 117 RefPtr<Element> blockquoteForNextIndent; |
118 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); | 118 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); |
119 VisiblePosition endAfterSelection = endOfParagraph(endOfParagraph(endOfSelec
tion).next()); | 119 VisiblePosition endAfterSelection = endOfParagraph(endOfParagraph(endOfSelec
tion).next()); |
120 m_endOfLastParagraph = endOfParagraph(endOfSelection).deepEquivalent(); | 120 m_endOfLastParagraph = endOfParagraph(endOfSelection).deepEquivalent(); |
121 | 121 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 m_endOfLastParagraph = Position(toText(text->previousSibling()),
m_endOfLastParagraph.offsetInContainerNode()); | 271 m_endOfLastParagraph = Position(toText(text->previousSibling()),
m_endOfLastParagraph.offsetInContainerNode()); |
272 } else | 272 } else |
273 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.off
setInContainerNode() - 1); | 273 m_endOfLastParagraph = Position(text.get(), m_endOfLastParagraph.off
setInContainerNode() - 1); |
274 } | 274 } |
275 | 275 |
276 return Position(text.get(), position.offsetInContainerNode() - 1); | 276 return Position(text.get(), position.offsetInContainerNode() - 1); |
277 } | 277 } |
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 |