1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "mozilla/ServoElementSnapshot.h"
8 #include "mozilla/dom/Element.h"
9 #include "nsIContentInlines.h"
10 #include "nsContentUtils.h"
11 
12 namespace mozilla {
13 
ServoElementSnapshot(Element * aElement)14 ServoElementSnapshot::ServoElementSnapshot(Element* aElement)
15   : mContains(Flags(0))
16   , mState(0)
17   , mExplicitRestyleHint(nsRestyleHint(0))
18   , mExplicitChangeHint(nsChangeHint(0))
19 {
20   mIsHTMLElementInHTMLDocument =
21     aElement->IsHTMLElement() && aElement->IsInHTMLDocument();
22   mIsInChromeDocument =
23     nsContentUtils::IsChromeDoc(aElement->OwnerDoc());
24 }
25 
26 void
AddAttrs(Element * aElement)27 ServoElementSnapshot::AddAttrs(Element* aElement)
28 {
29   MOZ_ASSERT(aElement);
30 
31   if (HasAny(Flags::Attributes)) {
32     return;
33   }
34 
35   uint32_t attrCount = aElement->GetAttrCount();
36   const nsAttrName* attrName;
37   for (uint32_t i = 0; i < attrCount; ++i) {
38     attrName = aElement->GetAttrNameAt(i);
39     const nsAttrValue* attrValue =
40       aElement->GetParsedAttr(attrName->LocalName(), attrName->NamespaceID());
41     mAttrs.AppendElement(ServoAttrSnapshot(*attrName, *attrValue));
42   }
43   mContains |= Flags::Attributes;
44 }
45 
46 } // namespace mozilla
47