tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ServoComputedData.h (4119B)


      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/. */
      6 
      7 #ifndef mozilla_ServoComputedData_h
      8 #define mozilla_ServoComputedData_h
      9 
     10 class nsWindowSizes;
     11 
     12 #include "mozilla/ServoStyleConsts.h"
     13 #include "nsStyleStructList.h"
     14 
     15 /*
     16 * ServoComputedData and its related types.
     17 */
     18 
     19 namespace mozilla {
     20 
     21 struct ServoWritingMode {
     22  uint8_t mBits;
     23 };
     24 
     25 struct ServoComputedCustomProperties {
     26  uintptr_t mInherited;
     27  uintptr_t mNonInherited;
     28 };
     29 
     30 struct ServoRuleNode {
     31  uintptr_t mPtr;
     32 };
     33 
     34 class ComputedStyle;
     35 
     36 }  // namespace mozilla
     37 
     38 #define FORWARD_STYLE_STRUCT(name_) struct nsStyle##name_;
     39 FOR_EACH_STYLE_STRUCT(FORWARD_STYLE_STRUCT, FORWARD_STYLE_STRUCT)
     40 #undef FORWARD_STYLE_STRUCT
     41 
     42 class ServoComputedData;
     43 
     44 struct ServoComputedDataForgotten {
     45  // Make sure you manually mem::forget the backing ServoComputedData
     46  // after calling this
     47  explicit ServoComputedDataForgotten(const ServoComputedData* aValue)
     48      : mPtr(aValue) {}
     49  const ServoComputedData* mPtr;
     50 };
     51 
     52 /**
     53 * We want C++ to be able to read the style struct fields of ComputedValues
     54 * so we define this type on the C++ side and use the bindgenned version
     55 * on the Rust side.
     56 */
     57 class ServoComputedData {
     58  friend class mozilla::ComputedStyle;
     59 
     60 public:
     61  // Constructs via memcpy.  Will not move out of aValue.
     62  explicit ServoComputedData(const ServoComputedDataForgotten aValue);
     63 
     64 #define SERVO_STYLE_STRUCT_ACCESSOR(name_)                        \
     65  const nsStyle##name_* name_;                                    \
     66  const nsStyle##name_* Style##name_() const MOZ_NONNULL_RETURN { \
     67    return name_;                                                 \
     68  }
     69  FOR_EACH_STYLE_STRUCT(SERVO_STYLE_STRUCT_ACCESSOR,
     70                        SERVO_STYLE_STRUCT_ACCESSOR)
     71 #undef SERVO_STYLE_STRUCT_ACCESSOR
     72 
     73  void AddSizeOfExcludingThis(nsWindowSizes& aSizes) const;
     74 
     75  mozilla::ServoWritingMode WritingMode() const { return writing_mode; }
     76 
     77 private:
     78  mozilla::ServoComputedCustomProperties custom_properties;
     79  /// The rule node representing the ordered list of rules matched for this
     80  /// node.  Can be None for default values and text nodes.  This is
     81  /// essentially an optimization to avoid referencing the root rule node.
     82  mozilla::ServoRuleNode rules;
     83  /// The element's computed values if visited, only computed if there's a
     84  /// relevant link for this element. A element's "relevant link" is the
     85  /// element being matched if it is a link or the nearest ancestor link.
     86  const mozilla::ComputedStyle* visited_style;
     87  /// The computed writing-mode of the element.
     88  mozilla::ServoWritingMode writing_mode;
     89  /// The effective zoom (as in, the CSS zoom property) of this style.
     90  ///
     91  /// zoom is a non-inherited property, yet changes to it propagate through in
     92  /// an inherited fashion, and all length resolution code need to access it.
     93  /// This could, in theory, be stored in any other inherited struct, but it's
     94  /// weird to have an inherited struct field depend on a non inherited
     95  /// property.
     96  ///
     97  /// So the style object itself is probably a reasonable place to store it.
     98  mozilla::StyleZoom effective_zoom;
     99  /// Various flags that affect our style.
    100  mozilla::StyleComputedValueFlags flags;
    101 
    102  // C++ just sees this struct as a bucket of bits, and will
    103  // do the wrong thing if we let it use the default copy ctor/assignment
    104  // operator. Remove them so that there is no footgun.
    105  //
    106  // We remove the move ctor/assignment operator as well, because
    107  // moves in C++ don't prevent destructors from being called,
    108  // which will lead to double frees.
    109  ServoComputedData& operator=(const ServoComputedData&) = delete;
    110  ServoComputedData(const ServoComputedData&) = delete;
    111  ServoComputedData&& operator=(const ServoComputedData&&) = delete;
    112  ServoComputedData(const ServoComputedData&&) = delete;
    113 };
    114 
    115 #endif  // mozilla_ServoComputedData_h