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
Use more generics and remove more code from mako files #17186
Merged
+159
−164
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Use generics for scroll-snap-points-*
- Loading branch information
commit 195e98e74579b8a8fd65e6ac0708d615aaceadf5
| @@ -0,0 +1,11 @@ | ||
| /* 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/. */ | ||
|
|
||
| //! Computed types for legacy Gecko-only properties. | ||
|
|
||
| use values::computed::length::LengthOrPercentage; | ||
| use values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint; | ||
|
|
||
| /// A computed type for scroll snap points. | ||
| pub type ScrollSnapPoint = GenericScrollSnapPoint<LengthOrPercentage>; |
| @@ -0,0 +1,54 @@ | ||
| /* 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 types for legacy Gecko-only properties that should probably be | ||
| //! unshipped at some point in the future. | ||
|
|
||
| use std::fmt; | ||
| use style_traits::ToCss; | ||
|
|
||
| /// A generic value for scroll snap points. | ||
| #[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)] | ||
| pub enum ScrollSnapPoint<LengthOrPercentage> { | ||
|
||
| /// `none` | ||
| None, | ||
| /// `repeat(<length-or-percentage>)` | ||
| Repeat(LengthOrPercentage) | ||
| } | ||
|
|
||
| impl<L> ScrollSnapPoint<L> { | ||
| /// Returns `none`. | ||
| #[inline] | ||
| pub fn none() -> Self { | ||
| ScrollSnapPoint::None | ||
| } | ||
|
|
||
| /// Returns the repeat argument, if any. | ||
| #[inline] | ||
| pub fn repeated(&self) -> Option<&L> { | ||
| match *self { | ||
| ScrollSnapPoint::None => None, | ||
| ScrollSnapPoint::Repeat(ref length) => Some(length), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<L> ToCss for ScrollSnapPoint<L> | ||
| where | ||
| L: ToCss, | ||
| { | ||
| fn to_css<W>(&self, dest: &mut W) -> fmt::Result | ||
| where | ||
| W: fmt::Write, | ||
| { | ||
| match *self { | ||
| ScrollSnapPoint::None => dest.write_str("none"), | ||
| ScrollSnapPoint::Repeat(ref length) => { | ||
| dest.write_str("repeat(")?; | ||
| length.to_css(dest)?; | ||
| dest.write_str(")") | ||
| }, | ||
| } | ||
| } | ||
| } | ||
| @@ -0,0 +1,26 @@ | ||
| /* 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/. */ | ||
|
|
||
| //! Specified types for legacy Gecko-only properties. | ||
|
|
||
| use cssparser::Parser; | ||
| use parser::{Parse, ParserContext}; | ||
| use values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint; | ||
| use values::specified::length::LengthOrPercentage; | ||
|
|
||
| /// A specified type for scroll snap points. | ||
| pub type ScrollSnapPoint = GenericScrollSnapPoint<LengthOrPercentage>; | ||
|
|
||
| impl Parse for ScrollSnapPoint { | ||
| fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { | ||
| if input.try(|i| i.expect_ident_matching("none")).is_ok() { | ||
| return Ok(GenericScrollSnapPoint::None); | ||
| } | ||
| input.expect_function_matching("repeat")?; | ||
| let length = input.parse_nested_block(|i| { | ||
| LengthOrPercentage::parse_non_negative(context, i) | ||
| })?; | ||
| Ok(GenericScrollSnapPoint::Repeat(length)) | ||
| } | ||
| } |
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
This is in a gecko-only module, so no need for a
cfg_attr(feature = "servo"...). Though any reason why compiling it for both hurts?