Commit 223b5884 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez Committed by morgan
Browse files

Bug 1909625 - Ignore CSS zoom and text zoom for canvas. r=gfx-reviewers,lsalzman

The spec doesn't mention anything about applying them, and other
browsers don't, so let's just be consistent...

Differential Revision: https://phabricator.services.mozilla.com/D221709
parent 5f129674
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
#include "CanvasRenderingContext2D.h"

#include "mozilla/gfx/Helpers.h"
#include "nsCSSValue.h"
#include "nsXULElement.h"

#include "nsMathUtils.h"
@@ -2585,14 +2586,8 @@ static already_AddRefed<StyleLockedDeclarationBlock> CreateDeclarationForServo(
    return nullptr;
  }

  // From canvas spec, force to set line-height property to 'normal' font
  // property.
  if (aProperty == eCSSProperty_font) {
    const nsCString normalString = "normal"_ns;
    Servo_DeclarationBlock_SetPropertyById(
        servoDeclarations, eCSSProperty_line_height, &normalString, false,
        env.mUrlExtraData, StyleParsingMode::DEFAULT, env.mCompatMode,
        env.mLoader, env.mRuleType, {});
    Servo_DeclarationBlock_SanitizeForCanvas(servoDeclarations);
  }

  return servoDeclarations.forget();
@@ -2657,12 +2652,9 @@ static already_AddRefed<const ComputedStyle> GetFontStyleForServo(
  // The font-size component must be converted to CSS px for reserialization,
  // so we update the declarations with the value from the computed style.
  if (!sc->StyleFont()->mFont.family.is_system_font) {
    nsAutoCString computedFontSize;
    sc->GetComputedPropertyValue(eCSSProperty_font_size, computedFontSize);
    Servo_DeclarationBlock_SetPropertyById(
        declarations, eCSSProperty_font_size, &computedFontSize, false, nullptr,
        StyleParsingMode::DEFAULT, eCompatibility_FullStandards, nullptr,
        StyleCssRuleType::Style, {});
    float px = sc->StyleFont()->mFont.size.ToCSSPixels();
    Servo_DeclarationBlock_SetLengthValue(declarations, eCSSProperty_font_size,
                                          px, eCSSUnit_Pixel);
  }

  // The font getter is required to be reserialized based on what we
+2 −3
Original line number Diff line number Diff line
@@ -1247,7 +1247,7 @@ impl<'b> Cascade<'b> {
        );
        debug_assert!(
            !text_scale.text_zoom_enabled(),
            "We only ever disable text zoom (in svg:text), never enable it"
            "We only ever disable text zoom never enable it"
        );
        let device = builder.device;
        builder.mutate_font().unzoom_fonts(device);
@@ -1257,9 +1257,8 @@ impl<'b> Cascade<'b> {
        debug_assert!(self.seen.contains(LonghandId::Zoom));
        // NOTE(emilio): Intentionally not using the effective zoom here, since all the inherited
        // zooms are already applied.
        let zoom = builder.get_box().clone_zoom();
        let old_size = builder.get_font().clone_font_size();
        let new_size = old_size.zoom(zoom);
        let new_size = old_size.zoom(builder.resolved_specified_zoom());
        if old_size == new_size {
            return;
        }
+11 −1
Original line number Diff line number Diff line
@@ -2711,6 +2711,16 @@ impl<'a> StyleBuilder<'a> {
        self.get_box().clone_zoom()
    }

    /// The zoom we need to apply for this element, without including ancestor effective zooms.
    pub fn resolved_specified_zoom(&self) -> computed::Zoom {
        let zoom = self.specified_zoom();
        if zoom.is_document() {
            self.inherited_effective_zoom().inverted()
        } else {
            zoom
        }
    }

    /// Inherited zoom.
    pub fn inherited_effective_zoom(&self) -> computed::Zoom {
        self.inherited_style.effective_zoom
@@ -2747,7 +2757,7 @@ impl<'a> StyleBuilder<'a> {
        let lh = device.calc_line_height(&font, writing_mode, None);
        if line_height_base == LineHeightBase::InheritedStyle {
            // Apply our own zoom if our style source is the parent style.
            computed::NonNegativeLength::new(self.get_box().clone_zoom().zoom(lh.px()))
            computed::NonNegativeLength::new(self.resolved_specified_zoom().zoom(lh.px()))
        } else {
            lh
        }
+12 −0
Original line number Diff line number Diff line
@@ -357,6 +357,18 @@ impl Zoom {
        self == Self::ONE
    }

    /// Returns whether we're the `document` keyword.
    #[inline]
    pub fn is_document(self) -> bool {
        self == Self::DOCUMENT
    }

    /// Returns the inverse of our value.
    #[inline]
    pub fn inverted(&self) -> Self {
        Self(Self::ONE.0 / self.0)
    }

    /// Returns the value as a float.
    #[inline]
    pub fn value(&self) -> f32 {
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ impl FontBaseSize {
            Self::InheritedStyle => {
                // If we're using the size from our inherited style, we still need to apply our
                // own zoom.
                let zoom = style.get_box().clone_zoom();
                let zoom = style.resolved_specified_zoom();
                style.get_parent_font().clone_font_size().zoom(zoom)
            },
        }
Loading