Bug 1448759 part 1 - Make KTableEntry an independent type. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Sun, 29 Apr 2018 21:17:26 +1000
changeset 789579 8c60f7d1a236205a44c5d5493a52230413d4392c
parent 789561 becbab46724a2d703373c273c83ad47981be0e09
child 789580 da7d1361f009c41feb06c6f025007c91c59a8e0c
push id108289
push userxquan@mozilla.com
push dateSun, 29 Apr 2018 23:15:53 +0000
reviewersheycam
bugs1448759
milestone61.0a1
Bug 1448759 part 1 - Make KTableEntry an independent type. r?heycam MozReview-Commit-ID: oZfJAigThN
editor/libeditor/CSSEditUtils.cpp
layout/style/ServoBindings.toml
layout/style/nsCSSProps.h
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
layout/style/nsMediaFeatures.cpp
layout/style/nsMediaFeatures.h
servo/components/style/gecko/media_queries.rs
--- a/editor/libeditor/CSSEditUtils.cpp
+++ b/editor/libeditor/CSSEditUtils.cpp
@@ -9,16 +9,17 @@
 #include "mozilla/ChangeStyleTransaction.h"
 #include "mozilla/HTMLEditor.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/DeclarationBlockInlines.h"
 #include "mozilla/dom/Element.h"
 #include "mozilla/mozalloc.h"
 #include "nsAString.h"
 #include "nsCOMPtr.h"
+#include "nsCSSProps.h"
 #include "nsColor.h"
 #include "nsComputedDOMStyle.h"
 #include "nsDebug.h"
 #include "nsDependentSubstring.h"
 #include "nsError.h"
 #include "nsGkAtoms.h"
 #include "nsAtom.h"
 #include "nsIContent.h"
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -72,16 +72,17 @@ headers = [
     "mozilla/dom/NameSpaceConstants.h",
     "mozilla/LookAndFeel.h",
     "mozilla/StaticPrefs.h",
     "mozilla/ServoBindings.h",
     "mozilla/ComputedStyle.h",
     "mozilla/ServoDeclarationBlock.h",
     "mozilla/ServoTraversalStatistics.h",
     "mozilla/SizeOfState.h",
+    "nsCSSProps.h",
     "nsContentUtils.h",
     "nsNameSpaceManager.h",
     "nsMediaFeatures.h",
     "nsXBLBinding.h",
 ]
 raw-lines = [
     # FIXME(emilio): Incrementally remove these "pub use"s. Probably
     # mozilla::css and mozilla::dom are easier.
@@ -267,16 +268,17 @@ whitelist-types = [
     "Keyframe",
     "MediumFeaturesChangedResult",
     "nsAttrName",
     "nsAttrValue",
     "nscolor",
     "nsChangeHint",
     "nsCSSCounterDesc",
     "nsCSSFontDesc",
+    "nsCSSKTableEntry",
     "nsCSSKeyword",
     "nsCSSPropertyID",
     "nsCSSPropertyIDSet",
     "nsCSSProps",
     "nsCSSShadowArray",
     "nsCSSValue",
     "nsCSSValueList",
     "nsCSSValueList_heap",
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -24,50 +24,51 @@
 #include "mozilla/EnumTypeTraits.h"
 #include "mozilla/Preferences.h"
 #include "nsXULAppAPI.h"
 
 // Length of the "--" prefix on custom names (such as custom property names,
 // and, in the future, custom media query names).
 #define CSS_CUSTOM_NAME_PREFIX_LENGTH 2
 
+struct nsCSSKTableEntry
+{
+  // nsCSSKTableEntry objects can be initialized either with an int16_t value
+  // or a value of an enumeration type that can fit within an int16_t.
+
+  constexpr nsCSSKTableEntry(nsCSSKeyword aKeyword, int16_t aValue)
+    : mKeyword(aKeyword)
+    , mValue(aValue)
+  {
+  }
+
+  template<typename T,
+           typename = typename std::enable_if<std::is_enum<T>::value>::type>
+  constexpr nsCSSKTableEntry(nsCSSKeyword aKeyword, T aValue)
+    : mKeyword(aKeyword)
+    , mValue(static_cast<int16_t>(aValue))
+  {
+    static_assert(mozilla::EnumTypeFitsWithin<T, int16_t>::value,
+                  "aValue must be an enum that fits within mValue");
+  }
+
+  bool IsSentinel() const
+  {
+    return mKeyword == eCSSKeyword_UNKNOWN && mValue == -1;
+  }
+
+  nsCSSKeyword mKeyword;
+  int16_t mValue;
+};
+
 class nsCSSProps {
 public:
   typedef mozilla::CSSEnabledState EnabledState;
   typedef mozilla::CSSPropFlags Flags;
-
-  struct KTableEntry
-  {
-    // KTableEntry objects can be initialized either with an int16_t value
-    // or a value of an enumeration type that can fit within an int16_t.
-
-    constexpr KTableEntry(nsCSSKeyword aKeyword, int16_t aValue)
-      : mKeyword(aKeyword)
-      , mValue(aValue)
-    {
-    }
-
-    template<typename T,
-             typename = typename std::enable_if<std::is_enum<T>::value>::type>
-    constexpr KTableEntry(nsCSSKeyword aKeyword, T aValue)
-      : mKeyword(aKeyword)
-      , mValue(static_cast<int16_t>(aValue))
-    {
-      static_assert(mozilla::EnumTypeFitsWithin<T, int16_t>::value,
-                    "aValue must be an enum that fits within mValue");
-    }
-
-    bool IsSentinel() const
-    {
-      return mKeyword == eCSSKeyword_UNKNOWN && mValue == -1;
-    }
-
-    nsCSSKeyword mKeyword;
-    int16_t mValue;
-  };
+  typedef nsCSSKTableEntry KTableEntry;
 
   static void AddRefTable(void);
   static void ReleaseTable(void);
 
   // Looks up the property with name aProperty and returns its corresponding
   // nsCSSPropertyID value.  If aProperty is the name of a custom property,
   // then eCSSPropertyExtra_variable will be returned.
   static nsCSSPropertyID LookupProperty(const nsAString& aProperty,
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -83,17 +83,17 @@ GetROCSSValueList(bool aCommaDelimited)
   return new nsDOMCSSValueList(aCommaDelimited, true);
 }
 
 template<typename T>
 already_AddRefed<CSSValue>
 GetBackgroundList(T nsStyleImageLayers::Layer::* aMember,
                   uint32_t nsStyleImageLayers::* aCount,
                   const nsStyleImageLayers& aLayers,
-                  const nsCSSProps::KTableEntry aTable[])
+                  const nsCSSKTableEntry aTable[])
 {
   RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
 
   for (uint32_t i = 0, i_end = aLayers.*aCount; i < i_end; ++i) {
     RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
     val->SetIdent(nsCSSProps::ValueToKeywordEnum(aLayers.mLayers[i].*aMember, aTable));
     valueList->AppendCSSValue(val.forget());
   }
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -12,17 +12,16 @@
 #include "mozilla/ArenaRefPtr.h"
 #include "mozilla/ArenaRefPtrInlines.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/StyleComplexColor.h"
 #include "mozilla/UniquePtr.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 #include "nscore.h"
-#include "nsCSSProps.h"
 #include "nsDOMCSSDeclaration.h"
 #include "mozilla/ComputedStyle.h"
 #include "nsIWeakReferenceUtils.h"
 #include "mozilla/gfx/Types.h"
 #include "nsCoord.h"
 #include "nsColor.h"
 #include "nsStyleStruct.h"
 #include "mozilla/WritingModes.h"
@@ -31,16 +30,17 @@ namespace mozilla {
 namespace dom {
 class DocGroup;
 class Element;
 } // namespace dom
 struct ComputedGridTrackInfo;
 } // namespace mozilla
 
 struct ComputedStyleMap;
+struct nsCSSKTableEntry;
 class nsIFrame;
 class nsIPresShell;
 class nsDOMCSSValueList;
 struct nsMargin;
 class nsROCSSPrimitiveValue;
 class nsStyleCoord;
 class nsStyleCorners;
 struct nsStyleFilter;
@@ -49,17 +49,17 @@ struct nsStyleImage;
 class nsStyleSides;
 struct nsTimingFunction;
 
 class nsComputedDOMStyle final : public nsDOMCSSDeclaration
                                , public nsStubMutationObserver
 {
 private:
   // Convenience typedefs:
-  typedef nsCSSProps::KTableEntry KTableEntry;
+  typedef nsCSSKTableEntry KTableEntry;
   typedef mozilla::dom::CSSValue CSSValue;
   typedef mozilla::StyleGeometryBox StyleGeometryBox;
 
   already_AddRefed<CSSValue>
   GetPropertyCSSValueWithoutWarning(const nsAString& aProp,
                                     mozilla::ErrorResult& aRv);
 
 public:
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -6,16 +6,17 @@
 
 /* the features that media queries can test */
 
 #include "nsMediaFeatures.h"
 #include "nsGkAtoms.h"
 #include "nsCSSKeywords.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
+#include "nsCSSProps.h"
 #include "nsCSSValue.h"
 #ifdef XP_WIN
 #include "mozilla/LookAndFeel.h"
 #endif
 #include "nsDeviceContext.h"
 #include "nsIBaseWindow.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
@@ -28,29 +29,29 @@ using namespace mozilla;
 
 static nsTArray<RefPtr<nsAtom>>* sSystemMetrics = nullptr;
 
 #ifdef XP_WIN
 // Cached theme identifier for the moz-windows-theme media query.
 static uint8_t sWinThemeId = LookAndFeel::eWindowsTheme_Generic;
 #endif
 
-static const nsCSSProps::KTableEntry kOrientationKeywords[] = {
+static const nsCSSKTableEntry kOrientationKeywords[] = {
   { eCSSKeyword_portrait,                 StyleOrientation::Portrait },
   { eCSSKeyword_landscape,                StyleOrientation::Landscape },
   { eCSSKeyword_UNKNOWN,                  -1 }
 };
 
-static const nsCSSProps::KTableEntry kScanKeywords[] = {
+static const nsCSSKTableEntry kScanKeywords[] = {
   { eCSSKeyword_progressive,              StyleScan::Progressive },
   { eCSSKeyword_interlace,                StyleScan::Interlace },
   { eCSSKeyword_UNKNOWN,                  -1 }
 };
 
-static const nsCSSProps::KTableEntry kDisplayModeKeywords[] = {
+static const nsCSSKTableEntry kDisplayModeKeywords[] = {
   { eCSSKeyword_browser,                 StyleDisplayMode::Browser },
   { eCSSKeyword_minimal_ui,              StyleDisplayMode::MinimalUi },
   { eCSSKeyword_standalone,              StyleDisplayMode::Standalone },
   { eCSSKeyword_fullscreen,              StyleDisplayMode::Fullscreen },
   { eCSSKeyword_UNKNOWN,                 -1 }
 };
 
 #ifdef XP_WIN
--- a/layout/style/nsMediaFeatures.h
+++ b/layout/style/nsMediaFeatures.h
@@ -4,20 +4,19 @@
  * 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/. */
 
 /* the features that media queries can test */
 
 #ifndef nsMediaFeatures_h_
 #define nsMediaFeatures_h_
 
-#include "nsCSSProps.h"
-
 class nsAtom;
 class nsIDocument;
+struct nsCSSKTableEntry;
 class nsCSSValue;
 class nsStaticAtom;
 
 struct nsMediaFeature;
 typedef void (*nsMediaFeatureValueGetter)(nsIDocument* aDocument,
                                           const nsMediaFeature* aFeature,
                                           nsCSSValue& aResult);
 
@@ -66,17 +65,17 @@ struct nsMediaFeature
 
   union {
     // In static arrays, it's the first member that's initialized.  We
     // need that to be void* so we can initialize both other types.
     // This member should never be accessed by name.
     const void* mInitializer_;
     // If mValueType == eEnumerated:  const int32_t*: keyword table in
     //   the same format as the keyword tables in nsCSSProps.
-    const nsCSSProps::KTableEntry* mKeywordTable;
+    const nsCSSKTableEntry* mKeywordTable;
     // If mGetter == GetSystemMetric (which implies mValueType ==
     //   eBoolInteger): nsAtom * const *, for the system metric.
     nsAtom * const * mMetric;
   } mData;
 
   // A function that returns the current value for this feature for a
   // given presentation.  If it returns eCSSUnit_Null, the feature is
   // not present.
--- a/servo/components/style/gecko/media_queries.rs
+++ b/servo/components/style/gecko/media_queries.rs
@@ -8,17 +8,17 @@ use app_units::AU_PER_PX;
 use app_units::Au;
 use context::QuirksMode;
 use cssparser::{BasicParseErrorKind, Parser, Token, RGBA};
 use euclid::Size2D;
 use euclid::TypedScale;
 use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
 use gecko_bindings::bindings;
 use gecko_bindings::structs;
-use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSUnit, nsCSSValue};
+use gecko_bindings::structs::{nsCSSKTableEntry, nsCSSKeyword, nsCSSUnit, nsCSSValue};
 use gecko_bindings::structs::{nsMediaFeature, nsMediaFeature_RangeType};
 use gecko_bindings::structs::{nsMediaFeature_ValueType, nsPresContext};
 use gecko_bindings::structs::RawGeckoPresContextOwned;
 use media_queries::MediaType;
 use parser::{Parse, ParserContext};
 use properties::ComputedValues;
 use servo_arc::Arc;
 use std::fmt::{self, Write};
@@ -474,17 +474,17 @@ where
             }
             features = features.offset(1);
         }
     }
     None
 }
 
 unsafe fn find_in_table<F>(
-    mut current_entry: *const nsCSSProps_KTableEntry,
+    mut current_entry: *const nsCSSKTableEntry,
     mut f: F,
 ) -> Option<(nsCSSKeyword, i16)>
 where
     F: FnMut(nsCSSKeyword, i16) -> bool,
 {
     loop {
         let value = (*current_entry).mValue;
         let keyword = (*current_entry).mKeyword;
@@ -539,17 +539,17 @@ fn parse_feature_value<'i, 't>(
         },
         nsMediaFeature_ValueType::eEnumerated => {
             let location = input.current_source_location();
             let keyword = input.expect_ident()?;
             let keyword = unsafe {
                 bindings::Gecko_LookupCSSKeyword(keyword.as_bytes().as_ptr(), keyword.len() as u32)
             };
 
-            let first_table_entry: *const nsCSSProps_KTableEntry =
+            let first_table_entry: *const nsCSSKTableEntry =
                 unsafe { *feature.mData.mKeywordTable.as_ref() };
 
             let value = match unsafe { find_in_table(first_table_entry, |kw, _| kw == keyword) } {
                 Some((_kw, value)) => value,
                 None => {
                     return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
                 },
             };