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