Bug 1461933 - Remove ServoBindings.h from ComputedStyleInline.h. r=emilio

For doing this, ServoComputedData is split into separate files, so that
files don't need to include ServoBindings.h just for accessing style
structs from ComputedStyles.

MozReview-Commit-ID: DPAd7PUUCl9

--HG--
extra : rebase_source : 7d6f739b7fb58a46e1624ba62e717412057ea9c1
This commit is contained in:
Xidorn Quan 2018-05-16 15:35:59 +10:00
parent d9091cf557
commit 5896b33074
16 changed files with 159 additions and 116 deletions

View File

@ -108,6 +108,7 @@
#include "mozilla/css/ImageLoader.h"
#include "mozilla/layers/IAPZCTreeManager.h" // for layers::ZoomToRectBehavior
#include "mozilla/dom/Promise.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/gfx/GPUProcessManager.h"
#include "mozilla/dom/TimeoutManager.h"

View File

@ -16,6 +16,7 @@
#include "nsLayoutCID.h"
#include "mozilla/dom/URL.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoStyleRuleMap.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"

View File

@ -177,6 +177,7 @@
#include "nsLayoutStylesheetCache.h"
#include "mozilla/layers/InputAPZContext.h"
#include "mozilla/layers/FocusTarget.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/StyleSheetInlines.h"

View File

@ -13,6 +13,7 @@
#include "brotli/decode.h"
#include "zlib.h"
#include "mozilla/dom/FontFaceSet.h"
#include "mozilla/ServoBindings.h"
#include "mozilla/ServoFontFaceRule.h"
#include "mozilla/Unused.h"

View File

@ -35,6 +35,7 @@
#include "LayerState.h"
#include "FrameMetrics.h"
#include "ImgDrawResult.h"
#include "mozilla/EffectCompositor.h"
#include "mozilla/EnumeratedArray.h"
#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"

View File

@ -11,6 +11,7 @@
#include "nsCRT.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/ComputedStyleInlines.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/CustomEvent.h"
#include "mozilla/dom/ScriptSettings.h"

View File

@ -13,6 +13,7 @@
#include <algorithm>
#include "mozilla/ArenaObjectID.h"
#include "mozilla/Assertions.h"
#include "mozilla/ServoComputedData.h"
#include "mozilla/ServoTypes.h"
#include "mozilla/ServoUtils.h"
#include "mozilla/StyleComplexColor.h"

View File

@ -15,9 +15,8 @@
#define ComputedStyleInlines_h
#include "mozilla/ComputedStyle.h"
#include "mozilla/ComputedStyle.h"
#include "mozilla/ServoComputedDataInlines.h"
#include "mozilla/ServoUtils.h"
#include "mozilla/ServoBindings.h"
namespace mozilla {
@ -28,7 +27,7 @@ ComputedStyle::Style##name_() { \
} \
const nsStyle##name_ * \
ComputedStyle::ThreadsafeStyle##name_() { \
if (mozilla::ServoStyleSet::IsInServoTraversal()) { \
if (mozilla::IsInServoTraversal()) { \
return ComputedData()->GetStyle##name_(); \
} \
return Style##name_(); \
@ -53,7 +52,7 @@ const nsStyle##name_ * ComputedStyle::DoGetStyle##name_() { \
/* perform any remaining main thread work on the struct */ \
if (needToCompute) { \
MOZ_ASSERT(NS_IsMainThread()); \
MOZ_ASSERT(!mozilla::ServoStyleSet::IsInServoTraversal()); \
MOZ_ASSERT(!mozilla::IsInServoTraversal()); \
const_cast<nsStyle##name_*>(data)->FinishStyle(mPresContext, nullptr); \
/* the ComputedStyle owns the struct */ \
AddStyleBit(NS_STYLE_INHERIT_BIT(name_)); \

View File

@ -8,6 +8,7 @@
#define mozilla_ServoBindingTypes_h
#include "mozilla/RefPtr.h"
#include "mozilla/ServoComputedData.h"
#include "mozilla/ServoTypes.h"
#include "mozilla/SheetType.h"
#include "mozilla/UniquePtr.h"

View File

@ -12,6 +12,7 @@
#include "mozilla/AtomArray.h"
#include "mozilla/ServoTypes.h"
#include "mozilla/ServoBindingTypes.h"
#include "mozilla/ServoComputedDataInlines.h"
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/css/SheetLoadData.h"
#include "mozilla/css/SheetParsingMode.h"
@ -20,7 +21,6 @@
#include "mozilla/ComputedTimingFunction.h"
#include "nsChangeHint.h"
#include "nsIDocument.h"
#include "nsStyleStruct.h"
/*
* API for Servo to access Gecko data structures.
@ -78,17 +78,6 @@ const bool GECKO_IS_NIGHTLY = true;
const bool GECKO_IS_NIGHTLY = false;
#endif
namespace mozilla {
#define STYLE_STRUCT(name_) struct Gecko##name_ {nsStyle##name_ gecko;};
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
}
#define STYLE_STRUCT(name_) \
const nsStyle##name_* ServoComputedData::GetStyle##name_() const { return &name_.mPtr->gecko; }
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#define NS_DECL_THREADSAFE_FFI_REFCOUNTING(class_, name_) \
void Gecko_AddRef##name_##ArbitraryThread(class_* aPtr); \
void Gecko_Release##name_##ArbitraryThread(class_* aPtr);

View File

@ -0,0 +1,111 @@
/* -*- 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_ServoComputedData_h
#define mozilla_ServoComputedData_h
#include "mozilla/ServoTypes.h"
/*
* ServoComputedData and its related types.
*/
#define STYLE_STRUCT(name_) struct nsStyle##name_;
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
namespace mozilla {
struct ServoWritingMode {
uint8_t mBits;
};
struct ServoCustomPropertiesMap {
uintptr_t mPtr;
};
struct ServoRuleNode {
uintptr_t mPtr;
};
class ComputedStyle;
struct ServoVisitedStyle {
// This is actually a strong reference
// but ServoComputedData's destructor is
// managed by the Rust code so we just use a
// regular pointer
ComputedStyle* mPtr;
};
struct ServoComputedValueFlags {
uint16_t mFlags;
};
#define STYLE_STRUCT(name_) struct Gecko##name_;
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
} // namespace mozilla
class ServoComputedData;
struct ServoComputedDataForgotten
{
// Make sure you manually mem::forget the backing ServoComputedData
// after calling this
explicit ServoComputedDataForgotten(const ServoComputedData* aValue) : mPtr(aValue) {}
const ServoComputedData* mPtr;
};
/**
* 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.
*/
class ServoComputedData
{
friend class mozilla::ComputedStyle;
public:
// Constructs via memcpy. Will not move out of aValue.
explicit ServoComputedData(const ServoComputedDataForgotten aValue);
#define STYLE_STRUCT(name_) \
mozilla::ServoRawOffsetArc<mozilla::Gecko##name_> name_; \
inline const nsStyle##name_* GetStyle##name_() const;
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
void AddSizeOfExcludingThis(nsWindowSizes& aSizes) 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
/// relevant link for this element. A element's "relevant link" is the
/// element being matched if it is a link or the nearest ancestor link.
mozilla::ServoVisitedStyle visited_style;
// C++ just sees this struct as a bucket of bits, and will
// do the wrong thing if we let it use the default copy ctor/assignment
// operator. Remove them so that there is no footgun.
//
// 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.
ServoComputedData& operator=(const ServoComputedData&) = delete;
ServoComputedData(const ServoComputedData&) = delete;
ServoComputedData&& operator=(const ServoComputedData&&) = delete;
ServoComputedData(const ServoComputedData&&) = delete;
};
#endif // mozilla_ServoComputedData_h

View File

@ -0,0 +1,24 @@
/* -*- 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_ServoComputedDataInlines_h
#define mozilla_ServoComputedDataInlines_h
#include "mozilla/ServoComputedData.h"
#include "nsStyleStruct.h"
namespace mozilla {
#define STYLE_STRUCT(name_) struct Gecko##name_ {nsStyle##name_ gecko;};
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
}
#define STYLE_STRUCT(name_) \
const nsStyle##name_* ServoComputedData::GetStyle##name_() const { return &name_.mPtr->gecko; }
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
#endif // mozilla_ServoComputedDataInlines_h

View File

@ -9,10 +9,6 @@
#include "mozilla/TypedEnumBits.h"
#define STYLE_STRUCT(name_) struct nsStyle##name_;
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
/*
* Type definitions used to interact with Servo. This gets included by nsINode,
* so don't add significant include dependencies to this file.
@ -129,44 +125,6 @@ enum class InheritTarget {
PlaceholderFrame,
};
struct ServoWritingMode {
uint8_t mBits;
};
struct ServoCustomPropertiesMap {
uintptr_t mPtr;
};
struct ServoRuleNode {
uintptr_t mPtr;
};
class ComputedStyle;
struct ServoVisitedStyle {
// This is actually a strong reference
// but ServoComputedData's destructor is
// managed by the Rust code so we just use a
// regular pointer
ComputedStyle* mPtr;
};
template <typename T>
struct ServoRawOffsetArc {
// Again, a strong reference, but
// managed by the Rust code
T* mPtr;
};
struct ServoComputedValueFlags {
uint16_t mFlags;
};
#define STYLE_STRUCT(name_) struct Gecko##name_;
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
// These measurements are obtained for both the UA cache and the Stylist, but
// not all the fields are used in both cases.
class ServoStyleSetSizes
@ -189,63 +147,13 @@ public:
{}
};
template <typename T>
struct ServoRawOffsetArc {
// Again, a strong reference, but
// managed by the Rust code
T* mPtr;
};
} // namespace mozilla
class ServoComputedData;
struct ServoComputedDataForgotten
{
// Make sure you manually mem::forget the backing ServoComputedData
// after calling this
explicit ServoComputedDataForgotten(const ServoComputedData* aValue) : mPtr(aValue) {}
const ServoComputedData* mPtr;
};
/**
* 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.
*/
class ServoComputedData
{
friend class mozilla::ComputedStyle;
public:
// Constructs via memcpy. Will not move out of aValue.
explicit ServoComputedData(const ServoComputedDataForgotten aValue);
#define STYLE_STRUCT(name_) \
mozilla::ServoRawOffsetArc<mozilla::Gecko##name_> name_; \
inline const nsStyle##name_* GetStyle##name_() const;
#include "nsStyleStructList.h"
#undef STYLE_STRUCT
void AddSizeOfExcludingThis(nsWindowSizes& aSizes) 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
/// relevant link for this element. A element's "relevant link" is the
/// element being matched if it is a link or the nearest ancestor link.
mozilla::ServoVisitedStyle visited_style;
// C++ just sees this struct as a bucket of bits, and will
// do the wrong thing if we let it use the default copy ctor/assignment
// operator. Remove them so that there is no footgun.
//
// 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.
ServoComputedData& operator=(const ServoComputedData&) = delete;
ServoComputedData(const ServoComputedData&) = delete;
ServoComputedData&& operator=(const ServoComputedData&&) = delete;
ServoComputedData(const ServoComputedData&&) = delete;
};
#endif // mozilla_ServoTypes_h

View File

@ -81,6 +81,8 @@ EXPORTS.mozilla += [
'ServoBindingList.h',
'ServoBindings.h',
'ServoBindingTypes.h',
'ServoComputedData.h',
'ServoComputedDataInlines.h',
'ServoCounterStyleRule.h',
'ServoCSSParser.h',
'ServoCSSRuleList.h',

View File

@ -43,6 +43,7 @@ class nsIURI;
class nsTextFrame;
class imgIContainer;
class nsPresContext;
struct nsStyleDisplay;
struct nsStyleVisibility;
namespace mozilla {
class ComputedStyle;

View File

@ -10,6 +10,7 @@
#include <time.h>
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/Element.h"
#include "mozilla/Logging.h"
#include "mozilla/Mutex.h"
#include "mozilla/Preferences.h"
@ -982,7 +983,7 @@ nsRFPService::GetSpoofedKeyCodeInfo(const nsIDocument* aDoc,
// If the content-langauge is not given, we try to get langauge from the HTML
// lang attribute.
if (language.IsEmpty()) {
Element* elm = aDoc->GetHtmlElement();
dom::Element* elm = aDoc->GetHtmlElement();
if (elm) {
elm->GetLang(language);