Skip to content
Snippets Groups Projects
Commit fac2ba04 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1856755 - Implement an internal zoom: document value that forces effective...

Bug 1856755 - Implement an internal zoom: document value that forces effective zoom to 1. r=jfkthame

The name matches the value that webkit (but not blink) exposes to the
web. We don't expose it.

Filed https://github.com/w3c/csswg-drafts/issues/9435 for this.

Differential Revision: https://phabricator.services.mozilla.com/D190025
parent cf2207d4
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,9 @@
-moz-min-font-size-ratio: initial;
-moz-box-collapse: initial;
/* We don't want zoom on our ancestors to affect our styles. */
zoom: document;
math-depth: initial;
/* As long as inert implies pointer-events: none as it does now, we're
* good. */
......
......@@ -897,8 +897,11 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
fn compute_zoom(&mut self) {
debug_assert!(matches!(self.cascade_mode, CascadeMode::Unvisited { .. }));
self.context.builder.effective_zoom =
self.context.builder.inherited_effective_zoom() * self.context.builder.specified_zoom();
self.context.builder.effective_zoom = self
.context
.builder
.inherited_effective_zoom()
.compute_effective(self.context.builder.specified_zoom());
}
fn compute_writing_mode(&mut self) {
......
......@@ -640,4 +640,5 @@ ${helpers.predefined_type(
spec="Non-standard (https://github.com/atanassov/css-zoom/ is the closest)",
gecko_pref="layout.css.zoom.enabled",
affects="layout",
enabled_in="ua",
)}
......@@ -291,20 +291,6 @@ pub type ZoomFixedPoint = FixedPoint<u16, ZOOM_FRACTION_BITS>;
#[repr(C)]
pub struct Zoom(ZoomFixedPoint);
impl std::ops::Mul for Zoom {
type Output = Zoom;
fn mul(self, rhs: Self) -> Self {
if self == Self::ONE {
return rhs;
}
if rhs == Self::ONE {
return self;
}
Zoom(ZoomFixedPoint::from_float(self.value() * rhs.value()))
}
}
impl ToComputedValue for specified::Zoom {
type ComputedValue = Zoom;
......@@ -312,6 +298,7 @@ impl ToComputedValue for specified::Zoom {
fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
let n = match *self {
Self::Normal => return Zoom::ONE,
Self::Document => return Zoom::DOCUMENT,
Self::Value(ref n) => n.0.to_number().get(),
};
if n == 0.0 {
......@@ -332,6 +319,10 @@ impl ToCss for Zoom {
where
W: fmt::Write,
{
use std::fmt::Write;
if *self == Self::DOCUMENT {
return dest.write_str("document");
}
self.value().to_css(dest)
}
}
......@@ -356,6 +347,10 @@ impl Zoom {
value: 1 << ZOOM_FRACTION_BITS,
});
/// The `document` value. This can appear in the computed zoom property value, but not in the
/// `effective_zoom` field.
pub const DOCUMENT: Zoom = Zoom(ZoomFixedPoint { value: 0 });
/// Returns whether we're the number 1.
#[inline]
pub fn is_one(self) -> bool {
......@@ -368,6 +363,20 @@ impl Zoom {
self.0.to_float()
}
/// Computes the effective zoom for a given new zoom value in rhs.
pub fn compute_effective(self, specified: Self) -> Self {
if specified == Self::DOCUMENT {
return Self::ONE;
}
if self == Self::ONE {
return specified;
}
if specified == Self::ONE {
return self;
}
Zoom(self.0 * specified.0)
}
/// Returns the zoomed value.
#[inline]
pub fn zoom(self, value: f32) -> f32 {
......
......@@ -1891,6 +1891,10 @@ impl ScrollbarGutter {
#[allow(missing_docs)]
pub enum Zoom {
Normal,
/// An internal value that resets the effective zoom to 1. Used for scrollbar parts, which
/// disregard zoom. We use this name because WebKit has this value exposed to the web.
#[parse(condition = "ParserContext::in_ua_sheet")]
Document,
Value(NonNegativeNumberOrPercentage),
}
......
<style>
* {
overflow: scroll scroll;
}
</style>
<h4 style="zoom: 3">
<figure>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment