Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1449400 part 5 - Remove StyleSetHandle. r=emilio
Browse files Browse the repository at this point in the history
This patch basically does:
* remove StyleSetHandle and its corresponding files
* revisit #includes of related header files and change correspondingly
* change nsIPresShell::mStyleSet to be UniquePtr<ServoStyleSet>
* change the creating path of ServoStyleSet to pass UniquePtr
* change other mentions of StyleSetHandle to ServoStyleSet*
* remove AsServo() calls on ServoStyleSet

Some unfortunate bits:
* some methods of (Servo)StyleSet only accepts ServoStyleSheet while
  many places call into the methods with StyleSheet, so there are many
  ->AsServo() added to sheets

MozReview-Commit-ID: K4zYnuhOurA
  • Loading branch information
upsuper committed Mar 29, 2018
1 parent c626a4a commit 24a7c53
Show file tree
Hide file tree
Showing 66 changed files with 250 additions and 848 deletions.
10 changes: 6 additions & 4 deletions chrome/nsChromeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ nsChromeRegistry* nsChromeRegistry::gChromeRegistry;

// DO NOT use namespace mozilla; it'll break due to a naming conflict between
// mozilla::TextRange and a TextRange in OSX headers.
using mozilla::ServoStyleSheet;
using mozilla::StyleSheet;
using mozilla::dom::IsChromeURI;
using mozilla::dom::Location;
Expand Down Expand Up @@ -403,12 +404,12 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
nsCOMPtr<nsIPresShell> shell = document->GetShell();
if (shell) {
// Reload only the chrome URL agent style sheets.
nsTArray<RefPtr<StyleSheet>> agentSheets;
nsTArray<RefPtr<ServoStyleSheet>> agentSheets;
rv = shell->GetAgentStyleSheets(agentSheets);
NS_ENSURE_SUCCESS(rv, rv);

nsTArray<RefPtr<StyleSheet>> newAgentSheets;
for (StyleSheet* sheet : agentSheets) {
nsTArray<RefPtr<ServoStyleSheet>> newAgentSheets;
for (ServoStyleSheet* sheet : agentSheets) {
nsIURI* uri = sheet->GetSheetURI();

if (IsChromeURI(uri)) {
Expand All @@ -417,7 +418,8 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
rv = document->LoadChromeSheetSync(uri, true, &newSheet);
if (NS_FAILED(rv)) return rv;
if (newSheet) {
rv = newAgentSheets.AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE;
rv = newAgentSheets.AppendElement(newSheet->AsServo())
? NS_OK : NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
}
}
Expand Down
9 changes: 3 additions & 6 deletions dom/animation/KeyframeEffectReadOnly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,8 @@ KeyframeEffectReadOnly::EnsureBaseStyle(
Element* animatingElement =
EffectCompositor::GetElementToRestyle(mTarget->mElement,
mTarget->mPseudoType);
aBaseComputedStyle =
aPresContext->StyleSet()->AsServo()->GetBaseContextForElement(
animatingElement,
aComputedStyle);
aBaseComputedStyle = aPresContext->StyleSet()->
GetBaseContextForElement(animatingElement, aComputedStyle);
}
RefPtr<RawServoAnimationValue> baseValue =
Servo_ComputedValues_ExtractAnimationValue(aBaseComputedStyle,
Expand Down Expand Up @@ -1488,8 +1486,7 @@ KeyframeEffectReadOnly::CreateComputedStyleForAnimationValue(
"CreateComputedStyleForAnimationValue needs to be called "
"with a valid ComputedStyle");

ServoStyleSet* styleSet =
aBaseComputedStyle->PresContext()->StyleSet()->AsServo();
ServoStyleSet* styleSet = aBaseComputedStyle->PresContext()->StyleSet();
Element* elementForResolve =
EffectCompositor::GetElementToRestyle(mTarget->mElement,
mTarget->mPseudoType);
Expand Down
4 changes: 2 additions & 2 deletions dom/animation/KeyframeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,8 @@ GetComputedKeyframeValues(const nsTArray<Keyframe>& aKeyframes,
return result;
}

result = presContext->StyleSet()->AsServo()
->GetComputedKeyframeValuesFor(aKeyframes, aElement, aComputedStyle);
result = presContext->StyleSet()->
GetComputedKeyframeValuesFor(aKeyframes, aElement, aComputedStyle);
return result;
}

Expand Down
5 changes: 2 additions & 3 deletions dom/base/ResponsiveImageSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,8 @@ ResponsiveImageSelector::ComputeFinalWidthForCurrentViewport(double *aWidth)
if (!pctx) {
return false;
}
nscoord effectiveWidth =
presShell->StyleSet()->AsServo()->EvaluateSourceSizeList(
mServoSourceSizeList.get());
nscoord effectiveWidth = presShell->StyleSet()->
EvaluateSourceSizeList(mServoSourceSizeList.get());

*aWidth = nsPresContext::AppUnitsToDoubleCSSPixels(std::max(effectiveWidth, 0));
return true;
Expand Down
35 changes: 17 additions & 18 deletions dom/base/nsDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@
#include "mozilla/dom/FontFaceSet.h"
#include "gfxPrefs.h"
#include "nsISupportsPrimitives.h"
#include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSetHandleInlines.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/dom/SVGSVGElement.h"
Expand Down Expand Up @@ -2457,7 +2456,7 @@ nsIDocument::RemoveDocStyleSheetsFromStyleSets()
if (sheet->IsApplicable()) {
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
shell->StyleSet()->RemoveDocStyleSheet(sheet);
shell->StyleSet()->RemoveDocStyleSheet(sheet->AsServo());
}
}
// XXX Tell observers?
Expand All @@ -2476,7 +2475,7 @@ nsIDocument::RemoveStyleSheetsFromStyleSets(
if (sheet->IsApplicable()) {
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
shell->StyleSet()->RemoveStyleSheet(aType, sheet);
shell->StyleSet()->RemoveStyleSheet(aType, sheet->AsServo());
}
}
// XXX Tell observers?
Expand Down Expand Up @@ -2538,18 +2537,18 @@ nsIDocument::ResetStylesheetsToURI(nsIURI* aURI)
}

static void
AppendSheetsToStyleSet(StyleSetHandle aStyleSet,
AppendSheetsToStyleSet(ServoStyleSet* aStyleSet,
const nsTArray<RefPtr<StyleSheet>>& aSheets,
SheetType aType)
{
for (StyleSheet* sheet : Reversed(aSheets)) {
aStyleSet->AppendStyleSheet(aType, sheet);
aStyleSet->AppendStyleSheet(aType, sheet->AsServo());
}
}


void
nsIDocument::FillStyleSet(StyleSetHandle aStyleSet)
nsIDocument::FillStyleSet(ServoStyleSet* aStyleSet)
{
NS_PRECONDITION(aStyleSet, "Must have a style set");
NS_PRECONDITION(aStyleSet->SheetCount(SheetType::Doc) == 0,
Expand All @@ -2559,22 +2558,22 @@ nsIDocument::FillStyleSet(StyleSetHandle aStyleSet)

for (StyleSheet* sheet : Reversed(mStyleSheets)) {
if (sheet->IsApplicable()) {
aStyleSet->AddDocStyleSheet(sheet, this);
aStyleSet->AddDocStyleSheet(sheet->AsServo(), this);
}
}

if (nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance()) {
nsTArray<RefPtr<StyleSheet>>& sheets =
*sheetService->AuthorStyleSheets();
for (StyleSheet* sheet : sheets) {
aStyleSet->AppendStyleSheet(SheetType::Doc, sheet);
aStyleSet->AppendStyleSheet(SheetType::Doc, sheet->AsServo());
}
}

// Iterate backwards to maintain order
for (StyleSheet* sheet : Reversed(mOnDemandBuiltInUASheets)) {
if (sheet->IsApplicable()) {
aStyleSet->PrependStyleSheet(SheetType::Agent, sheet);
aStyleSet->PrependStyleSheet(SheetType::Agent, sheet->AsServo());
}
}

Expand Down Expand Up @@ -3878,19 +3877,19 @@ AssertNoStaleServoDataIn(const nsINode& aSubtreeRoot)
already_AddRefed<nsIPresShell>
nsIDocument::CreateShell(nsPresContext* aContext,
nsViewManager* aViewManager,
StyleSetHandle aStyleSet)
UniquePtr<ServoStyleSet> aStyleSet)
{
NS_ASSERTION(!mPresShell, "We have a presshell already!");

NS_ENSURE_FALSE(GetBFCacheEntry(), nullptr);

FillStyleSet(aStyleSet);
FillStyleSet(aStyleSet.get());
AssertNoStaleServoDataIn(static_cast<nsINode&>(*this));

RefPtr<PresShell> shell = new PresShell;
// Note: we don't hold a ref to the shell (it holds a ref to us)
mPresShell = shell;
shell->Init(this, aContext, aViewManager, aStyleSet);
shell->Init(this, aContext, aViewManager, Move(aStyleSet));

// Make sure to never paint if we belong to an invisible DocShell.
nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
Expand Down Expand Up @@ -4311,7 +4310,7 @@ nsIDocument::AddOnDemandBuiltInUASheet(StyleSheet* aSheet)
// do not override Firefox OS/Mobile's content.css sheet. Maybe we should
// have an insertion point to match the order of
// nsDocumentViewer::CreateStyleSet though?
shell->StyleSet()->PrependStyleSheet(SheetType::Agent, aSheet);
shell->StyleSet()->PrependStyleSheet(SheetType::Agent, aSheet->AsServo());
}
}

Expand All @@ -4323,7 +4322,7 @@ nsIDocument::AddStyleSheetToStyleSets(StyleSheet* aSheet)
{
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
shell->StyleSet()->AddDocStyleSheet(aSheet, this);
shell->StyleSet()->AddDocStyleSheet(aSheet->AsServo(), this);
}
}

Expand Down Expand Up @@ -4390,7 +4389,7 @@ nsIDocument::RemoveStyleSheetFromStyleSets(StyleSheet* aSheet)
{
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
shell->StyleSet()->RemoveDocStyleSheet(aSheet);
shell->StyleSet()->RemoveDocStyleSheet(aSheet->AsServo());
}
}

Expand Down Expand Up @@ -4611,7 +4610,7 @@ nsIDocument::AddAdditionalStyleSheet(additionalSheetType aType, StyleSheet* aShe
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
SheetType type = ConvertAdditionalSheetType(aType);
shell->StyleSet()->AppendStyleSheet(type, aSheet);
shell->StyleSet()->AppendStyleSheet(type, aSheet->AsServo());
}

// Passing false, so documet.styleSheets.length will not be affected by
Expand Down Expand Up @@ -4639,7 +4638,7 @@ nsIDocument::RemoveAdditionalStyleSheet(additionalSheetType aType, nsIURI* aShee
nsCOMPtr<nsIPresShell> shell = GetShell();
if (shell) {
SheetType type = ConvertAdditionalSheetType(aType);
shell->StyleSet()->RemoveStyleSheet(type, sheetRef);
shell->StyleSet()->RemoveStyleSheet(type, sheetRef->AsServo());
}
}

Expand Down
1 change: 0 additions & 1 deletion dom/base/nsDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "nsCycleCollectionParticipant.h"
#include "nsContentList.h"
#include "nsGkAtoms.h"
#include "mozilla/StyleSetHandle.h"
#include "PLDHashTable.h"
#include "nsDOMAttributeMap.h"
#include "imgIRequest.h"
Expand Down
11 changes: 6 additions & 5 deletions dom/base/nsIDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ErrorResult;
class EventStates;
class EventListenerManager;
class PendingAnimationTracker;
class StyleSetHandle;
class ServoStyleSet;
template<typename> class OwningNonNull;
struct URLExtraData;

Expand Down Expand Up @@ -1181,9 +1181,10 @@ class nsIDocument : public nsINode,
* method is responsible for calling BeginObservingDocument() on the
* presshell if the presshell should observe document mutations.
*/
already_AddRefed<nsIPresShell> CreateShell(nsPresContext* aContext,
nsViewManager* aViewManager,
mozilla::StyleSetHandle aStyleSet);
already_AddRefed<nsIPresShell> CreateShell(
nsPresContext* aContext,
nsViewManager* aViewManager,
mozilla::UniquePtr<mozilla::ServoStyleSet> aStyleSet);
void DeleteShell();

nsIPresShell* GetShell() const
Expand Down Expand Up @@ -3715,7 +3716,7 @@ class nsIDocument : public nsINode,
const nsTArray<RefPtr<mozilla::StyleSheet>>& aSheets,
mozilla::SheetType aType);
void ResetStylesheetsToURI(nsIURI* aURI);
void FillStyleSet(mozilla::StyleSetHandle aStyleSet);
void FillStyleSet(mozilla::ServoStyleSet* aStyleSet);
void AddStyleSheetToStyleSets(mozilla::StyleSheet* aSheet);
void RemoveStyleSheetFromStyleSets(mozilla::StyleSheet* aSheet);
void NotifyStyleSheetAdded(mozilla::StyleSheet* aSheet, bool aDocumentSheet);
Expand Down
69 changes: 25 additions & 44 deletions dom/canvas/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@
#include "Units.h"
#include "CanvasUtils.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSetHandleInlines.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/layers/CanvasClient.h"
#include "mozilla/layers/WebRenderUserData.h"
#include "mozilla/layers/WebRenderCanvasRenderer.h"
Expand Down Expand Up @@ -743,23 +742,12 @@ CanvasGradient::AddColorStop(float aOffset, const nsAString& aColorstr, ErrorRes
return;
}

nscolor color;
bool ok;

nsIPresShell* shell = mContext ? mContext->GetPresShell() : nullptr;
ServoStyleSet* servoStyleSet = shell && shell->StyleSet()
? shell->StyleSet()->GetAsServo()
: nullptr;
ServoStyleSet* styleSet = shell ? shell->StyleSet() : nullptr;

bool useServoParser =
true;

if (useServoParser) {
ok = ServoCSSParser::ComputeColor(servoStyleSet, NS_RGB(0, 0, 0), aColorstr,
&color);
} else {
MOZ_CRASH("old style system disabled");
}
nscolor color;
bool ok = ServoCSSParser::ComputeColor(styleSet, NS_RGB(0, 0, 0),
aColorstr, &color);

if (!ok) {
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
Expand Down Expand Up @@ -1158,34 +1146,27 @@ CanvasRenderingContext2D::ParseColor(const nsAString& aString,
nsIDocument* document = mCanvasElement ? mCanvasElement->OwnerDoc() : nullptr;
css::Loader* loader = document ? document->CSSLoader() : nullptr;

bool useServoParser =
true;
nsIPresShell* presShell = GetPresShell();
ServoStyleSet* set = presShell ? presShell->StyleSet() : nullptr;

if (useServoParser) {
nsIPresShell* presShell = GetPresShell();
ServoStyleSet* set = presShell ? presShell->StyleSet()->AsServo() : nullptr;

// First, try computing the color without handling currentcolor.
bool wasCurrentColor = false;
if (!ServoCSSParser::ComputeColor(set, NS_RGB(0, 0, 0), aString, aColor,
&wasCurrentColor, loader)) {
return false;
}
// First, try computing the color without handling currentcolor.
bool wasCurrentColor = false;
if (!ServoCSSParser::ComputeColor(set, NS_RGB(0, 0, 0), aString, aColor,
&wasCurrentColor, loader)) {
return false;
}

if (wasCurrentColor && mCanvasElement) {
// Otherwise, get the value of the color property, flushing style
// if necessary.
RefPtr<ComputedStyle> canvasStyle =
nsComputedDOMStyle::GetComputedStyle(mCanvasElement, nullptr);
if (canvasStyle) {
*aColor = canvasStyle->StyleColor()->mColor;
}
// Beware that the presShell could be gone here.
if (wasCurrentColor && mCanvasElement) {
// Otherwise, get the value of the color property, flushing style
// if necessary.
RefPtr<ComputedStyle> canvasStyle =
nsComputedDOMStyle::GetComputedStyle(mCanvasElement, nullptr);
if (canvasStyle) {
*aColor = canvasStyle->StyleColor()->mColor;
}
return true;
// Beware that the presShell could be gone here.
}

MOZ_CRASH("old style system disabled");
return true;
}

nsresult
Expand Down Expand Up @@ -2704,7 +2685,7 @@ GetFontStyleForServo(Element* aElement, const nsAString& aFont,
return nullptr;
}

ServoStyleSet* styleSet = aPresShell->StyleSet()->AsServo();
ServoStyleSet* styleSet = aPresShell->StyleSet();

RefPtr<ComputedStyle> parentStyle;
// have to get a parent ComputedStyle for inherit-like relative
Expand All @@ -2723,7 +2704,7 @@ GetFontStyleForServo(Element* aElement, const nsAString& aFont,
aPresShell->GetDocument());
MOZ_ASSERT(declarations);

parentStyle = aPresShell->StyleSet()->AsServo()->
parentStyle = aPresShell->StyleSet()->
ResolveForDeclarations(nullptr, declarations);
}

Expand Down Expand Up @@ -2772,7 +2753,7 @@ ResolveFilterStyleForServo(const nsAString& aFilterString,
return nullptr;
}

ServoStyleSet* styleSet = aPresShell->StyleSet()->AsServo();
ServoStyleSet* styleSet = aPresShell->StyleSet();
RefPtr<ComputedStyle> computedValues =
styleSet->ResolveForDeclarations(aParentStyle, declarations);

Expand Down
2 changes: 0 additions & 2 deletions dom/html/nsGenericHTMLElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@
#include "mozilla/dom/HTMLBodyElement.h"
#include "imgIContainer.h"
#include "nsComputedDOMStyle.h"
#include "mozilla/StyleSetHandle.h"
#include "mozilla/StyleSetHandleInlines.h"
#include "ReferrerPolicy.h"
#include "mozilla/dom/HTMLLabelElement.h"
#include "mozilla/dom/HTMLInputElement.h"
Expand Down
Loading

0 comments on commit 24a7c53

Please sign in to comment.