OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008, 2009 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 , m_start(start) | 138 , m_start(start) |
139 , m_end(end) | 139 , m_end(end) |
140 , m_useEndingSelection(false) | 140 , m_useEndingSelection(false) |
141 , m_styledInlineElement(0) | 141 , m_styledInlineElement(0) |
142 , m_removeOnly(false) | 142 , m_removeOnly(false) |
143 , m_isInlineElementToRemoveFunction(0) | 143 , m_isInlineElementToRemoveFunction(0) |
144 { | 144 { |
145 } | 145 } |
146 | 146 |
147 ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnl
y, EditAction editingAction) | 147 ApplyStyleCommand::ApplyStyleCommand(PassRefPtr<Element> element, bool removeOnl
y, EditAction editingAction) |
148 : CompositeEditCommand(element->document()) | 148 : CompositeEditCommand(&element->document()) |
149 , m_style(EditingStyle::create()) | 149 , m_style(EditingStyle::create()) |
150 , m_editingAction(editingAction) | 150 , m_editingAction(editingAction) |
151 , m_propertyLevel(PropertyDefault) | 151 , m_propertyLevel(PropertyDefault) |
152 , m_start(endingSelection().start().downstream()) | 152 , m_start(endingSelection().start().downstream()) |
153 , m_end(endingSelection().end().upstream()) | 153 , m_end(endingSelection().end().upstream()) |
154 , m_useEndingSelection(true) | 154 , m_useEndingSelection(true) |
155 , m_styledInlineElement(element) | 155 , m_styledInlineElement(element) |
156 , m_removeOnly(removeOnly) | 156 , m_removeOnly(removeOnly) |
157 , m_isInlineElementToRemoveFunction(0) | 157 , m_isInlineElementToRemoveFunction(0) |
158 { | 158 { |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 pastEndNode = NodeTraversal::nextSkippingChildren(end.deprecatedNode()); | 683 pastEndNode = NodeTraversal::nextSkippingChildren(end.deprecatedNode()); |
684 | 684 |
685 // FIXME: Callers should perform this operation on a Range that includes the
br | 685 // FIXME: Callers should perform this operation on a Range that includes the
br |
686 // if they want style applied to the empty line. | 686 // if they want style applied to the empty line. |
687 if (start == end && start.deprecatedNode()->hasTagName(brTag)) | 687 if (start == end && start.deprecatedNode()->hasTagName(brTag)) |
688 pastEndNode = NodeTraversal::next(start.deprecatedNode()); | 688 pastEndNode = NodeTraversal::next(start.deprecatedNode()); |
689 | 689 |
690 // Start from the highest fully selected ancestor so that we can modify the
fully selected node. | 690 // Start from the highest fully selected ancestor so that we can modify the
fully selected node. |
691 // e.g. When applying font-size: large on <font color="blue">hello</font>, w
e need to include the font element in our run | 691 // e.g. When applying font-size: large on <font color="blue">hello</font>, w
e need to include the font element in our run |
692 // to generate <font color="blue" size="4">hello</font> instead of <font col
or="blue"><font size="4">hello</font></font> | 692 // to generate <font color="blue" size="4">hello</font> instead of <font col
or="blue"><font size="4">hello</font></font> |
693 RefPtr<Range> range = Range::create(startNode->document(), start, end); | 693 RefPtr<Range> range = Range::create(&startNode->document(), start, end); |
694 Element* editableRoot = startNode->rootEditableElement(); | 694 Element* editableRoot = startNode->rootEditableElement(); |
695 if (startNode != editableRoot) { | 695 if (startNode != editableRoot) { |
696 while (editableRoot && startNode->parentNode() != editableRoot && isNode
VisiblyContainedWithin(startNode->parentNode(), range.get())) | 696 while (editableRoot && startNode->parentNode() != editableRoot && isNode
VisiblyContainedWithin(startNode->parentNode(), range.get())) |
697 startNode = startNode->parentNode(); | 697 startNode = startNode->parentNode(); |
698 } | 698 } |
699 | 699 |
700 applyInlineStyleToNodeRange(style, startNode, pastEndNode); | 700 applyInlineStyleToNodeRange(style, startNode, pastEndNode); |
701 } | 701 } |
702 | 702 |
703 static bool containsNonEditableRegion(Node* node) | 703 static bool containsNonEditableRegion(Node* node) |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 break; | 978 break; |
979 } | 979 } |
980 | 980 |
981 return result; | 981 return result; |
982 } | 982 } |
983 | 983 |
984 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty
le) | 984 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty
le) |
985 { | 985 { |
986 ASSERT(node); | 986 ASSERT(node); |
987 | 987 |
988 node->document()->updateStyleIfNeeded(); | 988 node->document().updateStyleIfNeeded(); |
989 | 989 |
990 if (!style || style->isEmpty() || !node->renderer()) | 990 if (!style || style->isEmpty() || !node->renderer()) |
991 return; | 991 return; |
992 | 992 |
993 RefPtr<EditingStyle> newInlineStyle = style; | 993 RefPtr<EditingStyle> newInlineStyle = style; |
994 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) { | 994 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) { |
995 newInlineStyle = style->copy(); | 995 newInlineStyle = style->copy(); |
996 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt
yle::OverrideValues); | 996 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt
yle::OverrideValues); |
997 } | 997 } |
998 | 998 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 | 1147 |
1148 updateStartEnd(s, e); | 1148 updateStartEnd(s, e); |
1149 } | 1149 } |
1150 | 1150 |
1151 bool ApplyStyleCommand::nodeFullySelected(Node *node, const Position &start, con
st Position &end) const | 1151 bool ApplyStyleCommand::nodeFullySelected(Node *node, const Position &start, con
st Position &end) const |
1152 { | 1152 { |
1153 ASSERT(node); | 1153 ASSERT(node); |
1154 ASSERT(node->isElementNode()); | 1154 ASSERT(node->isElementNode()); |
1155 | 1155 |
1156 // The tree may have changed and Position::upstream() relies on an up-to-dat
e layout. | 1156 // The tree may have changed and Position::upstream() relies on an up-to-dat
e layout. |
1157 node->document()->updateLayoutIgnorePendingStylesheets(); | 1157 node->document().updateLayoutIgnorePendingStylesheets(); |
1158 | 1158 |
1159 return comparePositions(firstPositionInOrBeforeNode(node), start) >= 0 | 1159 return comparePositions(firstPositionInOrBeforeNode(node), start) >= 0 |
1160 && comparePositions(lastPositionInOrAfterNode(node).upstream(), end) <=
0; | 1160 && comparePositions(lastPositionInOrAfterNode(node).upstream(), end) <=
0; |
1161 } | 1161 } |
1162 | 1162 |
1163 bool ApplyStyleCommand::nodeFullyUnselected(Node *node, const Position &start, c
onst Position &end) const | 1163 bool ApplyStyleCommand::nodeFullyUnselected(Node *node, const Position &start, c
onst Position &end) const |
1164 { | 1164 { |
1165 ASSERT(node); | 1165 ASSERT(node); |
1166 ASSERT(node->isElementNode()); | 1166 ASSERT(node->isElementNode()); |
1167 | 1167 |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 String textToMove = nextText->data(); | 1541 String textToMove = nextText->data(); |
1542 insertTextIntoNode(childText, childText->length(), textToMove); | 1542 insertTextIntoNode(childText, childText->length(), textToMove); |
1543 removeNode(next); | 1543 removeNode(next); |
1544 // don't move child node pointer. it may want to merge with more text no
des. | 1544 // don't move child node pointer. it may want to merge with more text no
des. |
1545 } | 1545 } |
1546 | 1546 |
1547 updateStartEnd(newStart, newEnd); | 1547 updateStartEnd(newStart, newEnd); |
1548 } | 1548 } |
1549 | 1549 |
1550 } | 1550 } |
OLD | NEW |