<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>189397</bug_id>
          
          <creation_ts>2018-09-06 23:30:05 -0700</creation_ts>
          <short_desc>Improvements to zooming helper functions</short_desc>
          <delta_ts>2023-09-02 08:55:43 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Frédéric Wang Nélar">fred.wang</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>simon.fraser</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1457421</commentid>
    <comment_count>0</comment_count>
    <who name="Frédéric Wang Nélar">fred.wang</who>
    <bug_when>2018-09-06 23:30:05 -0700</bug_when>
    <thetext>We currently have at least three functions, with similar logic but different types of parameter. Maybe it would be possible to merge them into a single helper function. Some of them increment/decrement the value to workaround truncation and in bug 182230 Simon suggested to just floor/ceil after the division by zoomFactor. Not sure how that would impact accuracy.

RenderStyle.h:
inline int adjustForAbsoluteZoom(int value, const RenderStyle&amp; style)
{
    double zoomFactor = style.effectiveZoom();
    if (zoomFactor == 1)
        return value;
    // Needed because computeLengthInt truncates (rather than rounds) when scaling up.
    if (zoomFactor &gt; 1) {
        if (value &lt; 0)
            value--;
        else 
            value++;
    }

    return roundForImpreciseConversion&lt;int&gt;(value / zoomFactor);
}

Element.cpp:
static double adjustForLocalZoom(LayoutUnit value, const RenderElement&amp; renderer, double&amp; zoomFactor)
{
    zoomFactor = localZoomForRenderer(renderer);
    if (zoomFactor == 1)
        return value.toDouble();
    return value.toDouble() / zoomFactor;
}

HTMLBodyElement.cpp
static int adjustForZoom(int value, const Frame&amp; frame)
{
    double zoomFactor = frame.pageZoomFactor() * frame.frameScaleFactor();
    if (zoomFactor == 1)
        return value;
    // Needed because of truncation (rather than rounding) when scaling up.
    if (zoomFactor &gt; 1)
        value++;
    return static_cast&lt;int&gt;(value / zoomFactor);
}</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1975184</commentid>
    <comment_count>1</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-09-02 08:55:43 -0700</bug_when>
    <thetext>Some clean-up from Blink&apos;s commit: https://chromium.googlesource.com/chromium/src.git/+/ad54bc5824e5901329fd1ab1beb1a63443399a6a</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>