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