Commit 4598a511 authored by Jaebaek Seo's avatar Jaebaek Seo Committed by Commit Bot

Resize scrollbar for enabling use-zoom-for-DSF in Android

This is a subtask to enable use-zoom-for-DSF in Android. This CL correctly
applies the DSF to Android scrollbars when using the 'use-zoom-for-DSF' flag.

Bug: 737777
Change-Id: I207cdaf26b1501e99f80019acfe56240d704ce5a
Reviewed-on: https://chromium-review.googlesource.com/620328
Commit-Queue: Jaebaek Seo <jaebaek@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501579}
parent caf59bbb
......@@ -447,9 +447,15 @@ void VisualViewport::SetupScrollbar(WebScrollbar::Orientation orientation) {
: web_overlay_scrollbar_vertical_;
ScrollbarThemeOverlay& theme = ScrollbarThemeOverlay::MobileTheme();
int thumb_thickness = theme.ThumbThickness();
int scrollbar_thickness = theme.ScrollbarThickness(kRegularScrollbar);
int scrollbar_margin = theme.ScrollbarMargin();
int thumb_thickness = clampTo<int>(
std::floor(GetPage().GetChromeClient().WindowToViewportScalar(
theme.ThumbThickness())));
int scrollbar_thickness = clampTo<int>(
std::floor(GetPage().GetChromeClient().WindowToViewportScalar(
theme.ScrollbarThickness(kRegularScrollbar))));
int scrollbar_margin = clampTo<int>(
std::floor(GetPage().GetChromeClient().WindowToViewportScalar(
theme.ScrollbarMargin())));
if (!web_scrollbar_layer) {
ScrollingCoordinator* coordinator = GetPage().GetScrollingCoordinator();
......
......@@ -3,7 +3,9 @@
// found in the LICENSE file.
#include "build/build_config.h"
#include "core/frame/FrameTestHelpers.h"
#include "core/frame/LocalFrameView.h"
#include "core/frame/VisualViewport.h"
#include "core/frame/WebLocalFrameImpl.h"
#include "core/input/EventHandler.h"
#include "core/layout/LayoutView.h"
......@@ -16,6 +18,7 @@
#include "platform/testing/TestingPlatformSupport.h"
#include "platform/testing/URLTestHelpers.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/WebFloatRect.h"
#include "public/platform/WebThemeEngine.h"
#include "public/web/WebScriptSource.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -52,6 +55,79 @@ TEST_F(ScrollbarsTest, DocumentStyleRecalcPreservesScrollbars) {
ASSERT_TRUE(plsa->VerticalScrollbar() && plsa->HorizontalScrollbar());
}
class ScrollbarsWebViewClient : public FrameTestHelpers::TestWebViewClient {
public:
void ConvertWindowToViewport(WebFloatRect* rect) override {
rect->x *= device_scale_factor_;
rect->y *= device_scale_factor_;
rect->width *= device_scale_factor_;
rect->height *= device_scale_factor_;
}
void set_device_scale_factor(float device_scale_factor) {
device_scale_factor_ = device_scale_factor;
}
private:
float device_scale_factor_;
};
TEST_F(ScrollbarsTest, ScrollbarSizeForUseZoomDSF) {
ScrollbarsWebViewClient client;
client.set_device_scale_factor(1.f);
FrameTestHelpers::WebViewHelper web_view_helper;
WebViewImpl* web_view_impl =
web_view_helper.Initialize(nullptr, &client, nullptr, nullptr);
web_view_impl->Resize(IntSize(800, 600));
WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
FrameTestHelpers::LoadHTMLString(web_view_impl->MainFrameImpl(),
"<!DOCTYPE html>"
"<style>"
" body {"
" width: 1600px;"
" height: 1200px;"
" }"
"</style>"
"<body>"
"</body>",
base_url);
web_view_impl->UpdateAllLifecyclePhases();
Document* document =
ToLocalFrame(web_view_impl->GetPage()->MainFrame())->GetDocument();
VisualViewport& visual_viewport = document->GetPage()->GetVisualViewport();
int horizontal_scrollbar = clampTo<int>(std::floor(
visual_viewport.LayerForHorizontalScrollbar()->Size().Height()));
int vertical_scrollbar = clampTo<int>(
std::floor(visual_viewport.LayerForVerticalScrollbar()->Size().Width()));
const float device_scale = 3.5f;
client.set_device_scale_factor(device_scale);
web_view_impl->Resize(IntSize(400, 300));
EXPECT_EQ(
clampTo<int>(std::floor(horizontal_scrollbar * device_scale)),
clampTo<int>(std::floor(
visual_viewport.LayerForHorizontalScrollbar()->Size().Height())));
EXPECT_EQ(clampTo<int>(std::floor(vertical_scrollbar * device_scale)),
clampTo<int>(std::floor(
visual_viewport.LayerForVerticalScrollbar()->Size().Width())));
client.set_device_scale_factor(1.f);
web_view_impl->Resize(IntSize(800, 600));
EXPECT_EQ(
horizontal_scrollbar,
clampTo<int>(std::floor(
visual_viewport.LayerForHorizontalScrollbar()->Size().Height())));
EXPECT_EQ(vertical_scrollbar,
clampTo<int>(std::floor(
visual_viewport.LayerForVerticalScrollbar()->Size().Width())));
}
// Ensure that causing a change in scrollbar existence causes a nested layout
// to recalculate the existence of the opposite scrollbar. The bug here was
// caused by trying to avoid the layout when overlays are enabled but not
......
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