blob: 9a8726f234da4bbeaa2b6cee05aacb6d9e02ebf5 [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]075b204c2011-09-30 19:02:1634#include "chrome/browser/ui/cocoa/page_info_window.h"
[email protected]7d791652010-12-01 16:34:4935#include "chrome/browser/ui/cocoa/repost_form_warning_mac.h"
36#include "chrome/browser/ui/cocoa/restart_browser.h"
37#include "chrome/browser/ui/cocoa/status_bubble_mac.h"
38#include "chrome/browser/ui/cocoa/task_manager_mac.h"
[email protected]8450c4f2011-01-19 22:16:2239#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
[email protected]6a3ec2312010-12-02 19:30:1940#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.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]7b937362011-10-05 08:28:0743#include "chrome/common/chrome_switches.h"
[email protected]7d791652010-12-01 16:34:4944#include "chrome/common/pref_names.h"
[email protected]21f11682011-03-02 16:45:4245#include "content/browser/tab_contents/tab_contents.h"
[email protected]ad50def52011-10-19 23:17:0746#include "content/public/browser/notification_source.h"
[email protected]8bc38d22011-10-14 20:39:2047#include "content/public/browser/native_web_keyboard_event.h"
[email protected]6c2381d2011-10-19 02:52:5348#include "content/public/browser/notification_details.h"
[email protected]7d791652010-12-01 16:34:4949#include "grit/chromium_strings.h"
50#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1751#include "ui/base/l10n/l10n_util_mac.h"
[email protected]08397d52011-02-05 01:53:3852#include "ui/gfx/rect.h"
[email protected]7d791652010-12-01 16:34:4953
[email protected]400eaf82011-08-22 15:47:3954// Replicate specific 10.7 SDK declarations for building with prior SDKs.
55#if !defined(MAC_OS_X_VERSION_10_7) || \
56 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
57
58enum {
59 NSWindowAnimationBehaviorDefault = 0,
60 NSWindowAnimationBehaviorNone = 2,
61 NSWindowAnimationBehaviorDocumentWindow = 3,
62 NSWindowAnimationBehaviorUtilityWindow = 4,
63 NSWindowAnimationBehaviorAlertPanel = 5
64};
65typedef NSInteger NSWindowAnimationBehavior;
66
67@interface NSWindow (LionSDKDeclarations)
68- (NSWindowAnimationBehavior)animationBehavior;
69- (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
70@end
71
72#endif // MAC_OS_X_VERSION_10_7
73
[email protected]7d791652010-12-01 16:34:4974BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
[email protected]400eaf82011-08-22 15:47:3975 BrowserWindowController* controller)
[email protected]7d791652010-12-01 16:34:4976 : browser_(browser),
77 controller_(controller),
78 confirm_close_factory_(browser) {
[email protected]6c2381d2011-10-19 02:52:5379 registrar_.Add(
80 this, chrome::NOTIFICATION_SIDEBAR_CHANGED,
81 content::Source<SidebarManager>(SidebarManager::GetInstance()));
[email protected]cfecf9432011-09-27 17:10:0882
[email protected]3710d0002011-10-11 00:35:0083 pref_change_registrar_.Init(browser_->profile()->GetPrefs());
84 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
85
[email protected]cfecf9432011-09-27 17:10:0886 initial_show_state_ = browser_->GetSavedWindowShowState();
[email protected]7d791652010-12-01 16:34:4987}
88
89BrowserWindowCocoa::~BrowserWindowCocoa() {
90}
91
92void BrowserWindowCocoa::Show() {
93 // The Browser associated with this browser window must become the active
94 // browser at the time |Show()| is called. This is the natural behaviour under
95 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:|
96 // until we return to the runloop. Therefore any calls to
97 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return
98 // the previous browser instead if we don't explicitly set it here.
99 BrowserList::SetLastActive(browser_);
100
[email protected]8bc061f2011-08-31 22:46:23101 bool is_session_restore = browser_->is_session_restore();
[email protected]b5cc93c2011-09-02 02:33:42102 NSWindowAnimationBehavior saved_animation_behavior =
103 NSWindowAnimationBehaviorDefault;
[email protected]8bc061f2011-08-31 22:46:23104 bool did_save_animation_behavior = false;
105 // Turn off swishing when restoring windows.
106 if (is_session_restore &&
107 [window() respondsToSelector:@selector(animationBehavior)] &&
108 [window() respondsToSelector:@selector(setAnimationBehavior:)]) {
109 did_save_animation_behavior = true;
110 saved_animation_behavior = [window() animationBehavior];
111 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone];
112 }
[email protected]400eaf82011-08-22 15:47:39113
[email protected]8bc061f2011-08-31 22:46:23114 [window() makeKeyAndOrderFront:controller_];
[email protected]400eaf82011-08-22 15:47:39115
[email protected]8bc061f2011-08-31 22:46:23116 // When creating windows from nibs it is necessary to |makeKeyAndOrderFront:|
117 // prior to |orderOut:| then |miniaturize:| when restoring windows in the
118 // minimized state.
[email protected]cfecf9432011-09-27 17:10:08119 if (initial_show_state_ == ui::SHOW_STATE_MINIMIZED) {
[email protected]400eaf82011-08-22 15:47:39120 [window() orderOut:controller_];
121 [window() miniaturize:controller_];
[email protected]400eaf82011-08-22 15:47:39122 }
[email protected]cfecf9432011-09-27 17:10:08123 initial_show_state_ = ui::SHOW_STATE_DEFAULT;
[email protected]8bc061f2011-08-31 22:46:23124
125 // Restore window animation behavior.
126 if (did_save_animation_behavior)
127 [window() setAnimationBehavior:saved_animation_behavior];
[email protected]2f516c792011-09-19 22:22:09128
129 browser_->OnWindowDidShow();
[email protected]7d791652010-12-01 16:34:49130}
131
[email protected]d4db6c702011-03-28 21:49:14132void BrowserWindowCocoa::ShowInactive() {
[email protected]400eaf82011-08-22 15:47:39133 [window() orderFront:controller_];
[email protected]d4db6c702011-03-28 21:49:14134}
135
[email protected]7d791652010-12-01 16:34:49136void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) {
[email protected]ccb5895f2011-06-09 21:16:14137 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds];
138
[email protected]55c87fa2011-10-15 07:28:28139 ExitFullscreen();
[email protected]ccb5895f2011-06-09 21:16:14140 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0,
141 real_bounds.width(),
142 real_bounds.height());
[email protected]7d791652010-12-01 16:34:49143 // Flip coordinates based on the primary screen.
144 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
145 cocoa_bounds.origin.y =
[email protected]ccb5895f2011-06-09 21:16:14146 [screen frame].size.height - real_bounds.height() - real_bounds.y();
[email protected]7d791652010-12-01 16:34:49147
148 [window() setFrame:cocoa_bounds display:YES];
149}
150
151// Callers assume that this doesn't immediately delete the Browser object.
152// The controller implementing the window delegate methods called from
153// |-performClose:| must take precautions to ensure that.
154void BrowserWindowCocoa::Close() {
155 // If there is an overlay window, we contain a tab being dragged between
156 // windows. Don't hide the window as it makes the UI extra confused. We can
157 // still close the window, as that will happen when the drag completes.
158 if ([controller_ overlayWindow]) {
159 [controller_ deferPerformClose];
160 } else {
161 // Make sure we hide the window immediately. Even though performClose:
162 // calls orderOut: eventually, it leaves the window on-screen long enough
163 // that we start to see tabs shutting down. http://crbug.com/23959
164 // TODO(viettrungluu): This is kind of bad, since |-performClose:| calls
165 // |-windowShouldClose:| (on its delegate, which is probably the
166 // controller) which may return |NO| causing the window to not be closed,
167 // thereby leaving a hidden window. In fact, our window-closing procedure
168 // involves a (indirect) recursion on |-performClose:|, which is also bad.
169 [window() orderOut:controller_];
170 [window() performClose:controller_];
171 }
172}
173
174void BrowserWindowCocoa::Activate() {
175 [controller_ activate];
176}
177
178void BrowserWindowCocoa::Deactivate() {
179 // TODO(jcivelli): http://crbug.com/51364 Implement me.
180 NOTIMPLEMENTED();
181}
182
183void BrowserWindowCocoa::FlashFrame() {
184 [NSApp requestUserAttention:NSInformationalRequest];
185}
186
187bool BrowserWindowCocoa::IsActive() const {
188 return [window() isKeyWindow];
189}
190
191gfx::NativeWindow BrowserWindowCocoa::GetNativeHandle() {
192 return window();
193}
194
195BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() {
196 return NULL;
197}
198
199StatusBubble* BrowserWindowCocoa::GetStatusBubble() {
200 return [controller_ statusBubble];
201}
202
[email protected]c9bd2e82011-04-15 23:28:19203void BrowserWindowCocoa::ToolbarSizeChanged(bool is_animating) {
[email protected]7d791652010-12-01 16:34:49204 // According to beng, this is an ugly method that comes from the days when the
205 // download shelf was a ChromeView attached to the TabContents, and as its
206 // size changed via animation it notified through TCD/etc to the browser view
207 // to relayout for each tick of the animation. We don't need anything of the
208 // sort on Mac.
209}
210
211void BrowserWindowCocoa::UpdateTitleBar() {
212 NSString* newTitle =
213 base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab());
214
[email protected]d78e615e2011-09-06 21:46:03215 pending_window_title_.reset(
216 [BrowserWindowUtils scheduleReplaceOldTitle:pending_window_title_.get()
217 withNewTitle:newTitle
218 forWindow:window()]);
[email protected]7d791652010-12-01 16:34:49219}
220
[email protected]09b29342011-06-24 19:18:48221void BrowserWindowCocoa::BookmarkBarStateChanged(
222 BookmarkBar::AnimateChangeType change_type) {
223 // TODO: route changes to state through this.
[email protected]7d791652010-12-01 16:34:49224}
225
226void BrowserWindowCocoa::UpdateDevTools() {
227 [controller_ updateDevToolsForContents:
228 browser_->GetSelectedTabContents()];
229}
230
231void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) {
232 // Do nothing on Mac.
233}
234
235void BrowserWindowCocoa::SetStarredState(bool is_starred) {
236 [controller_ setStarredState:is_starred ? YES : NO];
237}
238
239gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const {
240 // Flip coordinates based on the primary screen.
241 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
242 NSRect frame = [controller_ regularWindowFrame];
243 gfx::Rect bounds(frame.origin.x, 0, frame.size.width, frame.size.height);
244 bounds.set_y([screen frame].size.height - frame.origin.y - frame.size.height);
245 return bounds;
246}
247
[email protected]d479b8e22011-02-09 05:19:49248gfx::Rect BrowserWindowCocoa::GetBounds() const {
249 return GetRestoredBounds();
250}
251
[email protected]7d791652010-12-01 16:34:49252bool BrowserWindowCocoa::IsMaximized() const {
253 return [window() isZoomed];
254}
255
[email protected]400eaf82011-08-22 15:47:39256bool BrowserWindowCocoa::IsMinimized() const {
257 return [window() isMiniaturized];
258}
259
[email protected]8d944b32011-10-17 06:11:53260void BrowserWindowCocoa::EnterFullscreen(
[email protected]22d74a6b2011-10-17 20:30:31261 const GURL& url, FullscreenExitBubbleType bubble_type) {
262 [controller_ enterFullscreenForURL:url
263 bubbleType:bubble_type];
[email protected]55c87fa2011-10-15 07:28:28264}
265
266void BrowserWindowCocoa::ExitFullscreen() {
[email protected]22d74a6b2011-10-17 20:30:31267 [controller_ exitFullscreen];
[email protected]8d944b32011-10-17 06:11:53268}
269
270void BrowserWindowCocoa::UpdateFullscreenExitBubbleContent(
271 const GURL& url,
272 FullscreenExitBubbleType bubble_type) {
[email protected]22d74a6b2011-10-17 20:30:31273 [controller_ updateFullscreenExitBubbleURL:url bubbleType:bubble_type];
[email protected]7d791652010-12-01 16:34:49274}
275
276bool BrowserWindowCocoa::IsFullscreen() const {
[email protected]8d944b32011-10-17 06:11:53277 return [controller_ isFullscreen];
[email protected]7d791652010-12-01 16:34:49278}
279
280bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const {
281 return false;
282}
283
284void BrowserWindowCocoa::ConfirmAddSearchProvider(
285 const TemplateURL* template_url,
286 Profile* profile) {
[email protected]464f0012011-07-07 02:12:51287 // The controller will release itself when the window closes.
288 EditSearchEngineCocoaController* editor =
289 [[EditSearchEngineCocoaController alloc] initWithProfile:profile
290 delegate:NULL
291 templateURL:template_url];
292 [NSApp beginSheet:[editor window]
293 modalForWindow:window()
294 modalDelegate:controller_
295 didEndSelector:@selector(sheetDidEnd:returnCode:context:)
296 contextInfo:NULL];
[email protected]7d791652010-12-01 16:34:49297}
298
299LocationBar* BrowserWindowCocoa::GetLocationBar() const {
300 return [controller_ locationBarBridge];
301}
302
303void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) {
304 [controller_ focusLocationBar:select_all ? YES : NO];
305}
306
307void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) {
308 [controller_ setIsLoading:is_loading force:force];
309}
310
311void BrowserWindowCocoa::UpdateToolbar(TabContentsWrapper* contents,
312 bool should_restore_state) {
313 [controller_ updateToolbarWithContents:contents->tab_contents()
314 shouldRestoreState:should_restore_state ? YES : NO];
315}
316
317void BrowserWindowCocoa::FocusToolbar() {
318 // Not needed on the Mac.
319}
320
321void BrowserWindowCocoa::FocusAppMenu() {
322 // Chrome uses the standard Mac OS X menu bar, so this isn't needed.
323}
324
325void BrowserWindowCocoa::RotatePaneFocus(bool forwards) {
326 // Not needed on the Mac.
327}
328
329void BrowserWindowCocoa::FocusBookmarksToolbar() {
330 // Not needed on the Mac.
331}
332
333void BrowserWindowCocoa::FocusChromeOSStatus() {
334 // Not needed on the Mac.
335}
336
337bool BrowserWindowCocoa::IsBookmarkBarVisible() const {
[email protected]a007e732011-08-05 13:32:19338 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
[email protected]7d791652010-12-01 16:34:49339}
340
341bool BrowserWindowCocoa::IsBookmarkBarAnimating() const {
342 return [controller_ isBookmarkBarAnimating];
343}
344
[email protected]95bf8a5b2010-12-22 16:04:07345bool BrowserWindowCocoa::IsTabStripEditable() const {
346 return ![controller_ isDragSessionActive];
347}
348
[email protected]7d791652010-12-01 16:34:49349bool BrowserWindowCocoa::IsToolbarVisible() const {
350 return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
351 browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
352}
353
354// This is called from Browser, which in turn is called directly from
355// a menu option. All we do here is set a preference. The act of
356// setting the preference sends notifications to all windows who then
357// know what to do.
358void BrowserWindowCocoa::ToggleBookmarkBar() {
359 bookmark_utils::ToggleWhenVisible(browser_->profile());
360}
361
362void BrowserWindowCocoa::AddFindBar(
363 FindBarCocoaController* find_bar_cocoa_controller) {
[email protected]632983f2011-08-08 22:51:24364 [controller_ addFindBar:find_bar_cocoa_controller];
[email protected]7d791652010-12-01 16:34:49365}
366
[email protected]4c6b474b72011-02-24 21:35:21367void BrowserWindowCocoa::ShowAboutChromeDialog() {
[email protected]287b90602011-03-02 22:43:27368 // Go through AppController's implementation to bring up the branded panel.
369 [[NSApp delegate] orderFrontStandardAboutPanel:nil];
[email protected]7d791652010-12-01 16:34:49370}
371
372void BrowserWindowCocoa::ShowUpdateChromeDialog() {
[email protected]678dae82011-02-11 20:03:08373 restart_browser::RequestRestart(window());
[email protected]7d791652010-12-01 16:34:49374}
375
376void BrowserWindowCocoa::ShowTaskManager() {
[email protected]7b937362011-10-05 08:28:07377#if defined(WEBUI_TASK_MANAGER)
378 TaskManagerDialog::Show();
379#else
380 // Uses WebUI TaskManager when swiches is set. It is beta feature.
381 if (CommandLine::ForCurrentProcess()
382 ->HasSwitch(switches::kEnableWebUITaskManager)) {
383 TaskManagerDialog::Show();
384 } else {
385 TaskManagerMac::Show(false);
386 }
387#endif // defined(WEBUI_TASK_MANAGER)
[email protected]adb6a84d2011-02-07 16:58:40388}
389
390void BrowserWindowCocoa::ShowBackgroundPages() {
[email protected]7b937362011-10-05 08:28:07391#if defined(WEBUI_TASK_MANAGER)
392 TaskManagerDialog::ShowBackgroundPages();
393#else
394 // Uses WebUI TaskManager when swiches is set. It is beta feature.
395 if (CommandLine::ForCurrentProcess()
396 ->HasSwitch(switches::kEnableWebUITaskManager)) {
397 TaskManagerDialog::ShowBackgroundPages();
398 } else {
399 TaskManagerMac::Show(true);
400 }
401#endif // defined(WEBUI_TASK_MANAGER)
[email protected]7d791652010-12-01 16:34:49402}
403
404void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
405 bool already_bookmarked) {
406 [controller_ showBookmarkBubbleForURL:url
407 alreadyBookmarked:(already_bookmarked ? YES : NO)];
408}
409
410bool BrowserWindowCocoa::IsDownloadShelfVisible() const {
411 return [controller_ isDownloadShelfVisible] != NO;
412}
413
414DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
415 DownloadShelfController* shelfController = [controller_ downloadShelf];
416 return [shelfController bridge];
417}
418
[email protected]7d791652010-12-01 16:34:49419void BrowserWindowCocoa::ShowRepostFormWarningDialog(
420 TabContents* tab_contents) {
421 RepostFormWarningMac::Create(GetNativeHandle(), tab_contents);
422}
423
[email protected]a3627e62011-09-07 00:04:57424void BrowserWindowCocoa::ShowCollectedCookiesDialog(
425 TabContentsWrapper* wrapper) {
[email protected]7d791652010-12-01 16:34:49426 // Deletes itself on close.
[email protected]a3627e62011-09-07 00:04:57427 new CollectedCookiesMac(GetNativeHandle(), wrapper);
[email protected]7d791652010-12-01 16:34:49428}
429
[email protected]7d791652010-12-01 16:34:49430// We allow closing the window here since the real quit decision on Mac is made
431// in [AppController quit:].
432void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() {
433 // Call InProgressDownloadResponse asynchronously to avoid a crash when the
434 // browser window is closed here (http://crbug.com/44454).
[email protected]a932d9e2011-09-29 01:14:34435 MessageLoop::current()->PostTask(FROM_HERE,
436 base::Bind(&Browser::InProgressDownloadResponse,
437 confirm_close_factory_.GetWeakPtr(), true));
[email protected]7d791652010-12-01 16:34:49438}
439
[email protected]7d791652010-12-01 16:34:49440void BrowserWindowCocoa::UserChangedTheme() {
441 [controller_ userChangedTheme];
442}
443
444int BrowserWindowCocoa::GetExtraRenderViewHeight() const {
445 // Currently this is only used on linux.
446 return 0;
447}
448
449void BrowserWindowCocoa::TabContentsFocused(TabContents* tab_contents) {
450 NOTIMPLEMENTED();
451}
452
453void BrowserWindowCocoa::ShowPageInfo(Profile* profile,
454 const GURL& url,
455 const NavigationEntry::SSLStatus& ssl,
456 bool show_history) {
457 browser::ShowPageInfoBubble(window(), profile, url, ssl, show_history);
458}
459
460void BrowserWindowCocoa::ShowAppMenu() {
461 // No-op. Mac doesn't support showing the menus via alt keys.
462}
463
464bool BrowserWindowCocoa::PreHandleKeyboardEvent(
465 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
[email protected]3a1381d2011-08-26 18:12:13466 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
[email protected]7d791652010-12-01 16:34:49467 return false;
468
[email protected]3a1381d2011-08-26 18:12:13469 int id = [BrowserWindowUtils getCommandId:event];
[email protected]7d791652010-12-01 16:34:49470 if (id == -1)
471 return false;
472
[email protected]3a1381d2011-08-26 18:12:13473 if (browser_->IsReservedCommandOrKey(id, event)) {
474 return [BrowserWindowUtils handleKeyboardEvent:event.os_event
475 inWindow:window()];
476 }
[email protected]7d791652010-12-01 16:34:49477
[email protected]3a1381d2011-08-26 18:12:13478 DCHECK(is_keyboard_shortcut);
[email protected]7d791652010-12-01 16:34:49479 *is_keyboard_shortcut = true;
[email protected]7d791652010-12-01 16:34:49480 return false;
481}
482
483void BrowserWindowCocoa::HandleKeyboardEvent(
484 const NativeWebKeyboardEvent& event) {
[email protected]3a1381d2011-08-26 18:12:13485 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event])
486 [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:window()];
[email protected]7d791652010-12-01 16:34:49487}
488
489void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog(
[email protected]f847e6082011-03-24 00:08:26490 TabContentsWrapper* tab_contents) {
[email protected]7d791652010-12-01 16:34:49491 NOTIMPLEMENTED();
492}
493
494void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog(
495 Profile* profile, const Extension* app) {
496 NOTIMPLEMENTED();
497}
498
499void BrowserWindowCocoa::Cut() {
500 [NSApp sendAction:@selector(cut:) to:nil from:nil];
501}
502
503void BrowserWindowCocoa::Copy() {
504 [NSApp sendAction:@selector(copy:) to:nil from:nil];
505}
506
507void BrowserWindowCocoa::Paste() {
508 [NSApp sendAction:@selector(paste:) to:nil from:nil];
509}
510
[email protected]7d791652010-12-01 16:34:49511void BrowserWindowCocoa::OpenTabpose() {
512 [controller_ openTabpose];
513}
514
[email protected]8d944b32011-10-17 06:11:53515void BrowserWindowCocoa::EnterPresentationMode(
516 const GURL& url,
517 FullscreenExitBubbleType bubble_type) {
[email protected]22d74a6b2011-10-17 20:30:31518 [controller_ enterPresentationModeForURL:url
519 bubbleType:bubble_type];
[email protected]8d944b32011-10-17 06:11:53520}
521
522void BrowserWindowCocoa::ExitPresentationMode() {
[email protected]22d74a6b2011-10-17 20:30:31523 [controller_ exitPresentationMode];
[email protected]d3766932011-08-04 22:18:23524}
525
526bool BrowserWindowCocoa::InPresentationMode() {
527 return [controller_ inPresentationMode];
528}
529
[email protected]e3690ed2011-03-25 20:25:14530void BrowserWindowCocoa::ShowInstant(TabContentsWrapper* preview) {
531 [controller_ showInstant:preview->tab_contents()];
[email protected]7d791652010-12-01 16:34:49532}
533
[email protected]3e481282011-10-15 15:39:50534void BrowserWindowCocoa::HideInstant() {
[email protected]7d791652010-12-01 16:34:49535 [controller_ hideInstant];
[email protected]7d791652010-12-01 16:34:49536}
537
538gfx::Rect BrowserWindowCocoa::GetInstantBounds() {
539 // Flip coordinates based on the primary screen.
540 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
541 NSRect monitorFrame = [screen frame];
542 NSRect frame = [controller_ instantFrame];
543 gfx::Rect bounds(NSRectToCGRect(frame));
544 bounds.set_y(NSHeight(monitorFrame) - bounds.y() - bounds.height());
545 return bounds;
546}
547
[email protected]588300d2011-04-28 21:06:35548WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds(
549 const gfx::Rect& bounds) {
550 return NEW_POPUP;
551}
552
[email protected]632983f2011-08-08 22:51:24553FindBar* BrowserWindowCocoa::CreateFindBar() {
554 // We could push the AddFindBar() call into the FindBarBridge
555 // constructor or the FindBarCocoaController init, but that makes
556 // unit testing difficult, since we would also require a
557 // BrowserWindow object.
558 FindBarBridge* bridge = new FindBarBridge();
559 AddFindBar(bridge->find_bar_cocoa_controller());
560 return bridge;
561}
562
[email protected]432115822011-07-10 15:52:27563void BrowserWindowCocoa::Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53564 const content::NotificationSource& source,
565 const content::NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27566 switch (type) {
[email protected]3710d0002011-10-11 00:35:00567 case chrome::NOTIFICATION_PREF_CHANGED: {
[email protected]7ac4b872011-10-19 03:30:42568 const std::string& pref_name =
569 *content::Details<std::string>(details).ptr();
[email protected]3710d0002011-10-11 00:35:00570 DCHECK(pref_name == prefs::kShowBookmarkBar);
571 [controller_ updateBookmarkBarVisibilityWithAnimation:YES];
[email protected]7d791652010-12-01 16:34:49572 break;
[email protected]3710d0002011-10-11 00:35:00573 }
[email protected]432115822011-07-10 15:52:27574 case chrome::NOTIFICATION_SIDEBAR_CHANGED:
[email protected]7d791652010-12-01 16:34:49575 UpdateSidebarForContents(
[email protected]6c2381d2011-10-19 02:52:53576 content::Details<SidebarContainer>(details)->tab_contents());
[email protected]7d791652010-12-01 16:34:49577 break;
578 default:
579 NOTREACHED(); // we don't ask for anything else!
580 break;
581 }
582}
583
584void BrowserWindowCocoa::DestroyBrowser() {
585 [controller_ destroyBrowser];
586
587 // at this point the controller is dead (autoreleased), so
588 // make sure we don't try to reference it any more.
589}
590
591NSWindow* BrowserWindowCocoa::window() const {
592 return [controller_ window];
593}
594
595void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) {
596 if (tab_contents == browser_->GetSelectedTabContents()) {
597 [controller_ updateSidebarForContents:tab_contents];
598 }
599}
[email protected]2f733a02011-10-06 15:17:34600
601void BrowserWindowCocoa::ShowAvatarBubble(TabContents* tab_contents,
602 const gfx::Rect& rect) {
603 NSView* view = tab_contents->GetNativeView();
[email protected]79ac3cb2011-10-12 17:11:21604 NSRect bounds = [view bounds];
605 NSPoint point;
606 point.x = NSMinX(bounds) + rect.right();
607 // The view's origin is at the bottom but |rect|'s origin is at the top.
608 point.y = NSMaxY(bounds) - rect.bottom();
[email protected]2f733a02011-10-06 15:17:34609 point = [view convertPoint:point toView:nil];
610 point = [[view window] convertBaseToScreen:point];
611
612 // |menu| will automatically release itself on close.
613 AvatarMenuBubbleController* menu =
614 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_
615 anchoredAt:point];
[email protected]51152d6d2011-11-07 01:55:12616 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
[email protected]2f733a02011-10-06 15:17:34617 [menu showWindow:nil];
618}
[email protected]7d2d08152011-10-25 22:58:47619
620void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() {
621 [[controller_ avatarButtonController] showAvatarBubble];
622}