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
--- 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(),
--- a/servo/components/style/gecko/generated/bindings.rs
+++ b/servo/components/style/gecko/generated/bindings.rs
@@ -49,17 +49,16 @@ use gecko_bindings::structs::RawGeckoSty
use gecko_bindings::structs::RawGeckoStyleChildrenIterator;
use gecko_bindings::structs::RawGeckoServoStyleRuleList;
use gecko_bindings::structs::RawGeckoURLExtraData;
use gecko_bindings::structs::RawGeckoXBLBinding;
use gecko_bindings::structs::RawServoSelectorList;
use gecko_bindings::structs::RawServoSourceSizeList;
use gecko_bindings::structs::RefPtr;
use gecko_bindings::structs::RustString;
-use gecko_bindings::structs::CSSPseudoClassType;
use gecko_bindings::structs::CSSPseudoElementType;
use gecko_bindings::structs::ServoTraversalFlags;
use gecko_bindings::structs::ComputedTimingFunction_BeforeFlag;
use gecko_bindings::structs::CounterStylePtr;
use gecko_bindings::structs::FontFamilyType;
use gecko_bindings::structs::FontSizePrefs;
use gecko_bindings::structs::GeckoFontMetrics;
use gecko_bindings::structs::IterationCompositeOperation;
@@ -623,36 +622,36 @@ extern "C" {
}
extern "C" {
pub fn Gecko_ElementState(element: RawGeckoElementBorrowed) -> u64;
}
extern "C" {
pub fn Gecko_IsRootElement(element: RawGeckoElementBorrowed) -> bool;
}
extern "C" {
- pub fn Gecko_MatchesElement(
- type_: CSSPseudoClassType,
- element: RawGeckoElementBorrowed,
- ) -> bool;
-}
-extern "C" {
pub fn Gecko_MatchLang(
element: RawGeckoElementBorrowed,
override_lang: *mut nsAtom,
has_override_lang: bool,
value: *const u16,
) -> bool;
}
extern "C" {
pub fn Gecko_GetXMLLangValue(element: RawGeckoElementBorrowed) -> *mut nsAtom;
}
extern "C" {
pub fn Gecko_GetDocumentLWTheme(aDocument: *const nsIDocument) -> nsIDocument_DocumentTheme;
}
extern "C" {
+ pub fn Gecko_IsTableBorderNonzero(element: RawGeckoElementBorrowed) -> bool;
+}
+extern "C" {
+ pub fn Gecko_IsBrowserFrame(element: RawGeckoElementBorrowed) -> bool;
+}
+extern "C" {
pub fn Gecko_AtomAttrValue(
element: RawGeckoElementBorrowed,
attribute: *mut nsAtom,
) -> *mut nsAtom;
}
extern "C" {
pub fn Gecko_LangValue(element: RawGeckoElementBorrowed) -> *mut nsAtom;
}
--- a/servo/components/style/gecko/wrapper.rs
+++ b/servo/components/style/gecko/wrapper.rs
@@ -27,17 +27,16 @@ use font_metrics::{FontMetrics, FontMetr
use gecko::data::GeckoStyleSheet;
use gecko::global_style_data::GLOBAL_STYLE_DATA;
use gecko::selector_parser::{SelectorImpl, NonTSPseudoClass, PseudoElement};
use gecko::snapshot_helpers;
use gecko_bindings::bindings;
use gecko_bindings::bindings::{Gecko_ConstructStyleChildrenIterator, Gecko_DestroyStyleChildrenIterator};
use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentLWTheme};
use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetNextStyleChild};
-use gecko_bindings::bindings::{Gecko_IsRootElement, Gecko_MatchesElement};
use gecko_bindings::bindings::{Gecko_SetNodeFlags, Gecko_UnsetNodeFlags};
use gecko_bindings::bindings::Gecko_ClassOrClassList;
use gecko_bindings::bindings::Gecko_ElementHasAnimations;
use gecko_bindings::bindings::Gecko_ElementHasCSSAnimations;
use gecko_bindings::bindings::Gecko_ElementHasCSSTransitions;
use gecko_bindings::bindings::Gecko_GetActiveLinkAttrDeclarationBlock;
use gecko_bindings::bindings::Gecko_GetAnimationRule;
use gecko_bindings::bindings::Gecko_GetExtraContentStyleDeclarations;
@@ -1991,17 +1990,17 @@ impl<'le> ::selectors::Element for Gecko
None => return false,
};
if !parent_node.is_document() {
return false;
}
unsafe {
- Gecko_IsRootElement(self.0)
+ bindings::Gecko_IsRootElement(self.0)
}
}
fn is_empty(&self) -> bool {
!self.as_node().dom_children().any(|child| unsafe {
Gecko_IsSignificantChild(child.0, true)
})
}
@@ -2119,19 +2118,21 @@ impl<'le> ::selectors::Element for Gecko
true
}
NonTSPseudoClass::MozNativeAnonymous => {
self.is_in_native_anonymous_subtree()
}
NonTSPseudoClass::MozUseShadowTreeRoot => {
self.is_root_of_use_element_shadow_tree()
}
- NonTSPseudoClass::MozTableBorderNonzero |
+ NonTSPseudoClass::MozTableBorderNonzero => unsafe {
+ bindings::Gecko_IsTableBorderNonzero(self.0)
+ }
NonTSPseudoClass::MozBrowserFrame => unsafe {
- Gecko_MatchesElement(pseudo_class.to_gecko_pseudoclasstype().unwrap(), self.0)
+ bindings::Gecko_IsBrowserFrame(self.0)
},
NonTSPseudoClass::MozIsHTML => {
self.is_html_element_in_html_document()
}
NonTSPseudoClass::MozLWTheme => {
self.document_theme() != DocumentTheme::Doc_Theme_None
}
NonTSPseudoClass::MozLWThemeBrightText => {