| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, EditingState* editingState) | 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 RawPtr<Node> lastNodeInSelectedParagraph = start.anchorNode(); |
| 73 RefPtrWillBeRawPtr<HTMLElement> listElement = enclosingList(lastNodeInSelect
edParagraph.get()); | 73 RawPtr<HTMLElement> listElement = enclosingList(lastNodeInSelectedParagraph.
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 RawPtr<Element> selectedListItem = enclosingBlock(lastNodeInSelectedParagrap
h.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 RawPtr<Element> previousList = ElementTraversal::previousSibling(*selectedLi
stItem); |
| 86 RefPtrWillBeRawPtr<Element> nextList = ElementTraversal::nextSibling(*select
edListItem); | 86 RawPtr<Element> nextList = ElementTraversal::nextSibling(*selectedListItem); |
| 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 RawPtr<HTMLElement> newList = toHTMLElement(document().createElement(listEle
ment->tagQName(), false).get()); |
| 92 insertNodeBefore(newList, selectedListItem.get(), editingState); | 92 insertNodeBefore(newList, selectedListItem.get(), editingState); |
| 93 if (editingState->isAborted()) | 93 if (editingState->isAborted()) |
| 94 return false; | 94 return false; |
| 95 | 95 |
| 96 // 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 |
| 97 // 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 |
| 98 // list item too would require proper deletion in that case. | 98 // list item too would require proper deletion in that case. |
| 99 if (end.anchorNode() == selectedListItem.get() || end.anchorNode()->isDescen
dantOf(selectedListItem->lastChild())) { | 99 if (end.anchorNode() == selectedListItem.get() || end.anchorNode()->isDescen
dantOf(selectedListItem->lastChild())) { |
| 100 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit
ion(end), newList.get(), selectedListItem.get(), editingState); | 100 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosit
ion(end), newList.get(), selectedListItem.get(), editingState); |
| 101 } else { | 101 } else { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 } | 114 } |
| 115 if (canMergeLists(newList.get(), nextList.get())) { | 115 if (canMergeLists(newList.get(), nextList.get())) { |
| 116 mergeIdenticalElements(newList.get(), nextList.get(), editingState); | 116 mergeIdenticalElements(newList.get(), nextList.get(), editingState); |
| 117 if (editingState->isAborted()) | 117 if (editingState->isAborted()) |
| 118 return false; | 118 return false; |
| 119 } | 119 } |
| 120 | 120 |
| 121 return true; | 121 return true; |
| 122 } | 122 } |
| 123 | 123 |
| 124 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, RawPtr<HTMLElement>& targetBlockquote, EditingState* editingState) |
| 125 { | 125 { |
| 126 Element* enclosingCell = toElement(enclosingNodeOfType(start, &isTableCell))
; | 126 Element* enclosingCell = toElement(enclosingNodeOfType(start, &isTableCell))
; |
| 127 Element* elementToSplitTo; | 127 Element* elementToSplitTo; |
| 128 if (enclosingCell) | 128 if (enclosingCell) |
| 129 elementToSplitTo = enclosingCell; | 129 elementToSplitTo = enclosingCell; |
| 130 else if (enclosingList(start.computeContainerNode())) | 130 else if (enclosingList(start.computeContainerNode())) |
| 131 elementToSplitTo = enclosingBlock(start.computeContainerNode()); | 131 elementToSplitTo = enclosingBlock(start.computeContainerNode()); |
| 132 else | 132 else |
| 133 elementToSplitTo = rootEditableElementOf(start); | 133 elementToSplitTo = rootEditableElementOf(start); |
| 134 | 134 |
| 135 if (!elementToSplitTo) | 135 if (!elementToSplitTo) |
| 136 return; | 136 return; |
| 137 | 137 |
| 138 RefPtrWillBeRawPtr<Node> outerBlock = (start.computeContainerNode() == eleme
ntToSplitTo) ? start.computeContainerNode() : splitTreeToNode(start.computeConta
inerNode(), elementToSplitTo).get(); | 138 RawPtr<Node> outerBlock = (start.computeContainerNode() == elementToSplitTo)
? start.computeContainerNode() : splitTreeToNode(start.computeContainerNode(),
elementToSplitTo).get(); |
| 139 | 139 |
| 140 VisiblePosition startOfContents = createVisiblePosition(start); | 140 VisiblePosition startOfContents = createVisiblePosition(start); |
| 141 if (!targetBlockquote) { | 141 if (!targetBlockquote) { |
| 142 // Create a new blockquote and insert it as a child of the root editable
element. We accomplish | 142 // Create a new blockquote and insert it as a child of the root editable
element. We accomplish |
| 143 // this by splitting all parents of the current paragraph up to that poi
nt. | 143 // this by splitting all parents of the current paragraph up to that poi
nt. |
| 144 targetBlockquote = createBlockElement(); | 144 targetBlockquote = createBlockElement(); |
| 145 if (outerBlock == start.computeContainerNode()) | 145 if (outerBlock == start.computeContainerNode()) |
| 146 insertNodeAt(targetBlockquote, start, editingState); | 146 insertNodeAt(targetBlockquote, start, editingState); |
| 147 else | 147 else |
| 148 insertNodeBefore(targetBlockquote, outerBlock, editingState); | 148 insertNodeBefore(targetBlockquote, outerBlock, editingState); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 visibleEndOfParagraph = createVisiblePosition(visibleEndOfParagraph.deep
Equivalent()); | 206 visibleEndOfParagraph = createVisiblePosition(visibleEndOfParagraph.deep
Equivalent()); |
| 207 if (visibleStartOfParagraph.isNotNull() && !isStartOfParagraph(visibleSt
artOfParagraph)) { | 207 if (visibleStartOfParagraph.isNotNull() && !isStartOfParagraph(visibleSt
artOfParagraph)) { |
| 208 insertNodeAt(HTMLBRElement::create(document()), visibleStartOfParagr
aph.deepEquivalent(), editingState); | 208 insertNodeAt(HTMLBRElement::create(document()), visibleStartOfParagr
aph.deepEquivalent(), editingState); |
| 209 if (editingState->isAborted()) | 209 if (editingState->isAborted()) |
| 210 return; | 210 return; |
| 211 } | 211 } |
| 212 if (visibleEndOfParagraph.isNotNull() && !isEndOfParagraph(visibleEndOfP
aragraph)) | 212 if (visibleEndOfParagraph.isNotNull() && !isEndOfParagraph(visibleEndOfP
aragraph)) |
| 213 insertNodeAt(HTMLBRElement::create(document()), visibleEndOfParagrap
h.deepEquivalent(), editingState); | 213 insertNodeAt(HTMLBRElement::create(document()), visibleEndOfParagrap
h.deepEquivalent(), editingState); |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 RefPtrWillBeRawPtr<Node> splitBlockquoteNode = enclosingElement; | 216 RawPtr<Node> splitBlockquoteNode = enclosingElement; |
| 217 if (Element* enclosingBlockFlow = enclosingBlock(visibleStartOfParagraph.dee
pEquivalent().anchorNode())) { | 217 if (Element* enclosingBlockFlow = enclosingBlock(visibleStartOfParagraph.dee
pEquivalent().anchorNode())) { |
| 218 if (enclosingBlockFlow != enclosingElement) { | 218 if (enclosingBlockFlow != enclosingElement) { |
| 219 splitBlockquoteNode = splitTreeToNode(enclosingBlockFlow, enclosingE
lement, true); | 219 splitBlockquoteNode = splitTreeToNode(enclosingBlockFlow, enclosingE
lement, true); |
| 220 } else { | 220 } else { |
| 221 // We split the blockquote at where we start outdenting. | 221 // We split the blockquote at where we start outdenting. |
| 222 Node* highestInlineNode = highestEnclosingNodeOfType(visibleStartOfP
aragraph.deepEquivalent(), isInline, CannotCrossEditingBoundary, enclosingBlockF
low); | 222 Node* highestInlineNode = highestEnclosingNodeOfType(visibleStartOfP
aragraph.deepEquivalent(), isInline, CannotCrossEditingBoundary, enclosingBlockF
low); |
| 223 splitElement(enclosingElement, highestInlineNode ? highestInlineNode
: visibleStartOfParagraph.deepEquivalent().anchorNode()); | 223 splitElement(enclosingElement, highestInlineNode ? highestInlineNode
: visibleStartOfParagraph.deepEquivalent().anchorNode()); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 VisiblePosition startOfParagraphToMove = startOfParagraph(visibleStartOfPara
graph); | 226 VisiblePosition startOfParagraphToMove = startOfParagraph(visibleStartOfPara
graph); |
| 227 VisiblePosition endOfParagraphToMove = endOfParagraph(visibleEndOfParagraph)
; | 227 VisiblePosition endOfParagraphToMove = endOfParagraph(visibleEndOfParagraph)
; |
| 228 if (startOfParagraphToMove.isNull() || endOfParagraphToMove.isNull()) | 228 if (startOfParagraphToMove.isNull() || endOfParagraphToMove.isNull()) |
| 229 return; | 229 return; |
| 230 RefPtrWillBeRawPtr<HTMLBRElement> placeholder = HTMLBRElement::create(docume
nt()); | 230 RawPtr<HTMLBRElement> placeholder = HTMLBRElement::create(document()); |
| 231 insertNodeBefore(placeholder, splitBlockquoteNode, editingState); | 231 insertNodeBefore(placeholder, splitBlockquoteNode, editingState); |
| 232 if (editingState->isAborted()) | 232 if (editingState->isAborted()) |
| 233 return; | 233 return; |
| 234 moveParagraph(startOfParagraphToMove, endOfParagraphToMove, createVisiblePos
ition(positionBeforeNode(placeholder.get())), editingState, true); | 234 moveParagraph(startOfParagraphToMove, endOfParagraphToMove, createVisiblePos
ition(positionBeforeNode(placeholder.get())), editingState, true); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // FIXME: We should merge this function with ApplyBlockElementCommand::formatSel
ection | 237 // FIXME: We should merge this function with ApplyBlockElementCommand::formatSel
ection |
| 238 void IndentOutdentCommand::outdentRegion(const VisiblePosition& startOfSelection
, const VisiblePosition& endOfSelection, EditingState* editingState) | 238 void IndentOutdentCommand::outdentRegion(const VisiblePosition& startOfSelection
, const VisiblePosition& endOfSelection, EditingState* editingState) |
| 239 { | 239 { |
| 240 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); | 240 VisiblePosition endOfCurrentParagraph = endOfParagraph(startOfSelection); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 | 275 |
| 276 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti
on, const VisiblePosition& endOfSelection, EditingState* editingState) | 276 void IndentOutdentCommand::formatSelection(const VisiblePosition& startOfSelecti
on, const VisiblePosition& endOfSelection, EditingState* editingState) |
| 277 { | 277 { |
| 278 if (m_typeOfAction == Indent) | 278 if (m_typeOfAction == Indent) |
| 279 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti
on, editingState); | 279 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelecti
on, editingState); |
| 280 else | 280 else |
| 281 outdentRegion(startOfSelection, endOfSelection, editingState); | 281 outdentRegion(startOfSelection, endOfSelection, editingState); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void IndentOutdentCommand::formatRange(const Position& start, const Position& en
d, const Position&, RefPtrWillBeRawPtr<HTMLElement>& blockquoteForNextIndent, Ed
itingState* editingState) | 284 void IndentOutdentCommand::formatRange(const Position& start, const Position& en
d, const Position&, RawPtr<HTMLElement>& blockquoteForNextIndent, EditingState*
editingState) |
| 285 { | 285 { |
| 286 bool indentingAsListItemResult = tryIndentingAsListItem(start, end, editingS
tate); | 286 bool indentingAsListItemResult = tryIndentingAsListItem(start, end, editingS
tate); |
| 287 if (editingState->isAborted()) | 287 if (editingState->isAborted()) |
| 288 return; | 288 return; |
| 289 if (indentingAsListItemResult) | 289 if (indentingAsListItemResult) |
| 290 blockquoteForNextIndent = nullptr; | 290 blockquoteForNextIndent = nullptr; |
| 291 else | 291 else |
| 292 indentIntoBlockquote(start, end, blockquoteForNextIndent, editingState); | 292 indentIntoBlockquote(start, end, blockquoteForNextIndent, editingState); |
| 293 } | 293 } |
| 294 | 294 |
| 295 } // namespace blink | 295 } // namespace blink |
| OLD | NEW |