Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Share code between Gecko and Servo for DOM APIs. #18863

Merged
merged 2 commits into from Oct 13, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

style: Share code for Element::Matches.

  • Loading branch information
emilio committed Oct 13, 2017
commit 9e6c49d47936777099bb35ef692a5622b68862c4
@@ -107,6 +107,7 @@ use style::CaseSensitivityExt;
use style::applicable_declarations::ApplicableDeclarationBlock;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::context::QuirksMode;
use style::dom_apis;
use style::element_state::*;
use style::invalidation::element::restyle_hints::RESTYLE_SELF;
use style::properties::{Importance, PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute};
@@ -2197,18 +2198,16 @@ impl ElementMethods for Element {

// https://dom.spec.whatwg.org/#dom-element-matches
fn Matches(&self, selectors: DOMString) -> Fallible<bool> {
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
Err(_) => Err(Error::Syntax),
Ok(selectors) => {
let quirks_mode = document_from_node(self).quirks_mode();
let root = DomRoot::from_ref(self);
// FIXME(bholley): Consider an nth-index cache here.
let mut ctx = MatchingContext::new(MatchingMode::Normal, None, None,
quirks_mode);
ctx.scope_element = Some(root.opaque());
Ok(matches_selector_list(&selectors, &root, &mut ctx))
}
}
let selectors =
match SelectorParser::parse_author_origin_no_namespace(&selectors) {
Err(_) => return Err(Error::Syntax),
Ok(selectors) => selectors,
};

let quirks_mode = document_from_node(self).quirks_mode();
let element = DomRoot::from_ref(self);

Ok(dom_apis::element_matches(&element, &selectors, quirks_mode))
}

// https://dom.spec.whatwg.org/#dom-element-webkitmatchesselector
@@ -0,0 +1,29 @@
/* 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/. */

//! Generic implementations of some DOM APIs so they can be shared between Servo
//! and Gecko.

use context::QuirksMode;
use selectors::{Element, SelectorList};
use selectors::matching::{self, MatchingContext, MatchingMode};

/// https://dom.spec.whatwg.org/#dom-element-matches
pub fn element_matches<E>(
element: &E,
selector_list: &SelectorList<E::Impl>,
quirks_mode: QuirksMode,
) -> bool
where
E: Element,
{
let mut context = MatchingContext::new(
MatchingMode::Normal,
None,
None,
quirks_mode,
);
context.scope_element = Some(element.opaque());
matching::matches_selector_list(selector_list, element, &mut context)
}
@@ -107,6 +107,7 @@ pub mod counter_style;
pub mod custom_properties;
pub mod data;
pub mod dom;
pub mod dom_apis;
pub mod driver;
pub mod element_state;
#[cfg(feature = "servo")] mod encoding_support;
@@ -1556,18 +1556,15 @@ pub unsafe extern "C" fn Servo_SelectorList_Matches(
selectors: RawServoSelectorListBorrowed,
) -> bool {
use std::borrow::Borrow;
use style::dom_apis;

let element = GeckoElement(element);
let mut context = MatchingContext::new(
MatchingMode::Normal,
None,
None,
element.owner_document_quirks_mode(),
);
context.scope_element = Some(element.opaque());

let selectors = ::selectors::SelectorList::from_ffi(selectors).borrow();
selectors::matching::matches_selector_list(&selectors, &element, &mut context)
dom_apis::element_matches(
&element,
&selectors,
element.owner_document_quirks_mode(),
)
}

#[no_mangle]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.