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

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

Issue 11081007: Remove implicit flooring Scale() method from Point and Size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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/canvas.cc ('k') | ui/gfx/image/image_skia_operations.cc » ('j') | 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 #include "ui/gfx/size_conversions.h"
13 14
14 namespace gfx { 15 namespace gfx {
15 namespace { 16 namespace {
16 17
17 bool HasForceDeviceScaleFactor() { 18 bool HasForceDeviceScaleFactor() {
18 return CommandLine::ForCurrentProcess()->HasSwitch( 19 return CommandLine::ForCurrentProcess()->HasSwitch(
19 switches::kForceDeviceScaleFactor); 20 switches::kForceDeviceScaleFactor);
20 } 21 }
21 22
22 float GetForcedDeviceScaleFactorImpl() { 23 float GetForcedDeviceScaleFactorImpl() {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 81
81 void Display::SetScaleAndBounds( 82 void Display::SetScaleAndBounds(
82 float device_scale_factor, 83 float device_scale_factor,
83 const gfx::Rect& bounds_in_pixel) { 84 const gfx::Rect& bounds_in_pixel) {
84 Insets insets = bounds_.InsetsFrom(work_area_); 85 Insets insets = bounds_.InsetsFrom(work_area_);
85 if (!HasForceDeviceScaleFactor()) 86 if (!HasForceDeviceScaleFactor())
86 device_scale_factor_ = device_scale_factor; 87 device_scale_factor_ = device_scale_factor;
87 #if defined(USE_AURA) 88 #if defined(USE_AURA)
88 bounds_in_pixel_ = bounds_in_pixel; 89 bounds_in_pixel_ = bounds_in_pixel;
89 #endif 90 #endif
90 bounds_ = gfx::Rect( 91 bounds_ = gfx::Rect(gfx::ToFlooredSize(
91 bounds_in_pixel.size().Scale(1.0f / device_scale_factor_)); 92 bounds_in_pixel.size().Scale(1.0f / device_scale_factor_)));
92 UpdateWorkAreaFromInsets(insets); 93 UpdateWorkAreaFromInsets(insets);
93 } 94 }
94 95
95 void Display::SetSize(const gfx::Size& size_in_pixel) { 96 void Display::SetSize(const gfx::Size& size_in_pixel) {
96 SetScaleAndBounds( 97 SetScaleAndBounds(
97 device_scale_factor_, 98 device_scale_factor_,
98 #if defined(USE_AURA) 99 #if defined(USE_AURA)
99 gfx::Rect(bounds_in_pixel_.origin(), size_in_pixel)); 100 gfx::Rect(bounds_in_pixel_.origin(), size_in_pixel));
100 #else 101 #else
101 gfx::Rect(bounds_.origin(), size_in_pixel)); 102 gfx::Rect(bounds_.origin(), size_in_pixel));
102 #endif 103 #endif
103 } 104 }
104 105
105 void Display::UpdateWorkAreaFromInsets(const gfx::Insets& insets) { 106 void Display::UpdateWorkAreaFromInsets(const gfx::Insets& insets) {
106 work_area_ = bounds_; 107 work_area_ = bounds_;
107 work_area_.Inset(insets); 108 work_area_.Inset(insets);
108 } 109 }
109 110
110 gfx::Size Display::GetSizeInPixel() const { 111 gfx::Size Display::GetSizeInPixel() const {
111 return size().Scale(device_scale_factor_); 112 return gfx::ToFlooredSize(size().Scale(device_scale_factor_));
112 } 113 }
113 114
114 std::string Display::ToString() const { 115 std::string Display::ToString() const {
115 return base::StringPrintf("Display[%lld] bounds=%s, workarea=%s, scale=%f", 116 return base::StringPrintf("Display[%lld] bounds=%s, workarea=%s, scale=%f",
116 static_cast<long long int>(id_), 117 static_cast<long long int>(id_),
117 bounds_.ToString().c_str(), 118 bounds_.ToString().c_str(),
118 work_area_.ToString().c_str(), 119 work_area_.ToString().c_str(),
119 device_scale_factor_); 120 device_scale_factor_);
120 } 121 }
121 122
122 } // namespace gfx 123 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/gfx/image/image_skia_operations.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698