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

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

Issue 2207043002: SetDeviceScaleFactorForTest Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SetDeviceScaleFactorForTest Created 4 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
« no previous file with comments | « ui/aura/test/test_screen.h ('k') | ui/aura/window_event_dispatcher_unittest.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/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 <vector>
10
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "ui/aura/env.h" 12 #include "ui/aura/env.h"
11 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
12 #include "ui/aura/window_event_dispatcher.h" 14 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/aura/window_tree_host.h" 15 #include "ui/aura/window_tree_host.h"
14 #include "ui/base/ime/input_method.h" 16 #include "ui/base/ime/input_method.h"
15 #include "ui/display/screen.h" 17 #include "ui/display/screen.h"
16 #include "ui/gfx/geometry/rect_conversions.h" 18 #include "ui/gfx/geometry/rect_conversions.h"
17 #include "ui/gfx/geometry/size_conversions.h" 19 #include "ui/gfx/geometry/size_conversions.h"
18 #include "ui/gfx/native_widget_types.h" 20 #include "ui/gfx/native_widget_types.h"
(...skipping 13 matching lines...) Expand all
32 TestScreen* TestScreen::Create(const gfx::Size& size) { 34 TestScreen* TestScreen::Create(const gfx::Size& size) {
33 const gfx::Size kDefaultSize(800, 600); 35 const gfx::Size kDefaultSize(800, 600);
34 // Use (0,0) because the desktop aura tests are executed in 36 // Use (0,0) because the desktop aura tests are executed in
35 // native environment where the display's origin is (0,0). 37 // native environment where the display's origin is (0,0).
36 return new TestScreen(gfx::Rect(size.IsEmpty() ? kDefaultSize : size)); 38 return new TestScreen(gfx::Rect(size.IsEmpty() ? kDefaultSize : size));
37 } 39 }
38 40
39 TestScreen::~TestScreen() { 41 TestScreen::~TestScreen() {
40 } 42 }
41 43
42 WindowTreeHost* TestScreen::CreateHostForPrimaryDisplay() { 44 void TestScreen::CreateHostForPrimaryDisplay() {
43 DCHECK(!host_); 45 DCHECK(!host_.get());
44 host_ = WindowTreeHost::Create(gfx::Rect(display_.GetSizeInPixel())); 46 host_.reset(WindowTreeHost::Create(gfx::Rect(display_.GetSizeInPixel())));
45 // Some tests don't correctly manage window focus/activation states. 47 // Some tests don't correctly manage window focus/activation states.
46 // Makes sure InputMethod is default focused so that IME basics can work. 48 // Makes sure InputMethod is default focused so that IME basics can work.
47 host_->GetInputMethod()->OnFocus(); 49 host_->GetInputMethod()->OnFocus();
48 host_->window()->AddObserver(this); 50 host_->window()->AddObserver(this);
49 host_->InitHost(); 51 host_->InitHost();
50 return host_;
51 }
52
53 void TestScreen::SetDeviceScaleFactor(float device_scale_factor) {
54 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel());
55 display_.SetScaleAndBounds(device_scale_factor, bounds_in_pixel);
56 host_->OnHostResized(bounds_in_pixel.size());
57 } 52 }
58 53
59 void TestScreen::SetDisplayRotation(display::Display::Rotation rotation) { 54 void TestScreen::SetDisplayRotation(display::Display::Rotation rotation) {
60 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel()); 55 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel());
61 gfx::Rect new_bounds(bounds_in_pixel); 56 gfx::Rect new_bounds(bounds_in_pixel);
62 if (IsRotationPortrait(rotation) != IsRotationPortrait(display_.rotation())) { 57 if (IsRotationPortrait(rotation) != IsRotationPortrait(display_.rotation())) {
63 new_bounds.set_width(bounds_in_pixel.height()); 58 new_bounds.set_width(bounds_in_pixel.height());
64 new_bounds.set_height(bounds_in_pixel.width()); 59 new_bounds.set_height(bounds_in_pixel.width());
65 } 60 }
66 display_.set_rotation(rotation); 61 display_.set_rotation(rotation);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return ui_scale; 109 return ui_scale;
115 } 110 }
116 111
117 void TestScreen::OnWindowBoundsChanged( 112 void TestScreen::OnWindowBoundsChanged(
118 Window* window, const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { 113 Window* window, const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) {
119 DCHECK_EQ(host_->window(), window); 114 DCHECK_EQ(host_->window(), window);
120 display_.SetSize(gfx::ScaleToFlooredSize(new_bounds.size(), 115 display_.SetSize(gfx::ScaleToFlooredSize(new_bounds.size(),
121 display_.device_scale_factor())); 116 display_.device_scale_factor()));
122 } 117 }
123 118
124 void TestScreen::OnWindowDestroying(Window* window) {
125 if (host_->window() == window)
126 host_ = NULL;
127 }
128
129 gfx::Point TestScreen::GetCursorScreenPoint() { 119 gfx::Point TestScreen::GetCursorScreenPoint() {
130 return Env::GetInstance()->last_mouse_location(); 120 return Env::GetInstance()->last_mouse_location();
131 } 121 }
132 122
133 bool TestScreen::IsWindowUnderCursor(gfx::NativeWindow window) { 123 bool TestScreen::IsWindowUnderCursor(gfx::NativeWindow window) {
134 return GetWindowAtScreenPoint(GetCursorScreenPoint()) == window; 124 return GetWindowAtScreenPoint(GetCursorScreenPoint()) == window;
135 } 125 }
136 126
137 gfx::NativeWindow TestScreen::GetWindowAtScreenPoint(const gfx::Point& point) { 127 gfx::NativeWindow TestScreen::GetWindowAtScreenPoint(const gfx::Point& point) {
138 if (!host_ || !host_->window()) 128 if (!host_ || !host_->window())
(...skipping 17 matching lines...) Expand all
156 display::Display TestScreen::GetDisplayNearestPoint( 146 display::Display TestScreen::GetDisplayNearestPoint(
157 const gfx::Point& point) const { 147 const gfx::Point& point) const {
158 return display_; 148 return display_;
159 } 149 }
160 150
161 display::Display TestScreen::GetDisplayMatching( 151 display::Display TestScreen::GetDisplayMatching(
162 const gfx::Rect& match_rect) const { 152 const gfx::Rect& match_rect) const {
163 return display_; 153 return display_;
164 } 154 }
165 155
166 void TestScreen::AddObserver(display::DisplayObserver* observer) {} 156 void TestScreen::AddObserver(display::DisplayObserver* observer) {
157 notifier_.AddObserver(observer);
158 }
167 159
168 void TestScreen::RemoveObserver(display::DisplayObserver* observer) {} 160 void TestScreen::RemoveObserver(display::DisplayObserver* observer) {
161 notifier_.RemoveObserver(observer);
162 }
163
164 void TestScreen::SetDeviceScaleFactorForTest(float device_scale_factor) {
165 gfx::Rect bounds_in_pixel(display_.GetSizeInPixel());
166
167 std::vector<display::Display> old_displays;
168 old_displays.push_back(display_);
169 display_.SetScaleAndBounds(device_scale_factor, bounds_in_pixel);
170 std::vector<display::Display> new_displays;
171 new_displays.push_back(display_);
172 LOG(ERROR) << "Calling On Host Resized: display=" << display_.ToString();
173 host_->OnHostResized(bounds_in_pixel.size());
174 LOG(ERROR) << "Calling On Host Resized: Done";
175 notifier_.NotifyDisplaysChanged(old_displays, new_displays);
176 }
169 177
170 TestScreen::TestScreen(const gfx::Rect& screen_bounds) 178 TestScreen::TestScreen(const gfx::Rect& screen_bounds)
171 : host_(NULL), 179 : ui_scale_(1.0f) {
172 ui_scale_(1.0f) {
173 static int64_t synthesized_display_id = 2000; 180 static int64_t synthesized_display_id = 2000;
174 display_.set_id(synthesized_display_id++); 181 display_.set_id(synthesized_display_id++);
175 display_.SetScaleAndBounds(1.0f, screen_bounds); 182 display_.SetScaleAndBounds(1.0f, screen_bounds);
176 } 183 }
177 184
178 } // namespace aura 185 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/test_screen.h ('k') | ui/aura/window_event_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698