Bug 1380133 - Part 1: Minor reformatting and encapsulation. r=emilio
MozReview-Commit-ID: 3hmptLbxxok
---
dom/animation/KeyframeUtils.h | 2 +-
layout/style/ServoBindings.cpp | 24 +++++++++++++++---------
layout/style/ServoStyleContext.cpp | 21 ++++++++++++---------
layout/style/ServoStyleContext.h | 33 ++++++++++++++-------------------
layout/style/ServoTypes.h | 24 ++++++++++++++----------
layout/style/nsAnimationManager.h | 7 +++----
6 files changed, 59 insertions(+), 52 deletions(-)
--- a/dom/animation/KeyframeUtils.h
+++ b/dom/animation/KeyframeUtils.h
@@ -11,17 +11,17 @@
#include "nsCSSPropertyID.h"
#include "nsTArrayForwardDeclare.h" // For nsTArray
#include "js/RootingAPI.h" // For JS::Handle
struct JSContext;
class JSObject;
class nsIDocument;
class nsStyleContext;
-struct ServoComputedValues;
+class ServoComputedValues;
struct RawServoDeclarationBlock;
namespace mozilla {
struct AnimationProperty;
enum class CSSPseudoElementType : uint8_t;
class ErrorResult;
struct Keyframe;
struct PropertyStyleAnimationValuePair;
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -204,31 +204,37 @@ Gecko_GetAnonymousContentForElement(RawG
void
Gecko_DestroyAnonymousContentList(nsTArray<nsIContent*>* aAnonContent)
{
MOZ_ASSERT(aAnonContent);
delete aAnonContent;
}
void
-Gecko_ServoStyleContext_Init(ServoStyleContext* aContext,
- const ServoStyleContext* aParentContext,
- RawGeckoPresContextBorrowed aPresContext, const ServoComputedValues* aValues,
- mozilla::CSSPseudoElementType aPseudoType, nsIAtom* aPseudoTag)
+Gecko_ServoStyleContext_Init(
+ ServoStyleContext* aContext,
+ const ServoStyleContext* aParentContext,
+ RawGeckoPresContextBorrowed aPresContext,
+ const ServoComputedValues* aValues,
+ mozilla::CSSPseudoElementType aPseudoType,
+ nsIAtom* aPseudoTag)
{
// because it is within an Arc it is unsafe for the Rust side to ever
// carry around a mutable non opaque reference to the context, so we
// cast it here.
- ServoStyleContext* parent = const_cast<ServoStyleContext*>(aParentContext);
- nsPresContext* pres = const_cast<nsPresContext*>(aPresContext);
- new (KnownNotNull, aContext) ServoStyleContext(parent, pres, aPseudoTag,
- aPseudoType, ServoComputedValuesForgotten(aValues));
+ auto parent = const_cast<ServoStyleContext*>(aParentContext);
+ auto presContext = const_cast<nsPresContext*>(aPresContext);
+ new (KnownNotNull, aContext) ServoStyleContext(
+ parent, presContext, aPseudoTag, aPseudoType,
+ ServoComputedValuesForgotten(aValues));
}
-ServoComputedValues::ServoComputedValues(const ServoComputedValuesForgotten aValue) {
+ServoComputedValues::ServoComputedValues(
+ const ServoComputedValuesForgotten aValue)
+{
PodAssign(this, aValue.mPtr);
}
const nsStyleVariables* ServoComputedValues::GetStyleVariables() const
{
return Servo_GetEmptyVariables();
}
--- a/layout/style/ServoStyleContext.cpp
+++ b/layout/style/ServoStyleContext.cpp
@@ -8,25 +8,26 @@
#include "nsStyleConsts.h"
#include "nsStyleStruct.h"
#include "nsPresContext.h"
#include "nsCSSRuleProcessor.h"
#include "mozilla/dom/HTMLBodyElement.h"
#include "mozilla/ServoBindings.h"
-using namespace mozilla;
+namespace mozilla {
-ServoStyleContext::ServoStyleContext(nsStyleContext* aParent,
- nsPresContext* aPresContext,
- nsIAtom* aPseudoTag,
- CSSPseudoElementType aPseudoType,
- ServoComputedValuesForgotten aComputedValues)
- : nsStyleContext(aParent, aPseudoTag, aPseudoType),
- mSource(aComputedValues)
+ServoStyleContext::ServoStyleContext(
+ nsStyleContext* aParent,
+ nsPresContext* aPresContext,
+ nsIAtom* aPseudoTag,
+ CSSPseudoElementType aPseudoType,
+ ServoComputedValuesForgotten aComputedValues)
+ : nsStyleContext(aParent, aPseudoTag, aPseudoType)
+ , mSource(aComputedValues)
{
mPresContext = aPresContext;
AddStyleBit(Servo_ComputedValues_GetStyleBits(&mSource));
FinishConstruction();
// No need to call ApplyStyleFixups here, since fixups are handled by Servo when
// producing the ServoComputedValues.
@@ -63,9 +64,11 @@ ServoStyleContext::UpdateWithElementStat
GetPseudoType() == CSSPseudoElementType::NotPseudo &&
mPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
nsIDocument* doc = aElementForAnimation->GetUncomposedDoc();
if (doc && doc->GetBodyElement() == aElementForAnimation) {
// Update the prescontext's body color
mPresContext->SetBodyTextColor(StyleColor()->mColor);
}
}
-}
\ No newline at end of file
+}
+
+} // namespace mozilla
--- a/layout/style/ServoStyleContext.h
+++ b/layout/style/ServoStyleContext.h
@@ -7,55 +7,50 @@
#ifndef mozilla_ServoStyleContext_h
#define mozilla_ServoStyleContext_h
#include "nsStyleContext.h"
namespace mozilla {
namespace dom {
- class Element;
-}
+class Element;
+} // namespace dom
-class ServoStyleContext final : public nsStyleContext {
+class ServoStyleContext final : public nsStyleContext
+{
public:
ServoStyleContext(nsStyleContext* aParent,
nsPresContext* aPresContext,
nsIAtom* aPseudoTag,
CSSPseudoElementType aPseudoType,
ServoComputedValuesForgotten aComputedValues);
- nsPresContext* PresContext() const {
- return mPresContext;
- }
-
- const ServoComputedValues* ComputedValues() const {
- return &mSource;
- }
+ nsPresContext* PresContext() const { return mPresContext; }
+ const ServoComputedValues* ComputedValues() const { return &mSource; }
- void AddRef() {
- Servo_StyleContext_AddRef(this);
- }
+ void AddRef() { Servo_StyleContext_AddRef(this); }
+ void Release() { Servo_StyleContext_Release(this); }
- void Release() {
- Servo_StyleContext_Release(this);
+ ServoStyleContext* GetStyleIfVisited() const
+ {
+ return ComputedValues()->visited_style.mPtr;
}
- ServoStyleContext* GetStyleIfVisited() const { return ComputedValues()->visited_style.mPtr; }
-
// Update visited state for a given element, and set the prescontext's
// body text color if applicable.
void UpdateWithElementState(dom::Element* aElement);
/**
* Makes this context match |aOther| in terms of which style structs have
* been resolved.
*/
- inline void ResolveSameStructsAs(nsPresContext* aPresContext, const ServoStyleContext* aOther);
+ inline void ResolveSameStructsAs(nsPresContext* aPresContext,
+ const ServoStyleContext* aOther);
private:
nsPresContext* mPresContext;
ServoComputedValues mSource;
};
-}
+} // namespace mozilla
#endif // mozilla_ServoStyleContext_h
--- a/layout/style/ServoTypes.h
+++ b/layout/style/ServoTypes.h
@@ -196,40 +196,49 @@ struct ServoComputedValueFlags {
#define STYLE_STRUCT(name_, checkdata_cb_) struct Gecko##name_;
#define STYLE_STRUCT_LIST_IGNORE_VARIABLES
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
} // namespace mozilla
+class ServoComputedValues;
-struct ServoComputedValues;
-struct ServoComputedValuesForgotten {
+struct ServoComputedValuesForgotten
+{
// Make sure you manually mem::forget the backing ServoComputedValues
// after calling this
explicit ServoComputedValuesForgotten(const ServoComputedValues* aValue) : mPtr(aValue) {}
const ServoComputedValues* mPtr;
};
/**
- * We want C++ to be abe to read the style struct fields of ComputedValues
+ * We want C++ to be able to read the style struct fields of ComputedValues
* so we define this type on the C++ side and use the bindgenned version
* on the Rust side.
- *
*/
-struct ServoComputedValues {
+class ServoComputedValues
+{
+ friend class mozilla::ServoStyleContext;
+
+public:
+ // Constructs via memcpy. Will not move out of aValue.
+ explicit ServoComputedValues(const ServoComputedValuesForgotten aValue);
+
#define STYLE_STRUCT(name_, checkdata_cb_) \
mozilla::ServoRawOffsetArc<mozilla::Gecko##name_> name_; \
inline const nsStyle##name_* GetStyle##name_() const;
#define STYLE_STRUCT_LIST_IGNORE_VARIABLES
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#undef STYLE_STRUCT_LIST_IGNORE_VARIABLES
const nsStyleVariables* GetStyleVariables() const;
+
+private:
mozilla::ServoCustomPropertiesMap custom_properties;
mozilla::ServoWritingMode writing_mode;
mozilla::ServoComputedValueFlags flags;
/// The rule node representing the ordered list of rules matched for this
/// node. Can be None for default values and text nodes. This is
/// essentially an optimization to avoid referencing the root rule node.
mozilla::ServoRuleNode rules;
/// The element's computed values if visited, only computed if there's a
@@ -251,16 +260,11 @@ struct ServoComputedValues {
//
// We remove the move ctor/assignment operator as well, because
// moves in C++ don't prevent destructors from being called,
// which will lead to double frees.
ServoComputedValues& operator=(const ServoComputedValues&) = delete;
ServoComputedValues(const ServoComputedValues&) = delete;
ServoComputedValues&& operator=(const ServoComputedValues&&) = delete;
ServoComputedValues(const ServoComputedValues&&) = delete;
-
- // Constructs via memcpy. Will not invalidate old struct
- explicit ServoComputedValues(const ServoComputedValuesForgotten aValue);
};
-
-
#endif // mozilla_ServoTypes_h
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -12,34 +12,33 @@
#include "mozilla/dom/Animation.h"
#include "mozilla/Keyframe.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/TimeStamp.h"
#include "nsRFPService.h"
class nsIGlobalObject;
class nsStyleContext;
+class ServoComputedValues;
struct nsStyleDisplay;
-struct ServoComputedValues;
namespace mozilla {
namespace css {
class Declaration;
} /* namespace css */
namespace dom {
class KeyframeEffectReadOnly;
class Promise;
} /* namespace dom */
+class GeckoStyleContext;
+class ServoStyleContext;
enum class CSSPseudoElementType : uint8_t;
struct NonOwningAnimationTarget;
-class GeckoStyleContext;
-class ServoStyleContext;
-
struct AnimationEventInfo {
RefPtr<dom::Element> mElement;
RefPtr<dom::Animation> mAnimation;
InternalAnimationEvent mEvent;
TimeStamp mTimeStamp;
AnimationEventInfo(dom::Element* aElement,
CSSPseudoElementType aPseudoType,