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

Side by Side Diff: ash/display/screen_ash.cc

Issue 2294853003: Break dependency between ash::DisplayManager and ash::ScreenAsh (Closed)
Patch Set: rebased Created 4 years, 3 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 | « ash/display/screen_ash.h ('k') | ash/shell.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ash/display/screen_ash.h" 5 #include "ash/display/screen_ash.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/shelf/shelf_widget.h" 8 #include "ash/common/shelf/shelf_widget.h"
9 #include "ash/common/wm/root_window_finder.h" 9 #include "ash/common/wm/root_window_finder.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/display/window_tree_host_manager.h" 11 #include "ash/display/window_tree_host_manager.h"
12 #include "ash/root_window_controller.h" 12 #include "ash/root_window_controller.h"
13 #include "ash/root_window_settings.h" 13 #include "ash/root_window_settings.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "ui/aura/client/screen_position_client.h" 16 #include "ui/aura/client/screen_position_client.h"
17 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
18 #include "ui/aura/window_event_dispatcher.h" 18 #include "ui/aura/window_event_dispatcher.h"
19 #include "ui/display/display.h" 19 #include "ui/display/display.h"
20 #include "ui/display/display_finder.h" 20 #include "ui/display/display_finder.h"
21 #include "ui/display/screen.h" 21 #include "ui/display/screen.h"
22 22
23 namespace ash { 23 namespace ash {
24 24
25 namespace { 25 namespace {
26 26
27 // We need to keep this in order for unittests to tell if
28 // the object in display::Screen::GetScreenByType is for shutdown.
29 display::Screen* screen_for_shutdown = nullptr;
30
27 DisplayManager* GetDisplayManager() { 31 DisplayManager* GetDisplayManager() {
28 return Shell::GetInstance()->display_manager(); 32 return Shell::GetInstance()->display_manager();
29 } 33 }
30 34
31 class ScreenForShutdown : public display::Screen { 35 class ScreenForShutdown : public display::Screen {
32 public: 36 public:
33 explicit ScreenForShutdown(ScreenAsh* screen_ash) 37 explicit ScreenForShutdown(display::Screen* screen_ash)
34 : display_list_(screen_ash->GetAllDisplays()), 38 : display_list_(screen_ash->GetAllDisplays()),
35 primary_display_(screen_ash->GetPrimaryDisplay()) {} 39 primary_display_(screen_ash->GetPrimaryDisplay()) {}
36 40
37 // display::Screen overrides: 41 // display::Screen overrides:
38 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } 42 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); }
39 bool IsWindowUnderCursor(gfx::NativeWindow window) override { return false; } 43 bool IsWindowUnderCursor(gfx::NativeWindow window) override { return false; }
40 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { 44 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override {
41 return NULL; 45 return NULL;
42 } 46 }
43 int GetNumDisplays() const override { return display_list_.size(); } 47 int GetNumDisplays() const override { return display_list_.size(); }
(...skipping 29 matching lines...) Expand all
73 77
74 DISALLOW_COPY_AND_ASSIGN(ScreenForShutdown); 78 DISALLOW_COPY_AND_ASSIGN(ScreenForShutdown);
75 }; 79 };
76 80
77 } // namespace 81 } // namespace
78 82
79 ScreenAsh::ScreenAsh() {} 83 ScreenAsh::ScreenAsh() {}
80 84
81 ScreenAsh::~ScreenAsh() {} 85 ScreenAsh::~ScreenAsh() {}
82 86
83 void ScreenAsh::NotifyMetricsChanged(const display::Display& display,
84 uint32_t metrics) {
85 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
86 OnDisplayMetricsChanged(display, metrics));
87 }
88
89 void ScreenAsh::NotifyDisplayAdded(const display::Display& display) {
90 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
91 OnDisplayAdded(display));
92 }
93
94 void ScreenAsh::NotifyDisplayRemoved(const display::Display& display) {
95 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
96 OnDisplayRemoved(display));
97 }
98
99 gfx::Point ScreenAsh::GetCursorScreenPoint() { 87 gfx::Point ScreenAsh::GetCursorScreenPoint() {
100 return aura::Env::GetInstance()->last_mouse_location(); 88 return aura::Env::GetInstance()->last_mouse_location();
101 } 89 }
102 90
103 bool ScreenAsh::IsWindowUnderCursor(gfx::NativeWindow window) { 91 bool ScreenAsh::IsWindowUnderCursor(gfx::NativeWindow window) {
104 return GetWindowAtScreenPoint( 92 return GetWindowAtScreenPoint(
105 display::Screen::GetScreen()->GetCursorScreenPoint()) == window; 93 display::Screen::GetScreen()->GetCursorScreenPoint()) == window;
106 } 94 }
107 95
108 gfx::NativeWindow ScreenAsh::GetWindowAtScreenPoint(const gfx::Point& point) { 96 gfx::NativeWindow ScreenAsh::GetWindowAtScreenPoint(const gfx::Point& point) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Fallback to the primary display if there is no matching display. 161 // Fallback to the primary display if there is no matching display.
174 return matching ? *matching : GetPrimaryDisplay(); 162 return matching ? *matching : GetPrimaryDisplay();
175 } 163 }
176 164
177 display::Display ScreenAsh::GetPrimaryDisplay() const { 165 display::Display ScreenAsh::GetPrimaryDisplay() const {
178 return GetDisplayManager()->GetDisplayForId( 166 return GetDisplayManager()->GetDisplayForId(
179 WindowTreeHostManager::GetPrimaryDisplayId()); 167 WindowTreeHostManager::GetPrimaryDisplayId());
180 } 168 }
181 169
182 void ScreenAsh::AddObserver(display::DisplayObserver* observer) { 170 void ScreenAsh::AddObserver(display::DisplayObserver* observer) {
183 observers_.AddObserver(observer); 171 GetDisplayManager()->AddObserver(observer);
184 } 172 }
185 173
186 void ScreenAsh::RemoveObserver(display::DisplayObserver* observer) { 174 void ScreenAsh::RemoveObserver(display::DisplayObserver* observer) {
187 observers_.RemoveObserver(observer); 175 GetDisplayManager()->RemoveObserver(observer);
188 } 176 }
189 177
190 display::Screen* ScreenAsh::CloneForShutdown() { 178 // static
191 return new ScreenForShutdown(this); 179 DisplayManager* ScreenAsh::CreateDisplayManager() {
180 std::unique_ptr<ScreenAsh> screen(new ScreenAsh);
181
182 display::Screen* current = display::Screen::GetScreen();
183 // If there is no native, or the native was for shutdown,
184 // use ash's screen.
185 if (!current || current == screen_for_shutdown)
186 display::Screen::SetScreenInstance(screen.get());
187 return new DisplayManager(std::move(screen));
188 }
189
190 // static
191 void ScreenAsh::CreateScreenForShutdown() {
192 delete screen_for_shutdown;
193 // fix this up...
194 screen_for_shutdown = new ScreenForShutdown(display::Screen::GetScreen());
195 display::Screen::SetScreenInstance(screen_for_shutdown);
192 } 196 }
193 197
194 } // namespace ash 198 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/screen_ash.h ('k') | ash/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698