0

Move Windows DPI Code from ui/gfx to ui/display

BUG=597761

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

Cr-Commit-Position: refs/heads/master@{#388224}
This commit is contained in:
robliao
2016-04-19 09:47:12 -07:00
committed by Commit bot
parent e2b6c18422
commit 18e220e823
57 changed files with 132 additions and 115 deletions

@ -21,7 +21,7 @@
#if defined(OS_WIN)
#include "ui/aura/window_tree_host.h"
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
namespace ash {
@ -171,7 +171,7 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
float device_scale_factor = 1.0f;
if (!GetDisplayBounds(main_spec, &bounds_in_native, &device_scale_factor)) {
#if defined(OS_WIN)
device_scale_factor = gfx::GetDPIScale();
device_scale_factor = display::win::GetDPIScale();
#endif
}

@ -39,7 +39,6 @@
#include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/result_codes.h"
#include "ui/gfx/win/dpi.h"
namespace {

@ -211,7 +211,6 @@
#include "chrome/installer/util/shell_util.h"
#include "components/startup_metric_utils/common/pre_read_field_trial_utils_win.h"
#include "ui/base/l10n/l10n_util_win.h"
#include "ui/gfx/win/dpi.h"
#include "ui/shell_dialogs/select_file_dialog.h"
#endif // defined(OS_WIN)

@ -12,8 +12,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/win/win_util.h"
#include "extensions/common/api/system_display.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/win/dpi.h"
namespace extensions {
@ -38,7 +38,7 @@ EnumMonitorCallback(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data) {
if (!EnumDisplayDevices(monitor_info.szDevice, 0, &device, 0))
return FALSE;
gfx::Size dpi(gfx::GetDPI());
gfx::Size dpi(display::win::GetDPI());
unit.id =
base::Int64ToString(base::Hash(base::WideToUTF8(monitor_info.szDevice)));
unit.name = base::WideToUTF8(device.DeviceString);

@ -11,10 +11,10 @@
#include "base/message_loop/message_loop.h"
#include "base/threading/thread.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/icon_util.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/win/dpi.h"
// static
IconGroupID IconLoader::ReadGroupIDFromFilepath(
@ -61,7 +61,8 @@ void IconLoader::ReadIcon() {
std::unique_ptr<SkBitmap> bitmap(
IconUtil::CreateSkBitmapFromHICON(file_info.hIcon));
if (bitmap.get()) {
gfx::ImageSkia image_skia(gfx::ImageSkiaRep(*bitmap, gfx::GetDPIScale()));
gfx::ImageSkia image_skia(gfx::ImageSkiaRep(*bitmap,
display::win::GetDPIScale()));
image_skia.MakeThreadSafe();
image_.reset(new gfx::Image(image_skia));
DestroyIcon(file_info.hIcon);

@ -10,7 +10,7 @@
#include "chrome/browser/ui/views/apps/chrome_native_app_window_views_win.h"
#include "chrome/browser/ui/views/apps/glass_app_window_frame_view_win.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#include "ui/views/controls/menu/native_menu_win.h"
AppWindowDesktopWindowTreeHostWin::AppWindowDesktopWindowTreeHostWin(
@ -69,7 +69,7 @@ void AppWindowDesktopWindowTreeHostWin::UpdateDWMFrame() {
gfx::Insets insets = app_window_->glass_frame_view()->GetGlassInsets();
// The DWM API's expect values in pixels. We need to convert from DIP to
// pixels here.
insets = insets.Scale(gfx::GetDPIScale());
insets = insets.Scale(display::win::GetDPIScale());
margins.cxLeftWidth = insets.left();
margins.cxRightWidth = insets.right();
margins.cyBottomHeight = insets.bottom();

@ -7,7 +7,7 @@
#include "base/win/windows_version.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "ui/base/hit_test.h"
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
@ -30,11 +30,11 @@ GlassAppWindowFrameViewWin::~GlassAppWindowFrameViewWin() {
}
gfx::Insets GlassAppWindowFrameViewWin::GetGlassInsets() const {
int caption_height = gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME) +
gfx::win::GetSystemMetricsInDIP(SM_CYCAPTION);
int caption_height = display::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME) +
display::win::GetSystemMetricsInDIP(SM_CYCAPTION);
int frame_size = base::win::GetVersion() < base::win::VERSION_WIN10
? gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME)
? display::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME)
: 0;
return gfx::Insets(caption_height, frame_size, frame_size, frame_size);
@ -55,7 +55,7 @@ gfx::Insets GlassAppWindowFrameViewWin::GetClientAreaInsets() const {
} else {
// On Windows 10 we use a 1 pixel non client border which is too thin as a
// resize target. This inset extends the resize region.
int resize_border = gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
int resize_border = display::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
insets.Set(0, resize_border, resize_border, resize_border);
}
return insets;
@ -103,7 +103,7 @@ int GlassAppWindowFrameViewWin::NonClientHitTest(const gfx::Point& point) {
: false;
// Don't allow overlapping resize handles when the window is maximized or
// fullscreen, as it can't be resized in those states.
int resize_border = gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
int resize_border = display::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
int frame_component =
GetHTComponentForFrame(point,
resize_border,

@ -15,8 +15,8 @@
#include <shellapi.h>
#include "base/win/win_util.h"
#include "base/win/windows_version.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/icon_util.h"
#include "ui/gfx/win/dpi.h"
#endif
@ -81,7 +81,7 @@ void ElevationIconSetter::SetButtonIcon(const base::Closure& callback,
#if defined(OS_WIN)
// Windows gives us back a correctly-scaled image for the current DPI, so
// mark this image as having been scaled for the current DPI already.
device_scale_factor = gfx::GetDPIScale();
device_scale_factor = display::win::GetDPIScale();
#endif
button_->SetImage(
views::Button::STATE_NORMAL,

@ -26,11 +26,11 @@
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle_win.h"
#include "ui/base/theme_provider.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/icon_util.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/win/dpi.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/layout_constants.h"
@ -228,10 +228,11 @@ int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
// See if we're in the sysmenu region. We still have to check the tabstrip
// first so that clicks in a tab don't get treated as sysmenu clicks.
int nonclient_border_thickness = NonClientBorderThickness(false);
if (gfx::Rect(nonclient_border_thickness,
gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME),
gfx::win::GetSystemMetricsInDIP(SM_CXSMICON),
gfx::win::GetSystemMetricsInDIP(SM_CYSMICON)).Contains(point))
gfx::Rect sys_menu_region(nonclient_border_thickness,
display::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME),
display::win::GetSystemMetricsInDIP(SM_CXSMICON),
display::win::GetSystemMetricsInDIP(SM_CYSMICON));
if (sys_menu_region.Contains(point))
return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU;
if (frame_component != HTNOWHERE)
@ -300,7 +301,7 @@ bool GlassBrowserFrameView::DoesIntersectRect(const views::View* target,
int GlassBrowserFrameView::FrameBorderThickness() const {
return (frame()->IsMaximized() || frame()->IsFullscreen()) ?
0 : gfx::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
0 : display::win::GetSystemMetricsInDIP(SM_CXSIZEFRAME);
}
int GlassBrowserFrameView::FrameTopBorderHeight(bool restored) const {
@ -308,7 +309,7 @@ int GlassBrowserFrameView::FrameTopBorderHeight(bool restored) const {
// frame has a 0 frame border around most edges and a CYSIZEFRAME-thick border
// at the top (see AeroGlassFrame::OnGetMinMaxInfo()).
return (frame()->IsFullscreen() && !restored) ?
0 : gfx::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME);
0 : display::win::GetSystemMetricsInDIP(SM_CYSIZEFRAME);
}
int GlassBrowserFrameView::NonClientBorderThickness(bool restored) const {
@ -520,7 +521,7 @@ void GlassBrowserFrameView::LayoutNewStyleAvatar() {
int button_y = frame()->IsMaximized() ? (FrameTopBorderHeight(false) - 1) : 1;
profile_switcher_.view()->SetBounds(
button_x, button_y, label_size.width(),
gfx::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1);
display::win::GetSystemMetricsInDIP(SM_CYMENUSIZE) + 1);
}
void GlassBrowserFrameView::LayoutIncognitoIcon() {

@ -7,7 +7,7 @@
#include "base/logging.h"
#include "base/i18n/rtl.h"
#include "ui/base/win/shell.h"
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
namespace {
@ -32,7 +32,7 @@ int GetMinimizeButtonOffsetForWindow(HWND hwnd) {
// returning it.
POINT minimize_button_corner = { titlebar_info.rgrect[2].left, 0 };
MapWindowPoints(HWND_DESKTOP, hwnd, &minimize_button_corner, 1);
return minimize_button_corner.x / gfx::GetDPIScale();
return minimize_button_corner.x / display::win::GetDPIScale();
}
} // namespace

@ -79,7 +79,7 @@
#include "base/trace_event/trace_event_etw_export_win.h"
#include "base/win/process_startup_helper.h"
#include "ui/base/win/atl_module.h"
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#elif defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/power_monitor/power_monitor_device_source.h"
@ -532,7 +532,7 @@ class ContentMainRunnerImpl : public ContentMainRunner {
switches::kDeviceScaleFactor);
double scale_factor = 0;
if (base::StringToDouble(scale_factor_string, &scale_factor))
gfx::SetDefaultDeviceScaleFactor(scale_factor);
display::win::SetDefaultDeviceScaleFactor(scale_factor);
}
#endif

@ -44,7 +44,7 @@
#include "content/common/sandbox_win.h"
#include "sandbox/win/src/process_mitigations.h"
#include "sandbox/win/src/sandbox_policy.h"
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
namespace content {
@ -435,8 +435,9 @@ bool PpapiPluginProcessHost::Init(const PepperPluginInfo& info) {
}
#if defined(OS_WIN)
cmd_line->AppendSwitchASCII(switches::kDeviceScaleFactor,
base::DoubleToString(gfx::GetDPIScale()));
cmd_line->AppendSwitchASCII(
switches::kDeviceScaleFactor,
base::DoubleToString(display::win::GetDPIScale()));
#endif
if (!plugin_launcher.empty())

@ -197,7 +197,7 @@
#include "content/common/font_cache_dispatcher_win.h"
#include "content/common/sandbox_win.h"
#include "sandbox/win/src/sandbox_policy.h"
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
#if defined(OS_MACOSX)
@ -1368,8 +1368,9 @@ void RenderProcessHostImpl::AppendRendererCommandLine(
command_line->AppendSwitch(switches::kEnablePinch);
#if defined(OS_WIN)
command_line->AppendSwitchASCII(switches::kDeviceScaleFactor,
base::DoubleToString(gfx::GetDPIScale()));
command_line->AppendSwitchASCII(
switches::kDeviceScaleFactor,
base::DoubleToString(display::win::GetDPIScale()));
#endif
AppendCompositorCommandLineFlags(command_line);

@ -91,8 +91,8 @@
#if defined(OS_WIN)
#include "base/win/win_util.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/platform_font_win.h"
#include "ui/gfx/win/dpi.h"
#endif
using base::TimeDelta;
@ -154,13 +154,13 @@ void GetWindowsSpecificPrefs(RendererPreferences* prefs) {
metrics.lfMessageFont);
prefs->vertical_scroll_bar_width_in_dips =
gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
display::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
prefs->horizontal_scroll_bar_height_in_dips =
gfx::win::GetSystemMetricsInDIP(SM_CYHSCROLL);
display::win::GetSystemMetricsInDIP(SM_CYHSCROLL);
prefs->arrow_bitmap_height_vertical_scroll_bar_in_dips =
gfx::win::GetSystemMetricsInDIP(SM_CYVSCROLL);
display::win::GetSystemMetricsInDIP(SM_CYVSCROLL);
prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips =
gfx::win::GetSystemMetricsInDIP(SM_CXHSCROLL);
display::win::GetSystemMetricsInDIP(SM_CXHSCROLL);
}
#endif

@ -43,7 +43,6 @@
#if defined(OS_WIN)
#include "base/win/windows_version.h"
#include "ui/gfx/win/dpi.h"
#endif
namespace content {

@ -38,6 +38,7 @@
'../third_party/libyuv/libyuv.gyp:libyuv',
'../third_party/widevine/cdm/widevine_cdm.gyp:widevine_cdm_version_h',
'../ui/accessibility/accessibility.gyp:accessibility',
'../ui/display/display.gyp:display',
'../ui/events/blink/events_blink.gyp:events_blink',
'../ui/events/events.gyp:dom_keycode_converter',
'../ui/gfx/gfx.gyp:gfx',

@ -863,6 +863,7 @@
'../ui/base/ui_base.gyp:ui_base_test_support',
'../ui/base/ui_base.gyp:ui_data_pack',
'../ui/compositor/compositor.gyp:compositor_test_support',
'../ui/display/display.gyp:display',
'../ui/events/events.gyp:dom_keycode_converter',
'../ui/events/events.gyp:events_base',
'../ui/events/events.gyp:events_test_support',

@ -32,8 +32,8 @@
#include "sandbox/win/src/sandbox.h"
#include "third_party/WebKit/public/web/win/WebFontRendering.h"
#include "third_party/skia/include/ports/SkTypeface_win.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/win/direct_write.h"
#include "ui/gfx/win/dpi.h"
#endif
#if defined(OS_CHROMEOS)
@ -156,7 +156,7 @@ int PpapiPluginMain(const MainFunctionParams& parameters) {
}
blink::WebFontRendering::setUseDirectWrite(use_direct_write);
blink::WebFontRendering::setDeviceScaleFactor(gfx::GetDPIScale());
blink::WebFontRendering::setDeviceScaleFactor(display::win::GetDPIScale());
#endif
main_message_loop.Run();

@ -82,6 +82,7 @@ source_set("renderer") {
"//ui/accessibility",
"//ui/base",
"//ui/base/ime",
"//ui/display",
"//ui/events:dom_keycode_converter",
"//ui/events:events_base",
"//ui/events/blink",

@ -25,8 +25,8 @@
#include "third_party/WebKit/public/web/win/WebFontRendering.h"
#include "third_party/icu/source/i18n/unicode/timezone.h"
#include "third_party/skia/include/ports/SkTypeface_win.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/win/direct_write.h"
#include "ui/gfx/win/dpi.h"
namespace content {
namespace {
@ -75,7 +75,8 @@ void RendererMainPlatformDelegate::PlatformInitialize() {
}
}
blink::WebFontRendering::setUseDirectWrite(use_direct_write);
blink::WebFontRendering::setDeviceScaleFactor(gfx::GetDPIScale());
// TODO(robliao): This should use WebScreenInfo. See http://crbug.com/604555.
blink::WebFontRendering::setDeviceScaleFactor(display::win::GetDPIScale());
}
void RendererMainPlatformDelegate::PlatformUninitialize() {

@ -80,6 +80,7 @@ source_set("test_support") {
"//ui/base:ui_data_pack",
"//ui/base/ime",
"//ui/compositor:test_support",
"//ui/display",
"//ui/events:dom_keycode_converter",
"//ui/events:events_base",
"//ui/events:gesture_detection",

@ -23,7 +23,7 @@
#include "url/url_util.h"
#if defined(OS_WIN)
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
#if defined(OS_ANDROID)
@ -108,7 +108,7 @@ void SetUpBlinkTestEnvironment() {
#endif
#if defined(OS_WIN)
gfx::SetDefaultDeviceScaleFactor(1.0f);
display::win::SetDefaultDeviceScaleFactor(1.0f);
#endif
// Explicitly initialize the GURL library before spawning any threads.

@ -20,7 +20,7 @@
#include "ui/gl/test/gl_surface_test_support.h"
#if defined(OS_WIN)
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
#if defined(OS_MACOSX)
@ -75,7 +75,7 @@ void ContentTestSuite::Initialize() {
#endif
#if defined(OS_WIN)
gfx::SetDefaultDeviceScaleFactor(1.0f);
display::win::SetDefaultDeviceScaleFactor(1.0f);
#endif
ContentTestSuiteBase::Initialize();

@ -236,6 +236,7 @@ executable("demo") {
"//ui/base",
"//ui/compositor",
"//ui/compositor:test_support",
"//ui/display",
"//ui/events",
"//ui/gfx",
"//ui/gfx/geometry",

@ -213,6 +213,7 @@
'../base/ui_base.gyp:ui_base',
'../compositor/compositor.gyp:compositor',
'../compositor/compositor.gyp:compositor_test_support',
'../display/display.gyp:display',
'../events/events.gyp:events',
'../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',

@ -1,3 +1,4 @@
include_rules = [
"+ui/display", # Windows DPI Initialization.
"+ui/gl/gl_surface.h", # To initialize GL bindings.
]

@ -36,7 +36,7 @@
#endif
#if defined(OS_WIN)
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
namespace {
@ -133,7 +133,7 @@ int DemoMain() {
gfx::GLSurface::InitializeOneOff();
#if defined(OS_WIN)
gfx::SetDefaultDeviceScaleFactor(1.0f);
display::win::SetDefaultDeviceScaleFactor(1.0f);
#endif
// The ContextFactory must exist before any Compositors are created.

@ -371,6 +371,7 @@ component("base") {
"//net",
"//third_party/icu",
"//ui/base:ui_data_pack",
"//ui/display",
"//ui/events",
"//ui/events/devices",
"//ui/resources",
@ -826,6 +827,7 @@ test("ui_base_unittests") {
"//ui/base",
"//ui/base:test_support",
"//ui/base:ui_data_pack",
"//ui/display",
"//ui/events:events_base",
"//ui/events:test_support",
"//ui/gfx:test_support",

@ -17,8 +17,8 @@
#include "base/win/i18n.h"
#include "base/win/windows_version.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/display.h"
#include "ui/gfx/win/dpi.h"
#include "ui/strings/grit/app_locale_settings.h"
namespace {
@ -155,7 +155,7 @@ bool NeedOverrideDefaultUIFont(base::string16* override_font_family,
}
void AdjustUIFont(LOGFONT* logfont) {
float dpi_scale = gfx::GetDPIScale();
float dpi_scale = display::win::GetDPIScale();
if (gfx::Display::HasForceDeviceScaleFactor()) {
// If the scale is forced, we don't need to adjust it here.
dpi_scale = 1.0f;

@ -9,7 +9,6 @@
#include "base/win/win_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "ui/gfx/win/dpi.h"
typedef PlatformTest L10nUtilWinTest;
@ -34,4 +33,4 @@ TEST_F(L10nUtilWinTest, TestDPIScaling) {
lf.lfHeight = static_cast<int>(1.8 * size + rounding);
l10n_util::AdjustUIFontForDIP(1.8f, &lf);
EXPECT_NEAR(size, lf.lfHeight, 1);
}
}

@ -52,7 +52,7 @@
#endif
#if defined(OS_WIN)
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
#if defined(OS_MACOSX) && !defined(OS_IOS)
@ -392,7 +392,9 @@ gfx::Image& ResourceBundle::GetImageNamed(int resource_id) {
ui::ScaleFactor scale_factor_to_load = GetMaxScaleFactor();
#elif defined(OS_WIN)
ui::ScaleFactor scale_factor_to_load =
gfx::GetDPIScale() > 1.25 ? GetMaxScaleFactor() : ui::SCALE_FACTOR_100P;
display::win::GetDPIScale() > 1.25
? GetMaxScaleFactor()
: ui::SCALE_FACTOR_100P;
#else
ui::ScaleFactor scale_factor_to_load = ui::SCALE_FACTOR_100P;
#endif

@ -29,7 +29,7 @@
#include "ui/strings/grit/app_locale_settings.h"
#if defined(OS_WIN)
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
using ::testing::_;
@ -461,7 +461,7 @@ TEST_F(ResourceBundleImageTest, GetRawDataResource) {
// via ResourceBundle::GetImageNamed().
TEST_F(ResourceBundleImageTest, GetImageNamed) {
#if defined(OS_WIN)
gfx::SetDefaultDeviceScaleFactor(2.0);
display::win::SetDefaultDeviceScaleFactor(2.0);
#endif
std::vector<ScaleFactor> supported_factors;
supported_factors.push_back(SCALE_FACTOR_100P);

@ -14,7 +14,6 @@
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_source.h"
#include "ui/gfx/win/dpi.h"
namespace ui {

@ -24,7 +24,7 @@
#endif
#if defined(OS_WIN)
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
namespace {
@ -49,7 +49,7 @@ void UIBaseTestSuite::Initialize() {
base::TestSuite::Initialize();
#if defined(OS_WIN)
gfx::SetDefaultDeviceScaleFactor(1.0);
display::win::SetDefaultDeviceScaleFactor(1.0);
#endif
#if defined(OS_ANDROID)

@ -67,6 +67,7 @@
'../../third_party/icu/icu.gyp:icui18n',
'../../third_party/icu/icu.gyp:icuuc',
'../../url/url.gyp:url_lib',
'../display/display.gyp:display',
'../events/events.gyp:events',
'../events/events.gyp:events_base',
'../events/platform/events_platform.gyp:events_platform',

@ -21,6 +21,7 @@
'../../third_party/icu/icu.gyp:icui18n',
'../../third_party/icu/icu.gyp:icuuc',
'../../url/url.gyp:url_lib',
'../display/display.gyp:display',
'../events/events.gyp:events_base',
'../gfx/gfx.gyp:gfx_test_support',
'../resources/ui_resources.gyp:ui_resources',

@ -11,7 +11,6 @@
#include "base/memory/scoped_vector.h"
#include "base/memory/singleton.h"
#include "base/stl_util.h"
#include "ui/gfx/win/dpi.h"
#include "ui/gfx/win/hwnd_util.h"
namespace {

@ -143,6 +143,7 @@ source_set("test_support") {
"//skia",
"//testing/gtest",
"//ui/base",
"//ui/display",
"//ui/gfx",
"//ui/gfx/geometry",
"//ui/gl:test_support",

@ -111,6 +111,7 @@
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/third_party/WebKit/public/blink.gyp:blink_minimal',
'<(DEPTH)/ui/base/ui_base.gyp:ui_base',
'<(DEPTH)/ui/display/display.gyp:display',
'<(DEPTH)/ui/gfx/gfx.gyp:gfx',
'<(DEPTH)/ui/gfx/gfx.gyp:gfx_geometry',
'<(DEPTH)/ui/gl/gl.gyp:gl',

@ -3,4 +3,5 @@ include_rules = [
"+gpu/command_buffer/common",
"+gpu/skia_bindings",
"+skia/ext",
"+ui/display",
]

@ -14,7 +14,7 @@
#include "ui/gl/test/gl_surface_test_support.h"
#if defined(OS_WIN)
#include "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#endif
namespace ui {
@ -32,7 +32,7 @@ void CompositorTestSuite::Initialize() {
gfx::RegisterPathProvider();
#if defined(OS_WIN)
gfx::SetDefaultDeviceScaleFactor(1.0f);
display::win::SetDefaultDeviceScaleFactor(1.0f);
#endif
message_loop_.reset(new base::MessageLoopForUI);

@ -41,6 +41,8 @@ component("display") {
"manager/display_layout_builder.h",
"win/display_info.cc",
"win/display_info.h",
"win/dpi.cc",
"win/dpi.h",
"win/screen_win.cc",
"win/screen_win.h",
"win/screen_win_display.cc",

@ -80,6 +80,8 @@
'manager/display_layout_builder.h',
'win/display_info.cc',
'win/display_info.h',
'win/dpi.cc',
'win/dpi.h',
'win/screen_win.cc',
'win/screen_win.h',
'win/screen_win_display.cc',

@ -1,10 +1,11 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2012 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 "ui/gfx/win/dpi.h"
#include "ui/display/win/dpi.h"
#include <windows.h>
#include "base/win/scoped_hdc.h"
#include "ui/gfx/display.h"
@ -17,19 +18,20 @@ float g_device_scale_factor = 0.f;
float GetUnforcedDeviceScaleFactor() {
return g_device_scale_factor ?
g_device_scale_factor :
static_cast<float>(gfx::GetDPI().width()) / kDefaultDPI;
static_cast<float>(display::win::GetDPI().width()) / kDefaultDPI;
}
} // namespace
namespace gfx {
namespace display {
namespace win {
void SetDefaultDeviceScaleFactor(float scale) {
DCHECK_NE(0.f, scale);
g_device_scale_factor = scale;
}
Size GetDPI() {
gfx::Size GetDPI() {
static int dpi_x = 0;
static int dpi_y = 0;
static bool should_initialize = true;
@ -43,7 +45,7 @@ Size GetDPI() {
dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX);
dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY);
}
return Size(dpi_x, dpi_y);
return gfx::Size(dpi_x, dpi_y);
}
float GetDPIScale() {
@ -53,8 +55,6 @@ float GetDPIScale() {
return (dpi_scale <= 1.25f) ? 1.f : dpi_scale;
}
namespace win {
int GetSystemMetricsInDIP(int metric) {
// The system metrics always reflect the system DPI, not whatever scale we've
// forced or decided to use.
@ -63,4 +63,4 @@ int GetSystemMetricsInDIP(int metric) {
}
} // namespace win
} // namespace gfx
} // namespace display

@ -1,36 +1,35 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2012 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 UI_GFX_DPI_WIN_H_
#define UI_GFX_DPI_WIN_H_
#ifndef UI_DISPLAY_WIN_DPI_H_
#define UI_DISPLAY_WIN_DPI_H_
#include "ui/display/display_export.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h"
namespace gfx {
namespace display {
namespace win {
// Sets the device scale factor that will be used unless overridden on the
// command line by --force-device-scale-factor. If this is not called, and that
// flag is not used, the scale factor used by the DIP conversion functions below
// will be that returned by GetDPIScale().
GFX_EXPORT void SetDefaultDeviceScaleFactor(float scale);
DISPLAY_EXPORT void SetDefaultDeviceScaleFactor(float scale);
GFX_EXPORT Size GetDPI();
DISPLAY_EXPORT gfx::Size GetDPI();
// Gets the scale factor of the display. For example, if the display DPI is
// 96 then the scale factor is 1.0. This clamps scale factors <= 1.25 to 1.0 to
// maintain previous (non-DPI-aware) behavior where only the font size was
// boosted.
GFX_EXPORT float GetDPIScale();
namespace win {
DISPLAY_EXPORT float GetDPIScale();
// Win32's GetSystemMetrics uses pixel measures. This function calls
// GetSystemMetrics for the given |metric|, then converts the result to DIP.
GFX_EXPORT int GetSystemMetricsInDIP(int metric);
DISPLAY_EXPORT int GetSystemMetricsInDIP(int metric);
} // namespace win
} // namespace gfx
} // namespace display
#endif // UI_GFX_DPI_WIN_H_
#endif // UI_DISPLAY_WIN_DPI_H_

@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "ui/display/win/display_info.h"
#include "ui/display/win/dpi.h"
#include "ui/display/win/screen_win_display.h"
#include "ui/gfx/display.h"
#include "ui/gfx/geometry/point.h"
@ -16,7 +17,6 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/win/dpi.h"
namespace display {
namespace win {
@ -57,7 +57,7 @@ BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor,
reinterpret_cast<std::vector<DisplayInfo>*>(data);
DCHECK(display_infos);
display_infos->push_back(DisplayInfo(MonitorInfoFromHMONITOR(monitor),
gfx::GetDPIScale()));
GetDPIScale()));
return TRUE;
}
@ -80,12 +80,12 @@ ScreenWin::~ScreenWin() = default;
// static
gfx::Point ScreenWin::ScreenToDIPPoint(const gfx::Point& pixel_point) {
return ScaleToFlooredPoint(pixel_point, 1.0f / gfx::GetDPIScale());
return ScaleToFlooredPoint(pixel_point, 1.0f / GetDPIScale());
}
// static
gfx::Point ScreenWin::DIPToScreenPoint(const gfx::Point& dip_point) {
return ScaleToFlooredPoint(dip_point, gfx::GetDPIScale());
return ScaleToFlooredPoint(dip_point, GetDPIScale());
}
// static
@ -134,14 +134,14 @@ gfx::Size ScreenWin::ScreenToDIPSize(HWND hwnd,
const gfx::Size& size_in_pixels) {
// Always ceil sizes. Otherwise we may be leaving off part of the bounds.
// TODO(robliao): Get the scale factor from |hwnd|.
return ScaleToCeiledSize(size_in_pixels, 1.0f / gfx::GetDPIScale());
return ScaleToCeiledSize(size_in_pixels, 1.0f / GetDPIScale());
}
// static
gfx::Size ScreenWin::DIPToScreenSize(HWND hwnd, const gfx::Size& dip_size) {
// Always ceil sizes. Otherwise we may be leaving off part of the bounds.
// TODO(robliao): Get the scale factor from |hwnd|.
return ScaleToCeiledSize(dip_size, gfx::GetDPIScale());
return ScaleToCeiledSize(dip_size, GetDPIScale());
}
HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const {

@ -6,7 +6,6 @@
#include "ui/display/win/display_info.h"
#include "ui/display/win/screen_win.h"
#include "ui/gfx/win/dpi.h"
namespace display {
namespace win {

@ -17,12 +17,12 @@
#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/win/display_info.h"
#include "ui/display/win/dpi.h"
#include "ui/display/win/screen_win_display.h"
#include "ui/gfx/display.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/test/display_util.h"
#include "ui/gfx/win/dpi.h"
namespace display {
namespace win {
@ -198,7 +198,7 @@ class ScreenWinTest : public testing::Test {
void SetUp() override {
testing::Test::SetUp();
gfx::SetDefaultDeviceScaleFactor(1.0);
display::win::SetDefaultDeviceScaleFactor(1.0);
screen_win_initializer_.reset(new TestScreenWinManager());
SetUpScreen(screen_win_initializer_.get());
screen_win_initializer_->InitializeScreenWin();
@ -206,7 +206,7 @@ class ScreenWinTest : public testing::Test {
void TearDown() override {
screen_win_initializer_.reset();
gfx::SetDefaultDeviceScaleFactor(1.0);
display::win::SetDefaultDeviceScaleFactor(1.0);
testing::Test::TearDown();
}
@ -297,8 +297,8 @@ class ScreenWinTestSingleDisplay1_25x : public ScreenWinTest {
ScreenWinTestSingleDisplay1_25x() = default;
void SetUpScreen(TestScreenWinInitializer* initializer) override {
gfx::SetDefaultDeviceScaleFactor(1.25);
// Add Monitor of Scale Factor 1.0 since gfx::GetDPIScale performs the
display::win::SetDefaultDeviceScaleFactor(1.25);
// Add Monitor of Scale Factor 1.0 since display::GetDPIScale performs the
// clamping and not ScreenWin.
initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
gfx::Rect(0, 0, 1920, 1100),
@ -358,7 +358,7 @@ class ScreenWinTestSingleDisplay1_5x : public ScreenWinTest {
ScreenWinTestSingleDisplay1_5x() = default;
void SetUpScreen(TestScreenWinInitializer* initializer) override {
gfx::SetDefaultDeviceScaleFactor(1.5);
display::win::SetDefaultDeviceScaleFactor(1.5);
initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
gfx::Rect(0, 0, 1920, 1100),
L"primary",
@ -417,7 +417,7 @@ class ScreenWinTestSingleDisplay2x : public ScreenWinTest {
ScreenWinTestSingleDisplay2x() = default;
void SetUpScreen(TestScreenWinInitializer* initializer) override {
gfx::SetDefaultDeviceScaleFactor(2.0);
display::win::SetDefaultDeviceScaleFactor(2.0);
initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
gfx::Rect(0, 0, 1920, 1100),
L"primary",
@ -575,7 +575,7 @@ class ScreenWinTestTwoDisplays2x : public ScreenWinTest {
ScreenWinTestTwoDisplays2x() = default;
void SetUpScreen(TestScreenWinInitializer* initializer) override {
gfx::SetDefaultDeviceScaleFactor(2.0);
display::win::SetDefaultDeviceScaleFactor(2.0);
initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200),
gfx::Rect(0, 0, 1920, 1100),
L"primary",
@ -678,7 +678,7 @@ class ScreenWinTestTwoDisplays2x1xVirtualized : public ScreenWinTest {
ScreenWinTestTwoDisplays2x1xVirtualized() = default;
void SetUpScreen(TestScreenWinInitializer* initializer) override {
gfx::SetDefaultDeviceScaleFactor(2.0);
display::win::SetDefaultDeviceScaleFactor(2.0);
initializer->AddMonitor(gfx::Rect(0, 0, 3200, 1600),
gfx::Rect(0, 0, 3200, 1500),
L"primary",

@ -209,8 +209,6 @@ component("gfx") {
"win/direct_manipulation.h",
"win/direct_write.cc",
"win/direct_write.h",
"win/dpi.cc",
"win/dpi.h",
"win/hwnd_util.cc",
"win/hwnd_util.h",
"win/physical_size.cc",

@ -310,8 +310,6 @@
'win/direct_manipulation.h',
'win/direct_write.cc',
'win/direct_write.h',
'win/dpi.cc',
'win/dpi.h',
'win/hwnd_util.cc',
'win/hwnd_util.h',
"win/physical_size.cc",

@ -49,6 +49,7 @@ component("native_theme") {
"//base/third_party/dynamic_annotations",
"//skia",
"//ui/base",
"//ui/display",
"//ui/gfx",
"//ui/gfx/geometry",
"//ui/resources",

@ -2,6 +2,7 @@ include_rules = [
"+skia/ext",
"+third_party/skia",
"+ui/base",
"+ui/display",
"+ui/gfx",
"+ui/resources/grit/ui_resources.h",
]

@ -15,6 +15,7 @@
'../../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../../skia/skia.gyp:skia',
'../base/ui_base.gyp:ui_base',
'../display/display.gyp:display',
'../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',
'../resources/ui_resources.gyp:ui_resources',

@ -24,13 +24,13 @@
#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkShader.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/display/win/dpi.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/gdi_util.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/win/dpi.h"
#include "ui/native_theme/common_theme.h"
// This was removed from Winvers.h but is still used.
@ -203,7 +203,7 @@ gfx::Size NativeThemeWin::GetPartSize(Part part,
case kScrollbarVerticalThumb:
case kScrollbarHorizontalTrack:
case kScrollbarVerticalTrack: {
int size = gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
int size = display::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
if (size == 0)
size = 17;
return gfx::Size(size, size);

@ -34,6 +34,7 @@ component("views") {
"//skia",
"//third_party/icu",
"//ui/accessibility",
"//ui/display",
"//ui/latency_info",
"//ui/native_theme",
"//ui/resources",

@ -8,9 +8,9 @@
#include <uxtheme.h>
#include <Vssym32.h>
#include "ui/display/win/dpi.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/win/dpi.h"
#include "ui/native_theme/native_theme.h"
#include "ui/native_theme/native_theme_aura.h"
#include "ui/views/controls/menu/menu_item_view.h"
@ -29,7 +29,7 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
// Hack to get the separator to display correctly on Windows where we may
// have fractional scales. We move the separator 1 pixel down to ensure that
// it falls within the clipping rect which is scaled up.
float device_scale = gfx::GetDPIScale();
float device_scale = display::win::GetDPIScale();
bool is_fractional_scale =
(device_scale - static_cast<int>(device_scale) != 0);
if (is_fractional_scale && separator_bounds.y() == 0)

@ -17,13 +17,13 @@
#include "ui/base/win/shell.h"
#include "ui/compositor/compositor_constants.h"
#include "ui/compositor/paint_context.h"
#include "ui/display/win/dpi.h"
#include "ui/display/win/screen_win.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/path.h"
#include "ui/gfx/path_win.h"
#include "ui/gfx/win/dpi.h"
#include "ui/native_theme/native_theme_aura.h"
#include "ui/native_theme/native_theme_win.h"
#include "ui/views/corewm/tooltip_win.h"
@ -306,9 +306,9 @@ void DesktopWindowTreeHostWin::SetShape(SkRegion* native_region) {
// See crbug.com/410593.
SkRegion* shape = native_region;
SkRegion device_region;
if (gfx::GetDPIScale() > 1.0) {
if (display::win::GetDPIScale() > 1.0) {
shape = &device_region;
const float& scale = gfx::GetDPIScale();
const float& scale = display::win::GetDPIScale();
std::vector<SkIRect> rects;
for (SkRegion::Iterator it(*native_region); !it.done(); it.next()) {
const SkIRect& rect = it.rect();