summaryrefslogtreecommitdiffstats
path: root/servo/components/style/queries
diff options
context:
space:
mode:
Diffstat (limited to 'servo/components/style/queries')
-rw-r--r--servo/components/style/queries/condition.rs88
-rw-r--r--servo/components/style/queries/feature.rs6
-rw-r--r--servo/components/style/queries/feature_expression.rs4
3 files changed, 6 insertions, 92 deletions
diff --git a/servo/components/style/queries/condition.rs b/servo/components/style/queries/condition.rs
index e17e6abd2e..25af4cdb01 100644
--- a/servo/components/style/queries/condition.rs
+++ b/servo/components/style/queries/condition.rs
@@ -13,6 +13,7 @@ use crate::{error_reporting::ContextualParseError, parser::ParserContext};
use cssparser::{Parser, Token};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
+use selectors::kleene_value::KleeneValue;
/// A binary `and` or `or` operator.
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss, ToShmem)]
@@ -29,93 +30,6 @@ enum AllowOr {
No,
}
-/// https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_and_Priest_logics
-#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
-pub enum KleeneValue {
- /// False
- False = 0,
- /// True
- True = 1,
- /// Either true or false, but we’re not sure which yet.
- Unknown,
-}
-
-impl From<bool> for KleeneValue {
- fn from(b: bool) -> Self {
- if b {
- Self::True
- } else {
- Self::False
- }
- }
-}
-
-impl KleeneValue {
- /// Turns this Kleene value to a bool, taking the unknown value as an
- /// argument.
- pub fn to_bool(self, unknown: bool) -> bool {
- match self {
- Self::True => true,
- Self::False => false,
- Self::Unknown => unknown,
- }
- }
-}
-
-impl std::ops::Not for KleeneValue {
- type Output = Self;
-
- fn not(self) -> Self {
- match self {
- Self::True => Self::False,
- Self::False => Self::True,
- Self::Unknown => Self::Unknown,
- }
- }
-}
-
-// Implements the logical and operation.
-impl std::ops::BitAnd for KleeneValue {
- type Output = Self;
-
- fn bitand(self, other: Self) -> Self {
- if self == Self::False || other == Self::False {
- return Self::False;
- }
- if self == Self::Unknown || other == Self::Unknown {
- return Self::Unknown;
- }
- Self::True
- }
-}
-
-// Implements the logical or operation.
-impl std::ops::BitOr for KleeneValue {
- type Output = Self;
-
- fn bitor(self, other: Self) -> Self {
- if self == Self::True || other == Self::True {
- return Self::True;
- }
- if self == Self::Unknown || other == Self::Unknown {
- return Self::Unknown;
- }
- Self::False
- }
-}
-
-impl std::ops::BitOrAssign for KleeneValue {
- fn bitor_assign(&mut self, other: Self) {
- *self = *self | other;
- }
-}
-
-impl std::ops::BitAndAssign for KleeneValue {
- fn bitand_assign(&mut self, other: Self) {
- *self = *self & other;
- }
-}
-
/// Represents a condition.
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem)]
pub enum QueryCondition {
diff --git a/servo/components/style/queries/feature.rs b/servo/components/style/queries/feature.rs
index 83ff7e7522..2d4c60c362 100644
--- a/servo/components/style/queries/feature.rs
+++ b/servo/components/style/queries/feature.rs
@@ -4,7 +4,6 @@
//! Query features.
-use super::condition::KleeneValue;
use crate::parser::ParserContext;
use crate::values::computed::{self, CSSPixelLength, Ratio, Resolution};
use crate::values::AtomString;
@@ -12,6 +11,7 @@ use crate::Atom;
use cssparser::Parser;
use std::fmt;
use style_traits::ParseError;
+use selectors::kleene_value::KleeneValue;
/// A generic discriminant for an enum value.
pub type KeywordDiscriminant = u8;
@@ -87,12 +87,12 @@ macro_rules! keyword_evaluator {
fn __evaluate(
context: &$crate::values::computed::Context,
value: Option<$crate::queries::feature::KeywordDiscriminant>,
- ) -> $crate::queries::condition::KleeneValue {
+ ) -> selectors::kleene_value::KleeneValue {
// This unwrap is ok because the only discriminants that get
// back to us is the ones that `parse` produces.
let value: Option<$keyword_type> =
value.map(|kw| ::num_traits::cast::FromPrimitive::from_u8(kw).unwrap());
- $crate::queries::condition::KleeneValue::from($actual_evaluator(context, value))
+ selectors::kleene_value::KleeneValue::from($actual_evaluator(context, value))
}
$crate::queries::feature::Evaluator::Enumerated {
diff --git a/servo/components/style/queries/feature_expression.rs b/servo/components/style/queries/feature_expression.rs
index c0171c2058..3450f85cba 100644
--- a/servo/components/style/queries/feature_expression.rs
+++ b/servo/components/style/queries/feature_expression.rs
@@ -8,16 +8,16 @@
use super::feature::{Evaluator, QueryFeatureDescription};
use super::feature::{FeatureFlags, KeywordDiscriminant};
use crate::parser::{Parse, ParserContext};
-use crate::queries::condition::KleeneValue;
use crate::str::{starts_with_ignore_ascii_case, string_as_ascii_lowercase};
use crate::values::computed::{self, Ratio, ToComputedValue};
use crate::values::specified::{Integer, Length, Number, Resolution};
use crate::values::{AtomString, CSSFloat};
use crate::{Atom, Zero};
use cssparser::{Parser, Token};
-use std::cmp::{Ordering, PartialOrd};
+use std::cmp::Ordering;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
+use selectors::kleene_value::KleeneValue;
/// Whether we're parsing a media or container query feature.
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToShmem)]