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

Side by Side Diff: ui/aura/test/test_screen.cc

Issue 475533008: Revert of Rotate screen in response to accelerator or device orientation sensors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | « athena/system/system_ui_impl.cc ('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/aura/test/test_screen.h" 5 #include "ui/aura/test/test_screen.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/aura/env.h" 8 #include "ui/aura/env.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/aura/window_event_dispatcher.h" 10 #include "ui/aura/window_event_dispatcher.h"
11 #include "ui/aura/window_tree_host.h" 11 #include "ui/aura/window_tree_host.h"
12 #include "ui/gfx/geometry/size_conversions.h" 12 #include "ui/gfx/geometry/size_conversions.h"
13 #include "ui/gfx/native_widget_types.h" 13 #include "ui/gfx/native_widget_types.h"
14 #include "ui/gfx/rect_conversions.h" 14 #include "ui/gfx/rect_conversions.h"
15 #include "ui/gfx/screen.h" 15 #include "ui/gfx/screen.h"
16 16
17 namespace aura { 17 namespace aura {
18 18
19 namespace {
20
21 bool IsRotationPortrait(gfx::Display::Rotation rotation) {
22 return rotation == gfx::Display::ROTATE_90 ||
23 rotation == gfx::Display::ROTATE_270;
24 }
25
26 } // namespace
27
28 // static 19 // static
29 TestScreen* TestScreen::Create(const gfx::Size& size) { 20 TestScreen* TestScreen::Create(const gfx::Size& size) {
30 const gfx::Size kDefaultSize(800, 600); 21 const gfx::Size kDefaultSize(800, 600);
31 // Use (0,0) because the desktop aura tests are executed in 22 // Use (0,0) because the desktop aura tests are executed in
32 // native environment where the display's origin is (0,0). 23 // native environment where the display's origin is (0,0).
33 return new TestScreen(gfx::Rect(size.IsEmpty() ? kDefaultSize : size)); 24 return new TestScreen(gfx::Rect(size.IsEmpty() ? kDefaultSize : size));
34 } 25 }
35 26
36 // static 27 // static
37 TestScreen* TestScreen::CreateFullscreen() { 28 TestScreen* TestScreen::CreateFullscreen() {
(...skipping 11 matching lines...) Expand all
49 return host_; 40 return host_;
50 } 41 }
51 42
52 void TestScreen::SetDeviceScaleFactor(float device_scale_factor) { 43 void TestScreen::SetDeviceScaleFactor(float device_scale_factor) {
53 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); 44 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel());
54 display_.SetScaleAndBounds(device_scale_factor, bounds_in_pixel); 45 display_.SetScaleAndBounds(device_scale_factor, bounds_in_pixel);
55 host_->OnHostResized(bounds_in_pixel.size()); 46 host_->OnHostResized(bounds_in_pixel.size());
56 } 47 }
57 48
58 void TestScreen::SetDisplayRotation(gfx::Display::Rotation rotation) { 49 void TestScreen::SetDisplayRotation(gfx::Display::Rotation rotation) {
59 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel());
60 gfx::Rect new_bounds(bounds_in_pixel);
61 if (IsRotationPortrait(rotation) != IsRotationPortrait(display_.rotation())) {
62 new_bounds.set_width(bounds_in_pixel.height());
63 new_bounds.set_height(bounds_in_pixel.width());
64 }
65 display_.set_rotation(rotation); 50 display_.set_rotation(rotation);
66 display_.SetScaleAndBounds(display_.device_scale_factor(), new_bounds); 51 // TODO(oshima|mukai): Update the display_ as well.
67 host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform()); 52 host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform());
68 } 53 }
69 54
70 void TestScreen::SetUIScale(float ui_scale) { 55 void TestScreen::SetUIScale(float ui_scale) {
71 ui_scale_ = ui_scale; 56 ui_scale_ = ui_scale;
72 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); 57 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel());
73 gfx::Rect new_bounds = gfx::ToNearestRect( 58 gfx::Rect new_bounds = gfx::ToNearestRect(
74 gfx::ScaleRect(bounds_in_pixel, 1.0f / ui_scale)); 59 gfx::ScaleRect(bounds_in_pixel, 1.0f / ui_scale));
75 display_.SetScaleAndBounds(display_.device_scale_factor(), new_bounds); 60 display_.SetScaleAndBounds(display_.device_scale_factor(), new_bounds);
76 host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform()); 61 host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform());
77 } 62 }
78 63
79 gfx::Transform TestScreen::GetRotationTransform() const { 64 gfx::Transform TestScreen::GetRotationTransform() const {
80 gfx::Transform rotate; 65 gfx::Transform rotate;
66 float one_pixel = 1.0f / display_.device_scale_factor();
81 switch (display_.rotation()) { 67 switch (display_.rotation()) {
82 case gfx::Display::ROTATE_0: 68 case gfx::Display::ROTATE_0:
83 break; 69 break;
84 case gfx::Display::ROTATE_90: 70 case gfx::Display::ROTATE_90:
85 rotate.Translate(display_.bounds().height(), 0); 71 rotate.Translate(display_.bounds().height() - one_pixel, 0);
86 rotate.Rotate(90); 72 rotate.Rotate(90);
87 break; 73 break;
88 case gfx::Display::ROTATE_270: 74 case gfx::Display::ROTATE_270:
89 rotate.Translate(0, display_.bounds().width()); 75 rotate.Translate(0, display_.bounds().width() - one_pixel);
90 rotate.Rotate(270); 76 rotate.Rotate(270);
91 break; 77 break;
92 case gfx::Display::ROTATE_180: 78 case gfx::Display::ROTATE_180:
93 rotate.Translate(display_.bounds().width(), 79 rotate.Translate(display_.bounds().width() - one_pixel,
94 display_.bounds().height()); 80 display_.bounds().height() - one_pixel);
95 rotate.Rotate(180); 81 rotate.Rotate(180);
96 break; 82 break;
97 } 83 }
98 84
99 return rotate; 85 return rotate;
100 } 86 }
101 87
102 gfx::Transform TestScreen::GetUIScaleTransform() const { 88 gfx::Transform TestScreen::GetUIScaleTransform() const {
103 gfx::Transform ui_scale; 89 gfx::Transform ui_scale;
104 ui_scale.Scale(1.0f / ui_scale_, 1.0f / ui_scale_); 90 ui_scale.Scale(1.0f / ui_scale_, 1.0f / ui_scale_);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 152
167 TestScreen::TestScreen(const gfx::Rect& screen_bounds) 153 TestScreen::TestScreen(const gfx::Rect& screen_bounds)
168 : host_(NULL), 154 : host_(NULL),
169 ui_scale_(1.0f) { 155 ui_scale_(1.0f) {
170 static int64 synthesized_display_id = 2000; 156 static int64 synthesized_display_id = 2000;
171 display_.set_id(synthesized_display_id++); 157 display_.set_id(synthesized_display_id++);
172 display_.SetScaleAndBounds(1.0f, screen_bounds); 158 display_.SetScaleAndBounds(1.0f, screen_bounds);
173 } 159 }
174 160
175 } // namespace aura 161 } // namespace aura
OLDNEW
« no previous file with comments | « athena/system/system_ui_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698