launcher_item_controller.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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.
4
5#ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
6#define CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
7
8#include "ash/launcher/launcher_types.h"
9#include "base/basictypes.h"
10#include "base/compiler_specific.h"
11#include "base/string16.h"
12
13class ChromeLauncherController;
14
15namespace aura {
16class Window;
17}
18
19namespace content {
20class WebContents;
21}
22
23// LauncherItemController is used by ChromeLauncherController to track one
24// or more windows associated with a launcher item.
25class LauncherItemController {
26 public:
27  enum Type {
28    TYPE_APP,
29    TYPE_APP_PANEL,
30    TYPE_EXTENSION_PANEL,
31    TYPE_SHORTCUT,
32    TYPE_TABBED
33  };
34
35  LauncherItemController(Type type,
36                         const std::string& app_id,
37                         ChromeLauncherController* launcher_controller);
38  virtual ~LauncherItemController();
39
40  Type type() const { return type_; }
41  ash::LauncherID launcher_id() const { return launcher_id_; }
42  void set_launcher_id(ash::LauncherID id) { launcher_id_ = id; }
43  const std::string& app_id() const { return app_id_; }
44  ChromeLauncherController* launcher_controller() {
45    return launcher_controller_;
46  }
47
48  // Returns the title for this item.
49  virtual string16 GetTitle() = 0;
50
51  // Returns true if this item controls |window|.
52  virtual bool HasWindow(aura::Window* window) const = 0;
53
54  // Returns true if this item is open.
55  virtual bool IsOpen() const = 0;
56
57  // Launches a new instance of the app associated with this item.
58  virtual void Launch(int event_flags) = 0;
59
60  // Shows and activates the most-recently-active window associated with the
61  // item, or launches the item if it is not currently open.
62  virtual void Activate() = 0;
63
64  // Closes all windows associated with this item.
65  virtual void Close() = 0;
66
67  // Indicates that the item at |index| has changed from its previous value.
68  virtual void LauncherItemChanged(int model_index,
69                                   const ash::LauncherItem& old_item) = 0;
70
71  // Called when the item is clicked. The behavior varies by the number of
72  // windows associated with the item:
73  // * One window: toggles the minimize state.
74  // * Multiple windows: cycles the active window.
75  virtual void Clicked() = 0;
76
77  // Called when the controlled item is removed from the launcher.
78  virtual void OnRemoved() = 0;
79
80  // Helper function to get the ash::LauncherItemType for the item type.
81  ash::LauncherItemType GetLauncherItemType() const;
82
83 protected:
84  // Helper function to return the title associated with |app_id_|.
85  // Returns an empty title if no matching extension can be found.
86  string16 GetAppTitle() const;
87
88 private:
89  const Type type_;
90  // App id will be empty if there is no app associated with the window.
91  const std::string app_id_;
92  ash::LauncherID launcher_id_;
93  ChromeLauncherController* launcher_controller_;
94
95  DISALLOW_COPY_AND_ASSIGN(LauncherItemController);
96};
97
98#endif  // CHROME_BROWSER_UI_ASH_LAUNCHER_LAUNCHER_ITEM_CONTROLLER_H_
99