blob: 4240680a0436875f4a5a221cdf951b10f3a53a2f [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"
[email protected]7d791652010-12-01 16:34:4914#include "chrome/browser/page_info_window.h"
15#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]464f0012011-07-07 02:12:5121#import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h"
[email protected]7d791652010-12-01 16:34:4922#import "chrome/browser/ui/cocoa/browser_window_controller.h"
[email protected]3a1381d2011-08-26 18:12:1323#import "chrome/browser/ui/cocoa/browser_window_utils.h"
[email protected]7d791652010-12-01 16:34:4924#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]632983f2011-08-08 22:51:2427#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
[email protected]7d791652010-12-01 16:34:4928#import "chrome/browser/ui/cocoa/html_dialog_window_controller.h"
[email protected]7d791652010-12-01 16:34:4929#import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h"
[email protected]a7d83ca2011-03-06 14:41:0730#import "chrome/browser/ui/cocoa/nsmenuitem_additions.h"
[email protected]7d791652010-12-01 16:34:4931#include "chrome/browser/ui/cocoa/repost_form_warning_mac.h"
32#include "chrome/browser/ui/cocoa/restart_browser.h"
33#include "chrome/browser/ui/cocoa/status_bubble_mac.h"
34#include "chrome/browser/ui/cocoa/task_manager_mac.h"
35#import "chrome/browser/ui/cocoa/theme_install_bubble_view.h"
[email protected]8450c4f2011-01-19 22:16:2236#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
[email protected]6a3ec2312010-12-02 19:30:1937#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]432115822011-07-10 15:52:2738#include "chrome/common/chrome_notification_types.h"
[email protected]7d791652010-12-01 16:34:4939#include "chrome/common/pref_names.h"
[email protected]21f11682011-03-02 16:45:4240#include "content/browser/tab_contents/tab_contents.h"
[email protected]4dd57932011-03-17 06:06:1241#include "content/common/native_web_keyboard_event.h"
[email protected]7f070d42011-03-09 20:25:3242#include "content/common/notification_service.h"
[email protected]7d791652010-12-01 16:34:4943#include "grit/chromium_strings.h"
44#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1745#include "ui/base/l10n/l10n_util_mac.h"
[email protected]08397d52011-02-05 01:53:3846#include "ui/gfx/rect.h"
[email protected]7d791652010-12-01 16:34:4947
[email protected]400eaf82011-08-22 15:47:3948// Replicate specific 10.7 SDK declarations for building with prior SDKs.
49#if !defined(MAC_OS_X_VERSION_10_7) || \
50 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
51
52enum {
53 NSWindowAnimationBehaviorDefault = 0,
54 NSWindowAnimationBehaviorNone = 2,
55 NSWindowAnimationBehaviorDocumentWindow = 3,
56 NSWindowAnimationBehaviorUtilityWindow = 4,
57 NSWindowAnimationBehaviorAlertPanel = 5
58};
59typedef NSInteger NSWindowAnimationBehavior;
60
61@interface NSWindow (LionSDKDeclarations)
62- (NSWindowAnimationBehavior)animationBehavior;
63- (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior;
64@end
65
66#endif // MAC_OS_X_VERSION_10_7
67
[email protected]7d791652010-12-01 16:34:4968BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
[email protected]400eaf82011-08-22 15:47:3969 BrowserWindowController* controller)
[email protected]7d791652010-12-01 16:34:4970 : browser_(browser),
71 controller_(controller),
72 confirm_close_factory_(browser) {
[email protected]0b4e22322011-08-11 19:50:3473 // Listen for bookmark bar visibility changes and set the initial state; we
74 // need to listen to all profiles because of normal profile/incognito issues.
[email protected]432115822011-07-10 15:52:2775 registrar_.Add(this,
76 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
[email protected]0b4e22322011-08-11 19:50:3477 NotificationService::AllBrowserContextsAndSources());
[email protected]432115822011-07-10 15:52:2778 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED,
[email protected]0b4e22322011-08-11 19:50:3479 Source<SidebarManager>(SidebarManager::GetInstance()));
[email protected]cfecf9432011-09-27 17:10:0880
81 initial_show_state_ = browser_->GetSavedWindowShowState();
[email protected]7d791652010-12-01 16:34:4982}
83
84BrowserWindowCocoa::~BrowserWindowCocoa() {
85}
86
87void BrowserWindowCocoa::Show() {
88 // The Browser associated with this browser window must become the active
89 // browser at the time |Show()| is called. This is the natural behaviour under
90 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:|
91 // until we return to the runloop. Therefore any calls to
92 // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return
93 // the previous browser instead if we don't explicitly set it here.
94 BrowserList::SetLastActive(browser_);
95
[email protected]8bc061f2011-08-31 22:46:2396 bool is_session_restore = browser_->is_session_restore();
[email protected]b5cc93c2011-09-02 02:33:4297 NSWindowAnimationBehavior saved_animation_behavior =
98 NSWindowAnimationBehaviorDefault;
[email protected]8bc061f2011-08-31 22:46:2399 bool did_save_animation_behavior = false;
100 // Turn off swishing when restoring windows.
101 if (is_session_restore &&
102 [window() respondsToSelector:@selector(animationBehavior)] &&
103 [window() respondsToSelector:@selector(setAnimationBehavior:)]) {
104 did_save_animation_behavior = true;
105 saved_animation_behavior = [window() animationBehavior];
106 [window() setAnimationBehavior:NSWindowAnimationBehaviorNone];
107 }
[email protected]400eaf82011-08-22 15:47:39108
[email protected]8bc061f2011-08-31 22:46:23109 [window() makeKeyAndOrderFront:controller_];
[email protected]400eaf82011-08-22 15:47:39110
[email protected]8bc061f2011-08-31 22:46:23111 // When creating windows from nibs it is necessary to |makeKeyAndOrderFront:|
112 // prior to |orderOut:| then |miniaturize:| when restoring windows in the
113 // minimized state.
[email protected]cfecf9432011-09-27 17:10:08114 if (initial_show_state_ == ui::SHOW_STATE_MINIMIZED) {
[email protected]400eaf82011-08-22 15:47:39115 [window() orderOut:controller_];
116 [window() miniaturize:controller_];
[email protected]400eaf82011-08-22 15:47:39117 }
[email protected]cfecf9432011-09-27 17:10:08118 initial_show_state_ = ui::SHOW_STATE_DEFAULT;
[email protected]8bc061f2011-08-31 22:46:23119
120 // Restore window animation behavior.
121 if (did_save_animation_behavior)
122 [window() setAnimationBehavior:saved_animation_behavior];
[email protected]2f516c792011-09-19 22:22:09123
124 browser_->OnWindowDidShow();
[email protected]7d791652010-12-01 16:34:49125}
126
[email protected]d4db6c702011-03-28 21:49:14127void BrowserWindowCocoa::ShowInactive() {
[email protected]400eaf82011-08-22 15:47:39128 [window() orderFront:controller_];
[email protected]d4db6c702011-03-28 21:49:14129}
130
[email protected]7d791652010-12-01 16:34:49131void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) {
[email protected]ccb5895f2011-06-09 21:16:14132 gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds];
133
[email protected]d479b8e22011-02-09 05:19:49134 SetFullscreen(false);
[email protected]ccb5895f2011-06-09 21:16:14135 NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0,
136 real_bounds.width(),
137 real_bounds.height());
[email protected]7d791652010-12-01 16:34:49138 // Flip coordinates based on the primary screen.
139 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
140 cocoa_bounds.origin.y =
[email protected]ccb5895f2011-06-09 21:16:14141 [screen frame].size.height - real_bounds.height() - real_bounds.y();
[email protected]7d791652010-12-01 16:34:49142
143 [window() setFrame:cocoa_bounds display:YES];
144}
145
146// Callers assume that this doesn't immediately delete the Browser object.
147// The controller implementing the window delegate methods called from
148// |-performClose:| must take precautions to ensure that.
149void BrowserWindowCocoa::Close() {
150 // If there is an overlay window, we contain a tab being dragged between
151 // windows. Don't hide the window as it makes the UI extra confused. We can
152 // still close the window, as that will happen when the drag completes.
153 if ([controller_ overlayWindow]) {
154 [controller_ deferPerformClose];
155 } else {
156 // Make sure we hide the window immediately. Even though performClose:
157 // calls orderOut: eventually, it leaves the window on-screen long enough
158 // that we start to see tabs shutting down. http://crbug.com/23959
159 // TODO(viettrungluu): This is kind of bad, since |-performClose:| calls
160 // |-windowShouldClose:| (on its delegate, which is probably the
161 // controller) which may return |NO| causing the window to not be closed,
162 // thereby leaving a hidden window. In fact, our window-closing procedure
163 // involves a (indirect) recursion on |-performClose:|, which is also bad.
164 [window() orderOut:controller_];
165 [window() performClose:controller_];
166 }
167}
168
169void BrowserWindowCocoa::Activate() {
170 [controller_ activate];
171}
172
173void BrowserWindowCocoa::Deactivate() {
174 // TODO(jcivelli): http://crbug.com/51364 Implement me.
175 NOTIMPLEMENTED();
176}
177
178void BrowserWindowCocoa::FlashFrame() {
179 [NSApp requestUserAttention:NSInformationalRequest];
180}
181
182bool BrowserWindowCocoa::IsActive() const {
183 return [window() isKeyWindow];
184}
185
186gfx::NativeWindow BrowserWindowCocoa::GetNativeHandle() {
187 return window();
188}
189
190BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() {
191 return NULL;
192}
193
194StatusBubble* BrowserWindowCocoa::GetStatusBubble() {
195 return [controller_ statusBubble];
196}
197
[email protected]c9bd2e82011-04-15 23:28:19198void BrowserWindowCocoa::ToolbarSizeChanged(bool is_animating) {
[email protected]7d791652010-12-01 16:34:49199 // According to beng, this is an ugly method that comes from the days when the
200 // download shelf was a ChromeView attached to the TabContents, and as its
201 // size changed via animation it notified through TCD/etc to the browser view
202 // to relayout for each tick of the animation. We don't need anything of the
203 // sort on Mac.
204}
205
206void BrowserWindowCocoa::UpdateTitleBar() {
207 NSString* newTitle =
208 base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab());
209
[email protected]d78e615e2011-09-06 21:46:03210 pending_window_title_.reset(
211 [BrowserWindowUtils scheduleReplaceOldTitle:pending_window_title_.get()
212 withNewTitle:newTitle
213 forWindow:window()]);
[email protected]7d791652010-12-01 16:34:49214}
215
[email protected]09b29342011-06-24 19:18:48216void BrowserWindowCocoa::BookmarkBarStateChanged(
217 BookmarkBar::AnimateChangeType change_type) {
218 // TODO: route changes to state through this.
[email protected]7d791652010-12-01 16:34:49219}
220
221void BrowserWindowCocoa::UpdateDevTools() {
222 [controller_ updateDevToolsForContents:
223 browser_->GetSelectedTabContents()];
224}
225
226void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) {
227 // Do nothing on Mac.
228}
229
230void BrowserWindowCocoa::SetStarredState(bool is_starred) {
231 [controller_ setStarredState:is_starred ? YES : NO];
232}
233
234gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const {
235 // Flip coordinates based on the primary screen.
236 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
237 NSRect frame = [controller_ regularWindowFrame];
238 gfx::Rect bounds(frame.origin.x, 0, frame.size.width, frame.size.height);
239 bounds.set_y([screen frame].size.height - frame.origin.y - frame.size.height);
240 return bounds;
241}
242
[email protected]d479b8e22011-02-09 05:19:49243gfx::Rect BrowserWindowCocoa::GetBounds() const {
244 return GetRestoredBounds();
245}
246
[email protected]7d791652010-12-01 16:34:49247bool BrowserWindowCocoa::IsMaximized() const {
248 return [window() isZoomed];
249}
250
[email protected]400eaf82011-08-22 15:47:39251bool BrowserWindowCocoa::IsMinimized() const {
252 return [window() isMiniaturized];
253}
254
[email protected]7d791652010-12-01 16:34:49255void BrowserWindowCocoa::SetFullscreen(bool fullscreen) {
256 [controller_ setFullscreen:fullscreen];
257}
258
259bool BrowserWindowCocoa::IsFullscreen() const {
260 return !![controller_ isFullscreen];
261}
262
263bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const {
264 return false;
265}
266
267void BrowserWindowCocoa::ConfirmAddSearchProvider(
268 const TemplateURL* template_url,
269 Profile* profile) {
[email protected]464f0012011-07-07 02:12:51270 // The controller will release itself when the window closes.
271 EditSearchEngineCocoaController* editor =
272 [[EditSearchEngineCocoaController alloc] initWithProfile:profile
273 delegate:NULL
274 templateURL:template_url];
275 [NSApp beginSheet:[editor window]
276 modalForWindow:window()
277 modalDelegate:controller_
278 didEndSelector:@selector(sheetDidEnd:returnCode:context:)
279 contextInfo:NULL];
[email protected]7d791652010-12-01 16:34:49280}
281
282LocationBar* BrowserWindowCocoa::GetLocationBar() const {
283 return [controller_ locationBarBridge];
284}
285
286void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) {
287 [controller_ focusLocationBar:select_all ? YES : NO];
288}
289
290void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) {
291 [controller_ setIsLoading:is_loading force:force];
292}
293
294void BrowserWindowCocoa::UpdateToolbar(TabContentsWrapper* contents,
295 bool should_restore_state) {
296 [controller_ updateToolbarWithContents:contents->tab_contents()
297 shouldRestoreState:should_restore_state ? YES : NO];
298}
299
300void BrowserWindowCocoa::FocusToolbar() {
301 // Not needed on the Mac.
302}
303
304void BrowserWindowCocoa::FocusAppMenu() {
305 // Chrome uses the standard Mac OS X menu bar, so this isn't needed.
306}
307
308void BrowserWindowCocoa::RotatePaneFocus(bool forwards) {
309 // Not needed on the Mac.
310}
311
312void BrowserWindowCocoa::FocusBookmarksToolbar() {
313 // Not needed on the Mac.
314}
315
316void BrowserWindowCocoa::FocusChromeOSStatus() {
317 // Not needed on the Mac.
318}
319
320bool BrowserWindowCocoa::IsBookmarkBarVisible() const {
[email protected]a007e732011-08-05 13:32:19321 return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
[email protected]7d791652010-12-01 16:34:49322}
323
324bool BrowserWindowCocoa::IsBookmarkBarAnimating() const {
325 return [controller_ isBookmarkBarAnimating];
326}
327
[email protected]95bf8a5b2010-12-22 16:04:07328bool BrowserWindowCocoa::IsTabStripEditable() const {
329 return ![controller_ isDragSessionActive];
330}
331
[email protected]7d791652010-12-01 16:34:49332bool BrowserWindowCocoa::IsToolbarVisible() const {
333 return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) ||
334 browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
335}
336
337// This is called from Browser, which in turn is called directly from
338// a menu option. All we do here is set a preference. The act of
339// setting the preference sends notifications to all windows who then
340// know what to do.
341void BrowserWindowCocoa::ToggleBookmarkBar() {
342 bookmark_utils::ToggleWhenVisible(browser_->profile());
343}
344
345void BrowserWindowCocoa::AddFindBar(
346 FindBarCocoaController* find_bar_cocoa_controller) {
[email protected]632983f2011-08-08 22:51:24347 [controller_ addFindBar:find_bar_cocoa_controller];
[email protected]7d791652010-12-01 16:34:49348}
349
[email protected]4c6b474b72011-02-24 21:35:21350void BrowserWindowCocoa::ShowAboutChromeDialog() {
[email protected]287b90602011-03-02 22:43:27351 // Go through AppController's implementation to bring up the branded panel.
352 [[NSApp delegate] orderFrontStandardAboutPanel:nil];
[email protected]7d791652010-12-01 16:34:49353}
354
355void BrowserWindowCocoa::ShowUpdateChromeDialog() {
[email protected]678dae82011-02-11 20:03:08356 restart_browser::RequestRestart(window());
[email protected]7d791652010-12-01 16:34:49357}
358
359void BrowserWindowCocoa::ShowTaskManager() {
[email protected]adb6a84d2011-02-07 16:58:40360 TaskManagerMac::Show(false);
361}
362
363void BrowserWindowCocoa::ShowBackgroundPages() {
364 TaskManagerMac::Show(true);
[email protected]7d791652010-12-01 16:34:49365}
366
367void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url,
368 bool already_bookmarked) {
369 [controller_ showBookmarkBubbleForURL:url
370 alreadyBookmarked:(already_bookmarked ? YES : NO)];
371}
372
373bool BrowserWindowCocoa::IsDownloadShelfVisible() const {
374 return [controller_ isDownloadShelfVisible] != NO;
375}
376
377DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() {
378 DownloadShelfController* shelfController = [controller_ downloadShelf];
379 return [shelfController bridge];
380}
381
[email protected]7d791652010-12-01 16:34:49382void BrowserWindowCocoa::ShowRepostFormWarningDialog(
383 TabContents* tab_contents) {
384 RepostFormWarningMac::Create(GetNativeHandle(), tab_contents);
385}
386
[email protected]a3627e62011-09-07 00:04:57387void BrowserWindowCocoa::ShowCollectedCookiesDialog(
388 TabContentsWrapper* wrapper) {
[email protected]7d791652010-12-01 16:34:49389 // Deletes itself on close.
[email protected]a3627e62011-09-07 00:04:57390 new CollectedCookiesMac(GetNativeHandle(), wrapper);
[email protected]7d791652010-12-01 16:34:49391}
392
[email protected]7d791652010-12-01 16:34:49393void BrowserWindowCocoa::ShowThemeInstallBubble() {
394 ThemeInstallBubbleView::Show(window());
395}
396
397// We allow closing the window here since the real quit decision on Mac is made
398// in [AppController quit:].
399void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() {
400 // Call InProgressDownloadResponse asynchronously to avoid a crash when the
401 // browser window is closed here (http://crbug.com/44454).
402 MessageLoop::current()->PostTask(
403 FROM_HERE,
404 confirm_close_factory_.NewRunnableMethod(
405 &Browser::InProgressDownloadResponse,
406 true));
407}
408
[email protected]b86451c2011-08-16 02:13:44409gfx::NativeWindow BrowserWindowCocoa::ShowHTMLDialog(
410 HtmlDialogUIDelegate* delegate,
411 gfx::NativeWindow parent_window) {
[email protected]7d791652010-12-01 16:34:49412 [HtmlDialogWindowController showHtmlDialog:delegate
413 profile:browser_->profile()];
[email protected]b86451c2011-08-16 02:13:44414 return NULL;
[email protected]7d791652010-12-01 16:34:49415}
416
417void BrowserWindowCocoa::UserChangedTheme() {
418 [controller_ userChangedTheme];
419}
420
421int BrowserWindowCocoa::GetExtraRenderViewHeight() const {
422 // Currently this is only used on linux.
423 return 0;
424}
425
426void BrowserWindowCocoa::TabContentsFocused(TabContents* tab_contents) {
427 NOTIMPLEMENTED();
428}
429
430void BrowserWindowCocoa::ShowPageInfo(Profile* profile,
431 const GURL& url,
432 const NavigationEntry::SSLStatus& ssl,
433 bool show_history) {
434 browser::ShowPageInfoBubble(window(), profile, url, ssl, show_history);
435}
436
437void BrowserWindowCocoa::ShowAppMenu() {
438 // No-op. Mac doesn't support showing the menus via alt keys.
439}
440
441bool BrowserWindowCocoa::PreHandleKeyboardEvent(
442 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) {
[email protected]3a1381d2011-08-26 18:12:13443 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
[email protected]7d791652010-12-01 16:34:49444 return false;
445
[email protected]3a1381d2011-08-26 18:12:13446 int id = [BrowserWindowUtils getCommandId:event];
[email protected]7d791652010-12-01 16:34:49447 if (id == -1)
448 return false;
449
[email protected]3a1381d2011-08-26 18:12:13450 if (browser_->IsReservedCommandOrKey(id, event)) {
451 return [BrowserWindowUtils handleKeyboardEvent:event.os_event
452 inWindow:window()];
453 }
[email protected]7d791652010-12-01 16:34:49454
[email protected]3a1381d2011-08-26 18:12:13455 DCHECK(is_keyboard_shortcut);
[email protected]7d791652010-12-01 16:34:49456 *is_keyboard_shortcut = true;
[email protected]7d791652010-12-01 16:34:49457 return false;
458}
459
460void BrowserWindowCocoa::HandleKeyboardEvent(
461 const NativeWebKeyboardEvent& event) {
[email protected]3a1381d2011-08-26 18:12:13462 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event])
463 [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:window()];
[email protected]7d791652010-12-01 16:34:49464}
465
466void BrowserWindowCocoa::ShowCreateWebAppShortcutsDialog(
[email protected]f847e6082011-03-24 00:08:26467 TabContentsWrapper* tab_contents) {
[email protected]7d791652010-12-01 16:34:49468 NOTIMPLEMENTED();
469}
470
471void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog(
472 Profile* profile, const Extension* app) {
473 NOTIMPLEMENTED();
474}
475
476void BrowserWindowCocoa::Cut() {
477 [NSApp sendAction:@selector(cut:) to:nil from:nil];
478}
479
480void BrowserWindowCocoa::Copy() {
481 [NSApp sendAction:@selector(copy:) to:nil from:nil];
482}
483
484void BrowserWindowCocoa::Paste() {
485 [NSApp sendAction:@selector(paste:) to:nil from:nil];
486}
487
488void BrowserWindowCocoa::ToggleTabStripMode() {
489 [controller_ toggleTabStripDisplayMode];
490}
491
492void BrowserWindowCocoa::OpenTabpose() {
493 [controller_ openTabpose];
494}
495
[email protected]d3766932011-08-04 22:18:23496void BrowserWindowCocoa::SetPresentationMode(bool presentation_mode) {
497 [controller_ setPresentationMode:presentation_mode];
498}
499
500bool BrowserWindowCocoa::InPresentationMode() {
501 return [controller_ inPresentationMode];
502}
503
[email protected]7d791652010-12-01 16:34:49504void BrowserWindowCocoa::PrepareForInstant() {
505 // TODO: implement fade as done on windows.
506}
507
[email protected]e3690ed2011-03-25 20:25:14508void BrowserWindowCocoa::ShowInstant(TabContentsWrapper* preview) {
509 [controller_ showInstant:preview->tab_contents()];
[email protected]7d791652010-12-01 16:34:49510}
511
[email protected]1946c932010-12-15 00:07:38512void BrowserWindowCocoa::HideInstant(bool instant_is_active) {
[email protected]7d791652010-12-01 16:34:49513 [controller_ hideInstant];
[email protected]1946c932010-12-15 00:07:38514
515 // TODO: add support for |instant_is_active|.
[email protected]7d791652010-12-01 16:34:49516}
517
518gfx::Rect BrowserWindowCocoa::GetInstantBounds() {
519 // Flip coordinates based on the primary screen.
520 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
521 NSRect monitorFrame = [screen frame];
522 NSRect frame = [controller_ instantFrame];
523 gfx::Rect bounds(NSRectToCGRect(frame));
524 bounds.set_y(NSHeight(monitorFrame) - bounds.y() - bounds.height());
525 return bounds;
526}
527
[email protected]588300d2011-04-28 21:06:35528WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds(
529 const gfx::Rect& bounds) {
530 return NEW_POPUP;
531}
532
[email protected]632983f2011-08-08 22:51:24533FindBar* BrowserWindowCocoa::CreateFindBar() {
534 // We could push the AddFindBar() call into the FindBarBridge
535 // constructor or the FindBarCocoaController init, but that makes
536 // unit testing difficult, since we would also require a
537 // BrowserWindow object.
538 FindBarBridge* bridge = new FindBarBridge();
539 AddFindBar(bridge->find_bar_cocoa_controller());
540 return bridge;
541}
542
[email protected]432115822011-07-10 15:52:27543void BrowserWindowCocoa::Observe(int type,
[email protected]7d791652010-12-01 16:34:49544 const NotificationSource& source,
545 const NotificationDetails& details) {
[email protected]432115822011-07-10 15:52:27546 switch (type) {
[email protected]7d791652010-12-01 16:34:49547 // Only the key window gets a direct toggle from the menu.
548 // Other windows hear about it from the notification.
[email protected]432115822011-07-10 15:52:27549 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED:
[email protected]0b4e22322011-08-11 19:50:34550 if (browser_->profile()->IsSameProfile(Source<Profile>(source).ptr()))
551 [controller_ updateBookmarkBarVisibilityWithAnimation:YES];
[email protected]7d791652010-12-01 16:34:49552 break;
[email protected]432115822011-07-10 15:52:27553 case chrome::NOTIFICATION_SIDEBAR_CHANGED:
[email protected]7d791652010-12-01 16:34:49554 UpdateSidebarForContents(
555 Details<SidebarContainer>(details)->tab_contents());
556 break;
557 default:
558 NOTREACHED(); // we don't ask for anything else!
559 break;
560 }
561}
562
563void BrowserWindowCocoa::DestroyBrowser() {
564 [controller_ destroyBrowser];
565
566 // at this point the controller is dead (autoreleased), so
567 // make sure we don't try to reference it any more.
568}
569
570NSWindow* BrowserWindowCocoa::window() const {
571 return [controller_ window];
572}
573
574void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) {
575 if (tab_contents == browser_->GetSelectedTabContents()) {
576 [controller_ updateSidebarForContents:tab_contents];
577 }
578}