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_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "ash/launcher/launcher_types.h" | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/gtest_prod_util.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/string16.h" | |
16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | |
17 #include "chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h" | |
18 #include "ui/aura/window_observer.h" | |
19 | |
20 class Browser; | |
21 class ChromeLauncherController; | |
22 class LauncherFaviconLoader; | |
23 class TabContents; | |
24 | |
25 namespace ash { | |
26 class LauncherModel; | |
27 } | |
28 | |
29 namespace aura { | |
30 class Window; | |
31 } | |
32 | |
33 // BrowserLauncherItemController is responsible for keeping the launcher | |
34 // representation of a window up to date as the active tab changes. | |
35 class BrowserLauncherItemController : public TabStripModelObserver, | |
36 public LauncherFaviconLoader::Delegate, | |
37 public aura::WindowObserver { | |
38 public: | |
39 // This API is to be used as part of testing only. | |
40 class TestApi { | |
41 public: | |
42 explicit TestApi(BrowserLauncherItemController* controller) | |
43 : controller_(controller) {} | |
44 ~TestApi() {} | |
45 | |
46 // Returns the launcher id for the browser window. | |
47 ash::LauncherID item_id() const { return controller_->item_id_; } | |
48 | |
49 private: | |
50 BrowserLauncherItemController* controller_; | |
51 }; | |
52 | |
53 enum Type { | |
54 TYPE_APP_PANEL, | |
55 TYPE_EXTENSION_PANEL, | |
56 TYPE_TABBED | |
57 }; | |
58 | |
59 BrowserLauncherItemController(aura::Window* window, | |
60 TabStripModel* tab_model, | |
61 ChromeLauncherController* launcher_controller, | |
62 Type type, | |
63 const std::string& app_id); | |
64 virtual ~BrowserLauncherItemController(); | |
65 | |
66 // Sets up this BrowserLauncherItemController. | |
67 void Init(); | |
68 | |
69 // Creates and returns a new BrowserLauncherItemController for |browser|. This | |
70 // returns NULL if a BrowserLauncherItemController is not needed for the | |
71 // specified browser. | |
72 static BrowserLauncherItemController* Create(Browser* browser); | |
73 | |
74 aura::Window* window() { return window_; } | |
75 | |
76 TabStripModel* tab_model() { return tab_model_; } | |
77 | |
78 Type type() const { return type_; } | |
79 | |
80 LauncherFaviconLoader* favicon_loader() const { | |
81 return favicon_loader_.get(); | |
82 } | |
83 | |
84 // Call to indicate that the window the tabcontents are in has changed its | |
85 // activation state. | |
86 void BrowserActivationStateChanged(); | |
87 | |
88 // TabStripModel overrides: | |
89 virtual void ActiveTabChanged(TabContents* old_contents, | |
90 TabContents* new_contents, | |
91 int index, | |
92 bool user_gesture) OVERRIDE; | |
93 virtual void TabInsertedAt(TabContents* contents, | |
94 int index, | |
95 bool foreground) OVERRIDE; | |
96 virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE; | |
97 virtual void TabChangedAt( | |
98 TabContents* tab, | |
99 int index, | |
100 TabStripModelObserver::TabChangeType change_type) OVERRIDE; | |
101 virtual void TabReplacedAt(TabStripModel* tab_strip_model, | |
102 TabContents* old_contents, | |
103 TabContents* new_contents, | |
104 int index) OVERRIDE; | |
105 | |
106 // LauncherFaviconLoader::Delegate overrides: | |
107 virtual void FaviconUpdated() OVERRIDE; | |
108 | |
109 // aura::WindowObserver overrides: | |
110 virtual void OnWindowPropertyChanged(aura::Window* window, | |
111 const void* key, | |
112 intptr_t old) OVERRIDE; | |
113 | |
114 private: | |
115 FRIEND_TEST_ALL_PREFIXES(BrowserLauncherItemControllerTest, PanelItem); | |
116 | |
117 // Used to identify what an update corresponds to. | |
118 enum UpdateType { | |
119 UPDATE_TAB_REMOVED, | |
120 UPDATE_TAB_CHANGED, | |
121 UPDATE_TAB_INSERTED, | |
122 }; | |
123 | |
124 // Updates the launcher item status base on the activation and attention | |
125 // state of the window. | |
126 void UpdateItemStatus(); | |
127 | |
128 // Updates the launcher from |tab|. | |
129 void UpdateLauncher(TabContents* tab); | |
130 | |
131 void UpdateAppState(TabContents* tab); | |
132 | |
133 ash::LauncherModel* launcher_model(); | |
134 | |
135 // Browser window we're in. | |
136 aura::Window* window_; | |
137 | |
138 TabStripModel* tab_model_; | |
139 | |
140 ChromeLauncherController* launcher_controller_; | |
141 | |
142 // Whether this corresponds to an app or tabbed browser. | |
143 const Type type_; | |
144 | |
145 const std::string app_id_; | |
146 | |
147 // Whether this is associated with an incognito profile. | |
148 const bool is_incognito_; | |
149 | |
150 // ID of the item. | |
151 ash::LauncherID item_id_; | |
152 | |
153 // Loads launcher sized favicons for panels. | |
154 scoped_ptr<LauncherFaviconLoader> favicon_loader_; | |
155 | |
156 DISALLOW_COPY_AND_ASSIGN(BrowserLauncherItemController); | |
157 }; | |
158 | |
159 #endif // CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_BROWSER_LAUNCHER_ITEM_CONTROLLER
_H_ | |
OLD | NEW |