Bug 1304302 part 11 - Remove StyleSheetHandle as well as other places reference it. r=heycam

MozReview-Commit-ID: FfYZiShjJNX

--HG--
extra : source : b75ca959d5bc0128e643a58126693b4cc704e09b
This commit is contained in:
Xidorn Quan 2016-09-26 22:03:25 +10:00
parent 2f49a48a09
commit 1da4aa60e1
7 changed files with 3 additions and 452 deletions

View File

@ -19,9 +19,9 @@ namespace mozilla {
/**
* A class for holding strong references to handle-managed objects.
*
* This is intended for use with objects like StyleSheet*, where
* the handle type is not a pointer but which can still have ->AddRef()
* and ->Release() called on it.
* This is intended for use with objects like RestyleManagerHandle,
* where the handle type is not a pointer but which can still have
* ->AddRef() and ->Release() called on it.
*/
template<typename T>
class HandleRefPtr

View File

@ -11,7 +11,6 @@
#include "mozilla/dom/CSSStyleSheetBinding.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/StyleBackendType.h"
#include "mozilla/StyleSheetHandle.h"
#include "mozilla/CORSMode.h"
class nsIDocument;
@ -70,7 +69,6 @@ public:
// correct type.
inline CSSStyleSheet* AsGecko();
inline ServoStyleSheet* AsServo();
inline StyleSheetHandle AsHandle();
inline const CSSStyleSheet* AsGecko() const;
inline const ServoStyleSheet* AsServo() const;

View File

@ -1,199 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_StyleSheetHandle_h
#define mozilla_StyleSheetHandle_h
#include "mozilla/css/SheetParsingMode.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/CORSMode.h"
#include "mozilla/HandleRefPtr.h"
#include "mozilla/RefCountType.h"
namespace mozilla {
namespace dom {
class SRIMetadata;
} // namespace dom
class CSSStyleSheet;
class ServoStyleSheet;
class StyleSheet;
} // namespace mozilla
class nsIDocument;
class nsIPrincipal;
class nsIURI;
namespace mozilla {
#define SERVO_BIT 0x1
/**
* Smart pointer class that can hold a pointer to either a CSSStyleSheet
* or a ServoStyleSheet.
*/
class StyleSheetHandle
{
public:
typedef HandleRefPtr<StyleSheetHandle> RefPtr;
// We define this Ptr class with a StyleSheet API that forwards on to the
// wrapped pointer, rather than putting these methods on StyleSheetHandle
// itself, so that we can have StyleSheetHandle behave like a smart pointer
// and be dereferenced with operator->.
class Ptr
{
public:
friend class ::mozilla::StyleSheetHandle;
bool IsGecko() const { return !IsServo(); }
bool IsServo() const
{
MOZ_ASSERT(mValue);
#ifdef MOZ_STYLO
return mValue & SERVO_BIT;
#else
return false;
#endif
}
inline StyleSheet* AsStyleSheet();
inline const StyleSheet* AsStyleSheet() const;
CSSStyleSheet* AsGecko()
{
MOZ_ASSERT(IsGecko());
return reinterpret_cast<CSSStyleSheet*>(mValue);
}
ServoStyleSheet* AsServo()
{
MOZ_ASSERT(IsServo());
return reinterpret_cast<ServoStyleSheet*>(mValue & ~SERVO_BIT);
}
CSSStyleSheet* GetAsGecko() { return IsGecko() ? AsGecko() : nullptr; }
ServoStyleSheet* GetAsServo() { return IsServo() ? AsServo() : nullptr; }
const CSSStyleSheet* AsGecko() const
{
return const_cast<Ptr*>(this)->AsGecko();
}
const ServoStyleSheet* AsServo() const
{
MOZ_ASSERT(IsServo());
return const_cast<Ptr*>(this)->AsServo();
}
void* AsVoidPtr() const
{
return reinterpret_cast<void*>(mValue & ~SERVO_BIT);
}
const CSSStyleSheet* GetAsGecko() const { return IsGecko() ? AsGecko() : nullptr; }
const ServoStyleSheet* GetAsServo() const { return IsServo() ? AsServo() : nullptr; }
// These inline methods are defined in StyleSheetHandleInlines.h.
inline MozExternalRefCountType AddRef();
inline MozExternalRefCountType Release();
// Style sheet interface. These inline methods are defined in
// StyleSheetHandleInlines.h and just forward to the underlying
// CSSStyleSheet or ServoStyleSheet. See corresponding comments in
// CSSStyleSheet.h for descriptions of these methods.
inline bool IsInline() const;
inline nsIURI* GetSheetURI() const;
inline nsIURI* GetOriginalURI() const;
inline nsIURI* GetBaseURI() const;
inline void SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI);
inline bool IsApplicable() const;
inline bool HasRules() const;
inline nsIDocument* GetOwningDocument() const;
inline void SetOwningDocument(nsIDocument* aDocument);
inline nsINode* GetOwnerNode() const;
inline void SetOwningNode(nsINode* aNode);
inline StyleSheetHandle GetParentSheet() const;
inline void AppendStyleSheet(StyleSheetHandle aSheet);
inline nsIPrincipal* Principal() const;
inline void SetPrincipal(nsIPrincipal* aPrincipal);
inline CORSMode GetCORSMode() const;
inline net::ReferrerPolicy GetReferrerPolicy() const;
inline void GetIntegrity(dom::SRIMetadata& aResult) const;
inline size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
#ifdef DEBUG
inline void List(FILE* aOut = stdout, int32_t aIndex = 0) const;
#endif
private:
// Stores a pointer to an CSSStyleSheet or a ServoStyleSheet. The least
// significant bit is 0 for the former, 1 for the latter.
uintptr_t mValue;
};
MOZ_IMPLICIT StyleSheetHandle(decltype(nullptr) = nullptr)
{
mPtr.mValue = 0;
}
StyleSheetHandle(const StyleSheetHandle& aOth) {
mPtr.mValue = aOth.mPtr.mValue;
}
MOZ_IMPLICIT StyleSheetHandle(CSSStyleSheet* aSet) { *this = aSet; }
MOZ_IMPLICIT StyleSheetHandle(ServoStyleSheet* aSet) { *this = aSet; }
MOZ_IMPLICIT StyleSheetHandle(const ::RefPtr<CSSStyleSheet>& aSet)
{
*this = aSet.get();
}
MOZ_IMPLICIT StyleSheetHandle(const ::RefPtr<ServoStyleSheet>& aSet)
{
*this = aSet.get();
}
StyleSheetHandle& operator=(decltype(nullptr)) { mPtr.mValue = 0; return *this; }
StyleSheetHandle& operator=(CSSStyleSheet* aSheet)
{
MOZ_ASSERT(!(reinterpret_cast<uintptr_t>(aSheet) & SERVO_BIT),
"least significant bit shouldn't be set; we use it for state");
mPtr.mValue = reinterpret_cast<uintptr_t>(aSheet);
return *this;
}
StyleSheetHandle& operator=(ServoStyleSheet* aSheet)
{
#ifdef MOZ_STYLO
MOZ_ASSERT(!(reinterpret_cast<uintptr_t>(aSheet) & SERVO_BIT),
"least significant bit shouldn't be set; we use it for state");
mPtr.mValue =
aSheet ? (reinterpret_cast<uintptr_t>(aSheet) | SERVO_BIT) : 0;
return *this;
#else
MOZ_CRASH("should not have a ServoStyleSheet object when MOZ_STYLO is "
"disabled");
#endif
}
// Make StyleSheetHandle usable in boolean contexts.
explicit operator bool() const { return !!mPtr.mValue; }
bool operator!() const { return !mPtr.mValue; }
// Make StyleSheetHandle behave like a smart pointer.
Ptr* operator->() { return &mPtr; }
const Ptr* operator->() const { return &mPtr; }
bool operator==(const StyleSheetHandle& aOther) const
{
return mPtr.mValue == aOther.mPtr.mValue;
}
private:
Ptr mPtr;
};
#undef SERVO_BIT
} // namespace mozilla
#endif // mozilla_StyleSheetHandle_h

View File

@ -1,214 +0,0 @@
/* -*- 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/. */
#ifndef mozilla_StyleSheetHandleInlines_h
#define mozilla_StyleSheetHandleInlines_h
#include "mozilla/CSSStyleSheet.h"
#include "mozilla/ServoStyleSheet.h"
#define FORWARD_CONCRETE(method_, geckoargs_, servoargs_) \
if (IsGecko()) { \
return AsGecko()->method_ geckoargs_; \
} else { \
return AsServo()->method_ servoargs_; \
}
#define FORWARD(method_, args_) FORWARD_CONCRETE(method_, args_, args_)
namespace mozilla {
StyleSheet*
StyleSheetHandle::Ptr::AsStyleSheet()
{
if (IsServo()) {
return AsServo();
}
return AsGecko();
}
const StyleSheet*
StyleSheetHandle::Ptr::AsStyleSheet() const
{
return const_cast<Ptr*>(this)->AsStyleSheet();
}
MozExternalRefCountType
StyleSheetHandle::Ptr::AddRef()
{
FORWARD(AddRef, ());
}
MozExternalRefCountType
StyleSheetHandle::Ptr::Release()
{
FORWARD(Release, ());
}
bool
StyleSheetHandle::Ptr::IsInline() const
{
FORWARD(IsInline, ());
}
nsIURI*
StyleSheetHandle::Ptr::GetSheetURI() const
{
FORWARD(GetSheetURI, ());
}
nsIURI*
StyleSheetHandle::Ptr::GetOriginalURI() const
{
FORWARD(GetOriginalURI, ());
}
nsIURI*
StyleSheetHandle::Ptr::GetBaseURI() const
{
FORWARD(GetBaseURI, ());
}
void
StyleSheetHandle::Ptr::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI, nsIURI* aBaseURI)
{
FORWARD(SetURIs, (aSheetURI, aOriginalSheetURI, aBaseURI));
}
bool
StyleSheetHandle::Ptr::IsApplicable() const
{
FORWARD(IsApplicable, ());
}
bool
StyleSheetHandle::Ptr::HasRules() const
{
FORWARD(HasRules, ());
}
nsIDocument*
StyleSheetHandle::Ptr::GetOwningDocument() const
{
FORWARD(GetOwningDocument, ());
}
void
StyleSheetHandle::Ptr::SetOwningDocument(nsIDocument* aDocument)
{
FORWARD(SetOwningDocument, (aDocument));
}
nsINode*
StyleSheetHandle::Ptr::GetOwnerNode() const
{
FORWARD(GetOwnerNode, ());
}
void
StyleSheetHandle::Ptr::SetOwningNode(nsINode* aNode)
{
FORWARD(SetOwningNode, (aNode));
}
StyleSheetHandle
StyleSheetHandle::Ptr::GetParentSheet() const
{
FORWARD(GetParentSheet, ());
}
void
StyleSheetHandle::Ptr::AppendStyleSheet(StyleSheetHandle aSheet)
{
FORWARD_CONCRETE(AppendStyleSheet, (aSheet->AsGecko()), (aSheet->AsServo()));
}
nsIPrincipal*
StyleSheetHandle::Ptr::Principal() const
{
FORWARD(Principal, ());
}
void
StyleSheetHandle::Ptr::SetPrincipal(nsIPrincipal* aPrincipal)
{
FORWARD(SetPrincipal, (aPrincipal));
}
mozilla::CORSMode
StyleSheetHandle::Ptr::GetCORSMode() const
{
FORWARD(GetCORSMode, ());
}
mozilla::net::ReferrerPolicy
StyleSheetHandle::Ptr::GetReferrerPolicy() const
{
FORWARD(GetReferrerPolicy, ());
}
void
StyleSheetHandle::Ptr::GetIntegrity(dom::SRIMetadata& aResult) const
{
FORWARD(GetIntegrity, (aResult));
}
size_t
StyleSheetHandle::Ptr::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
{
FORWARD(SizeOfIncludingThis, (aMallocSizeOf));
}
#ifdef DEBUG
void
StyleSheetHandle::Ptr::List(FILE* aOut, int32_t aIndex) const
{
FORWARD(List, (aOut, aIndex));
}
#endif
#undef FORWARD
#undef FORWARD_CONCRETE
inline void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
StyleSheetHandle& aField,
const char* aName,
uint32_t aFlags = 0)
{
if (aField && aField->IsGecko()) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCallback, aName);
aCallback.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, aField->AsGecko()));
}
}
inline void
ImplCycleCollectionUnlink(StyleSheetHandle& aField)
{
aField = nullptr;
}
inline void
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
StyleSheetHandle::RefPtr& aField,
const char* aName,
uint32_t aFlags = 0)
{
if (aField && aField->IsGecko()) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(aCallback, aName);
aCallback.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMCSSStyleSheet*, aField->AsGecko()));
}
}
inline void
ImplCycleCollectionUnlink(StyleSheetHandle::RefPtr& aField)
{
aField = nullptr;
}
} // namespace mozilla
#endif // mozilla_StyleSheetHandleInlines_h

View File

@ -28,15 +28,6 @@ StyleSheet::AsServo()
return static_cast<ServoStyleSheet*>(this);
}
StyleSheetHandle
StyleSheet::AsHandle()
{
if (IsServo()) {
return AsServo();
}
return AsGecko();
}
const CSSStyleSheet*
StyleSheet::AsGecko() const
{

View File

@ -106,8 +106,6 @@ EXPORTS.mozilla += [
'StyleSetHandle.h',
'StyleSetHandleInlines.h',
'StyleSheet.h',
'StyleSheetHandle.h',
'StyleSheetHandleInlines.h',
'StyleSheetInfo.h',
'StyleSheetInlines.h',
'StyleStructContext.h',

View File

@ -40,26 +40,3 @@ class smartptr_printer(object):
type_name = str(self.value.dereference().dynamic_type.pointer())
return '[(%s) %s]' % (type_name, str(self.value))
@GeckoPrettyPrinter('mozilla::StyleSheetHandle::RefPtr', '^mozilla::HandleRefPtr<mozilla::StyleSheetHandle>$')
class sheetptr_printer(object):
def __init__(self, value):
self.value = 0
if (value['mHandle'] and
value['mHandle']['mPtr'] and
value['mHandle']['mPtr']['mValue']):
self.value = int(value['mHandle']['mPtr']['mValue'])
def to_string(self):
if self.value == 0:
type_name = 'mozilla::StyleSheet *'
value = 0
else:
value = int(self.value)
if value & 0x1:
value = value & ~0x1
type_name = 'mozilla::ServoStyleSheet *'
else:
type_name = 'mozilla::CSSStyleSheet *'
return '[(%s) %s]' % (type_name, hex(value))