Bug 1449089 part 2 - Move matching logic of :-moz-table-border-nonzero and :-moz-browser-frame into individual binding functions. r=emilio
authorXidorn Quan <me@upsuper.org>
Wed, 28 Mar 2018 09:41:04 +1100
changeset 463836 7f17b7282ac73eaaabbc067959e547e60abcd49d
parent 463835 6545b04dfe5f7c7b237fe1f1b76a5df675795a2f
child 463837 e7b9d8cd1d2ece6c7b3e8ce37f6fab18d3435875
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1449089
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1449089 part 2 - Move matching logic of :-moz-table-border-nonzero and :-moz-browser-frame into individual binding functions. r=emilio MozReview-Commit-ID: Ic3EjtwSve0
layout/style/ServoBindings.cpp
layout/style/ServoBindings.h
layout/style/ServoBindings.toml
layout/style/ServoElementSnapshot.cpp
layout/style/nsCSSPseudoClasses.cpp
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -24,16 +24,17 @@
 #include "nsDeviceContext.h"
 #include "nsIContentInlines.h"
 #include "nsICrashReporter.h"
 #include "nsIDOMNode.h"
 #include "nsIDocumentInlines.h"
 #include "nsILoadContext.h"
 #include "nsIFrame.h"
 #include "nsIMemoryReporter.h"
+#include "nsIMozBrowserFrame.h"
 #include "nsINode.h"
 #include "nsIPresShell.h"
 #include "nsIPresShellInlines.h"
 #include "nsIPrincipal.h"
 #include "nsIURI.h"
 #include "nsFontMetrics.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsMappedAttributes.h"
@@ -295,23 +296,16 @@ Gecko_ElementState(RawGeckoElementBorrow
 }
 
 bool
 Gecko_IsRootElement(RawGeckoElementBorrowed aElement)
 {
   return aElement->OwnerDoc()->GetRootElement() == aElement;
 }
 
-bool
-Gecko_MatchesElement(CSSPseudoClassType aType,
-                     RawGeckoElementBorrowed aElement)
-{
-  return nsCSSPseudoClasses::MatchesElement(aType, aElement).value();
-}
-
 // Dirtiness tracking.
 void
 Gecko_SetNodeFlags(RawGeckoNodeBorrowed aNode, uint32_t aFlags)
 {
   const_cast<nsINode*>(aNode)->SetFlags(aFlags);
 }
 
 void
@@ -874,16 +868,35 @@ Gecko_GetXMLLangValue(RawGeckoElementBor
 }
 
 nsIDocument::DocumentTheme
 Gecko_GetDocumentLWTheme(const nsIDocument* aDocument)
 {
   return aDocument->ThreadSafeGetDocumentLWTheme();
 }
 
+bool
+Gecko_IsTableBorderNonzero(RawGeckoElementBorrowed aElement)
+{
+  if (!aElement->IsHTMLElement(nsGkAtoms::table)) {
+    return false;
+  }
+  const nsAttrValue *val = aElement->GetParsedAttr(nsGkAtoms::border);
+  return val && (val->Type() != nsAttrValue::eInteger ||
+                 val->GetIntegerValue() != 0);
+}
+
+bool
+Gecko_IsBrowserFrame(RawGeckoElementBorrowed aElement)
+{
+  nsIMozBrowserFrame* browserFrame =
+    const_cast<Element*>(aElement)->GetAsMozBrowserFrame();
+  return browserFrame && browserFrame->GetReallyIsBrowser();
+}
+
 template <typename Implementor>
 static nsAtom*
 AtomAttrValue(Implementor* aElement, nsAtom* aName)
 {
   const nsAttrValue* attr = aElement->GetParsedAttr(aName);
   return attr ? attr->GetAtomValue() : nullptr;
 }
 
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -185,22 +185,23 @@ Gecko_LoadStyleSheet(mozilla::css::Loade
                      RawGeckoURLExtraData* base_url_data,
                      const uint8_t* url_bytes,
                      uint32_t url_length,
                      RawServoMediaListStrong media_list);
 
 // Selector Matching.
 uint64_t Gecko_ElementState(RawGeckoElementBorrowed element);
 bool Gecko_IsRootElement(RawGeckoElementBorrowed element);
-bool Gecko_MatchesElement(mozilla::CSSPseudoClassType type, RawGeckoElementBorrowed element);
 bool Gecko_MatchLang(RawGeckoElementBorrowed element,
                      nsAtom* override_lang, bool has_override_lang,
                      const char16_t* value);
 nsAtom* Gecko_GetXMLLangValue(RawGeckoElementBorrowed element);
 nsIDocument::DocumentTheme Gecko_GetDocumentLWTheme(const nsIDocument* aDocument);
+bool Gecko_IsTableBorderNonzero(RawGeckoElementBorrowed element);
+bool Gecko_IsBrowserFrame(RawGeckoElementBorrowed element);
 
 // Attributes.
 #define SERVO_DECLARE_ELEMENT_ATTR_MATCHING_FUNCTIONS(prefix_, implementor_)  \
   nsAtom* prefix_##AtomAttrValue(implementor_ element, nsAtom* attribute);    \
   nsAtom* prefix_##LangValue(implementor_ element);                           \
   bool prefix_##HasAttr(implementor_ element, nsAtom* ns, nsAtom* name);      \
   bool prefix_##AttrEquals(implementor_ element, nsAtom* ns, nsAtom* name,    \
                            nsAtom* str, bool ignoreCase);                     \
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -510,17 +510,16 @@ structs-types = [
     "RawGeckoStyleChildrenIterator",
     "RawGeckoServoStyleRuleList",
     "RawGeckoURLExtraData",
     "RawGeckoXBLBinding",
     "RawServoSelectorList",
     "RawServoSourceSizeList",
     "RefPtr",
     "RustString",
-    "CSSPseudoClassType",
     "CSSPseudoElementType",
     "ServoTraversalFlags",
     "ComputedTimingFunction_BeforeFlag",
     "CounterStylePtr",
     "FontFamilyType",
     "FontSizePrefs",
     "GeckoFontMetrics",
     "IterationCompositeOperation",
--- a/layout/style/ServoElementSnapshot.cpp
+++ b/layout/style/ServoElementSnapshot.cpp
@@ -1,15 +1,16 @@
 /* -*- 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/. */
 
 #include "mozilla/ServoElementSnapshot.h"
+#include "mozilla/ServoBindings.h"
 #include "mozilla/dom/Element.h"
 #include "nsIContentInlines.h"
 #include "nsContentUtils.h"
 
 namespace mozilla {
 
 ServoElementSnapshot::ServoElementSnapshot(const Element* aElement)
   : mState(0)
@@ -31,19 +32,15 @@ void
 ServoElementSnapshot::AddOtherPseudoClassState(Element* aElement)
 {
   MOZ_ASSERT(aElement);
 
   if (HasOtherPseudoClassState()) {
     return;
   }
 
-  mIsTableBorderNonzero =
-    *nsCSSPseudoClasses::MatchesElement(CSSPseudoClassType::mozTableBorderNonzero,
-                                        aElement);
-  mIsMozBrowserFrame =
-    *nsCSSPseudoClasses::MatchesElement(CSSPseudoClassType::mozBrowserFrame,
-                                        aElement);
+  mIsTableBorderNonzero = Gecko_IsTableBorderNonzero(aElement);
+  mIsMozBrowserFrame = Gecko_IsBrowserFrame(aElement);
 
   mContains |= Flags::OtherPseudoClassState;
 }
 
 } // namespace mozilla
--- a/layout/style/nsCSSPseudoClasses.cpp
+++ b/layout/style/nsCSSPseudoClasses.cpp
@@ -289,33 +289,17 @@ nsCSSPseudoClasses::StringPseudoMatches(
     default: MOZ_ASSERT_UNREACHABLE("Called StringPseudoMatches() with unknown string-like pseudo");
   }
   return true;
 }
 
 /* static */ Maybe<bool>
 nsCSSPseudoClasses::MatchesElement(Type aType, const dom::Element* aElement)
 {
-  switch (aType) {
-    case CSSPseudoClassType::mozTableBorderNonzero: {
-      if (!aElement->IsHTMLElement(nsGkAtoms::table)) {
-        return Some(false);
-      }
-      const nsAttrValue *val = aElement->GetParsedAttr(nsGkAtoms::border);
-      return Some(val && (val->Type() != nsAttrValue::eInteger ||
-                          val->GetIntegerValue() != 0));
-    }
-    case CSSPseudoClassType::mozBrowserFrame: {
-      nsIMozBrowserFrame* browserFrame =
-        const_cast<Element*>(aElement)->GetAsMozBrowserFrame();
-      return Some(browserFrame && browserFrame->GetReallyIsBrowser());
-    }
-    default:
-      return Nothing();
-  }
+  return Nothing();
 }
 
 // The dependencies for all state dependent pseudo-classes (i.e. those declared
 // using CSS_STATE_DEPENDENT_PSEUDO_CLASS, the only one of which is :dir(...)).
 const EventStates
 nsCSSPseudoClasses::sPseudoClassStateDependences[size_t(CSSPseudoClassType::Count) + 2] = {
 #define CSS_PSEUDO_CLASS(_name, _value, _flags, _pref) \
   EventStates(),