Bug 189397 - Improvements to zooming helper functions
Summary: Improvements to zooming helper functions
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-06 23:30 PDT by Frédéric Wang (:fredw)
Modified: 2023-09-02 08:55 PDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frédéric Wang (:fredw) 2018-09-06 23:30:05 PDT
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& style)
{
    double zoomFactor = style.effectiveZoom();
    if (zoomFactor == 1)
        return value;
    // Needed because computeLengthInt truncates (rather than rounds) when scaling up.
    if (zoomFactor > 1) {
        if (value < 0)
            value--;
        else 
            value++;
    }

    return roundForImpreciseConversion<int>(value / zoomFactor);
}

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

HTMLBodyElement.cpp
static int adjustForZoom(int value, const Frame& frame)
{
    double zoomFactor = frame.pageZoomFactor() * frame.frameScaleFactor();
    if (zoomFactor == 1)
        return value;
    // Needed because of truncation (rather than rounding) when scaling up.
    if (zoomFactor > 1)
        value++;
    return static_cast<int>(value / zoomFactor);
}
Comment 1 Ahmad Saleem 2023-09-02 08:55:43 PDT
Some clean-up from Blink's commit: https://chromium.googlesource.com/chromium/src.git/+/ad54bc5824e5901329fd1ab1beb1a63443399a6a