Commit a6985b60 authored by oshima's avatar oshima Committed by Commit bot

Add dedicated windowToViewport method to convert FloatRect from window...

Add dedicated windowToViewport method to convert FloatRect from window coordinates to Viewport coordinates.

... to avoid rounding issue with fractional scale factor.
BUG=485650

Review URL: https://codereview.chromium.org/1603253003

Cr-Commit-Position: refs/heads/master@{#371762}
parent 7da2b204
......@@ -1777,6 +1777,15 @@ void RenderWidget::convertViewportToWindow(blink::WebRect* rect) {
}
}
void RenderWidget::convertWindowToViewport(blink::WebFloatRect* rect) {
if (IsUseZoomForDSFEnabled()) {
rect->x *= device_scale_factor_;
rect->y *= device_scale_factor_;
rect->width *= device_scale_factor_;
rect->height *= device_scale_factor_;
}
}
void RenderWidget::OnShowImeIfNeeded() {
#if defined(OS_ANDROID) || defined(USE_AURA)
UpdateTextInputState(ShowIme::IF_NEEDED, ChangeSource::FROM_NON_IME);
......
......@@ -235,6 +235,7 @@ class CONTENT_EXPORT RenderWidget
const blink::WebFloatSize& velocity) override;
void showImeIfNeeded() override;
void convertViewportToWindow(blink::WebRect* rect) override;
void convertWindowToViewport(blink::WebFloatRect* rect) override;
// Override point to obtain that the current input method state and caret
// position.
......
......@@ -40,6 +40,7 @@
#include "core/page/SpellCheckerClient.h"
#include "platform/DragImage.h"
#include "platform/geometry/FloatPoint.h"
#include "platform/geometry/FloatRect.h"
#include "platform/geometry/IntRect.h"
#include "platform/heap/Handle.h"
#include "platform/network/ResourceError.h"
......@@ -132,6 +133,7 @@ public:
void scheduleAnimation(Widget*) override {}
IntRect viewportToScreen(const IntRect& r) const override { return r; }
FloatRect windowToViewport(const FloatRect& r) const override { return r; }
WebScreenInfo screenInfo() const override { return WebScreenInfo(); }
void contentsSizeChanged(LocalFrame*, const IntSize&) const override {}
......
......@@ -191,15 +191,4 @@ void ChromeClient::print(LocalFrame* frame)
printDelegate(frame);
}
float ChromeClient::screenToViewport(float length) const
{
// Convert the thickness in the screen (dip) to the viewport by applying
// the invert of the viewport to screen scale.
// TODO(oshima): Add native implementation instead of using viewportToScreen.
IntRect inScreen(0, 0, 100, 0);
inScreen = viewportToScreen(inScreen);
return length * 100.f / inScreen.width();
}
} // namespace blink
......@@ -260,8 +260,6 @@ public:
virtual PassOwnPtr<WebFrameScheduler> createFrameScheduler() = 0;
float screenToViewport(float) const override;
protected:
~ChromeClient() override { }
......
......@@ -50,8 +50,8 @@ public:
// Converts the rect from the viewport coordinates to screen coordinates.
virtual IntRect viewportToScreen(const IntRect&) const = 0;
// Converts the length from the screen coordinates to the viewport coordinates.
virtual float screenToViewport(float length) const = 0;
// Converts the rect from the window coordinates to the viewport coordinates.
virtual FloatRect windowToViewport(const FloatRect&) const = 0;
virtual void scheduleAnimation(Widget*) = 0;
};
......
......@@ -29,6 +29,7 @@
#include "platform/HostWindow.h"
#include "platform/PlatformGestureEvent.h"
#include "platform/PlatformMouseEvent.h"
#include "platform/geometry/FloatRect.h"
#include "platform/graphics/paint/CullRect.h"
// See windowActiveChangedForSnowLeopardOnly() below.
// TODO(ellyjones): remove this when Snow Leopard support is gone.
......@@ -81,7 +82,7 @@ Scrollbar::Scrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orient
// alone when sizing).
int thickness = m_theme.scrollbarThickness(controlSize);
if (m_hostWindow)
thickness = m_hostWindow->screenToViewport(thickness);
thickness = m_hostWindow->windowToViewport(FloatRect(0, 0, thickness, 0)).width();
Widget::setFrameRect(IntRect(0, 0, thickness, thickness));
m_currentPos = scrollableAreaCurrentPos();
......@@ -482,7 +483,7 @@ int Scrollbar::scrollbarThickness() const
int thickness = orientation() == HorizontalScrollbar ? height() : width();
if (!thickness || !m_hostWindow)
return thickness;
return m_hostWindow->screenToViewport(m_theme.scrollbarThickness(controlSize()));
return m_hostWindow->windowToViewport(FloatRect(0, 0, m_theme.scrollbarThickness(controlSize()), 0)).width();
}
......
......@@ -64,6 +64,7 @@
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCursorInfo.h"
#include "public/platform/WebFloatRect.h"
#include "public/platform/WebFrameScheduler.h"
#include "public/platform/WebRect.h"
#include "public/platform/WebURLRequest.h"
......@@ -519,6 +520,14 @@ IntRect ChromeClientImpl::viewportToScreen(const IntRect& rectInViewport) const
return screenRect;
}
FloatRect ChromeClientImpl::windowToViewport(const FloatRect& rectInWindow) const
{
WebFloatRect viewportRect(rectInWindow);
if (m_webView->client())
m_webView->client()->convertWindowToViewport(&viewportRect);
return viewportRect;
}
WebScreenInfo ChromeClientImpl::screenInfo() const
{
return m_webView->client() ? m_webView->client()->screenInfo() : WebScreenInfo();
......
......@@ -94,6 +94,7 @@ public:
void invalidateRect(const IntRect&) override;
void scheduleAnimation(Widget*) override;
IntRect viewportToScreen(const IntRect&) const override;
FloatRect windowToViewport(const FloatRect&) const override;
WebScreenInfo screenInfo() const override;
void contentsSizeChanged(LocalFrame*, const IntSize&) const override;
void pageScaleFactorChanged() const override;
......
......@@ -128,8 +128,7 @@ void DateTimeChooserImpl::writeDocument(SharedBuffer* data)
addString("</style></head><body><div id=main>Loading...</div><script>\n"
"window.dialogArguments = {\n", data);
addProperty("anchorRectInScreen", m_parameters.anchorRectInScreen, data);
IntRect inScreen = m_chromeClient->viewportToScreen(IntRect(0, 0, 100, 0));
float scaleFactor = 100.f / inScreen.width();
float scaleFactor = m_chromeClient->windowToViewport(FloatRect(0, 0, 1.0f, 0)).width();
addProperty("zoomFactor", zoomFactor() / scaleFactor, data);
addProperty("min", valueToDateTimeString(m_parameters.minimum, m_parameters.type), data);
addProperty("max", valueToDateTimeString(m_parameters.maximum, m_parameters.type), data);
......
......@@ -290,8 +290,7 @@ void PopupMenuImpl::writeDocument(SharedBuffer* data)
addProperty("anchorRectInScreen", anchorRectInScreen, data);
float zoom = zoomFactor();
IntRect inScreen = m_chromeClient->viewportToScreen(IntRect(0, 0, 100, 0));
float scaleFactor = 100.f / inScreen.width();
float scaleFactor = m_chromeClient->windowToViewport(FloatRect(0, 0, 1.0f, 0)).width();
addProperty("zoomFactor", zoom / scaleFactor, data);
bool isRTL = !ownerStyle->isLeftToRightDirection();
addProperty("isRTL", isRTL, data);
......
......@@ -48,6 +48,7 @@ class WebString;
class WebWidget;
struct WebCursorInfo;
struct WebFloatPoint;
struct WebFloatRect;
struct WebFloatSize;
struct WebSize;
......@@ -177,6 +178,13 @@ public:
// TODO(oshima): Update the comment when the migration is completed.
virtual void convertViewportToWindow(WebRect* rect) {}
// Converts the |rect| from the coordinates in native window in
// DIP to Blink's Viewport coordinates. They're identical in
// tradional world, but will differ when use-zoom-for-dsf feature
// is eanbled. TODO(oshima): Update the comment when the
// migration is completed.
virtual void convertWindowToViewport(WebFloatRect* rect) {}
protected:
~WebWidgetClient() { }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment