blob: fe6dd8a1deae07703a4f01662758d33044f81874 [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]7d791652010-12-01 16:34:497#include "base/command_line.h"
8#include "base/logging.h"
9#include "base/message_loop.h"
10#include "base/sys_string_conversions.h"
11#include "chrome/app/chrome_command_ids.h"
12#include "chrome/browser/bookmarks/bookmark_utils.h"
13#include "chrome/browser/download/download_shelf.h"
14#include "chrome/browser/global_keyboard_shortcuts_mac.h"
15#include "chrome/browser/page_info_window.h"
16#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3317#include "chrome/browser/profiles/profile.h"
[email protected]7d791652010-12-01 16:34:4918#include "chrome/browser/sidebar/sidebar_container.h"
19#include "chrome/browser/sidebar/sidebar_manager.h"
[email protected]7d791652010-12-01 16:34:4920#include "chrome/browser/ui/browser.h"
21#include "chrome/browser/ui/browser_list.h"
22#import "chrome/browser/ui/cocoa/browser_window_controller.h"
23#import "chrome/browser/ui/cocoa/bug_report_window_controller.h"
24#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
[email protected]fa8102292011-01-20 16:21:2325#import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h"
[email protected]7d791652010-12-01 16:34:4926#import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
[email protected]7d791652010-12-01 16:34:4927#import "chrome/browser/ui/cocoa/html_dialog_window_controller.h"
[email protected]7d791652010-12-01 16:34:4928#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
[email protected]a7d83ca2011-03-06 14:41:0729#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
[email protected]7d791652010-12-01 16:34:4930#include "chrome/browser/ui/cocoa/repost_form_warning_mac.h"
31#include "chrome/browser/ui/cocoa/restart_browser.h"
32#include "chrome/browser/ui/cocoa/status_bubble_mac.h"
33#include "chrome/browser/ui/cocoa/task_manager_mac.h"
34#import "chrome/browser/ui/cocoa/theme_install_bubble_view.h"
[email protected]8450c4f2011-01-19 22:16:2235#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
[email protected]6a3ec2312010-12-02 19:30:1936#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]7d791652010-12-01 16:34:4937#include "chrome/common/pref_names.h"
[email protected]21f11682011-03-02 16:45:4238#include "content/browser/tab_contents/tab_contents.h"
[email protected]4dd57932011-03-17 06:06:1239#include "content/common/native_web_keyboard_event.h"
[email protected]7f070d42011-03-09 20:25:3240#include "content/common/notification_service.h"
[email protected]7d791652010-12-01 16:34:4941#include "grit/chromium_strings.h"
42#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1743#include "ui/base/l10n/l10n_util_mac.h"
[email protected]08397d52011-02-05 01:53:3844#include "ui/gfx/rect.h"
[email protected]7d791652010-12-01 16:34:4945
46BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
47 BrowserWindowController* controller,
48 NSWindow* window)
49 : browser_(browser),
50 controller_(controller),
51 confirm_close_factory_(browser) {
52 // This pref applies to all windows, so all must watch for it.
53 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
54 NotificationService::AllSources());
55 registrar_.Add(this, NotificationType::SIDEBAR_CHANGED,
56 NotificationService::AllSources());
57}
58
59BrowserWindowCocoa::~BrowserWindowCocoa() {
60}
61
62void BrowserWindowCocoa::Show() {
63 // The Browser associated with this browser window must become the active
64 // browser at the time |Show()| is called. This is the natural behaviour under
65 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:|
66 // until we return to the runloop. Therefore any calls to
67 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return
68 // the previous browser instead if we don't explicitly set it here.
69 BrowserList::SetLastActive(browser_);
70
71 [window() makeKeyAndOrderFront:controller_];
72}
73
[email protected]d4db6c702011-03-28 21:49:1474void BrowserWindowCocoa::ShowInactive() {
75 [window() orderFront:controller_];
76}
77
[email protected]7d791652010-12-01 16:34:4978void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) {
[email protected]ccb5895f2011-06-09 21:16:1479 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds];
80
[email protected]d479b8e22011-02-09 05:19:4981 SetFullscreen(false);
[email protected]ccb5895f2011-06-09 21:16:1482 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0,
83 real_bounds.width(),
84 real_bounds.height());
[email protected]7d791652010-12-01 16:34:4985 // Flip coordinates based on the primary screen.
86 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
87 cocoa_bounds.origin.y =
[email protected]ccb5895f2011-06-09 21:16:1488 [screen frame].size.height - real_bounds.height() - real_bounds.y();
[email protected]7d791652010-12-01 16:34:4989
90 [window() setFrame:cocoa_bounds display:YES];
91}
92
93// Callers assume that this doesn't immediately delete the Browser object.
94// The controller implementing the window delegate methods called from
95// |-performClose:| must take precautions to ensure that.
96void BrowserWindowCocoa::Close() {
97 // If there is an overlay window, we contain a tab being dragged between
98 // windows. Don't hide the window as it makes the UI extra confused. We can
99 // still close the window, as that will happen when the drag completes.
100 if ([controller_ overlayWindow]) {
101 [controller_ deferPerformClose];
102 } else {
103 // Make sure we hide the window immediately. Even though performClose:
104 // calls orderOut: eventually, it leaves the window on-screen long enough
105 // that we start to see tabs shutting down. http://crbug.com/23959
106 // TODO(viettrungluu): This is kind of bad, since |-performClose:| calls
107 // |-windowShouldClose:| (on its delegate, which is probably the
108 // controller) which may return |NO| causing the window to not be closed,
109 // thereby leaving a hidden window. In fact, our window-closing procedure
110 // involves a (indirect) recursion on |-performClose:|, which is also bad.
111 [window() orderOut:controller_];
112 [window() performClose:controller_];
113 }
114}
115
116void BrowserWindowCocoa::Activate() {
117 [controller_ activate];
118}
119
120void BrowserWindowCocoa::Deactivate() {
121 // TODO(jcivelli): http://crbug.com/51364 Implement me.
122 NOTIMPLEMENTED();
123}
124
125void BrowserWindowCocoa::FlashFrame() {
126 [NSApp requestUserAttention:NSInformationalRequest];
127}
128
129bool BrowserWindowCocoa::IsActive() const {
130 return [window() isKeyWindow];
131}
132
133gfx::NativeWindow BrowserWindowCocoa::GetNativeHandle() {
134 return window();
135}
136
137BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() {
138 return NULL;
139}
140
141StatusBubble* BrowserWindowCocoa::GetStatusBubble() {
142 return [controller_ statusBubble];
143}
144
[email protected]c9bd2e82011-04-15 23:28:19145void BrowserWindowCocoa::ToolbarSizeChanged(bool is_animating) {
[email protected]7d791652010-12-01 16:34:49146 // According to beng, this is an ugly method that comes from the days when the
147 // download shelf was a ChromeView attached to the TabContents, and as its
148 // size changed via animation it notified through TCD/etc to the browser view
149 // to relayout for each tick of the animation. We don't need anything of the
150 // sort on Mac.
151}
152
153void BrowserWindowCocoa::UpdateTitleBar() {
154 NSString* newTitle =
155 base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab());
156
157 // Work around Cocoa bug: if a window changes title during the tracking of the
158 // Window menu it doesn't display well and the constant re-sorting of the list
159 // makes it difficult for the user to pick the desired window. Delay window
160 // title updates until the default run-loop mode.
161
162 if (pending_window_title_.get())
163 [[NSRunLoop currentRunLoop]
164 cancelPerformSelector:@selector(setTitle:)
165 target:window()
166 argument:pending_window_title_.get()];
167
168 pending_window_title_.reset([newTitle copy]);
169 [[NSRunLoop currentRunLoop]
170 performSelector:@selector(setTitle:)
171 target:window()
172 argument:newTitle
173 order:0
174 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
175}
176
177void BrowserWindowCocoa::ShelfVisibilityChanged() {
178 // Mac doesn't yet support showing the bookmark bar at a different size on
179 // the new tab page. When it does, this method should attempt to relayout the
180 // bookmark bar/extension shelf as their preferred height may have changed.
181 // http://crbug.com/43346
182}
183
184void BrowserWindowCocoa::UpdateDevTools() {
185 [controller_ updateDevToolsForContents:
186 browser_->GetSelectedTabContents()];
187}
188
189void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) {
190 // Do nothing on Mac.
191}
192
193void BrowserWindowCocoa::SetStarredState(bool is_starred) {
194 [controller_ setStarredState:is_starred ? YES : NO];
195}
196
197gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const {
198 // Flip coordinates based on the primary screen.
199 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
200 NSRect frame = [controller_ regularWindowFrame];
201 gfx::Rect bounds(frame.origin.x, 0, frame.size.width, frame.size.height);
202 bounds.set_y([screen frame].size.height - frame.origin.y - frame.size.height);
203 return bounds;
204}
205
[email protected]d479b8e22011-02-09 05:19:49206gfx::Rect BrowserWindowCocoa::GetBounds() const {
207 return GetRestoredBounds();
208}
209
[email protected]7d791652010-12-01 16:34:49210bool BrowserWindowCocoa::IsMaximized() const {
211 return [window() isZoomed];
212}
213
214void BrowserWindowCocoa::SetFullscreen(bool fullscreen) {
215 [controller_ setFullscreen:fullscreen];
216}
217
218bool BrowserWindowCocoa::IsFullscreen() const {
219 return !![controller_ isFullscreen];
220}
221
222bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const {
223 return false;
224}
225
226void BrowserWindowCocoa::ConfirmAddSearchProvider(
227 const TemplateURL* template_url,
228 Profile* profile) {
[email protected]68a58f12011-03-09 16:31:25229 NOTIMPLEMENTED();
[email protected]7d791652010-12-01 16:34:49230}
231
232LocationBar* BrowserWindowCocoa::GetLocationBar() const {
233 return [controller_ locationBarBridge];
234}
235
236void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) {
237 [controller_ focusLocationBar:select_all ? YES : NO];
238}
239
240void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) {
241 [controller_ setIsLoading:is_loading force:force];
242}
243
244void BrowserWindowCocoa::UpdateToolbar(TabContentsWrapper* contents,
245 bool should_restore_state) {
246 [controller_ updateToolbarWithContents:contents->tab_contents()
247 shouldRestoreState:should_restore_state ? YES : NO];
248}
249
250void BrowserWindowCocoa::FocusToolbar() {
251 // Not needed on the Mac.
252}
253
254void BrowserWindowCocoa::FocusAppMenu() {
255 // Chrome uses the standard Mac OS X menu bar, so this isn't needed.
256}
257
258void BrowserWindowCocoa::RotatePaneFocus(bool forwards) {
259 // Not needed on the Mac.
260}
261
262void BrowserWindowCocoa::FocusBookmarksToolbar() {
263 // Not needed on the Mac.
264}
265
266void BrowserWindowCocoa::FocusChromeOSStatus() {
267 // Not needed on the Mac.
268}
269
270bool BrowserWindowCocoa::IsBookmarkBarVisible() const {
[email protected]b3be10fa2011-04-11 15:43:15271 return (browser_->profile()->GetPrefs()->GetBoolean(
272 prefs::kShowBookmarkBar) &&
273 browser_->profile()->GetPrefs()->GetBoolean(
274 prefs::kEnableBookmarkBar));
[email protected]7d791652010-12-01 16:34:49275}
276
277bool BrowserWindowCocoa::IsBookmarkBarAnimating() const {
278 return [controller_ isBookmarkBarAnimating];
279}
280
[email protected]95bf8a5b2010-12-22 16:04:07281bool BrowserWindowCocoa::IsTabStripEditable() const {
282 return ![controller_ isDragSessionActive];
283}
284
[email protected]7d791652010-12-01 16:34:49285bool BrowserWindowCocoa::IsToolbarVisible() const {
286 return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
287 browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
288}
289
290// This is called from Browser, which in turn is called directly from
291// a menu option. All we do here is set a preference. The act of
292// setting the preference sends notifications to all windows who then
293// know what to do.
294void BrowserWindowCocoa::ToggleBookmarkBar() {
295 bookmark_utils::ToggleWhenVisible(browser_->profile());
296}
297
298void BrowserWindowCocoa::AddFindBar(
299 FindBarCocoaController* find_bar_cocoa_controller) {
300 return [controller_ addFindBar:find_bar_cocoa_controller];
301}
302
[email protected]4c6b474b72011-02-24 21:35:21303void BrowserWindowCocoa::ShowAboutChromeDialog() {
[email protected]287b90602011-03-02 22:43:27304 // Go through AppController's implementation to bring up the branded panel.
305 [[NSApp delegate] orderFrontStandardAboutPanel:nil];
[email protected]7d791652010-12-01 16:34:49306}
307
308void BrowserWindowCocoa::ShowUpdateChromeDialog() {
[email protected]678dae82011-02-11 20:03:08309 restart_browser::RequestRestart(window());
[email protected]7d791652010-12-01 16:34:49310}
311
312void BrowserWindowCocoa::ShowTaskManager() {
[email protected]adb6a84d2011-02-07 16:58:40313 TaskManagerMac::Show(false);
314}
315
316void BrowserWindowCocoa::ShowBackgroundPages() {
317 TaskManagerMac::Show(true);
[email protected]7d791652010-12-01 16:34:49318}
319
320void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
321 bool already_bookmarked) {
322 [controller_ showBookmarkBubbleForURL:url
323 alreadyBookmarked:(already_bookmarked ? YES : NO)];
324}
325
326bool BrowserWindowCocoa::IsDownloadShelfVisible() const {
327 return [controller_ isDownloadShelfVisible] != NO;
328}
329
330DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
331 DownloadShelfController* shelfController = [controller_ downloadShelf];
332 return [shelfController bridge];
333}
334
[email protected]7d791652010-12-01 16:34:49335void BrowserWindowCocoa::ShowRepostFormWarningDialog(
336 TabContents* tab_contents) {
337 RepostFormWarningMac::Create(GetNativeHandle(), tab_contents);
338}
339
[email protected]7d791652010-12-01 16:34:49340void BrowserWindowCocoa::ShowCollectedCookiesDialog(TabContents* tab_contents) {
341 // Deletes itself on close.
342 new CollectedCookiesMac(GetNativeHandle(), tab_contents);
343}
344
[email protected]7d791652010-12-01 16:34:49345void BrowserWindowCocoa::ShowThemeInstallBubble() {
346 ThemeInstallBubbleView::Show(window());
347}
348
349// We allow closing the window here since the real quit decision on Mac is made
350// in [AppController quit:].
351void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() {
352 // Call InProgressDownloadResponse asynchronously to avoid a crash when the
353 // browser window is closed here (http://crbug.com/44454).
354 MessageLoop::current()->PostTask(
355 FROM_HERE,
356 confirm_close_factory_.NewRunnableMethod(
357 &Browser::InProgressDownloadResponse,
358 true));
359}
360
361void BrowserWindowCocoa::ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
362 gfx::NativeWindow parent_window) {
363 [HtmlDialogWindowController showHtmlDialog:delegate
364 profile:browser_->profile()];
365}
366
367void BrowserWindowCocoa::UserChangedTheme() {
368 [controller_ userChangedTheme];
369}
370
371int BrowserWindowCocoa::GetExtraRenderViewHeight() const {
372 // Currently this is only used on linux.
373 return 0;
374}
375
376void BrowserWindowCocoa::TabContentsFocused(TabContents* tab_contents) {
377 NOTIMPLEMENTED();
378}
379
380void BrowserWindowCocoa::ShowPageInfo(Profile* profile,
381 const GURL& url,
382 const NavigationEntry::SSLStatus& ssl,
383 bool show_history) {
384 browser::ShowPageInfoBubble(window(), profile, url, ssl, show_history);
385}
386
387void BrowserWindowCocoa::ShowAppMenu() {
388 // No-op. Mac doesn't support showing the menus via alt keys.
389}
390
391bool BrowserWindowCocoa::PreHandleKeyboardEvent(
392 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
393 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
394 return false;
395
396 DCHECK(event.os_event != NULL);
397 int id = GetCommandId(event);
398 if (id == -1)
399 return false;
400
[email protected]06181422011-02-09 17:44:21401 if (browser_->IsReservedCommandOrKey(id, event))
[email protected]7d791652010-12-01 16:34:49402 return HandleKeyboardEventInternal(event.os_event);
403
404 DCHECK(is_keyboard_shortcut != NULL);
405 *is_keyboard_shortcut = true;
406
407 return false;
408}
409
410void BrowserWindowCocoa::HandleKeyboardEvent(
411 const NativeWebKeyboardEvent& event) {
412 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
413 return;
414
415 DCHECK(event.os_event != NULL);
416 HandleKeyboardEventInternal(event.os_event);
417}
418
419@interface MenuWalker : NSObject
420+ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
421 menu:(NSMenu*)menu;
422@end
423
424@implementation MenuWalker
425+ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
426 menu:(NSMenu*)menu {
427 NSMenuItem* result = nil;
428
429 for (NSMenuItem *item in [menu itemArray]) {
430 NSMenu* submenu = [item submenu];
431 if (submenu) {
432 if (submenu != [NSApp servicesMenu])
433 result = [self itemForKeyEquivalent:key
434 menu:submenu];
[email protected]0f72a2dc2010-12-06 19:40:23435 } else if ([item cr_firesForKeyEventIfEnabled:key]) {
[email protected]7d791652010-12-01 16:34:49436 result = item;
437 }
438
439 if (result)
440 break;
441 }
442
443 return result;
444}
445@end
446
447int BrowserWindowCocoa::GetCommandId(const NativeWebKeyboardEvent& event) {
448 if ([event.os_event type] != NSKeyDown)
449 return -1;
450
451 // Look in menu.
452 NSMenuItem* item = [MenuWalker itemForKeyEquivalent:event.os_event
453 menu:[NSApp mainMenu]];
454
455 if (item && [item action] == @selector(commandDispatch:) && [item tag] > 0)
456 return [item tag];
457
458 // "Close window" doesn't use the |commandDispatch:| mechanism. Menu items
459 // that do not correspond to IDC_ constants need no special treatment however,
[email protected]06181422011-02-09 17:44:21460 // as they can't be blacklisted in |Browser::IsReservedCommandOrKey()| anyhow.
[email protected]7d791652010-12-01 16:34:49461 if (item && [item action] == @selector(performClose:))
462 return IDC_CLOSE_WINDOW;
463
464 // "Exit" doesn't use the |commandDispatch:| mechanism either.
465 if (item && [item action] == @selector(terminate:))
466 return IDC_EXIT;
467
468 // Look in secondary keyboard shortcuts.
469 NSUInteger modifiers = [event.os_event modifierFlags];
470 const bool cmdKey = (modifiers & NSCommandKeyMask) != 0;
471 const bool shiftKey = (modifiers & NSShiftKeyMask) != 0;
472 const bool cntrlKey = (modifiers & NSControlKeyMask) != 0;
473 const bool optKey = (modifiers & NSAlternateKeyMask) != 0;
474 const int keyCode = [event.os_event keyCode];
475 const unichar keyChar = KeyCharacterForEvent(event.os_event);
476
477 int cmdNum = CommandForWindowKeyboardShortcut(
478 cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
479 if (cmdNum != -1)
480 return cmdNum;
481
482 cmdNum = CommandForBrowserKeyboardShortcut(
483 cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
484 if (cmdNum != -1)
485 return cmdNum;
486
487 return -1;
488}
489
490bool BrowserWindowCocoa::HandleKeyboardEventInternal(NSEvent* event) {
491 ChromeEventProcessingWindow* event_window =
492 static_cast<ChromeEventProcessingWindow*>(window());
493 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
494
495 // Do not fire shortcuts on key up.
496 if ([event type] == NSKeyDown) {
497 // Send the event to the menu before sending it to the browser/window
498 // shortcut handling, so that if a user configures cmd-left to mean
499 // "previous tab", it takes precedence over the built-in "history back"
500 // binding. Other than that, the |-redispatchKeyEvent:| call would take care
501 // of invoking the original menu item shortcut as well.
502
503 if ([[NSApp mainMenu] performKeyEquivalent:event])
504 return true;
505
506 if ([event_window handleExtraBrowserKeyboardShortcut:event])
507 return true;
508
509 if ([event_window handleExtraWindowKeyboardShortcut:event])
510 return true;
511
512 if ([event_window handleDelayedWindowKeyboardShortcut:event])
513 return true;
514 }
515
516 return [event_window redispatchKeyEvent:event];
517}
518
519void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog(
[email protected]f847e6082011-03-24 00:08:26520 TabContentsWrapper* tab_contents) {
[email protected]7d791652010-12-01 16:34:49521 NOTIMPLEMENTED();
522}
523
524void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog(
525 Profile* profile, const Extension* app) {
526 NOTIMPLEMENTED();
527}
528
529void BrowserWindowCocoa::Cut() {
530 [NSApp sendAction:@selector(cut:) to:nil from:nil];
531}
532
533void BrowserWindowCocoa::Copy() {
534 [NSApp sendAction:@selector(copy:) to:nil from:nil];
535}
536
537void BrowserWindowCocoa::Paste() {
538 [NSApp sendAction:@selector(paste:) to:nil from:nil];
539}
540
541void BrowserWindowCocoa::ToggleTabStripMode() {
542 [controller_ toggleTabStripDisplayMode];
543}
544
545void BrowserWindowCocoa::OpenTabpose() {
546 [controller_ openTabpose];
547}
548
549void BrowserWindowCocoa::PrepareForInstant() {
550 // TODO: implement fade as done on windows.
551}
552
[email protected]e3690ed2011-03-25 20:25:14553void BrowserWindowCocoa::ShowInstant(TabContentsWrapper* preview) {
554 [controller_ showInstant:preview->tab_contents()];
[email protected]7d791652010-12-01 16:34:49555}
556
[email protected]1946c932010-12-15 00:07:38557void BrowserWindowCocoa::HideInstant(bool instant_is_active) {
[email protected]7d791652010-12-01 16:34:49558 [controller_ hideInstant];
[email protected]1946c932010-12-15 00:07:38559
560 // TODO: add support for |instant_is_active|.
[email protected]7d791652010-12-01 16:34:49561}
562
563gfx::Rect BrowserWindowCocoa::GetInstantBounds() {
564 // Flip coordinates based on the primary screen.
565 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
566 NSRect monitorFrame = [screen frame];
567 NSRect frame = [controller_ instantFrame];
568 gfx::Rect bounds(NSRectToCGRect(frame));
569 bounds.set_y(NSHeight(monitorFrame) - bounds.y() - bounds.height());
570 return bounds;
571}
572
[email protected]588300d2011-04-28 21:06:35573WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds(
574 const gfx::Rect& bounds) {
575 return NEW_POPUP;
576}
577
[email protected]7d791652010-12-01 16:34:49578void BrowserWindowCocoa::Observe(NotificationType type,
579 const NotificationSource& source,
580 const NotificationDetails& details) {
581 switch (type.value) {
582 // Only the key window gets a direct toggle from the menu.
583 // Other windows hear about it from the notification.
584 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED:
585 [controller_ updateBookmarkBarVisibilityWithAnimation:YES];
586 break;
587 case NotificationType::SIDEBAR_CHANGED:
588 UpdateSidebarForContents(
589 Details<SidebarContainer>(details)->tab_contents());
590 break;
591 default:
592 NOTREACHED(); // we don't ask for anything else!
593 break;
594 }
595}
596
597void BrowserWindowCocoa::DestroyBrowser() {
598 [controller_ destroyBrowser];
599
600 // at this point the controller is dead (autoreleased), so
601 // make sure we don't try to reference it any more.
602}
603
604NSWindow* BrowserWindowCocoa::window() const {
605 return [controller_ window];
606}
607
608void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) {
609 if (tab_contents == browser_->GetSelectedTabContents()) {
610 [controller_ updateSidebarForContents:tab_contents];
611 }
612}