OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PANELS_PANEL_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_H_ |
6 #define CHROME_BROWSER_UI_PANELS_PANEL_H_ | 6 #define CHROME_BROWSER_UI_PANELS_PANEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
10 | 10 |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/tabs/tab_strip_model_observer.h" |
13 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
15 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
16 | 17 |
17 class NativePanel; | 18 class NativePanel; |
18 class PanelManager; | 19 class PanelManager; |
19 class RenderViewHost; | 20 class RenderViewHost; |
20 | 21 |
21 // A platform independent implementation of BrowserWindow for Panels. This | 22 // A platform independent implementation of BrowserWindow for Panels. This |
22 // class would get the first crack at all the BrowserWindow calls for Panels and | 23 // class would get the first crack at all the BrowserWindow calls for Panels and |
23 // do one or more of the following: | 24 // do one or more of the following: |
24 // - Do nothing. The function is not relevant to Panels. | 25 // - Do nothing. The function is not relevant to Panels. |
25 // - Throw an exceptions. The function shouldn't be called for Panels. | 26 // - Throw an exceptions. The function shouldn't be called for Panels. |
26 // - Do Panel specific platform independent processing and then invoke the | 27 // - Do Panel specific platform independent processing and then invoke the |
27 // function on the platform specific BrowserWindow member. For example, | 28 // function on the platform specific BrowserWindow member. For example, |
28 // Panel size is restricted to certain limits. | 29 // Panel size is restricted to certain limits. |
29 // - Invoke an appropriate PanelManager function to do stuff that might affect | 30 // - Invoke an appropriate PanelManager function to do stuff that might affect |
30 // other Panels. For example deleting a panel would rearrange other panels. | 31 // other Panels. For example deleting a panel would rearrange other panels. |
31 class Panel : public BrowserWindow, public content::NotificationObserver { | 32 class Panel : public BrowserWindow, |
| 33 public TabStripModelObserver, |
| 34 public content::NotificationObserver { |
32 public: | 35 public: |
33 enum ExpansionState { | 36 enum ExpansionState { |
34 // The panel is fully expanded with both title-bar and the client-area. | 37 // The panel is fully expanded with both title-bar and the client-area. |
35 EXPANDED, | 38 EXPANDED, |
36 // The panel is shown with the title-bar only. | 39 // The panel is shown with the title-bar only. |
37 TITLE_ONLY, | 40 TITLE_ONLY, |
38 // The panel is shown with 3-pixel line. | 41 // The panel is shown with 3-pixel line. |
39 MINIMIZED | 42 MINIMIZED |
40 }; | 43 }; |
41 | 44 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 #if defined(OS_CHROMEOS) | 165 #if defined(OS_CHROMEOS) |
163 virtual void ShowMobileSetup() OVERRIDE; | 166 virtual void ShowMobileSetup() OVERRIDE; |
164 virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) OVERRIDE; | 167 virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) OVERRIDE; |
165 #endif | 168 #endif |
166 virtual void UpdatePreferredSize(TabContents* tab_contents, | 169 virtual void UpdatePreferredSize(TabContents* tab_contents, |
167 const gfx::Size& pref_size) OVERRIDE; | 170 const gfx::Size& pref_size) OVERRIDE; |
168 virtual void ShowAvatarBubble(TabContents* tab_contents, | 171 virtual void ShowAvatarBubble(TabContents* tab_contents, |
169 const gfx::Rect& rect) OVERRIDE; | 172 const gfx::Rect& rect) OVERRIDE; |
170 virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE; | 173 virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE; |
171 | 174 |
| 175 // TabStripModelObserver overrides. |
| 176 virtual void TabInsertedAt(TabContentsWrapper* contents, |
| 177 int index, |
| 178 bool foreground) OVERRIDE; |
| 179 |
172 // content::NotificationObserver overrides. | 180 // content::NotificationObserver overrides. |
173 virtual void Observe(int type, | 181 virtual void Observe(int type, |
174 const content::NotificationSource& source, | 182 const content::NotificationSource& source, |
175 const content::NotificationDetails& details) OVERRIDE; | 183 const content::NotificationDetails& details) OVERRIDE; |
176 | 184 |
177 // Construct a native panel BrowserWindow implementation for the specified | 185 // Construct a native panel BrowserWindow implementation for the specified |
178 // |browser|. | 186 // |browser|. |
179 static NativePanel* CreateNativePanel(Browser* browser, | 187 static NativePanel* CreateNativePanel(Browser* browser, |
180 Panel* panel, | 188 Panel* panel, |
181 const gfx::Rect& bounds); | 189 const gfx::Rect& bounds); |
182 | 190 |
183 // Gets the extension from the browser that a panel is created from. | 191 // Gets the extension from the browser that a panel is created from. |
184 // Returns NULL if it cannot be found. | 192 // Returns NULL if it cannot be found. |
185 static const Extension* GetExtensionFromBrowser(Browser* browser); | 193 static const Extension* GetExtensionFromBrowser(Browser* browser); |
186 | 194 |
187 // Used on platforms where the panel cannot determine its window size | 195 // Used on platforms where the panel cannot determine its window size |
188 // until the window has been created. (e.g. GTK) | 196 // until the window has been created. (e.g. GTK) |
189 void OnWindowSizeAvailable(); | 197 void OnWindowSizeAvailable(); |
190 | 198 |
| 199 // Asynchronous completion of panel close request. |
| 200 void OnNativePanelClosed(); |
| 201 |
191 NativePanel* native_panel() { return native_panel_; } | 202 NativePanel* native_panel() { return native_panel_; } |
192 Browser* browser() const; | 203 Browser* browser() const; |
193 ExpansionState expansion_state() const { return expansion_state_; } | 204 ExpansionState expansion_state() const { return expansion_state_; } |
194 const gfx::Size& min_size() const { return min_size_; } | 205 const gfx::Size& min_size() const { return min_size_; } |
195 const gfx::Size& max_size() const { return max_size_; } | 206 const gfx::Size& max_size() const { return max_size_; } |
196 | 207 |
197 protected: | 208 protected: |
198 virtual void DestroyBrowser() OVERRIDE; | 209 virtual void DestroyBrowser() OVERRIDE; |
199 | 210 |
200 private: | 211 private: |
201 friend class PanelManager; | 212 friend class PanelManager; |
202 friend class PanelBrowserTest; | 213 friend class PanelBrowserTest; |
203 FRIEND_TEST_ALL_PREFIXES(PanelBrowserTest, RestoredBounds); | 214 FRIEND_TEST_ALL_PREFIXES(PanelBrowserTest, RestoredBounds); |
204 | 215 |
205 // Panel can only be created using PanelManager::CreatePanel(). | 216 // Panel can only be created using PanelManager::CreatePanel(). |
206 Panel(Browser* browser, const gfx::Rect& bounds); | 217 Panel(Browser* browser, const gfx::Rect& bounds); |
207 | 218 |
208 // This is different from BrowserWindow::SetBounds(): | 219 // This is different from BrowserWindow::SetBounds(): |
209 // * SetPanelBounds() is only called by PanelManager to manage its position. | 220 // * SetPanelBounds() is only called by PanelManager to manage its position. |
210 // * SetBounds() is called by the API to try to change the bounds, which is | 221 // * SetBounds() is called by the API to try to change the bounds, which is |
211 // not allowed for Panel. | 222 // not allowed for Panel. |
212 void SetPanelBounds(const gfx::Rect& bounds); | 223 void SetPanelBounds(const gfx::Rect& bounds); |
213 | 224 |
214 // Updates the maximum size. | 225 // Updates the maximum size. |
215 void SetMaxSize(const gfx::Size& max_size); | 226 void SetMaxSize(const gfx::Size& max_size); |
216 | 227 |
217 // NULL might be returned if the tab has not been added. | 228 // NULL might be returned if the tab has not been added. |
218 RenderViewHost* GetRenderViewHost() const; | 229 RenderViewHost* GetRenderViewHost() const; |
219 | 230 |
| 231 void EnableAutoResize(RenderViewHost* render_view_host); |
| 232 |
220 // Requests RenderViewHost not to show the scrollbars till |max_size_| since | 233 // Requests RenderViewHost not to show the scrollbars till |max_size_| since |
221 // the panel can grow to |max_size_|. | 234 // the panel can grow to |max_size_|. |
222 void RequestRenderViewHostToDisableScrollbars( | 235 void RequestRenderViewHostToDisableScrollbars( |
223 RenderViewHost* render_view_host); | 236 RenderViewHost* render_view_host); |
224 | 237 |
225 // This is the minimum size that the panel can shrink to. | 238 // This is the minimum size that the panel can shrink to. |
226 gfx::Size min_size_; | 239 gfx::Size min_size_; |
227 | 240 |
228 // This is the size beyond which the panel is not going to grow to accomodate | 241 // This is the size beyond which the panel is not going to grow to accomodate |
229 // the growing content and WebKit would add the scrollbars in such case. | 242 // the growing content and WebKit would add the scrollbars in such case. |
230 gfx::Size max_size_; | 243 gfx::Size max_size_; |
231 | 244 |
232 // Platform specifc implementation for panels. It'd be one of | 245 // Platform specifc implementation for panels. It'd be one of |
233 // PanelBrowserWindowGtk/PanelBrowserView/PanelBrowserWindowCocoa. | 246 // PanelBrowserWindowGtk/PanelBrowserView/PanelBrowserWindowCocoa. |
234 NativePanel* native_panel_; // Weak, owns us. | 247 NativePanel* native_panel_; // Weak, owns us. |
235 | 248 |
236 ExpansionState expansion_state_; | 249 ExpansionState expansion_state_; |
237 | 250 |
238 // Stores the full height of the panel so we can restore it after it's | 251 // Stores the full height of the panel so we can restore it after it's |
239 // been minimized. | 252 // been minimized. |
240 int restored_height_; | 253 int restored_height_; |
241 | 254 |
242 content::NotificationRegistrar registrar_; | 255 content::NotificationRegistrar registrar_; |
243 | 256 |
244 DISALLOW_COPY_AND_ASSIGN(Panel); | 257 DISALLOW_COPY_AND_ASSIGN(Panel); |
245 }; | 258 }; |
246 | 259 |
247 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ | 260 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ |
OLD | NEW |