/* -*- 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/ServoStyleSet.h" #include "nsCSSAnonBoxes.h" #include "nsCSSPseudoElements.h" #include "nsStyleContext.h" #include "nsStyleSet.h" using namespace mozilla; using namespace mozilla::dom; ServoStyleSet::ServoStyleSet() : mPresContext(nullptr) , mRawSet(Servo_InitStyleSet()) , mBatching(0) { } void ServoStyleSet::Init(nsPresContext* aPresContext) { mPresContext = aPresContext; } void ServoStyleSet::BeginShutdown() { } void ServoStyleSet::Shutdown() { mRawSet = nullptr; } bool ServoStyleSet::GetAuthorStyleDisabled() const { return false; } nsresult ServoStyleSet::SetAuthorStyleDisabled(bool aStyleDisabled) { MOZ_CRASH("stylo: not implemented"); } void ServoStyleSet::BeginUpdate() { ++mBatching; } nsresult ServoStyleSet::EndUpdate() { MOZ_ASSERT(mBatching > 0); if (--mBatching > 0) { return NS_OK; } // ... do something ... return NS_OK; } // resolve a style context already_AddRefed ServoStyleSet::ResolveStyleFor(Element* aElement, nsStyleContext* aParentContext) { RefPtr computedValues = dont_AddRef(Servo_GetComputedValues(aElement)); MOZ_ASSERT(computedValues); // XXXbholley: nsStyleSet does visited handling here. // XXXbholley: Figure out the correct thing to pass here. Does this fixup // duplicate something that servo already does? bool skipFixup = false; return NS_NewStyleContext(aParentContext, mPresContext, nullptr, CSSPseudoElementType::NotPseudo, computedValues.forget(), skipFixup); } already_AddRefed ServoStyleSet::ResolveStyleFor(Element* aElement, nsStyleContext* aParentContext, TreeMatchContext& aTreeMatchContext) { MOZ_CRASH("stylo: not implemented"); } already_AddRefed ServoStyleSet::ResolveStyleForNonElement(nsStyleContext* aParentContext, nsIAtom* aPseudoTag) { MOZ_CRASH("stylo: not implemented"); } already_AddRefed ServoStyleSet::ResolvePseudoElementStyle(Element* aParentElement, CSSPseudoElementType aType, nsStyleContext* aParentContext, Element* aPseudoElement) { MOZ_CRASH("stylo: not implemented"); } // aFlags is an nsStyleSet flags bitfield already_AddRefed ServoStyleSet::ResolveAnonymousBoxStyle(nsIAtom* aPseudoTag, nsStyleContext* aParentContext, uint32_t aFlags) { MOZ_ASSERT(nsCSSAnonBoxes::IsAnonBox(aPseudoTag)); MOZ_ASSERT(aFlags == 0 || aFlags == nsStyleSet::eSkipParentDisplayBasedStyleFixup); bool skipFixup = aFlags & nsStyleSet::eSkipParentDisplayBasedStyleFixup; ServoComputedValues* parentStyle = aParentContext ? aParentContext->StyleSource().AsServoComputedValues() : nullptr; RefPtr computedValues = dont_AddRef(Servo_GetComputedValuesForAnonymousBox(parentStyle, aPseudoTag)); MOZ_ASSERT(computedValues); return NS_NewStyleContext(aParentContext, mPresContext, nullptr, CSSPseudoElementType::AnonBox, computedValues.forget(), skipFixup); } // manage the set of style sheets in the style set nsresult ServoStyleSet::AppendStyleSheet(SheetType aType, ServoStyleSheet* aSheet) { MOZ_ASSERT(aSheet); MOZ_ASSERT(aSheet->IsApplicable()); MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType)); mSheets[aType].RemoveElement(aSheet); mSheets[aType].AppendElement(aSheet); // Maintain a mirrored list of sheets on the servo side. Servo_AppendStyleSheet(aSheet->RawSheet(), mRawSet.get()); return NS_OK; } nsresult ServoStyleSet::PrependStyleSheet(SheetType aType, ServoStyleSheet* aSheet) { MOZ_ASSERT(aSheet); MOZ_ASSERT(aSheet->IsApplicable()); MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType)); mSheets[aType].RemoveElement(aSheet); mSheets[aType].InsertElementAt(0, aSheet); // Maintain a mirrored list of sheets on the servo side. Servo_PrependStyleSheet(aSheet->RawSheet(), mRawSet.get()); return NS_OK; } nsresult ServoStyleSet::RemoveStyleSheet(SheetType aType, ServoStyleSheet* aSheet) { MOZ_ASSERT(aSheet); MOZ_ASSERT(aSheet->IsApplicable()); MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType)); mSheets[aType].RemoveElement(aSheet); // Maintain a mirrored list of sheets on the servo side. Servo_RemoveStyleSheet(aSheet->RawSheet(), mRawSet.get()); return NS_OK; } nsresult ServoStyleSet::ReplaceSheets(SheetType aType, const nsTArray>& aNewSheets) { MOZ_CRASH("stylo: not implemented"); } nsresult ServoStyleSet::InsertStyleSheetBefore(SheetType aType, ServoStyleSheet* aNewSheet, ServoStyleSheet* aReferenceSheet) { MOZ_CRASH("stylo: not implemented"); } int32_t ServoStyleSet::SheetCount(SheetType aType) const { MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType)); return mSheets[aType].Length(); } ServoStyleSheet* ServoStyleSet::StyleSheetAt(SheetType aType, int32_t aIndex) const { MOZ_ASSERT(nsStyleSet::IsCSSSheetType(aType)); return mSheets[aType][aIndex]; } nsresult ServoStyleSet::RemoveDocStyleSheet(ServoStyleSheet* aSheet) { MOZ_CRASH("stylo: not implemented"); } nsresult ServoStyleSet::AddDocStyleSheet(ServoStyleSheet* aSheet, nsIDocument* aDocument) { // XXXbholley: Implement this. NS_ERROR("stylo: no support for adding doc stylesheets to ServoStyleSet"); return NS_OK; } already_AddRefed ServoStyleSet::ProbePseudoElementStyle(Element* aParentElement, CSSPseudoElementType aType, nsStyleContext* aParentContext) { MOZ_CRASH("stylo: not implemented"); } already_AddRefed ServoStyleSet::ProbePseudoElementStyle(Element* aParentElement, CSSPseudoElementType aType, nsStyleContext* aParentContext, TreeMatchContext& aTreeMatchContext, Element* aPseudoElement) { MOZ_CRASH("stylo: not implemented"); } nsRestyleHint ServoStyleSet::HasStateDependentStyle(dom::Element* aElement, EventStates aStateMask) { MOZ_CRASH("stylo: not implemented"); } nsRestyleHint ServoStyleSet::HasStateDependentStyle(dom::Element* aElement, CSSPseudoElementType aPseudoType, dom::Element* aPseudoElement, EventStates aStateMask) { MOZ_CRASH("stylo: not implemented"); }