blob: 2c63978f0eacceee23a3e2d62925a6410ba6bd53 [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"
[email protected]464f0012011-07-07 02:12:5122#import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h"
[email protected]7d791652010-12-01 16:34:4923#import "chrome/browser/ui/cocoa/browser_window_controller.h"
24#import "chrome/browser/ui/cocoa/bug_report_window_controller.h"
25#import "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
[email protected]fa8102292011-01-20 16:21:2326#import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h"
[email protected]7d791652010-12-01 16:34:4927#import "chrome/browser/ui/cocoa/download/download_shelf_controller.h"
[email protected]632983f2011-08-08 22:51:2428#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
[email protected]7d791652010-12-01 16:34:4929#import "chrome/browser/ui/cocoa/html_dialog_window_controller.h"
[email protected]7d791652010-12-01 16:34:4930#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
[email protected]a7d83ca2011-03-06 14:41:0731#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
[email protected]7d791652010-12-01 16:34:4932#include "chrome/browser/ui/cocoa/repost_form_warning_mac.h"
33#include "chrome/browser/ui/cocoa/restart_browser.h"
34#include "chrome/browser/ui/cocoa/status_bubble_mac.h"
35#include "chrome/browser/ui/cocoa/task_manager_mac.h"
36#import "chrome/browser/ui/cocoa/theme_install_bubble_view.h"
[email protected]8450c4f2011-01-19 22:16:2237#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
[email protected]6a3ec2312010-12-02 19:30:1938#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]432115822011-07-10 15:52:2739#include "chrome/common/chrome_notification_types.h"
[email protected]7d791652010-12-01 16:34:4940#include "chrome/common/pref_names.h"
[email protected]21f11682011-03-02 16:45:4241#include "content/browser/tab_contents/tab_contents.h"
[email protected]4dd57932011-03-17 06:06:1242#include "content/common/native_web_keyboard_event.h"
[email protected]7f070d42011-03-09 20:25:3243#include "content/common/notification_service.h"
[email protected]7d791652010-12-01 16:34:4944#include "grit/chromium_strings.h"
45#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1746#include "ui/base/l10n/l10n_util_mac.h"
[email protected]08397d52011-02-05 01:53:3847#include "ui/gfx/rect.h"
[email protected]7d791652010-12-01 16:34:4948
49BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
50 BrowserWindowController* controller,
51 NSWindow* window)
52 : browser_(browser),
53 controller_(controller),
54 confirm_close_factory_(browser) {
55 // This pref applies to all windows, so all must watch for it.
[email protected]432115822011-07-10 15:52:2756 registrar_.Add(this,
57 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
[email protected]7d791652010-12-01 16:34:4958 NotificationService::AllSources());
[email protected]432115822011-07-10 15:52:2759 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED,
[email protected]7d791652010-12-01 16:34:4960 NotificationService::AllSources());
61}
62
63BrowserWindowCocoa::~BrowserWindowCocoa() {
64}
65
66void BrowserWindowCocoa::Show() {
67 // The Browser associated with this browser window must become the active
68 // browser at the time |Show()| is called. This is the natural behaviour under
69 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:|
70 // until we return to the runloop. Therefore any calls to
71 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return
72 // the previous browser instead if we don't explicitly set it here.
73 BrowserList::SetLastActive(browser_);
74
75 [window() makeKeyAndOrderFront:controller_];
76}
77
[email protected]d4db6c702011-03-28 21:49:1478void BrowserWindowCocoa::ShowInactive() {
79 [window() orderFront:controller_];
80}
81
[email protected]7d791652010-12-01 16:34:4982void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) {
[email protected]ccb5895f2011-06-09 21:16:1483 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds];
84
[email protected]d479b8e22011-02-09 05:19:4985 SetFullscreen(false);
[email protected]ccb5895f2011-06-09 21:16:1486 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0,
87 real_bounds.width(),
88 real_bounds.height());
[email protected]7d791652010-12-01 16:34:4989 // Flip coordinates based on the primary screen.
90 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
91 cocoa_bounds.origin.y =
[email protected]ccb5895f2011-06-09 21:16:1492 [screen frame].size.height - real_bounds.height() - real_bounds.y();
[email protected]7d791652010-12-01 16:34:4993
94 [window() setFrame:cocoa_bounds display:YES];
95}
96
97// Callers assume that this doesn't immediately delete the Browser object.
98// The controller implementing the window delegate methods called from
99// |-performClose:| must take precautions to ensure that.
100void BrowserWindowCocoa::Close() {
101 // If there is an overlay window, we contain a tab being dragged between
102 // windows. Don't hide the window as it makes the UI extra confused. We can
103 // still close the window, as that will happen when the drag completes.
104 if ([controller_ overlayWindow]) {
105 [controller_ deferPerformClose];
106 } else {
107 // Make sure we hide the window immediately. Even though performClose:
108 // calls orderOut: eventually, it leaves the window on-screen long enough
109 // that we start to see tabs shutting down. http://crbug.com/23959
110 // TODO(viettrungluu): This is kind of bad, since |-performClose:| calls
111 // |-windowShouldClose:| (on its delegate, which is probably the
112 // controller) which may return |NO| causing the window to not be closed,
113 // thereby leaving a hidden window. In fact, our window-closing procedure
114 // involves a (indirect) recursion on |-performClose:|, which is also bad.
115 [window() orderOut:controller_];
116 [window() performClose:controller_];
117 }
118}
119
120void BrowserWindowCocoa::Activate() {
121 [controller_ activate];
122}
123
124void BrowserWindowCocoa::Deactivate() {
125 // TODO(jcivelli): http://crbug.com/51364 Implement me.
126 NOTIMPLEMENTED();
127}
128
129void BrowserWindowCocoa::FlashFrame() {
130 [NSApp requestUserAttention:NSInformationalRequest];
131}
132
133bool BrowserWindowCocoa::IsActive() const {
134 return [window() isKeyWindow];
135}
136
137gfx::NativeWindow BrowserWindowCocoa::GetNativeHandle() {
138 return window();
139}
140
141BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() {
142 return NULL;
143}
144
145StatusBubble* BrowserWindowCocoa::GetStatusBubble() {
146 return [controller_ statusBubble];
147}
148
[email protected]c9bd2e82011-04-15 23:28:19149void BrowserWindowCocoa::ToolbarSizeChanged(bool is_animating) {
[email protected]7d791652010-12-01 16:34:49150 // According to beng, this is an ugly method that comes from the days when the
151 // download shelf was a ChromeView attached to the TabContents, and as its
152 // size changed via animation it notified through TCD/etc to the browser view
153 // to relayout for each tick of the animation. We don't need anything of the
154 // sort on Mac.
155}
156
157void BrowserWindowCocoa::UpdateTitleBar() {
158 NSString* newTitle =
159 base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab());
160
161 // Work around Cocoa bug: if a window changes title during the tracking of the
162 // Window menu it doesn't display well and the constant re-sorting of the list
163 // makes it difficult for the user to pick the desired window. Delay window
164 // title updates until the default run-loop mode.
165
166 if (pending_window_title_.get())
167 [[NSRunLoop currentRunLoop]
168 cancelPerformSelector:@selector(setTitle:)
169 target:window()
170 argument:pending_window_title_.get()];
171
172 pending_window_title_.reset([newTitle copy]);
173 [[NSRunLoop currentRunLoop]
174 performSelector:@selector(setTitle:)
175 target:window()
176 argument:newTitle
177 order:0
178 modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
179}
180
[email protected]09b29342011-06-24 19:18:48181void BrowserWindowCocoa::BookmarkBarStateChanged(
182 BookmarkBar::AnimateChangeType change_type) {
183 // TODO: route changes to state through this.
[email protected]7d791652010-12-01 16:34:49184}
185
186void BrowserWindowCocoa::UpdateDevTools() {
187 [controller_ updateDevToolsForContents:
188 browser_->GetSelectedTabContents()];
189}
190
191void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) {
192 // Do nothing on Mac.
193}
194
195void BrowserWindowCocoa::SetStarredState(bool is_starred) {
196 [controller_ setStarredState:is_starred ? YES : NO];
197}
198
199gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const {
200 // Flip coordinates based on the primary screen.
201 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
202 NSRect frame = [controller_ regularWindowFrame];
203 gfx::Rect bounds(frame.origin.x, 0, frame.size.width, frame.size.height);
204 bounds.set_y([screen frame].size.height - frame.origin.y - frame.size.height);
205 return bounds;
206}
207
[email protected]d479b8e22011-02-09 05:19:49208gfx::Rect BrowserWindowCocoa::GetBounds() const {
209 return GetRestoredBounds();
210}
211
[email protected]7d791652010-12-01 16:34:49212bool BrowserWindowCocoa::IsMaximized() const {
213 return [window() isZoomed];
214}
215
216void BrowserWindowCocoa::SetFullscreen(bool fullscreen) {
217 [controller_ setFullscreen:fullscreen];
218}
219
220bool BrowserWindowCocoa::IsFullscreen() const {
221 return !![controller_ isFullscreen];
222}
223
224bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const {
225 return false;
226}
227
228void BrowserWindowCocoa::ConfirmAddSearchProvider(
229 const TemplateURL* template_url,
230 Profile* profile) {
[email protected]464f0012011-07-07 02:12:51231 // The controller will release itself when the window closes.
232 EditSearchEngineCocoaController* editor =
233 [[EditSearchEngineCocoaController alloc] initWithProfile:profile
234 delegate:NULL
235 templateURL:template_url];
236 [NSApp beginSheet:[editor window]
237 modalForWindow:window()
238 modalDelegate:controller_
239 didEndSelector:@selector(sheetDidEnd:returnCode:context:)
240 contextInfo:NULL];
[email protected]7d791652010-12-01 16:34:49241}
242
243LocationBar* BrowserWindowCocoa::GetLocationBar() const {
244 return [controller_ locationBarBridge];
245}
246
247void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) {
248 [controller_ focusLocationBar:select_all ? YES : NO];
249}
250
251void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) {
252 [controller_ setIsLoading:is_loading force:force];
253}
254
255void BrowserWindowCocoa::UpdateToolbar(TabContentsWrapper* contents,
256 bool should_restore_state) {
257 [controller_ updateToolbarWithContents:contents->tab_contents()
258 shouldRestoreState:should_restore_state ? YES : NO];
259}
260
261void BrowserWindowCocoa::FocusToolbar() {
262 // Not needed on the Mac.
263}
264
265void BrowserWindowCocoa::FocusAppMenu() {
266 // Chrome uses the standard Mac OS X menu bar, so this isn't needed.
267}
268
269void BrowserWindowCocoa::RotatePaneFocus(bool forwards) {
270 // Not needed on the Mac.
271}
272
273void BrowserWindowCocoa::FocusBookmarksToolbar() {
274 // Not needed on the Mac.
275}
276
277void BrowserWindowCocoa::FocusChromeOSStatus() {
278 // Not needed on the Mac.
279}
280
281bool BrowserWindowCocoa::IsBookmarkBarVisible() const {
[email protected]a007e732011-08-05 13:32:19282 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
[email protected]7d791652010-12-01 16:34:49283}
284
285bool BrowserWindowCocoa::IsBookmarkBarAnimating() const {
286 return [controller_ isBookmarkBarAnimating];
287}
288
[email protected]95bf8a5b2010-12-22 16:04:07289bool BrowserWindowCocoa::IsTabStripEditable() const {
290 return ![controller_ isDragSessionActive];
291}
292
[email protected]7d791652010-12-01 16:34:49293bool BrowserWindowCocoa::IsToolbarVisible() const {
294 return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
295 browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
296}
297
298// This is called from Browser, which in turn is called directly from
299// a menu option. All we do here is set a preference. The act of
300// setting the preference sends notifications to all windows who then
301// know what to do.
302void BrowserWindowCocoa::ToggleBookmarkBar() {
303 bookmark_utils::ToggleWhenVisible(browser_->profile());
304}
305
306void BrowserWindowCocoa::AddFindBar(
307 FindBarCocoaController* find_bar_cocoa_controller) {
[email protected]632983f2011-08-08 22:51:24308 [controller_ addFindBar:find_bar_cocoa_controller];
[email protected]7d791652010-12-01 16:34:49309}
310
[email protected]4c6b474b72011-02-24 21:35:21311void BrowserWindowCocoa::ShowAboutChromeDialog() {
[email protected]287b90602011-03-02 22:43:27312 // Go through AppController's implementation to bring up the branded panel.
313 [[NSApp delegate] orderFrontStandardAboutPanel:nil];
[email protected]7d791652010-12-01 16:34:49314}
315
316void BrowserWindowCocoa::ShowUpdateChromeDialog() {
[email protected]678dae82011-02-11 20:03:08317 restart_browser::RequestRestart(window());
[email protected]7d791652010-12-01 16:34:49318}
319
320void BrowserWindowCocoa::ShowTaskManager() {
[email protected]adb6a84d2011-02-07 16:58:40321 TaskManagerMac::Show(false);
322}
323
324void BrowserWindowCocoa::ShowBackgroundPages() {
325 TaskManagerMac::Show(true);
[email protected]7d791652010-12-01 16:34:49326}
327
328void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
329 bool already_bookmarked) {
330 [controller_ showBookmarkBubbleForURL:url
331 alreadyBookmarked:(already_bookmarked ? YES : NO)];
332}
333
334bool BrowserWindowCocoa::IsDownloadShelfVisible() const {
335 return [controller_ isDownloadShelfVisible] != NO;
336}
337
338DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
339 DownloadShelfController* shelfController = [controller_ downloadShelf];
340 return [shelfController bridge];
341}
342
[email protected]7d791652010-12-01 16:34:49343void BrowserWindowCocoa::ShowRepostFormWarningDialog(
344 TabContents* tab_contents) {
345 RepostFormWarningMac::Create(GetNativeHandle(), tab_contents);
346}
347
[email protected]7d791652010-12-01 16:34:49348void BrowserWindowCocoa::ShowCollectedCookiesDialog(TabContents* tab_contents) {
349 // Deletes itself on close.
350 new CollectedCookiesMac(GetNativeHandle(), tab_contents);
351}
352
[email protected]7d791652010-12-01 16:34:49353void BrowserWindowCocoa::ShowThemeInstallBubble() {
354 ThemeInstallBubbleView::Show(window());
355}
356
357// We allow closing the window here since the real quit decision on Mac is made
358// in [AppController quit:].
359void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() {
360 // Call InProgressDownloadResponse asynchronously to avoid a crash when the
361 // browser window is closed here (http://crbug.com/44454).
362 MessageLoop::current()->PostTask(
363 FROM_HERE,
364 confirm_close_factory_.NewRunnableMethod(
365 &Browser::InProgressDownloadResponse,
366 true));
367}
368
369void BrowserWindowCocoa::ShowHTMLDialog(HtmlDialogUIDelegate* delegate,
370 gfx::NativeWindow parent_window) {
371 [HtmlDialogWindowController showHtmlDialog:delegate
372 profile:browser_->profile()];
373}
374
375void BrowserWindowCocoa::UserChangedTheme() {
376 [controller_ userChangedTheme];
377}
378
379int BrowserWindowCocoa::GetExtraRenderViewHeight() const {
380 // Currently this is only used on linux.
381 return 0;
382}
383
384void BrowserWindowCocoa::TabContentsFocused(TabContents* tab_contents) {
385 NOTIMPLEMENTED();
386}
387
388void BrowserWindowCocoa::ShowPageInfo(Profile* profile,
389 const GURL& url,
390 const NavigationEntry::SSLStatus& ssl,
391 bool show_history) {
392 browser::ShowPageInfoBubble(window(), profile, url, ssl, show_history);
393}
394
395void BrowserWindowCocoa::ShowAppMenu() {
396 // No-op. Mac doesn't support showing the menus via alt keys.
397}
398
399bool BrowserWindowCocoa::PreHandleKeyboardEvent(
400 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
401 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
402 return false;
403
404 DCHECK(event.os_event != NULL);
405 int id = GetCommandId(event);
406 if (id == -1)
407 return false;
408
[email protected]06181422011-02-09 17:44:21409 if (browser_->IsReservedCommandOrKey(id, event))
[email protected]7d791652010-12-01 16:34:49410 return HandleKeyboardEventInternal(event.os_event);
411
412 DCHECK(is_keyboard_shortcut != NULL);
413 *is_keyboard_shortcut = true;
414
415 return false;
416}
417
418void BrowserWindowCocoa::HandleKeyboardEvent(
419 const NativeWebKeyboardEvent& event) {
420 if (event.skip_in_browser || event.type == NativeWebKeyboardEvent::Char)
421 return;
422
423 DCHECK(event.os_event != NULL);
424 HandleKeyboardEventInternal(event.os_event);
425}
426
427@interface MenuWalker : NSObject
428+ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
429 menu:(NSMenu*)menu;
430@end
431
432@implementation MenuWalker
433+ (NSMenuItem*)itemForKeyEquivalent:(NSEvent*)key
434 menu:(NSMenu*)menu {
435 NSMenuItem* result = nil;
436
437 for (NSMenuItem *item in [menu itemArray]) {
438 NSMenu* submenu = [item submenu];
439 if (submenu) {
440 if (submenu != [NSApp servicesMenu])
441 result = [self itemForKeyEquivalent:key
442 menu:submenu];
[email protected]0f72a2dc2010-12-06 19:40:23443 } else if ([item cr_firesForKeyEventIfEnabled:key]) {
[email protected]7d791652010-12-01 16:34:49444 result = item;
445 }
446
447 if (result)
448 break;
449 }
450
451 return result;
452}
453@end
454
455int BrowserWindowCocoa::GetCommandId(const NativeWebKeyboardEvent& event) {
456 if ([event.os_event type] != NSKeyDown)
457 return -1;
458
459 // Look in menu.
460 NSMenuItem* item = [MenuWalker itemForKeyEquivalent:event.os_event
461 menu:[NSApp mainMenu]];
462
463 if (item && [item action] == @selector(commandDispatch:) && [item tag] > 0)
464 return [item tag];
465
466 // "Close window" doesn't use the |commandDispatch:| mechanism. Menu items
467 // that do not correspond to IDC_ constants need no special treatment however,
[email protected]06181422011-02-09 17:44:21468 // as they can't be blacklisted in |Browser::IsReservedCommandOrKey()| anyhow.
[email protected]7d791652010-12-01 16:34:49469 if (item && [item action] == @selector(performClose:))
470 return IDC_CLOSE_WINDOW;
471
472 // "Exit" doesn't use the |commandDispatch:| mechanism either.
473 if (item && [item action] == @selector(terminate:))
474 return IDC_EXIT;
475
476 // Look in secondary keyboard shortcuts.
477 NSUInteger modifiers = [event.os_event modifierFlags];
478 const bool cmdKey = (modifiers & NSCommandKeyMask) != 0;
479 const bool shiftKey = (modifiers & NSShiftKeyMask) != 0;
480 const bool cntrlKey = (modifiers & NSControlKeyMask) != 0;
481 const bool optKey = (modifiers & NSAlternateKeyMask) != 0;
482 const int keyCode = [event.os_event keyCode];
483 const unichar keyChar = KeyCharacterForEvent(event.os_event);
484
485 int cmdNum = CommandForWindowKeyboardShortcut(
486 cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
487 if (cmdNum != -1)
488 return cmdNum;
489
490 cmdNum = CommandForBrowserKeyboardShortcut(
491 cmdKey, shiftKey, cntrlKey, optKey, keyCode, keyChar);
492 if (cmdNum != -1)
493 return cmdNum;
494
495 return -1;
496}
497
498bool BrowserWindowCocoa::HandleKeyboardEventInternal(NSEvent* event) {
499 ChromeEventProcessingWindow* event_window =
500 static_cast<ChromeEventProcessingWindow*>(window());
501 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]);
502
503 // Do not fire shortcuts on key up.
504 if ([event type] == NSKeyDown) {
505 // Send the event to the menu before sending it to the browser/window
506 // shortcut handling, so that if a user configures cmd-left to mean
507 // "previous tab", it takes precedence over the built-in "history back"
508 // binding. Other than that, the |-redispatchKeyEvent:| call would take care
509 // of invoking the original menu item shortcut as well.
510
511 if ([[NSApp mainMenu] performKeyEquivalent:event])
512 return true;
513
514 if ([event_window handleExtraBrowserKeyboardShortcut:event])
515 return true;
516
517 if ([event_window handleExtraWindowKeyboardShortcut:event])
518 return true;
519
520 if ([event_window handleDelayedWindowKeyboardShortcut:event])
521 return true;
522 }
523
524 return [event_window redispatchKeyEvent:event];
525}
526
527void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog(
[email protected]f847e6082011-03-24 00:08:26528 TabContentsWrapper* tab_contents) {
[email protected]7d791652010-12-01 16:34:49529 NOTIMPLEMENTED();
530}
531
532void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog(
533 Profile* profile, const Extension* app) {
534 NOTIMPLEMENTED();
535}
536
537void BrowserWindowCocoa::Cut() {
538 [NSApp sendAction:@selector(cut:) to:nil from:nil];
539}
540
541void BrowserWindowCocoa::Copy() {
542 [NSApp sendAction:@selector(copy:) to:nil from:nil];
543}
544
545void BrowserWindowCocoa::Paste() {
546 [NSApp sendAction:@selector(paste:) to:nil from:nil];
547}
548
549void BrowserWindowCocoa::ToggleTabStripMode() {
550 [controller_ toggleTabStripDisplayMode];
551}
552
553void BrowserWindowCocoa::OpenTabpose() {
554 [controller_ openTabpose];
555}
556
[email protected]d3766932011-08-04 22:18:23557void BrowserWindowCocoa::SetPresentationMode(bool presentation_mode) {
558 [controller_ setPresentationMode:presentation_mode];
559}
560
561bool BrowserWindowCocoa::InPresentationMode() {
562 return [controller_ inPresentationMode];
563}
564
[email protected]7d791652010-12-01 16:34:49565void BrowserWindowCocoa::PrepareForInstant() {
566 // TODO: implement fade as done on windows.
567}
568
[email protected]e3690ed2011-03-25 20:25:14569void BrowserWindowCocoa::ShowInstant(TabContentsWrapper* preview) {
570 [controller_ showInstant:preview->tab_contents()];
[email protected]7d791652010-12-01 16:34:49571}
572
[email protected]1946c932010-12-15 00:07:38573void BrowserWindowCocoa::HideInstant(bool instant_is_active) {
[email protected]7d791652010-12-01 16:34:49574 [controller_ hideInstant];
[email protected]1946c932010-12-15 00:07:38575
576 // TODO: add support for |instant_is_active|.
[email protected]7d791652010-12-01 16:34:49577}
578
579gfx::Rect BrowserWindowCocoa::GetInstantBounds() {
580 // Flip coordinates based on the primary screen.
581 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
582 NSRect monitorFrame = [screen frame];
583 NSRect frame = [controller_ instantFrame];
584 gfx::Rect bounds(NSRectToCGRect(frame));
585 bounds.set_y(NSHeight(monitorFrame) - bounds.y() - bounds.height());
586 return bounds;
587}
588
[email protected]588300d2011-04-28 21:06:35589WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds(
590 const gfx::Rect& bounds) {
591 return NEW_POPUP;
592}
593
[email protected]632983f2011-08-08 22:51:24594FindBar* BrowserWindowCocoa::CreateFindBar() {
595 // We could push the AddFindBar() call into the FindBarBridge
596 // constructor or the FindBarCocoaController init, but that makes
597 // unit testing difficult, since we would also require a
598 // BrowserWindow object.
599 FindBarBridge* bridge = new FindBarBridge();
600 AddFindBar(bridge->find_bar_cocoa_controller());
601 return bridge;
602}
603
[email protected]432115822011-07-10 15:52:27604void BrowserWindowCocoa::Observe(int type,
[email protected]7d791652010-12-01 16:34:49605 const NotificationSource& source,
606 const NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27607 switch (type) {
[email protected]7d791652010-12-01 16:34:49608 // Only the key window gets a direct toggle from the menu.
609 // Other windows hear about it from the notification.
[email protected]432115822011-07-10 15:52:27610 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED:
[email protected]7d791652010-12-01 16:34:49611 [controller_ updateBookmarkBarVisibilityWithAnimation:YES];
612 break;
[email protected]432115822011-07-10 15:52:27613 case chrome::NOTIFICATION_SIDEBAR_CHANGED:
[email protected]7d791652010-12-01 16:34:49614 UpdateSidebarForContents(
615 Details<SidebarContainer>(details)->tab_contents());
616 break;
617 default:
618 NOTREACHED(); // we don't ask for anything else!
619 break;
620 }
621}
622
623void BrowserWindowCocoa::DestroyBrowser() {
624 [controller_ destroyBrowser];
625
626 // at this point the controller is dead (autoreleased), so
627 // make sure we don't try to reference it any more.
628}
629
630NSWindow* BrowserWindowCocoa::window() const {
631 return [controller_ window];
632}
633
634void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) {
635 if (tab_contents == browser_->GetSelectedTabContents()) {
636 [controller_ updateSidebarForContents:tab_contents];
637 }
638}