Skip to content

Commit

Permalink
Bug 1244074 - Part 4: Use StyleSheetHandle instead of concrete style …
Browse files Browse the repository at this point in the history
…sheet class in most places. r=dholbert
  • Loading branch information
heycam committed Feb 24, 2016
1 parent cc34b83 commit 1c47d5e
Show file tree
Hide file tree
Showing 64 changed files with 1,031 additions and 777 deletions.
28 changes: 14 additions & 14 deletions chrome/nsChromeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "nsString.h"
#include "nsQueryObject.h"

#include "mozilla/CSSStyleSheet.h"
#include "mozilla/dom/URL.h"
#include "nsIConsoleService.h"
#include "nsIDocument.h"
Expand All @@ -30,12 +29,14 @@
#include "nsIScriptError.h"
#include "nsIWindowMediator.h"
#include "nsIPrefService.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"

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::CSSStyleSheet;
using mozilla::StyleSheetHandle;
using mozilla::dom::IsChromeURI;

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -401,19 +402,18 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
nsCOMPtr<nsIPresShell> shell = document->GetShell();
if (shell) {
// Reload only the chrome URL agent style sheets.
nsTArray<RefPtr<CSSStyleSheet>> agentSheets;
nsTArray<StyleSheetHandle::RefPtr> agentSheets;
rv = shell->GetAgentStyleSheets(agentSheets);
NS_ENSURE_SUCCESS(rv, rv);

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

if (IsChromeURI(uri)) {
// Reload the sheet.
RefPtr<CSSStyleSheet> newSheet;
rv = document->LoadChromeSheetSync(uri, true,
getter_AddRefs(newSheet));
StyleSheetHandle::RefPtr newSheet;
rv = document->LoadChromeSheetSync(uri, true, &newSheet);
if (NS_FAILED(rv)) return rv;
if (newSheet) {
rv = newAgentSheets.AppendElement(newSheet) ? NS_OK : NS_ERROR_FAILURE;
Expand All @@ -433,27 +433,27 @@ nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
int32_t count = document->GetNumberOfStyleSheets();

// Build an array of style sheets we need to reload.
nsTArray<RefPtr<CSSStyleSheet>> oldSheets(count);
nsTArray<RefPtr<CSSStyleSheet>> newSheets(count);
nsTArray<StyleSheetHandle::RefPtr> oldSheets(count);
nsTArray<StyleSheetHandle::RefPtr> newSheets(count);

// Iterate over the style sheets.
for (int32_t i = 0; i < count; i++) {
// Get the style sheet
CSSStyleSheet* styleSheet = document->GetStyleSheetAt(i);
StyleSheetHandle styleSheet = document->GetStyleSheetAt(i);
oldSheets.AppendElement(styleSheet);
}

// Iterate over our old sheets and kick off a sync load of the new
// sheet if and only if it's a chrome URL.
for (CSSStyleSheet* sheet : oldSheets) {
for (StyleSheetHandle sheet : oldSheets) {
nsIURI* uri = sheet ? sheet->GetOriginalURI() : nullptr;

if (uri && IsChromeURI(uri)) {
// Reload the sheet.
RefPtr<CSSStyleSheet> newSheet;
StyleSheetHandle::RefPtr newSheet;
// XXX what about chrome sheets that have a title or are disabled? This
// only works by sheer dumb luck.
document->LoadChromeSheetSync(uri, false, getter_AddRefs(newSheet));
document->LoadChromeSheetSync(uri, false, &newSheet);
// Even if it's null, we put in in there.
newSheets.AppendElement(newSheet);
} else {
Expand Down
19 changes: 14 additions & 5 deletions dom/base/ShadowRoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "mozilla/dom/HTMLContentElement.h"
#include "mozilla/dom/HTMLShadowElement.h"
#include "nsXBLPrototypeBinding.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetHandleInlines.h"

using namespace mozilla;
using namespace mozilla::dom;
Expand Down Expand Up @@ -130,7 +132,7 @@ ShadowRoot::StyleSheetChanged()
}

void
ShadowRoot::InsertSheet(CSSStyleSheet* aSheet,
ShadowRoot::InsertSheet(StyleSheetHandle aSheet,
nsIContent* aLinkingContent)
{
nsCOMPtr<nsIStyleSheetLinkingElement>
Expand All @@ -148,8 +150,8 @@ ShadowRoot::InsertSheet(CSSStyleSheet* aSheet,
break;
}

nsINode* sheetOwnerNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode();
if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwnerNode)) {
nsINode* sheetOwningNode = mProtoBinding->StyleSheetAt(i)->GetOwnerNode();
if (nsContentUtils::PositionIsBefore(aLinkingContent, sheetOwningNode)) {
mProtoBinding->InsertStyleSheetAt(i, aSheet);
break;
}
Expand All @@ -161,7 +163,7 @@ ShadowRoot::InsertSheet(CSSStyleSheet* aSheet,
}

void
ShadowRoot::RemoveSheet(CSSStyleSheet* aSheet)
ShadowRoot::RemoveSheet(StyleSheetHandle aSheet)
{
mProtoBinding->RemoveStyleSheet(aSheet);

Expand Down Expand Up @@ -752,7 +754,14 @@ ShadowRootStyleSheetList::IndexedGetter(uint32_t aIndex, bool& aFound)
return nullptr;
}

return mShadowRoot->mProtoBinding->StyleSheetAt(aIndex);
// XXXheycam Return null until ServoStyleSheet implements the right
// DOM interfaces.
StyleSheetHandle sheet = mShadowRoot->mProtoBinding->StyleSheetAt(aIndex);
if (sheet->IsServo()) {
NS_ERROR("stylo: can't return ServoStyleSheets to script yet");
return nullptr;
}
return sheet->AsGecko();
}

uint32_t
Expand Down
5 changes: 3 additions & 2 deletions dom/base/ShadowRoot.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/StyleSheetList.h"
#include "mozilla/StyleSheetHandle.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsTHashtable.h"
Expand Down Expand Up @@ -45,8 +46,8 @@ class ShadowRoot final : public DocumentFragment,

void AddToIdTable(Element* aElement, nsIAtom* aId);
void RemoveFromIdTable(Element* aElement, nsIAtom* aId);
void InsertSheet(CSSStyleSheet* aSheet, nsIContent* aLinkingContent);
void RemoveSheet(CSSStyleSheet* aSheet);
void InsertSheet(StyleSheetHandle aSheet, nsIContent* aLinkingContent);
void RemoveSheet(StyleSheetHandle aSheet);
bool ApplyAuthorStyles();
void SetApplyAuthorStyles(bool aApplyAuthorStyles);
StyleSheetList* StyleSheets();
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsContentSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ nsContentSink::Init(nsIDocument* aDoc,
}

NS_IMETHODIMP
nsContentSink::StyleSheetLoaded(CSSStyleSheet* aSheet,
nsContentSink::StyleSheetLoaded(StyleSheetHandle aSheet,
bool aWasAlternate,
nsresult aStatus)
{
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsContentSink.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class nsContentSink : public nsICSSLoaderObserver,
NS_DECL_NSITIMERCALLBACK

// nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet,
NS_IMETHOD StyleSheetLoaded(mozilla::StyleSheetHandle aSheet,
bool aWasAlternate,
nsresult aStatus) override;

Expand Down
Loading

0 comments on commit 1c47d5e

Please sign in to comment.