OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, 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 void FormatBlockCommand::formatSelection(const VisiblePosition& startOfSelection
, const VisiblePosition& endOfSelection) | 62 void FormatBlockCommand::formatSelection(const VisiblePosition& startOfSelection
, const VisiblePosition& endOfSelection) |
63 { | 63 { |
64 if (!isElementForFormatBlock(tagName())) | 64 if (!isElementForFormatBlock(tagName())) |
65 return; | 65 return; |
66 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelection); | 66 ApplyBlockElementCommand::formatSelection(startOfSelection, endOfSelection); |
67 m_didApply = true; | 67 m_didApply = true; |
68 } | 68 } |
69 | 69 |
70 void FormatBlockCommand::formatRange(const Position& start, const Position& end,
const Position& endOfSelection, RefPtrWillBeRawPtr<HTMLElement>& blockElement) | 70 void FormatBlockCommand::formatRange(const Position& start, const Position& end,
const Position& endOfSelection, RefPtrWillBeRawPtr<HTMLElement>& blockElement) |
71 { | 71 { |
72 Element* refElement = enclosingBlockFlowElement(VisiblePosition(end)); | 72 Element* refElement = enclosingBlockFlowElement(createVisiblePosition(end)); |
73 Element* root = editableRootForPosition(start); | 73 Element* root = editableRootForPosition(start); |
74 // Root is null for elements with contenteditable=false. | 74 // Root is null for elements with contenteditable=false. |
75 if (!root || !refElement) | 75 if (!root || !refElement) |
76 return; | 76 return; |
77 | 77 |
78 Node* nodeToSplitTo = enclosingBlockToSplitTreeTo(start.anchorNode()); | 78 Node* nodeToSplitTo = enclosingBlockToSplitTreeTo(start.anchorNode()); |
79 RefPtrWillBeRawPtr<Node> outerBlock = (start.anchorNode() == nodeToSplitTo)
? start.anchorNode() : splitTreeToNode(start.anchorNode(), nodeToSplitTo).get(); | 79 RefPtrWillBeRawPtr<Node> outerBlock = (start.anchorNode() == nodeToSplitTo)
? start.anchorNode() : splitTreeToNode(start.anchorNode(), nodeToSplitTo).get(); |
80 RefPtrWillBeRawPtr<Node> nodeAfterInsertionPosition = outerBlock; | 80 RefPtrWillBeRawPtr<Node> nodeAfterInsertionPosition = outerBlock; |
81 RefPtrWillBeRawPtr<Range> range = Range::create(document(), start, endOfSele
ction); | 81 RefPtrWillBeRawPtr<Range> range = Range::create(document(), start, endOfSele
ction); |
82 | 82 |
83 if (isElementForFormatBlock(refElement->tagQName()) && VisiblePosition(start
).deepEquivalent() == startOfBlock(VisiblePosition(start)).deepEquivalent() | 83 if (isElementForFormatBlock(refElement->tagQName()) && createVisiblePosition
(start).deepEquivalent() == startOfBlock(createVisiblePosition(start)).deepEquiv
alent() |
84 && (VisiblePosition(end).deepEquivalent() == endOfBlock(VisiblePosition(
end)).deepEquivalent() || isNodeVisiblyContainedWithin(*refElement, *range)) | 84 && (createVisiblePosition(end).deepEquivalent() == endOfBlock(createVisi
blePosition(end)).deepEquivalent() || isNodeVisiblyContainedWithin(*refElement,
*range)) |
85 && refElement != root && !root->isDescendantOf(refElement)) { | 85 && refElement != root && !root->isDescendantOf(refElement)) { |
86 // Already in a block element that only contains the current paragraph | 86 // Already in a block element that only contains the current paragraph |
87 if (refElement->hasTagName(tagName())) | 87 if (refElement->hasTagName(tagName())) |
88 return; | 88 return; |
89 nodeAfterInsertionPosition = refElement; | 89 nodeAfterInsertionPosition = refElement; |
90 } | 90 } |
91 | 91 |
92 if (!blockElement) { | 92 if (!blockElement) { |
93 // Create a new blockquote and insert it as a child of the root editable
element. We accomplish | 93 // Create a new blockquote and insert it as a child of the root editable
element. We accomplish |
94 // this by splitting all parents of the current paragraph up to that poi
nt. | 94 // this by splitting all parents of the current paragraph up to that poi
nt. |
95 blockElement = createBlockElement(); | 95 blockElement = createBlockElement(); |
96 insertNodeBefore(blockElement, nodeAfterInsertionPosition); | 96 insertNodeBefore(blockElement, nodeAfterInsertionPosition); |
97 } | 97 } |
98 | 98 |
99 Position lastParagraphInBlockNode = blockElement->lastChild() ? positionAfte
rNode(blockElement->lastChild()) : Position(); | 99 Position lastParagraphInBlockNode = blockElement->lastChild() ? positionAfte
rNode(blockElement->lastChild()) : Position(); |
100 bool wasEndOfParagraph = isEndOfParagraph(VisiblePosition(lastParagraphInBlo
ckNode)); | 100 bool wasEndOfParagraph = isEndOfParagraph(createVisiblePosition(lastParagrap
hInBlockNode)); |
101 | 101 |
102 moveParagraphWithClones(VisiblePosition(start), VisiblePosition(end), blockE
lement.get(), outerBlock.get()); | 102 moveParagraphWithClones(createVisiblePosition(start), createVisiblePosition(
end), blockElement.get(), outerBlock.get()); |
103 | 103 |
104 // Copy the inline style of the original block element to the newly created
block-style element. | 104 // Copy the inline style of the original block element to the newly created
block-style element. |
105 if (outerBlock.get() != nodeAfterInsertionPosition.get() && toHTMLElement(no
deAfterInsertionPosition.get())->hasAttribute(styleAttr)) | 105 if (outerBlock.get() != nodeAfterInsertionPosition.get() && toHTMLElement(no
deAfterInsertionPosition.get())->hasAttribute(styleAttr)) |
106 blockElement->setAttribute(styleAttr, toHTMLElement(nodeAfterInsertionPo
sition.get())->getAttribute(styleAttr)); | 106 blockElement->setAttribute(styleAttr, toHTMLElement(nodeAfterInsertionPo
sition.get())->getAttribute(styleAttr)); |
107 | 107 |
108 if (wasEndOfParagraph && !isEndOfParagraph(VisiblePosition(lastParagraphInBl
ockNode)) && !isStartOfParagraph(VisiblePosition(lastParagraphInBlockNode))) | 108 if (wasEndOfParagraph && !isEndOfParagraph(createVisiblePosition(lastParagra
phInBlockNode)) && !isStartOfParagraph(createVisiblePosition(lastParagraphInBloc
kNode))) |
109 insertBlockPlaceholder(lastParagraphInBlockNode); | 109 insertBlockPlaceholder(lastParagraphInBlockNode); |
110 } | 110 } |
111 | 111 |
112 Element* FormatBlockCommand::elementForFormatBlockCommand(Range* range) | 112 Element* FormatBlockCommand::elementForFormatBlockCommand(Range* range) |
113 { | 113 { |
114 if (!range) | 114 if (!range) |
115 return 0; | 115 return 0; |
116 | 116 |
117 Node* commonAncestor = range->commonAncestorContainer(); | 117 Node* commonAncestor = range->commonAncestorContainer(); |
118 while (commonAncestor && !isElementForFormatBlock(commonAncestor)) | 118 while (commonAncestor && !isElementForFormatBlock(commonAncestor)) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return n; | 168 return n; |
169 if (isEnclosingBlock(n)) | 169 if (isEnclosingBlock(n)) |
170 lastBlock = n; | 170 lastBlock = n; |
171 if (isHTMLListElement(n)) | 171 if (isHTMLListElement(n)) |
172 return n->parentNode()->hasEditableStyle() ? n->parentNode() : n; | 172 return n->parentNode()->hasEditableStyle() ? n->parentNode() : n; |
173 } | 173 } |
174 return lastBlock; | 174 return lastBlock; |
175 } | 175 } |
176 | 176 |
177 } | 177 } |
OLD | NEW |