blob: 007e07088993979441f29225b3ee4686e98580a9 [file] [log] [blame]
[email protected]35d06152011-01-10 22:19:421// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]7d791652010-12-01 16:34:492// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
6
[email protected]a932d9e2011-09-29 01:14:347#include "base/bind.h"
[email protected]7d791652010-12-01 16:34:498#include "base/command_line.h"
9#include "base/logging.h"
10#include "base/message_loop.h"
11#include "base/sys_string_conversions.h"
12#include "chrome/app/chrome_command_ids.h"
13#include "chrome/browser/bookmarks/bookmark_utils.h"
14#include "chrome/browser/download/download_shelf.h"
[email protected]7d791652010-12-01 16:34:4915#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3316#include "chrome/browser/profiles/profile.h"
[email protected]7d791652010-12-01 16:34:4917#include "chrome/browser/sidebar/sidebar_container.h"
18#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]7d791652010-12-01 16:34:4919#include "chrome/browser/ui/browser.h"
20#include "chrome/browser/ui/browser_list.h"
[email protected]7d2d08152011-10-25 22:58:4721#import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h"
[email protected]2f733a02011-10-06 15:17:3422#import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h"
[email protected]464f0012011-07-07 02:12:5123#import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h"
[email protected]7d791652010-12-01 16:34:4924#import "chrome/browser/ui/cocoa/browser_window_controller.h"
[email protected]3a1381d2011-08-26 18:12:1325#import "chrome/browser/ui/cocoa/browser_window_utils.h"
[email protected]7d791652010-12-01 16:34:4926#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
[email protected]fa8102292011-01-20 16:21:2327#import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h"
[email protected]7d791652010-12-01 16:34:4928#import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
[email protected]632983f2011-08-08 22:51:2429#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
[email protected]7d791652010-12-01 16:34:4930#import "chrome/browser/ui/cocoa/html_dialog_window_controller.h"
[email protected]51152d6d2011-11-07 01:55:1231#import "chrome/browser/ui/cocoa/info_bubble_view.h"
[email protected]7d791652010-12-01 16:34:4932#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
[email protected]a7d83ca2011-03-06 14:41:0733#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
[email protected]7d791652010-12-01 16:34:4934#include "chrome/browser/ui/cocoa/restart_browser.h"
35#include "chrome/browser/ui/cocoa/status_bubble_mac.h"
36#include "chrome/browser/ui/cocoa/task_manager_mac.h"
[email protected]8450c4f2011-01-19 22:16:2237#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
[email protected]7e2514c2011-11-28 20:04:4538#include "chrome/browser/ui/page_info_bubble.h"
[email protected]6a3ec2312010-12-02 19:30:1939#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]0bf4dc622011-12-19 06:59:4440#include "chrome/browser/ui/webui/chrome_web_ui.h"
[email protected]7b937362011-10-05 08:28:0741#include "chrome/browser/ui/webui/task_manager_dialog.h"
[email protected]432115822011-07-10 15:52:2742#include "chrome/common/chrome_notification_types.h"
[email protected]7d791652010-12-01 16:34:4943#include "chrome/common/pref_names.h"
[email protected]21f11682011-03-02 16:45:4244#include "content/browser/tab_contents/tab_contents.h"
[email protected]ad50def52011-10-19 23:17:0745#include "content/public/browser/notification_source.h"
[email protected]8bc38d22011-10-14 20:39:2046#include "content/public/browser/native_web_keyboard_event.h"
[email protected]6c2381d2011-10-19 02:52:5347#include "content/public/browser/notification_details.h"
[email protected]7d791652010-12-01 16:34:4948#include "grit/chromium_strings.h"
49#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1750#include "ui/base/l10n/l10n_util_mac.h"
[email protected]08397d52011-02-05 01:53:3851#include "ui/gfx/rect.h"
[email protected]7d791652010-12-01 16:34:4952
[email protected]d583e3f22011-12-27 21:38:1753using content::SSLStatus;
[email protected]2a6bc3e2011-12-28 23:51:3354using content::WebContents;
[email protected]d583e3f22011-12-27 21:38:1755
[email protected]400eaf82011-08-22 15:47:3956// Replicate specific 10.7 SDK declarations for building with prior SDKs.
57#if !defined(MAC_OS_X_VERSION_10_7) || \
58 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
59
60enum {
61 NSWindowAnimationBehaviorDefault = 0,
62 NSWindowAnimationBehaviorNone = 2,
63 NSWindowAnimationBehaviorDocumentWindow = 3,
64 NSWindowAnimationBehaviorUtilityWindow = 4,
65 NSWindowAnimationBehaviorAlertPanel = 5
66};
67typedef NSInteger NSWindowAnimationBehavior;
68
69@interface NSWindow (LionSDKDeclarations)
70- (NSWindowAnimationBehavior)animationBehavior;
71- (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
72@end
73
74#endif // MAC_OS_X_VERSION_10_7
75
[email protected]7d791652010-12-01 16:34:4976BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
[email protected]400eaf82011-08-22 15:47:3977 BrowserWindowController* controller)
[email protected]7d791652010-12-01 16:34:4978 : browser_(browser),
79 controller_(controller),
80 confirm_close_factory_(browser) {
[email protected]6c2381d2011-10-19 02:52:5381 registrar_.Add(
82 this, chrome::NOTIFICATION_SIDEBAR_CHANGED,
83 content::Source<SidebarManager>(SidebarManager::GetInstance()));
[email protected]cfecf9432011-09-27 17:10:0884
[email protected]3710d0002011-10-11 00:35:0085 pref_change_registrar_.Init(browser_->profile()->GetPrefs());
86 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
87
[email protected]cfecf9432011-09-27 17:10:0888 initial_show_state_ = browser_->GetSavedWindowShowState();
[email protected]7d791652010-12-01 16:34:4989}
90
91BrowserWindowCocoa::~BrowserWindowCocoa() {
92}
93
94void BrowserWindowCocoa::Show() {
95 // The Browser associated with this browser window must become the active
96 // browser at the time |Show()| is called. This is the natural behaviour under
97 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:|
98 // until we return to the runloop. Therefore any calls to
99 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return
100 // the previous browser instead if we don't explicitly set it here.
101 BrowserList::SetLastActive(browser_);
102
[email protected]8bc061f2011-08-31 22:46:23103 bool is_session_restore = browser_->is_session_restore();
[email protected]b5cc93c2011-09-02 02:33:42104 NSWindowAnimationBehavior saved_animation_behavior =
105 NSWindowAnimationBehaviorDefault;
[email protected]8bc061f2011-08-31 22:46:23106 bool did_save_animation_behavior = false;
107 // Turn off swishing when restoring windows.
108 if (is_session_restore &&
109 [window() respondsToSelector:@selector(animationBehavior)] &&
110 [window() respondsToSelector:@selector(setAnimationBehavior:)]) {
111 did_save_animation_behavior = true;
112 saved_animation_behavior = [window() animationBehavior];
113 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone];
114 }
[email protected]400eaf82011-08-22 15:47:39115
[email protected]8bc061f2011-08-31 22:46:23116 [window() makeKeyAndOrderFront:controller_];
[email protected]400eaf82011-08-22 15:47:39117
[email protected]8bc061f2011-08-31 22:46:23118 // When creating windows from nibs it is necessary to |makeKeyAndOrderFront:|
119 // prior to |orderOut:| then |miniaturize:| when restoring windows in the
120 // minimized state.
[email protected]cfecf9432011-09-27 17:10:08121 if (initial_show_state_ == ui::SHOW_STATE_MINIMIZED) {
[email protected]400eaf82011-08-22 15:47:39122 [window() orderOut:controller_];
123 [window() miniaturize:controller_];
[email protected]400eaf82011-08-22 15:47:39124 }
[email protected]cfecf9432011-09-27 17:10:08125 initial_show_state_ = ui::SHOW_STATE_DEFAULT;
[email protected]8bc061f2011-08-31 22:46:23126
127 // Restore window animation behavior.
128 if (did_save_animation_behavior)
129 [window() setAnimationBehavior:saved_animation_behavior];
[email protected]2f516c792011-09-19 22:22:09130
131 browser_->OnWindowDidShow();
[email protected]7d791652010-12-01 16:34:49132}
133
[email protected]d4db6c702011-03-28 21:49:14134void BrowserWindowCocoa::ShowInactive() {
[email protected]400eaf82011-08-22 15:47:39135 [window() orderFront:controller_];
[email protected]d4db6c702011-03-28 21:49:14136}
137
[email protected]7d791652010-12-01 16:34:49138void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) {
[email protected]ccb5895f2011-06-09 21:16:14139 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds];
140
[email protected]55c87fa2011-10-15 07:28:28141 ExitFullscreen();
[email protected]ccb5895f2011-06-09 21:16:14142 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0,
143 real_bounds.width(),
144 real_bounds.height());
[email protected]7d791652010-12-01 16:34:49145 // Flip coordinates based on the primary screen.
146 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
147 cocoa_bounds.origin.y =
[email protected]ccb5895f2011-06-09 21:16:14148 [screen frame].size.height - real_bounds.height() - real_bounds.y();
[email protected]7d791652010-12-01 16:34:49149
150 [window() setFrame:cocoa_bounds display:YES];
151}
152
153// Callers assume that this doesn't immediately delete the Browser object.
154// The controller implementing the window delegate methods called from
155// |-performClose:| must take precautions to ensure that.
156void BrowserWindowCocoa::Close() {
157 // If there is an overlay window, we contain a tab being dragged between
158 // windows. Don't hide the window as it makes the UI extra confused. We can
159 // still close the window, as that will happen when the drag completes.
160 if ([controller_ overlayWindow]) {
161 [controller_ deferPerformClose];
162 } else {
163 // Make sure we hide the window immediately. Even though performClose:
164 // calls orderOut: eventually, it leaves the window on-screen long enough
165 // that we start to see tabs shutting down. http://crbug.com/23959
166 // TODO(viettrungluu): This is kind of bad, since |-performClose:| calls
167 // |-windowShouldClose:| (on its delegate, which is probably the
168 // controller) which may return |NO| causing the window to not be closed,
169 // thereby leaving a hidden window. In fact, our window-closing procedure
170 // involves a (indirect) recursion on |-performClose:|, which is also bad.
171 [window() orderOut:controller_];
172 [window() performClose:controller_];
173 }
174}
175
176void BrowserWindowCocoa::Activate() {
177 [controller_ activate];
178}
179
180void BrowserWindowCocoa::Deactivate() {
181 // TODO(jcivelli): http://crbug.com/51364 Implement me.
182 NOTIMPLEMENTED();
183}
184
185void BrowserWindowCocoa::FlashFrame() {
186 [NSApp requestUserAttention:NSInformationalRequest];
187}
188
189bool BrowserWindowCocoa::IsActive() const {
190 return [window() isKeyWindow];
191}
192
193gfx::NativeWindow BrowserWindowCocoa::GetNativeHandle() {
194 return window();
195}
196
197BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() {
198 return NULL;
199}
200
201StatusBubble* BrowserWindowCocoa::GetStatusBubble() {
202 return [controller_ statusBubble];
203}
204
[email protected]c9bd2e82011-04-15 23:28:19205void BrowserWindowCocoa::ToolbarSizeChanged(bool is_animating) {
[email protected]7d791652010-12-01 16:34:49206 // According to beng, this is an ugly method that comes from the days when the
207 // download shelf was a ChromeView attached to the TabContents, and as its
208 // size changed via animation it notified through TCD/etc to the browser view
209 // to relayout for each tick of the animation. We don't need anything of the
210 // sort on Mac.
211}
212
213void BrowserWindowCocoa::UpdateTitleBar() {
214 NSString* newTitle =
215 base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab());
216
[email protected]d78e615e2011-09-06 21:46:03217 pending_window_title_.reset(
218 [BrowserWindowUtils scheduleReplaceOldTitle:pending_window_title_.get()
219 withNewTitle:newTitle
220 forWindow:window()]);
[email protected]7d791652010-12-01 16:34:49221}
222
[email protected]09b29342011-06-24 19:18:48223void BrowserWindowCocoa::BookmarkBarStateChanged(
224 BookmarkBar::AnimateChangeType change_type) {
225 // TODO: route changes to state through this.
[email protected]7d791652010-12-01 16:34:49226}
227
228void BrowserWindowCocoa::UpdateDevTools() {
229 [controller_ updateDevToolsForContents:
230 browser_->GetSelectedTabContents()];
231}
232
233void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) {
234 // Do nothing on Mac.
235}
236
237void BrowserWindowCocoa::SetStarredState(bool is_starred) {
238 [controller_ setStarredState:is_starred ? YES : NO];
239}
240
241gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const {
242 // Flip coordinates based on the primary screen.
243 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
244 NSRect frame = [controller_ regularWindowFrame];
245 gfx::Rect bounds(frame.origin.x, 0, frame.size.width, frame.size.height);
246 bounds.set_y([screen frame].size.height - frame.origin.y - frame.size.height);
247 return bounds;
248}
249
[email protected]d479b8e22011-02-09 05:19:49250gfx::Rect BrowserWindowCocoa::GetBounds() const {
251 return GetRestoredBounds();
252}
253
[email protected]7d791652010-12-01 16:34:49254bool BrowserWindowCocoa::IsMaximized() const {
255 return [window() isZoomed];
256}
257
[email protected]400eaf82011-08-22 15:47:39258bool BrowserWindowCocoa::IsMinimized() const {
259 return [window() isMiniaturized];
260}
261
[email protected]541e3ee2011-11-22 01:31:10262void BrowserWindowCocoa::Maximize() {
263 // Zoom toggles so only call if not already maximized.
264 if (!IsMaximized())
265 [window() zoom:controller_];
266}
267
268void BrowserWindowCocoa::Minimize() {
269 [window() miniaturize:controller_];
270}
271
272void BrowserWindowCocoa::Restore() {
273 if (IsMaximized())
274 [window() zoom:controller_]; // Toggles zoom mode.
275 else if (IsMinimized())
276 [window() deminiaturize:controller_];
277}
278
[email protected]8d944b32011-10-17 06:11:53279void BrowserWindowCocoa::EnterFullscreen(
[email protected]22d74a6b2011-10-17 20:30:31280 const GURL& url, FullscreenExitBubbleType bubble_type) {
281 [controller_ enterFullscreenForURL:url
282 bubbleType:bubble_type];
[email protected]55c87fa2011-10-15 07:28:28283}
284
285void BrowserWindowCocoa::ExitFullscreen() {
[email protected]22d74a6b2011-10-17 20:30:31286 [controller_ exitFullscreen];
[email protected]8d944b32011-10-17 06:11:53287}
288
289void BrowserWindowCocoa::UpdateFullscreenExitBubbleContent(
290 const GURL& url,
291 FullscreenExitBubbleType bubble_type) {
[email protected]22d74a6b2011-10-17 20:30:31292 [controller_ updateFullscreenExitBubbleURL:url bubbleType:bubble_type];
[email protected]7d791652010-12-01 16:34:49293}
294
295bool BrowserWindowCocoa::IsFullscreen() const {
[email protected]8d944b32011-10-17 06:11:53296 return [controller_ isFullscreen];
[email protected]7d791652010-12-01 16:34:49297}
298
299bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const {
300 return false;
301}
302
303void BrowserWindowCocoa::ConfirmAddSearchProvider(
304 const TemplateURL* template_url,
305 Profile* profile) {
[email protected]464f0012011-07-07 02:12:51306 // The controller will release itself when the window closes.
307 EditSearchEngineCocoaController* editor =
308 [[EditSearchEngineCocoaController alloc] initWithProfile:profile
309 delegate:NULL
310 templateURL:template_url];
311 [NSApp beginSheet:[editor window]
312 modalForWindow:window()
313 modalDelegate:controller_
314 didEndSelector:@selector(sheetDidEnd:returnCode:context:)
315 contextInfo:NULL];
[email protected]7d791652010-12-01 16:34:49316}
317
318LocationBar* BrowserWindowCocoa::GetLocationBar() const {
319 return [controller_ locationBarBridge];
320}
321
322void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) {
323 [controller_ focusLocationBar:select_all ? YES : NO];
324}
325
326void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) {
327 [controller_ setIsLoading:is_loading force:force];
328}
329
330void BrowserWindowCocoa::UpdateToolbar(TabContentsWrapper* contents,
331 bool should_restore_state) {
332 [controller_ updateToolbarWithContents:contents->tab_contents()
333 shouldRestoreState:should_restore_state ? YES : NO];
334}
335
336void BrowserWindowCocoa::FocusToolbar() {
337 // Not needed on the Mac.
338}
339
340void BrowserWindowCocoa::FocusAppMenu() {
341 // Chrome uses the standard Mac OS X menu bar, so this isn't needed.
342}
343
344void BrowserWindowCocoa::RotatePaneFocus(bool forwards) {
345 // Not needed on the Mac.
346}
347
348void BrowserWindowCocoa::FocusBookmarksToolbar() {
349 // Not needed on the Mac.
350}
351
352void BrowserWindowCocoa::FocusChromeOSStatus() {
353 // Not needed on the Mac.
354}
355
356bool BrowserWindowCocoa::IsBookmarkBarVisible() const {
[email protected]a007e732011-08-05 13:32:19357 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
[email protected]7d791652010-12-01 16:34:49358}
359
360bool BrowserWindowCocoa::IsBookmarkBarAnimating() const {
361 return [controller_ isBookmarkBarAnimating];
362}
363
[email protected]95bf8a5b2010-12-22 16:04:07364bool BrowserWindowCocoa::IsTabStripEditable() const {
365 return ![controller_ isDragSessionActive];
366}
367
[email protected]7d791652010-12-01 16:34:49368bool BrowserWindowCocoa::IsToolbarVisible() const {
369 return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
370 browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
371}
372
373// This is called from Browser, which in turn is called directly from
374// a menu option. All we do here is set a preference. The act of
375// setting the preference sends notifications to all windows who then
376// know what to do.
377void BrowserWindowCocoa::ToggleBookmarkBar() {
378 bookmark_utils::ToggleWhenVisible(browser_->profile());
379}
380
381void BrowserWindowCocoa::AddFindBar(
382 FindBarCocoaController* find_bar_cocoa_controller) {
[email protected]632983f2011-08-08 22:51:24383 [controller_ addFindBar:find_bar_cocoa_controller];
[email protected]7d791652010-12-01 16:34:49384}
385
[email protected]4c6b474b72011-02-24 21:35:21386void BrowserWindowCocoa::ShowAboutChromeDialog() {
[email protected]287b90602011-03-02 22:43:27387 // Go through AppController's implementation to bring up the branded panel.
388 [[NSApp delegate] orderFrontStandardAboutPanel:nil];
[email protected]7d791652010-12-01 16:34:49389}
390
391void BrowserWindowCocoa::ShowUpdateChromeDialog() {
[email protected]678dae82011-02-11 20:03:08392 restart_browser::RequestRestart(window());
[email protected]7d791652010-12-01 16:34:49393}
394
395void BrowserWindowCocoa::ShowTaskManager() {
[email protected]7b937362011-10-05 08:28:07396#if defined(WEBUI_TASK_MANAGER)
397 TaskManagerDialog::Show();
398#else
399 // Uses WebUI TaskManager when swiches is set. It is beta feature.
[email protected]0bf4dc622011-12-19 06:59:44400 if (ChromeWebUI::IsMoreWebUI()) {
[email protected]7b937362011-10-05 08:28:07401 TaskManagerDialog::Show();
402 } else {
403 TaskManagerMac::Show(false);
404 }
405#endif // defined(WEBUI_TASK_MANAGER)
[email protected]adb6a84d2011-02-07 16:58:40406}
407
408void BrowserWindowCocoa::ShowBackgroundPages() {
[email protected]7b937362011-10-05 08:28:07409#if defined(WEBUI_TASK_MANAGER)
410 TaskManagerDialog::ShowBackgroundPages();
411#else
412 // Uses WebUI TaskManager when swiches is set. It is beta feature.
[email protected]0bf4dc622011-12-19 06:59:44413 if (ChromeWebUI::IsMoreWebUI()) {
[email protected]7b937362011-10-05 08:28:07414 TaskManagerDialog::ShowBackgroundPages();
415 } else {
416 TaskManagerMac::Show(true);
417 }
418#endif // defined(WEBUI_TASK_MANAGER)
[email protected]7d791652010-12-01 16:34:49419}
420
421void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
422 bool already_bookmarked) {
423 [controller_ showBookmarkBubbleForURL:url
424 alreadyBookmarked:(already_bookmarked ? YES : NO)];
425}
426
427bool BrowserWindowCocoa::IsDownloadShelfVisible() const {
428 return [controller_ isDownloadShelfVisible] != NO;
429}
430
431DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
432 DownloadShelfController* shelfController = [controller_ downloadShelf];
433 return [shelfController bridge];
434}
435
[email protected]a3627e62011-09-07 00:04:57436void BrowserWindowCocoa::ShowCollectedCookiesDialog(
437 TabContentsWrapper* wrapper) {
[email protected]7d791652010-12-01 16:34:49438 // Deletes itself on close.
[email protected]a3627e62011-09-07 00:04:57439 new CollectedCookiesMac(GetNativeHandle(), wrapper);
[email protected]7d791652010-12-01 16:34:49440}
441
[email protected]7d791652010-12-01 16:34:49442// We allow closing the window here since the real quit decision on Mac is made
443// in [AppController quit:].
444void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() {
445 // Call InProgressDownloadResponse asynchronously to avoid a crash when the
446 // browser window is closed here (http://crbug.com/44454).
[email protected]a932d9e2011-09-29 01:14:34447 MessageLoop::current()->PostTask(FROM_HERE,
448 base::Bind(&Browser::InProgressDownloadResponse,
449 confirm_close_factory_.GetWeakPtr(), true));
[email protected]7d791652010-12-01 16:34:49450}
451
[email protected]7d791652010-12-01 16:34:49452void BrowserWindowCocoa::UserChangedTheme() {
453 [controller_ userChangedTheme];
454}
455
456int BrowserWindowCocoa::GetExtraRenderViewHeight() const {
457 // Currently this is only used on linux.
458 return 0;
459}
460
[email protected]2a6bc3e2011-12-28 23:51:33461void BrowserWindowCocoa::WebContentsFocused(WebContents* contents) {
[email protected]7d791652010-12-01 16:34:49462 NOTIMPLEMENTED();
463}
464
465void BrowserWindowCocoa::ShowPageInfo(Profile* profile,
466 const GURL& url,
[email protected]d583e3f22011-12-27 21:38:17467 const SSLStatus& ssl,
[email protected]7d791652010-12-01 16:34:49468 bool show_history) {
469 browser::ShowPageInfoBubble(window(), profile, url, ssl, show_history);
470}
471
472void BrowserWindowCocoa::ShowAppMenu() {
473 // No-op. Mac doesn't support showing the menus via alt keys.
474}
475
476bool BrowserWindowCocoa::PreHandleKeyboardEvent(
477 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
[email protected]3a1381d2011-08-26 18:12:13478 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
[email protected]7d791652010-12-01 16:34:49479 return false;
480
[email protected]3a1381d2011-08-26 18:12:13481 int id = [BrowserWindowUtils getCommandId:event];
[email protected]7d791652010-12-01 16:34:49482 if (id == -1)
483 return false;
484
[email protected]3a1381d2011-08-26 18:12:13485 if (browser_->IsReservedCommandOrKey(id, event)) {
486 return [BrowserWindowUtils handleKeyboardEvent:event.os_event
487 inWindow:window()];
488 }
[email protected]7d791652010-12-01 16:34:49489
[email protected]3a1381d2011-08-26 18:12:13490 DCHECK(is_keyboard_shortcut);
[email protected]7d791652010-12-01 16:34:49491 *is_keyboard_shortcut = true;
[email protected]7d791652010-12-01 16:34:49492 return false;
493}
494
495void BrowserWindowCocoa::HandleKeyboardEvent(
496 const NativeWebKeyboardEvent& event) {
[email protected]3a1381d2011-08-26 18:12:13497 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event])
498 [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:window()];
[email protected]7d791652010-12-01 16:34:49499}
500
501void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog(
[email protected]f847e6082011-03-24 00:08:26502 TabContentsWrapper* tab_contents) {
[email protected]7d791652010-12-01 16:34:49503 NOTIMPLEMENTED();
504}
505
506void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog(
507 Profile* profile, const Extension* app) {
508 NOTIMPLEMENTED();
509}
510
511void BrowserWindowCocoa::Cut() {
512 [NSApp sendAction:@selector(cut:) to:nil from:nil];
513}
514
515void BrowserWindowCocoa::Copy() {
516 [NSApp sendAction:@selector(copy:) to:nil from:nil];
517}
518
519void BrowserWindowCocoa::Paste() {
520 [NSApp sendAction:@selector(paste:) to:nil from:nil];
521}
522
[email protected]7d791652010-12-01 16:34:49523void BrowserWindowCocoa::OpenTabpose() {
524 [controller_ openTabpose];
525}
526
[email protected]8d944b32011-10-17 06:11:53527void BrowserWindowCocoa::EnterPresentationMode(
528 const GURL& url,
529 FullscreenExitBubbleType bubble_type) {
[email protected]22d74a6b2011-10-17 20:30:31530 [controller_ enterPresentationModeForURL:url
531 bubbleType:bubble_type];
[email protected]8d944b32011-10-17 06:11:53532}
533
534void BrowserWindowCocoa::ExitPresentationMode() {
[email protected]22d74a6b2011-10-17 20:30:31535 [controller_ exitPresentationMode];
[email protected]d3766932011-08-04 22:18:23536}
537
538bool BrowserWindowCocoa::InPresentationMode() {
539 return [controller_ inPresentationMode];
540}
541
[email protected]e3690ed2011-03-25 20:25:14542void BrowserWindowCocoa::ShowInstant(TabContentsWrapper* preview) {
543 [controller_ showInstant:preview->tab_contents()];
[email protected]7d791652010-12-01 16:34:49544}
545
[email protected]3e481282011-10-15 15:39:50546void BrowserWindowCocoa::HideInstant() {
[email protected]7d791652010-12-01 16:34:49547 [controller_ hideInstant];
[email protected]7d791652010-12-01 16:34:49548}
549
550gfx::Rect BrowserWindowCocoa::GetInstantBounds() {
551 // Flip coordinates based on the primary screen.
552 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
553 NSRect monitorFrame = [screen frame];
554 NSRect frame = [controller_ instantFrame];
555 gfx::Rect bounds(NSRectToCGRect(frame));
556 bounds.set_y(NSHeight(monitorFrame) - bounds.y() - bounds.height());
557 return bounds;
558}
559
[email protected]588300d2011-04-28 21:06:35560WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds(
561 const gfx::Rect& bounds) {
562 return NEW_POPUP;
563}
564
[email protected]632983f2011-08-08 22:51:24565FindBar* BrowserWindowCocoa::CreateFindBar() {
566 // We could push the AddFindBar() call into the FindBarBridge
567 // constructor or the FindBarCocoaController init, but that makes
568 // unit testing difficult, since we would also require a
569 // BrowserWindow object.
570 FindBarBridge* bridge = new FindBarBridge();
571 AddFindBar(bridge->find_bar_cocoa_controller());
572 return bridge;
573}
574
[email protected]432115822011-07-10 15:52:27575void BrowserWindowCocoa::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53576 const content::NotificationSource& source,
577 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27578 switch (type) {
[email protected]3710d0002011-10-11 00:35:00579 case chrome::NOTIFICATION_PREF_CHANGED: {
[email protected]7ac4b872011-10-19 03:30:42580 const std::string& pref_name =
581 *content::Details<std::string>(details).ptr();
[email protected]3710d0002011-10-11 00:35:00582 DCHECK(pref_name == prefs::kShowBookmarkBar);
583 [controller_ updateBookmarkBarVisibilityWithAnimation:YES];
[email protected]7d791652010-12-01 16:34:49584 break;
[email protected]3710d0002011-10-11 00:35:00585 }
[email protected]432115822011-07-10 15:52:27586 case chrome::NOTIFICATION_SIDEBAR_CHANGED:
[email protected]7d791652010-12-01 16:34:49587 UpdateSidebarForContents(
[email protected]6c2381d2011-10-19 02:52:53588 content::Details<SidebarContainer>(details)->tab_contents());
[email protected]7d791652010-12-01 16:34:49589 break;
590 default:
591 NOTREACHED(); // we don't ask for anything else!
592 break;
593 }
594}
595
596void BrowserWindowCocoa::DestroyBrowser() {
597 [controller_ destroyBrowser];
598
599 // at this point the controller is dead (autoreleased), so
600 // make sure we don't try to reference it any more.
601}
602
603NSWindow* BrowserWindowCocoa::window() const {
604 return [controller_ window];
605}
606
607void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) {
608 if (tab_contents == browser_->GetSelectedTabContents()) {
609 [controller_ updateSidebarForContents:tab_contents];
610 }
611}
[email protected]2f733a02011-10-06 15:17:34612
613void BrowserWindowCocoa::ShowAvatarBubble(TabContents* tab_contents,
614 const gfx::Rect& rect) {
615 NSView* view = tab_contents->GetNativeView();
[email protected]79ac3cb2011-10-12 17:11:21616 NSRect bounds = [view bounds];
617 NSPoint point;
618 point.x = NSMinX(bounds) + rect.right();
619 // The view's origin is at the bottom but |rect|'s origin is at the top.
620 point.y = NSMaxY(bounds) - rect.bottom();
[email protected]2f733a02011-10-06 15:17:34621 point = [view convertPoint:point toView:nil];
622 point = [[view window] convertBaseToScreen:point];
623
624 // |menu| will automatically release itself on close.
625 AvatarMenuBubbleController* menu =
626 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_
627 anchoredAt:point];
[email protected]51152d6d2011-11-07 01:55:12628 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
[email protected]2f733a02011-10-06 15:17:34629 [menu showWindow:nil];
630}
[email protected]7d2d08152011-10-25 22:58:47631
632void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() {
633 [[controller_ avatarButtonController] showAvatarBubble];
634}