Bug 1250767 - Add support for hanging servo node data off Gecko nodes. r=heycam,r=bz

This commit is contained in:
Bobby Holley 2016-02-23 17:28:50 -08:00
parent a09ec4bb1c
commit a817a64b59
4 changed files with 60 additions and 8 deletions

View File

@ -20,6 +20,7 @@
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/Likely.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/css/StyleRule.h"
@ -148,6 +149,12 @@ nsINode::~nsINode()
{
MOZ_ASSERT(!HasSlots(), "nsNodeUtils::LastRelease was not called?");
MOZ_ASSERT(mSubtreeRoot == this, "Didn't restore state properly?");
#ifdef MOZ_STYLO
if (mServoNodeData) {
Servo_DropNodeData(mServoNodeData);
}
#endif
}
void*

View File

@ -51,6 +51,7 @@ class nsIURI;
class nsNodeSupportsWeakRefTearoff;
class nsNodeWeakReference;
class nsDOMMutationObserver;
struct ServoNodeData;
namespace mozilla {
class EventListenerManager;
@ -313,14 +314,17 @@ public:
#ifdef MOZILLA_INTERNAL_API
explicit nsINode(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: mNodeInfo(aNodeInfo),
mParent(nullptr),
mBoolFlags(0),
mNextSibling(nullptr),
mPreviousSibling(nullptr),
mFirstChild(nullptr),
mSubtreeRoot(this),
mSlots(nullptr)
: mNodeInfo(aNodeInfo)
, mParent(nullptr)
, mBoolFlags(0)
, mNextSibling(nullptr)
, mPreviousSibling(nullptr)
, mFirstChild(nullptr)
, mSubtreeRoot(this)
, mSlots(nullptr)
#ifdef MOZ_STYLO
, mServoNodeData(nullptr)
#endif
{
}
#endif
@ -1971,6 +1975,23 @@ public:
#undef TOUCH_EVENT
#undef EVENT
ServoNodeData* GetServoNodeData() {
#ifdef MOZ_STYLO
return mServoNodeData;
#else
MOZ_CRASH("Accessing servo node data in non-stylo build");
#endif
}
void SetServoNodeData(ServoNodeData* aData) {
#ifdef MOZ_STYLO
MOZ_ASSERT(!mServoNodeData);
mServoNodeData = aData;
#else
MOZ_CRASH("Setting servo node data in non-stylo build");
#endif
}
protected:
static bool Traverse(nsINode *tmp, nsCycleCollectionTraversalCallback &cb);
static void Unlink(nsINode *tmp);
@ -2008,6 +2029,11 @@ protected:
// Storage for more members that are usually not needed; allocated lazily.
nsSlots* mSlots;
#ifdef MOZ_STYLO
// Layout data managed by Servo.
ServoNodeData* mServoNodeData;
#endif
};
inline nsIDOMNode* GetAsDOMNode(nsINode* aNode)

View File

@ -129,3 +129,14 @@ Gecko_IsRootElement(RawGeckoElement* aElement)
return aElement->OwnerDoc()->GetRootElement() == aElement;
}
ServoNodeData*
Gecko_GetNodeData(RawGeckoNode* aNode)
{
return aNode->GetServoNodeData();
}
void
Gecko_SetNodeData(RawGeckoNode* aNode, ServoNodeData* aData)
{
aNode->SetServoNodeData(aData);
}

View File

@ -25,6 +25,7 @@ using mozilla::dom::Element;
typedef mozilla::dom::Element RawGeckoElement;
class nsIDocument;
typedef nsIDocument RawGeckoDocument;
struct ServoNodeData;
#else
struct RawGeckoNode;
typedef struct RawGeckoNode RawGeckoNode;
@ -32,6 +33,8 @@ struct RawGeckoElement;
typedef struct RawGeckoElement RawGeckoElement;
struct RawGeckoDocument;
typedef struct RawGeckoDocument RawGeckoDocument;
struct ServoNodeData;
typedef struct ServoNodeData ServoNodeData;
#endif
#ifdef __cplusplus
@ -61,6 +64,11 @@ int Gecko_IsVisitedLink(RawGeckoElement* element);
int Gecko_IsUnvisitedLink(RawGeckoElement* element);
int Gecko_IsRootElement(RawGeckoElement* element);
// Node data.
ServoNodeData* Gecko_GetNodeData(RawGeckoNode* node);
void Gecko_SetNodeData(RawGeckoNode* node, ServoNodeData* data);
void Servo_DropNodeData(ServoNodeData* data);
// Servo API.
void Servo_RestyleDocument(RawGeckoDocument* aDoc);