Changeset 65013 in webkit


Ignore:
Timestamp:
Aug 9, 2010 4:18:37 PM (14 years ago)
Author:
rniwa@webkit.org
Message:

2010-08-09 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Tony Chang.

Use getIdentifierValue to obtain direction and unicode-bidi properties in ApplyStyleCommand
https://bugs.webkit.org/show_bug.cgi?id=43699

Deployed getIdentifierValue in various parts of ApplyStyleCommand where
direction and unicode-bidi properties were obtained manually.

No new tests since this is a cleanup.

  • editing/ApplyStyleCommand.cpp: (WebCore::getIdentifierValue): Takes CSSStyleDeclaration instead of CSSMutableStyleDeclaration. (WebCore::ApplyStyleCommand::splitAncestorsWithUnicodeBidi): Calls getIdentifierValue. (WebCore::ApplyStyleCommand::removeEmbeddingUpToEnclosingBlock): Calls getIdentifierValue. (WebCore::ApplyStyleCommand::applyInlineStyle): Calls getIdentifierValue.
  • editing/ApplyStyleCommand.h:
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65012 r65013  
     12010-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
    1202010-08-09  Adam Barth  <abarth@webkit.org>
    221
  • trunk/WebCore/editing/ApplyStyleCommand.cpp

    r64610 r65013  
    143143}
    144144
    145 static int getIdentifierValue(CSSMutableStyleDeclaration* style, int propertyID)
     145static int getIdentifierValue(CSSStyleDeclaration* style, int propertyID)
    146146{
    147147    if (!style)
     
    478478    style->diff(editingStyle);
    479479}
    480    
     480
    481481ApplyStyleCommand::ApplyStyleCommand(Document* document, CSSStyleDeclaration* style, EditAction editingAction, EPropertyLevel propertyLevel)
    482482    : CompositeEditCommand(document)
     
    794794}
    795795
    796 HTMLElement* ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool before, RefPtr<CSSPrimitiveValue> allowedDirection)
     796HTMLElement* ApplyStyleCommand::splitAncestorsWithUnicodeBidi(Node* node, bool before, int allowedDirection)
    797797{
    798798    // We are allowed to leave the highest ancestor with unicode-bidi unsplit if it is unicode-bidi: embed and direction: allowedDirection.
     
    804804    Node* highestAncestorWithUnicodeBidi = 0;
    805805    Node* nextHighestAncestorWithUnicodeBidi = 0;
    806     RefPtr<CSSPrimitiveValue> highestAncestorUnicodeBidi;
     806    int highestAncestorUnicodeBidi = 0;
    807807    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;
    816813        }
    817814    }
     
    822819    HTMLElement* unsplitAncestor = 0;
    823820
    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;
    834829    }
    835830
     
    853848        return;
    854849
    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())
    860854            continue;
    861         }
    862855
    863856        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        }
    888878    }
    889879}
     
    932922    }
    933923
    934     RefPtr<CSSValue> unicodeBidi = style->getPropertyCSSValue(CSSPropertyUnicodeBidi);
    935     RefPtr<CSSValue> direction;
     924    int unicodeBidi = getIdentifierValue(style, CSSPropertyUnicodeBidi);
     925    int direction = 0;
    936926    HTMLElement* startUnsplitAncestor = 0;
    937927    HTMLElement* endUnsplitAncestor = 0;
    938928    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);
    949934        removeEmbeddingUpToEnclosingBlock(start.node(), startUnsplitAncestor);
    950935        removeEmbeddingUpToEnclosingBlock(end.node(), endUnsplitAncestor);
     
    970955        RefPtr<CSSMutableStyleDeclaration> embeddingStyle = CSSMutableStyleDeclaration::create();
    971956        embeddingStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
    972         embeddingStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent());
     957        embeddingStyle->setProperty(CSSPropertyDirection, direction);
    973958        if (comparePositions(embeddingRemoveStart, embeddingRemoveEnd) <= 0)
    974959            removeInlineStyle(embeddingStyle, embeddingRemoveStart, embeddingRemoveEnd);
     
    1009994        Node* startEnclosingBlock = enclosingBlock(start.node());
    1010995        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;
    1020999            }
    10211000        }
     
    10231002        Node* endEnclosingBlock = enclosingBlock(end.node());
    10241003        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;
    10341007            }
    10351008        }
     
    10401013            RefPtr<CSSMutableStyleDeclaration> embeddingStyle = CSSMutableStyleDeclaration::create();
    10411014            embeddingStyle->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
    1042             embeddingStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent());
     1015            embeddingStyle->setProperty(CSSPropertyDirection, direction);
    10431016            applyInlineStyleToRange(embeddingStyle.get(), embeddingApplyStart, embeddingApplyEnd);
    10441017        }
  • trunk/WebCore/editing/ApplyStyleCommand.h

    r64610 r65013  
    107107    void joinChildTextNodes(Node*, const Position& start, const Position& end);
    108108
    109     HTMLElement* splitAncestorsWithUnicodeBidi(Node*, bool before, RefPtr<CSSPrimitiveValue> allowedDirection);
     109    HTMLElement* splitAncestorsWithUnicodeBidi(Node*, bool before, int allowedDirection);
    110110    void removeEmbeddingUpToEnclosingBlock(Node* node, Node* unsplitAncestor);
    111111
Note: See TracChangeset for help on using the changeset viewer.