Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: ui/base/layout.cc

Issue 211493009: Ensure that extension resources are loaded with the correct scaling applied on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unnecessary include Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/layout.h ('k') | ui/base/resource/resource_bundle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/base/layout.h" 5 #include "ui/base/layout.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "ui/base/touch/touch_device.h" 15 #include "ui/base/touch/touch_device.h"
16 #include "ui/base/ui_base_switches.h" 16 #include "ui/base/ui_base_switches.h"
17 #include "ui/gfx/display.h" 17 #include "ui/gfx/display.h"
18 #include "ui/gfx/image/image_skia.h" 18 #include "ui/gfx/image/image_skia.h"
19 #include "ui/gfx/screen.h" 19 #include "ui/gfx/screen.h"
20 20
21 #if defined(OS_WIN) 21 #if defined(OS_WIN)
22 #include "base/win/metro.h" 22 #include "base/win/metro.h"
23 #include "ui/gfx/win/dpi.h"
23 #include <Windows.h> 24 #include <Windows.h>
24 #endif // defined(OS_WIN) 25 #endif // defined(OS_WIN)
25 26
26 namespace ui { 27 namespace ui {
27 28
28 namespace { 29 namespace {
29 30
30 bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){ 31 bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){
31 return GetImageScale(lhs) < GetImageScale(rhs); 32 return GetImageScale(lhs) < GetImageScale(rhs);
32 } 33 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors); 84 g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors);
84 std::sort(g_supported_scale_factors->begin(), 85 std::sort(g_supported_scale_factors->begin(),
85 g_supported_scale_factors->end(), 86 g_supported_scale_factors->end(),
86 ScaleFactorComparator); 87 ScaleFactorComparator);
87 88
88 // Set ImageSkia's supported scales. 89 // Set ImageSkia's supported scales.
89 std::vector<float> scales; 90 std::vector<float> scales;
90 for (std::vector<ScaleFactor>::const_iterator it = 91 for (std::vector<ScaleFactor>::const_iterator it =
91 g_supported_scale_factors->begin(); 92 g_supported_scale_factors->begin();
92 it != g_supported_scale_factors->end(); ++it) { 93 it != g_supported_scale_factors->end(); ++it) {
93 scales.push_back(GetImageScale(*it)); 94 scales.push_back(GetImageScaleForScaleFactor(*it));
94 } 95 }
95 gfx::ImageSkia::SetSupportedScales(scales); 96 gfx::ImageSkia::SetSupportedScales(scales);
96 } 97 }
97 98
98 const std::vector<ScaleFactor>& GetSupportedScaleFactors() { 99 const std::vector<ScaleFactor>& GetSupportedScaleFactors() {
99 DCHECK(g_supported_scale_factors != NULL); 100 DCHECK(g_supported_scale_factors != NULL);
100 return *g_supported_scale_factors; 101 return *g_supported_scale_factors;
101 } 102 }
102 103
103 ScaleFactor GetSupportedScaleFactor(float scale) { 104 ScaleFactor GetSupportedScaleFactor(float scale) {
104 DCHECK(g_supported_scale_factors != NULL); 105 DCHECK(g_supported_scale_factors != NULL);
105 ScaleFactor closest_match = SCALE_FACTOR_100P; 106 ScaleFactor closest_match = SCALE_FACTOR_100P;
106 float smallest_diff = std::numeric_limits<float>::max(); 107 float smallest_diff = std::numeric_limits<float>::max();
107 for (size_t i = 0; i < g_supported_scale_factors->size(); ++i) { 108 for (size_t i = 0; i < g_supported_scale_factors->size(); ++i) {
108 ScaleFactor scale_factor = (*g_supported_scale_factors)[i]; 109 ScaleFactor scale_factor = (*g_supported_scale_factors)[i];
109 float diff = std::abs(kScaleFactorScales[scale_factor] - scale); 110 float diff = std::abs(kScaleFactorScales[scale_factor] - scale);
110 if (diff < smallest_diff) { 111 if (diff < smallest_diff) {
111 closest_match = scale_factor; 112 closest_match = scale_factor;
112 smallest_diff = diff; 113 smallest_diff = diff;
113 } 114 }
114 } 115 }
115 DCHECK_NE(closest_match, SCALE_FACTOR_NONE); 116 DCHECK_NE(closest_match, SCALE_FACTOR_NONE);
116 return closest_match; 117 return closest_match;
117 } 118 }
118 119
120 float GetImageScaleForScaleFactor(ScaleFactor scale_factor) {
121 return kScaleFactorScales[scale_factor];
sky 2014/03/26 20:43:27 Is it possible to make this private too? It's conf
ananta 2014/03/26 21:49:27 As per our discussion, moved the kScaleFactorScale
122 }
123
119 float GetImageScale(ScaleFactor scale_factor) { 124 float GetImageScale(ScaleFactor scale_factor) {
120 return kScaleFactorScales[scale_factor]; 125 #if defined(OS_WIN)
126 if (gfx::IsHighDPIEnabled())
127 return gfx::win::GetDeviceScaleFactor();
128 #endif
129 return GetImageScaleForScaleFactor(scale_factor);
121 } 130 }
122 131
123 bool IsScaleFactorSupported(ScaleFactor scale_factor) { 132 bool IsScaleFactorSupported(ScaleFactor scale_factor) {
124 DCHECK(g_supported_scale_factors != NULL); 133 DCHECK(g_supported_scale_factors != NULL);
125 return std::find(g_supported_scale_factors->begin(), 134 return std::find(g_supported_scale_factors->begin(),
126 g_supported_scale_factors->end(), 135 g_supported_scale_factors->end(),
127 scale_factor) != g_supported_scale_factors->end(); 136 scale_factor) != g_supported_scale_factors->end();
128 } 137 }
129 138
130 // Returns the scale factor closest to |scale| from the full list of factors. 139 // Returns the scale factor closest to |scale| from the full list of factors.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); 183 gfx::Screen* screen = gfx::Screen::GetScreenFor(view);
175 if (screen->IsDIPEnabled()) { 184 if (screen->IsDIPEnabled()) {
176 gfx::Display display = screen->GetDisplayNearestWindow(view); 185 gfx::Display display = screen->GetDisplayNearestWindow(view);
177 return GetSupportedScaleFactor(display.device_scale_factor()); 186 return GetSupportedScaleFactor(display.device_scale_factor());
178 } 187 }
179 return ui::SCALE_FACTOR_100P; 188 return ui::SCALE_FACTOR_100P;
180 } 189 }
181 #endif // !defined(OS_MACOSX) 190 #endif // !defined(OS_MACOSX)
182 191
183 } // namespace ui 192 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/layout.h ('k') | ui/base/resource/resource_bundle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698