From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- layout/style/ServoElementSnapshot.cpp | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 layout/style/ServoElementSnapshot.cpp (limited to 'layout/style/ServoElementSnapshot.cpp') diff --git a/layout/style/ServoElementSnapshot.cpp b/layout/style/ServoElementSnapshot.cpp new file mode 100644 index 0000000000..8c661072df --- /dev/null +++ b/layout/style/ServoElementSnapshot.cpp @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/ServoElementSnapshot.h" +#include "mozilla/GeckoBindings.h" +#include "mozilla/dom/Element.h" +#include "nsIContentInlines.h" +#include "nsContentUtils.h" + +namespace mozilla { + +ServoElementSnapshot::ServoElementSnapshot(const Element& aElement) + : mState(0), + mContains(Flags(0)), + mIsTableBorderNonzero(false), + mIsMozBrowserFrame(false), + mIsSelectListBox(false), + mClassAttributeChanged(false), + mIdAttributeChanged(false) { + MOZ_COUNT_CTOR(ServoElementSnapshot); + MOZ_ASSERT(NS_IsMainThread()); + mIsInChromeDocument = nsContentUtils::IsChromeDoc(aElement.OwnerDoc()); + mSupportsLangAttr = aElement.SupportsLangAttr(); +} + +void ServoElementSnapshot::AddOtherPseudoClassState(const Element& aElement) { + if (HasOtherPseudoClassState()) { + return; + } + + mIsTableBorderNonzero = Gecko_IsTableBorderNonzero(&aElement); + mIsMozBrowserFrame = Gecko_IsBrowserFrame(&aElement); + mIsSelectListBox = Gecko_IsSelectListBox(&aElement); + + mContains |= Flags::OtherPseudoClassState; +} + +void ServoElementSnapshot::AddAttrs(const Element& aElement, + int32_t aNameSpaceID, nsAtom* aAttribute) { + if (aNameSpaceID == kNameSpaceID_None) { + if (aAttribute == nsGkAtoms::_class) { + if (mClassAttributeChanged) { + return; + } + mClassAttributeChanged = true; + } else if (aAttribute == nsGkAtoms::id) { + if (mIdAttributeChanged) { + return; + } + mIdAttributeChanged = true; + } + } + + if (!mChangedAttrNames.Contains(aAttribute)) { + mChangedAttrNames.AppendElement(aAttribute); + } + + if (HasAttrs()) { + return; + } + + uint32_t attrCount = aElement.GetAttrCount(); + mAttrs.SetCapacity(attrCount); + for (uint32_t i = 0; i < attrCount; ++i) { + const BorrowedAttrInfo info = aElement.GetAttrInfoAt(i); + MOZ_ASSERT(info); + mAttrs.AppendElement(AttrArray::InternalAttr{*info.mName, *info.mValue}); + } + + mContains |= Flags::Attributes; + if (aElement.HasID()) { + mContains |= Flags::Id; + } + + if (const nsAttrValue* classValue = aElement.GetClasses()) { + // FIXME(emilio): It's pretty unfortunate that this is only relevant for + // SVG, yet it's a somewhat expensive copy. We should be able to do + // better! + mClass = *classValue; + mContains |= Flags::MaybeClass; + } +} + +} // namespace mozilla -- cgit v1.2.3