OLD | NEW |
| (Empty) |
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_VIEWS_AURA_LAUNCHER_LAUNCHER_UPDATER_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_AURA_LAUNCHER_LAUNCHER_UPDATER_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <string> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/compiler_specific.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/string16.h" | |
16 #include "chrome/browser/tabs/tab_strip_model_observer.h" | |
17 #include "ash/launcher/launcher_types.h" | |
18 | |
19 class Browser; | |
20 class ChromeLauncherDelegate; | |
21 class TabContentsWrapper; | |
22 | |
23 namespace ash { | |
24 class LauncherModel; | |
25 } | |
26 | |
27 namespace aura { | |
28 class Window; | |
29 } | |
30 | |
31 // LauncherUpdater is responsible for keeping the launcher representation of a | |
32 // window up to date as the tab strip changes. | |
33 class LauncherUpdater : public TabStripModelObserver { | |
34 public: | |
35 enum Type { | |
36 TYPE_APP, | |
37 TYPE_TABBED | |
38 }; | |
39 | |
40 LauncherUpdater(aura::Window* window, | |
41 TabStripModel* tab_model, | |
42 ChromeLauncherDelegate* launcher_delegate, | |
43 Type type, | |
44 const std::string& app_id); | |
45 virtual ~LauncherUpdater(); | |
46 | |
47 // Sets up this LauncherUpdater. | |
48 void Init(); | |
49 | |
50 // Creates and returns a new LauncherUpdater for |browser|. This returns | |
51 // NULL if a LauncherUpdater is not needed for the specified browser. | |
52 static LauncherUpdater* Create(Browser* browser); | |
53 | |
54 aura::Window* window() { return window_; } | |
55 | |
56 TabStripModel* tab_model() { return tab_model_; } | |
57 | |
58 TabContentsWrapper* GetTab(ash::LauncherID id); | |
59 | |
60 // TabStripModel overrides: | |
61 virtual void ActiveTabChanged(TabContentsWrapper* old_contents, | |
62 TabContentsWrapper* new_contents, | |
63 int index, | |
64 bool user_gesture) OVERRIDE; | |
65 virtual void TabChangedAt( | |
66 TabContentsWrapper* tab, | |
67 int index, | |
68 TabStripModelObserver::TabChangeType change_type) OVERRIDE; | |
69 virtual void TabInsertedAt(TabContentsWrapper* contents, | |
70 int index, | |
71 bool foreground) OVERRIDE; | |
72 virtual void TabReplacedAt(TabStripModel* tab_strip_model, | |
73 TabContentsWrapper* old_contents, | |
74 TabContentsWrapper* new_contents, | |
75 int index) OVERRIDE; | |
76 virtual void TabDetachedAt(TabContentsWrapper* contents, int index) OVERRIDE; | |
77 | |
78 private: | |
79 // AppTabDetails is used to identify a launcher item that corresponds to an | |
80 // app tab. | |
81 struct AppTabDetails { | |
82 AppTabDetails(); | |
83 ~AppTabDetails(); | |
84 | |
85 // ID of the launcher item. | |
86 ash::LauncherID id; | |
87 | |
88 // ID of the app (corresponds to Extension::id()). | |
89 std::string app_id; | |
90 }; | |
91 | |
92 // Used to identify what an update corresponds to. | |
93 enum UpdateType { | |
94 UPDATE_TAB_REMOVED, | |
95 UPDATE_TAB_CHANGED, | |
96 UPDATE_TAB_INSERTED, | |
97 }; | |
98 | |
99 typedef std::map<TabContentsWrapper*, AppTabDetails> AppTabMap; | |
100 | |
101 // Updates the launcher from |tab|. | |
102 void UpdateLauncher(TabContentsWrapper* tab); | |
103 | |
104 // Invoked when a tab changes in some way. Updates the Launcher appropriately. | |
105 void UpdateAppTabState(TabContentsWrapper* tab, UpdateType update_type); | |
106 | |
107 // Creates a launcher item for |tab|. | |
108 void AddAppItem(TabContentsWrapper* tab); | |
109 | |
110 void RegisterAppItem(ash::LauncherID id, TabContentsWrapper* tab); | |
111 | |
112 // Creates a tabbed launcher item. | |
113 void CreateTabbedItem(); | |
114 | |
115 // Returns true if this LauncherUpdater created the launcher item with the | |
116 // specified id. Returns true if it did. If the id corresponds to an app tab, | |
117 // |tab| is set to the TabContentsWrapper for the app tab. | |
118 bool ContainsID(ash::LauncherID id, TabContentsWrapper** tab); | |
119 | |
120 ash::LauncherModel* launcher_model(); | |
121 | |
122 // Browser window we're in. | |
123 aura::Window* window_; | |
124 | |
125 TabStripModel* tab_model_; | |
126 | |
127 ChromeLauncherDelegate* launcher_delegate_; | |
128 | |
129 // Whether this corresponds to an app or tabbed browser. | |
130 const Type type_; | |
131 | |
132 const std::string app_id_; | |
133 | |
134 // This is one of three possible values: | |
135 // . If type_ == TYPE_APP, this is the ID of the app item. | |
136 // . If type_ == TYPE_TABBED and all the tabs are app tabs this is -1. | |
137 // . Otherwise this is the id of the TYPE_TABBED item. | |
138 ash::LauncherID item_id_; | |
139 | |
140 // Used for any app tabs. | |
141 AppTabMap app_map_; | |
142 | |
143 DISALLOW_COPY_AND_ASSIGN(LauncherUpdater); | |
144 }; | |
145 | |
146 #endif // CHROME_BROWSER_UI_VIEWS_AURA_LAUNCHER_LAUNCHER_UPDATER_H_ | |
OLD | NEW |