| OLD | NEW |
| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
| 13 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
| 14 #include "ui/base/ime/input_method.h" | 14 #include "ui/base/ime/input_method.h" |
| 15 #include "ui/display/screen.h" |
| 15 #include "ui/gfx/geometry/rect_conversions.h" | 16 #include "ui/gfx/geometry/rect_conversions.h" |
| 16 #include "ui/gfx/geometry/size_conversions.h" | 17 #include "ui/gfx/geometry/size_conversions.h" |
| 17 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 18 #include "ui/gfx/screen.h" | |
| 19 | 19 |
| 20 namespace aura { | 20 namespace aura { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 bool IsRotationPortrait(gfx::Display::Rotation rotation) { | 24 bool IsRotationPortrait(display::Display::Rotation rotation) { |
| 25 return rotation == gfx::Display::ROTATE_90 || | 25 return rotation == display::Display::ROTATE_90 || |
| 26 rotation == gfx::Display::ROTATE_270; | 26 rotation == display::Display::ROTATE_270; |
| 27 } | 27 } |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 TestScreen* TestScreen::Create(const gfx::Size& size) { | 32 TestScreen* TestScreen::Create(const gfx::Size& size) { |
| 33 const gfx::Size kDefaultSize(800, 600); | 33 const gfx::Size kDefaultSize(800, 600); |
| 34 // Use (0,0) because the desktop aura tests are executed in | 34 // Use (0,0) because the desktop aura tests are executed in |
| 35 // native environment where the display's origin is (0,0). | 35 // native environment where the display's origin is (0,0). |
| 36 return new TestScreen(gfx::Rect(size.IsEmpty() ? kDefaultSize : size)); | 36 return new TestScreen(gfx::Rect(size.IsEmpty() ? kDefaultSize : size)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 host_->InitHost(); | 49 host_->InitHost(); |
| 50 return host_; | 50 return host_; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void TestScreen::SetDeviceScaleFactor(float device_scale_factor) { | 53 void TestScreen::SetDeviceScaleFactor(float device_scale_factor) { |
| 54 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); | 54 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); |
| 55 display_.SetScaleAndBounds(device_scale_factor, bounds_in_pixel); | 55 display_.SetScaleAndBounds(device_scale_factor, bounds_in_pixel); |
| 56 host_->OnHostResized(bounds_in_pixel.size()); | 56 host_->OnHostResized(bounds_in_pixel.size()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void TestScreen::SetDisplayRotation(gfx::Display::Rotation rotation) { | 59 void TestScreen::SetDisplayRotation(display::Display::Rotation rotation) { |
| 60 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); | 60 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); |
| 61 gfx::Rect new_bounds(bounds_in_pixel); | 61 gfx::Rect new_bounds(bounds_in_pixel); |
| 62 if (IsRotationPortrait(rotation) != IsRotationPortrait(display_.rotation())) { | 62 if (IsRotationPortrait(rotation) != IsRotationPortrait(display_.rotation())) { |
| 63 new_bounds.set_width(bounds_in_pixel.height()); | 63 new_bounds.set_width(bounds_in_pixel.height()); |
| 64 new_bounds.set_height(bounds_in_pixel.width()); | 64 new_bounds.set_height(bounds_in_pixel.width()); |
| 65 } | 65 } |
| 66 display_.set_rotation(rotation); | 66 display_.set_rotation(rotation); |
| 67 display_.SetScaleAndBounds(display_.device_scale_factor(), new_bounds); | 67 display_.SetScaleAndBounds(display_.device_scale_factor(), new_bounds); |
| 68 host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform()); | 68 host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void TestScreen::SetUIScale(float ui_scale) { | 71 void TestScreen::SetUIScale(float ui_scale) { |
| 72 ui_scale_ = ui_scale; | 72 ui_scale_ = ui_scale; |
| 73 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); | 73 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); |
| 74 gfx::Rect new_bounds = gfx::ToNearestRect( | 74 gfx::Rect new_bounds = gfx::ToNearestRect( |
| 75 gfx::ScaleRect(gfx::RectF(bounds_in_pixel), 1.0f / ui_scale)); | 75 gfx::ScaleRect(gfx::RectF(bounds_in_pixel), 1.0f / ui_scale)); |
| 76 display_.SetScaleAndBounds(display_.device_scale_factor(), new_bounds); | 76 display_.SetScaleAndBounds(display_.device_scale_factor(), new_bounds); |
| 77 host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform()); | 77 host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void TestScreen::SetWorkAreaInsets(const gfx::Insets& insets) { | 80 void TestScreen::SetWorkAreaInsets(const gfx::Insets& insets) { |
| 81 display_.UpdateWorkAreaFromInsets(insets); | 81 display_.UpdateWorkAreaFromInsets(insets); |
| 82 } | 82 } |
| 83 | 83 |
| 84 gfx::Transform TestScreen::GetRotationTransform() const { | 84 gfx::Transform TestScreen::GetRotationTransform() const { |
| 85 gfx::Transform rotate; | 85 gfx::Transform rotate; |
| 86 switch (display_.rotation()) { | 86 switch (display_.rotation()) { |
| 87 case gfx::Display::ROTATE_0: | 87 case display::Display::ROTATE_0: |
| 88 break; | 88 break; |
| 89 case gfx::Display::ROTATE_90: | 89 case display::Display::ROTATE_90: |
| 90 rotate.Translate(display_.bounds().height(), 0); | 90 rotate.Translate(display_.bounds().height(), 0); |
| 91 rotate.Rotate(90); | 91 rotate.Rotate(90); |
| 92 break; | 92 break; |
| 93 case gfx::Display::ROTATE_270: | 93 case display::Display::ROTATE_270: |
| 94 rotate.Translate(0, display_.bounds().width()); | 94 rotate.Translate(0, display_.bounds().width()); |
| 95 rotate.Rotate(270); | 95 rotate.Rotate(270); |
| 96 break; | 96 break; |
| 97 case gfx::Display::ROTATE_180: | 97 case display::Display::ROTATE_180: |
| 98 rotate.Translate(display_.bounds().width(), | 98 rotate.Translate(display_.bounds().width(), |
| 99 display_.bounds().height()); | 99 display_.bounds().height()); |
| 100 rotate.Rotate(180); | 100 rotate.Rotate(180); |
| 101 break; | 101 break; |
| 102 } | 102 } |
| 103 | 103 |
| 104 return rotate; | 104 return rotate; |
| 105 } | 105 } |
| 106 | 106 |
| 107 gfx::Transform TestScreen::GetUIScaleTransform() const { | 107 gfx::Transform TestScreen::GetUIScaleTransform() const { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 133 gfx::NativeWindow TestScreen::GetWindowAtScreenPoint(const gfx::Point& point) { | 133 gfx::NativeWindow TestScreen::GetWindowAtScreenPoint(const gfx::Point& point) { |
| 134 if (!host_ || !host_->window()) | 134 if (!host_ || !host_->window()) |
| 135 return nullptr; | 135 return nullptr; |
| 136 return host_->window()->GetTopWindowContainingPoint(point); | 136 return host_->window()->GetTopWindowContainingPoint(point); |
| 137 } | 137 } |
| 138 | 138 |
| 139 int TestScreen::GetNumDisplays() const { | 139 int TestScreen::GetNumDisplays() const { |
| 140 return 1; | 140 return 1; |
| 141 } | 141 } |
| 142 | 142 |
| 143 std::vector<gfx::Display> TestScreen::GetAllDisplays() const { | 143 std::vector<display::Display> TestScreen::GetAllDisplays() const { |
| 144 return std::vector<gfx::Display>(1, display_); | 144 return std::vector<display::Display>(1, display_); |
| 145 } | 145 } |
| 146 | 146 |
| 147 gfx::Display TestScreen::GetDisplayNearestWindow( | 147 display::Display TestScreen::GetDisplayNearestWindow( |
| 148 gfx::NativeWindow window) const { | 148 gfx::NativeWindow window) const { |
| 149 return display_; | 149 return display_; |
| 150 } | 150 } |
| 151 | 151 |
| 152 gfx::Display TestScreen::GetDisplayNearestPoint(const gfx::Point& point) const { | 152 display::Display TestScreen::GetDisplayNearestPoint( |
| 153 const gfx::Point& point) const { |
| 153 return display_; | 154 return display_; |
| 154 } | 155 } |
| 155 | 156 |
| 156 gfx::Display TestScreen::GetDisplayMatching(const gfx::Rect& match_rect) const { | 157 display::Display TestScreen::GetDisplayMatching( |
| 158 const gfx::Rect& match_rect) const { |
| 157 return display_; | 159 return display_; |
| 158 } | 160 } |
| 159 | 161 |
| 160 gfx::Display TestScreen::GetPrimaryDisplay() const { | 162 display::Display TestScreen::GetPrimaryDisplay() const { |
| 161 return display_; | 163 return display_; |
| 162 } | 164 } |
| 163 | 165 |
| 164 void TestScreen::AddObserver(gfx::DisplayObserver* observer) { | 166 void TestScreen::AddObserver(display::DisplayObserver* observer) {} |
| 165 } | |
| 166 | 167 |
| 167 void TestScreen::RemoveObserver(gfx::DisplayObserver* observer) { | 168 void TestScreen::RemoveObserver(display::DisplayObserver* observer) {} |
| 168 } | |
| 169 | 169 |
| 170 TestScreen::TestScreen(const gfx::Rect& screen_bounds) | 170 TestScreen::TestScreen(const gfx::Rect& screen_bounds) |
| 171 : host_(NULL), | 171 : host_(NULL), |
| 172 ui_scale_(1.0f) { | 172 ui_scale_(1.0f) { |
| 173 static int64_t synthesized_display_id = 2000; | 173 static int64_t synthesized_display_id = 2000; |
| 174 display_.set_id(synthesized_display_id++); | 174 display_.set_id(synthesized_display_id++); |
| 175 display_.SetScaleAndBounds(1.0f, screen_bounds); | 175 display_.SetScaleAndBounds(1.0f, screen_bounds); |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace aura | 178 } // namespace aura |
| OLD | NEW |