Home | History | Annotate | Download | only in shadow
      1 /*
      2  * Copyright (C) 2013 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef ShadowRootRareData_h
     32 #define ShadowRootRareData_h
     33 
     34 #include "core/dom/shadow/InsertionPoint.h"
     35 #include "core/html/shadow/HTMLContentElement.h"
     36 #include "core/html/shadow/HTMLShadowElement.h"
     37 #include "wtf/RefPtr.h"
     38 #include "wtf/Vector.h"
     39 
     40 namespace WebCore {
     41 
     42 class ShadowRootRareData {
     43 public:
     44     ShadowRootRareData()
     45         : m_descendantShadowElementCount(0)
     46         , m_descendantContentElementCount(0)
     47         , m_childShadowRootCount(0)
     48     {
     49     }
     50 
     51     HTMLShadowElement* shadowInsertionPointOfYoungerShadowRoot() const { return m_shadowInsertionPointOfYoungerShadowRoot.get(); }
     52     void setShadowInsertionPointOfYoungerShadowRoot(PassRefPtr<HTMLShadowElement> shadowInsertionPoint) { m_shadowInsertionPointOfYoungerShadowRoot = shadowInsertionPoint; }
     53 
     54     void didAddInsertionPoint(InsertionPoint*);
     55     void didRemoveInsertionPoint(InsertionPoint*);
     56 
     57     bool containsShadowElements() const { return m_descendantShadowElementCount; }
     58     bool containsContentElements() const { return m_descendantContentElementCount; }
     59     bool containsShadowRoots() const { return m_childShadowRootCount; }
     60 
     61     unsigned descendantShadowElementCount() const { return m_descendantShadowElementCount; }
     62 
     63     void didAddChildShadowRoot() { ++m_childShadowRootCount; }
     64     void didRemoveChildShadowRoot() { ASSERT(m_childShadowRootCount > 0); --m_childShadowRootCount; }
     65 
     66     unsigned childShadowRootCount() const { return m_childShadowRootCount; }
     67 
     68     const Vector<RefPtr<InsertionPoint> >& descendantInsertionPoints() { return m_descendantInsertionPoints; }
     69     void setDescendantInsertionPoints(Vector<RefPtr<InsertionPoint> >& list) { m_descendantInsertionPoints.swap(list); }
     70     void clearDescendantInsertionPoints() { m_descendantInsertionPoints.clear(); }
     71 
     72     StyleSheetList* styleSheets() { return m_styleSheetList.get(); }
     73     void setStyleSheets(PassRefPtr<StyleSheetList> styleSheetList) { m_styleSheetList = styleSheetList; }
     74 
     75 private:
     76     RefPtr<HTMLShadowElement> m_shadowInsertionPointOfYoungerShadowRoot;
     77     unsigned m_descendantShadowElementCount;
     78     unsigned m_descendantContentElementCount;
     79     unsigned m_childShadowRootCount;
     80     Vector<RefPtr<InsertionPoint> > m_descendantInsertionPoints;
     81     RefPtr<StyleSheetList> m_styleSheetList;
     82 };
     83 
     84 inline void ShadowRootRareData::didAddInsertionPoint(InsertionPoint* point)
     85 {
     86     if (isHTMLShadowElement(point))
     87         ++m_descendantShadowElementCount;
     88     else if (isHTMLContentElement(point))
     89         ++m_descendantContentElementCount;
     90     else
     91         ASSERT_NOT_REACHED();
     92 }
     93 
     94 inline void ShadowRootRareData::didRemoveInsertionPoint(InsertionPoint* point)
     95 {
     96     if (isHTMLShadowElement(point))
     97         --m_descendantShadowElementCount;
     98     else if (isHTMLContentElement(point))
     99         --m_descendantContentElementCount;
    100     else
    101         ASSERT_NOT_REACHED();
    102 
    103     ASSERT(m_descendantContentElementCount >= 0);
    104     ASSERT(m_descendantShadowElementCount >= 0);
    105 }
    106 
    107 } // namespace WebCore
    108 
    109 #endif
    110