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 "base/command_line.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ui/aura/aura_switches.h" |
| 10 #include "ui/aura/display_util.h" |
8 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
9 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
10 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
11 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
12 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
13 | 16 |
14 namespace aura { | 17 namespace aura { |
15 | 18 |
16 TestScreen::TestScreen(aura::RootWindow* root_window) | 19 TestScreen::TestScreen() : root_window_(NULL) { |
17 : root_window_(root_window) { | 20 const std::string size_str = |
| 21 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 22 switches::kAuraHostWindowSize); |
| 23 display_ = aura::CreateDisplayFromSpec(size_str); |
18 } | 24 } |
19 | 25 |
20 TestScreen::~TestScreen() { | 26 TestScreen::~TestScreen() { |
21 } | 27 } |
22 | 28 |
| 29 RootWindow* TestScreen::CreateRootWindowForPrimaryDisplay() { |
| 30 DCHECK(!root_window_); |
| 31 root_window_ = new RootWindow(RootWindow::CreateParams(display_.bounds())); |
| 32 root_window_->AddObserver(this); |
| 33 root_window_->Init(); |
| 34 if (UseFullscreenHostWindow()) |
| 35 root_window_->ConfineCursorToWindow(); |
| 36 return root_window_; |
| 37 } |
| 38 |
23 bool TestScreen::IsDIPEnabled() { | 39 bool TestScreen::IsDIPEnabled() { |
24 return true; | 40 return true; |
25 } | 41 } |
26 | 42 |
| 43 void TestScreen::OnWindowBoundsChanged( |
| 44 Window* window, const gfx::Rect& old_bounds, const gfx::Rect& new_bounds) { |
| 45 if (!UseFullscreenHostWindow()) { |
| 46 DCHECK_EQ(root_window_, window); |
| 47 display_.SetSize(new_bounds.size()); |
| 48 } |
| 49 } |
| 50 |
| 51 void TestScreen::OnWindowDestroying(Window* window) { |
| 52 if (root_window_ == window) |
| 53 root_window_ = NULL; |
| 54 } |
| 55 |
27 gfx::Point TestScreen::GetCursorScreenPoint() { | 56 gfx::Point TestScreen::GetCursorScreenPoint() { |
28 return Env::GetInstance()->last_mouse_location(); | 57 return Env::GetInstance()->last_mouse_location(); |
29 } | 58 } |
30 | 59 |
31 gfx::NativeWindow TestScreen::GetWindowAtCursorScreenPoint() { | 60 gfx::NativeWindow TestScreen::GetWindowAtCursorScreenPoint() { |
32 const gfx::Point point = GetCursorScreenPoint(); | 61 const gfx::Point point = GetCursorScreenPoint(); |
33 return root_window_->GetTopWindowContainingPoint(point); | 62 return root_window_->GetTopWindowContainingPoint(point); |
34 } | 63 } |
35 | 64 |
36 int TestScreen::GetNumDisplays() { | 65 int TestScreen::GetNumDisplays() { |
37 return 1; | 66 return 1; |
38 } | 67 } |
39 | 68 |
40 gfx::Display TestScreen::GetDisplayNearestWindow( | 69 gfx::Display TestScreen::GetDisplayNearestWindow( |
41 gfx::NativeWindow window) const { | 70 gfx::NativeWindow window) const { |
42 return GetMonitor(); | 71 return display_; |
43 } | 72 } |
44 | 73 |
45 gfx::Display TestScreen::GetDisplayNearestPoint(const gfx::Point& point) const { | 74 gfx::Display TestScreen::GetDisplayNearestPoint(const gfx::Point& point) const { |
46 return GetMonitor(); | 75 return display_; |
47 } | 76 } |
48 | 77 |
49 gfx::Display TestScreen::GetDisplayMatching(const gfx::Rect& match_rect) const { | 78 gfx::Display TestScreen::GetDisplayMatching(const gfx::Rect& match_rect) const { |
50 return GetMonitor(); | 79 return display_; |
51 } | 80 } |
52 | 81 |
53 gfx::Display TestScreen::GetPrimaryDisplay() const { | 82 gfx::Display TestScreen::GetPrimaryDisplay() const { |
54 return GetMonitor(); | 83 return display_; |
55 } | 84 } |
56 | 85 |
57 gfx::Display TestScreen::GetMonitor() const { | 86 void TestScreen::AddObserver(gfx::DisplayObserver* observer) { |
58 return gfx::Display(0, root_window_->bounds()); | 87 } |
| 88 |
| 89 void TestScreen::RemoveObserver(gfx::DisplayObserver* observer) { |
59 } | 90 } |
60 | 91 |
61 } // namespace aura | 92 } // namespace aura |
OLD | NEW |