| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 return node && node->layoutObject() && node->layoutObject()->isInline(); | 59 return node && node->layoutObject() && node->layoutObject()->isInline(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 | 62 |
| 63 IndentOutdentCommand::IndentOutdentCommand(Document& document, EIndentType typeO
fAction) | 63 IndentOutdentCommand::IndentOutdentCommand(Document& document, EIndentType typeO
fAction) |
| 64 : ApplyBlockElementCommand(document, blockquoteTag, "margin: 0 0 0 40px; bor
der: none; padding: 0px;") | 64 : ApplyBlockElementCommand(document, blockquoteTag, "margin: 0 0 0 40px; bor
der: none; padding: 0px;") |
| 65 , m_typeOfAction(typeOfAction) | 65 , m_typeOfAction(typeOfAction) |
| 66 { | 66 { |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P
osition& end) | 69 bool IndentOutdentCommand::tryIndentingAsListItem(const Position& start, const P
osition& end, EditingState* editingState) |
| 70 { | 70 { |
| 71 // If our selection is not inside a list, bail out. | 71 // If our selection is not inside a list, bail out. |
| 72 RefPtrWillBeRawPtr<Node> lastNodeInSelectedParagraph = start.anchorNode(); | 72 RefPtrWillBeRawPtr<Node> lastNodeInSelectedParagraph = start.anchorNode(); |
| 73 RefPtrWillBeRawPtr<HTMLElement> listElement = enclosingList(lastNodeInSelect
edParagraph.get()); | 73 RefPtrWillBeRawPtr<HTMLElement> listElement = enclosingList(lastNodeInSelect
edParagraph.get()); |
| 74 if (!listElement) | 74 if (!listElement) |
| 75 return false; | 75 return false; |
| 76 | 76 |
| 77 // 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. | 77 // 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. |
| 78 RefPtrWillBeRawPtr<Element> selectedListItem = enclosingBlock(lastNodeInSele
ctedParagraph.get()); | 78 RefPtrWillBeRawPtr<Element> selectedListItem = enclosingBlock(lastNodeInSele
ctedParagraph.get()); |
| 79 | 79 |
| 80 // FIXME: we need to deal with the case where there is no li (malformed HTML
) | 80 // FIXME: we need to deal with the case where there is no li (malformed HTML
) |
| 81 if (!isHTMLLIElement(selectedListItem)) | 81 if (!isHTMLLIElement(selectedListItem)) |
| 82 return false; | 82 return false; |
| 83 | 83 |
| 84 // FIXME: previousElementSibling does not ignore non-rendered content like <
span></span>. Should we? | 84 // FIXME: previousElementSibling does not ignore non-rendered content like <
span></span>. Should we? |
| 85 RefPtrWillBeRawPtr<Element> previousList = ElementTraversal::previousSibling
(*selectedListItem); | 85 RefPtrWillBeRawPtr<Element> previousList = ElementTraversal::previousSibling
(*selectedListItem); |
| 86 RefPtrWillBeRawPtr<Element> nextList = ElementTraversal::nextSibling(*select
edListItem); | 86 RefPtrWillBeRawPtr<Element> nextList = ElementTraversal::nextSibling(*select
edListItem); |
| 87 | 87 |
| 88 // We should calculate visible range in list item because inserting new | 88 // We should calculate visible range in list item because inserting new |
| 89 // list element will change visibility of list item, e.g. :first-child | 89 // list element will change visibility of list item, e.g. :first-child |
| 90 // CSS selector. | 90 // CSS selector. |
| 91 RefPtrWillBeRawPtr<HTMLElement> newList = toHTMLElement(document().createEle
ment(listElement->tagQName(), false).get()); | 91 RefPtrWillBeRawPtr<HTMLElement> newList = toHTMLElement(document().createEle
ment(listElement->tagQName(), false).get()); |
| 92 insertNodeBefore(newList, selectedListItem.get()); | 92 insertNodeBefore(newList, selectedListItem.get(), editingState); |
| 93 if (editingState->isAborted()) |
| 94 return false; |
| 93 | 95 |
| 94 // We should clone all the children of the list item for indenting purposes.
However, in case the current | 96 // We should clone all the children of the list item for indenting purposes.
However, in case the current |
| 95 // selection does not encompass all its children, we need to explicitally ha
ndle the same. The original | 97 // selection does not encompass all its children, we need to explicitally ha
ndle the same. The original |
| 96 // list item too would require proper deletion in that case. | 98 // list item too would require proper deletion in that case. |
| 97 if (end.anchorNode() == selectedListItem.get() || end.anchorNode()->isDescen
dantOf(selectedListItem->lastChild())) { | 99 if (end.anchorNode() == selectedListItem.get() || end.anchorNode()->isDescen
dantOf(selectedListItem->lastChild())) { |
| 98 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit
ion(end), newList.get(), selectedListItem.get()); | 100 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit
ion(end), newList.get(), selectedListItem.get(), editingState); |
| 99 } else { | 101 } else { |
| 100 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit
ion(positionAfterNode(selectedListItem->lastChild())), newList.get(), selectedLi
stItem.get()); | 102 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit
ion(positionAfterNode(selectedListItem->lastChild())), newList.get(), selectedLi
stItem.get(), editingState); |
| 101 removeNode(selectedListItem.get()); | 103 if (editingState->isAborted()) |
| 104 return false; |
| 105 removeNode(selectedListItem.get(), editingState); |
| 102 } | 106 } |
| 107 if (editingState->isAborted()) |
| 108 return false; |
| 103 | 109 |
| 104 if (canMergeLists(previousList.get(), newList.get())) | 110 if (canMergeLists(previousList.get(), newList.get())) { |
| 105 mergeIdenticalElements(previousList.get(), newList.get()); | 111 mergeIdenticalElements(previousList.get(), newList.get(), editingState); |
| 106 if (canMergeLists(newList.get(), nextList.get())) | 112 if (editingState->isAborted()) |
| 107 mergeIdenticalElements(newList.get(), nextList.get()); | 113 return false; |
| 114 } |
| 115 if (canMergeLists(newList.get(), nextList.get())) { |
| 116 mergeIdenticalElements(newList.get(), nextList.get(), editingState); |
| 117 if (editingState->isAborted()) |
| 118 return false; |
| 119 } |
| 108 | 120 |
| 109 return true; | 121 return true; |
| 110 } | 122 } |
| 111 | 123 |
| 112 void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos
ition& end, RefPtrWillBeRawPtr<HTMLElement>& targetBlockquote, EditingState* edi
tingState) | 124 void IndentOutdentCommand::indentIntoBlockquote(const Position& start, const Pos
ition& end, RefPtrWillBeRawPtr<HTMLElement>& targetBlockquote, EditingState* edi
tingState) |
| 113 { | 125 { |
| 114 Element* enclosingCell = toElement(enclosingNodeOfType(start, &isTableCell))
; | 126 Element* enclosingCell = toElement(enclosingNodeOfType(start, &isTableCell))
; |
| 115 Element* elementToSplitTo; | 127 Element* elementToSplitTo; |
| 116 if (enclosingCell) | 128 if (enclosingCell) |
| 117 elementToSplitTo = enclosingCell; | 129 elementToSplitTo = enclosingCell; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti
on, const VisiblePosition& endOfSelection, EditingState* editingState) | 266 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti
on, const VisiblePosition& endOfSelection, EditingState* editingState) |
| 255 { | 267 { |
| 256 if (m_typeOfAction == Indent) | 268 if (m_typeOfAction == Indent) |
| 257 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti
on, editingState); | 269 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti
on, editingState); |
| 258 else | 270 else |
| 259 outdentRegion(startOfSelection, endOfSelection); | 271 outdentRegion(startOfSelection, endOfSelection); |
| 260 } | 272 } |
| 261 | 273 |
| 262 void IndentOutdentCommand::formatRange(const Position& start, const Position& en
d, const Position&, RefPtrWillBeRawPtr<HTMLElement>& blockquoteForNextIndent, Ed
itingState* editingState) | 274 void IndentOutdentCommand::formatRange(const Position& start, const Position& en
d, const Position&, RefPtrWillBeRawPtr<HTMLElement>& blockquoteForNextIndent, Ed
itingState* editingState) |
| 263 { | 275 { |
| 264 if (tryIndentingAsListItem(start, end)) | 276 bool indentingAsListItemResult = tryIndentingAsListItem(start, end, editingS
tate); |
| 277 if (editingState->isAborted()) |
| 278 return; |
| 279 if (indentingAsListItemResult) |
| 265 blockquoteForNextIndent = nullptr; | 280 blockquoteForNextIndent = nullptr; |
| 266 else | 281 else |
| 267 indentIntoBlockquote(start, end, blockquoteForNextIndent, editingState); | 282 indentIntoBlockquote(start, end, blockquoteForNextIndent, editingState); |
| 268 } | 283 } |
| 269 | 284 |
| 270 } // namespace blink | 285 } // namespace blink |
| OLD | NEW |