Changeset 65013 in webkit
- Timestamp:
- Aug 9, 2010 4:18:37 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r65012 r65013 1 2010-08-09 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Tony Chang. 4 5 Use getIdentifierValue to obtain direction and unicode-bidi properties in ApplyStyleCommand 6 https://bugs.webkit.org/show_bug.cgi?id=43699 7 8 Deployed getIdentifierValue in various parts of ApplyStyleCommand where 9 direction and unicode-bidi properties were obtained manually. 10 11 No new tests since this is a cleanup. 12 13 * editing/ApplyStyleCommand.cpp: 14 (WebCore::getIdentifierValue): Takes CSSStyleDeclaration instead of CSSMutableStyleDeclaration. 15 (WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi): Calls getIdentifierValue. 16 (WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock): Calls getIdentifierValue. 17 (WebCore::ApplyStyleCommand::applyInlineStyle): Calls getIdentifierValue. 18 * editing/ApplyStyleCommand.h: 19 1 20 2010-08-09 Adam Barth <abarth@webkit.org> 2 21 -
trunk/WebCore/editing/ApplyStyleCommand.cpp
r64610 r65013 143 143 } 144 144 145 static int getIdentifierValue(CSS MutableStyleDeclaration* style, int propertyID)145 static int getIdentifierValue(CSSStyleDeclaration* style, int propertyID) 146 146 { 147 147 if (!style) … … 478 478 style->diff(editingStyle); 479 479 } 480 480 481 481 ApplyStyleCommand::ApplyStyleCommand(Document* document, CSSStyleDeclaration* style, EditAction editingAction, EPropertyLevel propertyLevel) 482 482 : CompositeEditCommand(document) … … 794 794 } 795 795 796 HTMLElement* ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool before, RefPtr<CSSPrimitiveValue>allowedDirection)796 HTMLElement* ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool before, int allowedDirection) 797 797 { 798 798 // We are allowed to leave the highest ancestor with unicode-bidi unsplit if it is unicode-bidi: embed and direction: allowedDirection. … … 804 804 Node* highestAncestorWithUnicodeBidi = 0; 805 805 Node* nextHighestAncestorWithUnicodeBidi = 0; 806 RefPtr<CSSPrimitiveValue> highestAncestorUnicodeBidi;806 int highestAncestorUnicodeBidi = 0; 807 807 for (Node* n = node->parent(); n != block; n = n->parent()) { 808 RefPtr<CSSValue> unicodeBidi = computedStyle(n)->getPropertyCSSValue(CSSPropertyUnicodeBidi); 809 if (unicodeBidi) { 810 ASSERT(unicodeBidi->isPrimitiveValue()); 811 if (static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent() != CSSValueNormal) { 812 highestAncestorUnicodeBidi = static_cast<CSSPrimitiveValue*>(unicodeBidi.get()); 813 nextHighestAncestorWithUnicodeBidi = highestAncestorWithUnicodeBidi; 814 highestAncestorWithUnicodeBidi = n; 815 } 808 int unicodeBidi = getIdentifierValue(computedStyle(n).get(), CSSPropertyUnicodeBidi); 809 if (unicodeBidi && unicodeBidi != CSSValueNormal) { 810 highestAncestorUnicodeBidi = unicodeBidi; 811 nextHighestAncestorWithUnicodeBidi = highestAncestorWithUnicodeBidi; 812 highestAncestorWithUnicodeBidi = n; 816 813 } 817 814 } … … 822 819 HTMLElement* unsplitAncestor = 0; 823 820 824 if (allowedDirection && highestAncestorUnicodeBidi->getIdent() != CSSValueBidiOverride) { 825 RefPtr<CSSValue> highestAncestorDirection = computedStyle(highestAncestorWithUnicodeBidi)->getPropertyCSSValue(CSSPropertyDirection); 826 ASSERT(highestAncestorDirection->isPrimitiveValue()); 827 if (static_cast<CSSPrimitiveValue*>(highestAncestorDirection.get())->getIdent() == allowedDirection->getIdent() && highestAncestorWithUnicodeBidi->isHTMLElement()) { 828 if (!nextHighestAncestorWithUnicodeBidi) 829 return static_cast<HTMLElement*>(highestAncestorWithUnicodeBidi); 830 831 unsplitAncestor = static_cast<HTMLElement*>(highestAncestorWithUnicodeBidi); 832 highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi; 833 } 821 if (allowedDirection && highestAncestorUnicodeBidi != CSSValueBidiOverride 822 && getIdentifierValue(computedStyle(highestAncestorWithUnicodeBidi).get(), CSSPropertyDirection) == allowedDirection 823 && highestAncestorWithUnicodeBidi->isHTMLElement()) { 824 if (!nextHighestAncestorWithUnicodeBidi) 825 return static_cast<HTMLElement*>(highestAncestorWithUnicodeBidi); 826 827 unsplitAncestor = static_cast<HTMLElement*>(highestAncestorWithUnicodeBidi); 828 highestAncestorWithUnicodeBidi = nextHighestAncestorWithUnicodeBidi; 834 829 } 835 830 … … 853 848 return; 854 849 855 Node* n = node->parent(); 856 while (n != block && n != unsplitAncestor) { 857 Node* parent = n->parent(); 858 if (!n->isStyledElement()) { 859 n = parent; 850 Node* parent = 0; 851 for (Node* n = node->parent(); n != block && n != unsplitAncestor; n = parent) { 852 parent = n->parent(); 853 if (!n->isStyledElement()) 860 854 continue; 861 }862 855 863 856 StyledElement* element = static_cast<StyledElement*>(n); 864 RefPtr<CSSValue> unicodeBidi = computedStyle(element)->getPropertyCSSValue(CSSPropertyUnicodeBidi); 865 if (unicodeBidi) { 866 ASSERT(unicodeBidi->isPrimitiveValue()); 867 if (static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent() != CSSValueNormal) { 868 // FIXME: This code should really consider the mapped attribute 'dir', the inline style declaration, 869 // and all matching style rules in order to determine how to best set the unicode-bidi property to 'normal'. 870 // For now, it assumes that if the 'dir' attribute is present, then removing it will suffice, and 871 // otherwise it sets the property in the inline style declaration. 872 if (element->hasAttribute(dirAttr)) { 873 // FIXME: If this is a BDO element, we should probably just remove it if it has no 874 // other attributes, like we (should) do with B and I elements. 875 removeNodeAttribute(element, dirAttr); 876 } else { 877 RefPtr<CSSMutableStyleDeclaration> inlineStyle = element->getInlineStyleDecl()->copy(); 878 inlineStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); 879 inlineStyle->removeProperty(CSSPropertyDirection); 880 setNodeAttribute(element, styleAttr, inlineStyle->cssText()); 881 // FIXME: should this be isSpanWithoutAttributesOrUnstyleStyleSpan? Need a test. 882 if (isUnstyledStyleSpan(element)) 883 removeNodePreservingChildren(element); 884 } 885 } 886 } 887 n = parent; 857 int unicodeBidi = getIdentifierValue(computedStyle(element).get(), CSSPropertyUnicodeBidi); 858 if (!unicodeBidi || unicodeBidi == CSSValueNormal) 859 continue; 860 861 // FIXME: This code should really consider the mapped attribute 'dir', the inline style declaration, 862 // and all matching style rules in order to determine how to best set the unicode-bidi property to 'normal'. 863 // For now, it assumes that if the 'dir' attribute is present, then removing it will suffice, and 864 // otherwise it sets the property in the inline style declaration. 865 if (element->hasAttribute(dirAttr)) { 866 // FIXME: If this is a BDO element, we should probably just remove it if it has no 867 // other attributes, like we (should) do with B and I elements. 868 removeNodeAttribute(element, dirAttr); 869 } else { 870 RefPtr<CSSMutableStyleDeclaration> inlineStyle = element->getInlineStyleDecl()->copy(); 871 inlineStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); 872 inlineStyle->removeProperty(CSSPropertyDirection); 873 setNodeAttribute(element, styleAttr, inlineStyle->cssText()); 874 // FIXME: should this be isSpanWithoutAttributesOrUnstyleStyleSpan? Need a test. 875 if (isUnstyledStyleSpan(element)) 876 removeNodePreservingChildren(element); 877 } 888 878 } 889 879 } … … 932 922 } 933 923 934 RefPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi);935 RefPtr<CSSValue> direction;924 int unicodeBidi = getIdentifierValue(style, CSSPropertyUnicodeBidi); 925 int direction = 0; 936 926 HTMLElement* startUnsplitAncestor = 0; 937 927 HTMLElement* endUnsplitAncestor = 0; 938 928 if (unicodeBidi) { 939 RefPtr<CSSPrimitiveValue> allowedDirection; 940 ASSERT(unicodeBidi->isPrimitiveValue()); 941 if (static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent() == CSSValueEmbed) { 942 // Leave alone an ancestor that provides the desired single level embedding, if there is one. 943 direction = style->getPropertyCSSValue(CSSPropertyDirection); 944 ASSERT(direction->isPrimitiveValue()); 945 allowedDirection = static_cast<CSSPrimitiveValue*>(direction.get()); 946 } 947 startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.node(), true, allowedDirection); 948 endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.node(), false, allowedDirection); 929 // Leave alone an ancestor that provides the desired single level embedding, if there is one. 930 if (unicodeBidi == CSSValueEmbed) 931 direction = getIdentifierValue(style, CSSPropertyDirection); 932 startUnsplitAncestor = splitAncestorsWithUnicodeBidi(start.node(), true, direction); 933 endUnsplitAncestor = splitAncestorsWithUnicodeBidi(end.node(), false, direction); 949 934 removeEmbeddingUpToEnclosingBlock(start.node(), startUnsplitAncestor); 950 935 removeEmbeddingUpToEnclosingBlock(end.node(), endUnsplitAncestor); … … 970 955 RefPtr<CSSMutableStyleDeclaration> embeddingStyle = CSSMutableStyleDeclaration::create(); 971 956 embeddingStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); 972 embeddingStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent());957 embeddingStyle->setProperty(CSSPropertyDirection, direction); 973 958 if (comparePositions(embeddingRemoveStart, embeddingRemoveEnd) <= 0) 974 959 removeInlineStyle(embeddingStyle, embeddingRemoveStart, embeddingRemoveEnd); … … 1009 994 Node* startEnclosingBlock = enclosingBlock(start.node()); 1010 995 for (Node* n = start.node(); n != startEnclosingBlock; n = n->parent()) { 1011 if (n->isHTMLElement()) { 1012 RefPtr<CSSValue> ancestorUnicodeBidi = computedStyle(n)->getPropertyCSSValue(CSSPropertyUnicodeBidi); 1013 if (ancestorUnicodeBidi) { 1014 ASSERT(ancestorUnicodeBidi->isPrimitiveValue()); 1015 if (static_cast<CSSPrimitiveValue*>(ancestorUnicodeBidi.get())->getIdent() == CSSValueEmbed) { 1016 embeddingApplyStart = positionInParentAfterNode(n); 1017 break; 1018 } 1019 } 996 if (n->isHTMLElement() && getIdentifierValue(computedStyle(n).get(), CSSPropertyUnicodeBidi) == CSSValueEmbed) { 997 embeddingApplyStart = positionInParentAfterNode(n); 998 break; 1020 999 } 1021 1000 } … … 1023 1002 Node* endEnclosingBlock = enclosingBlock(end.node()); 1024 1003 for (Node* n = end.node(); n != endEnclosingBlock; n = n->parent()) { 1025 if (n->isHTMLElement()) { 1026 RefPtr<CSSValue> ancestorUnicodeBidi = computedStyle(n)->getPropertyCSSValue(CSSPropertyUnicodeBidi); 1027 if (ancestorUnicodeBidi) { 1028 ASSERT(ancestorUnicodeBidi->isPrimitiveValue()); 1029 if (static_cast<CSSPrimitiveValue*>(ancestorUnicodeBidi.get())->getIdent() == CSSValueEmbed) { 1030 embeddingApplyEnd = positionInParentBeforeNode(n); 1031 break; 1032 } 1033 } 1004 if (n->isHTMLElement() && getIdentifierValue(computedStyle(n).get(), CSSPropertyUnicodeBidi) == CSSValueEmbed) { 1005 embeddingApplyEnd = positionInParentBeforeNode(n); 1006 break; 1034 1007 } 1035 1008 } … … 1040 1013 RefPtr<CSSMutableStyleDeclaration> embeddingStyle = CSSMutableStyleDeclaration::create(); 1041 1014 embeddingStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); 1042 embeddingStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent());1015 embeddingStyle->setProperty(CSSPropertyDirection, direction); 1043 1016 applyInlineStyleToRange(embeddingStyle.get(), embeddingApplyStart, embeddingApplyEnd); 1044 1017 } -
trunk/WebCore/editing/ApplyStyleCommand.h
r64610 r65013 107 107 void joinChildTextNodes(Node*, const Position& start, const Position& end); 108 108 109 HTMLElement* splitAncestorsWithUnicodeBidi(Node*, bool before, RefPtr<CSSPrimitiveValue>allowedDirection);109 HTMLElement* splitAncestorsWithUnicodeBidi(Node*, bool before, int allowedDirection); 110 110 void removeEmbeddingUpToEnclosingBlock(Node* node, Node* unsplitAncestor); 111 111
Note: See TracChangeset
for help on using the changeset viewer.