Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1156)

Side by Side Diff: chrome/browser/ui/panels/panel.h

Issue 10411036: Separate BrowserWindow from Panel class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac unit_tests compile Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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"
10
11 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/ui/base_window.h"
13 #include "chrome/browser/ui/panels/panel_constants.h" 12 #include "chrome/browser/ui/panels/panel_constants.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
15 #include "content/public/browser/notification_observer.h" 13 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 14 #include "content/public/browser/notification_registrar.h"
17 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
18 16
17 class Browser;
18 class BrowserWindow;
19 class NativePanel; 19 class NativePanel;
20 class PanelBrowserWindow;
20 class PanelManager; 21 class PanelManager;
21 class PanelStrip; 22 class PanelStrip;
22 23
23 namespace extensions { 24 namespace content {
24 class Extension; 25 class WebContents;
25 } 26 }
26 27
27 // A platform independent implementation of BrowserWindow for Panels. This 28 // A platform independent implementation of BaseWindow for Panels.
28 // class would get the first crack at all the BrowserWindow calls for Panels and 29 // This class gets the first crack at all the BaseWindow calls for Panels and
29 // do one or more of the following: 30 // does one or more of the following:
30 // - Do nothing. The function is not relevant to Panels. 31 // - Do nothing. The function is not relevant to Panels.
31 // - Throw an exceptions. The function shouldn't be called for Panels.
32 // - Do Panel specific platform independent processing and then invoke the 32 // - Do Panel specific platform independent processing and then invoke the
33 // function on the platform specific BrowserWindow member. For example, 33 // function on the platform specific member. For example, restrict panel
34 // Panel size is restricted to certain limits. 34 // size to certain limits.
35 // - Invoke an appropriate PanelManager function to do stuff that might affect 35 // - Invoke an appropriate PanelManager function to do stuff that might affect
36 // other Panels. For example deleting a panel would rearrange other panels. 36 // other Panels. For example deleting a panel would rearrange other panels.
37 class Panel : public BrowserWindow, 37 class Panel : public BaseWindow,
38 public TabStripModelObserver,
39 public content::NotificationObserver { 38 public content::NotificationObserver {
40 public: 39 public:
41 enum ExpansionState { 40 enum ExpansionState {
42 // The panel is fully expanded with both title-bar and the client-area. 41 // The panel is fully expanded with both title-bar and the client-area.
43 EXPANDED, 42 EXPANDED,
44 // The panel is shown with the title-bar only. 43 // The panel is shown with the title-bar only.
45 TITLE_ONLY, 44 TITLE_ONLY,
46 // The panel is shown with 3-pixel line. 45 // The panel is shown with 3-pixel line.
47 MINIMIZED 46 MINIMIZED
48 }; 47 };
49 48
50 // Controls how the attention should be drawn. 49 // Controls how the attention should be drawn.
51 enum AttentionMode { 50 enum AttentionMode {
52 // Uses the panel attention. The panel's titlebar would be painted 51 // Uses the panel attention. The panel's titlebar would be painted
53 // differently to attract the user's attention. This is the default mode. 52 // differently to attract the user's attention. This is the default mode.
54 USE_PANEL_ATTENTION = 0x01, 53 USE_PANEL_ATTENTION = 0x01,
55 // Uses the system attention. On Windows or Linux (depending on Window 54 // Uses the system attention. On Windows or Linux (depending on Window
56 // Manager), the app icon on taskbar will be flashed. On MacOS, the dock 55 // Manager), the app icon on taskbar will be flashed. On MacOS, the dock
57 // icon will jump once. 56 // icon will jump once.
(...skipping 23 matching lines...) Expand all
81 // top-most windows. 80 // top-most windows.
82 void EnsureFullyVisible(); 81 void EnsureFullyVisible();
83 82
84 int TitleOnlyHeight() const; 83 int TitleOnlyHeight() const;
85 84
86 // Returns true if the panel can be minimized or restored, depending on the 85 // Returns true if the panel can be minimized or restored, depending on the
87 // strip the panel is in. 86 // strip the panel is in.
88 bool CanMinimize() const; 87 bool CanMinimize() const;
89 bool CanRestore() const; 88 bool CanRestore() const;
90 89
91 // BrowserWindow overrides. 90 // BaseWindow overrides.
91 virtual bool IsActive() const OVERRIDE;
92 virtual bool IsMaximized() const OVERRIDE;
93 virtual bool IsMinimized() const OVERRIDE;
94 virtual bool IsFullscreen() const OVERRIDE;
95 virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
96 virtual gfx::Rect GetBounds() const OVERRIDE;
92 virtual void Show() OVERRIDE; 97 virtual void Show() OVERRIDE;
93 virtual void ShowInactive() OVERRIDE; 98 virtual void ShowInactive() OVERRIDE;
94 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
95 virtual void Close() OVERRIDE; 99 virtual void Close() OVERRIDE;
96 virtual void Activate() OVERRIDE; 100 virtual void Activate() OVERRIDE;
97 virtual void Deactivate() OVERRIDE; 101 virtual void Deactivate() OVERRIDE;
98 virtual bool IsActive() const OVERRIDE;
99 virtual void FlashFrame(bool flash) OVERRIDE;
100 virtual bool IsAlwaysOnTop() const OVERRIDE;
101 virtual gfx::NativeWindow GetNativeHandle() OVERRIDE;
102 virtual BrowserWindowTesting* GetBrowserWindowTesting() OVERRIDE;
103 virtual StatusBubble* GetStatusBubble() OVERRIDE;
104 virtual void ToolbarSizeChanged(bool is_animating) OVERRIDE;
105 virtual void UpdateTitleBar() OVERRIDE;
106 virtual void BookmarkBarStateChanged(
107 BookmarkBar::AnimateChangeType change_type) OVERRIDE;
108 virtual void UpdateDevTools() OVERRIDE;
109 virtual void SetDevToolsDockSide(DevToolsDockSide side) OVERRIDE;
110 virtual void UpdateLoadingAnimations(bool should_animate) OVERRIDE;
111 virtual void SetStarredState(bool is_starred) OVERRIDE;
112 virtual gfx::Rect GetRestoredBounds() const OVERRIDE;
113 virtual gfx::Rect GetBounds() const OVERRIDE;
114 virtual bool IsMaximized() const OVERRIDE;
115 virtual bool IsMinimized() const OVERRIDE;
116 virtual void Maximize() OVERRIDE; 102 virtual void Maximize() OVERRIDE;
117 virtual void Minimize() OVERRIDE; 103 virtual void Minimize() OVERRIDE;
118 virtual void Restore() OVERRIDE; 104 virtual void Restore() OVERRIDE;
119 virtual void EnterFullscreen( 105 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
120 const GURL& url, FullscreenExitBubbleType type) OVERRIDE; 106 virtual void SetDraggableRegion(SkRegion* region) OVERRIDE;
121 virtual void ExitFullscreen() OVERRIDE; 107 virtual void FlashFrame(bool flash) OVERRIDE;
122 virtual void UpdateFullscreenExitBubbleContent( 108 virtual bool IsAlwaysOnTop() const OVERRIDE;
123 const GURL& url,
124 FullscreenExitBubbleType bubble_type) OVERRIDE;
125 virtual bool IsFullscreen() const OVERRIDE;
126 virtual bool IsFullscreenBubbleVisible() const OVERRIDE;
127 virtual LocationBar* GetLocationBar() const OVERRIDE;
128 virtual void SetFocusToLocationBar(bool select_all) OVERRIDE;
129 virtual void UpdateReloadStopState(bool is_loading, bool force) OVERRIDE;
130 virtual void UpdateToolbar(TabContentsWrapper* contents,
131 bool should_restore_state) OVERRIDE;
132 virtual void FocusToolbar() OVERRIDE;
133 virtual void FocusAppMenu() OVERRIDE;
134 virtual void FocusBookmarksToolbar() OVERRIDE;
135 virtual void RotatePaneFocus(bool forwards) OVERRIDE;
136 virtual bool IsBookmarkBarVisible() const OVERRIDE;
137 virtual bool IsBookmarkBarAnimating() const OVERRIDE;
138 virtual bool IsTabStripEditable() const OVERRIDE;
139 virtual bool IsToolbarVisible() const OVERRIDE;
140 virtual gfx::Rect GetRootWindowResizerRect() const OVERRIDE;
141 virtual bool IsPanel() const OVERRIDE;
142 virtual void DisableInactiveFrame() OVERRIDE;
143 virtual void ConfirmAddSearchProvider(TemplateURL* template_url,
144 Profile* profile) OVERRIDE;
145 virtual void ToggleBookmarkBar() OVERRIDE;
146 virtual void ShowAboutChromeDialog() OVERRIDE;
147 virtual void ShowUpdateChromeDialog() OVERRIDE;
148 virtual void ShowTaskManager() OVERRIDE;
149 virtual void ShowBackgroundPages() OVERRIDE;
150 virtual void ShowBookmarkBubble(
151 const GURL& url, bool already_bookmarked) OVERRIDE;
152 virtual void ShowChromeToMobileBubble() OVERRIDE;
153 #if defined(ENABLE_ONE_CLICK_SIGNIN)
154 virtual void ShowOneClickSigninBubble(
155 const base::Closure& learn_more_callback,
156 const base::Closure& advanced_callback) OVERRIDE;
157 #endif
158 virtual bool IsDownloadShelfVisible() const OVERRIDE;
159 virtual DownloadShelf* GetDownloadShelf() OVERRIDE;
160 virtual void ConfirmBrowserCloseWithPendingDownloads() OVERRIDE;
161 virtual void UserChangedTheme() OVERRIDE;
162 virtual int GetExtraRenderViewHeight() const OVERRIDE;
163 virtual void WebContentsFocused(content::WebContents* contents) OVERRIDE;
164 virtual void ShowPageInfo(Profile* profile,
165 const GURL& url,
166 const content::SSLStatus& ssl,
167 bool show_history) OVERRIDE;
168 virtual void ShowWebsiteSettings(Profile* profile,
169 TabContentsWrapper* tab_contents_wrapper,
170 const GURL& url,
171 const content::SSLStatus& ssl,
172 bool show_history) OVERRIDE;
173 virtual void ShowAppMenu() OVERRIDE;
174 virtual bool PreHandleKeyboardEvent(
175 const content::NativeWebKeyboardEvent& event,
176 bool* is_keyboard_shortcut) OVERRIDE;
177 virtual void HandleKeyboardEvent(
178 const content::NativeWebKeyboardEvent& event) OVERRIDE;
179 virtual void ShowCreateWebAppShortcutsDialog(
180 TabContentsWrapper* tab_contents) OVERRIDE;
181 virtual void ShowCreateChromeAppShortcutsDialog(
182 Profile* profile, const extensions::Extension* app) OVERRIDE;
183 virtual void Cut() OVERRIDE;
184 virtual void Copy() OVERRIDE;
185 virtual void Paste() OVERRIDE;
186 #if defined(OS_MACOSX)
187 virtual void OpenTabpose() OVERRIDE;
188 virtual void EnterPresentationMode(
189 const GURL& url,
190 FullscreenExitBubbleType bubble_type) OVERRIDE;
191 virtual void ExitPresentationMode() OVERRIDE;
192 virtual bool InPresentationMode() OVERRIDE;
193 #endif
194 virtual void ShowInstant(TabContentsWrapper* preview) OVERRIDE;
195 virtual void HideInstant() OVERRIDE;
196 virtual gfx::Rect GetInstantBounds() OVERRIDE;
197 virtual WindowOpenDisposition GetDispositionForPopupBounds(
198 const gfx::Rect& bounds) OVERRIDE;
199 virtual FindBar* CreateFindBar() OVERRIDE;
200 virtual void ResizeDueToAutoResize(content::WebContents* web_contents,
201 const gfx::Size& new_size) OVERRIDE;
202 virtual void ShowAvatarBubble(content::WebContents* web_contents,
203 const gfx::Rect& rect) OVERRIDE;
204 virtual void ShowAvatarBubbleFromAvatarButton() OVERRIDE;
205
206 // TabStripModelObserver overrides.
207 virtual void TabInsertedAt(TabContentsWrapper* contents,
208 int index,
209 bool foreground) OVERRIDE;
210 109
211 // content::NotificationObserver overrides. 110 // content::NotificationObserver overrides.
212 virtual void Observe(int type, 111 virtual void Observe(int type,
213 const content::NotificationSource& source, 112 const content::NotificationSource& source,
214 const content::NotificationDetails& details) OVERRIDE; 113 const content::NotificationDetails& details) OVERRIDE;
215 114
216 // Construct a native panel BrowserWindow implementation for the specified 115 // Construct a native panel BrowserWindow implementation for the specified
217 // |browser|. 116 // |browser|.
218 static NativePanel* CreateNativePanel(Browser* browser, 117 static NativePanel* CreateNativePanel(Browser* browser,
219 Panel* panel, 118 Panel* panel,
220 const gfx::Rect& bounds); 119 const gfx::Rect& bounds);
221 120
222 // Invoked when the native panel has detected a mouse click on the 121 // Invoked when the native panel has detected a mouse click on the
223 // panel's titlebar, minimize or restore buttons. Behavior of the 122 // panel's titlebar, minimize or restore buttons. Behavior of the
224 // click may be modified as indicated by |modifier|. 123 // click may be modified as indicated by |modifier|.
225 void OnTitlebarClicked(panel::ClickModifier modifier); 124 void OnTitlebarClicked(panel::ClickModifier modifier);
226 void OnMinimizeButtonClicked(panel::ClickModifier modifier); 125 void OnMinimizeButtonClicked(panel::ClickModifier modifier);
227 void OnRestoreButtonClicked(panel::ClickModifier modifier); 126 void OnRestoreButtonClicked(panel::ClickModifier modifier);
228 127
229 // Used on platforms where the panel cannot determine its window size 128 // Used on platforms where the panel cannot determine its window size
230 // until the window has been created. (e.g. GTK) 129 // until the window has been created. (e.g. GTK)
231 void OnWindowSizeAvailable(); 130 void OnWindowSizeAvailable();
232 131
233 // Asynchronous completion of panel close request. 132 // Asynchronous completion of panel close request.
234 void OnNativePanelClosed(); 133 void OnNativePanelClosed();
235 134
236 NativePanel* native_panel() { return native_panel_; } 135 NativePanel* native_panel() { return native_panel_; }
237 Browser* browser() const { return browser_; } 136 Browser* browser() const { return browser_; }
137 BrowserWindow* browser_window() const;
238 138
239 // May be NULL if: 139 // May be NULL if:
240 // * panel is newly created and has not been positioned yet. 140 // * panel is newly created and has not been positioned yet.
241 // * panel is being closed asynchronously. 141 // * panel is being closed asynchronously.
242 // Please use it with caution. 142 // Please use it with caution.
243 PanelStrip* panel_strip() const { return panel_strip_; } 143 PanelStrip* panel_strip() const { return panel_strip_; }
244 144
245 // Sets the current panel strip that contains this panel. 145 // Sets the current panel strip that contains this panel.
246 void set_panel_strip(PanelStrip* new_strip) { panel_strip_ = new_strip; } 146 void set_panel_strip(PanelStrip* new_strip) { panel_strip_ = new_strip; }
247 147
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // Ensures that the panel's size does not exceed the display area by 181 // Ensures that the panel's size does not exceed the display area by
282 // updating maximum and full size of the panel. This is called each time 182 // updating maximum and full size of the panel. This is called each time
283 // when display settings are changed. Note that bounds are not updated here 183 // when display settings are changed. Note that bounds are not updated here
284 // and the call of setting bounds or refreshing layout should be called after 184 // and the call of setting bounds or refreshing layout should be called after
285 // this. 185 // this.
286 void LimitSizeToDisplayArea(const gfx::Rect& display_area); 186 void LimitSizeToDisplayArea(const gfx::Rect& display_area);
287 187
288 // Sets whether the panel will auto resize according to its content. 188 // Sets whether the panel will auto resize according to its content.
289 void SetAutoResizable(bool resizable); 189 void SetAutoResizable(bool resizable);
290 190
191 // Configures the web contents for auto resize, including configurations
192 // on the renderer and detecting renderer changes.
193 void EnableWebContentsAutoResize(content::WebContents* web_contents);
194
195 // Invoked when the preferred window size of the given panel might need to
196 // get changed due to the contents being auto-resized.
197 void OnWindowAutoResized(const gfx::Size& preferred_window_size);
198
291 // Sets minimum and maximum size for the panel. 199 // Sets minimum and maximum size for the panel.
292 void SetSizeRange(const gfx::Size& min_size, const gfx::Size& max_size); 200 void SetSizeRange(const gfx::Size& min_size, const gfx::Size& max_size);
293 201
294 // Updates the maximum size of the panel so that it's never smaller than the 202 // Updates the maximum size of the panel so that it's never smaller than the
295 // panel's desired size. Note that even if the user resizes the panel smaller 203 // panel's desired size. Note that even if the user resizes the panel smaller
296 // later, the increased maximum size will still be in effect. Since it's not 204 // later, the increased maximum size will still be in effect. Since it's not
297 // possible currently to switch the panel back to autosizing from 205 // possible currently to switch the panel back to autosizing from
298 // user-resizable, it should not be a problem. 206 // user-resizable, it should not be a problem.
299 void IncreaseMaxSize(const gfx::Size& desired_panel_size); 207 void IncreaseMaxSize(const gfx::Size& desired_panel_size);
300 208
(...skipping 16 matching lines...) Expand all
317 gfx::Size ClampSize(const gfx::Size& size) const; 225 gfx::Size ClampSize(const gfx::Size& size) const;
318 226
319 // Called when the panel's active state changes. 227 // Called when the panel's active state changes.
320 // |active| is true if panel became active. 228 // |active| is true if panel became active.
321 void OnActiveStateChanged(bool active); 229 void OnActiveStateChanged(bool active);
322 230
323 // Called when the panel starts/ends the user resizing. 231 // Called when the panel starts/ends the user resizing.
324 void OnPanelStartUserResizing(); 232 void OnPanelStartUserResizing();
325 void OnPanelEndUserResizing(); 233 void OnPanelEndUserResizing();
326 234
327 protected:
328 virtual void DestroyBrowser() OVERRIDE;
329
330 private: 235 private:
331 friend class PanelManager; 236 friend class PanelManager;
332 friend class PanelBrowserTest; 237 friend class PanelBrowserTest;
333 FRIEND_TEST_ALL_PREFIXES(PanelBrowserTest, RestoredBounds); 238 FRIEND_TEST_ALL_PREFIXES(PanelBrowserTest, RestoredBounds);
334 239
335 enum MaxSizePolicy { 240 enum MaxSizePolicy {
336 // Default maximum size is proportional to the work area. 241 // Default maximum size is proportional to the work area.
337 DEFAULT_MAX_SIZE, 242 DEFAULT_MAX_SIZE,
338 // Custom maximum size is used when the panel is resized by the user. 243 // Custom maximum size is used when the panel is resized by the user.
339 CUSTOM_MAX_SIZE 244 CUSTOM_MAX_SIZE
340 }; 245 };
341 246
342 // Panel can only be created using PanelManager::CreatePanel(). 247 // Panel can only be created using PanelManager::CreatePanel().
343 // |requested_size| is the desired size for the panel, but actual 248 // |requested_size| is the desired size for the panel, but actual
344 // size may differ after panel layout. 249 // size may differ after panel layout.
345 Panel(Browser* browser, const gfx::Size& requested_size); 250 Panel(Browser* browser, const gfx::Size& requested_size);
346 251
347 // Configures the web contents for auto resize, including configurations
348 // on the renderer and detecting renderer changes.
349 void EnableWebContentsAutoResize(content::WebContents* web_contents);
350
351 // Configures the renderer for auto resize (if auto resize is enabled). 252 // Configures the renderer for auto resize (if auto resize is enabled).
352 void ConfigureAutoResize(content::WebContents* web_contents); 253 void ConfigureAutoResize(content::WebContents* web_contents);
353 254
354 Browser* browser_; // Weak, owned by native panel. 255 Browser* browser_; // Weak, owned by native panel.
355 256
257 // A BrowserWindow for the browser to interact with.
258 scoped_ptr<PanelBrowserWindow> panel_browser_window_;
259
356 // Current collection of panels to which this panel belongs. This determines 260 // Current collection of panels to which this panel belongs. This determines
357 // the panel's screen layout. 261 // the panel's screen layout.
358 PanelStrip* panel_strip_; // Owned by PanelManager. 262 PanelStrip* panel_strip_; // Owned by PanelManager.
359 263
360 bool initialized_; 264 bool initialized_;
361 265
362 // Stores the full size of the panel so we can restore it after it's 266 // Stores the full size of the panel so we can restore it after it's
363 // been minimized or squeezed due to lack of space in the strip. 267 // been minimized or squeezed due to lack of space in the strip.
364 gfx::Size full_size_; 268 gfx::Size full_size_;
365 269
(...skipping 25 matching lines...) Expand all
391 AttentionMode attention_mode_; 295 AttentionMode attention_mode_;
392 296
393 ExpansionState expansion_state_; 297 ExpansionState expansion_state_;
394 298
395 content::NotificationRegistrar registrar_; 299 content::NotificationRegistrar registrar_;
396 300
397 DISALLOW_COPY_AND_ASSIGN(Panel); 301 DISALLOW_COPY_AND_ASSIGN(Panel);
398 }; 302 };
399 303
400 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_ 304 #endif // CHROME_BROWSER_UI_PANELS_PANEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698