Changeset 110161 in webkit


Ignore:
Timestamp:
Mar 8, 2012 3:25:33 AM (12 years ago)
Author:
shinyak@chromium.org
Message:

<shadow> should be rendered correctly.
https://bugs.webkit.org/show_bug.cgi?id=78596

Reviewed by Hajime Morita.

Source/WebCore:

This patch supports <shadow> element rendering.

When attaching <shadow> element, if it is in the oldest shadow tree, it runs a part of
distribution algorithm. If it is in non-oldest shadow tree, it runs tree a part of
tree composition algorithm to assign a older shadow root. In this patch, InsertionPonit
try to treat the distributed host children and the assigned shadow children similarly.

NodeRenderingContext supports rendering <shadow> element. Since the assigned shadow children
are treated like distributed host children, that change is to consider non-youngest shadow
tree basically also.

Tests: fast/dom/shadow/shadow-element-rendering-multiple.html

fast/dom/shadow/shadow-element-rendering-single.html

  • dom/NodeRenderingContext.cpp:

(WebCore):
(WebCore::NodeRenderingContext::NodeRenderingContext):

Does not ignore non-youngest shadow tree.

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::ShadowRoot):

  • dom/ShadowRoot.h:

(ShadowRoot):
(WebCore::ShadowRoot::assignedTo):
(WebCore):
(WebCore::ShadowRoot::setAssignedTo):
(WebCore::ShadowRoot::isUsedForRendering):

Returns true if ShadowRoot is youngest or assigned to some InsertionPoint.

(WebCore::toShadowRoot):

  • dom/ShadowTree.cpp:

(WebCore::ShadowTree::insertionPointFor):

Returns InsertionPoint to which node is distributed.

  • dom/ShadowTree.h:

(ShadowTree):

  • html/shadow/HTMLContentElement.h:

(WebCore::HTMLContentElement::doesSelectFromHostChildren):
(HTMLContentElement):

  • html/shadow/HTMLShadowElement.cpp:

(WebCore::HTMLShadowElement::HTMLShadowElement):
(WebCore::HTMLShadowElement::select):
(WebCore::HTMLShadowElement::doesSelectFromHostChildren):
(WebCore):

  • html/shadow/HTMLShadowElement.h:

(HTMLShadowElement):

  • html/shadow/InsertionPoint.cpp:

(WebCore::InsertionPoint::attach):
(WebCore::InsertionPoint::detach):
(WebCore::InsertionPoint::assignedFrom):
(WebCore):
(WebCore::InsertionPoint::assignShadowRoot):
(WebCore::InsertionPoint::clearAssignment):

  • html/shadow/InsertionPoint.h:

(InsertionPoint):

LayoutTests:

Contains tests both in case <shadow> appears in the oldest shadow root and
non-olderst shadow tree.

  • fast/dom/shadow/shadow-element-rendering-multiple-expected.txt: Added.
  • fast/dom/shadow/shadow-element-rendering-multiple.html: Added.
  • fast/dom/shadow/shadow-element-rendering-single-expected.txt: Added.
  • fast/dom/shadow/shadow-element-rendering-single.html: Added.
  • platform/efl/Skipped:
  • platform/mac/Skipped:
  • platform/qt/Skipped:
  • platform/win/Skipped:
  • platform/wincairo/Skipped:
  • platform/wk2/Skipped:
Location:
trunk
Files:
4 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r110155 r110161  
     12012-03-08  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        <shadow> should be rendered correctly.
     4        https://bugs.webkit.org/show_bug.cgi?id=78596
     5
     6        Reviewed by Hajime Morita.
     7
     8        Contains tests both in case <shadow> appears in the oldest shadow root and
     9        non-olderst shadow tree.
     10
     11        * fast/dom/shadow/shadow-element-rendering-multiple-expected.txt: Added.
     12        * fast/dom/shadow/shadow-element-rendering-multiple.html: Added.
     13        * fast/dom/shadow/shadow-element-rendering-single-expected.txt: Added.
     14        * fast/dom/shadow/shadow-element-rendering-single.html: Added.
     15        * platform/efl/Skipped:
     16        * platform/mac/Skipped:
     17        * platform/qt/Skipped:
     18        * platform/win/Skipped:
     19        * platform/wincairo/Skipped:
     20        * platform/wk2/Skipped:
     21
    1222012-03-08  Yoshifumi Inoue  <yosin@chromium.org>
    223
  • trunk/LayoutTests/platform/efl/Skipped

    r110028 r110161  
    20812081fast/dom/shadow/shadow-root-new.html
    20822082fast/dom/shadow/shadow-root-append.html
     2083fast/dom/shadow/shadow-element-rendering-single.html
     2084fast/dom/shadow/shadow-element-rendering-multiple.html
    20832085fast/dom/shadow/multiple-shadowroot.html
    20842086fast/dom/shadow/multiple-shadowroot-rendering.html
  • trunk/LayoutTests/platform/mac/Skipped

    r109359 r110161  
    437437fast/dom/shadow/shadow-ul-li.html
    438438fast/dom/shadow/shadow-root-append.html
     439fast/dom/shadow/shadow-element-rendering-single.html
     440fast/dom/shadow/shadow-element-rendering-multiple.html
    439441fast/dom/shadow/multiple-shadowroot.html
    440442fast/dom/shadow/multiple-shadowroot-rendering.html
  • trunk/LayoutTests/platform/qt/Skipped

    r109891 r110161  
    176176fast/dom/shadow/shadow-ul-li.html
    177177fast/dom/shadow/shadow-root-append.html
     178fast/dom/shadow/shadow-element-rendering-single.html
     179fast/dom/shadow/shadow-element-rendering-multiple.html
    178180fast/dom/shadow/multiple-shadowroot.html
    179181fast/dom/shadow/multiple-shadowroot-rendering.html
  • trunk/LayoutTests/platform/win/Skipped

    r110090 r110161  
    14631463fast/dom/shadow/shadow-ul-li.html
    14641464fast/dom/shadow/shadow-root-append.html
     1465fast/dom/shadow/shadow-element-rendering-single.html
     1466fast/dom/shadow/shadow-element-rendering-multiple.html
    14651467fast/dom/shadow/multiple-shadowroot.html
    14661468fast/dom/shadow/multiple-shadowroot-rendering.html
  • trunk/LayoutTests/platform/wincairo/Skipped

    r109359 r110161  
    19761976fast/dom/shadow/shadow-root-new.html
    19771977fast/dom/shadow/shadow-root-append.html
     1978fast/dom/shadow/shadow-element-rendering-single.html
     1979fast/dom/shadow/shadow-element-rendering-multiple.html
    19781980fast/dom/shadow/multiple-shadowroot.html
    19791981fast/dom/shadow/multiple-shadowroot-rendering.html
  • trunk/LayoutTests/platform/wk2/Skipped

    r109792 r110161  
    10741074fast/dom/shadow/shadow-ul-li.html
    10751075fast/dom/shadow/shadow-root-append.html
     1076fast/dom/shadow/shadow-element-rendering-single.html
     1077fast/dom/shadow/shadow-element-rendering-multiple.html
    10761078fast/dom/shadow/multiple-shadowroot.html
    10771079fast/dom/shadow/multiple-shadowroot-rendering.html
  • trunk/Source/WebCore/ChangeLog

    r110160 r110161  
     12012-03-08  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        <shadow> should be rendered correctly.
     4        https://bugs.webkit.org/show_bug.cgi?id=78596
     5
     6        Reviewed by Hajime Morita.
     7
     8        This patch supports <shadow> element rendering.
     9
     10        When attaching <shadow> element, if it is in the oldest shadow tree, it runs a part of
     11        distribution algorithm. If it is in non-oldest shadow tree, it runs tree a part of
     12        tree composition algorithm to assign a older shadow root. In this patch, InsertionPonit
     13        try to treat the distributed host children and the assigned shadow children similarly.
     14
     15        NodeRenderingContext supports rendering <shadow> element. Since the assigned shadow children
     16        are treated like distributed host children, that change is to consider non-youngest shadow
     17        tree basically also.
     18
     19        Tests: fast/dom/shadow/shadow-element-rendering-multiple.html
     20               fast/dom/shadow/shadow-element-rendering-single.html
     21
     22        * dom/NodeRenderingContext.cpp:
     23        (WebCore):
     24        (WebCore::NodeRenderingContext::NodeRenderingContext):
     25          Does not ignore non-youngest shadow tree.
     26        * dom/ShadowRoot.cpp:
     27        (WebCore::ShadowRoot::ShadowRoot):
     28        * dom/ShadowRoot.h:
     29        (ShadowRoot):
     30        (WebCore::ShadowRoot::assignedTo):
     31        (WebCore):
     32        (WebCore::ShadowRoot::setAssignedTo):
     33        (WebCore::ShadowRoot::isUsedForRendering):
     34          Returns true if ShadowRoot is youngest or assigned to some InsertionPoint.
     35        (WebCore::toShadowRoot):
     36        * dom/ShadowTree.cpp:
     37        (WebCore::ShadowTree::insertionPointFor):
     38          Returns InsertionPoint to which node is distributed.
     39        * dom/ShadowTree.h:
     40        (ShadowTree):
     41        * html/shadow/HTMLContentElement.h:
     42        (WebCore::HTMLContentElement::doesSelectFromHostChildren):
     43        (HTMLContentElement):
     44        * html/shadow/HTMLShadowElement.cpp:
     45        (WebCore::HTMLShadowElement::HTMLShadowElement):
     46        (WebCore::HTMLShadowElement::select):
     47        (WebCore::HTMLShadowElement::doesSelectFromHostChildren):
     48        (WebCore):
     49        * html/shadow/HTMLShadowElement.h:
     50        (HTMLShadowElement):
     51        * html/shadow/InsertionPoint.cpp:
     52        (WebCore::InsertionPoint::attach):
     53        (WebCore::InsertionPoint::detach):
     54        (WebCore::InsertionPoint::assignedFrom):
     55        (WebCore):
     56        (WebCore::InsertionPoint::assignShadowRoot):
     57        (WebCore::InsertionPoint::clearAssignment):
     58        * html/shadow/InsertionPoint.h:
     59        (InsertionPoint):
     60
    1612012-03-06  Hans Wennborg  <hans@chromium.org>
    262
  • trunk/Source/WebCore/dom/NodeRenderingContext.cpp

    r109704 r110161  
    3030#include "HTMLContentElement.h"
    3131#include "HTMLContentSelector.h"
     32#include "HTMLNames.h"
     33#include "HTMLShadowElement.h"
    3234#include "Node.h"
    3335#include "RenderFlowThread.h"
     
    4345
    4446namespace WebCore {
     47
     48using namespace HTMLNames;
    4549
    4650static RenderObject* firstRendererOf(Node*);
     
    6064        return;
    6165
    62     if (parent->isShadowRoot()) {
    63         // FIXME: We don't support <shadow> yet, so the non-youngest shadow won't be rendered.
    64         // https://bugs.webkit.org/shod_bugs.cgi?id=78596
    65         if (toShadowRoot(parent)->isYoungest())
    66             m_phase = AttachingShadowChild;
    67         else
    68             m_phase = AttachingNotDistributed;
     66    if (parent->isShadowRoot() && toShadowRoot(parent)->isYoungest()) {
     67        m_phase = AttachingShadowChild;
    6968        m_parentNodeForRenderingAndStyle = parent->shadowHost();
    7069        return;
    7170    }
    7271
    73     if (parent->isElementNode()) {
    74         if (toElement(parent)->hasShadowRoot()) {
     72    if (parent->isElementNode() || parent->isShadowRoot()) {
     73        if (parent->isElementNode() && toElement(parent)->hasShadowRoot())
    7574            m_visualParentShadowTree = toElement(parent)->shadowTree();
    76             if ((m_insertionPoint = m_visualParentShadowTree->insertionPointFor(m_node))
    77                 && m_visualParentShadowTree->isSelectorActive()) {
    78 
    79                 // FIXME: We don't support <shadow> yet, so the non-youngest shadow won't be rendered.
    80                 // https://bugs.webkit.org/show_bugs.cgi?id=78596
    81                 if (toShadowRoot(m_insertionPoint->shadowTreeRootNode())->isYoungest()) {
     75        else if (parent->isShadowRoot())
     76            m_visualParentShadowTree = toShadowRoot(parent)->tree();
     77
     78        if (m_visualParentShadowTree) {
     79            if ((m_insertionPoint = m_visualParentShadowTree->insertionPointFor(m_node))) {
     80                if (toShadowRoot(m_insertionPoint->shadowTreeRootNode())->isUsedForRendering()) {
    8281                    m_phase = AttachingDistributed;
    8382                    m_parentNodeForRenderingAndStyle = NodeRenderingContext(m_insertionPoint).parentNodeForRenderingAndStyle();
     
    9291
    9392        if (isShadowBoundary(parent)) {
    94             // FIXME: We don't support <shadow> yet, so the non-youngest shadow won't be rendered.
    95             // https://bugs.webkit.org/show_bugs.cgi?id=78596
    96             if (!toShadowRoot(parent->shadowTreeRootNode())->isYoungest()) {
     93            if (!toShadowRoot(parent->shadowTreeRootNode())->isUsedForRendering()) {
    9794                m_phase = AttachingNotDistributed;
    9895                m_parentNodeForRenderingAndStyle = parent;
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r109563 r110161  
    5353    , m_next(0)
    5454    , m_applyAuthorSheets(false)
     55    , m_insertionPointAssignedTo(0)
    5556{
    5657    ASSERT(document);
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r109563 r110161  
    8484    virtual void attach();
    8585
     86    bool isUsedForRendering() const;
     87    InsertionPoint* assignedTo() const;
     88    void setAssignedTo(InsertionPoint*);
     89
    8690private:
    8791    ShadowRoot(Document*);
     
    9599    ShadowRoot* m_next;
    96100    bool m_applyAuthorSheets : 1;
     101    InsertionPoint* m_insertionPointAssignedTo;
    97102};
     103
     104inline InsertionPoint* ShadowRoot::assignedTo() const
     105{
     106    return m_insertionPointAssignedTo;
     107}
     108
     109inline void ShadowRoot::setAssignedTo(InsertionPoint* insertionPoint)
     110{
     111    ASSERT(!m_insertionPointAssignedTo || !insertionPoint);
     112    m_insertionPointAssignedTo = insertionPoint;
     113}
     114
     115inline bool ShadowRoot::isUsedForRendering() const
     116{
     117    return isYoungest() || assignedTo();
     118}
    98119
    99120inline const ShadowRoot* toShadowRoot(const Node* node)
     
    108129}
    109130
     131inline ShadowRoot* toShadowRoot(TreeScope* scope)
     132{
     133    ASSERT(!scope || scope->isShadowRoot());
     134    return static_cast<ShadowRoot*>(scope);
     135}
     136
    110137// Put this TreeScope method here to inline it.
    111138inline bool TreeScope::isShadowRoot() const
  • trunk/Source/WebCore/dom/ShadowTree.cpp

    r109563 r110161  
    3232#include "Element.h"
    3333#include "HTMLContentSelector.h"
     34#include "HTMLShadowElement.h"
    3435#include "InspectorInstrumentation.h"
    3536#include "RuntimeEnabledFeatures.h"
     
    199200InsertionPoint* ShadowTree::insertionPointFor(Node* node) const
    200201{
     202    ASSERT(node && node->parentNode());
     203
     204    if (node->parentNode()->isShadowRoot()) {
     205        if (InsertionPoint* insertionPoint = toShadowRoot(node->parentNode())->assignedTo())
     206            return insertionPoint;
     207
     208        return 0;
     209    }
     210
    201211    if (!m_selector)
    202212        return 0;
     
    205215        return 0;
    206216    return found->insertionPoint();
    207 }
    208 
    209 bool ShadowTree::isSelectorActive() const
    210 {
    211     return m_selector && m_selector->hasCandidates();
    212217}
    213218
  • trunk/Source/WebCore/dom/ShadowTree.h

    r109290 r110161  
    8383    HTMLContentSelector* ensureSelector();
    8484
    85     bool isSelectorActive() const;
    86 
    8785private:
    8886    Element* host() const;
  • trunk/Source/WebCore/html/shadow/HTMLContentElement.h

    r110151 r110161  
    4848    virtual bool isSelectValid() const;
    4949
     50    bool doesSelectFromHostChildren() const { return true; }
     51
    5052protected:
    5153    HTMLContentElement(const QualifiedName&, Document*);
  • trunk/Source/WebCore/html/shadow/HTMLShadowElement.cpp

    r106794 r110161  
    3030
    3131#include "config.h"
    32 
    33 #if ENABLE(SHADOW_DOM)
    34 
    3532#include "HTMLShadowElement.h"
    3633
    3734#include "HTMLNames.h"
     35#include "ShadowRoot.h"
     36#include <wtf/text/AtomicString.h>
    3837
    3938namespace WebCore {
     
    4241
    4342inline HTMLShadowElement::HTMLShadowElement(const QualifiedName& tagName, Document* document)
    44     : HTMLElement(tagName, document)
     43    : InsertionPoint(tagName, document)
    4544{
    4645    ASSERT(hasTagName(HTMLNames::shadowTag));
     
    5655}
    5756
     57const AtomicString& HTMLShadowElement::select() const
     58{
     59     return nullAtom;
     60}
     61
     62bool HTMLShadowElement::doesSelectFromHostChildren() const
     63{
     64    TreeScope* scope = treeScope();
     65
     66    if (scope->isShadowRoot())
     67        return toShadowRoot(scope)->isOldest();
     68    return false;
     69}
     70
    5871} // namespace WebCore
    59 
    60 #endif // ENABLE(SHADOW_DOM)
  • trunk/Source/WebCore/html/shadow/HTMLShadowElement.h

    r107347 r110161  
    3232#define HTMLShadowElement_h
    3333
    34 #if ENABLE(SHADOW_DOM)
    35 
    36 #include "HTMLElement.h"
     34#include "InsertionPoint.h"
     35#include <wtf/Forward.h>
    3736
    3837namespace WebCore {
    3938
    40 class HTMLShadowElement : public HTMLElement {
     39class HTMLShadowElement : public InsertionPoint {
    4140public:
    4241    static PassRefPtr<HTMLShadowElement> create(const QualifiedName&, Document*);
     
    4443    virtual ~HTMLShadowElement();
    4544
     45    const AtomicString& select() const;
     46    bool isSelectValid() const OVERRIDE { return true; }
     47    bool doesSelectFromHostChildren() const;
     48
    4649private:
    4750    HTMLShadowElement(const QualifiedName&, Document*);
    48     virtual bool isShadowElement() const { return true; }
    4951};
    5052
    5153} // namespace WebCore
    5254
    53 #endif // ENABLE(SHADOW_DOM)
    54 
    5555#endif // HTMLShadowElement_h
  • trunk/Source/WebCore/html/shadow/InsertionPoint.cpp

    r109864 r110161  
    4949void InsertionPoint::attach()
    5050{
    51     if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode())) {
    52         distributeHostChildren(root->tree());
    53         attachDistributedNode();
     51    TreeScope* scope = treeScope();
     52    if (scope->isShadowRoot()) {
     53        ShadowRoot* root = toShadowRoot(scope);
     54        if (doesSelectFromHostChildren()) {
     55            distributeHostChildren(root->tree());
     56            attachDistributedNode();
     57        } else if (!root->olderShadowRoot()->assignedTo()) {
     58            ASSERT(!root->olderShadowRoot()->attached());
     59            assignShadowRoot(root->olderShadowRoot());
     60            root->olderShadowRoot()->attach();
     61        }
    5462    }
    5563
     
    6169    if (ShadowRoot* root = toShadowRoot(shadowTreeRootNode())) {
    6270        ShadowTree* tree = root->tree();
    63         clearDistribution(tree);
     71
     72        if (doesSelectFromHostChildren())
     73            clearDistribution(tree);
     74        else if (ShadowRoot* assignedShadowRoot = assignedFrom())
     75            clearAssignment(assignedShadowRoot);
    6476
    6577        // When shadow element is detached, shadow tree should be recreated to re-calculate selector for
     
    7082    ASSERT(m_selections.isEmpty());
    7183    HTMLElement::detach();
     84}
     85
     86ShadowRoot* InsertionPoint::assignedFrom() const
     87{
     88    TreeScope* scope = treeScope();
     89    if (!scope->isShadowRoot())
     90        return 0;
     91
     92    ShadowRoot* olderShadowRoot = toShadowRoot(scope)->olderShadowRoot();
     93    if (olderShadowRoot && olderShadowRoot->assignedTo() == this)
     94        return olderShadowRoot;
     95    return 0;
    7296}
    7397
     
    103127}
    104128
     129inline void InsertionPoint::assignShadowRoot(ShadowRoot* shadowRoot)
     130{
     131    shadowRoot->setAssignedTo(this);
     132    m_selections.clear();
     133    for (Node* node = shadowRoot->firstChild(); node; node = node->nextSibling())
     134        m_selections.append(HTMLContentSelection::create(this, node));
     135}
     136
     137inline void InsertionPoint::clearAssignment(ShadowRoot* shadowRoot)
     138{
     139    shadowRoot->setAssignedTo(0);
     140    m_selections.clear();
     141}
     142
    105143} // namespace WebCore
  • trunk/Source/WebCore/html/shadow/InsertionPoint.h

    r110151 r110161  
    3434#include "HTMLContentSelector.h"
    3535#include "HTMLElement.h"
     36#include "HTMLNames.h"
    3637#include <wtf/Forward.h>
    3738
     
    4849    virtual const AtomicString& select() const = 0;
    4950    virtual bool isSelectValid() const = 0;
     51    virtual bool doesSelectFromHostChildren() const = 0;
    5052
    5153    virtual void attach();
     
    5355
    5456    virtual bool isInsertionPoint() const OVERRIDE { return true; }
     57    ShadowRoot* assignedFrom() const;
    5558
    5659protected:
     
    6265    void clearDistribution(ShadowTree*);
    6366    void attachDistributedNode();
     67
     68    void assignShadowRoot(ShadowRoot*);
     69    void clearAssignment(ShadowRoot*);
    6470
    6571    HTMLContentSelectionList m_selections;
Note: See TracChangeset for help on using the changeset viewer.