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

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

Issue 10540091: Rename gfx::Monitor to gfx::Display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
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/monitor.h" 5 #include "ui/gfx/display.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "ui/base/ui_base_switches.h" 11 #include "ui/base/ui_base_switches.h"
12 #include "ui/gfx/insets.h" 12 #include "ui/gfx/insets.h"
13 13
14 namespace gfx { 14 namespace gfx {
15 namespace { 15 namespace {
16 16
17 float GetDefaultDeviceScaleFactorImpl() { 17 float GetDefaultDeviceScaleFactorImpl() {
18 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 18 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
19 double scale_in_double = 1.0; 19 double scale_in_double = 1.0;
20 if (command_line.HasSwitch(switches::kDefaultDeviceScaleFactor)) { 20 if (command_line.HasSwitch(switches::kDefaultDeviceScaleFactor)) {
21 std::string value = 21 std::string value =
22 command_line.GetSwitchValueASCII(switches::kDefaultDeviceScaleFactor); 22 command_line.GetSwitchValueASCII(switches::kDefaultDeviceScaleFactor);
23 if (!base::StringToDouble(value, &scale_in_double)) 23 if (!base::StringToDouble(value, &scale_in_double))
24 LOG(ERROR) << "Failed to parse the deafult device scale factor:" << value; 24 LOG(ERROR) << "Failed to parse the deafult device scale factor:" << value;
25 } 25 }
26 return static_cast<float>(scale_in_double); 26 return static_cast<float>(scale_in_double);
27 } 27 }
28 28
29 } // namespace 29 } // namespace
30 30
31 // static 31 // static
32 float Monitor::GetDefaultDeviceScaleFactor() { 32 float Display::GetDefaultDeviceScaleFactor() {
33 static const float kDefaultDeviceScaleFactor = 33 static const float kDefaultDeviceScaleFactor =
34 GetDefaultDeviceScaleFactorImpl(); 34 GetDefaultDeviceScaleFactorImpl();
35 return kDefaultDeviceScaleFactor; 35 return kDefaultDeviceScaleFactor;
36 } 36 }
37 37
38 Monitor::Monitor() 38 Display::Display()
39 : id_(-1), 39 : id_(-1),
40 device_scale_factor_(GetDefaultDeviceScaleFactor()) { 40 device_scale_factor_(GetDefaultDeviceScaleFactor()) {
41 } 41 }
42 42
43 Monitor::Monitor(int id) 43 Display::Display(int id)
44 : id_(id), 44 : id_(id),
45 device_scale_factor_(GetDefaultDeviceScaleFactor()) { 45 device_scale_factor_(GetDefaultDeviceScaleFactor()) {
46 } 46 }
47 47
48 Monitor::Monitor(int id, const gfx::Rect& bounds) 48 Display::Display(int id, const gfx::Rect& bounds)
49 : id_(id), 49 : id_(id),
50 bounds_(bounds), 50 bounds_(bounds),
51 work_area_(bounds), 51 work_area_(bounds),
52 device_scale_factor_(GetDefaultDeviceScaleFactor()) { 52 device_scale_factor_(GetDefaultDeviceScaleFactor()) {
53 #if defined(USE_AURA) 53 #if defined(USE_AURA)
54 SetScaleAndBounds(device_scale_factor_, bounds); 54 SetScaleAndBounds(device_scale_factor_, bounds);
55 #endif 55 #endif
56 } 56 }
57 57
58 Monitor::~Monitor() { 58 Display::~Display() {
59 } 59 }
60 60
61 Insets Monitor::GetWorkAreaInsets() const { 61 Insets Display::GetWorkAreaInsets() const {
62 return gfx::Insets(work_area_.y() - bounds_.y(), 62 return gfx::Insets(work_area_.y() - bounds_.y(),
63 work_area_.x() - bounds_.x(), 63 work_area_.x() - bounds_.x(),
64 bounds_.bottom() - work_area_.bottom(), 64 bounds_.bottom() - work_area_.bottom(),
65 bounds_.right() - work_area_.right()); 65 bounds_.right() - work_area_.right());
66 } 66 }
67 67
68 void Monitor::SetScaleAndBounds( 68 void Display::SetScaleAndBounds(
69 float device_scale_factor, 69 float device_scale_factor,
70 const gfx::Rect& bounds_in_pixel) { 70 const gfx::Rect& bounds_in_pixel) {
71 Insets insets = bounds_.InsetsFrom(work_area_); 71 Insets insets = bounds_.InsetsFrom(work_area_);
72 device_scale_factor_ = device_scale_factor; 72 device_scale_factor_ = device_scale_factor;
73 #if defined(USE_AURA) 73 #if defined(USE_AURA)
74 bounds_in_pixel_ = bounds_in_pixel; 74 bounds_in_pixel_ = bounds_in_pixel;
75 #endif 75 #endif
76 // TODO(oshima): For m19, work area/monitor bounds that chrome/webapps sees 76 // TODO(oshima): For m19, work area/display bounds that chrome/webapps sees
77 // has (0, 0) origin because it's simpler and enough. Fix this when 77 // has (0, 0) origin because it's simpler and enough. Fix this when
78 // real multi monitor support is implemented. 78 // real multi display support is implemented.
79 bounds_ = gfx::Rect( 79 bounds_ = gfx::Rect(
80 bounds_in_pixel.size().Scale(1.0f / device_scale_factor_)); 80 bounds_in_pixel.size().Scale(1.0f / device_scale_factor_));
81 UpdateWorkAreaFromInsets(insets); 81 UpdateWorkAreaFromInsets(insets);
82 } 82 }
83 83
84 void Monitor::SetSize(const gfx::Size& size_in_pixel) { 84 void Display::SetSize(const gfx::Size& size_in_pixel) {
85 SetScaleAndBounds( 85 SetScaleAndBounds(
86 device_scale_factor_, 86 device_scale_factor_,
87 #if defined(USE_AURA) 87 #if defined(USE_AURA)
88 gfx::Rect(bounds_in_pixel_.origin(), size_in_pixel)); 88 gfx::Rect(bounds_in_pixel_.origin(), size_in_pixel));
89 #else 89 #else
90 gfx::Rect(bounds_.origin(), size_in_pixel)); 90 gfx::Rect(bounds_.origin(), size_in_pixel));
91 #endif 91 #endif
92 } 92 }
93 93
94 void Monitor::UpdateWorkAreaFromInsets(const gfx::Insets& insets) { 94 void Display::UpdateWorkAreaFromInsets(const gfx::Insets& insets) {
95 work_area_ = bounds_; 95 work_area_ = bounds_;
96 work_area_.Inset(insets); 96 work_area_.Inset(insets);
97 } 97 }
98 98
99 gfx::Size Monitor::GetSizeInPixel() const { 99 gfx::Size Display::GetSizeInPixel() const {
100 return size().Scale(device_scale_factor_); 100 return size().Scale(device_scale_factor_);
101 } 101 }
102 102
103 std::string Monitor::ToString() const { 103 std::string Display::ToString() const {
104 return base::StringPrintf("Monitor[%d] bounds=%s, workarea=%s, scale=%f", 104 return base::StringPrintf("Display[%d] bounds=%s, workarea=%s, scale=%f",
105 id_, 105 id_,
106 bounds_.ToString().c_str(), 106 bounds_.ToString().c_str(),
107 work_area_.ToString().c_str(), 107 work_area_.ToString().c_str(),
108 device_scale_factor_); 108 device_scale_factor_);
109 } 109 }
110 110
111 } // namespace gfx 111 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/display.h ('k') | ui/gfx/display_unittest.cc » ('j') | ui/gfx/screen.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698