1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_SHELL_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_SHELL_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
14 #include "ui/aura/window_observer.h"
28 class ChromeLauncherController;
30 // This is a ShellWindowItemLauncherController for shell windows. There is one
31 // instance per app, per launcher id.
32 // For apps with multiple windows, each item controller keeps track of all
33 // windows associated with the app and their activation order.
34 // Instances are owned by ash::LauncherItemDelegateManager.
36 // Tests are in chrome_launcher_controller_browsertest.cc
38 class ShellWindowLauncherItemController : public LauncherItemController,
39 public aura::WindowObserver {
41 ShellWindowLauncherItemController(Type type,
42 const std::string& app_launcher_id,
43 const std::string& app_id,
44 ChromeLauncherController* controller);
46 virtual ~ShellWindowLauncherItemController();
48 void AddShellWindow(apps::ShellWindow* shell_window,
49 ash::LauncherItemStatus status);
51 void RemoveShellWindowForWindow(aura::Window* window);
53 void SetActiveWindow(aura::Window* window);
55 const std::string& app_launcher_id() const { return app_launcher_id_; }
57 // LauncherItemController overrides:
58 virtual bool IsCurrentlyShownInWindow(aura::Window* window) const OVERRIDE;
59 virtual bool IsOpen() const OVERRIDE;
60 virtual bool IsVisible() const OVERRIDE;
61 virtual void Launch(ash::LaunchSource source, int event_flags) OVERRIDE;
62 virtual void Activate(ash::LaunchSource source) OVERRIDE;
63 virtual void Close() OVERRIDE;
64 virtual ChromeLauncherAppMenuItems GetApplicationList(
65 int event_flags) OVERRIDE;
66 virtual void ItemSelected(const ui::Event& eent) OVERRIDE;
67 virtual base::string16 GetTitle() OVERRIDE;
68 virtual ui::MenuModel* CreateContextMenu(
69 aura::Window* root_window) OVERRIDE;
70 virtual ash::LauncherMenuModel* CreateApplicationMenu(
71 int event_flags) OVERRIDE;
72 virtual bool IsDraggable() OVERRIDE;
73 virtual bool ShouldShowTooltip() OVERRIDE;
75 // aura::WindowObserver overrides:
76 virtual void OnWindowPropertyChanged(aura::Window* window,
78 intptr_t old) OVERRIDE;
80 // Get the number of running applications/incarnations of this.
81 size_t shell_window_count() const { return shell_windows_.size(); }
83 // Activates the window at position |index|.
84 void ActivateIndexedApp(size_t index);
87 typedef std::list<apps::ShellWindow*> ShellWindowList;
89 void ShowAndActivateOrMinimize(apps::ShellWindow* shell_window);
91 // Activate the given |window_to_show|, or - if already selected - advance to
92 // the next window of similar type.
93 void ActivateOrAdvanceToNextShellWindow(apps::ShellWindow* window_to_show);
95 // List of associated shell windows
96 ShellWindowList shell_windows_;
98 // Pointer to the most recently active shell window
99 apps::ShellWindow* last_active_shell_window_;
101 // The launcher id associated with this set of windows. There is one
102 // AppLauncherItemController for each |app_launcher_id_|.
103 const std::string app_launcher_id_;
105 // Scoped list of observed windows (for removal on destruction)
106 ScopedObserver<aura::Window, aura::WindowObserver> observed_windows_;
108 DISALLOW_COPY_AND_ASSIGN(ShellWindowLauncherItemController);
111 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_SHELL_WINDOW_LAUNCHER_ITEM_CONTROLLER_H_