| OLD | NEW |
| 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/monitor.h" | 5 #include "ui/gfx/monitor.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" |
| 10 #include "base/stringprintf.h" |
| 11 #include "ui/base/ui_base_switches.h" |
| 7 #include "ui/gfx/insets.h" | 12 #include "ui/gfx/insets.h" |
| 8 #include "base/stringprintf.h" | |
| 9 | 13 |
| 10 namespace gfx { | 14 namespace gfx { |
| 15 namespace { |
| 11 | 16 |
| 12 Monitor::Monitor() : id_(-1), device_scale_factor_(1.0) { | 17 float GetDefaultDeviceScaleFactorImpl() { |
| 18 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 19 double scale_in_double = 1.0; |
| 20 if (command_line.HasSwitch(switches::kDefaultDeviceScaleFactor)) { |
| 21 std::string value = |
| 22 command_line.GetSwitchValueASCII(switches::kDefaultDeviceScaleFactor); |
| 23 if (!base::StringToDouble(value, &scale_in_double)) |
| 24 LOG(ERROR) << "Failed to parse the deafult device scale factor:" << value; |
| 25 } |
| 26 return static_cast<float>(scale_in_double); |
| 13 } | 27 } |
| 14 | 28 |
| 15 Monitor::Monitor(int id) : id_(id), device_scale_factor_(1.0) { | 29 } // namespace |
| 30 |
| 31 // static |
| 32 float Monitor::GetDefaultDeviceScaleFactor() { |
| 33 static const float kDefaultDeviceScaleFactor = |
| 34 GetDefaultDeviceScaleFactorImpl(); |
| 35 return kDefaultDeviceScaleFactor; |
| 36 } |
| 37 |
| 38 Monitor::Monitor() |
| 39 : id_(-1), |
| 40 device_scale_factor_(GetDefaultDeviceScaleFactor()) { |
| 41 } |
| 42 |
| 43 Monitor::Monitor(int id) |
| 44 : id_(id), |
| 45 device_scale_factor_(GetDefaultDeviceScaleFactor()) { |
| 16 } | 46 } |
| 17 | 47 |
| 18 Monitor::Monitor(int id, const gfx::Rect& bounds) | 48 Monitor::Monitor(int id, const gfx::Rect& bounds) |
| 19 : id_(id), | 49 : id_(id), |
| 20 bounds_(bounds), | 50 bounds_(bounds), |
| 21 work_area_(bounds), | 51 work_area_(bounds), |
| 22 device_scale_factor_(1.0) { | 52 device_scale_factor_(GetDefaultDeviceScaleFactor()) { |
| 23 #if defined(USE_ASH) | 53 #if defined(USE_ASH) |
| 24 SetScaleAndBounds(device_scale_factor_, bounds); | 54 SetScaleAndBounds(device_scale_factor_, bounds); |
| 25 #endif | 55 #endif |
| 26 } | 56 } |
| 27 | 57 |
| 28 Monitor::~Monitor() { | 58 Monitor::~Monitor() { |
| 29 } | 59 } |
| 30 | 60 |
| 31 void Monitor::SetScaleAndBounds( | 61 void Monitor::SetScaleAndBounds( |
| 32 float device_scale_factor, | 62 float device_scale_factor, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 95 |
| 66 std::string Monitor::ToString() const { | 96 std::string Monitor::ToString() const { |
| 67 return base::StringPrintf("Monitor[%d] bounds=%s, workarea=%s, scale=%f", | 97 return base::StringPrintf("Monitor[%d] bounds=%s, workarea=%s, scale=%f", |
| 68 id_, | 98 id_, |
| 69 bounds_.ToString().c_str(), | 99 bounds_.ToString().c_str(), |
| 70 work_area_.ToString().c_str(), | 100 work_area_.ToString().c_str(), |
| 71 device_scale_factor_); | 101 device_scale_factor_); |
| 72 } | 102 } |
| 73 | 103 |
| 74 } // namespace gfx | 104 } // namespace gfx |
| OLD | NEW |