Commit 3ecbe62a authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

weblayer: Set device_scale_adjustment

Copy implementation from chrome. Retrieve min_width from ui::Display.

Bug: 1052496
Change-Id: I453919244580e4c22439b8d7aa5a7da1c9aec289
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2154852
Commit-Queue: Bo <boliu@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760562}
parent 3797ae2c
...@@ -46,6 +46,8 @@ void PopulateFixedWebPreferences(WebPreferences* web_prefs) { ...@@ -46,6 +46,8 @@ void PopulateFixedWebPreferences(WebPreferences* web_prefs) {
!::features::IsUsingVizForWebView(); !::features::IsUsingVizForWebView();
web_prefs->disable_accelerated_small_canvases = true; web_prefs->disable_accelerated_small_canvases = true;
web_prefs->reenable_web_components_v0 = true; web_prefs->reenable_web_components_v0 = true;
// WebView has historically not adjusted font scale for text autosizing.
web_prefs->device_scale_adjustment = 1.0;
} }
const void* const kAwSettingsUserDataKey = &kAwSettingsUserDataKey; const void* const kAwSettingsUserDataKey = &kAwSettingsUserDataKey;
......
...@@ -2358,8 +2358,6 @@ jumbo_static_library("browser") { ...@@ -2358,8 +2358,6 @@ jumbo_static_library("browser") {
"android/chrome_backup_agent.h", "android/chrome_backup_agent.h",
"android/chrome_backup_watcher.cc", "android/chrome_backup_watcher.cc",
"android/chrome_backup_watcher.h", "android/chrome_backup_watcher.h",
"android/chrome_context_util.cc",
"android/chrome_context_util.h",
"android/chrome_session_state.cc", "android/chrome_session_state.cc",
"android/chrome_session_state.h", "android/chrome_session_state.h",
"android/chrome_startup_flags.cc", "android/chrome_startup_flags.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/android/chrome_context_util.h"
#include "base/android/jni_android.h"
#include "chrome/browser/util/jni_headers/ChromeContextUtil_jni.h"
namespace chrome {
namespace android {
ChromeContextUtil::ChromeContextUtil() {}
// static
int ChromeContextUtil::GetSmallestDIPWidth() {
return Java_ChromeContextUtil_getSmallestDIPWidth(
base::android::AttachCurrentThread());
}
} // namespace android
} // namespace chrome
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ANDROID_CHROME_CONTEXT_UTIL_H_
#define CHROME_BROWSER_ANDROID_CHROME_CONTEXT_UTIL_H_
namespace chrome {
namespace android {
class ChromeContextUtil {
public:
// Smallest possible screen size in density-independent pixels.
static int GetSmallestDIPWidth();
private:
ChromeContextUtil();
};
} // namespace android
} // namespace chrome
#endif // CHROME_BROWSER_ANDROID_CHROME_CONTEXT_UTIL_H_
...@@ -403,7 +403,6 @@ ...@@ -403,7 +403,6 @@
#include "chrome/android/features/dev_ui/buildflags.h" #include "chrome/android/features/dev_ui/buildflags.h"
#include "chrome/android/modules/extra_icu/provider/module_provider.h" #include "chrome/android/modules/extra_icu/provider/module_provider.h"
#include "chrome/browser/android/app_hooks.h" #include "chrome/browser/android/app_hooks.h"
#include "chrome/browser/android/chrome_context_util.h"
#include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h" #include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h"
#include "chrome/browser/android/devtools_manager_delegate_android.h" #include "chrome/browser/android/devtools_manager_delegate_android.h"
#include "chrome/browser/android/ntp/new_tab_page_url_handler.h" #include "chrome/browser/android/ntp/new_tab_page_url_handler.h"
...@@ -867,27 +866,6 @@ class CertificateReportingServiceCertReporter : public SSLCertReporter { ...@@ -867,27 +866,6 @@ class CertificateReportingServiceCertReporter : public SSLCertReporter {
DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter); DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter);
}; };
#if defined(OS_ANDROID)
float GetDeviceScaleAdjustment() {
static const float kMinFSM = 1.05f;
static const int kWidthForMinFSM = 320;
static const float kMaxFSM = 1.3f;
static const int kWidthForMaxFSM = 800;
int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth();
if (minWidth <= kWidthForMinFSM)
return kMinFSM;
if (minWidth >= kWidthForMaxFSM)
return kMaxFSM;
// The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
float ratio = static_cast<float>(minWidth - kWidthForMinFSM) /
(kWidthForMaxFSM - kWidthForMinFSM);
return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
}
#endif // defined(OS_ANDROID)
#if BUILDFLAG(ENABLE_EXTENSIONS) #if BUILDFLAG(ENABLE_EXTENSIONS)
AppLoadedInTabSource ClassifyAppLoadedInTabSource( AppLoadedInTabSource ClassifyAppLoadedInTabSource(
...@@ -3061,7 +3039,6 @@ void ChromeContentBrowserClient::OverrideWebkitPrefs( ...@@ -3061,7 +3039,6 @@ void ChromeContentBrowserClient::OverrideWebkitPrefs(
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
web_prefs->font_scale_factor = web_prefs->font_scale_factor =
static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment();
web_prefs->force_enable_zoom = web_prefs->force_enable_zoom =
prefs->GetBoolean(prefs::kWebKitForceEnableZoom); prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
#endif #endif
......
...@@ -9,7 +9,6 @@ android_library("java") { ...@@ -9,7 +9,6 @@ android_library("java") {
"android/java/src/org/chromium/chrome/browser/util/AccessibilityUtil.java", "android/java/src/org/chromium/chrome/browser/util/AccessibilityUtil.java",
"android/java/src/org/chromium/chrome/browser/util/AndroidTaskUtils.java", "android/java/src/org/chromium/chrome/browser/util/AndroidTaskUtils.java",
"android/java/src/org/chromium/chrome/browser/util/BitmapCache.java", "android/java/src/org/chromium/chrome/browser/util/BitmapCache.java",
"android/java/src/org/chromium/chrome/browser/util/ChromeContextUtil.java",
"android/java/src/org/chromium/chrome/browser/util/ChromeFileProvider.java", "android/java/src/org/chromium/chrome/browser/util/ChromeFileProvider.java",
"android/java/src/org/chromium/chrome/browser/util/FileSizeUtil.java", "android/java/src/org/chromium/chrome/browser/util/FileSizeUtil.java",
"android/java/src/org/chromium/chrome/browser/util/HashUtil.java", "android/java/src/org/chromium/chrome/browser/util/HashUtil.java",
...@@ -32,10 +31,8 @@ android_library("java") { ...@@ -32,10 +31,8 @@ android_library("java") {
} }
generate_jni("jni_headers") { generate_jni("jni_headers") {
sources = [ sources =
"android/java/src/org/chromium/chrome/browser/util/ChromeContextUtil.java", [ "android/java/src/org/chromium/chrome/browser/util/PlatformUtil.java" ]
"android/java/src/org/chromium/chrome/browser/util/PlatformUtil.java",
]
} }
android_library("javatests") { android_library("javatests") {
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.util;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
final class ChromeContextUtil {
private ChromeContextUtil() {}
@CalledByNative
private static int getSmallestDIPWidth() {
return ContextUtils.getApplicationContext()
.getResources()
.getConfiguration()
.smallestScreenWidthDp;
}
}
...@@ -89,7 +89,9 @@ ...@@ -89,7 +89,9 @@
#include "ui/base/pointer/pointer_device.h" #include "ui/base/pointer/pointer_device.h"
#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#include "ui/display/display.h"
#include "ui/display/display_switches.h" #include "ui/display/display_switches.h"
#include "ui/display/screen.h"
#include "ui/events/blink/blink_features.h" #include "ui/events/blink/blink_features.h"
#include "ui/gfx/animation/animation.h" #include "ui/gfx/animation/animation.h"
#include "ui/gfx/color_space.h" #include "ui/gfx/color_space.h"
...@@ -137,6 +139,25 @@ void GetFontInfo(gfx::win::SystemFont system_font, ...@@ -137,6 +139,25 @@ void GetFontInfo(gfx::win::SystemFont system_font,
} }
#endif // OS_WIN #endif // OS_WIN
#if defined(OS_ANDROID)
float GetDeviceScaleAdjustment(int min_width) {
static const float kMinFSM = 1.05f;
static const int kWidthForMinFSM = 320;
static const float kMaxFSM = 1.3f;
static const int kWidthForMaxFSM = 800;
if (min_width <= kWidthForMinFSM)
return kMinFSM;
if (min_width >= kWidthForMaxFSM)
return kMaxFSM;
// The font scale multiplier varies linearly between kMinFSM and kMaxFSM.
float ratio = static_cast<float>(min_width - kWidthForMinFSM) /
(kWidthForMaxFSM - kWidthForMinFSM);
return ratio * (kMaxFSM - kMinFSM) + kMinFSM;
}
#endif
} // namespace } // namespace
// static // static
...@@ -624,6 +645,14 @@ const WebPreferences RenderViewHostImpl::ComputeWebPreferences() { ...@@ -624,6 +645,14 @@ const WebPreferences RenderViewHostImpl::ComputeWebPreferences() {
if (delegate_->HasPersistentVideo()) if (delegate_->HasPersistentVideo())
prefs.media_controls_enabled = false; prefs.media_controls_enabled = false;
#if defined(OS_ANDROID)
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
gfx::Size size = display.GetSizeInPixel();
int min_width = size.width() < size.height() ? size.width() : size.height();
prefs.device_scale_adjustment = GetDeviceScaleAdjustment(
static_cast<int>(min_width / display.device_scale_factor()));
#endif // OS_ANDROID
GetContentClient()->browser()->OverrideWebkitPrefs(this, &prefs); GetContentClient()->browser()->OverrideWebkitPrefs(this, &prefs);
return prefs; return prefs;
} }
......
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