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/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/common/notification_observer.h" |
| 13 #include "content/common/notification_registrar.h" |
12 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
13 | 15 |
14 class NativePanel; | 16 class NativePanel; |
15 class PanelManager; | 17 class PanelManager; |
| 18 class RenderViewHost; |
16 | 19 |
17 // A platform independent implementation of BrowserWindow for Panels. This | 20 // A platform independent implementation of BrowserWindow for Panels. This |
18 // class would get the first crack at all the BrowserWindow calls for Panels and | 21 // class would get the first crack at all the BrowserWindow calls for Panels and |
19 // do one or more of the following: | 22 // do one or more of the following: |
20 // - Do nothing. The function is not relevant to Panels. | 23 // - Do nothing. The function is not relevant to Panels. |
21 // - Throw an exceptions. The function shouldn't be called for Panels. | 24 // - Throw an exceptions. The function shouldn't be called for Panels. |
22 // - Do Panel specific platform independent processing and then invoke the | 25 // - Do Panel specific platform independent processing and then invoke the |
23 // function on the platform specific BrowserWindow member. For example, | 26 // function on the platform specific BrowserWindow member. For example, |
24 // Panel size is restricted to certain limits. | 27 // Panel size is restricted to certain limits. |
25 // - Invoke an appropriate PanelManager function to do stuff that might affect | 28 // - Invoke an appropriate PanelManager function to do stuff that might affect |
26 // other Panels. For example deleting a panel would rearrange other panels. | 29 // other Panels. For example deleting a panel would rearrange other panels. |
27 class Panel : public BrowserWindow { | 30 class Panel : public BrowserWindow, public NotificationObserver { |
28 public: | 31 public: |
29 enum ExpansionState { | 32 enum ExpansionState { |
30 // The panel is fully expanded with both title-bar and the client-area. | 33 // The panel is fully expanded with both title-bar and the client-area. |
31 EXPANDED, | 34 EXPANDED, |
32 // The panel is shown with the title-bar only. | 35 // The panel is shown with the title-bar only. |
33 TITLE_ONLY, | 36 TITLE_ONLY, |
34 // The panel is shown with 3-pxiel line. | 37 // The panel is shown with 3-pxiel line. |
35 MINIMIZED | 38 MINIMIZED |
36 }; | 39 }; |
37 | 40 |
38 virtual ~Panel(); | 41 virtual ~Panel(); |
39 | 42 |
40 // Returns the PanelManager associated with this panel. | 43 // Returns the PanelManager associated with this panel. |
41 PanelManager* manager() const; | 44 PanelManager* manager() const; |
42 | 45 |
43 void SetExpansionState(ExpansionState new_expansion_state); | 46 void SetExpansionState(ExpansionState new_expansion_state); |
44 | 47 |
45 bool ShouldBringUpTitlebar(int mouse_x, int mouse_y) const; | 48 bool ShouldBringUpTitlebar(int mouse_x, int mouse_y) const; |
46 | 49 |
47 bool IsDrawingAttention() const; | 50 bool IsDrawingAttention() const; |
48 | 51 |
| 52 // Gets or sets the restored height, which is the full height of the panel |
| 53 // when it is expanded. |
| 54 int GetRestoredHeight() const; |
| 55 void SetRestoredHeight(int height); |
| 56 |
49 // BrowserWindow overrides. | 57 // BrowserWindow overrides. |
50 virtual void Show() OVERRIDE; | 58 virtual void Show() OVERRIDE; |
51 virtual void ShowInactive() OVERRIDE; | 59 virtual void ShowInactive() OVERRIDE; |
52 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; | 60 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; |
53 virtual void Close() OVERRIDE; | 61 virtual void Close() OVERRIDE; |
54 virtual void Activate() OVERRIDE; | 62 virtual void Activate() OVERRIDE; |
55 virtual void Deactivate() OVERRIDE; | 63 virtual void Deactivate() OVERRIDE; |
56 virtual bool IsActive() const OVERRIDE; | 64 virtual bool IsActive() const OVERRIDE; |
57 virtual void FlashFrame() OVERRIDE; | 65 virtual void FlashFrame() OVERRIDE; |
58 virtual gfx::NativeWindow GetNativeHandle() OVERRIDE; | 66 virtual gfx::NativeWindow GetNativeHandle() OVERRIDE; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 virtual void PrepareForInstant() OVERRIDE; | 147 virtual void PrepareForInstant() OVERRIDE; |
140 virtual void ShowInstant(TabContentsWrapper* preview) OVERRIDE; | 148 virtual void ShowInstant(TabContentsWrapper* preview) OVERRIDE; |
141 virtual void HideInstant(bool instant_is_active) OVERRIDE; | 149 virtual void HideInstant(bool instant_is_active) OVERRIDE; |
142 virtual gfx::Rect GetInstantBounds() OVERRIDE; | 150 virtual gfx::Rect GetInstantBounds() OVERRIDE; |
143 virtual WindowOpenDisposition GetDispositionForPopupBounds( | 151 virtual WindowOpenDisposition GetDispositionForPopupBounds( |
144 const gfx::Rect& bounds) OVERRIDE; | 152 const gfx::Rect& bounds) OVERRIDE; |
145 virtual FindBar* CreateFindBar() OVERRIDE; | 153 virtual FindBar* CreateFindBar() OVERRIDE; |
146 #if defined(OS_CHROMEOS) | 154 #if defined(OS_CHROMEOS) |
147 virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) OVERRIDE; | 155 virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) OVERRIDE; |
148 #endif | 156 #endif |
| 157 virtual void UpdatePreferredSize(TabContents* tab_contents, |
| 158 const gfx::Size& pref_size) OVERRIDE; |
| 159 |
| 160 // NotificationObserver overrides. |
| 161 virtual void Observe(int type, |
| 162 const NotificationSource& source, |
| 163 const NotificationDetails& details) OVERRIDE; |
149 | 164 |
150 // Construct a native panel BrowserWindow implementation for the specified | 165 // Construct a native panel BrowserWindow implementation for the specified |
151 // |browser|. | 166 // |browser|. |
152 static NativePanel* CreateNativePanel(Browser* browser, | 167 static NativePanel* CreateNativePanel(Browser* browser, |
153 Panel* panel, | 168 Panel* panel, |
154 const gfx::Rect& bounds); | 169 const gfx::Rect& bounds); |
155 | 170 |
156 // Gets the extension from the browser that a panel is created from. | 171 // Gets the extension from the browser that a panel is created from. |
157 // Returns NULL if it cannot be found. | 172 // Returns NULL if it cannot be found. |
158 static const Extension* GetExtension(Browser* browser); | 173 static const Extension* GetExtension(Browser* browser); |
159 | 174 |
160 #ifdef UNIT_TEST | |
161 NativePanel* native_panel() { return native_panel_; } | 175 NativePanel* native_panel() { return native_panel_; } |
162 #endif | |
163 | |
164 Browser* browser() const; | 176 Browser* browser() const; |
165 ExpansionState expansion_state() const { return expansion_state_; } | 177 ExpansionState expansion_state() const { return expansion_state_; } |
| 178 const gfx::Size& min_size() const { return min_size_; } |
| 179 const gfx::Size& max_size() const { return max_size_; } |
166 | 180 |
167 protected: | 181 protected: |
168 virtual void DestroyBrowser() OVERRIDE; | 182 virtual void DestroyBrowser() OVERRIDE; |
169 | 183 |
170 private: | 184 private: |
171 friend class PanelManager; | 185 friend class PanelManager; |
172 | 186 |
173 // Panel can only be created using PanelManager::CreatePanel(). | 187 // Panel can only be created using PanelManager::CreatePanel(). |
174 Panel(Browser* browser, const gfx::Rect& bounds); | 188 Panel(Browser* browser, const gfx::Rect& bounds); |
175 | 189 |
176 // This is different from BrowserWindow::SetBounds(): | 190 // This is different from BrowserWindow::SetBounds(): |
177 // * SetPanelBounds() is only called by PanelManager to manage its position. | 191 // * SetPanelBounds() is only called by PanelManager to manage its position. |
178 // * SetBounds() is called by the API to try to change the bounds, which is | 192 // * SetBounds() is called by the API to try to change the bounds, which is |
179 // not allowed for Panel. | 193 // not allowed for Panel. |
180 void SetPanelBounds(const gfx::Rect& bounds); | 194 void SetPanelBounds(const gfx::Rect& bounds); |
181 | 195 |
| 196 // Updates the maximum size. |
| 197 void SetMaxSize(const gfx::Size& max_size); |
| 198 |
| 199 // NULL might be returned if the tab has not been added. |
| 200 RenderViewHost* GetRenderViewHost() const; |
| 201 |
| 202 // Requests RenderViewHost not to show the scrollbars till |max_size_| since |
| 203 // the panel can grow to |max_size_|. |
| 204 void RequestRenderViewHostToDisableScrollbars( |
| 205 RenderViewHost* render_view_host); |
| 206 |
| 207 // This is the minimum size that the panel can shrink to. |
| 208 gfx::Size min_size_; |
| 209 |
| 210 // This is the size beyond which the panel is not going to grow to accomodate |
| 211 // the growing content and WebKit would add the scrollbars in such case. |
| 212 gfx::Size max_size_; |
| 213 |
182 // Platform specifc implementation for panels. It'd be one of | 214 // Platform specifc implementation for panels. It'd be one of |
183 // PanelBrowserWindowGtk/PanelBrowserView/PanelBrowserWindowCocoa. | 215 // PanelBrowserWindowGtk/PanelBrowserView/PanelBrowserWindowCocoa. |
184 NativePanel* native_panel_; // Weak, owns us. | 216 NativePanel* native_panel_; // Weak, owns us. |
185 | 217 |
186 ExpansionState expansion_state_; | 218 ExpansionState expansion_state_; |
187 | 219 |
| 220 NotificationRegistrar registrar_; |
| 221 |
188 DISALLOW_COPY_AND_ASSIGN(Panel); | 222 DISALLOW_COPY_AND_ASSIGN(Panel); |
189 }; | 223 }; |
190 | 224 |
191 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ | 225 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ |
OLD | NEW |