| OLD | NEW |
| 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/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/display/window_tree_host_manager.h" | 8 #include "ash/display/window_tree_host_manager.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/root_window_settings.h" | 10 #include "ash/root_window_settings.h" |
| 11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
| 12 #include "ash/shelf/shelf_widget.h" | 12 #include "ash/shelf/shelf_widget.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/wm/aura/wm_window_aura.h" | 14 #include "ash/wm/aura/wm_window_aura.h" |
| 15 #include "ash/wm/common/root_window_finder.h" | 15 #include "ash/wm/common/root_window_finder.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "ui/aura/client/screen_position_client.h" | 17 #include "ui/aura/client/screen_position_client.h" |
| 18 #include "ui/aura/env.h" | 18 #include "ui/aura/env.h" |
| 19 #include "ui/aura/window_event_dispatcher.h" | 19 #include "ui/aura/window_event_dispatcher.h" |
| 20 #include "ui/gfx/display.h" | 20 #include "ui/display/display.h" |
| 21 #include "ui/display/screen.h" |
| 21 #include "ui/gfx/display_finder.h" | 22 #include "ui/gfx/display_finder.h" |
| 22 #include "ui/gfx/screen.h" | |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 DisplayManager* GetDisplayManager() { | 28 DisplayManager* GetDisplayManager() { |
| 29 return Shell::GetInstance()->display_manager(); | 29 return Shell::GetInstance()->display_manager(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 class ScreenForShutdown : public gfx::Screen { | 32 class ScreenForShutdown : public display::Screen { |
| 33 public: | 33 public: |
| 34 explicit ScreenForShutdown(ScreenAsh* screen_ash) | 34 explicit ScreenForShutdown(ScreenAsh* screen_ash) |
| 35 : display_list_(screen_ash->GetAllDisplays()), | 35 : display_list_(screen_ash->GetAllDisplays()), |
| 36 primary_display_(screen_ash->GetPrimaryDisplay()) { | 36 primary_display_(screen_ash->GetPrimaryDisplay()) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 // gfx::Screen overrides: | 39 // display::Screen overrides: |
| 40 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | 40 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } |
| 41 gfx::NativeWindow GetWindowUnderCursor() override { return NULL; } | 41 gfx::NativeWindow GetWindowUnderCursor() override { return NULL; } |
| 42 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { | 42 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { |
| 43 return NULL; | 43 return NULL; |
| 44 } | 44 } |
| 45 int GetNumDisplays() const override { return display_list_.size(); } | 45 int GetNumDisplays() const override { return display_list_.size(); } |
| 46 std::vector<gfx::Display> GetAllDisplays() const override { | 46 std::vector<display::Display> GetAllDisplays() const override { |
| 47 return display_list_; | 47 return display_list_; |
| 48 } | 48 } |
| 49 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { | 49 display::Display GetDisplayNearestWindow( |
| 50 gfx::NativeView view) const override { |
| 50 return primary_display_; | 51 return primary_display_; |
| 51 } | 52 } |
| 52 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { | 53 display::Display GetDisplayNearestPoint( |
| 54 const gfx::Point& point) const override { |
| 53 return *gfx::FindDisplayNearestPoint(display_list_, point); | 55 return *gfx::FindDisplayNearestPoint(display_list_, point); |
| 54 } | 56 } |
| 55 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override { | 57 display::Display GetDisplayMatching( |
| 56 const gfx::Display* matching = | 58 const gfx::Rect& match_rect) const override { |
| 59 const display::Display* matching = |
| 57 gfx::FindDisplayWithBiggestIntersection(display_list_, match_rect); | 60 gfx::FindDisplayWithBiggestIntersection(display_list_, match_rect); |
| 58 // Fallback to the primary display if there is no matching display. | 61 // Fallback to the primary display if there is no matching display. |
| 59 return matching ? *matching : GetPrimaryDisplay(); | 62 return matching ? *matching : GetPrimaryDisplay(); |
| 60 } | 63 } |
| 61 gfx::Display GetPrimaryDisplay() const override { return primary_display_; } | 64 display::Display GetPrimaryDisplay() const override { |
| 62 void AddObserver(gfx::DisplayObserver* observer) override { | 65 return primary_display_; |
| 66 } |
| 67 void AddObserver(display::DisplayObserver* observer) override { |
| 63 NOTREACHED() << "Observer should not be added during shutdown"; | 68 NOTREACHED() << "Observer should not be added during shutdown"; |
| 64 } | 69 } |
| 65 void RemoveObserver(gfx::DisplayObserver* observer) override {} | 70 void RemoveObserver(display::DisplayObserver* observer) override {} |
| 66 | 71 |
| 67 private: | 72 private: |
| 68 const std::vector<gfx::Display> display_list_; | 73 const std::vector<display::Display> display_list_; |
| 69 const gfx::Display primary_display_; | 74 const display::Display primary_display_; |
| 70 | 75 |
| 71 DISALLOW_COPY_AND_ASSIGN(ScreenForShutdown); | 76 DISALLOW_COPY_AND_ASSIGN(ScreenForShutdown); |
| 72 }; | 77 }; |
| 73 | 78 |
| 74 } // namespace | 79 } // namespace |
| 75 | 80 |
| 76 ScreenAsh::ScreenAsh() { | 81 ScreenAsh::ScreenAsh() { |
| 77 } | 82 } |
| 78 | 83 |
| 79 ScreenAsh::~ScreenAsh() { | 84 ScreenAsh::~ScreenAsh() { |
| 80 } | 85 } |
| 81 | 86 |
| 82 void ScreenAsh::NotifyMetricsChanged(const gfx::Display& display, | 87 void ScreenAsh::NotifyMetricsChanged(const display::Display& display, |
| 83 uint32_t metrics) { | 88 uint32_t metrics) { |
| 84 FOR_EACH_OBSERVER(gfx::DisplayObserver, | 89 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, |
| 85 observers_, | |
| 86 OnDisplayMetricsChanged(display, metrics)); | 90 OnDisplayMetricsChanged(display, metrics)); |
| 87 } | 91 } |
| 88 | 92 |
| 89 void ScreenAsh::NotifyDisplayAdded(const gfx::Display& display) { | 93 void ScreenAsh::NotifyDisplayAdded(const display::Display& display) { |
| 90 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, OnDisplayAdded(display)); | 94 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, |
| 95 OnDisplayAdded(display)); |
| 91 } | 96 } |
| 92 | 97 |
| 93 void ScreenAsh::NotifyDisplayRemoved(const gfx::Display& display) { | 98 void ScreenAsh::NotifyDisplayRemoved(const display::Display& display) { |
| 94 FOR_EACH_OBSERVER( | 99 FOR_EACH_OBSERVER(display::DisplayObserver, observers_, |
| 95 gfx::DisplayObserver, observers_, OnDisplayRemoved(display)); | 100 OnDisplayRemoved(display)); |
| 96 } | 101 } |
| 97 | 102 |
| 98 gfx::Point ScreenAsh::GetCursorScreenPoint() { | 103 gfx::Point ScreenAsh::GetCursorScreenPoint() { |
| 99 return aura::Env::GetInstance()->last_mouse_location(); | 104 return aura::Env::GetInstance()->last_mouse_location(); |
| 100 } | 105 } |
| 101 | 106 |
| 102 gfx::NativeWindow ScreenAsh::GetWindowUnderCursor() { | 107 gfx::NativeWindow ScreenAsh::GetWindowUnderCursor() { |
| 103 return GetWindowAtScreenPoint( | 108 return GetWindowAtScreenPoint( |
| 104 gfx::Screen::GetScreen()->GetCursorScreenPoint()); | 109 display::Screen::GetScreen()->GetCursorScreenPoint()); |
| 105 } | 110 } |
| 106 | 111 |
| 107 gfx::NativeWindow ScreenAsh::GetWindowAtScreenPoint(const gfx::Point& point) { | 112 gfx::NativeWindow ScreenAsh::GetWindowAtScreenPoint(const gfx::Point& point) { |
| 108 aura::Window* root_window = | 113 aura::Window* root_window = |
| 109 wm::WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(point)); | 114 wm::WmWindowAura::GetAuraWindow(wm::GetRootWindowAt(point)); |
| 110 aura::client::ScreenPositionClient* position_client = | 115 aura::client::ScreenPositionClient* position_client = |
| 111 aura::client::GetScreenPositionClient(root_window); | 116 aura::client::GetScreenPositionClient(root_window); |
| 112 | 117 |
| 113 gfx::Point local_point = point; | 118 gfx::Point local_point = point; |
| 114 if (position_client) | 119 if (position_client) |
| 115 position_client->ConvertPointFromScreen(root_window, &local_point); | 120 position_client->ConvertPointFromScreen(root_window, &local_point); |
| 116 | 121 |
| 117 return root_window->GetTopWindowContainingPoint(local_point); | 122 return root_window->GetTopWindowContainingPoint(local_point); |
| 118 } | 123 } |
| 119 | 124 |
| 120 int ScreenAsh::GetNumDisplays() const { | 125 int ScreenAsh::GetNumDisplays() const { |
| 121 return GetDisplayManager()->GetNumDisplays(); | 126 return GetDisplayManager()->GetNumDisplays(); |
| 122 } | 127 } |
| 123 | 128 |
| 124 std::vector<gfx::Display> ScreenAsh::GetAllDisplays() const { | 129 std::vector<display::Display> ScreenAsh::GetAllDisplays() const { |
| 125 return GetDisplayManager()->active_display_list(); | 130 return GetDisplayManager()->active_display_list(); |
| 126 } | 131 } |
| 127 | 132 |
| 128 gfx::Display ScreenAsh::GetDisplayNearestWindow(gfx::NativeView window) const { | 133 display::Display ScreenAsh::GetDisplayNearestWindow( |
| 134 gfx::NativeView window) const { |
| 129 if (!window) | 135 if (!window) |
| 130 return GetPrimaryDisplay(); | 136 return GetPrimaryDisplay(); |
| 131 const aura::Window* root_window = window->GetRootWindow(); | 137 const aura::Window* root_window = window->GetRootWindow(); |
| 132 if (!root_window) | 138 if (!root_window) |
| 133 return GetPrimaryDisplay(); | 139 return GetPrimaryDisplay(); |
| 134 const RootWindowSettings* rws = GetRootWindowSettings(root_window); | 140 const RootWindowSettings* rws = GetRootWindowSettings(root_window); |
| 135 int64_t id = rws->display_id; | 141 int64_t id = rws->display_id; |
| 136 // if id is |kInvaildDisplayID|, it's being deleted. | 142 // if id is |kInvaildDisplayID|, it's being deleted. |
| 137 DCHECK(id != gfx::Display::kInvalidDisplayID); | 143 DCHECK(id != display::Display::kInvalidDisplayID); |
| 138 if (id == gfx::Display::kInvalidDisplayID) | 144 if (id == display::Display::kInvalidDisplayID) |
| 139 return GetPrimaryDisplay(); | 145 return GetPrimaryDisplay(); |
| 140 | 146 |
| 141 DisplayManager* display_manager = GetDisplayManager(); | 147 DisplayManager* display_manager = GetDisplayManager(); |
| 142 // RootWindow needs Display to determine its device scale factor | 148 // RootWindow needs Display to determine its device scale factor |
| 143 // for non desktop display. | 149 // for non desktop display. |
| 144 gfx::Display mirroring_display = display_manager->GetMirroringDisplayById(id); | 150 display::Display mirroring_display = |
| 151 display_manager->GetMirroringDisplayById(id); |
| 145 if (mirroring_display.is_valid()) | 152 if (mirroring_display.is_valid()) |
| 146 return mirroring_display; | 153 return mirroring_display; |
| 147 return display_manager->GetDisplayForId(id); | 154 return display_manager->GetDisplayForId(id); |
| 148 } | 155 } |
| 149 | 156 |
| 150 gfx::Display ScreenAsh::GetDisplayNearestPoint(const gfx::Point& point) const { | 157 display::Display ScreenAsh::GetDisplayNearestPoint( |
| 151 const gfx::Display& display = | 158 const gfx::Point& point) const { |
| 159 const display::Display& display = |
| 152 GetDisplayManager()->FindDisplayContainingPoint(point); | 160 GetDisplayManager()->FindDisplayContainingPoint(point); |
| 153 if (display.is_valid()) | 161 if (display.is_valid()) |
| 154 return display; | 162 return display; |
| 155 // Fallback to the display that has the shortest Manhattan distance from | 163 // Fallback to the display that has the shortest Manhattan distance from |
| 156 // the |point|. This is correct in the only areas that matter, namely in the | 164 // the |point|. This is correct in the only areas that matter, namely in the |
| 157 // corners between the physical screens. | 165 // corners between the physical screens. |
| 158 return *gfx::FindDisplayNearestPoint( | 166 return *gfx::FindDisplayNearestPoint( |
| 159 GetDisplayManager()->active_display_list(), point); | 167 GetDisplayManager()->active_display_list(), point); |
| 160 } | 168 } |
| 161 | 169 |
| 162 gfx::Display ScreenAsh::GetDisplayMatching(const gfx::Rect& match_rect) const { | 170 display::Display ScreenAsh::GetDisplayMatching( |
| 171 const gfx::Rect& match_rect) const { |
| 163 if (match_rect.IsEmpty()) | 172 if (match_rect.IsEmpty()) |
| 164 return GetDisplayNearestPoint(match_rect.origin()); | 173 return GetDisplayNearestPoint(match_rect.origin()); |
| 165 const gfx::Display* matching = gfx::FindDisplayWithBiggestIntersection( | 174 const display::Display* matching = gfx::FindDisplayWithBiggestIntersection( |
| 166 GetDisplayManager()->active_display_list(), match_rect); | 175 GetDisplayManager()->active_display_list(), match_rect); |
| 167 // Fallback to the primary display if there is no matching display. | 176 // Fallback to the primary display if there is no matching display. |
| 168 return matching ? *matching : GetPrimaryDisplay(); | 177 return matching ? *matching : GetPrimaryDisplay(); |
| 169 } | 178 } |
| 170 | 179 |
| 171 gfx::Display ScreenAsh::GetPrimaryDisplay() const { | 180 display::Display ScreenAsh::GetPrimaryDisplay() const { |
| 172 return GetDisplayManager()->GetDisplayForId( | 181 return GetDisplayManager()->GetDisplayForId( |
| 173 WindowTreeHostManager::GetPrimaryDisplayId()); | 182 WindowTreeHostManager::GetPrimaryDisplayId()); |
| 174 } | 183 } |
| 175 | 184 |
| 176 void ScreenAsh::AddObserver(gfx::DisplayObserver* observer) { | 185 void ScreenAsh::AddObserver(display::DisplayObserver* observer) { |
| 177 observers_.AddObserver(observer); | 186 observers_.AddObserver(observer); |
| 178 } | 187 } |
| 179 | 188 |
| 180 void ScreenAsh::RemoveObserver(gfx::DisplayObserver* observer) { | 189 void ScreenAsh::RemoveObserver(display::DisplayObserver* observer) { |
| 181 observers_.RemoveObserver(observer); | 190 observers_.RemoveObserver(observer); |
| 182 } | 191 } |
| 183 | 192 |
| 184 gfx::Screen* ScreenAsh::CloneForShutdown() { | 193 display::Screen* ScreenAsh::CloneForShutdown() { |
| 185 return new ScreenForShutdown(this); | 194 return new ScreenForShutdown(this); |
| 186 } | 195 } |
| 187 | 196 |
| 188 } // namespace ash | 197 } // namespace ash |
| OLD | NEW |