Bug 1883861 - Part 1: Move visitMemoryBarrier into the common CodeGenerator file...
[gecko.git] / layout / style / ServoComputedData.h
blob9da716263bb86c7c8e9e563bba5c7d09d94fb0cb
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ServoComputedData_h
8 #define mozilla_ServoComputedData_h
10 class nsWindowSizes;
12 #include "mozilla/ServoStyleConsts.h"
15 * ServoComputedData and its related types.
18 namespace mozilla {
20 struct ServoWritingMode {
21 uint8_t mBits;
24 struct ServoComputedCustomProperties {
25 uintptr_t mInherited;
26 uintptr_t mNonInherited;
29 struct ServoRuleNode {
30 uintptr_t mPtr;
33 class ComputedStyle;
35 } // namespace mozilla
37 #define STYLE_STRUCT(name_) struct nsStyle##name_;
38 #include "nsStyleStructList.h"
39 #undef STYLE_STRUCT
41 class ServoComputedData;
43 struct ServoComputedDataForgotten {
44 // Make sure you manually mem::forget the backing ServoComputedData
45 // after calling this
46 explicit ServoComputedDataForgotten(const ServoComputedData* aValue)
47 : mPtr(aValue) {}
48 const ServoComputedData* mPtr;
51 /**
52 * We want C++ to be able to read the style struct fields of ComputedValues
53 * so we define this type on the C++ side and use the bindgenned version
54 * on the Rust side.
56 class ServoComputedData {
57 friend class mozilla::ComputedStyle;
59 public:
60 // Constructs via memcpy. Will not move out of aValue.
61 explicit ServoComputedData(const ServoComputedDataForgotten aValue);
63 #define STYLE_STRUCT(name_) \
64 const nsStyle##name_* name_; \
65 const nsStyle##name_* Style##name_() const MOZ_NONNULL_RETURN { \
66 return name_; \
68 #include "nsStyleStructList.h"
69 #undef STYLE_STRUCT
71 void AddSizeOfExcludingThis(nsWindowSizes& aSizes) const;
73 mozilla::ServoWritingMode WritingMode() const { return writing_mode; }
75 private:
76 mozilla::ServoComputedCustomProperties custom_properties;
77 mozilla::ServoWritingMode writing_mode;
78 /// The effective zoom (as in, the CSS zoom property) of this style.
79 ///
80 /// zoom is a non-inherited property, yet changes to it propagate through in
81 /// an inherited fashion, and all length resolution code need to access it.
82 /// This could, in theory, be stored in any other inherited struct, but it's
83 /// weird to have an inherited struct field depend on a non inherited
84 /// property.
85 ///
86 /// So the style object itself is probably a reasonable place to store it.
87 mozilla::StyleZoom effective_zoom;
88 mozilla::StyleComputedValueFlags flags;
89 /// The rule node representing the ordered list of rules matched for this
90 /// node. Can be None for default values and text nodes. This is
91 /// essentially an optimization to avoid referencing the root rule node.
92 mozilla::ServoRuleNode rules;
93 /// The element's computed values if visited, only computed if there's a
94 /// relevant link for this element. A element's "relevant link" is the
95 /// element being matched if it is a link or the nearest ancestor link.
96 const mozilla::ComputedStyle* visited_style;
98 // C++ just sees this struct as a bucket of bits, and will
99 // do the wrong thing if we let it use the default copy ctor/assignment
100 // operator. Remove them so that there is no footgun.
102 // We remove the move ctor/assignment operator as well, because
103 // moves in C++ don't prevent destructors from being called,
104 // which will lead to double frees.
105 ServoComputedData& operator=(const ServoComputedData&) = delete;
106 ServoComputedData(const ServoComputedData&) = delete;
107 ServoComputedData&& operator=(const ServoComputedData&&) = delete;
108 ServoComputedData(const ServoComputedData&&) = delete;
111 #endif // mozilla_ServoComputedData_h