blob: c365a27f0ecc0b79bc9b7b1f30ffb62b93f58bd4 [file] [log] [blame]
[email protected]69b04b92010-11-08 22:12:181// Copyright (c) 2010 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_BROWSER_WINDOW_H_
6#define CHROME_BROWSER_UI_BROWSER_WINDOW_H_
7#pragma once
8
9#include "chrome/browser/tab_contents/navigation_entry.h"
10#include "chrome/common/content_settings_types.h"
11#include "gfx/native_widget_types.h"
12
13class Browser;
14class BrowserWindowTesting;
15class DownloadShelf;
16class FindBar;
17class GURL;
18class HtmlDialogUIDelegate;
19class LocationBar;
20class Profile;
21class StatusBubble;
22class TabContents;
23class TemplateURL;
24class TemplateURLModel;
25#if !defined(OS_MACOSX)
26class ToolbarView;
27#endif
28struct NativeWebKeyboardEvent;
29
30namespace gfx {
31class Rect;
32}
33
34namespace views {
35class Window;
36}
37
38////////////////////////////////////////////////////////////////////////////////
39// BrowserWindow interface
40// An interface implemented by the "view" of the Browser window.
41//
42// NOTE: All getters may return NULL.
43class BrowserWindow {
44 public:
45 // Show the window, or activates it if it's already visible.
46 virtual void Show() = 0;
47
48 // Sets the window's size and position to the specified values.
49 virtual void SetBounds(const gfx::Rect& bounds) = 0;
50
51 // Closes the frame as soon as possible. If the frame is not in a drag
52 // session, it will close immediately; otherwise, it will move offscreen (so
53 // events are still fired) until the drag ends, then close. This assumes
54 // that the Browser is not immediately destroyed, but will be eventually
55 // destroyed by other means (eg, the tab strip going to zero elements).
56 // Bad things happen if the Browser dtor is called directly as a result of
57 // invoking this method.
58 virtual void Close() = 0;
59
60 // Activates (brings to front) the window. Restores the window from minimized
61 // state if necessary.
62 virtual void Activate() = 0;
63
64 // Deactivates the window, making the next window in the Z order the active
65 // window.
66 virtual void Deactivate() = 0;
67
68 // Returns true if the window is currently the active/focused window.
69 virtual bool IsActive() const = 0;
70
71 // Flashes the taskbar item associated with this frame.
72 virtual void FlashFrame() = 0;
73
74 // Return a platform dependent identifier for this frame. On Windows, this
75 // returns an HWND.
76 virtual gfx::NativeWindow GetNativeHandle() = 0;
77
78 // Returns a pointer to the testing interface to the Browser window, or NULL
79 // if there is none.
80 virtual BrowserWindowTesting* GetBrowserWindowTesting() = 0;
81
82 // Return the status bubble associated with the frame
83 virtual StatusBubble* GetStatusBubble() = 0;
84
85 // Inform the receiving frame that an animation has progressed in the
86 // selected tab.
87 // TODO(beng): Remove. Infobars/Boomarks bars should talk directly to
88 // BrowserView.
89 virtual void SelectedTabToolbarSizeChanged(bool is_animating) = 0;
90
91 // Inform the frame that the selected tab favicon or title has changed. Some
92 // frames may need to refresh their title bar.
93 virtual void UpdateTitleBar() = 0;
94
95 // Invoked when the visibility of the bookmark bar.
96 // NOTE: this is NOT sent when the user toggles the visibility of this,
97 // but rather when the user transitions from a page that forces
98 // it to be visibile to one that doesn't have it visible (or
99 // vice-versa).
100 // TODO(sky): see about routing visibility pref changing through here too.
101 virtual void ShelfVisibilityChanged() = 0;
102
103 // Inform the frame that the dev tools window for the selected tab has
104 // changed.
105 virtual void UpdateDevTools() = 0;
106
107 // Update any loading animations running in the window. |should_animate| is
108 // true if there are tabs loading and the animations should continue, false
109 // if there are no active loads and the animations should end.
110 virtual void UpdateLoadingAnimations(bool should_animate) = 0;
111
112 // Sets the starred state for the current tab.
113 virtual void SetStarredState(bool is_starred) = 0;
114
115 // Returns the nonmaximized bounds of the frame (even if the frame is
116 // currently maximized or minimized) in terms of the screen coordinates.
117 virtual gfx::Rect GetRestoredBounds() const = 0;
118
119 // TODO(beng): REMOVE?
120 // Returns true if the frame is maximized (aka zoomed).
121 virtual bool IsMaximized() const = 0;
122
123 // Accessors for fullscreen mode state.
124 virtual void SetFullscreen(bool fullscreen) = 0;
125 virtual bool IsFullscreen() const = 0;
126
127 // Returns true if the fullscreen bubble is visible.
128 virtual bool IsFullscreenBubbleVisible() const = 0;
129
130 // Returns the location bar.
131 virtual LocationBar* GetLocationBar() const = 0;
132
133 // Tries to focus the location bar. Clears the window focus (to avoid
134 // inconsistent state) if this fails.
135 virtual void SetFocusToLocationBar(bool select_all) = 0;
136
137 // Informs the view whether or not a load is in progress for the current tab.
138 // The view can use this notification to update the reload/stop button.
139 virtual void UpdateReloadStopState(bool is_loading, bool force) = 0;
140
141 // Updates the toolbar with the state for the specified |contents|.
142 virtual void UpdateToolbar(TabContents* contents,
143 bool should_restore_state) = 0;
144
145 // Focuses the toolbar (for accessibility).
146 virtual void FocusToolbar() = 0;
147
148 // Focuses the app menu like it was a menu bar.
149 //
150 // Not used on the Mac, which has a "normal" menu bar.
151 virtual void FocusAppMenu() = 0;
152
153 // Focuses the bookmarks toolbar (for accessibility).
154 virtual void FocusBookmarksToolbar() = 0;
155
156 // Focuses the Chrome OS status view (for accessibility).
157 virtual void FocusChromeOSStatus() = 0;
158
159 // Moves keyboard focus to the next pane.
160 virtual void RotatePaneFocus(bool forwards) = 0;
161
162 // Returns whether the bookmark bar is visible or not.
163 virtual bool IsBookmarkBarVisible() const = 0;
164
165 // Returns whether the bookmark bar is animating or not.
166 virtual bool IsBookmarkBarAnimating() const = 0;
167
168 // Returns whether the tool bar is visible or not.
169 virtual bool IsToolbarVisible() const = 0;
170
171 // Returns the rect where the resize corner should be drawn by the render
172 // widget host view (on top of what the renderer returns). We return an empty
173 // rect to identify that there shouldn't be a resize corner (in the cases
174 // where we take care of it ourselves at the browser level).
175 virtual gfx::Rect GetRootWindowResizerRect() const = 0;
176
177 // Tells the frame not to render as inactive until the next activation change.
178 // This is required on Windows when dropdown selects are shown to prevent the
179 // select from deactivating the browser frame. A stub implementation is
180 // provided here since the functionality is Windows-specific.
181 virtual void DisableInactiveFrame() {}
182
183 // Shows a confirmation dialog box for setting the default search engine
184 // described by |template_url|. Takes ownership of |template_url|.
185 virtual void ConfirmSetDefaultSearchProvider(
186 TabContents* tab_contents,
187 TemplateURL* template_url,
188 TemplateURLModel* template_url_model) {
189 // TODO(levin): Implement this for non-Windows platforms and make it pure.
190 }
191
192 // Shows a confirmation dialog box for adding a search engine described by
193 // |template_url|. Takes ownership of |template_url|.
194 virtual void ConfirmAddSearchProvider(const TemplateURL* template_url,
195 Profile* profile) = 0;
196
197 // Shows or hides the bookmark bar depending on its current visibility.
198 virtual void ToggleBookmarkBar() = 0;
199
200 // Shows the About Chrome dialog box.
201 virtual views::Window* ShowAboutChromeDialog() = 0;
202
203 // Shows the Update Recommended dialog box.
204 virtual void ShowUpdateChromeDialog() = 0;
205
206 // Shows the Task manager.
207 virtual void ShowTaskManager() = 0;
208
209 // Shows the Bookmark bubble. |url| is the URL being bookmarked,
210 // |already_bookmarked| is true if the url is already bookmarked.
211 virtual void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) = 0;
212
213 // Whether or not the shelf view is visible.
214 virtual bool IsDownloadShelfVisible() const = 0;
215
216 // Returns the DownloadShelf.
217 virtual DownloadShelf* GetDownloadShelf() = 0;
218
219 // Shows the Report a Bug dialog box.
220 virtual void ShowReportBugDialog() = 0;
221
222 // Shows the Clear Browsing Data dialog box.
223 virtual void ShowClearBrowsingDataDialog() = 0;
224
225 // Shows the Import Bookmarks & Settings dialog box.
226 virtual void ShowImportDialog() = 0;
227
228 // Shows the Search Engines dialog box.
229 virtual void ShowSearchEnginesDialog() = 0;
230
231 // Shows the Password Manager dialog box.
232 virtual void ShowPasswordManager() = 0;
233
234 // Shows the repost form confirmation dialog box.
235 virtual void ShowRepostFormWarningDialog(TabContents* tab_contents) = 0;
236
237 // Shows the Content Settings dialog box.
238 virtual void ShowContentSettingsWindow(ContentSettingsType content_type,
239 Profile* profile) = 0;
240
241 // Shows the collected cookies dialog box.
242 virtual void ShowCollectedCookiesDialog(TabContents* tab_contents) = 0;
243
244 // Shows a dialog to the user that something is wrong with the profile.
245 // |message_id| is the ID for a string in the string table which will be
246 // displayed in the dialog.
247 virtual void ShowProfileErrorDialog(int message_id) = 0;
248
249 // Show the bubble that indicates to the user that a theme is being installed.
250 virtual void ShowThemeInstallBubble() = 0;
251
252 // Shows the confirmation dialog box warning that the browser is closing with
253 // in-progress downloads.
254 // This method should call Browser::InProgressDownloadResponse once the user
255 // has confirmed.
256 virtual void ConfirmBrowserCloseWithPendingDownloads() = 0;
257
258 // Shows a dialog box with HTML content, e.g. for Gears. |parent_window| is
259 // the window the dialog should be opened modal to and is a native window
260 // handle.
261 virtual void ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
262 gfx::NativeWindow parent_window) = 0;
263
264 // Asks the window to continue a drag operation begun in a different browser
265 // window. |tab_bounds| are the bounds of the Tab view that was dragged from
266 // the source window, in screen coordinates. The corresponding Tab view in
267 // this new window will be positioned at these bounds for a seamless
268 // appearance.
269 virtual void ContinueDraggingDetachedTab(const gfx::Rect& tab_bounds) {}
270
271 // BrowserThemeProvider calls this when a user has changed his or her theme,
272 // indicating that it's time to redraw everything.
273 virtual void UserChangedTheme() = 0;
274
275 // Get extra vertical height that the render view should add to its requests
276 // to webkit. This can help prevent sending extraneous layout/repaint requests
277 // when the delegate is in the process of resizing the tab contents view (e.g.
278 // during infobar animations).
279 virtual int GetExtraRenderViewHeight() const = 0;
280
281 // Notification that |tab_contents| got the focus through user action (click
282 // on the page).
283 virtual void TabContentsFocused(TabContents* tab_contents) = 0;
284
285 // Shows the page info using the specified information.
286 // |url| is the url of the page/frame the info applies to, |ssl| is the SSL
287 // information for that page/frame. If |show_history| is true, a section
288 // showing how many times that URL has been visited is added to the page info.
289 virtual void ShowPageInfo(Profile* profile,
290 const GURL& url,
291 const NavigationEntry::SSLStatus& ssl,
292 bool show_history) = 0;
293
294 // Shows the app menu (for accessibility).
295 virtual void ShowAppMenu() = 0;
296
297 // Allows the BrowserWindow object to handle the specified keyboard event
298 // before sending it to the renderer.
299 // Returns true if the |event| was handled. Otherwise, if the |event| would
300 // be handled in HandleKeyboardEvent() method as a normal keyboard shortcut,
301 // |*is_keyboard_shortcut| should be set to true.
302 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
303 bool* is_keyboard_shortcut) = 0;
304
305 // Allows the BrowserWindow object to handle the specified keyboard event,
306 // if the renderer did not process it.
307 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) = 0;
308
309 // Shows the create web app shortcut dialog box.
310 virtual void ShowCreateShortcutsDialog(TabContents* tab_contents) = 0;
311
312 // Clipboard commands applied to the whole browser window.
313 virtual void Cut() = 0;
314 virtual void Copy() = 0;
315 virtual void Paste() = 0;
316
317 // Switches between available tabstrip display modes.
318 virtual void ToggleTabStripMode() = 0;
319
320#if defined(OS_MACOSX)
321 // Opens the tabpose view.
322 virtual void OpenTabpose() = 0;
323#endif
324
325 // Invoked when instant's tab contents should be shown.
326 virtual void ShowInstant(TabContents* preview_contents) = 0;
327
328 // Invoked when the instant's tab contents should be hidden.
329 virtual void HideInstant() = 0;
330
331 // Returns the desired bounds for instant in screen coordinates. Note that if
332 // instant isn't currently visible this returns the bounds instant would be
333 // placed at.
334 virtual gfx::Rect GetInstantBounds() = 0;
335
336 // Construct a BrowserWindow implementation for the specified |browser|.
337 static BrowserWindow* CreateBrowserWindow(Browser* browser);
338
339 // Construct a FindBar implementation for the specified |browser|.
340 static FindBar* CreateFindBar(Browser* browser_window);
341
342 protected:
343 friend class BrowserList;
344 friend class BrowserView;
345 virtual void DestroyBrowser() = 0;
346
347 virtual ~BrowserWindow() {}
348};
349
350#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
351class BookmarkBarView;
352class LocationBarView;
353
354namespace views {
355class View;
356}
357#endif // defined(OS_WIN)
358
359// A BrowserWindow utility interface used for accessing elements of the browser
360// UI used only by UI test automation.
361class BrowserWindowTesting {
362 public:
363#if defined(OS_WIN) || defined(TOOLKIT_VIEWS)
364 // Returns the BookmarkBarView.
365 virtual BookmarkBarView* GetBookmarkBarView() const = 0;
366
367 // Returns the LocationBarView.
368 virtual LocationBarView* GetLocationBarView() const = 0;
369
370 // Returns the TabContentsContainer.
371 virtual views::View* GetTabContentsContainerView() const = 0;
372
373 // Returns the TabContentsContainer.
374 virtual views::View* GetSidebarContainerView() const = 0;
375
376 // Returns the ToolbarView.
377 virtual ToolbarView* GetToolbarView() const = 0;
378#endif
379
380 protected:
381 virtual ~BrowserWindowTesting() {}
382};
383
384#endif // CHROME_BROWSER_UI_BROWSER_WINDOW_H_