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

Side by Side Diff: ui/gfx/display.cc

Issue 1563183008: Added capability on Windows to get the physical dimensions of your attached monitors. Also added th… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 11 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
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/gfx/display.h" 5 #include "ui/gfx/display.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 #include "ui/gfx/geometry/insets.h" 15 #include "ui/gfx/geometry/insets.h"
15 #include "ui/gfx/geometry/point_conversions.h" 16 #include "ui/gfx/geometry/point_conversions.h"
16 #include "ui/gfx/geometry/point_f.h" 17 #include "ui/gfx/geometry/point_f.h"
17 #include "ui/gfx/geometry/size_conversions.h" 18 #include "ui/gfx/geometry/size_conversions.h"
18 #include "ui/gfx/switches.h" 19 #include "ui/gfx/switches.h"
19 20
21 #if defined(OS_WIN)
22 #include "ui/gfx/screen_win.h"
23 #include "ui/gfx/win/physical_size.h"
24 #endif
25
20 namespace gfx { 26 namespace gfx {
21 namespace { 27 namespace {
22 28
23 // This variable tracks whether the forced device scale factor switch needs to 29 // This variable tracks whether the forced device scale factor switch needs to
24 // be read from the command line, i.e. if it is set to -1 then the command line 30 // be read from the command line, i.e. if it is set to -1 then the command line
25 // is checked. 31 // is checked.
26 int g_has_forced_device_scale_factor = -1; 32 int g_has_forced_device_scale_factor = -1;
27 33
28 // This variable caches the forced device scale factor value which is read off 34 // This variable caches the forced device scale factor value which is read off
29 // the command line. If the cache is invalidated by setting this variable to 35 // the command line. If the cache is invalidated by setting this variable to
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 bounds_.ToString().c_str(), 194 bounds_.ToString().c_str(),
189 work_area_.ToString().c_str(), 195 work_area_.ToString().c_str(),
190 device_scale_factor_, 196 device_scale_factor_,
191 IsInternal() ? "internal" : "external"); 197 IsInternal() ? "internal" : "external");
192 } 198 }
193 199
194 bool Display::IsInternal() const { 200 bool Display::IsInternal() const {
195 return is_valid() && (id_ == internal_display_id_); 201 return is_valid() && (id_ == internal_display_id_);
196 } 202 }
197 203
204 bool Display::GetPhysicalSize(int* width_mm, int* height_mm) const {
205 #if defined(OS_WIN)
206 std::vector<gfx::DisplaySize> display_sizes;
207 gfx::GetPhysicalSizeForDisplays(&display_sizes);
208 for (size_t i = 0; i < display_sizes.size(); ++i) {
scottmg 2016/01/09 01:00:05 for (const auto& display_size : display_sizes) ?
Bret 2016/01/12 00:23:46 Done.
209 const gfx::DisplaySize& display_size = display_sizes[i];
210 int64_t interface_id =
211 ScreenWin::GenerateDisplayId(display_size.display_name);
212 if (interface_id == id_) {
213 *width_mm = display_size.width_mm;
214 *height_mm = display_size.height_mm;
215 return true;
216 }
217 }
218 return false;
219 #else
220 // unimplemented
scottmg 2016/01/09 01:00:05 "Unimplemented." or just delete this line, since t
Bret 2016/01/12 00:23:46 Done.
221 NOTREACHED();
222 #endif
223 }
224
198 // static 225 // static
199 int64_t Display::InternalDisplayId() { 226 int64_t Display::InternalDisplayId() {
200 DCHECK_NE(kInvalidDisplayID, internal_display_id_); 227 DCHECK_NE(kInvalidDisplayID, internal_display_id_);
201 return internal_display_id_; 228 return internal_display_id_;
202 } 229 }
203 230
204 // static 231 // static
205 void Display::SetInternalDisplayId(int64_t internal_display_id) { 232 void Display::SetInternalDisplayId(int64_t internal_display_id) {
206 internal_display_id_ = internal_display_id; 233 internal_display_id_ = internal_display_id;
207 } 234 }
208 235
209 // static 236 // static
210 bool Display::IsInternalDisplayId(int64_t display_id) { 237 bool Display::IsInternalDisplayId(int64_t display_id) {
211 DCHECK_NE(kInvalidDisplayID, display_id); 238 DCHECK_NE(kInvalidDisplayID, display_id);
212 return HasInternalDisplay() && internal_display_id_ == display_id; 239 return HasInternalDisplay() && internal_display_id_ == display_id;
213 } 240 }
214 241
215 // static 242 // static
216 bool Display::HasInternalDisplay() { 243 bool Display::HasInternalDisplay() {
217 return internal_display_id_ != kInvalidDisplayID; 244 return internal_display_id_ != kInvalidDisplayID;
218 } 245 }
219 246
220 } // namespace gfx 247 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698