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 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 IndentOutdentCommand::IndentOutdentCommand(Document& document, EIndentType typeO
fAction) | 47 IndentOutdentCommand::IndentOutdentCommand(Document& document, EIndentType typeO
fAction) |
48 : ApplyBlockElementCommand(document, blockquoteTag, "margin: 0 0 0 40px; bor
der: none; padding: 0px;") | 48 : ApplyBlockElementCommand(document, blockquoteTag, "margin: 0 0 0 40px; bor
der: none; padding: 0px;") |
49 , m_typeOfAction(typeOfAction) | 49 , m_typeOfAction(typeOfAction) |
50 { | 50 { |
51 } | 51 } |
52 | 52 |
53 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P
osition& end) | 53 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P
osition& end) |
54 { | 54 { |
55 // If our selection is not inside a list, bail out. | 55 // If our selection is not inside a list, bail out. |
56 RefPtr<Node> lastNodeInSelectedParagraph = start.deprecatedNode(); | 56 RefPtrWillBeRawPtr<Node> lastNodeInSelectedParagraph = start.deprecatedNode(
); |
57 RefPtr<Element> listNode = enclosingList(lastNodeInSelectedParagraph.get()); | 57 RefPtrWillBeRawPtr<Element> listNode = enclosingList(lastNodeInSelectedParag
raph.get()); |
58 if (!listNode) | 58 if (!listNode) |
59 return false; | 59 return false; |
60 | 60 |
61 // Find the block that we want to indent. If it's not a list item (e.g., a
div inside a list item), we bail out. | 61 // Find the block that we want to indent. If it's not a list item (e.g., a
div inside a list item), we bail out. |
62 RefPtr<Element> selectedListItem = enclosingBlock(lastNodeInSelectedParagrap
h.get()); | 62 RefPtrWillBeRawPtr<Element> selectedListItem = enclosingBlock(lastNodeInSele
ctedParagraph.get()); |
63 | 63 |
64 // FIXME: we need to deal with the case where there is no li (malformed HTML
) | 64 // FIXME: we need to deal with the case where there is no li (malformed HTML
) |
65 if (!selectedListItem || !isHTMLLIElement(*selectedListItem)) | 65 if (!selectedListItem || !isHTMLLIElement(*selectedListItem)) |
66 return false; | 66 return false; |
67 | 67 |
68 // FIXME: previousElementSibling does not ignore non-rendered content like <
span></span>. Should we? | 68 // FIXME: previousElementSibling does not ignore non-rendered content like <
span></span>. Should we? |
69 RefPtr<Element> previousList = ElementTraversal::previousSibling(*selectedLi
stItem); | 69 RefPtrWillBeRawPtr<Element> previousList = ElementTraversal::previousSibling
(*selectedListItem); |
70 RefPtr<Element> nextList = ElementTraversal::nextSibling(*selectedListItem); | 70 RefPtrWillBeRawPtr<Element> nextList = ElementTraversal::nextSibling(*select
edListItem); |
71 | 71 |
72 // We should calculate visible range in list item because inserting new | 72 // We should calculate visible range in list item because inserting new |
73 // list element will change visibility of list item, e.g. :first-child | 73 // list element will change visibility of list item, e.g. :first-child |
74 // CSS selector. | 74 // CSS selector. |
75 RefPtrWillBeRawPtr<Element> newList = document().createElement(listNode->tag
QName(), false); | 75 RefPtrWillBeRawPtr<Element> newList = document().createElement(listNode->tag
QName(), false); |
76 insertNodeBefore(newList, selectedListItem.get()); | 76 insertNodeBefore(newList, selectedListItem.get()); |
77 | 77 |
78 // We should clone all the children of the list item for indenting purposes.
However, in case the current | 78 // We should clone all the children of the list item for indenting purposes.
However, in case the current |
79 // selection does not encompass all its children, we need to explicitally ha
ndle the same. The original | 79 // selection does not encompass all its children, we need to explicitally ha
ndle the same. The original |
80 // list item too would require proper deletion in that case. | 80 // list item too would require proper deletion in that case. |
81 if (end.anchorNode() == selectedListItem.get() || end.anchorNode()->isDescen
dantOf(selectedListItem->lastChild())) { | 81 if (end.anchorNode() == selectedListItem.get() || end.anchorNode()->isDescen
dantOf(selectedListItem->lastChild())) { |
82 moveParagraphWithClones(VisiblePosition(start), VisiblePosition(end), ne
wList.get(), selectedListItem.get()); | 82 moveParagraphWithClones(VisiblePosition(start), VisiblePosition(end), ne
wList.get(), selectedListItem.get()); |
83 } else { | 83 } else { |
84 moveParagraphWithClones(VisiblePosition(start), VisiblePosition(position
AfterNode(selectedListItem->lastChild())), newList.get(), selectedListItem.get()
); | 84 moveParagraphWithClones(VisiblePosition(start), VisiblePosition(position
AfterNode(selectedListItem->lastChild())), newList.get(), selectedListItem.get()
); |
85 removeNode(selectedListItem.get()); | 85 removeNode(selectedListItem.get()); |
86 } | 86 } |
87 | 87 |
88 if (canMergeLists(previousList.get(), newList.get())) | 88 if (canMergeLists(previousList.get(), newList.get())) |
89 mergeIdenticalElements(previousList.get(), newList.get()); | 89 mergeIdenticalElements(previousList.get(), newList.get()); |
90 if (canMergeLists(newList.get(), nextList.get())) | 90 if (canMergeLists(newList.get(), nextList.get())) |
91 mergeIdenticalElements(newList.get(), nextList.get()); | 91 mergeIdenticalElements(newList.get(), nextList.get()); |
92 | 92 |
93 return true; | 93 return true; |
94 } | 94 } |
95 | 95 |
96 void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos
ition& end, RefPtr<Element>& targetBlockquote) | 96 void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos
ition& end, RefPtrWillBeRawPtr<Element>& targetBlockquote) |
97 { | 97 { |
98 Node* enclosingCell = enclosingNodeOfType(start, &isTableCell); | 98 Node* enclosingCell = enclosingNodeOfType(start, &isTableCell); |
99 Node* nodeToSplitTo; | 99 Node* nodeToSplitTo; |
100 if (enclosingCell) | 100 if (enclosingCell) |
101 nodeToSplitTo = enclosingCell; | 101 nodeToSplitTo = enclosingCell; |
102 else if (enclosingList(start.containerNode())) | 102 else if (enclosingList(start.containerNode())) |
103 nodeToSplitTo = enclosingBlock(start.containerNode()); | 103 nodeToSplitTo = enclosingBlock(start.containerNode()); |
104 else | 104 else |
105 nodeToSplitTo = editableRootForPosition(start); | 105 nodeToSplitTo = editableRootForPosition(start); |
106 | 106 |
107 if (!nodeToSplitTo) | 107 if (!nodeToSplitTo) |
108 return; | 108 return; |
109 | 109 |
110 RefPtr<Node> outerBlock = (start.containerNode() == nodeToSplitTo) ? start.c
ontainerNode() : splitTreeToNode(start.containerNode(), nodeToSplitTo); | 110 RefPtrWillBeRawPtr<Node> outerBlock = (start.containerNode() == nodeToSplitT
o) ? start.containerNode() : splitTreeToNode(start.containerNode(), nodeToSplitT
o).get(); |
111 | 111 |
112 VisiblePosition startOfContents(start); | 112 VisiblePosition startOfContents(start); |
113 if (!targetBlockquote) { | 113 if (!targetBlockquote) { |
114 // Create a new blockquote and insert it as a child of the root editable
element. We accomplish | 114 // Create a new blockquote and insert it as a child of the root editable
element. We accomplish |
115 // this by splitting all parents of the current paragraph up to that poi
nt. | 115 // this by splitting all parents of the current paragraph up to that poi
nt. |
116 targetBlockquote = createBlockElement(); | 116 targetBlockquote = createBlockElement(); |
117 if (outerBlock == start.containerNode()) | 117 if (outerBlock == start.containerNode()) |
118 insertNodeAt(targetBlockquote, start); | 118 insertNodeAt(targetBlockquote, start); |
119 else | 119 else |
120 insertNodeBefore(targetBlockquote, outerBlock); | 120 insertNodeBefore(targetBlockquote, outerBlock); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 visibleStartOfParagraph = VisiblePosition(visibleStartOfParagraph.deepEq
uivalent()); | 170 visibleStartOfParagraph = VisiblePosition(visibleStartOfParagraph.deepEq
uivalent()); |
171 visibleEndOfParagraph = VisiblePosition(visibleEndOfParagraph.deepEquiva
lent()); | 171 visibleEndOfParagraph = VisiblePosition(visibleEndOfParagraph.deepEquiva
lent()); |
172 if (visibleStartOfParagraph.isNotNull() && !isStartOfParagraph(visibleSt
artOfParagraph)) | 172 if (visibleStartOfParagraph.isNotNull() && !isStartOfParagraph(visibleSt
artOfParagraph)) |
173 insertNodeAt(createBreakElement(document()), visibleStartOfParagraph
.deepEquivalent()); | 173 insertNodeAt(createBreakElement(document()), visibleStartOfParagraph
.deepEquivalent()); |
174 if (visibleEndOfParagraph.isNotNull() && !isEndOfParagraph(visibleEndOfP
aragraph)) | 174 if (visibleEndOfParagraph.isNotNull() && !isEndOfParagraph(visibleEndOfP
aragraph)) |
175 insertNodeAt(createBreakElement(document()), visibleEndOfParagraph.d
eepEquivalent()); | 175 insertNodeAt(createBreakElement(document()), visibleEndOfParagraph.d
eepEquivalent()); |
176 | 176 |
177 return; | 177 return; |
178 } | 178 } |
179 Node* enclosingBlockFlow = enclosingBlock(visibleStartOfParagraph.deepEquiva
lent().deprecatedNode()); | 179 Node* enclosingBlockFlow = enclosingBlock(visibleStartOfParagraph.deepEquiva
lent().deprecatedNode()); |
180 RefPtr<Node> splitBlockquoteNode = enclosingNode; | 180 RefPtrWillBeRawPtr<Node> splitBlockquoteNode = enclosingNode; |
181 if (enclosingBlockFlow != enclosingNode) | 181 if (enclosingBlockFlow != enclosingNode) |
182 splitBlockquoteNode = splitTreeToNode(enclosingBlockFlow, enclosingNode,
true); | 182 splitBlockquoteNode = splitTreeToNode(enclosingBlockFlow, enclosingNode,
true); |
183 else { | 183 else { |
184 // We split the blockquote at where we start outdenting. | 184 // We split the blockquote at where we start outdenting. |
185 Node* highestInlineNode = highestEnclosingNodeOfType(visibleStartOfParag
raph.deepEquivalent(), isInline, CannotCrossEditingBoundary, enclosingBlockFlow)
; | 185 Node* highestInlineNode = highestEnclosingNodeOfType(visibleStartOfParag
raph.deepEquivalent(), isInline, CannotCrossEditingBoundary, enclosingBlockFlow)
; |
186 splitElement(toElement(enclosingNode), (highestInlineNode) ? highestInli
neNode : visibleStartOfParagraph.deepEquivalent().deprecatedNode()); | 186 splitElement(toElement(enclosingNode), (highestInlineNode) ? highestInli
neNode : visibleStartOfParagraph.deepEquivalent().deprecatedNode()); |
187 } | 187 } |
188 RefPtr<Node> placeholder = createBreakElement(document()); | 188 RefPtrWillBeRawPtr<Node> placeholder = createBreakElement(document()); |
189 insertNodeBefore(placeholder, splitBlockquoteNode); | 189 insertNodeBefore(placeholder, splitBlockquoteNode); |
190 moveParagraph(startOfParagraph(visibleStartOfParagraph), endOfParagraph(visi
bleEndOfParagraph), VisiblePosition(positionBeforeNode(placeholder.get())), true
); | 190 moveParagraph(startOfParagraph(visibleStartOfParagraph), endOfParagraph(visi
bleEndOfParagraph), VisiblePosition(positionBeforeNode(placeholder.get())), true
); |
191 } | 191 } |
192 | 192 |
193 // FIXME: We should merge this function with ApplyBlockElementCommand::formatSel
ection | 193 // FIXME: We should merge this function with ApplyBlockElementCommand::formatSel
ection |
194 void IndentOutdentCommand::outdentRegion(const VisiblePosition& startOfSelection
, const VisiblePosition& endOfSelection) | 194 void IndentOutdentCommand::outdentRegion(const VisiblePosition& startOfSelection
, const VisiblePosition& endOfSelection) |
195 { | 195 { |
196 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); | 196 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); |
197 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection); | 197 VisiblePosition endOfLastParagraph = endOfParagraph(endOfSelection); |
198 | 198 |
(...skipping 29 matching lines...) Expand all Loading... |
228 } | 228 } |
229 | 229 |
230 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti
on, const VisiblePosition& endOfSelection) | 230 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti
on, const VisiblePosition& endOfSelection) |
231 { | 231 { |
232 if (m_typeOfAction == Indent) | 232 if (m_typeOfAction == Indent) |
233 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti
on); | 233 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti
on); |
234 else | 234 else |
235 outdentRegion(startOfSelection, endOfSelection); | 235 outdentRegion(startOfSelection, endOfSelection); |
236 } | 236 } |
237 | 237 |
238 void IndentOutdentCommand::formatRange(const Position& start, const Position& en
d, const Position&, RefPtr<Element>& blockquoteForNextIndent) | 238 void IndentOutdentCommand::formatRange(const Position& start, const Position& en
d, const Position&, RefPtrWillBeRawPtr<Element>& blockquoteForNextIndent) |
239 { | 239 { |
240 if (tryIndentingAsListItem(start, end)) | 240 if (tryIndentingAsListItem(start, end)) |
241 blockquoteForNextIndent = nullptr; | 241 blockquoteForNextIndent = nullptr; |
242 else | 242 else |
243 indentIntoBlockquote(start, end, blockquoteForNextIndent); | 243 indentIntoBlockquote(start, end, blockquoteForNextIndent); |
244 } | 244 } |
245 | 245 |
246 } | 246 } |
OLD | NEW |