| OLD | NEW |
| (Empty) | |
| 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 * * Neither the name of Google Inc. nor the names of its |
| 11 * contributors may be used to endorse or promote products derived from |
| 12 * this software without specific prior written permission. |
| 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ |
| 26 |
| 27 #include "config.h" |
| 28 #include "core/dom/shadow/ScopeContentDistribution.h" |
| 29 |
| 30 #include "core/dom/NodeTraversal.h" |
| 31 #include "core/dom/shadow/InsertionPoint.h" |
| 32 #include "core/dom/shadow/ShadowRoot.h" |
| 33 #include "core/html/shadow/HTMLContentElement.h" |
| 34 #include "core/html/shadow/HTMLShadowElement.h" |
| 35 |
| 36 namespace WebCore { |
| 37 |
| 38 ScopeContentDistribution::ScopeContentDistribution() |
| 39 : m_insertionPointAssignedTo(0) |
| 40 , m_numberOfShadowElementChildren(0) |
| 41 , m_numberOfContentElementChildren(0) |
| 42 , m_numberOfElementShadowChildren(0) |
| 43 , m_insertionPointListIsValid(false) |
| 44 { |
| 45 } |
| 46 |
| 47 void ScopeContentDistribution::setInsertionPointAssignedTo(PassRefPtr<InsertionP
oint> insertionPoint) |
| 48 { |
| 49 m_insertionPointAssignedTo = insertionPoint; |
| 50 } |
| 51 |
| 52 void ScopeContentDistribution::invalidateInsertionPointList() |
| 53 { |
| 54 m_insertionPointListIsValid = false; |
| 55 m_insertionPointList.clear(); |
| 56 } |
| 57 |
| 58 const Vector<RefPtr<InsertionPoint> >& ScopeContentDistribution::ensureInsertion
PointList(ShadowRoot* shadowRoot) |
| 59 { |
| 60 if (m_insertionPointListIsValid) |
| 61 return m_insertionPointList; |
| 62 |
| 63 m_insertionPointListIsValid = true; |
| 64 ASSERT(m_insertionPointList.isEmpty()); |
| 65 |
| 66 if (!shadowRoot->containsInsertionPoints()) |
| 67 return m_insertionPointList; |
| 68 |
| 69 for (Element* element = ElementTraversal::firstWithin(shadowRoot); element;
element = ElementTraversal::next(element, shadowRoot)) { |
| 70 if (element->isInsertionPoint()) |
| 71 m_insertionPointList.append(toInsertionPoint(element)); |
| 72 } |
| 73 |
| 74 return m_insertionPointList; |
| 75 } |
| 76 |
| 77 void ScopeContentDistribution::registerInsertionPoint(InsertionPoint* point) |
| 78 { |
| 79 if (isHTMLShadowElement(point)) |
| 80 ++m_numberOfShadowElementChildren; |
| 81 else if (isHTMLContentElement(point)) |
| 82 ++m_numberOfContentElementChildren; |
| 83 else |
| 84 ASSERT_NOT_REACHED(); |
| 85 |
| 86 invalidateInsertionPointList(); |
| 87 } |
| 88 |
| 89 void ScopeContentDistribution::unregisterInsertionPoint(InsertionPoint* point) |
| 90 { |
| 91 if (isHTMLShadowElement(point)) |
| 92 --m_numberOfShadowElementChildren; |
| 93 else if (isHTMLContentElement(point)) |
| 94 --m_numberOfContentElementChildren; |
| 95 else |
| 96 ASSERT_NOT_REACHED(); |
| 97 |
| 98 ASSERT(m_numberOfContentElementChildren >= 0); |
| 99 ASSERT(m_numberOfShadowElementChildren >= 0); |
| 100 |
| 101 invalidateInsertionPointList(); |
| 102 } |
| 103 |
| 104 } // namespace WebCore |
| OLD | NEW |