Bug 1250788 - Part 3.3: Implement enough of ServoStyleSheet for Loader to be able to create and parse one. r=bholley

This commit is contained in:
Cameron McCormack 2016-02-26 12:51:01 +11:00
parent 03e9025216
commit bc4b843c37
5 changed files with 95 additions and 89 deletions

View File

@ -147,3 +147,33 @@ Gecko_SetNodeData(RawGeckoNode* aNode, ServoNodeData* aData)
{
aNode->SetServoNodeData(aData);
}
#ifndef MOZ_STYLO
void
Servo_DropNodeData(ServoNodeData* data)
{
MOZ_CRASH("stylo: shouldn't be calling Servo_DropNodeData in a "
"non-MOZ_STYLO build");
}
RawServoStyleSheet*
Servo_StylesheetFromUTF8Bytes(const uint8_t* bytes, uint32_t length)
{
MOZ_CRASH("stylo: shouldn't be calling Servo_StylesheetFromUTF8Bytes in a "
"non-MOZ_STYLO build");
}
void
Servo_ReleaseStylesheet(RawServoStyleSheet* sheet)
{
MOZ_CRASH("stylo: shouldn't be calling Servo_ReleaseStylesheet in a "
"non-MOZ_STYLO build");
}
void
Servo_RestyleDocument(RawGeckoDocument* aDoc)
{
MOZ_CRASH("stylo: shouldn't be calling Servo_RestyleDocument in a "
"non-MOZ_STYLO build");
}
#endif

View File

@ -6,50 +6,35 @@
#include "mozilla/ServoStyleSheet.h"
using namespace mozilla::dom;
namespace mozilla {
nsIURI*
ServoStyleSheet::GetSheetURI() const
ServoStyleSheet::ServoStyleSheet(CORSMode aCORSMode,
net::ReferrerPolicy aReferrerPolicy,
const dom::SRIMetadata& aIntegrity)
: StyleSheetInfo(aCORSMode, aReferrerPolicy, aIntegrity)
{
MOZ_CRASH("stylo: not implemented");
}
nsIURI*
ServoStyleSheet::GetOriginalURI() const
ServoStyleSheet::~ServoStyleSheet()
{
MOZ_CRASH("stylo: not implemented");
}
nsIURI*
ServoStyleSheet::GetBaseURI() const
{
MOZ_CRASH("stylo: not implemented");
}
void
ServoStyleSheet::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI)
{
MOZ_CRASH("stylo: not implemented");
DropSheet();
}
bool
ServoStyleSheet::IsApplicable() const
{
MOZ_CRASH("stylo: not implemented");
return !mDisabled && mComplete;
}
void
ServoStyleSheet::SetComplete()
{
MOZ_CRASH("stylo: not implemented");
}
MOZ_ASSERT(!mComplete);
void
ServoStyleSheet::SetParsingMode(css::SheetParsingMode aMode)
{
MOZ_CRASH("stylo: not implemented");
mComplete = true;
NS_ERROR("stylo: ServoStyleSheet::SetComplete should do the things "
"CSSStyleSheet::SetComplete does");
}
bool
@ -61,7 +46,9 @@ ServoStyleSheet::HasRules() const
nsIDocument*
ServoStyleSheet::GetOwningDocument() const
{
MOZ_CRASH("stylo: not implemented");
NS_ERROR("stylo: GetOwningDocument not implemented, returning null");
return nullptr;
}
void
@ -70,18 +57,6 @@ ServoStyleSheet::SetOwningDocument(nsIDocument* aDocument)
MOZ_CRASH("stylo: not implemented");
}
void
ServoStyleSheet::SetOwningNode(nsINode* aOwningNode)
{
MOZ_CRASH("stylo: not implemented");
}
nsINode*
ServoStyleSheet::GetOwnerNode() const
{
MOZ_CRASH("stylo: not implemented");
}
StyleSheetHandle
ServoStyleSheet::GetParentSheet() const
{
@ -94,36 +69,6 @@ ServoStyleSheet::AppendStyleSheet(StyleSheetHandle aSheet)
MOZ_CRASH("stylo: not implemented");
}
nsIPrincipal*
ServoStyleSheet::Principal() const
{
MOZ_CRASH("stylo: not implemented");
}
void
ServoStyleSheet::SetPrincipal(nsIPrincipal* aPrincipal)
{
MOZ_CRASH("stylo: not implemented");
}
CORSMode
ServoStyleSheet::GetCORSMode() const
{
MOZ_CRASH("stylo: not implemented");
}
net::ReferrerPolicy
ServoStyleSheet::GetReferrerPolicy() const
{
MOZ_CRASH("stylo: not implemented");
}
void
ServoStyleSheet::GetIntegrity(dom::SRIMetadata& aResult) const
{
MOZ_CRASH("stylo: not implemented");
}
void
ServoStyleSheet::ParseSheet(const nsAString& aInput,
nsIURI* aSheetURI,
@ -132,7 +77,17 @@ ServoStyleSheet::ParseSheet(const nsAString& aInput,
uint32_t aLineNumber,
css::SheetParsingMode aParsingMode)
{
MOZ_CRASH("stylo: not implemented");
DropSheet();
NS_ConvertUTF16toUTF8 input(aInput);
mSheet = already_AddRefed<RawServoStyleSheet>(Servo_StylesheetFromUTF8Bytes(
reinterpret_cast<const uint8_t*>(input.get()), input.Length()));
}
void
ServoStyleSheet::DropSheet()
{
mSheet = nullptr;
}
size_t

View File

@ -7,45 +7,50 @@
#ifndef mozilla_ServoStyleSheet_h
#define mozilla_ServoStyleSheet_h
#include "mozilla/dom/SRIMetadata.h"
#include "mozilla/RefPtr.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/StyleSheetInfo.h"
#include "nsStringFwd.h"
namespace mozilla {
template<>
struct RefPtrTraits<RawServoStyleSheet>
{
static void AddRef(RawServoStyleSheet* aPtr) {
MOZ_CRASH("stylo: not implemented");
}
static void Release(RawServoStyleSheet* aPtr) {
Servo_ReleaseStylesheet(aPtr);
}
};
/**
* CSS style sheet object that is a wrapper for a Servo Stylesheet.
*/
class ServoStyleSheet
class ServoStyleSheet : public StyleSheet
, public StyleSheetInfo
{
public:
NS_INLINE_DECL_REFCOUNTING(ServoStyleSheet)
ServoStyleSheet(CORSMode aCORSMode,
net::ReferrerPolicy aReferrerPolicy,
const dom::SRIMetadata& aIntegrity);
nsIURI* GetSheetURI() const;
nsIURI* GetOriginalURI() const;
nsIURI* GetBaseURI() const;
void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
NS_INLINE_DECL_REFCOUNTING(ServoStyleSheet)
bool IsApplicable() const;
void SetComplete();
void SetParsingMode(css::SheetParsingMode aMode);
bool HasRules() const;
nsIDocument* GetOwningDocument() const;
void SetOwningDocument(nsIDocument* aDocument);
void SetOwningNode(nsINode* aOwningNode);
nsINode* GetOwnerNode() const;
StyleSheetHandle GetParentSheet() const;
void AppendStyleSheet(StyleSheetHandle aSheet);
nsIPrincipal* Principal() const;
void SetPrincipal(nsIPrincipal* aPrincipal);
CORSMode GetCORSMode() const;
net::ReferrerPolicy GetReferrerPolicy() const;
void GetIntegrity(dom::SRIMetadata& aResult) const;
void ParseSheet(const nsAString& aInput,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
@ -60,7 +65,12 @@ public:
#endif
protected:
~ServoStyleSheet() {}
~ServoStyleSheet();
private:
void DropSheet();
RefPtr<RawServoStyleSheet> mSheet;
};
} // namespace mozilla

View File

@ -33,6 +33,8 @@ public:
mParsingMode = aParsingMode;
}
nsINode* GetOwnerNode() const { return mOwningNode; }
protected:
nsINode* mOwningNode; // weak ref
css::SheetParsingMode mParsingMode;

View File

@ -35,9 +35,18 @@ public:
const dom::SRIMetadata& aIntegrity);
StyleSheetInfo(const StyleSheetInfo& aCopy);
nsIURI* GetSheetURI() const { return mSheetURI; }
nsIURI* GetOriginalURI() const { return mOriginalSheetURI; }
nsIURI* GetBaseURI() const { return mBaseURI; }
void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
nsIPrincipal* Principal() const { return mPrincipal; }
void SetPrincipal(nsIPrincipal* aPrincipal);
CORSMode GetCORSMode() const { return mCORSMode; }
net::ReferrerPolicy GetReferrerPolicy() const { return mReferrerPolicy; }
void GetIntegrity(dom::SRIMetadata& aResult) const { aResult = mIntegrity; }
protected:
nsCOMPtr<nsIURI> mSheetURI; // for error reports, etc.
nsCOMPtr<nsIURI> mOriginalSheetURI; // for GetHref. Can be null.