Files
tubestation/layout/style/ServoStyleSheet.cpp
Xidorn Quan 42a86c72db Bug 1292432 part 2 - Make StyleSheet inherit nsIDOMCSSStyleSheet. r=heycam
Some method impls are also moved from CSSStyleSheet to StyleSheet so
that they can be shared between the two subclasses.

The new interface methods added to ServoStyleSheet is currently left
unimplemented. They would be implemented in later patches.

MozReview-Commit-ID: 45wHT9BSHTK
2016-10-14 22:25:38 +11:00

157 lines
3.9 KiB
C++

/* -*- 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/ServoStyleSheet.h"
#include "mozilla/StyleBackendType.h"
namespace mozilla {
ServoStyleSheet::ServoStyleSheet(css::SheetParsingMode aParsingMode,
CORSMode aCORSMode,
net::ReferrerPolicy aReferrerPolicy,
const dom::SRIMetadata& aIntegrity)
: StyleSheet(StyleBackendType::Servo, aParsingMode)
, mSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity)
{
}
ServoStyleSheet::~ServoStyleSheet()
{
DropSheet();
}
NS_INTERFACE_MAP_BEGIN(ServoStyleSheet)
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(ServoStyleSheet)
NS_IMPL_RELEASE(ServoStyleSheet)
bool
ServoStyleSheet::HasRules() const
{
return mSheet && Servo_StyleSheet_HasRules(mSheet);
}
void
ServoStyleSheet::SetOwningDocument(nsIDocument* aDocument)
{
// XXXheycam: Traverse to child ServoStyleSheets to set this, like
// CSSStyleSheet::SetOwningDocument does.
mDocument = aDocument;
}
ServoStyleSheet*
ServoStyleSheet::GetParentSheet() const
{
// XXXheycam: When we implement support for child sheets, we'll have
// to fix SetOwningDocument to propagate the owning document down
// to the children.
MOZ_CRASH("stylo: not implemented");
}
void
ServoStyleSheet::AppendStyleSheet(ServoStyleSheet* aSheet)
{
// XXXheycam: When we implement support for child sheets, we'll have
// to fix SetOwningDocument to propagate the owning document down
// to the children.
MOZ_CRASH("stylo: not implemented");
}
nsresult
ServoStyleSheet::ParseSheet(const nsAString& aInput,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
uint32_t aLineNumber)
{
DropSheet();
RefPtr<ThreadSafeURIHolder> base = new ThreadSafeURIHolder(aBaseURI);
RefPtr<ThreadSafeURIHolder> referrer = new ThreadSafeURIHolder(aSheetURI);
RefPtr<ThreadSafePrincipalHolder> principal =
new ThreadSafePrincipalHolder(aSheetPrincipal);
nsCString baseString;
nsresult rv = aBaseURI->GetSpec(baseString);
NS_ENSURE_SUCCESS(rv, rv);
NS_ConvertUTF16toUTF8 input(aInput);
mSheet = Servo_StyleSheet_FromUTF8Bytes(
reinterpret_cast<const uint8_t*>(input.get()), input.Length(),
mParsingMode,
reinterpret_cast<const uint8_t*>(baseString.get()), baseString.Length(),
base, referrer, principal).Consume();
return NS_OK;
}
void
ServoStyleSheet::DropSheet()
{
mSheet = nullptr;
}
size_t
ServoStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
MOZ_CRASH("stylo: not implemented");
}
#ifdef DEBUG
void
ServoStyleSheet::List(FILE* aOut, int32_t aIndex) const
{
MOZ_CRASH("stylo: not implemented");
}
#endif
// nsIDOMStyleSheet implementation
NS_IMETHODIMP
ServoStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ServoStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsIDOMCSSStyleSheet implementation
nsresult
ServoStyleSheet::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
ServoStyleSheet::GetCssRules(nsIDOMCSSRuleList** aCssRules)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
ServoStyleSheet::InsertRule(const nsAString& rule,
uint32_t aIndex, uint32_t* aReturn)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
ServoStyleSheet::DeleteRule(uint32_t aIndex)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
} // namespace mozilla