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 "wtf/RefPtr.h"
     36 #include "wtf/Vector.h"
     37 
     38 namespace blink {
     39 
     40 class ShadowRootRareData : public NoBaseWillBeGarbageCollected<ShadowRootRareData> {
     41 public:
     42     ShadowRootRareData()
     43         : m_descendantShadowElementCount(0)
     44         , m_descendantContentElementCount(0)
     45         , m_childShadowRootCount(0)
     46     {
     47     }
     48 
     49     HTMLShadowElement* shadowInsertionPointOfYoungerShadowRoot() const { return m_shadowInsertionPointOfYoungerShadowRoot.get(); }
     50     void setShadowInsertionPointOfYoungerShadowRoot(PassRefPtrWillBeRawPtr<HTMLShadowElement> shadowInsertionPoint) { m_shadowInsertionPointOfYoungerShadowRoot = shadowInsertionPoint; }
     51 
     52     void didAddInsertionPoint(InsertionPoint*);
     53     void didRemoveInsertionPoint(InsertionPoint*);
     54 
     55     bool containsShadowElements() const { return m_descendantShadowElementCount; }
     56     bool containsContentElements() const { return m_descendantContentElementCount; }
     57     bool containsShadowRoots() const { return m_childShadowRootCount; }
     58 
     59     unsigned descendantShadowElementCount() const { return m_descendantShadowElementCount; }
     60 
     61     void didAddChildShadowRoot() { ++m_childShadowRootCount; }
     62     void didRemoveChildShadowRoot() { ASSERT(m_childShadowRootCount > 0); --m_childShadowRootCount; }
     63 
     64     unsigned childShadowRootCount() const { return m_childShadowRootCount; }
     65 
     66     const WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> >& descendantInsertionPoints() { return m_descendantInsertionPoints; }
     67     void setDescendantInsertionPoints(WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> >& list) { m_descendantInsertionPoints.swap(list); }
     68     void clearDescendantInsertionPoints() { m_descendantInsertionPoints.clear(); }
     69 
     70     StyleSheetList* styleSheets() { return m_styleSheetList.get(); }
     71     void setStyleSheets(PassRefPtrWillBeRawPtr<StyleSheetList> styleSheetList) { m_styleSheetList = styleSheetList; }
     72 
     73     void trace(Visitor* visitor)
     74     {
     75         visitor->trace(m_shadowInsertionPointOfYoungerShadowRoot);
     76         visitor->trace(m_descendantInsertionPoints);
     77         visitor->trace(m_styleSheetList);
     78     }
     79 
     80 private:
     81     RefPtrWillBeMember<HTMLShadowElement> m_shadowInsertionPointOfYoungerShadowRoot;
     82     unsigned m_descendantShadowElementCount;
     83     unsigned m_descendantContentElementCount;
     84     unsigned m_childShadowRootCount;
     85     WillBeHeapVector<RefPtrWillBeMember<InsertionPoint> > m_descendantInsertionPoints;
     86     RefPtrWillBeMember<StyleSheetList> m_styleSheetList;
     87 };
     88 
     89 inline void ShadowRootRareData::didAddInsertionPoint(InsertionPoint* point)
     90 {
     91     ASSERT(point);
     92     if (isHTMLShadowElement(*point))
     93         ++m_descendantShadowElementCount;
     94     else if (isHTMLContentElement(*point))
     95         ++m_descendantContentElementCount;
     96     else
     97         ASSERT_NOT_REACHED();
     98 }
     99 
    100 inline void ShadowRootRareData::didRemoveInsertionPoint(InsertionPoint* point)
    101 {
    102     ASSERT(point);
    103     if (isHTMLShadowElement(*point))
    104         --m_descendantShadowElementCount;
    105     else if (isHTMLContentElement(*point))
    106         --m_descendantContentElementCount;
    107     else
    108         ASSERT_NOT_REACHED();
    109 
    110     ASSERT(m_descendantContentElementCount >= 0);
    111     ASSERT(m_descendantShadowElementCount >= 0);
    112 }
    113 
    114 } // namespace blink
    115 
    116 #endif
    117