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

chore(css): update cssparser@0.27.0 #3

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
300 changes: 127 additions & 173 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ members = [

[workspace.dependencies]
smallvec = "1"
selectors = "0.21.0"
cssparser = "0.25.0"
selectors = "0.22.0"
cssparser = "0.27.0"
html5ever = "0.26"
ego-tree = "0.6.2"
lazy_static = "1.4"
2 changes: 1 addition & 1 deletion accessibility-rs/src/engine/rules/utils/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn get_unique_selector(ele: &ElementRef<'_>) -> String {
let node_name = ele.value().name();

if selector.is_empty() && ele.has_attribute("class") {
let node_selector = node_name.to_string() + &ele.local_name().to_string();
let node_selector = node_name.to_string() + &ele.value().local_name.to_string();
let only_selector = single_selector(ele, &node_selector);
if only_selector {
selector = node_selector;
Expand Down
3 changes: 2 additions & 1 deletion accessibility-rs/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use mocks::mock;

#[test]
fn _audit() {
let _ = accessibility_rs::audit(AuditConfig::new(
let report = accessibility_rs::audit(AuditConfig::new(
mock::MOCK_WEBSITE_HTML,
&mock::MOCK_CSS_RULES,
false,
"en",
));
println!("{:?}", report)
}
2 changes: 1 addition & 1 deletion accessibility-scraper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cssparser = { workspace = true }
ego-tree = { workspace = true }
html5ever = { workspace = true }
selectors = { workspace = true }
smallvec = "0.6.14"
smallvec = "1"
tendril = "0.4.3"
ahash = "0.8"
indexmap = { version = "2.0.0", optional = true }
Expand Down
88 changes: 49 additions & 39 deletions accessibility-scraper/src/element_ref/element.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
use html5ever::Namespace;
use super::ElementRef;
use crate::selector::{CssLocalName, CssString, NonTSPseudoClass, PseudoElement, Simple};
use html5ever::{LocalName, Namespace};
use selectors::{
attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint},
matching, Element, OpaqueElement,
};

use super::ElementRef;
use crate::selector::{CssLocalName, CssString, NonTSPseudoClass, PseudoElement, Simple};

/// Note: will never match against non-tree-structure pseudo-classes.
impl<'a> Element for ElementRef<'a> {
type Impl = Simple;

fn local_name(&self) -> &<Self::Impl as selectors::SelectorImpl>::BorrowedLocalName {
&self.value().local_name
#[inline]
fn is_part(&self, _name: &LocalName) -> bool {
false
}

#[inline]
fn imported_part(&self, _: &LocalName) -> Option<LocalName> {
None
}

fn namespace(&self) -> &Namespace {
&self.value().name.ns
#[inline]
fn exported_part(&self, _: &LocalName) -> Option<LocalName> {
None
}

#[inline]
fn is_same_type(&self, other: &Self) -> bool {
self.value().name == other.value().name
}

#[inline]
fn is_pseudo_element(&self) -> bool {
false
}

#[inline]
fn has_local_name(&self, name: &CssLocalName) -> bool {
self.value().name.local == *name.0
}

#[inline]
fn has_namespace(&self, namespace: &Namespace) -> bool {
&self.value().name.ns == *&namespace
}

fn opaque(&self) -> OpaqueElement {
Expand All @@ -35,22 +61,6 @@ impl<'a> Element for ElementRef<'a> {
None
}

// fn is_pseudo_element(&self) -> bool {
// false
// }

// fn is_part(&self, _name: &CssLocalName) -> bool {
// false
// }

// fn is_same_type(&self, other: &Self) -> bool {
// self.value().name == other.value().name
// }

// fn imported_part(&self, _: &CssLocalName) -> Option<CssLocalName> {
// None
// }

fn prev_sibling_element(&self) -> Option<Self> {
self.prev_siblings()
.find(|sibling| sibling.value().is_element())
Expand All @@ -63,25 +73,11 @@ impl<'a> Element for ElementRef<'a> {
.map(ElementRef::new)
}

// fn first_element_child(&self) -> Option<Self> {
// self.children()
// .find(|child| child.value().is_element())
// .map(ElementRef::new)
// }

fn is_html_element_in_html_document(&self) -> bool {
// FIXME: Is there more to this?
self.value().name.ns == ns!(html)
}

// fn has_local_name(&self, name: &CssLocalName) -> bool {
// self.value().name.local == name.0
// }

// fn has_namespace(&self, namespace: &Namespace) -> bool {
// &self.value().name.ns == namespace
// }

fn attr_matches(
&self,
ns: &NamespaceConstraint<&Namespace>,
Expand All @@ -104,7 +100,21 @@ impl<'a> Element for ElementRef<'a> {
where
F: FnMut(&Self, selectors::matching::ElementSelectorFlags),
{
match *pseudo_class {}
use self::NonTSPseudoClass::*;

match *pseudo_class {
Active | Focus | Hover | Enabled | Disabled | Checked | Indeterminate | Visited => {
false
}
AnyLink | Link => {
self.value().name.ns == ns!(html)
&& matches!(
self.value().name.local,
local_name!("a") | local_name!("area") | local_name!("link")
)
&& self.has_attribute("href")
}
}
}

fn match_pseudo_element(
Expand Down
6 changes: 6 additions & 0 deletions accessibility-scraper/src/element_ref/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ pub struct ElementRef<'a> {

impl<'a> ElementRef<'a> {
/// Create a new element reference
#[inline]
pub fn new(node: NodeRef<'a, Node>) -> Self {
ElementRef { node }
}

/// Wraps a `NodeRef` only if it references a `Node::Element`.
#[inline]
pub fn wrap(node: NodeRef<'a, Node>) -> Option<Self> {
if node.value().is_element() {
Some(ElementRef::new(node))
Expand All @@ -34,11 +36,13 @@ impl<'a> ElementRef<'a> {
}

/// Returns the `Element` referenced by `self`.
#[inline]
pub fn value(&self) -> &'a Element {
self.node.value().as_element().unwrap()
}

/// Returns an iterator over descendent elements matching a selector.
#[inline]
pub fn select<'b>(&self, selector: &'b Selector) -> Select<'a, 'b> {
let mut inner = self.traverse();
inner.next(); // Skip Edge::Open(self).
Expand Down Expand Up @@ -72,6 +76,7 @@ impl<'a> ElementRef<'a> {
}

/// Returns the value of an attribute.
#[inline]
pub fn attr(&self, attr: &str) -> Option<&str> {
self.value().attr(attr)
}
Expand All @@ -84,6 +89,7 @@ impl<'a> ElementRef<'a> {
}

/// Returns if the element has the attibute and not empty
#[inline]
pub fn has_attribute(&self, attr: &str) -> bool {
match self.attr(attr) {
Some(val) => !val.trim().is_empty(),
Expand Down
50 changes: 42 additions & 8 deletions accessibility-scraper/src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl parser::SelectorImpl for Simple {
type Identifier = CssLocalName;
type ClassName = CssLocalName;
type LocalName = CssLocalName;
type PartName = LocalName;
type NamespacePrefix = CssLocalName;
type NamespaceUrl = Namespace;
type BorrowedNamespaceUrl = Namespace;
Expand Down Expand Up @@ -145,27 +146,60 @@ impl cssparser::ToCss for CssLocalName {
}

/// Non Tree-Structural Pseudo-Class.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum NonTSPseudoClass {}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NonTSPseudoClass {
/// any link
AnyLink,
/// a link
Link,
/// a visited link
Visited,
/// a active element
Active,
/// a focused element
Focus,
/// a element that is hovered
Hover,
/// a element that has enabled checked
Enabled,
/// a element that has disabled prop
Disabled,
/// a element that has the checked property
Checked,
/// an indeterminate element
Indeterminate,
}

impl parser::NonTSPseudoClass for NonTSPseudoClass {
type Impl = Simple;

fn is_active_or_hover(&self) -> bool {
false
}

// fn is_user_action_state(&self) -> bool {
// false
// }
fn is_user_action_state(&self) -> bool {
false
}
fn has_zero_specificity(&self) -> bool {
false
}
}

impl cssparser::ToCss for NonTSPseudoClass {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
dest.write_str("")
dest.write_str(match *self {
NonTSPseudoClass::AnyLink => ":any-link",
NonTSPseudoClass::Link => ":link",
NonTSPseudoClass::Visited => ":visited",
NonTSPseudoClass::Active => ":active",
NonTSPseudoClass::Focus => ":focus",
NonTSPseudoClass::Hover => ":hover",
NonTSPseudoClass::Enabled => ":enabled",
NonTSPseudoClass::Disabled => ":disabled",
NonTSPseudoClass::Checked => ":checked",
NonTSPseudoClass::Indeterminate => ":indeterminate",
})
}
}

Expand Down
16 changes: 11 additions & 5 deletions accessibility-tree/victor/src/style/properties/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use crate::style::values::*;
use cssparser::{Color, RGBA};

type FourSidesAuto = FourSides<SpecifiedLengthOrPercentageOrAuto>;
type FourSidesAutoPercentage = FourSides<SpecifiedLengthOrPercentage>;
type FourSidesLineStyle = FourSides<LineStyle>;
type FourSidesColor = FourSides<Color>;
type FourSidesLineWidth = FourSides<SpecifiedLineWidth>;

properties! {
type Discriminant = u8;

Expand Down Expand Up @@ -61,31 +67,31 @@ properties! {
}

@shorthands {
"margin" => FourSides<SpecifiedLengthOrPercentageOrAuto> {
"margin" => FourSidesAuto {
top: margin_top,
left: margin_left,
bottom: margin_bottom,
right: margin_right,
}
"padding" => FourSides<SpecifiedLengthOrPercentage> {
"padding" => FourSidesAutoPercentage {
top: padding_top,
left: padding_left,
bottom: padding_bottom,
right: padding_right,
}
"border-style" => FourSides<LineStyle> {
"border-style" => FourSidesLineStyle {
top: border_top_style,
left: border_left_style,
bottom: border_bottom_style,
right: border_right_style,
}
"border-color" => FourSides<Color> {
"border-color" => FourSidesColor {
top: border_top_color,
left: border_left_color,
bottom: border_bottom_color,
right: border_right_color,
}
"border-width" => FourSides<SpecifiedLineWidth> {
"border-width" => FourSidesLineWidth {
top: border_top_width,
left: border_left_width,
bottom: border_bottom_width,
Expand Down
Loading