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 23 matching lines...) Expand all Loading... |
34 #include "core/editing/htmlediting.h" | 34 #include "core/editing/htmlediting.h" |
35 #include "core/html/HTMLElement.h" | 35 #include "core/html/HTMLElement.h" |
36 #include "core/rendering/RenderObject.h" | 36 #include "core/rendering/RenderObject.h" |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 using namespace HTMLNames; | 40 using namespace HTMLNames; |
41 | 41 |
42 static bool isListOrIndentBlockquote(const Node* node) | 42 static bool isListOrIndentBlockquote(const Node* node) |
43 { | 43 { |
44 return node && (node->hasTagName(ulTag) || node->hasTagName(olTag) || node->
hasTagName(blockquoteTag)); | 44 return node && (isHTMLUListElement(*node) || isHTMLOListElement(*node) || no
de->hasTagName(blockquoteTag)); |
45 } | 45 } |
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 RefPtr<Node> lastNodeInSelectedParagraph = start.deprecatedNode(); |
57 RefPtr<Element> listNode = enclosingList(lastNodeInSelectedParagraph.get()); | 57 RefPtr<Element> listNode = enclosingList(lastNodeInSelectedParagraph.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 RefPtr<Element> selectedListItem = enclosingBlock(lastNodeInSelectedParagrap
h.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->hasTagName(liTag)) | 65 if (!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 RefPtr<Element> previousList = ElementTraversal::previousSibling(*selectedLi
stItem); |
70 RefPtr<Element> nextList = ElementTraversal::nextSibling(*selectedListItem); | 70 RefPtr<Element> nextList = ElementTraversal::nextSibling(*selectedListItem); |
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 RefPtr<Element> newList = document().createElement(listNode->tagQName(), fal
se); | 75 RefPtr<Element> newList = document().createElement(listNode->tagQName(), fal
se); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 void IndentOutdentCommand::outdentParagraph() | 127 void IndentOutdentCommand::outdentParagraph() |
128 { | 128 { |
129 VisiblePosition visibleStartOfParagraph = startOfParagraph(endingSelection()
.visibleStart()); | 129 VisiblePosition visibleStartOfParagraph = startOfParagraph(endingSelection()
.visibleStart()); |
130 VisiblePosition visibleEndOfParagraph = endOfParagraph(visibleStartOfParagra
ph); | 130 VisiblePosition visibleEndOfParagraph = endOfParagraph(visibleStartOfParagra
ph); |
131 | 131 |
132 Node* enclosingNode = enclosingNodeOfType(visibleStartOfParagraph.deepEquiva
lent(), &isListOrIndentBlockquote); | 132 Node* enclosingNode = enclosingNodeOfType(visibleStartOfParagraph.deepEquiva
lent(), &isListOrIndentBlockquote); |
133 if (!enclosingNode || !enclosingNode->parentNode()->rendererIsEditable()) //
We can't outdent if there is no place to go! | 133 if (!enclosingNode || !enclosingNode->parentNode()->rendererIsEditable()) //
We can't outdent if there is no place to go! |
134 return; | 134 return; |
135 | 135 |
136 // Use InsertListCommand to remove the selection from the list | 136 // Use InsertListCommand to remove the selection from the list |
137 if (enclosingNode->hasTagName(olTag)) { | 137 if (isHTMLOListElement(*enclosingNode)) { |
138 applyCommandToComposite(InsertListCommand::create(document(), InsertList
Command::OrderedList)); | 138 applyCommandToComposite(InsertListCommand::create(document(), InsertList
Command::OrderedList)); |
139 return; | 139 return; |
140 } | 140 } |
141 if (enclosingNode->hasTagName(ulTag)) { | 141 if (isHTMLUListElement(*enclosingNode)) { |
142 applyCommandToComposite(InsertListCommand::create(document(), InsertList
Command::UnorderedList)); | 142 applyCommandToComposite(InsertListCommand::create(document(), InsertList
Command::UnorderedList)); |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 // The selection is inside a blockquote i.e. enclosingNode is a blockquote | 146 // The selection is inside a blockquote i.e. enclosingNode is a blockquote |
147 VisiblePosition positionInEnclosingBlock = VisiblePosition(firstPositionInNo
de(enclosingNode)); | 147 VisiblePosition positionInEnclosingBlock = VisiblePosition(firstPositionInNo
de(enclosingNode)); |
148 // If the blockquote is inline, the start of the enclosing block coincides w
ith | 148 // If the blockquote is inline, the start of the enclosing block coincides w
ith |
149 // positionInEnclosingBlock. | 149 // positionInEnclosingBlock. |
150 VisiblePosition startOfEnclosingBlock = (enclosingNode->renderer() && enclos
ingNode->renderer()->isInline()) ? positionInEnclosingBlock : startOfBlock(posit
ionInEnclosingBlock); | 150 VisiblePosition startOfEnclosingBlock = (enclosingNode->renderer() && enclos
ingNode->renderer()->isInline()) ? positionInEnclosingBlock : startOfBlock(posit
ionInEnclosingBlock); |
151 VisiblePosition lastPositionInEnclosingBlock = VisiblePosition(lastPositionI
nNode(enclosingNode)); | 151 VisiblePosition lastPositionInEnclosingBlock = VisiblePosition(lastPositionI
nNode(enclosingNode)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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&, RefPtr<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 |