2016-02-26 04:51:01 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2016-03-02 01:38:13 +03:00
|
|
|
#include "mozilla/StyleSheet.h"
|
|
|
|
|
2016-03-02 02:10:45 +03:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2016-03-02 01:38:13 +03:00
|
|
|
#include "mozilla/ServoStyleSheet.h"
|
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
|
|
|
#include "mozilla/CSSStyleSheet.h"
|
2016-02-26 04:51:01 +03:00
|
|
|
|
2016-09-29 09:19:06 +03:00
|
|
|
#include "nsNullPrincipal.h"
|
|
|
|
|
2016-02-26 04:51:01 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2016-08-02 23:12:27 +03:00
|
|
|
StyleSheet::StyleSheet(StyleBackendType aType, css::SheetParsingMode aParsingMode)
|
2016-03-01 23:39:29 +03:00
|
|
|
: mDocument(nullptr)
|
|
|
|
, mOwningNode(nullptr)
|
2016-08-02 23:12:27 +03:00
|
|
|
, mParsingMode(aParsingMode)
|
2016-03-02 01:38:13 +03:00
|
|
|
, mType(aType)
|
2016-02-26 04:51:01 +03:00
|
|
|
, mDisabled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleSheet::StyleSheet(const StyleSheet& aCopy,
|
2016-03-01 23:39:29 +03:00
|
|
|
nsIDocument* aDocumentToUse,
|
2016-02-26 04:51:01 +03:00
|
|
|
nsINode* aOwningNodeToUse)
|
2016-03-01 23:39:29 +03:00
|
|
|
: mDocument(aDocumentToUse)
|
|
|
|
, mOwningNode(aOwningNodeToUse)
|
2016-02-26 04:51:01 +03:00
|
|
|
, mParsingMode(aCopy.mParsingMode)
|
2016-03-02 01:38:13 +03:00
|
|
|
, mType(aCopy.mType)
|
2016-02-26 04:51:01 +03:00
|
|
|
, mDisabled(aCopy.mDisabled)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-02 23:17:06 +03:00
|
|
|
mozilla::dom::CSSStyleSheetParsingMode
|
|
|
|
StyleSheet::ParsingModeDOM()
|
|
|
|
{
|
|
|
|
#define CHECK(X, Y) \
|
|
|
|
static_assert(static_cast<int>(X) == static_cast<int>(Y), \
|
|
|
|
"mozilla::dom::CSSStyleSheetParsingMode and mozilla::css::SheetParsingMode should have identical values");
|
|
|
|
|
|
|
|
CHECK(mozilla::dom::CSSStyleSheetParsingMode::Agent, css::eAgentSheetFeatures);
|
|
|
|
CHECK(mozilla::dom::CSSStyleSheetParsingMode::User, css::eUserSheetFeatures);
|
|
|
|
CHECK(mozilla::dom::CSSStyleSheetParsingMode::Author, css::eAuthorSheetFeatures);
|
|
|
|
|
|
|
|
#undef CHECK
|
|
|
|
|
|
|
|
return static_cast<mozilla::dom::CSSStyleSheetParsingMode>(mParsingMode);
|
|
|
|
}
|
|
|
|
|
2016-03-02 02:10:45 +03:00
|
|
|
bool
|
|
|
|
StyleSheet::IsComplete() const
|
|
|
|
{
|
|
|
|
return SheetInfo().mComplete;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleSheet::SetComplete()
|
|
|
|
{
|
2016-09-26 15:03:25 +03:00
|
|
|
NS_ASSERTION(!IsGecko() || !AsGecko()->mDirty,
|
|
|
|
"Can't set a dirty sheet complete!");
|
2016-03-02 02:10:45 +03:00
|
|
|
SheetInfo().mComplete = true;
|
|
|
|
if (mDocument && !mDisabled) {
|
|
|
|
// Let the document know
|
|
|
|
mDocument->BeginUpdate(UPDATE_STYLE);
|
2016-09-26 15:03:25 +03:00
|
|
|
mDocument->SetStyleSheetApplicableState(this, true);
|
2016-03-02 02:10:45 +03:00
|
|
|
mDocument->EndUpdate(UPDATE_STYLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOwningNode && !mDisabled &&
|
|
|
|
mOwningNode->HasFlag(NODE_IS_IN_SHADOW_TREE) &&
|
|
|
|
mOwningNode->IsContent()) {
|
2016-07-08 00:05:28 +03:00
|
|
|
dom::ShadowRoot* shadowRoot = mOwningNode->AsContent()->GetContainingShadow();
|
2016-03-02 02:10:45 +03:00
|
|
|
shadowRoot->StyleSheetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-29 09:19:06 +03:00
|
|
|
StyleSheetInfo::StyleSheetInfo(CORSMode aCORSMode,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
const dom::SRIMetadata& aIntegrity)
|
|
|
|
: mPrincipal(nsNullPrincipal::Create())
|
|
|
|
, mCORSMode(aCORSMode)
|
|
|
|
, mReferrerPolicy(aReferrerPolicy)
|
|
|
|
, mIntegrity(aIntegrity)
|
|
|
|
, mComplete(false)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mPrincipalSet(false)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (!mPrincipal) {
|
|
|
|
NS_RUNTIMEABORT("nsNullPrincipal::Init failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-26 04:51:01 +03:00
|
|
|
} // namespace mozilla
|