ServoElementSnapshot.cpp (2803B)
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 9 #include "mozilla/GeckoBindings.h" 10 #include "mozilla/dom/Element.h" 11 #include "nsContentUtils.h" 12 #include "nsIContentInlines.h" 13 14 namespace mozilla { 15 16 ServoElementSnapshot::ServoElementSnapshot(const Element& aElement) 17 : mState(0), 18 mContains(Flags(0)), 19 mIsTableBorderNonzero(false), 20 mIsSelectListBox(false), 21 mClassAttributeChanged(false), 22 mIdAttributeChanged(false) { 23 MOZ_COUNT_CTOR(ServoElementSnapshot); 24 MOZ_ASSERT(NS_IsMainThread()); 25 mIsInChromeDocument = nsContentUtils::IsChromeDoc(aElement.OwnerDoc()); 26 mSupportsLangAttr = aElement.SupportsLangAttr(); 27 } 28 29 void ServoElementSnapshot::AddOtherPseudoClassState(const Element& aElement) { 30 if (HasOtherPseudoClassState()) { 31 return; 32 } 33 34 mIsTableBorderNonzero = Gecko_IsTableBorderNonzero(&aElement); 35 mIsSelectListBox = Gecko_IsSelectListBox(&aElement); 36 37 mContains |= Flags::OtherPseudoClassState; 38 } 39 40 void ServoElementSnapshot::AddAttrs(const Element& aElement, 41 int32_t aNameSpaceID, nsAtom* aAttribute) { 42 if (aNameSpaceID == kNameSpaceID_None) { 43 if (aAttribute == nsGkAtoms::_class) { 44 if (mClassAttributeChanged) { 45 return; 46 } 47 mClassAttributeChanged = true; 48 } else if (aAttribute == nsGkAtoms::id) { 49 if (mIdAttributeChanged) { 50 return; 51 } 52 mIdAttributeChanged = true; 53 } 54 } 55 56 if (!mChangedAttrNames.Contains(aAttribute)) { 57 mChangedAttrNames.AppendElement(aAttribute); 58 } 59 60 if (HasAttrs()) { 61 return; 62 } 63 64 uint32_t attrCount = aElement.GetAttrCount(); 65 mAttrs.SetCapacity(attrCount); 66 for (uint32_t i = 0; i < attrCount; ++i) { 67 const BorrowedAttrInfo info = aElement.GetAttrInfoAt(i); 68 MOZ_ASSERT(info); 69 mAttrs.AppendElement(AttrArray::InternalAttr{*info.mName, *info.mValue}); 70 } 71 72 mContains |= Flags::Attributes; 73 if (aElement.HasID()) { 74 mContains |= Flags::Id; 75 } 76 77 if (const nsAttrValue* classValue = aElement.GetClasses()) { 78 // FIXME(emilio): It's pretty unfortunate that this is only relevant for 79 // SVG, yet it's a somewhat expensive copy. We should be able to do 80 // better! 81 mClass = *classValue; 82 mContains |= Flags::MaybeClass; 83 } 84 } 85 86 void ServoElementSnapshot::AddCustomStates(Element& aElement) { 87 if (mContains & Flags::CustomState) { 88 return; 89 } 90 mCustomStates = aElement.EnsureCustomStates().Clone(); 91 mContains |= Flags::CustomState; 92 } 93 } // namespace mozilla