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

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

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

Powered by Google App Engine
This is Rietveld 408576698