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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 virtual void PrepareForInstant() OVERRIDE; | 146 virtual void PrepareForInstant() OVERRIDE; |
139 virtual void ShowInstant(TabContentsWrapper* preview) OVERRIDE; | 147 virtual void ShowInstant(TabContentsWrapper* preview) OVERRIDE; |
140 virtual void HideInstant(bool instant_is_active) OVERRIDE; | 148 virtual void HideInstant(bool instant_is_active) OVERRIDE; |
141 virtual gfx::Rect GetInstantBounds() OVERRIDE; | 149 virtual gfx::Rect GetInstantBounds() OVERRIDE; |
142 virtual WindowOpenDisposition GetDispositionForPopupBounds( | 150 virtual WindowOpenDisposition GetDispositionForPopupBounds( |
143 const gfx::Rect& bounds) OVERRIDE; | 151 const gfx::Rect& bounds) OVERRIDE; |
144 virtual FindBar* CreateFindBar() OVERRIDE; | 152 virtual FindBar* CreateFindBar() OVERRIDE; |
145 #if defined(OS_CHROMEOS) | 153 #if defined(OS_CHROMEOS) |
146 virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) OVERRIDE; | 154 virtual void ShowKeyboardOverlay(gfx::NativeWindow owning_window) OVERRIDE; |
147 #endif | 155 #endif |
| 156 virtual void UpdatePreferredSize(TabContents* tab_contents, |
| 157 const gfx::Size& pref_size) OVERRIDE; |
| 158 |
| 159 // NotificationObserver overrides. |
| 160 virtual void Observe(int type, |
| 161 const NotificationSource& source, |
| 162 const NotificationDetails& details) OVERRIDE; |
148 | 163 |
149 // Construct a native panel BrowserWindow implementation for the specified | 164 // Construct a native panel BrowserWindow implementation for the specified |
150 // |browser|. | 165 // |browser|. |
151 static NativePanel* CreateNativePanel(Browser* browser, | 166 static NativePanel* CreateNativePanel(Browser* browser, |
152 Panel* panel, | 167 Panel* panel, |
153 const gfx::Rect& bounds); | 168 const gfx::Rect& bounds); |
154 | 169 |
155 // Gets the extension from the browser that a panel is created from. | 170 // Gets the extension from the browser that a panel is created from. |
156 // Returns NULL if it cannot be found. | 171 // Returns NULL if it cannot be found. |
157 static const Extension* GetExtension(Browser* browser); | 172 static const Extension* GetExtension(Browser* browser); |
158 | 173 |
159 #ifdef UNIT_TEST | |
160 NativePanel* native_panel() { return native_panel_; } | 174 NativePanel* native_panel() { return native_panel_; } |
161 #endif | |
162 | |
163 Browser* browser() const; | 175 Browser* browser() const; |
164 ExpansionState expansion_state() const { return expansion_state_; } | 176 ExpansionState expansion_state() const { return expansion_state_; } |
| 177 const gfx::Size& min_size() const { return min_size_; } |
| 178 const gfx::Size& max_size() const { return max_size_; } |
165 | 179 |
166 protected: | 180 protected: |
167 virtual void DestroyBrowser() OVERRIDE; | 181 virtual void DestroyBrowser() OVERRIDE; |
168 | 182 |
169 private: | 183 private: |
170 friend class PanelManager; | 184 friend class PanelManager; |
171 | 185 |
172 // Panel can only be created using PanelManager::CreatePanel(). | 186 // Panel can only be created using PanelManager::CreatePanel(). |
173 Panel(Browser* browser, const gfx::Rect& bounds); | 187 Panel(Browser* browser, const gfx::Rect& bounds); |
174 | 188 |
175 // This is different from BrowserWindow::SetBounds(): | 189 // This is different from BrowserWindow::SetBounds(): |
176 // * SetPanelBounds() is only called by PanelManager to manage its position. | 190 // * SetPanelBounds() is only called by PanelManager to manage its position. |
177 // * SetBounds() is called by the API to try to change the bounds, which is | 191 // * SetBounds() is called by the API to try to change the bounds, which is |
178 // not allowed for Panel. | 192 // not allowed for Panel. |
179 void SetPanelBounds(const gfx::Rect& bounds); | 193 void SetPanelBounds(const gfx::Rect& bounds); |
180 | 194 |
| 195 // Updates the maximum size. |
| 196 void SetMaxSize(const gfx::Size& max_size); |
| 197 |
| 198 // NULL might be returned if the tab has not been added. |
| 199 RenderViewHost* GetRenderViewHost() const; |
| 200 |
| 201 // Requests RenderViewHost not to show the scrollbars till |max_size_| since |
| 202 // the panel can grow to |max_size_|. |
| 203 void RequestRenderViewHostToDisableScrollbars( |
| 204 RenderViewHost* render_view_host); |
| 205 |
| 206 // This is the minimum size that the panel can shrink to. |
| 207 gfx::Size min_size_; |
| 208 |
| 209 // This is the size beyond which the panel is not going to grow to accomodate |
| 210 // the growing content and WebKit would add the scrollbars in such case. |
| 211 gfx::Size max_size_; |
| 212 |
181 // Platform specifc implementation for panels. It'd be one of | 213 // Platform specifc implementation for panels. It'd be one of |
182 // PanelBrowserWindowGtk/PanelBrowserView/PanelBrowserWindowCocoa. | 214 // PanelBrowserWindowGtk/PanelBrowserView/PanelBrowserWindowCocoa. |
183 NativePanel* native_panel_; // Weak, owns us. | 215 NativePanel* native_panel_; // Weak, owns us. |
184 | 216 |
185 ExpansionState expansion_state_; | 217 ExpansionState expansion_state_; |
186 | 218 |
| 219 NotificationRegistrar registrar_; |
| 220 |
187 DISALLOW_COPY_AND_ASSIGN(Panel); | 221 DISALLOW_COPY_AND_ASSIGN(Panel); |
188 }; | 222 }; |
189 | 223 |
190 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ | 224 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ |
OLD | NEW |