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

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: Fixed Compositing browser tests high dpi Created 6 years, 8 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(kScaleFactorScales[*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
119 float GetImageScale(ScaleFactor scale_factor) { 120 float GetImageScale(ScaleFactor scale_factor) {
120 return kScaleFactorScales[scale_factor]; 121 #if defined(OS_WIN)
122 if (gfx::IsHighDPIEnabled())
123 return gfx::win::GetDeviceScaleFactor();
124 #endif
125 return GetScaleForScaleFactor(scale_factor);
121 } 126 }
122 127
123 bool IsScaleFactorSupported(ScaleFactor scale_factor) { 128 bool IsScaleFactorSupported(ScaleFactor scale_factor) {
124 DCHECK(g_supported_scale_factors != NULL); 129 DCHECK(g_supported_scale_factors != NULL);
125 return std::find(g_supported_scale_factors->begin(), 130 return std::find(g_supported_scale_factors->begin(),
126 g_supported_scale_factors->end(), 131 g_supported_scale_factors->end(),
127 scale_factor) != g_supported_scale_factors->end(); 132 scale_factor) != g_supported_scale_factors->end();
128 } 133 }
129 134
130 // Returns the scale factor closest to |scale| from the full list of factors. 135 // Returns the scale factor closest to |scale| from the full list of factors.
131 // Note that it does NOT rely on the list of supported scale factors. 136 // Note that it does NOT rely on the list of supported scale factors.
132 // Finding the closest match is inefficient and shouldn't be done frequently. 137 // Finding the closest match is inefficient and shouldn't be done frequently.
133 ScaleFactor FindClosestScaleFactorUnsafe(float scale) { 138 ScaleFactor FindClosestScaleFactorUnsafe(float scale) {
134 float smallest_diff = std::numeric_limits<float>::max(); 139 float smallest_diff = std::numeric_limits<float>::max();
135 ScaleFactor closest_match = SCALE_FACTOR_100P; 140 ScaleFactor closest_match = SCALE_FACTOR_100P;
136 for (int i = SCALE_FACTOR_100P; i < NUM_SCALE_FACTORS; ++i) { 141 for (int i = SCALE_FACTOR_100P; i < NUM_SCALE_FACTORS; ++i) {
137 const ScaleFactor scale_factor = static_cast<ScaleFactor>(i); 142 const ScaleFactor scale_factor = static_cast<ScaleFactor>(i);
138 float diff = std::abs(kScaleFactorScales[scale_factor] - scale); 143 float diff = std::abs(kScaleFactorScales[scale_factor] - scale);
139 if (diff < smallest_diff) { 144 if (diff < smallest_diff) {
140 closest_match = scale_factor; 145 closest_match = scale_factor;
141 smallest_diff = diff; 146 smallest_diff = diff;
142 } 147 }
143 } 148 }
144 return closest_match; 149 return closest_match;
145 } 150 }
146 151
152 float GetScaleForScaleFactor(ScaleFactor scale_factor) {
153 return kScaleFactorScales[scale_factor];
154 }
155
147 namespace test { 156 namespace test {
148 157
149 ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors( 158 ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors(
150 const std::vector<ui::ScaleFactor>& new_scale_factors) { 159 const std::vector<ui::ScaleFactor>& new_scale_factors) {
151 if (g_supported_scale_factors) { 160 if (g_supported_scale_factors) {
152 original_scale_factors_ = 161 original_scale_factors_ =
153 new std::vector<ScaleFactor>(*g_supported_scale_factors); 162 new std::vector<ScaleFactor>(*g_supported_scale_factors);
154 } else { 163 } else {
155 original_scale_factors_ = NULL; 164 original_scale_factors_ = NULL;
156 } 165 }
(...skipping 17 matching lines...) Expand all
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