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

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

Issue 10546158: Remove --default-device-scale-factor (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
« no previous file with comments | « ui/gfx/display.h ('k') | no next file » | 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/gfx/display.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 bool HasForceDeviceScaleFactor() {
18 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 18 return CommandLine::ForCurrentProcess()->HasSwitch(
19 switches::kForceDeviceScaleFactor);
20 }
21
22 float GetForcedDeviceScaleFactorImpl() {
19 double scale_in_double = 1.0; 23 double scale_in_double = 1.0;
20 if (command_line.HasSwitch(switches::kDefaultDeviceScaleFactor)) { 24 if (HasForceDeviceScaleFactor()) {
21 std::string value = 25 std::string value = CommandLine::ForCurrentProcess()->
22 command_line.GetSwitchValueASCII(switches::kDefaultDeviceScaleFactor); 26 GetSwitchValueASCII(switches::kForceDeviceScaleFactor);
23 if (!base::StringToDouble(value, &scale_in_double)) 27 if (!base::StringToDouble(value, &scale_in_double))
24 LOG(ERROR) << "Failed to parse the deafult device scale factor:" << value; 28 LOG(ERROR) << "Failed to parse the deafult device scale factor:" << value;
25 } 29 }
26 return static_cast<float>(scale_in_double); 30 return static_cast<float>(scale_in_double);
27 } 31 }
28 32
29 } // namespace 33 } // namespace
30 34
31 // static 35 // static
32 float Display::GetDefaultDeviceScaleFactor() { 36 float Display::GetForcedDeviceScaleFactor() {
33 static const float kDefaultDeviceScaleFactor = 37 static const float kForcedDeviceScaleFactor =
34 GetDefaultDeviceScaleFactorImpl(); 38 GetForcedDeviceScaleFactorImpl();
35 return kDefaultDeviceScaleFactor; 39 return kForcedDeviceScaleFactor;
36 } 40 }
37 41
38 Display::Display() 42 Display::Display()
39 : id_(-1), 43 : id_(-1),
40 device_scale_factor_(GetDefaultDeviceScaleFactor()) { 44 device_scale_factor_(GetForcedDeviceScaleFactor()) {
41 } 45 }
42 46
43 Display::Display(int id) 47 Display::Display(int id)
44 : id_(id), 48 : id_(id),
45 device_scale_factor_(GetDefaultDeviceScaleFactor()) { 49 device_scale_factor_(GetForcedDeviceScaleFactor()) {
46 } 50 }
47 51
48 Display::Display(int id, const gfx::Rect& bounds) 52 Display::Display(int id, const gfx::Rect& bounds)
49 : id_(id), 53 : id_(id),
50 bounds_(bounds), 54 bounds_(bounds),
51 work_area_(bounds), 55 work_area_(bounds),
52 device_scale_factor_(GetDefaultDeviceScaleFactor()) { 56 device_scale_factor_(GetForcedDeviceScaleFactor()) {
53 #if defined(USE_AURA) 57 #if defined(USE_AURA)
54 SetScaleAndBounds(device_scale_factor_, bounds); 58 SetScaleAndBounds(device_scale_factor_, bounds);
55 #endif 59 #endif
56 } 60 }
57 61
58 Display::~Display() { 62 Display::~Display() {
59 } 63 }
60 64
61 Insets Display::GetWorkAreaInsets() const { 65 Insets Display::GetWorkAreaInsets() const {
62 return gfx::Insets(work_area_.y() - bounds_.y(), 66 return gfx::Insets(work_area_.y() - bounds_.y(),
63 work_area_.x() - bounds_.x(), 67 work_area_.x() - bounds_.x(),
64 bounds_.bottom() - work_area_.bottom(), 68 bounds_.bottom() - work_area_.bottom(),
65 bounds_.right() - work_area_.right()); 69 bounds_.right() - work_area_.right());
66 } 70 }
67 71
68 void Display::SetScaleAndBounds( 72 void Display::SetScaleAndBounds(
69 float device_scale_factor, 73 float device_scale_factor,
70 const gfx::Rect& bounds_in_pixel) { 74 const gfx::Rect& bounds_in_pixel) {
71 Insets insets = bounds_.InsetsFrom(work_area_); 75 Insets insets = bounds_.InsetsFrom(work_area_);
72 device_scale_factor_ = device_scale_factor; 76 if (!HasForceDeviceScaleFactor())
77 device_scale_factor_ = device_scale_factor;
73 #if defined(USE_AURA) 78 #if defined(USE_AURA)
74 bounds_in_pixel_ = bounds_in_pixel; 79 bounds_in_pixel_ = bounds_in_pixel;
75 #endif 80 #endif
76 // TODO(oshima): For m19, work area/display bounds that chrome/webapps sees 81 // 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 82 // has (0, 0) origin because it's simpler and enough. Fix this when
78 // real multi display support is implemented. 83 // real multi display support is implemented.
79 bounds_ = gfx::Rect( 84 bounds_ = gfx::Rect(
80 bounds_in_pixel.size().Scale(1.0f / device_scale_factor_)); 85 bounds_in_pixel.size().Scale(1.0f / device_scale_factor_));
81 UpdateWorkAreaFromInsets(insets); 86 UpdateWorkAreaFromInsets(insets);
82 } 87 }
(...skipping 19 matching lines...) Expand all
102 107
103 std::string Display::ToString() const { 108 std::string Display::ToString() const {
104 return base::StringPrintf("Display[%d] bounds=%s, workarea=%s, scale=%f", 109 return base::StringPrintf("Display[%d] bounds=%s, workarea=%s, scale=%f",
105 id_, 110 id_,
106 bounds_.ToString().c_str(), 111 bounds_.ToString().c_str(),
107 work_area_.ToString().c_str(), 112 work_area_.ToString().c_str(),
108 device_scale_factor_); 113 device_scale_factor_);
109 } 114 }
110 115
111 } // namespace gfx 116 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/display.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698