| 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/aura/wm_shelf_aura.h" | 5 #include "ash/aura/wm_shelf_aura.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/shelf/wm_shelf_observer.h" | 8 #include "ash/common/shelf/wm_shelf_observer.h" |
| 9 #include "ash/common/wm_window.h" | 9 #include "ash/common/wm_window.h" |
| 10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
| 11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
| 12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 14 | 14 |
| 15 namespace ash { | 15 namespace ash { |
| 16 | 16 |
| 17 // WmShelfAura::AutoHideEventHandler ------------------------------------------- |
| 18 |
| 19 // Forwards mouse and gesture events to ShelfLayoutManager for auto-hide. |
| 20 // TODO(mash): Add similar event handling support for mash. |
| 21 class WmShelfAura::AutoHideEventHandler : public ui::EventHandler { |
| 22 public: |
| 23 explicit AutoHideEventHandler(ShelfLayoutManager* shelf_layout_manager) |
| 24 : shelf_layout_manager_(shelf_layout_manager) { |
| 25 Shell::GetInstance()->AddPreTargetHandler(this); |
| 26 } |
| 27 ~AutoHideEventHandler() override { |
| 28 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 29 } |
| 30 |
| 31 // Overridden from ui::EventHandler: |
| 32 void OnMouseEvent(ui::MouseEvent* event) override { |
| 33 shelf_layout_manager_->UpdateAutoHideForMouseEvent( |
| 34 event, WmWindowAura::Get(static_cast<aura::Window*>(event->target()))); |
| 35 } |
| 36 void OnGestureEvent(ui::GestureEvent* event) override { |
| 37 shelf_layout_manager_->UpdateAutoHideForGestureEvent( |
| 38 event, WmWindowAura::Get(static_cast<aura::Window*>(event->target()))); |
| 39 } |
| 40 |
| 41 private: |
| 42 ShelfLayoutManager* shelf_layout_manager_; |
| 43 DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler); |
| 44 }; |
| 45 |
| 46 // WmShelfAura ----------------------------------------------------------------- |
| 47 |
| 17 WmShelfAura::WmShelfAura() {} | 48 WmShelfAura::WmShelfAura() {} |
| 18 | 49 |
| 19 WmShelfAura::~WmShelfAura() {} | 50 WmShelfAura::~WmShelfAura() {} |
| 20 | 51 |
| 21 void WmShelfAura::SetShelfLayoutManager( | 52 void WmShelfAura::SetShelfLayoutManager( |
| 22 ShelfLayoutManager* shelf_layout_manager) { | 53 ShelfLayoutManager* shelf_layout_manager) { |
| 23 DCHECK(!shelf_layout_manager_); | 54 DCHECK(!shelf_layout_manager_); |
| 24 shelf_layout_manager_ = shelf_layout_manager; | 55 shelf_layout_manager_ = shelf_layout_manager; |
| 25 shelf_layout_manager_->AddObserver(this); | 56 shelf_layout_manager_->AddObserver(this); |
| 26 } | 57 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 41 } | 72 } |
| 42 | 73 |
| 43 // static | 74 // static |
| 44 Shelf* WmShelfAura::GetShelf(WmShelf* shelf) { | 75 Shelf* WmShelfAura::GetShelf(WmShelf* shelf) { |
| 45 return static_cast<WmShelfAura*>(shelf)->shelf_; | 76 return static_cast<WmShelfAura*>(shelf)->shelf_; |
| 46 } | 77 } |
| 47 | 78 |
| 48 void WmShelfAura::ResetShelfLayoutManager() { | 79 void WmShelfAura::ResetShelfLayoutManager() { |
| 49 if (!shelf_layout_manager_) | 80 if (!shelf_layout_manager_) |
| 50 return; | 81 return; |
| 82 auto_hide_event_handler_.reset(); |
| 51 shelf_layout_manager_->RemoveObserver(this); | 83 shelf_layout_manager_->RemoveObserver(this); |
| 52 shelf_layout_manager_ = nullptr; | 84 shelf_layout_manager_ = nullptr; |
| 53 } | 85 } |
| 54 | 86 |
| 55 WmWindow* WmShelfAura::GetWindow() { | 87 WmWindow* WmShelfAura::GetWindow() { |
| 56 // Use |shelf_layout_manager_| to access ShelfWidget because it is set | 88 // Use |shelf_layout_manager_| to access ShelfWidget because it is set |
| 57 // before |shelf_| is available. | 89 // before |shelf_| is available. |
| 58 return WmWindowAura::Get( | 90 return WmWindowAura::Get( |
| 59 shelf_layout_manager_->shelf_widget()->GetNativeView()); | 91 shelf_layout_manager_->shelf_widget()->GetNativeView()); |
| 60 } | 92 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 WmWindowAura::GetAuraWindow(window)); | 165 WmWindowAura::GetAuraWindow(window)); |
| 134 } | 166 } |
| 135 | 167 |
| 136 bool WmShelfAura::ProcessGestureEvent(const ui::GestureEvent& event) { | 168 bool WmShelfAura::ProcessGestureEvent(const ui::GestureEvent& event) { |
| 137 // Can be called at login screen. | 169 // Can be called at login screen. |
| 138 if (!shelf_layout_manager_) | 170 if (!shelf_layout_manager_) |
| 139 return false; | 171 return false; |
| 140 return shelf_layout_manager_->ProcessGestureEvent(event); | 172 return shelf_layout_manager_->ProcessGestureEvent(event); |
| 141 } | 173 } |
| 142 | 174 |
| 143 void WmShelfAura::UpdateAutoHideForMouseEvent(ui::MouseEvent* event) { | |
| 144 // Auto-hide support for ash_sysui. | |
| 145 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | |
| 146 shelf_layout_manager_->UpdateAutoHideForMouseEvent(event); | |
| 147 } | |
| 148 | |
| 149 void WmShelfAura::UpdateAutoHideForGestureEvent(ui::GestureEvent* event) { | |
| 150 // Auto-hide support for ash_sysui. | |
| 151 if (Shell::GetInstance()->in_mus() && shelf_layout_manager_) | |
| 152 shelf_layout_manager_->UpdateAutoHideForGestureEvent(event); | |
| 153 } | |
| 154 | |
| 155 void WmShelfAura::AddObserver(WmShelfObserver* observer) { | 175 void WmShelfAura::AddObserver(WmShelfObserver* observer) { |
| 156 observers_.AddObserver(observer); | 176 observers_.AddObserver(observer); |
| 157 } | 177 } |
| 158 | 178 |
| 159 void WmShelfAura::RemoveObserver(WmShelfObserver* observer) { | 179 void WmShelfAura::RemoveObserver(WmShelfObserver* observer) { |
| 160 observers_.RemoveObserver(observer); | 180 observers_.RemoveObserver(observer); |
| 161 } | 181 } |
| 162 | 182 |
| 163 void WmShelfAura::SetKeyboardBoundsForTesting(const gfx::Rect& bounds) { | 183 void WmShelfAura::SetKeyboardBoundsForTesting(const gfx::Rect& bounds) { |
| 164 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); | 184 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 181 BackgroundAnimatorChangeType change_type) { | 201 BackgroundAnimatorChangeType change_type) { |
| 182 if (background_type == GetBackgroundType()) | 202 if (background_type == GetBackgroundType()) |
| 183 return; | 203 return; |
| 184 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 204 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
| 185 OnBackgroundTypeChanged(background_type, change_type)); | 205 OnBackgroundTypeChanged(background_type, change_type)); |
| 186 } | 206 } |
| 187 | 207 |
| 188 void WmShelfAura::WillChangeVisibilityState(ShelfVisibilityState new_state) { | 208 void WmShelfAura::WillChangeVisibilityState(ShelfVisibilityState new_state) { |
| 189 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 209 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
| 190 WillChangeVisibilityState(new_state)); | 210 WillChangeVisibilityState(new_state)); |
| 211 |
| 212 if (new_state != SHELF_AUTO_HIDE) { |
| 213 auto_hide_event_handler_.reset(); |
| 214 } else if (!auto_hide_event_handler_) { |
| 215 auto_hide_event_handler_.reset( |
| 216 new AutoHideEventHandler(shelf_layout_manager_)); |
| 217 } |
| 191 } | 218 } |
| 192 | 219 |
| 193 void WmShelfAura::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | 220 void WmShelfAura::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |
| 194 FOR_EACH_OBSERVER(WmShelfObserver, observers_, | 221 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
| 195 OnAutoHideStateChanged(new_state)); | 222 OnAutoHideStateChanged(new_state)); |
| 196 } | 223 } |
| 197 | 224 |
| 198 void WmShelfAura::OnShelfIconPositionsChanged() { | 225 void WmShelfAura::OnShelfIconPositionsChanged() { |
| 199 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged()); | 226 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged()); |
| 200 } | 227 } |
| 201 | 228 |
| 202 } // namespace ash | 229 } // namespace ash |
| OLD | NEW |