| 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 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | |
| 9 | |
| 10 #include <list> | 8 #include <list> |
| 11 #include <string> | 9 #include <string> |
| 12 | 10 |
| 13 #include "base/macros.h" | 11 #include "base/macros.h" |
| 14 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
| 15 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 13 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 16 #include "ui/aura/window_observer.h" | 14 #include "ui/aura/window_observer.h" |
| 17 | 15 |
| 18 namespace aura { | 16 namespace aura { |
| 19 class Window; | 17 class Window; |
| 20 } | 18 } |
| 21 | 19 |
| 22 namespace extensions { | 20 namespace ui { |
| 23 class AppWindow; | 21 class BaseWindow; |
| 24 } | 22 } |
| 25 | 23 |
| 26 class ChromeLauncherController; | 24 class ChromeLauncherController; |
| 27 | 25 |
| 28 // This is a LauncherItemController for app windows. There is one instance per | 26 // This is a LauncherItemController for abstract app windows. There is one |
| 29 // app, per launcher id. For apps with multiple windows, each item controller | 27 // instance per app, per launcher id. For apps with multiple windows, each item |
| 30 // keeps track of all windows associated with the app and their activation | 28 // controller keeps track of all windows associated with the app and their |
| 31 // order. Instances are owned by ash::ShelfItemDelegateManager. | 29 // activation order. Instances are owned by ash::ShelfItemDelegateManager. |
| 32 // | 30 // |
| 33 // Tests are in chrome_launcher_controller_browsertest.cc | 31 // Tests are in chrome_launcher_controller_browsertest.cc |
| 34 class AppWindowLauncherItemController : public LauncherItemController, | 32 class AppWindowLauncherItemController : public LauncherItemController, |
| 35 public aura::WindowObserver { | 33 public aura::WindowObserver { |
| 36 public: | 34 public: |
| 37 AppWindowLauncherItemController(Type type, | |
| 38 const std::string& app_shelf_id, | |
| 39 const std::string& app_id, | |
| 40 ChromeLauncherController* controller); | |
| 41 | |
| 42 ~AppWindowLauncherItemController() override; | 35 ~AppWindowLauncherItemController() override; |
| 43 | 36 |
| 44 void AddAppWindow(extensions::AppWindow* app_window, | 37 void AddWindow(ui::BaseWindow* window); |
| 45 ash::ShelfItemStatus status); | |
| 46 | 38 |
| 47 void RemoveAppWindowForWindow(aura::Window* window); | 39 void RemoveWindowForNativeWindow(aura::Window* window); |
| 48 | 40 |
| 49 void SetActiveWindow(aura::Window* window); | 41 void SetActiveWindow(aura::Window* window); |
| 50 | 42 |
| 51 const std::string& app_shelf_id() const { return app_shelf_id_; } | 43 const std::string& app_shelf_id() const { return app_shelf_id_; } |
| 52 | 44 |
| 53 // LauncherItemController overrides: | 45 // LauncherItemController overrides: |
| 54 bool IsOpen() const override; | 46 bool IsOpen() const override; |
| 55 bool IsVisible() const override; | 47 bool IsVisible() const override; |
| 56 void Launch(ash::LaunchSource source, int event_flags) override; | 48 void Launch(ash::LaunchSource source, int event_flags) override; |
| 57 ash::ShelfItemDelegate::PerformedAction Activate( | 49 ash::ShelfItemDelegate::PerformedAction Activate( |
| 58 ash::LaunchSource source) override; | 50 ash::LaunchSource source) override; |
| 59 ChromeLauncherAppMenuItems GetApplicationList(int event_flags) override; | 51 ChromeLauncherAppMenuItems GetApplicationList(int event_flags) override; |
| 60 ash::ShelfItemDelegate::PerformedAction ItemSelected( | 52 ash::ShelfItemDelegate::PerformedAction ItemSelected( |
| 61 const ui::Event& eent) override; | 53 const ui::Event& eent) override; |
| 62 base::string16 GetTitle() override; | 54 base::string16 GetTitle() override; |
| 63 ash::ShelfMenuModel* CreateApplicationMenu(int event_flags) override; | |
| 64 bool IsDraggable() override; | 55 bool IsDraggable() override; |
| 65 bool CanPin() const override; | 56 bool CanPin() const override; |
| 66 bool ShouldShowTooltip() override; | 57 bool ShouldShowTooltip() override; |
| 67 void Close() override; | 58 void Close() override; |
| 68 | 59 |
| 69 // aura::WindowObserver overrides: | 60 // aura::WindowObserver overrides: |
| 70 void OnWindowPropertyChanged(aura::Window* window, | 61 void OnWindowPropertyChanged(aura::Window* window, |
| 71 const void* key, | 62 const void* key, |
| 72 intptr_t old) override; | 63 intptr_t old) override; |
| 73 | 64 |
| 74 // Get the number of running applications/incarnations of this. | 65 // Get the number of running applications/incarnations of this. |
| 75 size_t app_window_count() const { return app_windows_.size(); } | 66 size_t window_count() const { return windows_.size(); } |
| 76 | 67 |
| 77 // Activates the window at position |index|. | 68 // Activates the window at position |index|. |
| 78 void ActivateIndexedApp(size_t index); | 69 void ActivateIndexedApp(size_t index); |
| 79 | 70 |
| 80 private: | 71 protected: |
| 81 typedef std::list<extensions::AppWindow*> AppWindowList; | 72 using WindowList = std::list<ui::BaseWindow*>; |
| 73 |
| 74 AppWindowLauncherItemController(Type type, |
| 75 const std::string& app_shelf_id, |
| 76 const std::string& app_id, |
| 77 ChromeLauncherController* controller); |
| 78 |
| 79 // Called when app window is removed from controller. |
| 80 virtual void OnWindowRemoved(ui::BaseWindow* window) {} |
| 82 | 81 |
| 83 // Returns the action performed. Should be one of kNoAction, | 82 // Returns the action performed. Should be one of kNoAction, |
| 84 // kExistingWindowActivated, or kExistingWindowMinimized. | 83 // kExistingWindowActivated, or kExistingWindowMinimized. |
| 85 ash::ShelfItemDelegate::PerformedAction ShowAndActivateOrMinimize( | 84 ash::ShelfItemDelegate::PerformedAction ShowAndActivateOrMinimize( |
| 86 extensions::AppWindow* app_window); | 85 ui::BaseWindow* window); |
| 87 | 86 |
| 88 // Activate the given |window_to_show|, or - if already selected - advance to | 87 // Activate the given |window_to_show|, or - if already selected - advance to |
| 89 // the next window of similar type. | 88 // the next window of similar type. |
| 90 // Returns the action performed. Should be one of kNoAction, | 89 // Returns the action performed. Should be one of kNoAction, |
| 91 // kExistingWindowActivated, or kExistingWindowMinimized. | 90 // kExistingWindowActivated, or kExistingWindowMinimized. |
| 92 ash::ShelfItemDelegate::PerformedAction ActivateOrAdvanceToNextAppWindow( | 91 ash::ShelfItemDelegate::PerformedAction ActivateOrAdvanceToNextAppWindow( |
| 93 extensions::AppWindow* window_to_show); | 92 ui::BaseWindow* window_to_show); |
| 93 |
| 94 const WindowList& windows() { return windows_; } |
| 95 |
| 96 private: |
| 97 WindowList::iterator GetFromNativeWindow(aura::Window* window); |
| 94 | 98 |
| 95 // List of associated app windows | 99 // List of associated app windows |
| 96 AppWindowList app_windows_; | 100 WindowList windows_; |
| 97 | 101 |
| 98 // Pointer to the most recently active app window | 102 // Pointer to the most recently active app window |
| 99 extensions::AppWindow* last_active_app_window_; | 103 ui::BaseWindow* last_active_window_ = nullptr; |
| 100 | 104 |
| 101 // The launcher id associated with this set of windows. There is one | 105 // The launcher id associated with this set of windows. There is one |
| 102 // AppLauncherItemController for each |app_shelf_id_|. | 106 // AppLauncherItemController for each |app_shelf_id_|. |
| 103 const std::string app_shelf_id_; | 107 const std::string app_shelf_id_; |
| 104 | 108 |
| 105 // Scoped list of observed windows (for removal on destruction) | 109 // Scoped list of observed windows (for removal on destruction) |
| 106 ScopedObserver<aura::Window, aura::WindowObserver> observed_windows_; | 110 ScopedObserver<aura::Window, aura::WindowObserver> observed_windows_; |
| 107 | 111 |
| 108 DISALLOW_COPY_AND_ASSIGN(AppWindowLauncherItemController); | 112 DISALLOW_COPY_AND_ASSIGN(AppWindowLauncherItemController); |
| 109 }; | 113 }; |
| 110 | 114 |
| 111 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_ | 115 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_APP_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_ |
| OLD | NEW |