Changeset 111632 in webkit


Ignore:
Timestamp:
Mar 21, 2012 6:08:22 PM (12 years ago)
Author:
rniwa@webkit.org
Message:

BDI element should have dir=auto by default
https://bugs.webkit.org/show_bug.cgi?id=68773

Reviewed by Daniel Bates.

Source/WebCore:

Treat bdi elements without dir content attribute as if they have dir=auto per spec:
http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-bdi-element

The patch tries to encapsulate the logic to look for dir content attribute and dir=auto.

It also adds HTMLBDIElement interface (binding remains to use HTMLElement) to set
selfOrAncestorHasDirAutoAttribute flag true by default, which is used by functions like
directionalityIfhasDirAutoAttribute to look for elements with dir=auto. Since dir=auto-ness of bdi
elements can be overridden by dir content attribute, we must change and only change the default value.

Tests: fast/text/international/bdi-dir-default-to-auto-expected.html

fast/text/international/bdi-dir-default-to-auto.html

  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSStyleSelector.cpp:

(WebCore::CSSStyleSelector::collectMatchingRulesForList):

  • html/HTMLBDIElement.h: Added.

(WebCore):
(HTMLBDIElement):
(WebCore::HTMLBDIElement::create):
(WebCore::HTMLBDIElement::HTMLBDIElement): Sets selfOrAncestorHasDirAutoAttribute to true because
bdi elements are treated as if it has dir=auto by default.

  • html/HTMLElement.cpp:

(WebCore::elementAffectsDirectionality): Added. Checks if the specified element is bdi or
has dir content attribute.
(WebCore):
(WebCore::setHasDirAutoFlagRecursively):
(WebCore::HTMLElement::hasDirectionAuto): Added. Checks if the specified element should be treated
as if it has dir=auto (bdi or element with dir=auto).
(WebCore::HTMLElement::directionalityIfhasDirAutoAttribute):
(WebCore::HTMLElement::adjustDirectionalityIfNeededAfterChildAttributeChanged):
(WebCore::HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged):

  • html/HTMLElement.h:

(HTMLElement):

  • html/HTMLTagNames.in: Use HTMLBDIElement instead of HTMLElement for constructing bdi element

to set selfOrAncestorHasDirAutoAttribute true but still use HTMLElement for binding.

LayoutTests:

Add a test written by Aharon Lanin.

  • fast/text/international/bdi-dir-default-to-auto-expected.html: Added.
  • fast/text/international/bdi-dir-default-to-auto.html: Added.
Location:
trunk
Files:
3 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r111628 r111632  
     12012-03-21  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        BDI element should have dir=auto by default
     4        https://bugs.webkit.org/show_bug.cgi?id=68773
     5
     6        Reviewed by Daniel Bates.
     7
     8        Add a test written by Aharon Lanin.
     9
     10        * fast/text/international/bdi-dir-default-to-auto-expected.html: Added.
     11        * fast/text/international/bdi-dir-default-to-auto.html: Added.
     12
    1132012-03-21  Eric Carlson  <eric.carlson@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r111631 r111632  
     12012-03-21  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        BDI element should have dir=auto by default
     4        https://bugs.webkit.org/show_bug.cgi?id=68773
     5
     6        Reviewed by Daniel Bates.
     7
     8        Treat bdi elements without dir content attribute as if they have dir=auto per spec:
     9        http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-bdi-element
     10
     11        The patch tries to encapsulate the logic to look for dir content attribute and dir=auto.
     12
     13        It also adds HTMLBDIElement interface (binding remains to use HTMLElement) to set
     14        selfOrAncestorHasDirAutoAttribute flag true by default, which is used by functions like
     15        directionalityIfhasDirAutoAttribute to look for elements with dir=auto. Since dir=auto-ness of bdi
     16        elements can be overridden by dir content attribute, we must change and only change the default value.
     17
     18        Tests: fast/text/international/bdi-dir-default-to-auto-expected.html
     19               fast/text/international/bdi-dir-default-to-auto.html
     20
     21        * GNUmakefile.list.am:
     22        * Target.pri:
     23        * WebCore.gypi:
     24        * WebCore.vcproj/WebCore.vcproj:
     25        * WebCore.xcodeproj/project.pbxproj:
     26        * css/CSSStyleSelector.cpp:
     27        (WebCore::CSSStyleSelector::collectMatchingRulesForList):
     28        * html/HTMLBDIElement.h: Added.
     29        (WebCore):
     30        (HTMLBDIElement):
     31        (WebCore::HTMLBDIElement::create):
     32        (WebCore::HTMLBDIElement::HTMLBDIElement): Sets selfOrAncestorHasDirAutoAttribute to true because
     33        bdi elements are treated as if it has dir=auto by default.
     34        * html/HTMLElement.cpp:
     35        (WebCore::elementAffectsDirectionality): Added. Checks if the specified element is bdi or
     36        has dir content attribute.
     37        (WebCore):
     38        (WebCore::setHasDirAutoFlagRecursively):
     39        (WebCore::HTMLElement::hasDirectionAuto): Added. Checks if the specified element should be treated
     40        as if it has dir=auto (bdi or element with dir=auto).
     41        (WebCore::HTMLElement::directionalityIfhasDirAutoAttribute):
     42        (WebCore::HTMLElement::adjustDirectionalityIfNeededAfterChildAttributeChanged):
     43        (WebCore::HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged):
     44        * html/HTMLElement.h:
     45        (HTMLElement):
     46        * html/HTMLTagNames.in: Use HTMLBDIElement instead of HTMLElement for constructing bdi element
     47        to set selfOrAncestorHasDirAutoAttribute true but still use HTMLElement for binding.
     48
    1492012-03-21  Luke Macpherson  <macpherson@chromium.org>
    250
  • trunk/Source/WebCore/GNUmakefile.list.am

    r111474 r111632  
    22172217        Source/WebCore/html/HTMLBaseFontElement.cpp \
    22182218        Source/WebCore/html/HTMLBaseFontElement.h \
     2219        Source/WebCore/html/HTMLBDIElement.h \
    22192220        Source/WebCore/html/HTMLBodyElement.cpp \
    22202221        Source/WebCore/html/HTMLBodyElement.h \
  • trunk/Source/WebCore/Target.pri

    r111578 r111632  
    18491849    html/HTMLBaseFontElement.h \
    18501850    html/HTMLBodyElement.h \
     1851    html/HTMLBDIElement.h \
    18511852    html/HTMLBRElement.h \
    18521853    html/HTMLButtonElement.h \
  • trunk/Source/WebCore/WebCore.gypi

    r111572 r111632  
    53285328            'html/HTMLAudioElement.cpp',
    53295329            'html/HTMLAudioElement.h',
     5330            'html/HTMLBDIElement.h',
    53305331            'html/HTMLBRElement.cpp',
    53315332            'html/HTMLBRElement.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r111547 r111632  
    5767557675                        </File>
    5767657676                        <File
     57677                                RelativePath="..\html\HTMLBDIElement.h"
     57678                                >
     57679                        </File>
     57680                        <File
    5767757681                                RelativePath="..\html\HTMLBodyElement.cpp"
    5767857682                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r111474 r111632  
    35863586                9B0FB191140DB5790022588F /* HTTPValidation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B0FB18F140DB5790022588F /* HTTPValidation.cpp */; };
    35873587                9B0FB192140DB5790022588F /* HTTPValidation.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B0FB190140DB5790022588F /* HTTPValidation.h */; };
     3588                9B24DE8E15194B9500C59C27 /* HTMLBDIElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B24DE8C15194B9500C59C27 /* HTMLBDIElement.h */; };
    35883589                9B2B7AC11509850A008932CC /* MicroDataItemValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9B2F7CF714562120007F8B50 /* MicroDataItemValue.cpp */; };
    35893590                9B2D8A7914997CCF00ECEF3E /* UndoStep.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B2D8A7814997CCF00ECEF3E /* UndoStep.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1056210563                9B0FB18F140DB5790022588F /* HTTPValidation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPValidation.cpp; sourceTree = "<group>"; };
    1056310564                9B0FB190140DB5790022588F /* HTTPValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTTPValidation.h; sourceTree = "<group>"; };
     10565                9B24DE8C15194B9500C59C27 /* HTMLBDIElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLBDIElement.h; sourceTree = "<group>"; };
    1056410566                9B2D8A7814997CCF00ECEF3E /* UndoStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UndoStep.h; sourceTree = "<group>"; };
    1056510567                9B2F7CF714562120007F8B50 /* MicroDataItemValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MicroDataItemValue.cpp; sourceTree = "<group>"; };
     
    1364313645                                B22277CA0D00BF1E0071B782 /* svg */,
    1364413646                                417DA4CD13734204007C57FB /* testing */,
    13645                                 FD315FA212B025B100C1A359 /* webaudio */,
     13647                                FD315FA212B025B100C1A359 /* Modules/webaudio */,
    1364613648                                2E4346310F546A6800B0F1BA /* workers */,
    1364713649                                E1F0424309839389006694EA /* xml */,
     
    1677216774                                A8DF3FCA097FA0FB0052981B /* HTMLBaseFontElement.h */,
    1677316775                                1AE2A9F10A1CDA5700B42B25 /* HTMLBaseFontElement.idl */,
     16776                                9B24DE8C15194B9500C59C27 /* HTMLBDIElement.h */,
    1677416777                                A871DE1D0A152AC800B12A68 /* HTMLBodyElement.cpp */,
    1677516778                                A871DE200A152AC800B12A68 /* HTMLBodyElement.h */,
     
    2117021173                        sourceTree = "<group>";
    2117121174                };
    21172                 FD315FA212B025B100C1A359 /* webaudio */ = {
     21175                FD315FA212B025B100C1A359 /* Modules/webaudio */ = {
    2117321176                        isa = PBXGroup;
    2117421177                        children = (
     
    2269122694                                A871DC1F0A15205700B12A68 /* HTMLBaseElement.h in Headers */,
    2269222695                                A8DF3FD2097FA0FC0052981B /* HTMLBaseFontElement.h in Headers */,
     22696                                9B24DE8E15194B9500C59C27 /* HTMLBDIElement.h in Headers */,
    2269322697                                A871DE2C0A152AC800B12A68 /* HTMLBodyElement.h in Headers */,
    2269422698                                A8CFF7AA0A156978000A4234 /* HTMLBRElement.h in Headers */,
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r111631 r111632  
    12741274}
    12751275
     1276inline bool elementHasDirectionAuto(Element* element)
     1277{
     1278    return element->isHTMLElement() && toHTMLElement(element)->hasDirectionAuto();
     1279}
     1280
    12761281bool CSSStyleSelector::canShareStyleWithElement(StyledElement* element) const
    12771282{
     
    13681373#endif
    13691374
    1370     if (equalIgnoringCase(element->fastGetAttribute(dirAttr), "auto") || equalIgnoringCase(m_element->fastGetAttribute(dirAttr), "auto"))
     1375    if (elementHasDirectionAuto(element) || elementHasDirectionAuto(m_element))
    13711376        return false;
    13721377
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r110263 r111632  
    796796}
    797797
     798static inline bool elementAffectsDirectionality(const Node* node)
     799{
     800    return node->isHTMLElement() && (node->hasTagName(bdiTag) || toHTMLElement(node)->hasAttribute(dirAttr));
     801}
     802
    798803static void setHasDirAutoFlagRecursively(Node* firstNode, bool flag, Node* lastNode = 0)
    799804{
     
    806811            return;
    807812
    808         if (node->isHTMLElement() && toElement(node)->hasAttribute(dirAttr)) {
     813        if (elementAffectsDirectionality(node)) {
    809814            if (node == lastNode)
    810815                return;
     
    825830}
    826831
     832bool HTMLElement::hasDirectionAuto() const
     833{
     834    const AtomicString& direction = fastGetAttribute(dirAttr);
     835    return (hasTagName(bdiTag) && direction == nullAtom) || equalIgnoringCase(direction, "auto");
     836}
     837
    827838TextDirection HTMLElement::directionalityIfhasDirAutoAttribute(bool& isAuto) const
    828839{
    829     if (!(selfOrAncestorHasDirAutoAttribute() && equalIgnoringCase(getAttribute(dirAttr), "auto"))) {
     840    if (!(selfOrAncestorHasDirAutoAttribute() && hasDirectionAuto())) {
    830841        isAuto = false;
    831842        return LTR;
     
    900911        Element* elementToAdjust = this;
    901912        for (; elementToAdjust; elementToAdjust = elementToAdjust->parentElement()) {
    902             if (elementToAdjust->hasAttribute(dirAttr)) {
     913            if (elementAffectsDirectionality(elementToAdjust)) {
    903914                elementToAdjust->setNeedsStyleRecalc();
    904915                return;
     
    922933        Node* node = beforeChange ? beforeChange->traverseNextSibling() : 0;
    923934        for (int counter = 0; node && counter < childCountDelta; counter++, node = node->traverseNextSibling()) {
    924             if (node->isElementNode() && toElement(node)->hasAttribute(dirAttr))
     935            if (elementAffectsDirectionality(node))
    925936                continue;
    926937
     
    933944
    934945    Node* oldMarkedNode = beforeChange ? beforeChange->traverseNextSibling() : 0;
    935     while (oldMarkedNode && oldMarkedNode->isHTMLElement() && toHTMLElement(oldMarkedNode)->hasAttribute(dirAttr))
     946    while (oldMarkedNode && elementAffectsDirectionality(oldMarkedNode))
    936947        oldMarkedNode = oldMarkedNode->traverseNextSibling(this);
    937948    if (oldMarkedNode)
     
    939950
    940951    for (Element* elementToAdjust = this; elementToAdjust; elementToAdjust = elementToAdjust->parentElement()) {
    941         if (elementToAdjust->isHTMLElement() && elementToAdjust->hasAttribute(dirAttr)) {
     952        if (elementAffectsDirectionality(elementToAdjust)) {
    942953            toHTMLElement(elementToAdjust)->calculateAndAdjustDirectionality();
    943954            return;
  • trunk/Source/WebCore/html/HTMLElement.h

    r110927 r111632  
    9191    HTMLFormElement* findFormAncestor() const;
    9292
     93    bool hasDirectionAuto() const;
    9394    TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
    9495
  • trunk/Source/WebCore/html/HTMLTagNames.in

    r111532 r111632  
    1616base
    1717basefont interfaceName=HTMLBaseFontElement
    18 bdi interfaceName=HTMLElement
     18bdi interfaceName=HTMLBDIElement, JSInterfaceName=HTMLElement
    1919bdo interfaceName=HTMLElement
    2020bgsound interfaceName=HTMLElement
Note: See TracChangeset for help on using the changeset viewer.