[email protected] | 3a80ea33 | 2012-01-09 19:53:29 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 2 | // 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] | a932d9e | 2011-09-29 01:14:34 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 8 | #include "base/command_line.h" |
| 9 | #include "base/logging.h" |
[email protected] | d82a3c9f | 2012-02-22 04:46:00 | [diff] [blame] | 10 | #include "base/mac/mac_util.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 11 | #include "base/message_loop.h" |
| 12 | #include "base/sys_string_conversions.h" |
| 13 | #include "chrome/app/chrome_command_ids.h" |
| 14 | #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 15 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 16 | #include "chrome/browser/extensions/tab_helper.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 17 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 18 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 19 | #include "chrome/browser/ui/browser.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 20 | #include "chrome/browser/ui/browser_command_controller.h" |
[email protected] | 3f32b9b | 2012-07-09 16:59:28 | [diff] [blame] | 21 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 22 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser_tabstrip.h" |
[email protected] | 1f0b50b | 2012-06-22 20:37:16 | [diff] [blame] | 24 | #include "chrome/browser/ui/browser_window_state.h" |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 25 | #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" |
[email protected] | 2f733a0 | 2011-10-06 15:17:34 | [diff] [blame] | 26 | #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" |
[email protected] | 464f001 | 2011-07-07 02:12:51 | [diff] [blame] | 27 | #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 28 | #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 29 | #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 30 | #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 31 | #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 32 | #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
[email protected] | 51152d6d | 2011-11-07 01:55:12 | [diff] [blame] | 33 | #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 34 | #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
[email protected] | a7d83ca | 2011-03-06 14:41:07 | [diff] [blame] | 35 | #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 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] | 8450c4f | 2011-01-19 22:16:22 | [diff] [blame] | 39 | #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
[email protected] | 684dace4 | 2012-07-01 14:30:41 | [diff] [blame] | 40 | #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" |
[email protected] | 5436c8fd | 2012-07-02 11:30:46 | [diff] [blame] | 41 | #import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h" |
[email protected] | 7e2514c | 2011-11-28 20:04:45 | [diff] [blame] | 42 | #include "chrome/browser/ui/page_info_bubble.h" |
[email protected] | 55eed87f | 2012-06-11 16:47:32 | [diff] [blame] | 43 | #include "chrome/browser/ui/tab_contents/tab_contents.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 44 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 45 | #include "chrome/common/pref_names.h" |
[email protected] | 8bc38d2 | 2011-10-14 20:39:20 | [diff] [blame] | 46 | #include "content/public/browser/native_web_keyboard_event.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 47 | #include "content/public/browser/notification_details.h" |
[email protected] | 684dace4 | 2012-07-01 14:30:41 | [diff] [blame] | 48 | #include "content/public/browser/notification_source.h" |
[email protected] | e8558cf2 | 2012-01-10 03:10:51 | [diff] [blame] | 49 | #include "content/public/browser/web_contents.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 50 | #include "grit/chromium_strings.h" |
| 51 | #include "grit/generated_resources.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 52 | #include "ui/base/l10n/l10n_util_mac.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 53 | #include "ui/gfx/rect.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 54 | |
[email protected] | fe54b4a | 2012-03-28 16:11:04 | [diff] [blame] | 55 | #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 56 | #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" |
| 57 | #endif |
| 58 | |
[email protected] | b87ee52 | 2012-05-18 15:16:54 | [diff] [blame] | 59 | using content::NativeWebKeyboardEvent; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 60 | using content::SSLStatus; |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 61 | using content::WebContents; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 62 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 63 | // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| 64 | #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| 65 | MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 66 | |
| 67 | enum { |
| 68 | NSWindowAnimationBehaviorDefault = 0, |
| 69 | NSWindowAnimationBehaviorNone = 2, |
| 70 | NSWindowAnimationBehaviorDocumentWindow = 3, |
| 71 | NSWindowAnimationBehaviorUtilityWindow = 4, |
| 72 | NSWindowAnimationBehaviorAlertPanel = 5 |
| 73 | }; |
| 74 | typedef NSInteger NSWindowAnimationBehavior; |
| 75 | |
| 76 | @interface NSWindow (LionSDKDeclarations) |
| 77 | - (NSWindowAnimationBehavior)animationBehavior; |
| 78 | - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; |
| 79 | @end |
| 80 | |
| 81 | #endif // MAC_OS_X_VERSION_10_7 |
| 82 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 83 | BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 84 | BrowserWindowController* controller) |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 85 | : browser_(browser), |
| 86 | controller_(controller), |
[email protected] | ad99634 | 2012-01-14 00:29:59 | [diff] [blame] | 87 | confirm_close_factory_(browser), |
[email protected] | 6a9b53a2 | 2012-10-09 02:43:34 | [diff] [blame] | 88 | initial_show_state_(ui::SHOW_STATE_DEFAULT), |
[email protected] | ad99634 | 2012-01-14 00:29:59 | [diff] [blame] | 89 | attention_request_id_(0) { |
[email protected] | cfecf943 | 2011-09-27 17:10:08 | [diff] [blame] | 90 | |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 91 | pref_change_registrar_.Init(browser_->profile()->GetPrefs()); |
| 92 | pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
[email protected] | 6a9b53a2 | 2012-10-09 02:43:34 | [diff] [blame] | 93 | gfx::Rect bounds; |
| 94 | chrome::GetSavedWindowBoundsAndShowState(browser_, |
| 95 | &bounds, |
| 96 | &initial_show_state_); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 100 | } |
| 101 | |
| 102 | void BrowserWindowCocoa::Show() { |
| 103 | // The Browser associated with this browser window must become the active |
| 104 | // browser at the time |Show()| is called. This is the natural behaviour under |
| 105 | // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| 106 | // until we return to the runloop. Therefore any calls to |
| 107 | // |BrowserList::GetLastActive()| (for example, in bookmark_util), will return |
| 108 | // the previous browser instead if we don't explicitly set it here. |
| 109 | BrowserList::SetLastActive(browser_); |
| 110 | |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 111 | bool is_session_restore = browser_->is_session_restore(); |
[email protected] | b5cc93c | 2011-09-02 02:33:42 | [diff] [blame] | 112 | NSWindowAnimationBehavior saved_animation_behavior = |
| 113 | NSWindowAnimationBehaviorDefault; |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 114 | bool did_save_animation_behavior = false; |
| 115 | // Turn off swishing when restoring windows. |
| 116 | if (is_session_restore && |
| 117 | [window() respondsToSelector:@selector(animationBehavior)] && |
| 118 | [window() respondsToSelector:@selector(setAnimationBehavior:)]) { |
| 119 | did_save_animation_behavior = true; |
| 120 | saved_animation_behavior = [window() animationBehavior]; |
| 121 | [window() setAnimationBehavior:NSWindowAnimationBehaviorNone]; |
| 122 | } |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 123 | |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 124 | [window() makeKeyAndOrderFront:controller_]; |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 125 | |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 126 | // When creating windows from nibs it is necessary to |makeKeyAndOrderFront:| |
| 127 | // prior to |orderOut:| then |miniaturize:| when restoring windows in the |
| 128 | // minimized state. |
[email protected] | cfecf943 | 2011-09-27 17:10:08 | [diff] [blame] | 129 | if (initial_show_state_ == ui::SHOW_STATE_MINIMIZED) { |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 130 | [window() orderOut:controller_]; |
| 131 | [window() miniaturize:controller_]; |
[email protected] | 85b0ac6 | 2012-02-09 01:57:43 | [diff] [blame] | 132 | } else if (initial_show_state_ == ui::SHOW_STATE_FULLSCREEN) { |
[email protected] | 3f32b9b | 2012-07-09 16:59:28 | [diff] [blame] | 133 | chrome::ToggleFullscreenMode(browser_); |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 134 | } |
[email protected] | cfecf943 | 2011-09-27 17:10:08 | [diff] [blame] | 135 | initial_show_state_ = ui::SHOW_STATE_DEFAULT; |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 136 | |
| 137 | // Restore window animation behavior. |
| 138 | if (did_save_animation_behavior) |
| 139 | [window() setAnimationBehavior:saved_animation_behavior]; |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 140 | |
| 141 | browser_->OnWindowDidShow(); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 142 | } |
| 143 | |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame] | 144 | void BrowserWindowCocoa::ShowInactive() { |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 145 | [window() orderFront:controller_]; |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame] | 146 | } |
| 147 | |
[email protected] | 7d412f7 | 2012-10-25 04:59:15 | [diff] [blame^] | 148 | void BrowserWindowCocoa::Hide() { |
| 149 | // Not implemented. |
| 150 | } |
| 151 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 152 | void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
[email protected] | ccb5895f | 2011-06-09 21:16:14 | [diff] [blame] | 153 | gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; |
| 154 | |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 155 | ExitFullscreen(); |
[email protected] | ccb5895f | 2011-06-09 21:16:14 | [diff] [blame] | 156 | NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, |
| 157 | real_bounds.width(), |
| 158 | real_bounds.height()); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 159 | // Flip coordinates based on the primary screen. |
| 160 | NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 161 | cocoa_bounds.origin.y = |
[email protected] | 03e0f5f1e | 2012-06-07 21:35:39 | [diff] [blame] | 162 | NSHeight([screen frame]) - real_bounds.height() - real_bounds.y(); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 163 | |
| 164 | [window() setFrame:cocoa_bounds display:YES]; |
| 165 | } |
| 166 | |
| 167 | // Callers assume that this doesn't immediately delete the Browser object. |
| 168 | // The controller implementing the window delegate methods called from |
| 169 | // |-performClose:| must take precautions to ensure that. |
| 170 | void BrowserWindowCocoa::Close() { |
| 171 | // If there is an overlay window, we contain a tab being dragged between |
| 172 | // windows. Don't hide the window as it makes the UI extra confused. We can |
| 173 | // still close the window, as that will happen when the drag completes. |
[email protected] | 60f9429 | 2012-03-12 22:24:27 | [diff] [blame] | 174 | if ([controller_ overlayWindow]) { |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 175 | [controller_ deferPerformClose]; |
[email protected] | 60f9429 | 2012-03-12 22:24:27 | [diff] [blame] | 176 | } else { |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 177 | // Using |-performClose:| can prevent the window from actually closing if |
| 178 | // a JavaScript beforeunload handler opens an alert during shutdown, as |
| 179 | // documented at <http://crbug.com/118424>. Re-implement |
| 180 | // -[NSWindow performClose:] as closely as possible to how Apple documents |
| 181 | // it. |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 182 | // |
| 183 | // Before calling |-close|, hide the window immediately. |-performClose:| |
| 184 | // would do something similar, and this ensures that the window is removed |
| 185 | // from AppKit's display list. Not doing so can lead to crashes like |
| 186 | // <http://crbug.com/156101>. |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 187 | id<NSWindowDelegate> delegate = [window() delegate]; |
| 188 | SEL window_should_close = @selector(windowShouldClose:); |
| 189 | if ([delegate respondsToSelector:window_should_close]) { |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 190 | if ([delegate windowShouldClose:window()]) { |
| 191 | [window() orderOut:nil]; |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 192 | [window() close]; |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 193 | } |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 194 | } else if ([window() respondsToSelector:window_should_close]) { |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 195 | if ([window() performSelector:window_should_close withObject:window()]) { |
| 196 | [window() orderOut:nil]; |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 197 | [window() close]; |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 198 | } |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 199 | } else { |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 200 | [window() orderOut:nil]; |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 201 | [window() close]; |
| 202 | } |
[email protected] | 60f9429 | 2012-03-12 22:24:27 | [diff] [blame] | 203 | } |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void BrowserWindowCocoa::Activate() { |
| 207 | [controller_ activate]; |
| 208 | } |
| 209 | |
| 210 | void BrowserWindowCocoa::Deactivate() { |
| 211 | // TODO(jcivelli): http://crbug.com/51364 Implement me. |
| 212 | NOTIMPLEMENTED(); |
| 213 | } |
| 214 | |
[email protected] | ad99634 | 2012-01-14 00:29:59 | [diff] [blame] | 215 | void BrowserWindowCocoa::FlashFrame(bool flash) { |
| 216 | if (flash) { |
| 217 | attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; |
| 218 | } else { |
| 219 | [NSApp cancelUserAttentionRequest:attention_request_id_]; |
| 220 | attention_request_id_ = 0; |
| 221 | } |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | d101b0c | 2012-03-16 00:30:57 | [diff] [blame] | 224 | bool BrowserWindowCocoa::IsAlwaysOnTop() const { |
| 225 | return false; |
| 226 | } |
| 227 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 228 | bool BrowserWindowCocoa::IsActive() const { |
| 229 | return [window() isKeyWindow]; |
| 230 | } |
| 231 | |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 232 | gfx::NativeWindow BrowserWindowCocoa::GetNativeWindow() { |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 233 | return window(); |
| 234 | } |
| 235 | |
| 236 | BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() { |
| 237 | return NULL; |
| 238 | } |
| 239 | |
| 240 | StatusBubble* BrowserWindowCocoa::GetStatusBubble() { |
| 241 | return [controller_ statusBubble]; |
| 242 | } |
| 243 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 244 | void BrowserWindowCocoa::UpdateTitleBar() { |
| 245 | NSString* newTitle = |
| 246 | base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab()); |
| 247 | |
[email protected] | d78e615e | 2011-09-06 21:46:03 | [diff] [blame] | 248 | pending_window_title_.reset( |
| 249 | [BrowserWindowUtils scheduleReplaceOldTitle:pending_window_title_.get() |
| 250 | withNewTitle:newTitle |
| 251 | forWindow:window()]); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 252 | } |
| 253 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 254 | void BrowserWindowCocoa::BookmarkBarStateChanged( |
| 255 | BookmarkBar::AnimateChangeType change_type) { |
| 256 | // TODO: route changes to state through this. |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void BrowserWindowCocoa::UpdateDevTools() { |
| 260 | [controller_ updateDevToolsForContents: |
[email protected] | 52877dbc6 | 2012-06-29 22:22:03 | [diff] [blame] | 261 | chrome::GetActiveWebContents(browser_)]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 264 | void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) { |
| 265 | // Do nothing on Mac. |
| 266 | } |
| 267 | |
| 268 | void BrowserWindowCocoa::SetStarredState(bool is_starred) { |
| 269 | [controller_ setStarredState:is_starred ? YES : NO]; |
| 270 | } |
| 271 | |
[email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 272 | void BrowserWindowCocoa::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 273 | [controller_ zoomChangedForActiveTab:can_show_bubble ? YES : NO]; |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 276 | gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const { |
| 277 | // Flip coordinates based on the primary screen. |
| 278 | NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 279 | NSRect frame = [controller_ regularWindowFrame]; |
[email protected] | 03e0f5f1e | 2012-06-07 21:35:39 | [diff] [blame] | 280 | gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); |
| 281 | bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 282 | return bounds; |
| 283 | } |
| 284 | |
[email protected] | d479b8e2 | 2011-02-09 05:19:49 | [diff] [blame] | 285 | gfx::Rect BrowserWindowCocoa::GetBounds() const { |
| 286 | return GetRestoredBounds(); |
| 287 | } |
| 288 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 289 | bool BrowserWindowCocoa::IsMaximized() const { |
| 290 | return [window() isZoomed]; |
| 291 | } |
| 292 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 293 | bool BrowserWindowCocoa::IsMinimized() const { |
| 294 | return [window() isMiniaturized]; |
| 295 | } |
| 296 | |
[email protected] | 541e3ee | 2011-11-22 01:31:10 | [diff] [blame] | 297 | void BrowserWindowCocoa::Maximize() { |
| 298 | // Zoom toggles so only call if not already maximized. |
| 299 | if (!IsMaximized()) |
| 300 | [window() zoom:controller_]; |
| 301 | } |
| 302 | |
| 303 | void BrowserWindowCocoa::Minimize() { |
| 304 | [window() miniaturize:controller_]; |
| 305 | } |
| 306 | |
| 307 | void BrowserWindowCocoa::Restore() { |
| 308 | if (IsMaximized()) |
| 309 | [window() zoom:controller_]; // Toggles zoom mode. |
| 310 | else if (IsMinimized()) |
| 311 | [window() deminiaturize:controller_]; |
| 312 | } |
| 313 | |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 314 | void BrowserWindowCocoa::EnterFullscreen( |
[email protected] | 22d74a6b | 2011-10-17 20:30:31 | [diff] [blame] | 315 | const GURL& url, FullscreenExitBubbleType bubble_type) { |
| 316 | [controller_ enterFullscreenForURL:url |
| 317 | bubbleType:bubble_type]; |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | void BrowserWindowCocoa::ExitFullscreen() { |
[email protected] | 22d74a6b | 2011-10-17 20:30:31 | [diff] [blame] | 321 | [controller_ exitFullscreen]; |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | void BrowserWindowCocoa::UpdateFullscreenExitBubbleContent( |
| 325 | const GURL& url, |
| 326 | FullscreenExitBubbleType bubble_type) { |
[email protected] | 22d74a6b | 2011-10-17 20:30:31 | [diff] [blame] | 327 | [controller_ updateFullscreenExitBubbleURL:url bubbleType:bubble_type]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | bool BrowserWindowCocoa::IsFullscreen() const { |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 331 | return [controller_ isFullscreen]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { |
| 335 | return false; |
| 336 | } |
| 337 | |
| 338 | void BrowserWindowCocoa::ConfirmAddSearchProvider( |
[email protected] | 3613347d | 2012-04-27 20:27:37 | [diff] [blame] | 339 | TemplateURL* template_url, |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 340 | Profile* profile) { |
[email protected] | 464f001 | 2011-07-07 02:12:51 | [diff] [blame] | 341 | // The controller will release itself when the window closes. |
| 342 | EditSearchEngineCocoaController* editor = |
| 343 | [[EditSearchEngineCocoaController alloc] initWithProfile:profile |
| 344 | delegate:NULL |
| 345 | templateURL:template_url]; |
| 346 | [NSApp beginSheet:[editor window] |
| 347 | modalForWindow:window() |
| 348 | modalDelegate:controller_ |
| 349 | didEndSelector:@selector(sheetDidEnd:returnCode:context:) |
| 350 | contextInfo:NULL]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | LocationBar* BrowserWindowCocoa::GetLocationBar() const { |
| 354 | return [controller_ locationBarBridge]; |
| 355 | } |
| 356 | |
| 357 | void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) { |
| 358 | [controller_ focusLocationBar:select_all ? YES : NO]; |
| 359 | } |
| 360 | |
| 361 | void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) { |
| 362 | [controller_ setIsLoading:is_loading force:force]; |
| 363 | } |
| 364 | |
[email protected] | 55eed87f | 2012-06-11 16:47:32 | [diff] [blame] | 365 | void BrowserWindowCocoa::UpdateToolbar(TabContents* contents, |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 366 | bool should_restore_state) { |
[email protected] | 83a2610a | 2012-01-05 01:00:27 | [diff] [blame] | 367 | [controller_ updateToolbarWithContents:contents->web_contents() |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 368 | shouldRestoreState:should_restore_state ? YES : NO]; |
| 369 | } |
| 370 | |
| 371 | void BrowserWindowCocoa::FocusToolbar() { |
| 372 | // Not needed on the Mac. |
| 373 | } |
| 374 | |
| 375 | void BrowserWindowCocoa::FocusAppMenu() { |
| 376 | // Chrome uses the standard Mac OS X menu bar, so this isn't needed. |
| 377 | } |
| 378 | |
| 379 | void BrowserWindowCocoa::RotatePaneFocus(bool forwards) { |
| 380 | // Not needed on the Mac. |
| 381 | } |
| 382 | |
| 383 | void BrowserWindowCocoa::FocusBookmarksToolbar() { |
| 384 | // Not needed on the Mac. |
| 385 | } |
| 386 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 387 | |
| 388 | bool BrowserWindowCocoa::IsBookmarkBarVisible() const { |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 389 | return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | bool BrowserWindowCocoa::IsBookmarkBarAnimating() const { |
| 393 | return [controller_ isBookmarkBarAnimating]; |
| 394 | } |
| 395 | |
[email protected] | 95bf8a5b | 2010-12-22 16:04:07 | [diff] [blame] | 396 | bool BrowserWindowCocoa::IsTabStripEditable() const { |
| 397 | return ![controller_ isDragSessionActive]; |
| 398 | } |
| 399 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 400 | bool BrowserWindowCocoa::IsToolbarVisible() const { |
| 401 | return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || |
| 402 | browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); |
| 403 | } |
| 404 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 405 | gfx::Rect BrowserWindowCocoa::GetRootWindowResizerRect() const { |
[email protected] | 9f872709 | 2012-02-08 01:38:18 | [diff] [blame] | 406 | if (IsDownloadShelfVisible()) |
| 407 | return gfx::Rect(); |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 408 | NSRect tabRect = [controller_ selectedTabGrowBoxRect]; |
| 409 | return gfx::Rect(NSRectToCGRect(tabRect)); |
| 410 | } |
| 411 | |
[email protected] | 5f58c2af | 2012-01-11 17:55:29 | [diff] [blame] | 412 | bool BrowserWindowCocoa::IsPanel() const { |
| 413 | return false; |
| 414 | } |
| 415 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 416 | // This is called from Browser, which in turn is called directly from |
| 417 | // a menu option. All we do here is set a preference. The act of |
| 418 | // setting the preference sends notifications to all windows who then |
| 419 | // know what to do. |
| 420 | void BrowserWindowCocoa::ToggleBookmarkBar() { |
| 421 | bookmark_utils::ToggleWhenVisible(browser_->profile()); |
| 422 | } |
| 423 | |
| 424 | void BrowserWindowCocoa::AddFindBar( |
| 425 | FindBarCocoaController* find_bar_cocoa_controller) { |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 426 | [controller_ addFindBar:find_bar_cocoa_controller]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 427 | } |
| 428 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 429 | void BrowserWindowCocoa::ShowUpdateChromeDialog() { |
[email protected] | 678dae8 | 2011-02-11 20:03:08 | [diff] [blame] | 430 | restart_browser::RequestRestart(window()); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | void BrowserWindowCocoa::ShowTaskManager() { |
[email protected] | 898febec | 2012-05-31 18:15:48 | [diff] [blame] | 434 | TaskManagerMac::Show(false); |
[email protected] | adb6a84d | 2011-02-07 16:58:40 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | void BrowserWindowCocoa::ShowBackgroundPages() { |
[email protected] | 898febec | 2012-05-31 18:15:48 | [diff] [blame] | 438 | TaskManagerMac::Show(true); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, |
| 442 | bool already_bookmarked) { |
| 443 | [controller_ showBookmarkBubbleForURL:url |
| 444 | alreadyBookmarked:(already_bookmarked ? YES : NO)]; |
| 445 | } |
| 446 | |
[email protected] | b106ca5 | 2012-03-13 06:08:46 | [diff] [blame] | 447 | void BrowserWindowCocoa::ShowChromeToMobileBubble() { |
[email protected] | 24bbcdd | 2012-03-27 03:14:17 | [diff] [blame] | 448 | [controller_ showChromeToMobileBubble]; |
[email protected] | b106ca5 | 2012-03-13 06:08:46 | [diff] [blame] | 449 | } |
| 450 | |
[email protected] | 235a056 | 2012-03-26 22:22:35 | [diff] [blame] | 451 | #if defined(ENABLE_ONE_CLICK_SIGNIN) |
[email protected] | fe54b4a | 2012-03-28 16:11:04 | [diff] [blame] | 452 | void BrowserWindowCocoa::ShowOneClickSigninBubble( |
[email protected] | e4b66bf | 2012-05-29 20:39:51 | [diff] [blame] | 453 | const StartSyncCallback& start_sync_callback) { |
[email protected] | fe54b4a | 2012-03-28 16:11:04 | [diff] [blame] | 454 | OneClickSigninBubbleController* bubble_controller = |
| 455 | [[OneClickSigninBubbleController alloc] |
| 456 | initWithBrowserWindowController:cocoa_controller() |
[email protected] | e4b66bf | 2012-05-29 20:39:51 | [diff] [blame] | 457 | start_sync_callback:start_sync_callback]; |
[email protected] | fe54b4a | 2012-03-28 16:11:04 | [diff] [blame] | 458 | [bubble_controller showWindow:nil]; |
[email protected] | 235a056 | 2012-03-26 22:22:35 | [diff] [blame] | 459 | } |
| 460 | #endif |
| 461 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 462 | bool BrowserWindowCocoa::IsDownloadShelfVisible() const { |
| 463 | return [controller_ isDownloadShelfVisible] != NO; |
| 464 | } |
| 465 | |
| 466 | DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() { |
| 467 | DownloadShelfController* shelfController = [controller_ downloadShelf]; |
| 468 | return [shelfController bridge]; |
| 469 | } |
| 470 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 471 | // We allow closing the window here since the real quit decision on Mac is made |
| 472 | // in [AppController quit:]. |
| 473 | void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads() { |
| 474 | // Call InProgressDownloadResponse asynchronously to avoid a crash when the |
| 475 | // browser window is closed here (http://crbug.com/44454). |
[email protected] | a932d9e | 2011-09-29 01:14:34 | [diff] [blame] | 476 | MessageLoop::current()->PostTask(FROM_HERE, |
| 477 | base::Bind(&Browser::InProgressDownloadResponse, |
| 478 | confirm_close_factory_.GetWeakPtr(), true)); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 481 | void BrowserWindowCocoa::UserChangedTheme() { |
| 482 | [controller_ userChangedTheme]; |
| 483 | } |
| 484 | |
| 485 | int BrowserWindowCocoa::GetExtraRenderViewHeight() const { |
| 486 | // Currently this is only used on linux. |
| 487 | return 0; |
| 488 | } |
| 489 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 490 | void BrowserWindowCocoa::WebContentsFocused(WebContents* contents) { |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 491 | NOTIMPLEMENTED(); |
| 492 | } |
| 493 | |
[email protected] | 4eb4ec0 | 2012-06-19 15:54:21 | [diff] [blame] | 494 | void BrowserWindowCocoa::ShowPageInfo(WebContents* web_contents, |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 495 | const GURL& url, |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 496 | const SSLStatus& ssl, |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 497 | bool show_history) { |
[email protected] | 684dace4 | 2012-07-01 14:30:41 | [diff] [blame] | 498 | chrome::ShowPageInfoBubble(window(), web_contents, url, ssl, show_history, |
| 499 | browser_); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 500 | } |
| 501 | |
[email protected] | b8e681e8 | 2012-02-20 10:18:47 | [diff] [blame] | 502 | void BrowserWindowCocoa::ShowWebsiteSettings( |
| 503 | Profile* profile, |
[email protected] | 55eed87f | 2012-06-11 16:47:32 | [diff] [blame] | 504 | TabContents* tab_contents, |
[email protected] | b8e681e8 | 2012-02-20 10:18:47 | [diff] [blame] | 505 | const GURL& url, |
| 506 | const content::SSLStatus& ssl, |
| 507 | bool show_history) { |
[email protected] | 5436c8fd | 2012-07-02 11:30:46 | [diff] [blame] | 508 | WebsiteSettingsUIBridge::Show( |
| 509 | window(), profile, tab_contents, url, ssl); |
[email protected] | b8e681e8 | 2012-02-20 10:18:47 | [diff] [blame] | 510 | } |
| 511 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 512 | void BrowserWindowCocoa::ShowAppMenu() { |
| 513 | // No-op. Mac doesn't support showing the menus via alt keys. |
| 514 | } |
| 515 | |
| 516 | bool BrowserWindowCocoa::PreHandleKeyboardEvent( |
| 517 | const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 518 | if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 519 | return false; |
| 520 | |
[email protected] | d2885ba | 2012-08-17 10:23:12 | [diff] [blame] | 521 | if (event.type == WebKit::WebInputEvent::RawKeyDown && |
| 522 | [controller_ handledByExtensionCommand:event.os_event]) |
| 523 | return true; |
| 524 | |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 525 | int id = [BrowserWindowUtils getCommandId:event]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 526 | if (id == -1) |
| 527 | return false; |
| 528 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 529 | if (browser_->command_controller()->IsReservedCommandOrKey(id, event)) { |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 530 | return [BrowserWindowUtils handleKeyboardEvent:event.os_event |
| 531 | inWindow:window()]; |
| 532 | } |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 533 | |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 534 | DCHECK(is_keyboard_shortcut); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 535 | *is_keyboard_shortcut = true; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 536 | return false; |
| 537 | } |
| 538 | |
| 539 | void BrowserWindowCocoa::HandleKeyboardEvent( |
| 540 | const NativeWebKeyboardEvent& event) { |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 541 | if ([BrowserWindowUtils shouldHandleKeyboardEvent:event]) |
| 542 | [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:window()]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 543 | } |
| 544 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 545 | void BrowserWindowCocoa::ShowCreateChromeAppShortcutsDialog( |
[email protected] | 1c321ee | 2012-05-21 03:02:34 | [diff] [blame] | 546 | Profile* profile, const extensions::Extension* app) { |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 547 | NOTIMPLEMENTED(); |
| 548 | } |
| 549 | |
| 550 | void BrowserWindowCocoa::Cut() { |
| 551 | [NSApp sendAction:@selector(cut:) to:nil from:nil]; |
| 552 | } |
| 553 | |
| 554 | void BrowserWindowCocoa::Copy() { |
| 555 | [NSApp sendAction:@selector(copy:) to:nil from:nil]; |
| 556 | } |
| 557 | |
| 558 | void BrowserWindowCocoa::Paste() { |
| 559 | [NSApp sendAction:@selector(paste:) to:nil from:nil]; |
| 560 | } |
| 561 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 562 | void BrowserWindowCocoa::OpenTabpose() { |
| 563 | [controller_ openTabpose]; |
| 564 | } |
| 565 | |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 566 | void BrowserWindowCocoa::EnterPresentationMode( |
| 567 | const GURL& url, |
| 568 | FullscreenExitBubbleType bubble_type) { |
[email protected] | 22d74a6b | 2011-10-17 20:30:31 | [diff] [blame] | 569 | [controller_ enterPresentationModeForURL:url |
| 570 | bubbleType:bubble_type]; |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | void BrowserWindowCocoa::ExitPresentationMode() { |
[email protected] | 22d74a6b | 2011-10-17 20:30:31 | [diff] [blame] | 574 | [controller_ exitPresentationMode]; |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | bool BrowserWindowCocoa::InPresentationMode() { |
| 578 | return [controller_ inPresentationMode]; |
| 579 | } |
| 580 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 581 | gfx::Rect BrowserWindowCocoa::GetInstantBounds() { |
| 582 | // Flip coordinates based on the primary screen. |
| 583 | NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 584 | NSRect monitorFrame = [screen frame]; |
| 585 | NSRect frame = [controller_ instantFrame]; |
| 586 | gfx::Rect bounds(NSRectToCGRect(frame)); |
| 587 | bounds.set_y(NSHeight(monitorFrame) - bounds.y() - bounds.height()); |
| 588 | return bounds; |
| 589 | } |
| 590 | |
[email protected] | 85fd03e | 2012-09-04 22:50:14 | [diff] [blame] | 591 | bool BrowserWindowCocoa::IsInstantTabShowing() { |
| 592 | return [controller_ isInstantTabShowing]; |
| 593 | } |
| 594 | |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 595 | WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds( |
| 596 | const gfx::Rect& bounds) { |
[email protected] | d82a3c9f | 2012-02-22 04:46:00 | [diff] [blame] | 597 | // In Lion fullscreen mode, convert popups into tabs. |
| 598 | if (base::mac::IsOSLionOrLater() && IsFullscreen()) |
| 599 | return NEW_FOREGROUND_TAB; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 600 | return NEW_POPUP; |
| 601 | } |
| 602 | |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 603 | FindBar* BrowserWindowCocoa::CreateFindBar() { |
| 604 | // We could push the AddFindBar() call into the FindBarBridge |
| 605 | // constructor or the FindBarCocoaController init, but that makes |
| 606 | // unit testing difficult, since we would also require a |
| 607 | // BrowserWindow object. |
| 608 | FindBarBridge* bridge = new FindBarBridge(); |
| 609 | AddFindBar(bridge->find_bar_cocoa_controller()); |
| 610 | return bridge; |
| 611 | } |
| 612 | |
[email protected] | d3afce9 | 2012-10-07 05:47:36 | [diff] [blame] | 613 | bool BrowserWindowCocoa::GetConstrainedWindowTopY(int* top_y) { |
| 614 | return false; |
[email protected] | 6a15176 | 2012-10-03 22:33:19 | [diff] [blame] | 615 | } |
| 616 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 617 | void BrowserWindowCocoa::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 618 | const content::NotificationSource& source, |
| 619 | const content::NotificationDetails& details) { |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 620 | switch (type) { |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 621 | case chrome::NOTIFICATION_PREF_CHANGED: { |
[email protected] | 7ac4b87 | 2011-10-19 03:30:42 | [diff] [blame] | 622 | const std::string& pref_name = |
| 623 | *content::Details<std::string>(details).ptr(); |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 624 | DCHECK(pref_name == prefs::kShowBookmarkBar); |
| 625 | [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 626 | break; |
[email protected] | 3710d000 | 2011-10-11 00:35:00 | [diff] [blame] | 627 | } |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 628 | default: |
| 629 | NOTREACHED(); // we don't ask for anything else! |
| 630 | break; |
| 631 | } |
| 632 | } |
| 633 | |
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 634 | extensions::ActiveTabPermissionGranter* |
| 635 | BrowserWindowCocoa::GetActiveTabPermissionGranter() { |
| 636 | TabContents* tab_contents = |
| 637 | browser_->tab_strip_model()->GetActiveTabContents(); |
| 638 | if (!tab_contents) |
| 639 | return NULL; |
| 640 | extensions::TabHelper* tab_helper = |
| 641 | extensions::TabHelper::FromWebContents(tab_contents->web_contents()); |
| 642 | return tab_helper ? tab_helper->active_tab_permission_granter() : NULL; |
| 643 | } |
| 644 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 645 | void BrowserWindowCocoa::DestroyBrowser() { |
| 646 | [controller_ destroyBrowser]; |
| 647 | |
| 648 | // at this point the controller is dead (autoreleased), so |
| 649 | // make sure we don't try to reference it any more. |
| 650 | } |
| 651 | |
| 652 | NSWindow* BrowserWindowCocoa::window() const { |
| 653 | return [controller_ window]; |
| 654 | } |
| 655 | |
[email protected] | 0ec4898e | 2011-12-30 21:09:24 | [diff] [blame] | 656 | void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents, |
[email protected] | 2f733a0 | 2011-10-06 15:17:34 | [diff] [blame] | 657 | const gfx::Rect& rect) { |
[email protected] | 0ec4898e | 2011-12-30 21:09:24 | [diff] [blame] | 658 | NSView* view = web_contents->GetNativeView(); |
[email protected] | 79ac3cb | 2011-10-12 17:11:21 | [diff] [blame] | 659 | NSRect bounds = [view bounds]; |
| 660 | NSPoint point; |
| 661 | point.x = NSMinX(bounds) + rect.right(); |
| 662 | // The view's origin is at the bottom but |rect|'s origin is at the top. |
| 663 | point.y = NSMaxY(bounds) - rect.bottom(); |
[email protected] | 2f733a0 | 2011-10-06 15:17:34 | [diff] [blame] | 664 | point = [view convertPoint:point toView:nil]; |
| 665 | point = [[view window] convertBaseToScreen:point]; |
| 666 | |
| 667 | // |menu| will automatically release itself on close. |
| 668 | AvatarMenuBubbleController* menu = |
| 669 | [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ |
| 670 | anchoredAt:point]; |
[email protected] | 51152d6d | 2011-11-07 01:55:12 | [diff] [blame] | 671 | [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; |
[email protected] | 2f733a0 | 2011-10-06 15:17:34 | [diff] [blame] | 672 | [menu showWindow:nil]; |
| 673 | } |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 674 | |
| 675 | void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() { |
| 676 | [[controller_ avatarButtonController] showAvatarBubble]; |
| 677 | } |