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/. */
7 #include "mozilla/ServoElementSnapshot.h"
8 #include "mozilla/GeckoBindings.h"
9 #include "mozilla/dom/Element.h"
10 #include "nsIContentInlines.h"
11 #include "nsContentUtils.h"
15 ServoElementSnapshot::ServoElementSnapshot(const Element
& aElement
)
18 mIsTableBorderNonzero(false),
19 mIsSelectListBox(false),
20 mClassAttributeChanged(false),
21 mIdAttributeChanged(false) {
22 MOZ_COUNT_CTOR(ServoElementSnapshot
);
23 MOZ_ASSERT(NS_IsMainThread());
24 mIsInChromeDocument
= nsContentUtils::IsChromeDoc(aElement
.OwnerDoc());
25 mSupportsLangAttr
= aElement
.SupportsLangAttr();
28 void ServoElementSnapshot::AddOtherPseudoClassState(const Element
& aElement
) {
29 if (HasOtherPseudoClassState()) {
33 mIsTableBorderNonzero
= Gecko_IsTableBorderNonzero(&aElement
);
34 mIsSelectListBox
= Gecko_IsSelectListBox(&aElement
);
36 mContains
|= Flags::OtherPseudoClassState
;
39 void ServoElementSnapshot::AddAttrs(const Element
& aElement
,
40 int32_t aNameSpaceID
, nsAtom
* aAttribute
) {
41 if (aNameSpaceID
== kNameSpaceID_None
) {
42 if (aAttribute
== nsGkAtoms::_class
) {
43 if (mClassAttributeChanged
) {
46 mClassAttributeChanged
= true;
47 } else if (aAttribute
== nsGkAtoms::id
) {
48 if (mIdAttributeChanged
) {
51 mIdAttributeChanged
= true;
55 if (!mChangedAttrNames
.Contains(aAttribute
)) {
56 mChangedAttrNames
.AppendElement(aAttribute
);
63 uint32_t attrCount
= aElement
.GetAttrCount();
64 mAttrs
.SetCapacity(attrCount
);
65 for (uint32_t i
= 0; i
< attrCount
; ++i
) {
66 const BorrowedAttrInfo info
= aElement
.GetAttrInfoAt(i
);
68 mAttrs
.AppendElement(AttrArray::InternalAttr
{*info
.mName
, *info
.mValue
});
71 mContains
|= Flags::Attributes
;
72 if (aElement
.HasID()) {
73 mContains
|= Flags::Id
;
76 if (const nsAttrValue
* classValue
= aElement
.GetClasses()) {
77 // FIXME(emilio): It's pretty unfortunate that this is only relevant for
78 // SVG, yet it's a somewhat expensive copy. We should be able to do
81 mContains
|= Flags::MaybeClass
;
85 void ServoElementSnapshot::AddCustomStates(Element
& aElement
) {
86 if (mContains
& Flags::CustomState
) {
89 mCustomStates
= aElement
.EnsureCustomStates().Clone();
90 mContains
|= Flags::CustomState
;
92 } // namespace mozilla