зеркало из https://github.com/mozilla/gecko-dev.git
Bug 676054 - part2: Provide AUTHOR_SHEET type for registering with nsIStyleSheetService. r=bz
This commit is contained in:
Родитель
646d27f717
Коммит
a731451bde
|
@ -187,6 +187,7 @@ LOCAL_INCLUDES += \
|
|||
-I$(topsrcdir)/dom/ipc \
|
||||
-I$(topsrcdir)/image/src \
|
||||
-I$(topsrcdir)/js/xpconnect/src \
|
||||
-I$(topsrcdir)/layout/base \
|
||||
-I$(topsrcdir)/layout/generic \
|
||||
-I$(topsrcdir)/layout/style \
|
||||
-I$(topsrcdir)/layout/svg \
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
#include "nsIRefreshURI.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsStyleSheetService.h"
|
||||
|
||||
#include "nsNetUtil.h" // for NS_MakeAbsoluteURI
|
||||
|
||||
|
@ -2318,6 +2319,14 @@ nsDocument::ResetStylesheetsToURI(nsIURI* aURI)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static bool
|
||||
AppendAuthorSheet(nsIStyleSheet *aSheet, void *aData)
|
||||
{
|
||||
nsStyleSet *styleSet = static_cast<nsStyleSet*>(aData);
|
||||
styleSet->AppendStyleSheet(nsStyleSet::eDocSheet, aSheet);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
nsDocument::FillStyleSet(nsStyleSet* aStyleSet)
|
||||
{
|
||||
|
@ -2331,6 +2340,12 @@ nsDocument::FillStyleSet(nsStyleSet* aStyleSet)
|
|||
NS_PRECONDITION(mStyleAttrStyleSheet, "No style attr stylesheet?");
|
||||
NS_PRECONDITION(mAttrStyleSheet, "No attr stylesheet?");
|
||||
|
||||
nsCOMPtr<nsIStyleSheetService> dummy =
|
||||
do_GetService(NS_STYLESHEETSERVICE_CONTRACTID);
|
||||
|
||||
nsStyleSheetService *sheetService = nsStyleSheetService::gInstance;
|
||||
|
||||
|
||||
aStyleSet->AppendStyleSheet(nsStyleSet::ePresHintSheet, mAttrStyleSheet);
|
||||
|
||||
aStyleSet->AppendStyleSheet(nsStyleSet::eStyleAttrSheet,
|
||||
|
@ -2344,6 +2359,11 @@ nsDocument::FillStyleSet(nsStyleSet* aStyleSet)
|
|||
}
|
||||
}
|
||||
|
||||
if (sheetService) {
|
||||
sheetService->AuthorStyleSheets()->EnumerateForwards(AppendAuthorSheet,
|
||||
aStyleSet);
|
||||
}
|
||||
|
||||
for (i = mCatalogSheets.Count() - 1; i >= 0; --i) {
|
||||
nsIStyleSheet* sheet = mCatalogSheets[i];
|
||||
if (sheet->IsApplicable()) {
|
||||
|
|
|
@ -19,6 +19,7 @@ interface nsIStyleSheetService : nsISupports
|
|||
{
|
||||
const unsigned long AGENT_SHEET = 0;
|
||||
const unsigned long USER_SHEET = 1;
|
||||
const unsigned long AUTHOR_SHEET = 2;
|
||||
|
||||
/**
|
||||
* Synchronously loads a style sheet from |sheetURI| and adds it to the list
|
||||
|
|
|
@ -880,8 +880,10 @@ PresShell::Init(nsIDocument* aDocument,
|
|||
if (os) {
|
||||
os->AddObserver(this, "agent-sheet-added", false);
|
||||
os->AddObserver(this, "user-sheet-added", false);
|
||||
os->AddObserver(this, "author-sheet-added", false);
|
||||
os->AddObserver(this, "agent-sheet-removed", false);
|
||||
os->AddObserver(this, "user-sheet-removed", false);
|
||||
os->AddObserver(this, "author-sheet-removed", false);
|
||||
#ifdef MOZ_XUL
|
||||
os->AddObserver(this, "chrome-flush-skin-caches", false);
|
||||
#endif
|
||||
|
@ -970,8 +972,10 @@ PresShell::Destroy()
|
|||
if (os) {
|
||||
os->RemoveObserver(this, "agent-sheet-added");
|
||||
os->RemoveObserver(this, "user-sheet-added");
|
||||
os->RemoveObserver(this, "author-sheet-added");
|
||||
os->RemoveObserver(this, "agent-sheet-removed");
|
||||
os->RemoveObserver(this, "user-sheet-removed");
|
||||
os->RemoveObserver(this, "author-sheet-removed");
|
||||
#ifdef MOZ_XUL
|
||||
os->RemoveObserver(this, "chrome-flush-skin-caches");
|
||||
#endif
|
||||
|
@ -1510,6 +1514,18 @@ PresShell::AddAgentSheet(nsISupports* aSheet)
|
|||
ReconstructStyleData();
|
||||
}
|
||||
|
||||
void
|
||||
PresShell::AddAuthorSheet(nsISupports* aSheet)
|
||||
{
|
||||
nsCOMPtr<nsIStyleSheet> sheet = do_QueryInterface(aSheet);
|
||||
if (!sheet) {
|
||||
return;
|
||||
}
|
||||
|
||||
mStyleSet->AppendStyleSheet(nsStyleSet::eDocSheet, sheet);
|
||||
ReconstructStyleData();
|
||||
}
|
||||
|
||||
void
|
||||
PresShell::RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet)
|
||||
{
|
||||
|
@ -7752,6 +7768,11 @@ PresShell::Observe(nsISupports* aSubject,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, "author-sheet-added") && mStyleSet) {
|
||||
AddAuthorSheet(aSubject);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, "agent-sheet-removed") && mStyleSet) {
|
||||
RemoveSheet(nsStyleSet::eAgentSheet, aSubject);
|
||||
return NS_OK;
|
||||
|
@ -7762,6 +7783,11 @@ PresShell::Observe(nsISupports* aSubject,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, "author-sheet-removed") && mStyleSet) {
|
||||
RemoveSheet(nsStyleSet::eDocSheet, aSubject);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_WARNING("unrecognized topic in PresShell::Observe");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
|
|
@ -489,6 +489,7 @@ protected:
|
|||
*/
|
||||
void AddUserSheet(nsISupports* aSheet);
|
||||
void AddAgentSheet(nsISupports* aSheet);
|
||||
void AddAuthorSheet(nsISupports* aSheet);
|
||||
void RemoveSheet(nsStyleSet::sheetType aType, nsISupports* aSheet);
|
||||
|
||||
// Hide a view if it is a popup
|
||||
|
|
|
@ -42,7 +42,7 @@ nsStyleSheetService *nsStyleSheetService::gInstance = nullptr;
|
|||
|
||||
nsStyleSheetService::nsStyleSheetService()
|
||||
{
|
||||
PR_STATIC_ASSERT(0 == AGENT_SHEET && 1 == USER_SHEET);
|
||||
PR_STATIC_ASSERT(0 == AGENT_SHEET && 1 == USER_SHEET && 2 == AUTHOR_SHEET);
|
||||
NS_ASSERTION(!gInstance, "Someone is using CreateInstance instead of GetService");
|
||||
gInstance = this;
|
||||
nsLayoutStatics::AddRef();
|
||||
|
@ -129,6 +129,9 @@ nsStyleSheetService::Init()
|
|||
catMan->EnumerateCategory("user-style-sheets", getter_AddRefs(sheets));
|
||||
RegisterFromEnumerator(catMan, "user-style-sheets", sheets, USER_SHEET);
|
||||
|
||||
catMan->EnumerateCategory("author-style-sheets", getter_AddRefs(sheets));
|
||||
RegisterFromEnumerator(catMan, "author-style-sheets", sheets, AUTHOR_SHEET);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -138,8 +141,20 @@ nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI,
|
|||
{
|
||||
nsresult rv = LoadAndRegisterSheetInternal(aSheetURI, aSheetType);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
const char* message = (aSheetType == AGENT_SHEET) ?
|
||||
"agent-sheet-added" : "user-sheet-added";
|
||||
const char* message;
|
||||
switch (aSheetType) {
|
||||
case AGENT_SHEET:
|
||||
message = "agent-sheet-added";
|
||||
break;
|
||||
case USER_SHEET:
|
||||
message = "user-sheet-added";
|
||||
break;
|
||||
case AUTHOR_SHEET:
|
||||
message = "author-sheet-added";
|
||||
break;
|
||||
default:
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
nsCOMPtr<nsIObserverService> serv =
|
||||
mozilla::services::GetObserverService();
|
||||
if (serv) {
|
||||
|
@ -156,7 +171,9 @@ nsresult
|
|||
nsStyleSheetService::LoadAndRegisterSheetInternal(nsIURI *aSheetURI,
|
||||
uint32_t aSheetType)
|
||||
{
|
||||
NS_ENSURE_ARG(aSheetType == AGENT_SHEET || aSheetType == USER_SHEET);
|
||||
NS_ENSURE_ARG(aSheetType == AGENT_SHEET ||
|
||||
aSheetType == USER_SHEET ||
|
||||
aSheetType == AUTHOR_SHEET);
|
||||
NS_ENSURE_ARG_POINTER(aSheetURI);
|
||||
|
||||
nsRefPtr<mozilla::css::Loader> loader = new mozilla::css::Loader();
|
||||
|
@ -178,7 +195,9 @@ NS_IMETHODIMP
|
|||
nsStyleSheetService::SheetRegistered(nsIURI *sheetURI,
|
||||
uint32_t aSheetType, bool *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(aSheetType == AGENT_SHEET || aSheetType == USER_SHEET);
|
||||
NS_ENSURE_ARG(aSheetType == AGENT_SHEET ||
|
||||
aSheetType == USER_SHEET ||
|
||||
aSheetType == AUTHOR_SHEET);
|
||||
NS_ENSURE_ARG_POINTER(sheetURI);
|
||||
NS_PRECONDITION(_retval, "Null out param");
|
||||
|
||||
|
@ -190,7 +209,9 @@ nsStyleSheetService::SheetRegistered(nsIURI *sheetURI,
|
|||
NS_IMETHODIMP
|
||||
nsStyleSheetService::UnregisterSheet(nsIURI *sheetURI, uint32_t aSheetType)
|
||||
{
|
||||
NS_ENSURE_ARG(aSheetType == AGENT_SHEET || aSheetType == USER_SHEET);
|
||||
NS_ENSURE_ARG(aSheetType == AGENT_SHEET ||
|
||||
aSheetType == USER_SHEET ||
|
||||
aSheetType == AUTHOR_SHEET);
|
||||
NS_ENSURE_ARG_POINTER(sheetURI);
|
||||
|
||||
int32_t foundIndex = FindSheetByURI(mSheets[aSheetType], sheetURI);
|
||||
|
@ -198,8 +219,19 @@ nsStyleSheetService::UnregisterSheet(nsIURI *sheetURI, uint32_t aSheetType)
|
|||
nsCOMPtr<nsIStyleSheet> sheet = mSheets[aSheetType][foundIndex];
|
||||
mSheets[aSheetType].RemoveObjectAt(foundIndex);
|
||||
|
||||
const char* message = (aSheetType == AGENT_SHEET) ?
|
||||
"agent-sheet-removed" : "user-sheet-removed";
|
||||
const char* message;
|
||||
switch (aSheetType) {
|
||||
case AGENT_SHEET:
|
||||
message = "agent-sheet-removed";
|
||||
break;
|
||||
case USER_SHEET:
|
||||
message = "user-sheet-removed";
|
||||
break;
|
||||
case AUTHOR_SHEET:
|
||||
message = "author-sheet-removed";
|
||||
break;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> serv =
|
||||
mozilla::services::GetObserverService();
|
||||
if (serv)
|
||||
|
@ -234,6 +266,8 @@ nsStyleSheetService::SizeOfIncludingThisHelper(nsMallocSizeOfFun aMallocSizeOf)
|
|||
aMallocSizeOf);
|
||||
n += mSheets[USER_SHEET].SizeOfExcludingThis(SizeOfElementIncludingThis,
|
||||
aMallocSizeOf);
|
||||
n += mSheets[AUTHOR_SHEET].SizeOfExcludingThis(SizeOfElementIncludingThis,
|
||||
aMallocSizeOf);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ class nsStyleSheetService MOZ_FINAL : public nsIStyleSheetService
|
|||
|
||||
nsCOMArray<nsIStyleSheet>* AgentStyleSheets() { return &mSheets[AGENT_SHEET]; }
|
||||
nsCOMArray<nsIStyleSheet>* UserStyleSheets() { return &mSheets[USER_SHEET]; }
|
||||
nsCOMArray<nsIStyleSheet>* AuthorStyleSheets() { return &mSheets[AUTHOR_SHEET]; }
|
||||
|
||||
static size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
|
||||
|
||||
|
@ -59,7 +60,7 @@ class nsStyleSheetService MOZ_FINAL : public nsIStyleSheetService
|
|||
|
||||
size_t SizeOfIncludingThisHelper(nsMallocSizeOfFun aMallocSizeOf) const;
|
||||
|
||||
nsCOMArray<nsIStyleSheet> mSheets[2];
|
||||
nsCOMArray<nsIStyleSheet> mSheets[3];
|
||||
|
||||
nsIMemoryReporter* mReporter;
|
||||
};
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsTransitionManager.h"
|
||||
#include "nsAnimationManager.h"
|
||||
#include "nsEventStates.h"
|
||||
#include "nsStyleSheetService.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "sampler.h"
|
||||
|
||||
|
@ -362,8 +363,11 @@ nsStyleSet::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
|
|||
nsCOMArray<nsIStyleSheet>& docSheets = mSheets[eDocSheet];
|
||||
|
||||
docSheets.RemoveObject(aSheet);
|
||||
nsStyleSheetService *sheetService = nsStyleSheetService::gInstance;
|
||||
|
||||
// lowest index first
|
||||
int32_t newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet);
|
||||
|
||||
int32_t count = docSheets.Count();
|
||||
int32_t index;
|
||||
for (index = 0; index < count; index++) {
|
||||
|
@ -371,6 +375,14 @@ nsStyleSet::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument)
|
|||
int32_t sheetDocIndex = aDocument->GetIndexOfStyleSheet(sheet);
|
||||
if (sheetDocIndex > newDocIndex)
|
||||
break;
|
||||
|
||||
// If the sheet is not owned by the document it can be an author
|
||||
// sheet registered at nsStyleSheetService, which means the new
|
||||
// doc sheet should end up before it.
|
||||
if (sheetDocIndex < 0 &&
|
||||
sheetService &&
|
||||
sheetService->AuthorStyleSheets()->IndexOf(sheet) >= 0)
|
||||
break;
|
||||
}
|
||||
if (!docSheets.InsertObjectAt(aSheet, index))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
|
|
@ -74,6 +74,11 @@ function loadAndRegisterAgentSheet(win, style)
|
|||
loadAndRegisterSheet(win, style, "AGENT_SHEET");
|
||||
}
|
||||
|
||||
function loadAndRegisterAuthorSheet(win, style)
|
||||
{
|
||||
loadAndRegisterSheet(win, style, "AUTHOR_SHEET");
|
||||
}
|
||||
|
||||
function unregisterUserSheet(win, style)
|
||||
{
|
||||
unregisterSheet(win, style, "USER_SHEET");
|
||||
|
@ -84,6 +89,11 @@ function unregisterAgentSheet(win, style)
|
|||
unregisterSheet(win, style, "AGENT_SHEET");
|
||||
}
|
||||
|
||||
function unregisterAuthorSheet(win, style)
|
||||
{
|
||||
unregisterSheet(win, style, "AUTHOR_SHEET");
|
||||
}
|
||||
|
||||
function loadAndRegisterSheet(win, style, type)
|
||||
{
|
||||
var sss = Components.classes["@mozilla.org/content/style-sheet-service;1"]
|
||||
|
@ -159,6 +169,13 @@ var author = {
|
|||
removeRules: removeDocSheet
|
||||
};
|
||||
|
||||
var authorFromManager = {
|
||||
type: 'authorFromManager',
|
||||
color: 'rgb(255, 0, 255)',
|
||||
addRules: loadAndRegisterAuthorSheet,
|
||||
removeRules: unregisterAuthorSheet
|
||||
};
|
||||
|
||||
function loadAndCheck(win, firstType, secondType, swap, result1, result2)
|
||||
{
|
||||
var firstStyle = getStyle(firstType.color, false);
|
||||
|
@ -240,6 +257,15 @@ function run()
|
|||
testStyleVsStyle(win, additionalAgent, additionalUser,
|
||||
{AB:{rr:1, ii:0, ri:1, ir:0}, BA:{rr:1, ii:0, ri:1, ir:0}});
|
||||
|
||||
testStyleVsStyle(win, authorFromManager, author,
|
||||
{AB:{rr:0, ii:0, ri:1, ir:0}, BA:{rr:0, ii:0, ri:1, ir:0}});
|
||||
|
||||
testStyleVsStyle(win, authorFromManager, user,
|
||||
{AB:{rr:0, ii:1, ri:1, ir:0}, BA:{rr:0, ii:1, ri:1, ir:0}});
|
||||
|
||||
testStyleVsStyle(win, authorFromManager, additionalUser,
|
||||
{AB:{rr:0, ii:1, ri:1, ir:0}, BA:{rr:0, ii:1, ri:1, ir:0}});
|
||||
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче