| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/common/shelf/wm_shelf.h" | 5 #include "ash/common/shelf/wm_shelf.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" |
| 7 #include "ash/common/shelf/shelf_controller.h" | 8 #include "ash/common/shelf/shelf_controller.h" |
| 8 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 9 #include "ash/common/shelf/shelf_item_delegate.h" | 10 #include "ash/common/shelf/shelf_item_delegate.h" |
| 10 #include "ash/common/shelf/shelf_layout_manager.h" | 11 #include "ash/common/shelf/shelf_layout_manager.h" |
| 11 #include "ash/common/shelf/shelf_locking_manager.h" | 12 #include "ash/common/shelf/shelf_locking_manager.h" |
| 12 #include "ash/common/shelf/shelf_model.h" | 13 #include "ash/common/shelf/shelf_model.h" |
| 13 #include "ash/common/shelf/shelf_widget.h" | 14 #include "ash/common/shelf/shelf_widget.h" |
| 14 #include "ash/common/shelf/wm_shelf_observer.h" | 15 #include "ash/common/shelf/wm_shelf_observer.h" |
| 15 #include "ash/common/system/tray/system_tray_delegate.h" | 16 #include "ash/common/system/tray/system_tray_delegate.h" |
| 16 #include "ash/common/wm_lookup.h" | 17 #include "ash/common/wm_lookup.h" |
| 17 #include "ash/common/wm_root_window_controller.h" | 18 #include "ash/common/wm_root_window_controller.h" |
| 18 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
| 19 #include "ash/common/wm_window.h" | 20 #include "ash/common/wm_window.h" |
| 20 #include "ash/public/cpp/shell_window_ids.h" | 21 #include "ash/public/cpp/shell_window_ids.h" |
| 22 #include "ash/shelf/shelf_bezel_event_handler.h" |
| 23 #include "ash/shell.h" |
| 21 #include "base/logging.h" | 24 #include "base/logging.h" |
| 25 #include "base/memory/ptr_util.h" |
| 26 #include "ui/aura/env.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
| 23 | 28 |
| 24 namespace ash { | 29 namespace ash { |
| 25 | 30 |
| 31 // WmShelf::AutoHideEventHandler ----------------------------------------------- |
| 32 |
| 33 // Forwards mouse and gesture events to ShelfLayoutManager for auto-hide. |
| 34 // TODO(mash): Add similar event handling support for mash. |
| 35 class WmShelf::AutoHideEventHandler : public ui::EventHandler { |
| 36 public: |
| 37 explicit AutoHideEventHandler(ShelfLayoutManager* shelf_layout_manager) |
| 38 : shelf_layout_manager_(shelf_layout_manager) { |
| 39 Shell::GetInstance()->AddPreTargetHandler(this); |
| 40 } |
| 41 ~AutoHideEventHandler() override { |
| 42 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 43 } |
| 44 |
| 45 // Overridden from ui::EventHandler: |
| 46 void OnMouseEvent(ui::MouseEvent* event) override { |
| 47 shelf_layout_manager_->UpdateAutoHideForMouseEvent( |
| 48 event, WmWindowAura::Get(static_cast<aura::Window*>(event->target()))); |
| 49 } |
| 50 void OnGestureEvent(ui::GestureEvent* event) override { |
| 51 shelf_layout_manager_->UpdateAutoHideForGestureEvent( |
| 52 event, WmWindowAura::Get(static_cast<aura::Window*>(event->target()))); |
| 53 } |
| 54 |
| 55 private: |
| 56 ShelfLayoutManager* shelf_layout_manager_; |
| 57 DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler); |
| 58 }; |
| 59 |
| 60 // WmShelf --------------------------------------------------------------------- |
| 61 |
| 62 WmShelf::WmShelf() : time_last_auto_hide_change_(base::TimeTicks::Now()) {} |
| 63 |
| 64 WmShelf::~WmShelf() {} |
| 65 |
| 26 // static | 66 // static |
| 27 WmShelf* WmShelf::ForWindow(WmWindow* window) { | 67 WmShelf* WmShelf::ForWindow(WmWindow* window) { |
| 28 return window->GetRootWindowController()->GetShelf(); | 68 return window->GetRootWindowController()->GetShelf(); |
| 29 } | 69 } |
| 30 | 70 |
| 31 // static | 71 // static |
| 32 bool WmShelf::CanChangeShelfAlignment() { | 72 bool WmShelf::CanChangeShelfAlignment() { |
| 33 if (WmShell::Get()->system_tray_delegate()->IsUserSupervised()) | 73 if (WmShell::Get()->system_tray_delegate()->IsUserSupervised()) |
| 34 return false; | 74 return false; |
| 35 | 75 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 65 DCHECK(!shelf_layout_manager_); | 105 DCHECK(!shelf_layout_manager_); |
| 66 shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); | 106 shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); |
| 67 shelf_layout_manager_->AddObserver(this); | 107 shelf_layout_manager_->AddObserver(this); |
| 68 | 108 |
| 69 // Must occur after |shelf_widget_| is constructed because the system tray | 109 // Must occur after |shelf_widget_| is constructed because the system tray |
| 70 // constructors call back into WmShelf::shelf_widget(). | 110 // constructors call back into WmShelf::shelf_widget(). |
| 71 DCHECK(!shelf_widget_->status_area_widget()); | 111 DCHECK(!shelf_widget_->status_area_widget()); |
| 72 WmWindow* status_container = | 112 WmWindow* status_container = |
| 73 root->GetChildByShellWindowId(kShellWindowId_StatusContainer); | 113 root->GetChildByShellWindowId(kShellWindowId_StatusContainer); |
| 74 shelf_widget_->CreateStatusAreaWidget(status_container); | 114 shelf_widget_->CreateStatusAreaWidget(status_container); |
| 115 |
| 116 // TODO: ShelfBezelEventHandler needs to work with mus too. |
| 117 // http://crbug.com/636647 |
| 118 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL) |
| 119 bezel_event_handler_ = base::MakeUnique<ShelfBezelEventHandler>(this); |
| 75 } | 120 } |
| 76 | 121 |
| 77 void WmShelf::ShutdownShelfWidget() { | 122 void WmShelf::ShutdownShelfWidget() { |
| 78 if (shelf_widget_) | 123 if (shelf_widget_) |
| 79 shelf_widget_->Shutdown(); | 124 shelf_widget_->Shutdown(); |
| 80 } | 125 } |
| 81 | 126 |
| 82 void WmShelf::DestroyShelfWidget() { | 127 void WmShelf::DestroyShelfWidget() { |
| 83 shelf_widget_.reset(); | 128 shelf_widget_.reset(); |
| 84 } | 129 } |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 347 } |
| 303 | 348 |
| 304 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { | 349 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { |
| 305 return shelf_locking_manager_.get(); | 350 return shelf_locking_manager_.get(); |
| 306 } | 351 } |
| 307 | 352 |
| 308 ShelfView* WmShelf::GetShelfViewForTesting() { | 353 ShelfView* WmShelf::GetShelfViewForTesting() { |
| 309 return shelf_view_; | 354 return shelf_view_; |
| 310 } | 355 } |
| 311 | 356 |
| 312 WmShelf::WmShelf() : time_last_auto_hide_change_(base::TimeTicks::Now()) {} | 357 void WmShelf::WillDeleteShelfLayoutManager() { |
| 358 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS) { |
| 359 // TODO(sky): this should be removed once Shell is used everywhere. |
| 360 ShutdownShelfWidget(); |
| 361 } |
| 313 | 362 |
| 314 WmShelf::~WmShelf() {} | 363 // Clear event handlers that might forward events to the destroyed instance. |
| 364 auto_hide_event_handler_.reset(); |
| 365 bezel_event_handler_.reset(); |
| 315 | 366 |
| 316 void WmShelf::WillDeleteShelfLayoutManager() { | |
| 317 DCHECK(shelf_layout_manager_); | 367 DCHECK(shelf_layout_manager_); |
| 318 shelf_layout_manager_->RemoveObserver(this); | 368 shelf_layout_manager_->RemoveObserver(this); |
| 319 shelf_layout_manager_ = nullptr; | 369 shelf_layout_manager_ = nullptr; |
| 320 } | 370 } |
| 321 | 371 |
| 322 void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { | 372 void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { |
| 323 for (auto& observer : observers_) | 373 for (auto& observer : observers_) |
| 324 observer.WillChangeVisibilityState(new_state); | 374 observer.WillChangeVisibilityState(new_state); |
| 375 if (new_state != SHELF_AUTO_HIDE) { |
| 376 auto_hide_event_handler_.reset(); |
| 377 } else if (!auto_hide_event_handler_ && |
| 378 aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL) { |
| 379 auto_hide_event_handler_ = |
| 380 base::MakeUnique<AutoHideEventHandler>(shelf_layout_manager()); |
| 381 } |
| 325 } | 382 } |
| 326 | 383 |
| 327 void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | 384 void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |
| 328 for (auto& observer : observers_) | 385 for (auto& observer : observers_) |
| 329 observer.OnAutoHideStateChanged(new_state); | 386 observer.OnAutoHideStateChanged(new_state); |
| 330 } | 387 } |
| 331 | 388 |
| 332 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, | 389 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, |
| 333 BackgroundAnimatorChangeType change_type) { | 390 BackgroundAnimatorChangeType change_type) { |
| 334 if (background_type == GetBackgroundType()) | 391 if (background_type == GetBackgroundType()) |
| 335 return; | 392 return; |
| 336 for (auto& observer : observers_) | 393 for (auto& observer : observers_) |
| 337 observer.OnBackgroundTypeChanged(background_type, change_type); | 394 observer.OnBackgroundTypeChanged(background_type, change_type); |
| 338 } | 395 } |
| 339 | 396 |
| 340 } // namespace ash | 397 } // namespace ash |
| OLD | NEW |