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