| 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 "athena/env/public/athena_env.h" | 5 #include "athena/env/public/athena_env.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "athena/util/fill_layout_manager.h" | 9 #include "athena/util/fill_layout_manager.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 screen_for_shutdown = new ScreenForShutdown(screen->GetPrimaryDisplay()); | 49 screen_for_shutdown = new ScreenForShutdown(screen->GetPrimaryDisplay()); |
| 50 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, | 50 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, |
| 51 screen_for_shutdown); | 51 screen_for_shutdown); |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 explicit ScreenForShutdown(const gfx::Display& primary_display) | 55 explicit ScreenForShutdown(const gfx::Display& primary_display) |
| 56 : primary_display_(primary_display) {} | 56 : primary_display_(primary_display) {} |
| 57 | 57 |
| 58 // gfx::Screen overrides: | 58 // gfx::Screen overrides: |
| 59 virtual gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | 59 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } |
| 60 virtual gfx::NativeWindow GetWindowUnderCursor() override { return nullptr; } | 60 gfx::NativeWindow GetWindowUnderCursor() override { return NULL; } |
| 61 virtual gfx::NativeWindow GetWindowAtScreenPoint( | 61 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { |
| 62 const gfx::Point& point) override { | |
| 63 return nullptr; | 62 return nullptr; |
| 64 } | 63 } |
| 65 virtual int GetNumDisplays() const override { return 1; } | 64 int GetNumDisplays() const override { return 1; } |
| 66 virtual std::vector<gfx::Display> GetAllDisplays() const override { | 65 std::vector<gfx::Display> GetAllDisplays() const override { |
| 67 std::vector<gfx::Display> displays(1, primary_display_); | 66 std::vector<gfx::Display> displays(1, primary_display_); |
| 68 return displays; | 67 return displays; |
| 69 } | 68 } |
| 70 virtual gfx::Display GetDisplayNearestWindow( | 69 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { |
| 71 gfx::NativeView view) const override { | |
| 72 return primary_display_; | 70 return primary_display_; |
| 73 } | 71 } |
| 74 virtual gfx::Display GetDisplayNearestPoint( | 72 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { |
| 75 const gfx::Point& point) const override { | |
| 76 return primary_display_; | 73 return primary_display_; |
| 77 } | 74 } |
| 78 virtual gfx::Display GetDisplayMatching( | 75 gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override { |
| 79 const gfx::Rect& match_rect) const override { | |
| 80 return primary_display_; | 76 return primary_display_; |
| 81 } | 77 } |
| 82 virtual gfx::Display GetPrimaryDisplay() const override { | 78 gfx::Display GetPrimaryDisplay() const override { return primary_display_; } |
| 83 return primary_display_; | 79 void AddObserver(gfx::DisplayObserver* observer) override { |
| 84 } | |
| 85 virtual void AddObserver(gfx::DisplayObserver* observer) override { | |
| 86 NOTREACHED() << "Observer should not be added during shutdown"; | 80 NOTREACHED() << "Observer should not be added during shutdown"; |
| 87 } | 81 } |
| 88 virtual void RemoveObserver(gfx::DisplayObserver* observer) override {} | 82 void RemoveObserver(gfx::DisplayObserver* observer) override {} |
| 89 | 83 |
| 90 const gfx::Display primary_display_; | 84 const gfx::Display primary_display_; |
| 91 | 85 |
| 92 DISALLOW_COPY_AND_ASSIGN(ScreenForShutdown); | 86 DISALLOW_COPY_AND_ASSIGN(ScreenForShutdown); |
| 93 }; | 87 }; |
| 94 | 88 |
| 95 // A class that bridges the gap between CursorManager and Aura. It borrows | 89 // A class that bridges the gap between CursorManager and Aura. It borrows |
| 96 // heavily from AshNativeCursorManager. | 90 // heavily from AshNativeCursorManager. |
| 97 class AthenaNativeCursorManager : public wm::NativeCursorManager { | 91 class AthenaNativeCursorManager : public wm::NativeCursorManager { |
| 98 public: | 92 public: |
| 99 explicit AthenaNativeCursorManager(aura::WindowTreeHost* host) | 93 explicit AthenaNativeCursorManager(aura::WindowTreeHost* host) |
| 100 : host_(host), image_cursors_(new ui::ImageCursors) {} | 94 : host_(host), image_cursors_(new ui::ImageCursors) {} |
| 101 virtual ~AthenaNativeCursorManager() {} | 95 ~AthenaNativeCursorManager() override {} |
| 102 | 96 |
| 103 // wm::NativeCursorManager overrides. | 97 // wm::NativeCursorManager overrides. |
| 104 virtual void SetDisplay(const gfx::Display& display, | 98 void SetDisplay(const gfx::Display& display, |
| 105 wm::NativeCursorManagerDelegate* delegate) override { | 99 wm::NativeCursorManagerDelegate* delegate) override { |
| 106 if (image_cursors_->SetDisplay(display, display.device_scale_factor())) | 100 if (image_cursors_->SetDisplay(display, display.device_scale_factor())) |
| 107 SetCursor(delegate->GetCursor(), delegate); | 101 SetCursor(delegate->GetCursor(), delegate); |
| 108 } | 102 } |
| 109 | 103 |
| 110 virtual void SetCursor(gfx::NativeCursor cursor, | 104 void SetCursor(gfx::NativeCursor cursor, |
| 111 wm::NativeCursorManagerDelegate* delegate) override { | 105 wm::NativeCursorManagerDelegate* delegate) override { |
| 112 image_cursors_->SetPlatformCursor(&cursor); | 106 image_cursors_->SetPlatformCursor(&cursor); |
| 113 cursor.set_device_scale_factor(image_cursors_->GetScale()); | 107 cursor.set_device_scale_factor(image_cursors_->GetScale()); |
| 114 delegate->CommitCursor(cursor); | 108 delegate->CommitCursor(cursor); |
| 115 | 109 |
| 116 if (delegate->IsCursorVisible()) | 110 if (delegate->IsCursorVisible()) |
| 117 ApplyCursor(cursor); | 111 ApplyCursor(cursor); |
| 118 } | 112 } |
| 119 | 113 |
| 120 virtual void SetVisibility( | 114 void SetVisibility(bool visible, |
| 121 bool visible, | 115 wm::NativeCursorManagerDelegate* delegate) override { |
| 122 wm::NativeCursorManagerDelegate* delegate) override { | |
| 123 delegate->CommitVisibility(visible); | 116 delegate->CommitVisibility(visible); |
| 124 | 117 |
| 125 if (visible) { | 118 if (visible) { |
| 126 SetCursor(delegate->GetCursor(), delegate); | 119 SetCursor(delegate->GetCursor(), delegate); |
| 127 } else { | 120 } else { |
| 128 gfx::NativeCursor invisible_cursor(ui::kCursorNone); | 121 gfx::NativeCursor invisible_cursor(ui::kCursorNone); |
| 129 image_cursors_->SetPlatformCursor(&invisible_cursor); | 122 image_cursors_->SetPlatformCursor(&invisible_cursor); |
| 130 ApplyCursor(invisible_cursor); | 123 ApplyCursor(invisible_cursor); |
| 131 } | 124 } |
| 132 } | 125 } |
| 133 | 126 |
| 134 virtual void SetCursorSet( | 127 void SetCursorSet(ui::CursorSetType cursor_set, |
| 135 ui::CursorSetType cursor_set, | 128 wm::NativeCursorManagerDelegate* delegate) override { |
| 136 wm::NativeCursorManagerDelegate* delegate) override { | |
| 137 image_cursors_->SetCursorSet(cursor_set); | 129 image_cursors_->SetCursorSet(cursor_set); |
| 138 delegate->CommitCursorSet(cursor_set); | 130 delegate->CommitCursorSet(cursor_set); |
| 139 if (delegate->IsCursorVisible()) | 131 if (delegate->IsCursorVisible()) |
| 140 SetCursor(delegate->GetCursor(), delegate); | 132 SetCursor(delegate->GetCursor(), delegate); |
| 141 } | 133 } |
| 142 | 134 |
| 143 virtual void SetMouseEventsEnabled( | 135 void SetMouseEventsEnabled( |
| 144 bool enabled, | 136 bool enabled, |
| 145 wm::NativeCursorManagerDelegate* delegate) override { | 137 wm::NativeCursorManagerDelegate* delegate) override { |
| 146 delegate->CommitMouseEventsEnabled(enabled); | 138 delegate->CommitMouseEventsEnabled(enabled); |
| 147 SetVisibility(delegate->IsCursorVisible(), delegate); | 139 SetVisibility(delegate->IsCursorVisible(), delegate); |
| 148 } | 140 } |
| 149 | 141 |
| 150 private: | 142 private: |
| 151 // Sets |cursor| as the active cursor within Aura. | 143 // Sets |cursor| as the active cursor within Aura. |
| 152 void ApplyCursor(gfx::NativeCursor cursor) { host_->SetCursor(cursor); } | 144 void ApplyCursor(gfx::NativeCursor cursor) { host_->SetCursor(cursor); } |
| 153 | 145 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 user_activity_notifier_.reset(new ui::UserActivityPowerManagerNotifier( | 203 user_activity_notifier_.reset(new ui::UserActivityPowerManagerNotifier( |
| 212 user_activity_detector_.get())); | 204 user_activity_detector_.get())); |
| 213 | 205 |
| 214 host_->AddObserver(this); | 206 host_->AddObserver(this); |
| 215 host_->Show(); | 207 host_->Show(); |
| 216 | 208 |
| 217 DCHECK(!instance); | 209 DCHECK(!instance); |
| 218 instance = this; | 210 instance = this; |
| 219 } | 211 } |
| 220 | 212 |
| 221 virtual ~AthenaEnvImpl() { | 213 ~AthenaEnvImpl() override { |
| 222 instance = nullptr; | 214 instance = nullptr; |
| 223 | 215 |
| 224 host_->RemoveObserver(this); | 216 host_->RemoveObserver(this); |
| 225 if (input_method_filter_) | 217 if (input_method_filter_) |
| 226 root_window_event_filter_->RemoveHandler(input_method_filter_.get()); | 218 root_window_event_filter_->RemoveHandler(input_method_filter_.get()); |
| 227 if (user_activity_detector_) { | 219 if (user_activity_detector_) { |
| 228 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler( | 220 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler( |
| 229 user_activity_detector_.get()); | 221 user_activity_detector_.get()); |
| 230 } | 222 } |
| 231 root_window_event_filter_.reset(); | 223 root_window_event_filter_.reset(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 249 private: | 241 private: |
| 250 struct Finder { | 242 struct Finder { |
| 251 explicit Finder(const base::Closure& c) : closure(c) {} | 243 explicit Finder(const base::Closure& c) : closure(c) {} |
| 252 bool operator()(const base::Closure& other) { | 244 bool operator()(const base::Closure& other) { |
| 253 return closure.Equals(other); | 245 return closure.Equals(other); |
| 254 } | 246 } |
| 255 base::Closure closure; | 247 base::Closure closure; |
| 256 }; | 248 }; |
| 257 | 249 |
| 258 // AthenaEnv: | 250 // AthenaEnv: |
| 259 virtual aura::WindowTreeHost* GetHost() override { return host_.get(); } | 251 aura::WindowTreeHost* GetHost() override { return host_.get(); } |
| 260 | 252 |
| 261 virtual void SetDisplayWorkAreaInsets(const gfx::Insets& insets) override { | 253 void SetDisplayWorkAreaInsets(const gfx::Insets& insets) override { |
| 262 screen_->SetWorkAreaInsets(insets); | 254 screen_->SetWorkAreaInsets(insets); |
| 263 } | 255 } |
| 264 | 256 |
| 265 virtual void AddTerminatingCallback(const base::Closure& closure) override { | 257 void AddTerminatingCallback(const base::Closure& closure) override { |
| 266 if (closure.is_null()) | 258 if (closure.is_null()) |
| 267 return; | 259 return; |
| 268 DCHECK(terminating_callbacks_.end() == | 260 DCHECK(terminating_callbacks_.end() == |
| 269 std::find_if(terminating_callbacks_.begin(), | 261 std::find_if(terminating_callbacks_.begin(), |
| 270 terminating_callbacks_.end(), | 262 terminating_callbacks_.end(), |
| 271 Finder(closure))); | 263 Finder(closure))); |
| 272 terminating_callbacks_.push_back(closure); | 264 terminating_callbacks_.push_back(closure); |
| 273 } | 265 } |
| 274 | 266 |
| 275 virtual void RemoveTerminatingCallback( | 267 void RemoveTerminatingCallback(const base::Closure& closure) override { |
| 276 const base::Closure& closure) override { | |
| 277 std::vector<base::Closure>::iterator iter = | 268 std::vector<base::Closure>::iterator iter = |
| 278 std::find_if(terminating_callbacks_.begin(), | 269 std::find_if(terminating_callbacks_.begin(), |
| 279 terminating_callbacks_.end(), | 270 terminating_callbacks_.end(), |
| 280 Finder(closure)); | 271 Finder(closure)); |
| 281 if (iter != terminating_callbacks_.end()) | 272 if (iter != terminating_callbacks_.end()) |
| 282 terminating_callbacks_.erase(iter); | 273 terminating_callbacks_.erase(iter); |
| 283 } | 274 } |
| 284 | 275 |
| 285 virtual void OnTerminating() override { | 276 void OnTerminating() override { |
| 286 for (std::vector<base::Closure>::iterator iter = | 277 for (std::vector<base::Closure>::iterator iter = |
| 287 terminating_callbacks_.begin(); | 278 terminating_callbacks_.begin(); |
| 288 iter != terminating_callbacks_.end(); | 279 iter != terminating_callbacks_.end(); |
| 289 ++iter) { | 280 ++iter) { |
| 290 iter->Run(); | 281 iter->Run(); |
| 291 } | 282 } |
| 292 } | 283 } |
| 293 | 284 |
| 294 // ui::DisplayConfigurator::Observer: | 285 // ui::DisplayConfigurator::Observer: |
| 295 virtual void OnDisplayModeChanged(const std::vector< | 286 void OnDisplayModeChanged( |
| 296 ui::DisplayConfigurator::DisplayState>& displays) override { | 287 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) |
| 288 override { |
| 297 gfx::Size size = GetPrimaryDisplaySize(); | 289 gfx::Size size = GetPrimaryDisplaySize(); |
| 298 if (!size.IsEmpty()) | 290 if (!size.IsEmpty()) |
| 299 host_->UpdateRootWindowSize(size); | 291 host_->UpdateRootWindowSize(size); |
| 300 } | 292 } |
| 301 | 293 |
| 302 // aura::WindowTreeHostObserver: | 294 // aura::WindowTreeHostObserver: |
| 303 virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) override { | 295 void OnHostCloseRequested(const aura::WindowTreeHost* host) override { |
| 304 base::MessageLoopForUI::current()->PostTask( | 296 base::MessageLoopForUI::current()->PostTask( |
| 305 FROM_HERE, base::MessageLoop::QuitClosure()); | 297 FROM_HERE, base::MessageLoop::QuitClosure()); |
| 306 } | 298 } |
| 307 | 299 |
| 308 gfx::Size GetPrimaryDisplaySize() const { | 300 gfx::Size GetPrimaryDisplaySize() const { |
| 309 const std::vector<ui::DisplayConfigurator::DisplayState>& displays = | 301 const std::vector<ui::DisplayConfigurator::DisplayState>& displays = |
| 310 display_configurator_->cached_displays(); | 302 display_configurator_->cached_displays(); |
| 311 if (displays.empty()) | 303 if (displays.empty()) |
| 312 return gfx::Size(); | 304 return gfx::Size(); |
| 313 const ui::DisplayMode* mode = displays[0].display->current_mode(); | 305 const ui::DisplayMode* mode = displays[0].display->current_mode(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 337 |
| 346 // static | 338 // static |
| 347 | 339 |
| 348 // static | 340 // static |
| 349 void AthenaEnv::Shutdown() { | 341 void AthenaEnv::Shutdown() { |
| 350 DCHECK(instance); | 342 DCHECK(instance); |
| 351 delete instance; | 343 delete instance; |
| 352 } | 344 } |
| 353 | 345 |
| 354 } // namespace athena | 346 } // namespace athena |
| OLD | NEW |