| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/gfx/monitor.h" | |
| 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" | |
| 12 #include "ui/gfx/insets.h" | |
| 13 | |
| 14 namespace gfx { | |
| 15 namespace { | |
| 16 | |
| 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); | |
| 27 } | |
| 28 | |
| 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()) { | |
| 46 } | |
| 47 | |
| 48 Monitor::Monitor(int id, const gfx::Rect& bounds) | |
| 49 : id_(id), | |
| 50 bounds_(bounds), | |
| 51 work_area_(bounds), | |
| 52 device_scale_factor_(GetDefaultDeviceScaleFactor()) { | |
| 53 #if defined(USE_AURA) | |
| 54 SetScaleAndBounds(device_scale_factor_, bounds); | |
| 55 #endif | |
| 56 } | |
| 57 | |
| 58 Monitor::~Monitor() { | |
| 59 } | |
| 60 | |
| 61 Insets Monitor::GetWorkAreaInsets() const { | |
| 62 return gfx::Insets(work_area_.y() - bounds_.y(), | |
| 63 work_area_.x() - bounds_.x(), | |
| 64 bounds_.bottom() - work_area_.bottom(), | |
| 65 bounds_.right() - work_area_.right()); | |
| 66 } | |
| 67 | |
| 68 void Monitor::SetScaleAndBounds( | |
| 69 float device_scale_factor, | |
| 70 const gfx::Rect& bounds_in_pixel) { | |
| 71 Insets insets = bounds_.InsetsFrom(work_area_); | |
| 72 device_scale_factor_ = device_scale_factor; | |
| 73 #if defined(USE_AURA) | |
| 74 bounds_in_pixel_ = bounds_in_pixel; | |
| 75 #endif | |
| 76 // TODO(oshima): For m19, work area/monitor bounds that chrome/webapps sees | |
| 77 // has (0, 0) origin because it's simpler and enough. Fix this when | |
| 78 // real multi monitor support is implemented. | |
| 79 bounds_ = gfx::Rect( | |
| 80 bounds_in_pixel.size().Scale(1.0f / device_scale_factor_)); | |
| 81 UpdateWorkAreaFromInsets(insets); | |
| 82 } | |
| 83 | |
| 84 void Monitor::SetSize(const gfx::Size& size_in_pixel) { | |
| 85 SetScaleAndBounds( | |
| 86 device_scale_factor_, | |
| 87 #if defined(USE_AURA) | |
| 88 gfx::Rect(bounds_in_pixel_.origin(), size_in_pixel)); | |
| 89 #else | |
| 90 gfx::Rect(bounds_.origin(), size_in_pixel)); | |
| 91 #endif | |
| 92 } | |
| 93 | |
| 94 void Monitor::UpdateWorkAreaFromInsets(const gfx::Insets& insets) { | |
| 95 work_area_ = bounds_; | |
| 96 work_area_.Inset(insets); | |
| 97 } | |
| 98 | |
| 99 gfx::Size Monitor::GetSizeInPixel() const { | |
| 100 return size().Scale(device_scale_factor_); | |
| 101 } | |
| 102 | |
| 103 std::string Monitor::ToString() const { | |
| 104 return base::StringPrintf("Monitor[%d] bounds=%s, workarea=%s, scale=%f", | |
| 105 id_, | |
| 106 bounds_.ToString().c_str(), | |
| 107 work_area_.ToString().c_str(), | |
| 108 device_scale_factor_); | |
| 109 } | |
| 110 | |
| 111 } // namespace gfx | |
| OLD | NEW |