| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 EditAction ApplyStyleCommand::editingAction() const | 238 EditAction ApplyStyleCommand::editingAction() const |
| 239 { | 239 { |
| 240 return m_editingAction; | 240 return m_editingAction; |
| 241 } | 241 } |
| 242 | 242 |
| 243 void ApplyStyleCommand::applyBlockStyle(EditingStyle *style, EditingState* editi
ngState) | 243 void ApplyStyleCommand::applyBlockStyle(EditingStyle *style, EditingState* editi
ngState) |
| 244 { | 244 { |
| 245 // update document layout once before removing styles | 245 // update document layout once before removing styles |
| 246 // so that we avoid the expense of updating before each and every call | 246 // so that we avoid the expense of updating before each and every call |
| 247 // to check a computed style | 247 // to check a computed style |
| 248 document().updateLayoutIgnorePendingStylesheets(); | 248 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 249 | 249 |
| 250 // get positions we want to use for applying style | 250 // get positions we want to use for applying style |
| 251 Position start = startPosition(); | 251 Position start = startPosition(); |
| 252 Position end = endPosition(); | 252 Position end = endPosition(); |
| 253 if (comparePositions(end, start) < 0) { | 253 if (comparePositions(end, start) < 0) { |
| 254 Position swap = start; | 254 Position swap = start; |
| 255 start = end; | 255 start = end; |
| 256 end = swap; | 256 end = swap; |
| 257 } | 257 } |
| 258 | 258 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 } | 585 } |
| 586 | 586 |
| 587 void ApplyStyleCommand::applyInlineStyle(EditingStyle* style, EditingState* edit
ingState) | 587 void ApplyStyleCommand::applyInlineStyle(EditingStyle* style, EditingState* edit
ingState) |
| 588 { | 588 { |
| 589 ContainerNode* startDummySpanAncestor = nullptr; | 589 ContainerNode* startDummySpanAncestor = nullptr; |
| 590 ContainerNode* endDummySpanAncestor = nullptr; | 590 ContainerNode* endDummySpanAncestor = nullptr; |
| 591 | 591 |
| 592 // update document layout once before removing styles | 592 // update document layout once before removing styles |
| 593 // so that we avoid the expense of updating before each and every call | 593 // so that we avoid the expense of updating before each and every call |
| 594 // to check a computed style | 594 // to check a computed style |
| 595 document().updateLayoutIgnorePendingStylesheets(); | 595 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 596 | 596 |
| 597 // adjust to the positions we want to use for applying style | 597 // adjust to the positions we want to use for applying style |
| 598 Position start = startPosition(); | 598 Position start = startPosition(); |
| 599 Position end = endPosition(); | 599 Position end = endPosition(); |
| 600 | 600 |
| 601 if (start.isNull() || end.isNull()) | 601 if (start.isNull() || end.isNull()) |
| 602 return; | 602 return; |
| 603 | 603 |
| 604 if (comparePositions(end, start) < 0) { | 604 if (comparePositions(end, start) < 0) { |
| 605 Position swap = start; | 605 Position swap = start; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 mergeEndWithNextIfIdentical(start, end, editingState); | 699 mergeEndWithNextIfIdentical(start, end, editingState); |
| 700 if (editingState->isAborted()) | 700 if (editingState->isAborted()) |
| 701 return; | 701 return; |
| 702 start = startPosition(); | 702 start = startPosition(); |
| 703 end = endPosition(); | 703 end = endPosition(); |
| 704 } | 704 } |
| 705 | 705 |
| 706 // update document layout once before running the rest of the function | 706 // update document layout once before running the rest of the function |
| 707 // so that we avoid the expense of updating before each and every call | 707 // so that we avoid the expense of updating before each and every call |
| 708 // to check a computed style | 708 // to check a computed style |
| 709 document().updateLayoutIgnorePendingStylesheets(); | 709 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 710 | 710 |
| 711 EditingStyle* styleToApply = style; | 711 EditingStyle* styleToApply = style; |
| 712 if (hasTextDirection) { | 712 if (hasTextDirection) { |
| 713 // Avoid applying the unicode-bidi and direction properties beneath ance
stors that already have them. | 713 // Avoid applying the unicode-bidi and direction properties beneath ance
stors that already have them. |
| 714 HTMLElement* embeddingStartElement = highestEmbeddingAncestor(start.anch
orNode(), enclosingBlock(start.anchorNode())); | 714 HTMLElement* embeddingStartElement = highestEmbeddingAncestor(start.anch
orNode(), enclosingBlock(start.anchorNode())); |
| 715 HTMLElement* embeddingEndElement = highestEmbeddingAncestor(end.anchorNo
de(), enclosingBlock(end.anchorNode())); | 715 HTMLElement* embeddingEndElement = highestEmbeddingAncestor(end.anchorNo
de(), enclosingBlock(end.anchorNode())); |
| 716 | 716 |
| 717 if (embeddingStartElement || embeddingEndElement) { | 717 if (embeddingStartElement || embeddingEndElement) { |
| 718 Position embeddingApplyStart = embeddingStartElement ? positionInPar
entAfterNode(*embeddingStartElement) : start; | 718 Position embeddingApplyStart = embeddingStartElement ? positionInPar
entAfterNode(*embeddingStartElement) : start; |
| 719 Position embeddingApplyEnd = embeddingEndElement ? positionInParentB
eforeNode(*embeddingEndElement) : end; | 719 Position embeddingApplyEnd = embeddingEndElement ? positionInParentB
eforeNode(*embeddingEndElement) : end; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 | 828 |
| 829 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::InlineRunToApplyStyle); | 829 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::InlineRunToApplyStyle); |
| 830 | 830 |
| 831 namespace blink { | 831 namespace blink { |
| 832 | 832 |
| 833 void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, Node* s
tartNode, Node* pastEndNode, EditingState* editingState) | 833 void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, Node* s
tartNode, Node* pastEndNode, EditingState* editingState) |
| 834 { | 834 { |
| 835 if (m_removeOnly) | 835 if (m_removeOnly) |
| 836 return; | 836 return; |
| 837 | 837 |
| 838 document().updateLayoutIgnorePendingStylesheets(); | 838 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 839 | 839 |
| 840 HeapVector<InlineRunToApplyStyle> runs; | 840 HeapVector<InlineRunToApplyStyle> runs; |
| 841 Node* node = startNode; | 841 Node* node = startNode; |
| 842 for (Node* next; node && node != pastEndNode; node = next) { | 842 for (Node* next; node && node != pastEndNode; node = next) { |
| 843 next = NodeTraversal::next(*node); | 843 next = NodeTraversal::next(*node); |
| 844 | 844 |
| 845 if (!node->layoutObject() || !node->hasEditableStyle()) | 845 if (!node->layoutObject() || !node->hasEditableStyle()) |
| 846 continue; | 846 continue; |
| 847 | 847 |
| 848 if (!node->layoutObjectIsRichlyEditable() && node->isHTMLElement()) { | 848 if (!node->layoutObjectIsRichlyEditable() && node->isHTMLElement()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 removeConflictingInlineStyleFromRun(style, run.start, run.end, run.pastE
ndNode, editingState); | 897 removeConflictingInlineStyleFromRun(style, run.start, run.end, run.pastE
ndNode, editingState); |
| 898 if (editingState->isAborted()) | 898 if (editingState->isAborted()) |
| 899 return; | 899 return; |
| 900 if (run.startAndEndAreStillInDocument()) { | 900 if (run.startAndEndAreStillInDocument()) { |
| 901 run.positionForStyleComputation = positionToComputeInlineStyleChange
(run.start, run.dummyElement, editingState); | 901 run.positionForStyleComputation = positionToComputeInlineStyleChange
(run.start, run.dummyElement, editingState); |
| 902 if (editingState->isAborted()) | 902 if (editingState->isAborted()) |
| 903 return; | 903 return; |
| 904 } | 904 } |
| 905 } | 905 } |
| 906 | 906 |
| 907 document().updateLayoutIgnorePendingStylesheets(); | 907 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 908 | 908 |
| 909 for (auto& run : runs) { | 909 for (auto& run : runs) { |
| 910 if (run.positionForStyleComputation.isNotNull()) | 910 if (run.positionForStyleComputation.isNotNull()) |
| 911 run.change = StyleChange(style, run.positionForStyleComputation); | 911 run.change = StyleChange(style, run.positionForStyleComputation); |
| 912 } | 912 } |
| 913 | 913 |
| 914 for (auto& run : runs) { | 914 for (auto& run : runs) { |
| 915 if (run.dummyElement) { | 915 if (run.dummyElement) { |
| 916 removeNode(run.dummyElement, editingState); | 916 removeNode(run.dummyElement, editingState); |
| 917 if (editingState->isAborted()) | 917 if (editingState->isAborted()) |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 break; | 1096 break; |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 return result; | 1099 return result; |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty
le, EditingState* editingState) | 1102 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty
le, EditingState* editingState) |
| 1103 { | 1103 { |
| 1104 DCHECK(node); | 1104 DCHECK(node); |
| 1105 | 1105 |
| 1106 node->document().updateLayoutTree(); | 1106 node->document().updateStyleAndLayoutTree(); |
| 1107 | 1107 |
| 1108 if (!style || style->isEmpty() || !node->layoutObject() || isHTMLIFrameEleme
nt(*node)) | 1108 if (!style || style->isEmpty() || !node->layoutObject() || isHTMLIFrameEleme
nt(*node)) |
| 1109 return; | 1109 return; |
| 1110 | 1110 |
| 1111 EditingStyle* newInlineStyle = style; | 1111 EditingStyle* newInlineStyle = style; |
| 1112 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) { | 1112 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) { |
| 1113 newInlineStyle = style->copy(); | 1113 newInlineStyle = style->copy(); |
| 1114 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt
yle::OverrideValues); | 1114 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt
yle::OverrideValues); |
| 1115 } | 1115 } |
| 1116 | 1116 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 break; | 1289 break; |
| 1290 node = next; | 1290 node = next; |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 updateStartEnd(s, e); | 1293 updateStartEnd(s, e); |
| 1294 } | 1294 } |
| 1295 | 1295 |
| 1296 bool ApplyStyleCommand::elementFullySelected(HTMLElement& element, const Positio
n& start, const Position& end) const | 1296 bool ApplyStyleCommand::elementFullySelected(HTMLElement& element, const Positio
n& start, const Position& end) const |
| 1297 { | 1297 { |
| 1298 // The tree may have changed and Position::upstream() relies on an up-to-dat
e layout. | 1298 // The tree may have changed and Position::upstream() relies on an up-to-dat
e layout. |
| 1299 element.document().updateLayoutIgnorePendingStylesheets(); | 1299 element.document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1300 | 1300 |
| 1301 return comparePositions(firstPositionInOrBeforeNode(&element), start) >= 0 | 1301 return comparePositions(firstPositionInOrBeforeNode(&element), start) >= 0 |
| 1302 && comparePositions(mostBackwardCaretPosition(lastPositionInOrAfterNode(
&element)), end) <= 0; | 1302 && comparePositions(mostBackwardCaretPosition(lastPositionInOrAfterNode(
&element)), end) <= 0; |
| 1303 } | 1303 } |
| 1304 | 1304 |
| 1305 void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position&
end) | 1305 void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position&
end) |
| 1306 { | 1306 { |
| 1307 DCHECK(start.computeContainerNode()->isTextNode()) << start; | 1307 DCHECK(start.computeContainerNode()->isTextNode()) << start; |
| 1308 | 1308 |
| 1309 Position newEnd; | 1309 Position newEnd; |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1731 DEFINE_TRACE(ApplyStyleCommand) | 1731 DEFINE_TRACE(ApplyStyleCommand) |
| 1732 { | 1732 { |
| 1733 visitor->trace(m_style); | 1733 visitor->trace(m_style); |
| 1734 visitor->trace(m_start); | 1734 visitor->trace(m_start); |
| 1735 visitor->trace(m_end); | 1735 visitor->trace(m_end); |
| 1736 visitor->trace(m_styledInlineElement); | 1736 visitor->trace(m_styledInlineElement); |
| 1737 CompositeEditCommand::trace(visitor); | 1737 CompositeEditCommand::trace(visitor); |
| 1738 } | 1738 } |
| 1739 | 1739 |
| 1740 } // namespace blink | 1740 } // namespace blink |
| OLD | NEW |