Bug 1540093 - Refactor some enabledness checks. r=mats

There are some common checks that could get some easy-to-use aliases.

Differential Revision: https://phabricator.services.mozilla.com/D25117

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-03-29 11:12:12 +00:00
Родитель cb2ec13acb
Коммит 3514c8548d
4 изменённых файлов: 111 добавлений и 105 удалений

Просмотреть файл

@ -17,7 +17,6 @@ use crate::parser::{Parse, ParserContext};
#[cfg(feature = "servo")]
use crate::servo::media_queries::MEDIA_FEATURES;
use crate::str::{starts_with_ignore_ascii_case, string_as_ascii_lowercase};
use crate::stylesheets::Origin;
use crate::values::computed::{self, ToComputedValue};
use crate::values::specified::{Integer, Length, Number, Resolution};
use crate::values::{serialize_atom_identifier, CSSFloat};
@ -290,7 +289,7 @@ impl MediaFeatureExpression {
let mut requirements = ParsingRequirements::empty();
if context.chrome_rules_enabled() || context.stylesheet_origin == Origin::UserAgent {
if context.in_ua_or_chrome_sheet() {
requirements.insert(ParsingRequirements::CHROME_AND_UA_ONLY);
}

Просмотреть файл

@ -146,10 +146,23 @@ impl<'a> ParserContext<'a> {
error_reporter.report_error(self.url_data, location, error)
}
/// Whether we're in a user-agent stylesheet.
#[inline]
pub fn in_ua_sheet(&self) -> bool {
self.stylesheet_origin == Origin::UserAgent
}
/// Returns whether chrome-only rules should be parsed.
#[inline]
pub fn chrome_rules_enabled(&self) -> bool {
self.url_data.is_chrome() || self.stylesheet_origin == Origin::User
}
/// Whether we're in a user-agent stylesheet or chrome rules are enabled.
#[inline]
pub fn in_ua_or_chrome_sheet(&self) -> bool {
self.in_ua_sheet() || self.chrome_rules_enabled()
}
}
/// A trait to abstract parsing of a specified value given a `ParserContext` and

Просмотреть файл

@ -223,8 +223,7 @@ impl SupportsCondition {
#[cfg(feature = "gecko")]
fn eval_moz_bool_pref(name: &CStr, cx: &ParserContext) -> bool {
use crate::gecko_bindings::bindings;
use crate::stylesheets::Origin;
if cx.stylesheet_origin != Origin::UserAgent && !cx.chrome_rules_enabled() {
if !cx.in_ua_or_chrome_sheet() {
return false;
}
unsafe { bindings::Gecko_GetBoolPrefValue(name.as_ptr()) }

Просмотреть файл

@ -21,22 +21,17 @@ use std::fmt::{self, Write};
use style_traits::{CssWriter, KeywordsCollectFn, ParseError};
use style_traits::{SpecifiedValueInfo, StyleParseErrorKind, ToCss};
fn in_ua_or_chrome_sheet(context: &ParserContext) -> bool {
use crate::stylesheets::Origin;
context.stylesheet_origin == Origin::UserAgent || context.chrome_rules_enabled()
}
#[cfg(feature = "gecko")]
fn moz_display_values_enabled(context: &ParserContext) -> bool {
use crate::gecko_bindings::structs;
in_ua_or_chrome_sheet(context) ||
context.in_ua_or_chrome_sheet() ||
unsafe { structs::StaticPrefs_sVarCache_layout_css_xul_display_values_content_enabled }
}
#[cfg(feature = "gecko")]
fn moz_box_display_values_enabled(context: &ParserContext) -> bool {
use crate::gecko_bindings::structs;
in_ua_or_chrome_sheet(context) ||
context.in_ua_or_chrome_sheet() ||
unsafe {
structs::StaticPrefs_sVarCache_layout_css_xul_box_display_values_content_enabled
}
@ -988,27 +983,27 @@ pub enum Appearance {
/// A typical dialog button.
Button,
/// Various arrows that go in buttons
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ButtonArrowDown,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ButtonArrowNext,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ButtonArrowPrevious,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ButtonArrowUp,
/// A rectangular button that contains complex content
/// like images (e.g. HTML <button> elements)
ButtonBevel,
/// The focus outline box inside of a button.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ButtonFocus,
/// The caret of a text area
Caret,
/// A dual toolbar button (e.g., a Back button with a dropdown)
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Dualbutton,
/// A groupbox.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Groupbox,
/// A inner-spin button.
InnerSpinButton,
@ -1017,17 +1012,17 @@ pub enum Appearance {
/// A listbox item.
Listitem,
/// Menu Bar background
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menubar,
/// <menu> and <menuitem> appearances
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menuitem,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Checkmenuitem,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Radiomenuitem,
/// For text on non-iconic menuitems only
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menuitemtext,
/// A dropdown list.
Menulist,
@ -1038,28 +1033,28 @@ pub enum Appearance {
/// An editable textfield with a dropdown list (a combobox).
MenulistTextfield,
/// Menu Popup background.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menupopup,
/// menu checkbox/radio appearances
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menucheckbox,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menuradio,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menuseparator,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menuarrow,
/// An image in the menu gutter, like in bookmarks or history.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Menuimage,
/// A horizontal meter bar.
#[parse(aliases = "meterbar")]
Meter,
/// The meter bar's meter indicator.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Meterchunk,
/// The "arrowed" part of the dropdown button that open up a dropdown list.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMenulistButton,
/// For HTML's <input type=number>
NumberInput,
@ -1067,7 +1062,7 @@ pub enum Appearance {
#[parse(aliases = "progressbar")]
ProgressBar,
/// The progress bar's progress indicator
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Progresschunk,
/// A vertical progress bar.
ProgressbarVertical,
@ -1077,25 +1072,25 @@ pub enum Appearance {
Radio,
/// A generic container that always repaints on state changes. This is a
/// hack to make XUL checkboxes and radio buttons work.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
CheckboxContainer,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
RadioContainer,
/// The label part of a checkbox or radio button, used for painting a focus
/// outline.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
CheckboxLabel,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
RadioLabel,
/// nsRangeFrame and its subparts
Range,
RangeThumb,
/// The resizer background area in a status bar for the resizer widget in
/// the corner of a window.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Resizerpanel,
/// The resizer itself.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Resizer,
/// A slider.
ScaleHorizontal,
@ -1109,26 +1104,26 @@ pub enum Appearance {
/// The ticks for a slider.
Scalethumbtick,
/// A scrollbar.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Scrollbar,
/// A small scrollbar.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ScrollbarSmall,
/// The scrollbar slider
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ScrollbarHorizontal,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ScrollbarVertical,
/// A scrollbar button (up/down/left/right).
/// Keep these in order (some code casts these values to `int` in order to
/// compare them against each other).
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ScrollbarbuttonUp,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ScrollbarbuttonDown,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ScrollbarbuttonLeft,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ScrollbarbuttonRight,
/// The scrollbar thumb.
ScrollbarthumbHorizontal,
@ -1137,47 +1132,47 @@ pub enum Appearance {
ScrollbartrackHorizontal,
ScrollbartrackVertical,
/// The scroll corner
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Scrollcorner,
/// A searchfield.
Searchfield,
/// A separator. Can be horizontal or vertical.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Separator,
/// A spin control (up/down control for time/date pickers).
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Spinner,
/// The up button of a spin control.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
SpinnerUpbutton,
/// The down button of a spin control.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
SpinnerDownbutton,
/// The textfield of a spin control
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
SpinnerTextfield,
/// A splitter. Can be horizontal or vertical.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Splitter,
/// A status bar in a main application window.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Statusbar,
/// A single pane of a status bar.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Statusbarpanel,
/// A single tab in a tab widget.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Tab,
/// A single pane (inside the tabpanels container).
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Tabpanel,
/// The tab panels container.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Tabpanels,
/// The tabs scroll arrows (left/right).
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
TabScrollArrowBack,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
TabScrollArrowForward,
/// A multi-line text field, e.g. HTML <textarea>.
#[parse(aliases = "textfield-multiline")]
@ -1185,119 +1180,119 @@ pub enum Appearance {
/// A single-line text field, e.g. HTML <input type=text>.
Textfield,
/// A toolbar in an application window.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Toolbar,
/// A single toolbar button (with no associated dropdown).
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Toolbarbutton,
/// The dropdown portion of a toolbar button
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
ToolbarbuttonDropdown,
/// The gripper for a toolbar.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Toolbargripper,
/// The toolbox that contains the toolbars.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Toolbox,
/// A tooltip.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Tooltip,
/// A listbox or tree widget header
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Treeheader,
/// An individual header cell
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Treeheadercell,
/// The sort arrow for a header.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Treeheadersortarrow,
/// A tree item.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Treeitem,
/// A tree widget branch line
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Treeline,
/// A tree widget twisty.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Treetwisty,
/// Open tree widget twisty.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Treetwistyopen,
/// A tree widget.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Treeview,
/// Window and dialog backgrounds.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Window,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
Dialog,
/// Vista Rebars.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWinCommunicationsToolbox,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWinMediaToolbox,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWinBrowsertabbarToolbox,
/// Vista glass.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWinGlass,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWinBorderlessGlass,
/// -moz-apperance style used in setting proper glass margins.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWinExcludeGlass,
/// Titlebar elements on the Mac.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacFullscreenButton,
/// Mac help button.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacHelpButton,
/// Windows themed window frame elements.
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowButtonBox,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowButtonBoxMaximized,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowButtonClose,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowButtonMaximize,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowButtonMinimize,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowButtonRestore,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowFrameBottom,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowFrameLeft,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowFrameRight,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowTitlebar,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozWindowTitlebarMaximized,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozGtkInfoBar,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacActiveSourceListSelection,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacDisclosureButtonClosed,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacDisclosureButtonOpen,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacSourceList,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacSourceListSelection,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacVibrancyDark,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacVibrancyLight,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacVibrantTitlebarDark,
#[parse(condition = "in_ua_or_chrome_sheet")]
#[parse(condition = "ParserContext::in_ua_or_chrome_sheet")]
MozMacVibrantTitlebarLight,
/// A non-disappearing scrollbar.