Chromium Code Reviews| Index: ash/common/shelf/wm_shelf.cc |
| diff --git a/ash/common/shelf/wm_shelf.cc b/ash/common/shelf/wm_shelf.cc |
| index a86a9915a3f02315610627c1a69a46971b185e69..aee9807629b02335b043e268e6eb378926db4418 100644 |
| --- a/ash/common/shelf/wm_shelf.cc |
| +++ b/ash/common/shelf/wm_shelf.cc |
| @@ -4,6 +4,7 @@ |
| #include "ash/common/shelf/wm_shelf.h" |
| +#include "ash/aura/wm_window_aura.h" |
| #include "ash/common/shelf/shelf_controller.h" |
| #include "ash/common/shelf/shelf_delegate.h" |
| #include "ash/common/shelf/shelf_item_delegate.h" |
| @@ -18,11 +19,50 @@ |
| #include "ash/common/wm_shell.h" |
| #include "ash/common/wm_window.h" |
| #include "ash/public/cpp/shell_window_ids.h" |
| +#include "ash/shelf/shelf_bezel_event_handler.h" |
| +#include "ash/shell.h" |
| #include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "ui/aura/env.h" |
| #include "ui/gfx/geometry/rect.h" |
| namespace ash { |
| +// WmShelf::AutoHideEventHandler ----------------------------------------------- |
| + |
| +// Forwards mouse and gesture events to ShelfLayoutManager for auto-hide. |
| +// TODO(mash): Add similar event handling support for mash. |
| +class WmShelf::AutoHideEventHandler : public ui::EventHandler { |
| + public: |
| + explicit AutoHideEventHandler(ShelfLayoutManager* shelf_layout_manager) |
| + : shelf_layout_manager_(shelf_layout_manager) { |
| + Shell::GetInstance()->AddPreTargetHandler(this); |
| + } |
| + ~AutoHideEventHandler() override { |
| + Shell::GetInstance()->RemovePreTargetHandler(this); |
| + } |
| + |
| + // Overridden from ui::EventHandler: |
| + void OnMouseEvent(ui::MouseEvent* event) override { |
| + shelf_layout_manager_->UpdateAutoHideForMouseEvent( |
| + event, WmWindowAura::Get(static_cast<aura::Window*>(event->target()))); |
| + } |
| + void OnGestureEvent(ui::GestureEvent* event) override { |
| + shelf_layout_manager_->UpdateAutoHideForGestureEvent( |
| + event, WmWindowAura::Get(static_cast<aura::Window*>(event->target()))); |
| + } |
| + |
| + private: |
| + ShelfLayoutManager* shelf_layout_manager_; |
| + DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler); |
| +}; |
| + |
| +// WmShelf --------------------------------------------------------------------- |
| + |
| +WmShelf::WmShelf() : time_last_auto_hide_change_(base::TimeTicks::Now()) {} |
| + |
| +WmShelf::~WmShelf() {} |
| + |
| // static |
| WmShelf* WmShelf::ForWindow(WmWindow* window) { |
| return window->GetRootWindowController()->GetShelf(); |
| @@ -72,6 +112,11 @@ void WmShelf::CreateShelfWidget(WmWindow* root) { |
| WmWindow* status_container = |
| root->GetChildByShellWindowId(kShellWindowId_StatusContainer); |
| shelf_widget_->CreateStatusAreaWidget(status_container); |
| + |
| + // TODO: ShelfBezelEventHandler needs to work with mus too. |
| + // http://crbug.com/636647 |
| + if (aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL) |
| + bezel_event_handler_ = base::MakeUnique<ShelfBezelEventHandler>(this); |
| } |
| void WmShelf::ShutdownShelfWidget() { |
| @@ -309,11 +354,16 @@ ShelfView* WmShelf::GetShelfViewForTesting() { |
| return shelf_view_; |
| } |
| -WmShelf::WmShelf() : time_last_auto_hide_change_(base::TimeTicks::Now()) {} |
| +void WmShelf::WillDeleteShelfLayoutManager() { |
| + if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS) { |
| + // TODO(sky): this should be removed once consolidate on Shell. |
|
msw
2017/01/09 19:13:55
optional nit: grammar
|
| + ShutdownShelfWidget(); |
| + } |
| -WmShelf::~WmShelf() {} |
| + // Clear event handlers that might forward events to the destroyed instance. |
| + auto_hide_event_handler_.reset(); |
| + bezel_event_handler_.reset(); |
| -void WmShelf::WillDeleteShelfLayoutManager() { |
| DCHECK(shelf_layout_manager_); |
| shelf_layout_manager_->RemoveObserver(this); |
| shelf_layout_manager_ = nullptr; |
| @@ -322,6 +372,13 @@ void WmShelf::WillDeleteShelfLayoutManager() { |
| void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { |
| for (auto& observer : observers_) |
| observer.WillChangeVisibilityState(new_state); |
| + if (new_state != SHELF_AUTO_HIDE) { |
| + auto_hide_event_handler_.reset(); |
| + } else if (!auto_hide_event_handler_ && |
| + aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL) { |
| + auto_hide_event_handler_ = |
| + base::MakeUnique<AutoHideEventHandler>(shelf_layout_manager()); |
| + } |
| } |
| void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |