| 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/shelf/wm_shelf.h" | 5 #include "ash/shelf/shelf.h" | 
| 6 | 6 | 
| 7 #include "ash/public/cpp/config.h" | 7 #include "ash/public/cpp/config.h" | 
| 8 #include "ash/public/cpp/shelf_item_delegate.h" | 8 #include "ash/public/cpp/shelf_item_delegate.h" | 
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" | 
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" | 
| 11 #include "ash/session/session_controller.h" | 11 #include "ash/session/session_controller.h" | 
| 12 #include "ash/shelf/shelf_bezel_event_handler.h" | 12 #include "ash/shelf/shelf_bezel_event_handler.h" | 
| 13 #include "ash/shelf/shelf_controller.h" | 13 #include "ash/shelf/shelf_controller.h" | 
| 14 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/shelf/shelf_layout_manager.h" | 
| 15 #include "ash/shelf/shelf_model.h" | 15 #include "ash/shelf/shelf_model.h" | 
|  | 16 #include "ash/shelf/shelf_observer.h" | 
| 16 #include "ash/shelf/shelf_widget.h" | 17 #include "ash/shelf/shelf_widget.h" | 
| 17 #include "ash/shelf/wm_shelf_observer.h" |  | 
| 18 #include "ash/shell.h" | 18 #include "ash/shell.h" | 
| 19 #include "ash/wm_window.h" | 19 #include "ash/wm_window.h" | 
| 20 #include "base/logging.h" | 20 #include "base/logging.h" | 
| 21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" | 
| 22 #include "ui/display/types/display_constants.h" | 22 #include "ui/display/types/display_constants.h" | 
| 23 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" | 
| 24 | 24 | 
| 25 namespace ash { | 25 namespace ash { | 
| 26 | 26 | 
| 27 namespace { | 27 namespace { | 
| 28 | 28 | 
| 29 // A callback that does nothing after shelf item selection handling. | 29 // A callback that does nothing after shelf item selection handling. | 
| 30 void NoopCallback(ShelfAction, | 30 void NoopCallback(ShelfAction, | 
| 31                   base::Optional<std::vector<mojom::MenuItemPtr>>) {} | 31                   base::Optional<std::vector<mojom::MenuItemPtr>>) {} | 
| 32 | 32 | 
| 33 }  // namespace | 33 }  // namespace | 
| 34 | 34 | 
| 35 // WmShelf::AutoHideEventHandler ----------------------------------------------- | 35 // Shelf::AutoHideEventHandler ----------------------------------------------- | 
| 36 | 36 | 
| 37 // Forwards mouse and gesture events to ShelfLayoutManager for auto-hide. | 37 // Forwards mouse and gesture events to ShelfLayoutManager for auto-hide. | 
| 38 // TODO(mash): Add similar event handling support for mash. | 38 // TODO(mash): Add similar event handling support for mash. | 
| 39 class WmShelf::AutoHideEventHandler : public ui::EventHandler { | 39 class Shelf::AutoHideEventHandler : public ui::EventHandler { | 
| 40  public: | 40  public: | 
| 41   explicit AutoHideEventHandler(ShelfLayoutManager* shelf_layout_manager) | 41   explicit AutoHideEventHandler(ShelfLayoutManager* shelf_layout_manager) | 
| 42       : shelf_layout_manager_(shelf_layout_manager) { | 42       : shelf_layout_manager_(shelf_layout_manager) { | 
| 43     Shell::Get()->AddPreTargetHandler(this); | 43     Shell::Get()->AddPreTargetHandler(this); | 
| 44   } | 44   } | 
| 45   ~AutoHideEventHandler() override { | 45   ~AutoHideEventHandler() override { | 
| 46     Shell::Get()->RemovePreTargetHandler(this); | 46     Shell::Get()->RemovePreTargetHandler(this); | 
| 47   } | 47   } | 
| 48 | 48 | 
| 49   // Overridden from ui::EventHandler: | 49   // Overridden from ui::EventHandler: | 
| 50   void OnMouseEvent(ui::MouseEvent* event) override { | 50   void OnMouseEvent(ui::MouseEvent* event) override { | 
| 51     shelf_layout_manager_->UpdateAutoHideForMouseEvent( | 51     shelf_layout_manager_->UpdateAutoHideForMouseEvent( | 
| 52         event, static_cast<aura::Window*>(event->target())); | 52         event, static_cast<aura::Window*>(event->target())); | 
| 53   } | 53   } | 
| 54   void OnGestureEvent(ui::GestureEvent* event) override { | 54   void OnGestureEvent(ui::GestureEvent* event) override { | 
| 55     shelf_layout_manager_->UpdateAutoHideForGestureEvent( | 55     shelf_layout_manager_->UpdateAutoHideForGestureEvent( | 
| 56         event, static_cast<aura::Window*>(event->target())); | 56         event, static_cast<aura::Window*>(event->target())); | 
| 57   } | 57   } | 
| 58 | 58 | 
| 59  private: | 59  private: | 
| 60   ShelfLayoutManager* shelf_layout_manager_; | 60   ShelfLayoutManager* shelf_layout_manager_; | 
| 61   DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler); | 61   DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler); | 
| 62 }; | 62 }; | 
| 63 | 63 | 
| 64 // WmShelf --------------------------------------------------------------------- | 64 // Shelf --------------------------------------------------------------------- | 
| 65 | 65 | 
| 66 WmShelf::WmShelf() : shelf_locking_manager_(this) { | 66 Shelf::Shelf() : shelf_locking_manager_(this) { | 
| 67   // TODO: ShelfBezelEventHandler needs to work with mus too. | 67   // TODO: ShelfBezelEventHandler needs to work with mus too. | 
| 68   // http://crbug.com/636647 | 68   // http://crbug.com/636647 | 
| 69   if (Shell::GetAshConfig() != Config::MASH) | 69   if (Shell::GetAshConfig() != Config::MASH) | 
| 70     bezel_event_handler_ = base::MakeUnique<ShelfBezelEventHandler>(this); | 70     bezel_event_handler_ = base::MakeUnique<ShelfBezelEventHandler>(this); | 
| 71 } | 71 } | 
| 72 | 72 | 
| 73 WmShelf::~WmShelf() {} | 73 Shelf::~Shelf() {} | 
| 74 | 74 | 
| 75 // static | 75 // static | 
| 76 WmShelf* WmShelf::ForWindow(aura::Window* window) { | 76 Shelf* Shelf::ForWindow(aura::Window* window) { | 
| 77   return GetRootWindowController(window->GetRootWindow())->GetShelf(); | 77   return GetRootWindowController(window->GetRootWindow())->GetShelf(); | 
| 78 } | 78 } | 
| 79 | 79 | 
| 80 // static | 80 // static | 
| 81 bool WmShelf::CanChangeShelfAlignment() { | 81 bool Shelf::CanChangeShelfAlignment() { | 
| 82   if (Shell::Get()->session_controller()->IsUserSupervised()) | 82   if (Shell::Get()->session_controller()->IsUserSupervised()) | 
| 83     return false; | 83     return false; | 
| 84 | 84 | 
| 85   const LoginStatus login_status = | 85   const LoginStatus login_status = | 
| 86       Shell::Get()->session_controller()->login_status(); | 86       Shell::Get()->session_controller()->login_status(); | 
| 87 | 87 | 
| 88   switch (login_status) { | 88   switch (login_status) { | 
| 89     case LoginStatus::LOCKED: | 89     case LoginStatus::LOCKED: | 
| 90     // Shelf alignment changes can be requested while being locked, but will | 90     // Shelf alignment changes can be requested while being locked, but will | 
| 91     // be applied upon unlock. | 91     // be applied upon unlock. | 
| 92     case LoginStatus::USER: | 92     case LoginStatus::USER: | 
| 93     case LoginStatus::OWNER: | 93     case LoginStatus::OWNER: | 
| 94       return true; | 94       return true; | 
| 95     case LoginStatus::PUBLIC: | 95     case LoginStatus::PUBLIC: | 
| 96     case LoginStatus::SUPERVISED: | 96     case LoginStatus::SUPERVISED: | 
| 97     case LoginStatus::GUEST: | 97     case LoginStatus::GUEST: | 
| 98     case LoginStatus::KIOSK_APP: | 98     case LoginStatus::KIOSK_APP: | 
| 99     case LoginStatus::ARC_KIOSK_APP: | 99     case LoginStatus::ARC_KIOSK_APP: | 
| 100     case LoginStatus::NOT_LOGGED_IN: | 100     case LoginStatus::NOT_LOGGED_IN: | 
| 101       return false; | 101       return false; | 
| 102   } | 102   } | 
| 103 | 103 | 
| 104   NOTREACHED(); | 104   NOTREACHED(); | 
| 105   return false; | 105   return false; | 
| 106 } | 106 } | 
| 107 | 107 | 
| 108 void WmShelf::CreateShelfWidget(WmWindow* root) { | 108 void Shelf::CreateShelfWidget(WmWindow* root) { | 
| 109   DCHECK(!shelf_widget_); | 109   DCHECK(!shelf_widget_); | 
| 110   WmWindow* shelf_container = | 110   WmWindow* shelf_container = | 
| 111       root->GetChildByShellWindowId(kShellWindowId_ShelfContainer); | 111       root->GetChildByShellWindowId(kShellWindowId_ShelfContainer); | 
| 112   shelf_widget_.reset(new ShelfWidget(shelf_container, this)); | 112   shelf_widget_.reset(new ShelfWidget(shelf_container, this)); | 
| 113 | 113 | 
| 114   DCHECK(!shelf_layout_manager_); | 114   DCHECK(!shelf_layout_manager_); | 
| 115   shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); | 115   shelf_layout_manager_ = shelf_widget_->shelf_layout_manager(); | 
| 116   shelf_layout_manager_->AddObserver(this); | 116   shelf_layout_manager_->AddObserver(this); | 
| 117 | 117 | 
| 118   // Must occur after |shelf_widget_| is constructed because the system tray | 118   // Must occur after |shelf_widget_| is constructed because the system tray | 
| 119   // constructors call back into WmShelf::shelf_widget(). | 119   // constructors call back into Shelf::shelf_widget(). | 
| 120   DCHECK(!shelf_widget_->status_area_widget()); | 120   DCHECK(!shelf_widget_->status_area_widget()); | 
| 121   WmWindow* status_container = | 121   WmWindow* status_container = | 
| 122       root->GetChildByShellWindowId(kShellWindowId_StatusContainer); | 122       root->GetChildByShellWindowId(kShellWindowId_StatusContainer); | 
| 123   shelf_widget_->CreateStatusAreaWidget(status_container); | 123   shelf_widget_->CreateStatusAreaWidget(status_container); | 
| 124 } | 124 } | 
| 125 | 125 | 
| 126 void WmShelf::ShutdownShelfWidget() { | 126 void Shelf::ShutdownShelfWidget() { | 
| 127   if (shelf_widget_) | 127   if (shelf_widget_) | 
| 128     shelf_widget_->Shutdown(); | 128     shelf_widget_->Shutdown(); | 
| 129 } | 129 } | 
| 130 | 130 | 
| 131 void WmShelf::DestroyShelfWidget() { | 131 void Shelf::DestroyShelfWidget() { | 
| 132   shelf_widget_.reset(); | 132   shelf_widget_.reset(); | 
| 133 } | 133 } | 
| 134 | 134 | 
| 135 void WmShelf::NotifyShelfInitialized() { | 135 void Shelf::NotifyShelfInitialized() { | 
| 136   DCHECK(shelf_layout_manager_); | 136   DCHECK(shelf_layout_manager_); | 
| 137   DCHECK(shelf_widget_); | 137   DCHECK(shelf_widget_); | 
| 138   Shell::Get()->shelf_controller()->NotifyShelfInitialized(this); | 138   Shell::Get()->shelf_controller()->NotifyShelfInitialized(this); | 
| 139 } | 139 } | 
| 140 | 140 | 
| 141 WmWindow* WmShelf::GetWindow() { | 141 WmWindow* Shelf::GetWindow() { | 
| 142   return WmWindow::Get(shelf_widget_->GetNativeWindow()); | 142   return WmWindow::Get(shelf_widget_->GetNativeWindow()); | 
| 143 } | 143 } | 
| 144 | 144 | 
| 145 void WmShelf::SetAlignment(ShelfAlignment alignment) { | 145 void Shelf::SetAlignment(ShelfAlignment alignment) { | 
| 146   DCHECK(shelf_layout_manager_); | 146   DCHECK(shelf_layout_manager_); | 
| 147 | 147 | 
| 148   if (alignment_ == alignment) | 148   if (alignment_ == alignment) | 
| 149     return; | 149     return; | 
| 150 | 150 | 
| 151   if (shelf_locking_manager_.is_locked() && | 151   if (shelf_locking_manager_.is_locked() && | 
| 152       alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 152       alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 
| 153     shelf_locking_manager_.set_stored_alignment(alignment); | 153     shelf_locking_manager_.set_stored_alignment(alignment); | 
| 154     return; | 154     return; | 
| 155   } | 155   } | 
| 156 | 156 | 
| 157   alignment_ = alignment; | 157   alignment_ = alignment; | 
| 158   // The ShelfWidget notifies the ShelfView of the alignment change. | 158   // The ShelfWidget notifies the ShelfView of the alignment change. | 
| 159   shelf_widget_->OnShelfAlignmentChanged(); | 159   shelf_widget_->OnShelfAlignmentChanged(); | 
| 160   shelf_layout_manager_->LayoutShelf(); | 160   shelf_layout_manager_->LayoutShelf(); | 
| 161   Shell::Get()->shelf_controller()->NotifyShelfAlignmentChanged(this); | 161   Shell::Get()->shelf_controller()->NotifyShelfAlignmentChanged(this); | 
| 162   Shell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); | 162   Shell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); | 
| 163 } | 163 } | 
| 164 | 164 | 
| 165 bool WmShelf::IsHorizontalAlignment() const { | 165 bool Shelf::IsHorizontalAlignment() const { | 
| 166   switch (alignment_) { | 166   switch (alignment_) { | 
| 167     case SHELF_ALIGNMENT_BOTTOM: | 167     case SHELF_ALIGNMENT_BOTTOM: | 
| 168     case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 168     case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 
| 169       return true; | 169       return true; | 
| 170     case SHELF_ALIGNMENT_LEFT: | 170     case SHELF_ALIGNMENT_LEFT: | 
| 171     case SHELF_ALIGNMENT_RIGHT: | 171     case SHELF_ALIGNMENT_RIGHT: | 
| 172       return false; | 172       return false; | 
| 173   } | 173   } | 
| 174   NOTREACHED(); | 174   NOTREACHED(); | 
| 175   return true; | 175   return true; | 
| 176 } | 176 } | 
| 177 | 177 | 
| 178 int WmShelf::SelectValueForShelfAlignment(int bottom, | 178 int Shelf::SelectValueForShelfAlignment(int bottom, int left, int right) const { | 
| 179                                           int left, |  | 
| 180                                           int right) const { |  | 
| 181   switch (alignment_) { | 179   switch (alignment_) { | 
| 182     case SHELF_ALIGNMENT_BOTTOM: | 180     case SHELF_ALIGNMENT_BOTTOM: | 
| 183     case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 181     case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 
| 184       return bottom; | 182       return bottom; | 
| 185     case SHELF_ALIGNMENT_LEFT: | 183     case SHELF_ALIGNMENT_LEFT: | 
| 186       return left; | 184       return left; | 
| 187     case SHELF_ALIGNMENT_RIGHT: | 185     case SHELF_ALIGNMENT_RIGHT: | 
| 188       return right; | 186       return right; | 
| 189   } | 187   } | 
| 190   NOTREACHED(); | 188   NOTREACHED(); | 
| 191   return bottom; | 189   return bottom; | 
| 192 } | 190 } | 
| 193 | 191 | 
| 194 int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const { | 192 int Shelf::PrimaryAxisValue(int horizontal, int vertical) const { | 
| 195   return IsHorizontalAlignment() ? horizontal : vertical; | 193   return IsHorizontalAlignment() ? horizontal : vertical; | 
| 196 } | 194 } | 
| 197 | 195 | 
| 198 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { | 196 void Shelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { | 
| 199   DCHECK(shelf_layout_manager_); | 197   DCHECK(shelf_layout_manager_); | 
| 200 | 198 | 
| 201   if (auto_hide_behavior_ == auto_hide_behavior) | 199   if (auto_hide_behavior_ == auto_hide_behavior) | 
| 202     return; | 200     return; | 
| 203 | 201 | 
| 204   auto_hide_behavior_ = auto_hide_behavior; | 202   auto_hide_behavior_ = auto_hide_behavior; | 
| 205   Shell::Get()->shelf_controller()->NotifyShelfAutoHideBehaviorChanged(this); | 203   Shell::Get()->shelf_controller()->NotifyShelfAutoHideBehaviorChanged(this); | 
| 206   Shell::Get()->NotifyShelfAutoHideBehaviorChanged( | 204   Shell::Get()->NotifyShelfAutoHideBehaviorChanged( | 
| 207       GetWindow()->GetRootWindow()); | 205       GetWindow()->GetRootWindow()); | 
| 208 } | 206 } | 
| 209 | 207 | 
| 210 ShelfAutoHideState WmShelf::GetAutoHideState() const { | 208 ShelfAutoHideState Shelf::GetAutoHideState() const { | 
| 211   return shelf_layout_manager_->auto_hide_state(); | 209   return shelf_layout_manager_->auto_hide_state(); | 
| 212 } | 210 } | 
| 213 | 211 | 
| 214 void WmShelf::UpdateAutoHideState() { | 212 void Shelf::UpdateAutoHideState() { | 
| 215   shelf_layout_manager_->UpdateAutoHideState(); | 213   shelf_layout_manager_->UpdateAutoHideState(); | 
| 216 } | 214 } | 
| 217 | 215 | 
| 218 ShelfBackgroundType WmShelf::GetBackgroundType() const { | 216 ShelfBackgroundType Shelf::GetBackgroundType() const { | 
| 219   return shelf_widget_->GetBackgroundType(); | 217   return shelf_widget_->GetBackgroundType(); | 
| 220 } | 218 } | 
| 221 | 219 | 
| 222 void WmShelf::UpdateVisibilityState() { | 220 void Shelf::UpdateVisibilityState() { | 
| 223   if (shelf_layout_manager_) | 221   if (shelf_layout_manager_) | 
| 224     shelf_layout_manager_->UpdateVisibilityState(); | 222     shelf_layout_manager_->UpdateVisibilityState(); | 
| 225 } | 223 } | 
| 226 | 224 | 
| 227 ShelfVisibilityState WmShelf::GetVisibilityState() const { | 225 ShelfVisibilityState Shelf::GetVisibilityState() const { | 
| 228   return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() | 226   return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() | 
| 229                                : SHELF_HIDDEN; | 227                                : SHELF_HIDDEN; | 
| 230 } | 228 } | 
| 231 | 229 | 
| 232 gfx::Rect WmShelf::GetIdealBounds() { | 230 gfx::Rect Shelf::GetIdealBounds() { | 
| 233   return shelf_layout_manager_->GetIdealBounds(); | 231   return shelf_layout_manager_->GetIdealBounds(); | 
| 234 } | 232 } | 
| 235 | 233 | 
| 236 gfx::Rect WmShelf::GetUserWorkAreaBounds() const { | 234 gfx::Rect Shelf::GetUserWorkAreaBounds() const { | 
| 237   return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() | 235   return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() | 
| 238                                : gfx::Rect(); | 236                                : gfx::Rect(); | 
| 239 } | 237 } | 
| 240 | 238 | 
| 241 void WmShelf::UpdateIconPositionForPanel(WmWindow* panel) { | 239 void Shelf::UpdateIconPositionForPanel(WmWindow* panel) { | 
| 242   shelf_widget_->UpdateIconPositionForPanel(panel); | 240   shelf_widget_->UpdateIconPositionForPanel(panel); | 
| 243 } | 241 } | 
| 244 | 242 | 
| 245 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | 243 gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | 
| 246   if (!shelf_widget_) | 244   if (!shelf_widget_) | 
| 247     return gfx::Rect(); | 245     return gfx::Rect(); | 
| 248   return shelf_widget_->GetScreenBoundsOfItemIconForWindow(window); | 246   return shelf_widget_->GetScreenBoundsOfItemIconForWindow(window); | 
| 249 } | 247 } | 
| 250 | 248 | 
| 251 // static | 249 // static | 
| 252 void WmShelf::LaunchShelfItem(int item_index) { | 250 void Shelf::LaunchShelfItem(int item_index) { | 
| 253   ShelfModel* shelf_model = Shell::Get()->shelf_model(); | 251   ShelfModel* shelf_model = Shell::Get()->shelf_model(); | 
| 254   const ShelfItems& items = shelf_model->items(); | 252   const ShelfItems& items = shelf_model->items(); | 
| 255   int item_count = shelf_model->item_count(); | 253   int item_count = shelf_model->item_count(); | 
| 256   int indexes_left = item_index >= 0 ? item_index : item_count; | 254   int indexes_left = item_index >= 0 ? item_index : item_count; | 
| 257   int found_index = -1; | 255   int found_index = -1; | 
| 258 | 256 | 
| 259   // Iterating until we have hit the index we are interested in which | 257   // Iterating until we have hit the index we are interested in which | 
| 260   // is true once indexes_left becomes negative. | 258   // is true once indexes_left becomes negative. | 
| 261   for (int i = 0; i < item_count && indexes_left >= 0; i++) { | 259   for (int i = 0; i < item_count && indexes_left >= 0; i++) { | 
| 262     if (items[i].type != TYPE_APP_LIST) { | 260     if (items[i].type != TYPE_APP_LIST) { | 
| 263       found_index = i; | 261       found_index = i; | 
| 264       indexes_left--; | 262       indexes_left--; | 
| 265     } | 263     } | 
| 266   } | 264   } | 
| 267 | 265 | 
| 268   // There are two ways how found_index can be valid: a.) the nth item was | 266   // There are two ways how found_index can be valid: a.) the nth item was | 
| 269   // found (which is true when indexes_left is -1) or b.) the last item was | 267   // found (which is true when indexes_left is -1) or b.) the last item was | 
| 270   // requested (which is true when index was passed in as a negative number). | 268   // requested (which is true when index was passed in as a negative number). | 
| 271   if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { | 269   if (found_index >= 0 && (indexes_left == -1 || item_index < 0)) { | 
| 272     // Then set this one as active (or advance to the next item of its kind). | 270     // Then set this one as active (or advance to the next item of its kind). | 
| 273     ActivateShelfItem(found_index); | 271     ActivateShelfItem(found_index); | 
| 274   } | 272   } | 
| 275 } | 273 } | 
| 276 | 274 | 
| 277 // static | 275 // static | 
| 278 void WmShelf::ActivateShelfItem(int item_index) { | 276 void Shelf::ActivateShelfItem(int item_index) { | 
| 279   ShelfModel* shelf_model = Shell::Get()->shelf_model(); | 277   ShelfModel* shelf_model = Shell::Get()->shelf_model(); | 
| 280   const ShelfItem& item = shelf_model->items()[item_index]; | 278   const ShelfItem& item = shelf_model->items()[item_index]; | 
| 281   ShelfItemDelegate* item_delegate = shelf_model->GetShelfItemDelegate(item.id); | 279   ShelfItemDelegate* item_delegate = shelf_model->GetShelfItemDelegate(item.id); | 
| 282   std::unique_ptr<ui::Event> event = base::MakeUnique<ui::KeyEvent>( | 280   std::unique_ptr<ui::Event> event = base::MakeUnique<ui::KeyEvent>( | 
| 283       ui::ET_KEY_RELEASED, ui::VKEY_UNKNOWN, ui::EF_NONE); | 281       ui::ET_KEY_RELEASED, ui::VKEY_UNKNOWN, ui::EF_NONE); | 
| 284   item_delegate->ItemSelected(std::move(event), display::kInvalidDisplayId, | 282   item_delegate->ItemSelected(std::move(event), display::kInvalidDisplayId, | 
| 285                               LAUNCH_FROM_UNKNOWN, base::Bind(&NoopCallback)); | 283                               LAUNCH_FROM_UNKNOWN, base::Bind(&NoopCallback)); | 
| 286 } | 284 } | 
| 287 | 285 | 
| 288 bool WmShelf::ProcessGestureEvent(const ui::GestureEvent& event) { | 286 bool Shelf::ProcessGestureEvent(const ui::GestureEvent& event) { | 
| 289   // Can be called at login screen. | 287   // Can be called at login screen. | 
| 290   if (!shelf_layout_manager_) | 288   if (!shelf_layout_manager_) | 
| 291     return false; | 289     return false; | 
| 292   return shelf_layout_manager_->ProcessGestureEvent(event); | 290   return shelf_layout_manager_->ProcessGestureEvent(event); | 
| 293 } | 291 } | 
| 294 | 292 | 
| 295 void WmShelf::AddObserver(WmShelfObserver* observer) { | 293 void Shelf::AddObserver(ShelfObserver* observer) { | 
| 296   observers_.AddObserver(observer); | 294   observers_.AddObserver(observer); | 
| 297 } | 295 } | 
| 298 | 296 | 
| 299 void WmShelf::RemoveObserver(WmShelfObserver* observer) { | 297 void Shelf::RemoveObserver(ShelfObserver* observer) { | 
| 300   observers_.RemoveObserver(observer); | 298   observers_.RemoveObserver(observer); | 
| 301 } | 299 } | 
| 302 | 300 | 
| 303 void WmShelf::NotifyShelfIconPositionsChanged() { | 301 void Shelf::NotifyShelfIconPositionsChanged() { | 
| 304   for (auto& observer : observers_) | 302   for (auto& observer : observers_) | 
| 305     observer.OnShelfIconPositionsChanged(); | 303     observer.OnShelfIconPositionsChanged(); | 
| 306 } | 304 } | 
| 307 | 305 | 
| 308 StatusAreaWidget* WmShelf::GetStatusAreaWidget() const { | 306 StatusAreaWidget* Shelf::GetStatusAreaWidget() const { | 
| 309   return shelf_widget_->status_area_widget(); | 307   return shelf_widget_->status_area_widget(); | 
| 310 } | 308 } | 
| 311 | 309 | 
| 312 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { | 310 void Shelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { | 
| 313   shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); | 311   shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); | 
| 314 } | 312 } | 
| 315 | 313 | 
| 316 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { | 314 ShelfLockingManager* Shelf::GetShelfLockingManagerForTesting() { | 
| 317   return &shelf_locking_manager_; | 315   return &shelf_locking_manager_; | 
| 318 } | 316 } | 
| 319 | 317 | 
| 320 ShelfView* WmShelf::GetShelfViewForTesting() { | 318 ShelfView* Shelf::GetShelfViewForTesting() { | 
| 321   return shelf_widget_->shelf_view_for_testing(); | 319   return shelf_widget_->shelf_view_for_testing(); | 
| 322 } | 320 } | 
| 323 | 321 | 
| 324 void WmShelf::WillDeleteShelfLayoutManager() { | 322 void Shelf::WillDeleteShelfLayoutManager() { | 
| 325   if (Shell::GetAshConfig() == Config::MASH) { | 323   if (Shell::GetAshConfig() == Config::MASH) { | 
| 326     // TODO(sky): this should be removed once Shell is used everywhere. | 324     // TODO(sky): this should be removed once Shell is used everywhere. | 
| 327     ShutdownShelfWidget(); | 325     ShutdownShelfWidget(); | 
| 328   } | 326   } | 
| 329 | 327 | 
| 330   // Clear event handlers that might forward events to the destroyed instance. | 328   // Clear event handlers that might forward events to the destroyed instance. | 
| 331   auto_hide_event_handler_.reset(); | 329   auto_hide_event_handler_.reset(); | 
| 332   bezel_event_handler_.reset(); | 330   bezel_event_handler_.reset(); | 
| 333 | 331 | 
| 334   DCHECK(shelf_layout_manager_); | 332   DCHECK(shelf_layout_manager_); | 
| 335   shelf_layout_manager_->RemoveObserver(this); | 333   shelf_layout_manager_->RemoveObserver(this); | 
| 336   shelf_layout_manager_ = nullptr; | 334   shelf_layout_manager_ = nullptr; | 
| 337 } | 335 } | 
| 338 | 336 | 
| 339 void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { | 337 void Shelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { | 
| 340   for (auto& observer : observers_) | 338   for (auto& observer : observers_) | 
| 341     observer.WillChangeVisibilityState(new_state); | 339     observer.WillChangeVisibilityState(new_state); | 
| 342   if (new_state != SHELF_AUTO_HIDE) { | 340   if (new_state != SHELF_AUTO_HIDE) { | 
| 343     auto_hide_event_handler_.reset(); | 341     auto_hide_event_handler_.reset(); | 
| 344   } else if (!auto_hide_event_handler_ && | 342   } else if (!auto_hide_event_handler_ && | 
| 345              Shell::GetAshConfig() != Config::MASH) { | 343              Shell::GetAshConfig() != Config::MASH) { | 
| 346     auto_hide_event_handler_ = | 344     auto_hide_event_handler_ = | 
| 347         base::MakeUnique<AutoHideEventHandler>(shelf_layout_manager()); | 345         base::MakeUnique<AutoHideEventHandler>(shelf_layout_manager()); | 
| 348   } | 346   } | 
| 349 } | 347 } | 
| 350 | 348 | 
| 351 void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | 349 void Shelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { | 
| 352   for (auto& observer : observers_) | 350   for (auto& observer : observers_) | 
| 353     observer.OnAutoHideStateChanged(new_state); | 351     observer.OnAutoHideStateChanged(new_state); | 
| 354 } | 352 } | 
| 355 | 353 | 
| 356 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, | 354 void Shelf::OnBackgroundUpdated(ShelfBackgroundType background_type, | 
| 357                                   AnimationChangeType change_type) { | 355                                 AnimationChangeType change_type) { | 
| 358   if (background_type == GetBackgroundType()) | 356   if (background_type == GetBackgroundType()) | 
| 359     return; | 357     return; | 
| 360   for (auto& observer : observers_) | 358   for (auto& observer : observers_) | 
| 361     observer.OnBackgroundTypeChanged(background_type, change_type); | 359     observer.OnBackgroundTypeChanged(background_type, change_type); | 
| 362 } | 360 } | 
| 363 | 361 | 
| 364 }  // namespace ash | 362 }  // namespace ash | 
| OLD | NEW | 
|---|