| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 EditAction ApplyStyleCommand::editingAction() const | 228 EditAction ApplyStyleCommand::editingAction() const |
| 229 { | 229 { |
| 230 return m_editingAction; | 230 return m_editingAction; |
| 231 } | 231 } |
| 232 | 232 |
| 233 void ApplyStyleCommand::applyBlockStyle(EditingStyle *style, EditingState* editi
ngState) | 233 void ApplyStyleCommand::applyBlockStyle(EditingStyle *style, EditingState* editi
ngState) |
| 234 { | 234 { |
| 235 // update document layout once before removing styles | 235 // update document layout once before removing styles |
| 236 // so that we avoid the expense of updating before each and every call | 236 // so that we avoid the expense of updating before each and every call |
| 237 // to check a computed style | 237 // to check a computed style |
| 238 document().updateLayoutIgnorePendingStylesheets(); | 238 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 239 | 239 |
| 240 // get positions we want to use for applying style | 240 // get positions we want to use for applying style |
| 241 Position start = startPosition(); | 241 Position start = startPosition(); |
| 242 Position end = endPosition(); | 242 Position end = endPosition(); |
| 243 if (comparePositions(end, start) < 0) { | 243 if (comparePositions(end, start) < 0) { |
| 244 Position swap = start; | 244 Position swap = start; |
| 245 start = end; | 245 start = end; |
| 246 end = swap; | 246 end = swap; |
| 247 } | 247 } |
| 248 | 248 |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 } | 575 } |
| 576 | 576 |
| 577 void ApplyStyleCommand::applyInlineStyle(EditingStyle* style, EditingState* edit
ingState) | 577 void ApplyStyleCommand::applyInlineStyle(EditingStyle* style, EditingState* edit
ingState) |
| 578 { | 578 { |
| 579 ContainerNode* startDummySpanAncestor = nullptr; | 579 ContainerNode* startDummySpanAncestor = nullptr; |
| 580 ContainerNode* endDummySpanAncestor = nullptr; | 580 ContainerNode* endDummySpanAncestor = nullptr; |
| 581 | 581 |
| 582 // update document layout once before removing styles | 582 // update document layout once before removing styles |
| 583 // so that we avoid the expense of updating before each and every call | 583 // so that we avoid the expense of updating before each and every call |
| 584 // to check a computed style | 584 // to check a computed style |
| 585 document().updateLayoutIgnorePendingStylesheets(); | 585 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 586 | 586 |
| 587 // adjust to the positions we want to use for applying style | 587 // adjust to the positions we want to use for applying style |
| 588 Position start = startPosition(); | 588 Position start = startPosition(); |
| 589 Position end = endPosition(); | 589 Position end = endPosition(); |
| 590 | 590 |
| 591 if (start.isNull() || end.isNull()) | 591 if (start.isNull() || end.isNull()) |
| 592 return; | 592 return; |
| 593 | 593 |
| 594 if (comparePositions(end, start) < 0) { | 594 if (comparePositions(end, start) < 0) { |
| 595 Position swap = start; | 595 Position swap = start; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 mergeEndWithNextIfIdentical(start, end, editingState); | 689 mergeEndWithNextIfIdentical(start, end, editingState); |
| 690 if (editingState->isAborted()) | 690 if (editingState->isAborted()) |
| 691 return; | 691 return; |
| 692 start = startPosition(); | 692 start = startPosition(); |
| 693 end = endPosition(); | 693 end = endPosition(); |
| 694 } | 694 } |
| 695 | 695 |
| 696 // update document layout once before running the rest of the function | 696 // update document layout once before running the rest of the function |
| 697 // so that we avoid the expense of updating before each and every call | 697 // so that we avoid the expense of updating before each and every call |
| 698 // to check a computed style | 698 // to check a computed style |
| 699 document().updateLayoutIgnorePendingStylesheets(); | 699 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 700 | 700 |
| 701 EditingStyle* styleToApply = style; | 701 EditingStyle* styleToApply = style; |
| 702 if (hasTextDirection) { | 702 if (hasTextDirection) { |
| 703 // Avoid applying the unicode-bidi and direction properties beneath ance
stors that already have them. | 703 // Avoid applying the unicode-bidi and direction properties beneath ance
stors that already have them. |
| 704 HTMLElement* embeddingStartElement = highestEmbeddingAncestor(start.anch
orNode(), enclosingBlock(start.anchorNode())); | 704 HTMLElement* embeddingStartElement = highestEmbeddingAncestor(start.anch
orNode(), enclosingBlock(start.anchorNode())); |
| 705 HTMLElement* embeddingEndElement = highestEmbeddingAncestor(end.anchorNo
de(), enclosingBlock(end.anchorNode())); | 705 HTMLElement* embeddingEndElement = highestEmbeddingAncestor(end.anchorNo
de(), enclosingBlock(end.anchorNode())); |
| 706 | 706 |
| 707 if (embeddingStartElement || embeddingEndElement) { | 707 if (embeddingStartElement || embeddingEndElement) { |
| 708 Position embeddingApplyStart = embeddingStartElement ? positionInPar
entAfterNode(*embeddingStartElement) : start; | 708 Position embeddingApplyStart = embeddingStartElement ? positionInPar
entAfterNode(*embeddingStartElement) : start; |
| 709 Position embeddingApplyEnd = embeddingEndElement ? positionInParentB
eforeNode(*embeddingEndElement) : end; | 709 Position embeddingApplyEnd = embeddingEndElement ? positionInParentB
eforeNode(*embeddingEndElement) : end; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 | 818 |
| 819 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::InlineRunToApplyStyle); | 819 WTF_ALLOW_INIT_WITH_MEM_FUNCTIONS(blink::InlineRunToApplyStyle); |
| 820 | 820 |
| 821 namespace blink { | 821 namespace blink { |
| 822 | 822 |
| 823 void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, Node* s
tartNode, Node* pastEndNode, EditingState* editingState) | 823 void ApplyStyleCommand::applyInlineStyleToNodeRange(EditingStyle* style, Node* s
tartNode, Node* pastEndNode, EditingState* editingState) |
| 824 { | 824 { |
| 825 if (m_removeOnly) | 825 if (m_removeOnly) |
| 826 return; | 826 return; |
| 827 | 827 |
| 828 document().updateLayoutIgnorePendingStylesheets(); | 828 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 829 | 829 |
| 830 HeapVector<InlineRunToApplyStyle> runs; | 830 HeapVector<InlineRunToApplyStyle> runs; |
| 831 Node* node = startNode; | 831 Node* node = startNode; |
| 832 for (Node* next; node && node != pastEndNode; node = next) { | 832 for (Node* next; node && node != pastEndNode; node = next) { |
| 833 next = NodeTraversal::next(*node); | 833 next = NodeTraversal::next(*node); |
| 834 | 834 |
| 835 if (!node->layoutObject() || !node->hasEditableStyle()) | 835 if (!node->layoutObject() || !node->hasEditableStyle()) |
| 836 continue; | 836 continue; |
| 837 | 837 |
| 838 if (!node->layoutObjectIsRichlyEditable() && node->isHTMLElement()) { | 838 if (!node->layoutObjectIsRichlyEditable() && node->isHTMLElement()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 removeConflictingInlineStyleFromRun(style, run.start, run.end, run.pastE
ndNode, editingState); | 887 removeConflictingInlineStyleFromRun(style, run.start, run.end, run.pastE
ndNode, editingState); |
| 888 if (editingState->isAborted()) | 888 if (editingState->isAborted()) |
| 889 return; | 889 return; |
| 890 if (run.startAndEndAreStillInDocument()) { | 890 if (run.startAndEndAreStillInDocument()) { |
| 891 run.positionForStyleComputation = positionToComputeInlineStyleChange
(run.start, run.dummyElement, editingState); | 891 run.positionForStyleComputation = positionToComputeInlineStyleChange
(run.start, run.dummyElement, editingState); |
| 892 if (editingState->isAborted()) | 892 if (editingState->isAborted()) |
| 893 return; | 893 return; |
| 894 } | 894 } |
| 895 } | 895 } |
| 896 | 896 |
| 897 document().updateLayoutIgnorePendingStylesheets(); | 897 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 898 | 898 |
| 899 for (auto& run : runs) { | 899 for (auto& run : runs) { |
| 900 if (run.positionForStyleComputation.isNotNull()) | 900 if (run.positionForStyleComputation.isNotNull()) |
| 901 run.change = StyleChange(style, run.positionForStyleComputation); | 901 run.change = StyleChange(style, run.positionForStyleComputation); |
| 902 } | 902 } |
| 903 | 903 |
| 904 for (auto& run : runs) { | 904 for (auto& run : runs) { |
| 905 if (run.dummyElement) { | 905 if (run.dummyElement) { |
| 906 removeNode(run.dummyElement, editingState); | 906 removeNode(run.dummyElement, editingState); |
| 907 if (editingState->isAborted()) | 907 if (editingState->isAborted()) |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 break; | 1086 break; |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 return result; | 1089 return result; |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty
le, EditingState* editingState) | 1092 void ApplyStyleCommand::applyInlineStyleToPushDown(Node* node, EditingStyle* sty
le, EditingState* editingState) |
| 1093 { | 1093 { |
| 1094 DCHECK(node); | 1094 DCHECK(node); |
| 1095 | 1095 |
| 1096 node->document().updateLayoutTree(); | 1096 node->document().updateStyleAndLayoutTree(); |
| 1097 | 1097 |
| 1098 if (!style || style->isEmpty() || !node->layoutObject() || isHTMLIFrameEleme
nt(*node)) | 1098 if (!style || style->isEmpty() || !node->layoutObject() || isHTMLIFrameEleme
nt(*node)) |
| 1099 return; | 1099 return; |
| 1100 | 1100 |
| 1101 EditingStyle* newInlineStyle = style; | 1101 EditingStyle* newInlineStyle = style; |
| 1102 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) { | 1102 if (node->isHTMLElement() && toHTMLElement(node)->inlineStyle()) { |
| 1103 newInlineStyle = style->copy(); | 1103 newInlineStyle = style->copy(); |
| 1104 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt
yle::OverrideValues); | 1104 newInlineStyle->mergeInlineStyleOfElement(toHTMLElement(node), EditingSt
yle::OverrideValues); |
| 1105 } | 1105 } |
| 1106 | 1106 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 break; | 1279 break; |
| 1280 node = next; | 1280 node = next; |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 updateStartEnd(s, e); | 1283 updateStartEnd(s, e); |
| 1284 } | 1284 } |
| 1285 | 1285 |
| 1286 bool ApplyStyleCommand::elementFullySelected(HTMLElement& element, const Positio
n& start, const Position& end) const | 1286 bool ApplyStyleCommand::elementFullySelected(HTMLElement& element, const Positio
n& start, const Position& end) const |
| 1287 { | 1287 { |
| 1288 // The tree may have changed and Position::upstream() relies on an up-to-dat
e layout. | 1288 // The tree may have changed and Position::upstream() relies on an up-to-dat
e layout. |
| 1289 element.document().updateLayoutIgnorePendingStylesheets(); | 1289 element.document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 1290 | 1290 |
| 1291 return comparePositions(firstPositionInOrBeforeNode(&element), start) >= 0 | 1291 return comparePositions(firstPositionInOrBeforeNode(&element), start) >= 0 |
| 1292 && comparePositions(mostBackwardCaretPosition(lastPositionInOrAfterNode(
&element)), end) <= 0; | 1292 && comparePositions(mostBackwardCaretPosition(lastPositionInOrAfterNode(
&element)), end) <= 0; |
| 1293 } | 1293 } |
| 1294 | 1294 |
| 1295 void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position&
end) | 1295 void ApplyStyleCommand::splitTextAtStart(const Position& start, const Position&
end) |
| 1296 { | 1296 { |
| 1297 DCHECK(start.computeContainerNode()->isTextNode()) << start; | 1297 DCHECK(start.computeContainerNode()->isTextNode()) << start; |
| 1298 | 1298 |
| 1299 Position newEnd; | 1299 Position newEnd; |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1721 DEFINE_TRACE(ApplyStyleCommand) | 1721 DEFINE_TRACE(ApplyStyleCommand) |
| 1722 { | 1722 { |
| 1723 visitor->trace(m_style); | 1723 visitor->trace(m_style); |
| 1724 visitor->trace(m_start); | 1724 visitor->trace(m_start); |
| 1725 visitor->trace(m_end); | 1725 visitor->trace(m_end); |
| 1726 visitor->trace(m_styledInlineElement); | 1726 visitor->trace(m_styledInlineElement); |
| 1727 CompositeEditCommand::trace(visitor); | 1727 CompositeEditCommand::trace(visitor); |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 } // namespace blink | 1730 } // namespace blink |
| OLD | NEW |