[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] | 0610ab5 | 2013-12-04 03:22:51 | [diff] [blame] | 11 | #import "base/mac/sdk_forward_declarations.h" |
[email protected] | 3cc55ad | 2013-07-17 22:17:41 | [diff] [blame] | 12 | #include "base/message_loop/message_loop.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 13 | #include "base/prefs/pref_service.h" |
[email protected] | 3268d7b7 | 2013-03-28 17:41:43 | [diff] [blame] | 14 | #include "base/strings/sys_string_conversions.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 15 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | dcc8fbc | 2013-07-12 00:54:09 | [diff] [blame] | 16 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 17 | #include "chrome/browser/download/download_shelf.h" |
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 18 | #include "chrome/browser/extensions/tab_helper.h" |
[email protected] | ee6a527 | 2013-07-15 21:14:01 | [diff] [blame] | 19 | #include "chrome/browser/fullscreen.h" |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 20 | #include "chrome/browser/password_manager/password_manager.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 21 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 25ebfd36 | 2013-01-16 05:41:55 | [diff] [blame] | 22 | #include "chrome/browser/shell_integration.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 24 | #include "chrome/browser/ui/browser_command_controller.h" |
[email protected] | 320b369 | 2014-01-29 21:32:38 | [diff] [blame^] | 25 | #include "chrome/browser/ui/browser_commands_mac.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 26 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 1f0b50b | 2012-06-22 20:37:16 | [diff] [blame] | 27 | #include "chrome/browser/ui/browser_window_state.h" |
[email protected] | 25d0b8b7 | 2014-01-23 22:12:12 | [diff] [blame] | 28 | #import "chrome/browser/ui/cocoa/browser/avatar_base_controller.h" |
[email protected] | 2f733a0 | 2011-10-06 15:17:34 | [diff] [blame] | 29 | #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" |
[email protected] | 464f001 | 2011-07-07 02:12:51 | [diff] [blame] | 30 | #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 31 | #import "chrome/browser/ui/cocoa/browser/password_generation_bubble_controller.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 32 | #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 33 | #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 34 | #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 35 | #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 36 | #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
[email protected] | 51152d6d | 2011-11-07 01:55:12 | [diff] [blame] | 37 | #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 38 | #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
[email protected] | a7d83ca | 2011-03-06 14:41:07 | [diff] [blame] | 39 | #import "chrome/browser/ui/cocoa/nsmenuitem_additions.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 40 | #include "chrome/browser/ui/cocoa/restart_browser.h" |
| 41 | #include "chrome/browser/ui/cocoa/status_bubble_mac.h" |
| 42 | #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
[email protected] | 8450c4f | 2011-01-19 22:16:22 | [diff] [blame] | 43 | #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
[email protected] | 684dace4 | 2012-07-01 14:30:41 | [diff] [blame] | 44 | #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" |
[email protected] | 5436c8fd | 2012-07-02 11:30:46 | [diff] [blame] | 45 | #import "chrome/browser/ui/cocoa/website_settings_bubble_controller.h" |
[email protected] | e2395da | 2013-01-23 22:05:35 | [diff] [blame] | 46 | #include "chrome/browser/ui/search/search_model.h" |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 47 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 25ebfd36 | 2013-01-16 05:41:55 | [diff] [blame] | 48 | #include "chrome/browser/web_applications/web_app.h" |
[email protected] | 52a1cc3 | 2013-07-18 19:02:41 | [diff] [blame] | 49 | #include "chrome/common/chrome_switches.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 50 | #include "chrome/common/pref_names.h" |
[email protected] | e620d36 | 2013-09-09 08:01:53 | [diff] [blame] | 51 | #include "components/autofill/core/common/password_form.h" |
[email protected] | 8bc38d2 | 2011-10-14 20:39:20 | [diff] [blame] | 52 | #include "content/public/browser/native_web_keyboard_event.h" |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 53 | #include "content/public/browser/notification_details.h" |
[email protected] | 684dace4 | 2012-07-01 14:30:41 | [diff] [blame] | 54 | #include "content/public/browser/notification_source.h" |
[email protected] | e8558cf2 | 2012-01-10 03:10:51 | [diff] [blame] | 55 | #include "content/public/browser/web_contents.h" |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 56 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 57 | #include "grit/chromium_strings.h" |
| 58 | #include "grit/generated_resources.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 59 | #include "ui/base/l10n/l10n_util_mac.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 60 | #include "ui/gfx/rect.h" |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 61 | |
[email protected] | fe54b4a | 2012-03-28 16:11:04 | [diff] [blame] | 62 | #if defined(ENABLE_ONE_CLICK_SIGNIN) |
| 63 | #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" |
[email protected] | 8aa690c | 2013-02-06 22:33:12 | [diff] [blame] | 64 | #import "chrome/browser/ui/cocoa/one_click_signin_dialog_controller.h" |
[email protected] | fe54b4a | 2012-03-28 16:11:04 | [diff] [blame] | 65 | #endif |
| 66 | |
[email protected] | b87ee52 | 2012-05-18 15:16:54 | [diff] [blame] | 67 | using content::NativeWebKeyboardEvent; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 68 | using content::SSLStatus; |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 69 | using content::WebContents; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 70 | |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 71 | namespace { |
| 72 | |
| 73 | NSPoint GetPointForBubble(content::WebContents* web_contents, |
| 74 | int x_offset, |
| 75 | int y_offset) { |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 76 | NSView* view = web_contents->GetView()->GetNativeView(); |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 77 | NSRect bounds = [view bounds]; |
| 78 | NSPoint point; |
| 79 | point.x = NSMinX(bounds) + x_offset; |
| 80 | // The view's origin is at the bottom but |rect|'s origin is at the top. |
| 81 | point.y = NSMaxY(bounds) - y_offset; |
| 82 | point = [view convertPoint:point toView:nil]; |
| 83 | point = [[view window] convertBaseToScreen:point]; |
| 84 | return point; |
| 85 | } |
| 86 | |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 87 | } // namespace |
| 88 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 89 | BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 90 | BrowserWindowController* controller) |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 91 | : browser_(browser), |
| 92 | controller_(controller), |
[email protected] | 6a9b53a2 | 2012-10-09 02:43:34 | [diff] [blame] | 93 | initial_show_state_(ui::SHOW_STATE_DEFAULT), |
[email protected] | ad99634 | 2012-01-14 00:29:59 | [diff] [blame] | 94 | attention_request_id_(0) { |
[email protected] | cfecf943 | 2011-09-27 17:10:08 | [diff] [blame] | 95 | |
[email protected] | 6a9b53a2 | 2012-10-09 02:43:34 | [diff] [blame] | 96 | gfx::Rect bounds; |
| 97 | chrome::GetSavedWindowBoundsAndShowState(browser_, |
| 98 | &bounds, |
| 99 | &initial_show_state_); |
[email protected] | e2395da | 2013-01-23 22:05:35 | [diff] [blame] | 100 | |
| 101 | browser_->search_model()->AddObserver(this); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | BrowserWindowCocoa::~BrowserWindowCocoa() { |
[email protected] | e2395da | 2013-01-23 22:05:35 | [diff] [blame] | 105 | browser_->search_model()->RemoveObserver(this); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void BrowserWindowCocoa::Show() { |
| 109 | // The Browser associated with this browser window must become the active |
| 110 | // browser at the time |Show()| is called. This is the natural behaviour under |
| 111 | // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| 112 | // until we return to the runloop. Therefore any calls to |
[email protected] | 4d90025 | 2012-11-20 20:37:11 | [diff] [blame] | 113 | // |chrome::FindLastActiveWithHostDesktopType| will return the previous |
| 114 | // browser instead if we don't explicitly set it here. |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 115 | BrowserList::SetLastActive(browser_); |
| 116 | |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 117 | bool is_session_restore = browser_->is_session_restore(); |
[email protected] | b5cc93c | 2011-09-02 02:33:42 | [diff] [blame] | 118 | NSWindowAnimationBehavior saved_animation_behavior = |
| 119 | NSWindowAnimationBehaviorDefault; |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 120 | bool did_save_animation_behavior = false; |
| 121 | // Turn off swishing when restoring windows. |
| 122 | if (is_session_restore && |
| 123 | [window() respondsToSelector:@selector(animationBehavior)] && |
| 124 | [window() respondsToSelector:@selector(setAnimationBehavior:)]) { |
| 125 | did_save_animation_behavior = true; |
| 126 | saved_animation_behavior = [window() animationBehavior]; |
| 127 | [window() setAnimationBehavior:NSWindowAnimationBehaviorNone]; |
| 128 | } |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 129 | |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 130 | [window() makeKeyAndOrderFront:controller_]; |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 131 | |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 132 | // When creating windows from nibs it is necessary to |makeKeyAndOrderFront:| |
| 133 | // prior to |orderOut:| then |miniaturize:| when restoring windows in the |
| 134 | // minimized state. |
[email protected] | cfecf943 | 2011-09-27 17:10:08 | [diff] [blame] | 135 | if (initial_show_state_ == ui::SHOW_STATE_MINIMIZED) { |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 136 | [window() orderOut:controller_]; |
| 137 | [window() miniaturize:controller_]; |
[email protected] | 85b0ac6 | 2012-02-09 01:57:43 | [diff] [blame] | 138 | } else if (initial_show_state_ == ui::SHOW_STATE_FULLSCREEN) { |
[email protected] | 320b369 | 2014-01-29 21:32:38 | [diff] [blame^] | 139 | chrome::ToggleFullscreenWithChromeOrFallback(browser_); |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 140 | } |
[email protected] | cfecf943 | 2011-09-27 17:10:08 | [diff] [blame] | 141 | initial_show_state_ = ui::SHOW_STATE_DEFAULT; |
[email protected] | 8bc061f | 2011-08-31 22:46:23 | [diff] [blame] | 142 | |
| 143 | // Restore window animation behavior. |
| 144 | if (did_save_animation_behavior) |
| 145 | [window() setAnimationBehavior:saved_animation_behavior]; |
[email protected] | 2f516c79 | 2011-09-19 22:22:09 | [diff] [blame] | 146 | |
| 147 | browser_->OnWindowDidShow(); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame] | 150 | void BrowserWindowCocoa::ShowInactive() { |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 151 | [window() orderFront:controller_]; |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | 7d412f7 | 2012-10-25 04:59:15 | [diff] [blame] | 154 | void BrowserWindowCocoa::Hide() { |
| 155 | // Not implemented. |
| 156 | } |
| 157 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 158 | void BrowserWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
[email protected] | ccb5895f | 2011-06-09 21:16:14 | [diff] [blame] | 159 | gfx::Rect real_bounds = [controller_ enforceMinWindowSize:bounds]; |
| 160 | |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 161 | ExitFullscreen(); |
[email protected] | ccb5895f | 2011-06-09 21:16:14 | [diff] [blame] | 162 | NSRect cocoa_bounds = NSMakeRect(real_bounds.x(), 0, |
| 163 | real_bounds.width(), |
| 164 | real_bounds.height()); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 165 | // Flip coordinates based on the primary screen. |
| 166 | NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 167 | cocoa_bounds.origin.y = |
[email protected] | 03e0f5f1e | 2012-06-07 21:35:39 | [diff] [blame] | 168 | NSHeight([screen frame]) - real_bounds.height() - real_bounds.y(); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 169 | |
| 170 | [window() setFrame:cocoa_bounds display:YES]; |
| 171 | } |
| 172 | |
| 173 | // Callers assume that this doesn't immediately delete the Browser object. |
| 174 | // The controller implementing the window delegate methods called from |
| 175 | // |-performClose:| must take precautions to ensure that. |
| 176 | void BrowserWindowCocoa::Close() { |
| 177 | // If there is an overlay window, we contain a tab being dragged between |
| 178 | // windows. Don't hide the window as it makes the UI extra confused. We can |
| 179 | // still close the window, as that will happen when the drag completes. |
[email protected] | 60f9429 | 2012-03-12 22:24:27 | [diff] [blame] | 180 | if ([controller_ overlayWindow]) { |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 181 | [controller_ deferPerformClose]; |
[email protected] | 60f9429 | 2012-03-12 22:24:27 | [diff] [blame] | 182 | } else { |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 183 | // Using |-performClose:| can prevent the window from actually closing if |
| 184 | // a JavaScript beforeunload handler opens an alert during shutdown, as |
| 185 | // documented at <http://crbug.com/118424>. Re-implement |
| 186 | // -[NSWindow performClose:] as closely as possible to how Apple documents |
| 187 | // it. |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 188 | // |
| 189 | // Before calling |-close|, hide the window immediately. |-performClose:| |
| 190 | // would do something similar, and this ensures that the window is removed |
| 191 | // from AppKit's display list. Not doing so can lead to crashes like |
| 192 | // <http://crbug.com/156101>. |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 193 | id<NSWindowDelegate> delegate = [window() delegate]; |
| 194 | SEL window_should_close = @selector(windowShouldClose:); |
| 195 | if ([delegate respondsToSelector:window_should_close]) { |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 196 | if ([delegate windowShouldClose:window()]) { |
| 197 | [window() orderOut:nil]; |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 198 | [window() close]; |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 199 | } |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 200 | } else if ([window() respondsToSelector:window_should_close]) { |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 201 | if ([window() performSelector:window_should_close withObject:window()]) { |
| 202 | [window() orderOut:nil]; |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 203 | [window() close]; |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 204 | } |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 205 | } else { |
[email protected] | d1136ca | 2012-10-18 23:35:55 | [diff] [blame] | 206 | [window() orderOut:nil]; |
[email protected] | 5ea5197 | 2012-10-15 16:45:47 | [diff] [blame] | 207 | [window() close]; |
| 208 | } |
[email protected] | 60f9429 | 2012-03-12 22:24:27 | [diff] [blame] | 209 | } |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void BrowserWindowCocoa::Activate() { |
| 213 | [controller_ activate]; |
| 214 | } |
| 215 | |
| 216 | void BrowserWindowCocoa::Deactivate() { |
| 217 | // TODO(jcivelli): http://crbug.com/51364 Implement me. |
| 218 | NOTIMPLEMENTED(); |
| 219 | } |
| 220 | |
[email protected] | ad99634 | 2012-01-14 00:29:59 | [diff] [blame] | 221 | void BrowserWindowCocoa::FlashFrame(bool flash) { |
| 222 | if (flash) { |
| 223 | attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; |
| 224 | } else { |
| 225 | [NSApp cancelUserAttentionRequest:attention_request_id_]; |
| 226 | attention_request_id_ = 0; |
| 227 | } |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 228 | } |
| 229 | |
[email protected] | d101b0c | 2012-03-16 00:30:57 | [diff] [blame] | 230 | bool BrowserWindowCocoa::IsAlwaysOnTop() const { |
| 231 | return false; |
| 232 | } |
| 233 | |
[email protected] | 46d4605 | 2013-10-11 11:27:22 | [diff] [blame] | 234 | void BrowserWindowCocoa::SetAlwaysOnTop(bool always_on_top) { |
| 235 | // Not implemented for browser windows. |
| 236 | NOTIMPLEMENTED(); |
| 237 | } |
| 238 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 239 | bool BrowserWindowCocoa::IsActive() const { |
| 240 | return [window() isKeyWindow]; |
| 241 | } |
| 242 | |
[email protected] | 90556dd | 2012-06-07 20:26:18 | [diff] [blame] | 243 | gfx::NativeWindow BrowserWindowCocoa::GetNativeWindow() { |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 244 | return window(); |
| 245 | } |
| 246 | |
| 247 | BrowserWindowTesting* BrowserWindowCocoa::GetBrowserWindowTesting() { |
| 248 | return NULL; |
| 249 | } |
| 250 | |
| 251 | StatusBubble* BrowserWindowCocoa::GetStatusBubble() { |
| 252 | return [controller_ statusBubble]; |
| 253 | } |
| 254 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 255 | void BrowserWindowCocoa::UpdateTitleBar() { |
| 256 | NSString* newTitle = |
| 257 | base::SysUTF16ToNSString(browser_->GetWindowTitleForCurrentTab()); |
| 258 | |
[email protected] | d78e615e | 2011-09-06 21:46:03 | [diff] [blame] | 259 | pending_window_title_.reset( |
| 260 | [BrowserWindowUtils scheduleReplaceOldTitle:pending_window_title_.get() |
| 261 | withNewTitle:newTitle |
| 262 | forWindow:window()]); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 263 | } |
| 264 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 265 | void BrowserWindowCocoa::BookmarkBarStateChanged( |
| 266 | BookmarkBar::AnimateChangeType change_type) { |
[email protected] | 1eeccb9 | 2012-12-06 20:31:24 | [diff] [blame] | 267 | [[controller_ bookmarkBarController] |
| 268 | updateState:browser_->bookmark_bar_state() |
| 269 | changeType:change_type]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void BrowserWindowCocoa::UpdateDevTools() { |
| 273 | [controller_ updateDevToolsForContents: |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 274 | browser_->tab_strip_model()->GetActiveWebContents()]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) { |
| 278 | // Do nothing on Mac. |
| 279 | } |
| 280 | |
| 281 | void BrowserWindowCocoa::SetStarredState(bool is_starred) { |
| 282 | [controller_ setStarredState:is_starred ? YES : NO]; |
| 283 | } |
| 284 | |
[email protected] | 3917f82a | 2013-11-21 06:25:54 | [diff] [blame] | 285 | void BrowserWindowCocoa::SetTranslateIconToggled(bool is_lit) { |
| 286 | NOTIMPLEMENTED(); |
| 287 | } |
| 288 | |
[email protected] | 08726d5e | 2013-09-24 21:52:55 | [diff] [blame] | 289 | void BrowserWindowCocoa::OnActiveTabChanged(content::WebContents* old_contents, |
| 290 | content::WebContents* new_contents, |
| 291 | int index, |
| 292 | int reason) { |
| 293 | // TODO(pkasting): Perhaps the code in |
| 294 | // TabStripController::activateTabWithContents should move here? Or this |
| 295 | // should call that (instead of TabStripModelObserverBridge doing so)? It's |
| 296 | // not obvious to me why Mac doesn't handle tab changes in BrowserWindow the |
| 297 | // way views and GTK do. |
| 298 | } |
| 299 | |
[email protected] | 5423c37 | 2012-08-22 05:50:16 | [diff] [blame] | 300 | void BrowserWindowCocoa::ZoomChangedForActiveTab(bool can_show_bubble) { |
| 301 | [controller_ zoomChangedForActiveTab:can_show_bubble ? YES : NO]; |
[email protected] | 6f80e93 | 2012-06-04 19:00:07 | [diff] [blame] | 302 | } |
| 303 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 304 | gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const { |
| 305 | // Flip coordinates based on the primary screen. |
| 306 | NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 307 | NSRect frame = [controller_ regularWindowFrame]; |
[email protected] | 03e0f5f1e | 2012-06-07 21:35:39 | [diff] [blame] | 308 | gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); |
| 309 | bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 310 | return bounds; |
| 311 | } |
| 312 | |
[email protected] | 68eeede | 2013-05-09 06:10:57 | [diff] [blame] | 313 | ui::WindowShowState BrowserWindowCocoa::GetRestoredState() const { |
| 314 | if (IsMaximized()) |
| 315 | return ui::SHOW_STATE_MAXIMIZED; |
| 316 | if (IsMinimized()) |
| 317 | return ui::SHOW_STATE_MINIMIZED; |
| 318 | return ui::SHOW_STATE_NORMAL; |
| 319 | } |
| 320 | |
[email protected] | d479b8e2 | 2011-02-09 05:19:49 | [diff] [blame] | 321 | gfx::Rect BrowserWindowCocoa::GetBounds() const { |
| 322 | return GetRestoredBounds(); |
| 323 | } |
| 324 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 325 | bool BrowserWindowCocoa::IsMaximized() const { |
| 326 | return [window() isZoomed]; |
| 327 | } |
| 328 | |
[email protected] | 400eaf8 | 2011-08-22 15:47:39 | [diff] [blame] | 329 | bool BrowserWindowCocoa::IsMinimized() const { |
| 330 | return [window() isMiniaturized]; |
| 331 | } |
| 332 | |
[email protected] | 541e3ee | 2011-11-22 01:31:10 | [diff] [blame] | 333 | void BrowserWindowCocoa::Maximize() { |
| 334 | // Zoom toggles so only call if not already maximized. |
| 335 | if (!IsMaximized()) |
| 336 | [window() zoom:controller_]; |
| 337 | } |
| 338 | |
| 339 | void BrowserWindowCocoa::Minimize() { |
| 340 | [window() miniaturize:controller_]; |
| 341 | } |
| 342 | |
| 343 | void BrowserWindowCocoa::Restore() { |
| 344 | if (IsMaximized()) |
| 345 | [window() zoom:controller_]; // Toggles zoom mode. |
| 346 | else if (IsMinimized()) |
| 347 | [window() deminiaturize:controller_]; |
| 348 | } |
| 349 | |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 350 | void BrowserWindowCocoa::EnterFullscreen( |
[email protected] | 22d74a6b | 2011-10-17 20:30:31 | [diff] [blame] | 351 | const GURL& url, FullscreenExitBubbleType bubble_type) { |
[email protected] | 52a1cc3 | 2013-07-18 19:02:41 | [diff] [blame] | 352 | // When simplified fullscreen is enabled, always enter normal fullscreen. |
| 353 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 354 | if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) { |
[email protected] | 75050152 | 2013-07-20 01:44:29 | [diff] [blame] | 355 | if (url.is_empty()) |
| 356 | [controller_ enterFullscreen]; |
| 357 | else |
| 358 | [controller_ enterFullscreenForURL:url bubbleType:bubble_type]; |
[email protected] | 52a1cc3 | 2013-07-18 19:02:41 | [diff] [blame] | 359 | return; |
| 360 | } |
| 361 | |
[email protected] | 34337d3 | 2013-01-29 20:29:01 | [diff] [blame] | 362 | [controller_ enterPresentationModeForURL:url |
| 363 | bubbleType:bubble_type]; |
[email protected] | 55c87fa | 2011-10-15 07:28:28 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void BrowserWindowCocoa::ExitFullscreen() { |
[email protected] | 22d74a6b | 2011-10-17 20:30:31 | [diff] [blame] | 367 | [controller_ exitFullscreen]; |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | void BrowserWindowCocoa::UpdateFullscreenExitBubbleContent( |
| 371 | const GURL& url, |
| 372 | FullscreenExitBubbleType bubble_type) { |
[email protected] | 22d74a6b | 2011-10-17 20:30:31 | [diff] [blame] | 373 | [controller_ updateFullscreenExitBubbleURL:url bubbleType:bubble_type]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 374 | } |
| 375 | |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 376 | bool BrowserWindowCocoa::ShouldHideUIForFullscreen() const { |
| 377 | // On Mac, fullscreen mode has most normal things (in a slide-down panel). |
| 378 | return false; |
| 379 | } |
| 380 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 381 | bool BrowserWindowCocoa::IsFullscreen() const { |
[email protected] | 34337d3 | 2013-01-29 20:29:01 | [diff] [blame] | 382 | if ([controller_ inPresentationMode]) |
| 383 | CHECK([controller_ isFullscreen]); // Presentation mode must be fullscreen. |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 384 | return [controller_ isFullscreen]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | bool BrowserWindowCocoa::IsFullscreenBubbleVisible() const { |
| 388 | return false; |
| 389 | } |
| 390 | |
| 391 | void BrowserWindowCocoa::ConfirmAddSearchProvider( |
[email protected] | 3613347d | 2012-04-27 20:27:37 | [diff] [blame] | 392 | TemplateURL* template_url, |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 393 | Profile* profile) { |
[email protected] | 464f001 | 2011-07-07 02:12:51 | [diff] [blame] | 394 | // The controller will release itself when the window closes. |
| 395 | EditSearchEngineCocoaController* editor = |
| 396 | [[EditSearchEngineCocoaController alloc] initWithProfile:profile |
| 397 | delegate:NULL |
| 398 | templateURL:template_url]; |
| 399 | [NSApp beginSheet:[editor window] |
| 400 | modalForWindow:window() |
| 401 | modalDelegate:controller_ |
| 402 | didEndSelector:@selector(sheetDidEnd:returnCode:context:) |
| 403 | contextInfo:NULL]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | LocationBar* BrowserWindowCocoa::GetLocationBar() const { |
| 407 | return [controller_ locationBarBridge]; |
| 408 | } |
| 409 | |
| 410 | void BrowserWindowCocoa::SetFocusToLocationBar(bool select_all) { |
| 411 | [controller_ focusLocationBar:select_all ? YES : NO]; |
| 412 | } |
| 413 | |
| 414 | void BrowserWindowCocoa::UpdateReloadStopState(bool is_loading, bool force) { |
| 415 | [controller_ setIsLoading:is_loading force:force]; |
| 416 | } |
| 417 | |
[email protected] | 2e7fe431 | 2013-08-21 17:19:48 | [diff] [blame] | 418 | void BrowserWindowCocoa::UpdateToolbar(content::WebContents* contents) { |
| 419 | [controller_ updateToolbarWithContents:contents]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void BrowserWindowCocoa::FocusToolbar() { |
| 423 | // Not needed on the Mac. |
| 424 | } |
| 425 | |
| 426 | void BrowserWindowCocoa::FocusAppMenu() { |
| 427 | // Chrome uses the standard Mac OS X menu bar, so this isn't needed. |
| 428 | } |
| 429 | |
| 430 | void BrowserWindowCocoa::RotatePaneFocus(bool forwards) { |
| 431 | // Not needed on the Mac. |
| 432 | } |
| 433 | |
| 434 | void BrowserWindowCocoa::FocusBookmarksToolbar() { |
| 435 | // Not needed on the Mac. |
| 436 | } |
| 437 | |
[email protected] | 822ca8c6 | 2013-04-19 00:49:15 | [diff] [blame] | 438 | void BrowserWindowCocoa::FocusInfobars() { |
| 439 | // Not needed on the Mac. |
| 440 | } |
| 441 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 442 | bool BrowserWindowCocoa::IsBookmarkBarVisible() const { |
[email protected] | a007e73 | 2011-08-05 13:32:19 | [diff] [blame] | 443 | return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | bool BrowserWindowCocoa::IsBookmarkBarAnimating() const { |
| 447 | return [controller_ isBookmarkBarAnimating]; |
| 448 | } |
| 449 | |
[email protected] | 95bf8a5b | 2010-12-22 16:04:07 | [diff] [blame] | 450 | bool BrowserWindowCocoa::IsTabStripEditable() const { |
| 451 | return ![controller_ isDragSessionActive]; |
| 452 | } |
| 453 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 454 | bool BrowserWindowCocoa::IsToolbarVisible() const { |
| 455 | return browser_->SupportsWindowFeature(Browser::FEATURE_TOOLBAR) || |
| 456 | browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR); |
| 457 | } |
| 458 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 459 | gfx::Rect BrowserWindowCocoa::GetRootWindowResizerRect() const { |
[email protected] | 9f872709 | 2012-02-08 01:38:18 | [diff] [blame] | 460 | if (IsDownloadShelfVisible()) |
| 461 | return gfx::Rect(); |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 462 | NSRect tabRect = [controller_ selectedTabGrowBoxRect]; |
| 463 | return gfx::Rect(NSRectToCGRect(tabRect)); |
| 464 | } |
| 465 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 466 | void BrowserWindowCocoa::AddFindBar( |
| 467 | FindBarCocoaController* find_bar_cocoa_controller) { |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 468 | [controller_ addFindBar:find_bar_cocoa_controller]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 469 | } |
| 470 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 471 | void BrowserWindowCocoa::ShowUpdateChromeDialog() { |
[email protected] | 678dae8 | 2011-02-11 20:03:08 | [diff] [blame] | 472 | restart_browser::RequestRestart(window()); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 473 | } |
| 474 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 475 | void BrowserWindowCocoa::ShowBookmarkBubble(const GURL& url, |
| 476 | bool already_bookmarked) { |
| 477 | [controller_ showBookmarkBubbleForURL:url |
| 478 | alreadyBookmarked:(already_bookmarked ? YES : NO)]; |
| 479 | } |
| 480 | |
[email protected] | e625b760 | 2013-10-28 09:24:56 | [diff] [blame] | 481 | void BrowserWindowCocoa::ShowTranslateBubble( |
| 482 | content::WebContents* contents, |
[email protected] | 6d37ab2 | 2013-12-03 11:18:30 | [diff] [blame] | 483 | TranslateBubbleModel::ViewState view_state, |
| 484 | TranslateErrors::Type error_type) { |
| 485 | NOTIMPLEMENTED(); |
[email protected] | e625b760 | 2013-10-28 09:24:56 | [diff] [blame] | 486 | } |
| 487 | |
[email protected] | 235a056 | 2012-03-26 22:22:35 | [diff] [blame] | 488 | #if defined(ENABLE_ONE_CLICK_SIGNIN) |
[email protected] | fe54b4a | 2012-03-28 16:11:04 | [diff] [blame] | 489 | void BrowserWindowCocoa::ShowOneClickSigninBubble( |
[email protected] | 265c927 | 2013-01-25 19:18:45 | [diff] [blame] | 490 | OneClickSigninBubbleType type, |
[email protected] | dcd024987 | 2013-12-06 23:58:45 | [diff] [blame] | 491 | const base::string16& email, |
| 492 | const base::string16& error_message, |
[email protected] | 265c927 | 2013-01-25 19:18:45 | [diff] [blame] | 493 | const StartSyncCallback& start_sync_callback) { |
[email protected] | 02ada8bf | 2013-05-02 01:34:22 | [diff] [blame] | 494 | WebContents* web_contents = |
| 495 | browser_->tab_strip_model()->GetActiveWebContents(); |
[email protected] | 8aa690c | 2013-02-06 22:33:12 | [diff] [blame] | 496 | if (type == ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE) { |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 497 | base::scoped_nsobject<OneClickSigninBubbleController> bubble_controller([ |
| 498 | [OneClickSigninBubbleController alloc] |
| 499 | initWithBrowserWindowController:cocoa_controller() |
| 500 | webContents:web_contents |
| 501 | errorMessage:base::SysUTF16ToNSString(error_message) |
| 502 | callback:start_sync_callback]); |
[email protected] | 8aa690c | 2013-02-06 22:33:12 | [diff] [blame] | 503 | [bubble_controller showWindow:nil]; |
| 504 | } else { |
[email protected] | 8aa690c | 2013-02-06 22:33:12 | [diff] [blame] | 505 | // Deletes itself when the dialog closes. |
[email protected] | c28050a | 2013-07-10 04:56:40 | [diff] [blame] | 506 | new OneClickSigninDialogController( |
| 507 | web_contents, start_sync_callback, email); |
[email protected] | 8aa690c | 2013-02-06 22:33:12 | [diff] [blame] | 508 | } |
[email protected] | 235a056 | 2012-03-26 22:22:35 | [diff] [blame] | 509 | } |
| 510 | #endif |
| 511 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 512 | bool BrowserWindowCocoa::IsDownloadShelfVisible() const { |
| 513 | return [controller_ isDownloadShelfVisible] != NO; |
| 514 | } |
| 515 | |
| 516 | DownloadShelf* BrowserWindowCocoa::GetDownloadShelf() { |
| 517 | DownloadShelfController* shelfController = [controller_ downloadShelf]; |
| 518 | return [shelfController bridge]; |
| 519 | } |
| 520 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 521 | // We allow closing the window here since the real quit decision on Mac is made |
| 522 | // in [AppController quit:]. |
[email protected] | edfca70 | 2013-08-16 08:58:14 | [diff] [blame] | 523 | void BrowserWindowCocoa::ConfirmBrowserCloseWithPendingDownloads( |
| 524 | int download_count, |
| 525 | Browser::DownloadClosePreventionType dialog_type, |
| 526 | bool app_modal, |
| 527 | const base::Callback<void(bool)>& callback) { |
| 528 | callback.Run(true); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 529 | } |
| 530 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 531 | void BrowserWindowCocoa::UserChangedTheme() { |
| 532 | [controller_ userChangedTheme]; |
| 533 | } |
| 534 | |
| 535 | int BrowserWindowCocoa::GetExtraRenderViewHeight() const { |
| 536 | // Currently this is only used on linux. |
| 537 | return 0; |
| 538 | } |
| 539 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 540 | void BrowserWindowCocoa::WebContentsFocused(WebContents* contents) { |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 541 | NOTIMPLEMENTED(); |
| 542 | } |
| 543 | |
[email protected] | b8e681e8 | 2012-02-20 10:18:47 | [diff] [blame] | 544 | void BrowserWindowCocoa::ShowWebsiteSettings( |
| 545 | Profile* profile, |
[email protected] | 36ad4aa8 | 2012-11-21 19:20:48 | [diff] [blame] | 546 | content::WebContents* web_contents, |
[email protected] | b8e681e8 | 2012-02-20 10:18:47 | [diff] [blame] | 547 | const GURL& url, |
[email protected] | 9fb47a8 | 2013-07-05 11:34:02 | [diff] [blame] | 548 | const content::SSLStatus& ssl) { |
[email protected] | a4ed9ed | 2013-07-11 23:40:13 | [diff] [blame] | 549 | WebsiteSettingsUIBridge::Show(window(), profile, web_contents, url, ssl); |
[email protected] | b8e681e8 | 2012-02-20 10:18:47 | [diff] [blame] | 550 | } |
| 551 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 552 | void BrowserWindowCocoa::ShowAppMenu() { |
| 553 | // No-op. Mac doesn't support showing the menus via alt keys. |
| 554 | } |
| 555 | |
| 556 | bool BrowserWindowCocoa::PreHandleKeyboardEvent( |
| 557 | const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 558 | if (![BrowserWindowUtils shouldHandleKeyboardEvent:event]) |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 559 | return false; |
| 560 | |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 561 | if (event.type == blink::WebInputEvent::RawKeyDown && |
[email protected] | d2885ba | 2012-08-17 10:23:12 | [diff] [blame] | 562 | [controller_ handledByExtensionCommand:event.os_event]) |
| 563 | return true; |
| 564 | |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 565 | int id = [BrowserWindowUtils getCommandId:event]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 566 | if (id == -1) |
| 567 | return false; |
| 568 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 569 | if (browser_->command_controller()->IsReservedCommandOrKey(id, event)) { |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 570 | return [BrowserWindowUtils handleKeyboardEvent:event.os_event |
| 571 | inWindow:window()]; |
| 572 | } |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 573 | |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 574 | DCHECK(is_keyboard_shortcut); |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 575 | *is_keyboard_shortcut = true; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 576 | return false; |
| 577 | } |
| 578 | |
| 579 | void BrowserWindowCocoa::HandleKeyboardEvent( |
| 580 | const NativeWebKeyboardEvent& event) { |
[email protected] | 3a1381d | 2011-08-26 18:12:13 | [diff] [blame] | 581 | if ([BrowserWindowUtils shouldHandleKeyboardEvent:event]) |
| 582 | [BrowserWindowUtils handleKeyboardEvent:event.os_event inWindow:window()]; |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 583 | } |
| 584 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 585 | void BrowserWindowCocoa::Cut() { |
| 586 | [NSApp sendAction:@selector(cut:) to:nil from:nil]; |
| 587 | } |
| 588 | |
| 589 | void BrowserWindowCocoa::Copy() { |
| 590 | [NSApp sendAction:@selector(copy:) to:nil from:nil]; |
| 591 | } |
| 592 | |
| 593 | void BrowserWindowCocoa::Paste() { |
| 594 | [NSApp sendAction:@selector(paste:) to:nil from:nil]; |
| 595 | } |
| 596 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 597 | void BrowserWindowCocoa::OpenTabpose() { |
| 598 | [controller_ openTabpose]; |
| 599 | } |
| 600 | |
[email protected] | 34337d3 | 2013-01-29 20:29:01 | [diff] [blame] | 601 | void BrowserWindowCocoa::EnterFullscreenWithChrome() { |
[email protected] | 52a1cc3 | 2013-07-18 19:02:41 | [diff] [blame] | 602 | // This method cannot be called if simplified fullscreen is enabled. |
| 603 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 604 | DCHECK(!command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)); |
| 605 | |
[email protected] | ee6a527 | 2013-07-15 21:14:01 | [diff] [blame] | 606 | CHECK(chrome::mac::SupportsSystemFullscreen()); |
[email protected] | 34337d3 | 2013-01-29 20:29:01 | [diff] [blame] | 607 | if ([controller_ inPresentationMode]) |
| 608 | [controller_ exitPresentationMode]; |
| 609 | else |
| 610 | [controller_ enterFullscreen]; |
[email protected] | 8d944b3 | 2011-10-17 06:11:53 | [diff] [blame] | 611 | } |
| 612 | |
[email protected] | 34337d3 | 2013-01-29 20:29:01 | [diff] [blame] | 613 | bool BrowserWindowCocoa::IsFullscreenWithChrome() { |
[email protected] | 52a1cc3 | 2013-07-18 19:02:41 | [diff] [blame] | 614 | // The WithChrome mode does not exist when simplified fullscreen is enabled. |
| 615 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 616 | if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) |
| 617 | return false; |
[email protected] | 34337d3 | 2013-01-29 20:29:01 | [diff] [blame] | 618 | return IsFullscreen() && ![controller_ inPresentationMode]; |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 619 | } |
| 620 | |
[email protected] | 34337d3 | 2013-01-29 20:29:01 | [diff] [blame] | 621 | bool BrowserWindowCocoa::IsFullscreenWithoutChrome() { |
[email protected] | 52a1cc3 | 2013-07-18 19:02:41 | [diff] [blame] | 622 | // Presentation mode does not exist if simplified fullscreen is enabled. The |
| 623 | // WithoutChrome mode simply maps to whether or not the window is fullscreen. |
| 624 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 625 | if (command_line->HasSwitch(switches::kEnableSimplifiedFullscreen)) |
| 626 | return IsFullscreen(); |
| 627 | |
[email protected] | 34337d3 | 2013-01-29 20:29:01 | [diff] [blame] | 628 | return IsFullscreen() && [controller_ inPresentationMode]; |
[email protected] | d376693 | 2011-08-04 22:18:23 | [diff] [blame] | 629 | } |
| 630 | |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 631 | WindowOpenDisposition BrowserWindowCocoa::GetDispositionForPopupBounds( |
| 632 | const gfx::Rect& bounds) { |
[email protected] | d82a3c9f | 2012-02-22 04:46:00 | [diff] [blame] | 633 | // In Lion fullscreen mode, convert popups into tabs. |
[email protected] | ee6a527 | 2013-07-15 21:14:01 | [diff] [blame] | 634 | if (chrome::mac::SupportsSystemFullscreen() && IsFullscreen()) |
[email protected] | d82a3c9f | 2012-02-22 04:46:00 | [diff] [blame] | 635 | return NEW_FOREGROUND_TAB; |
[email protected] | 588300d | 2011-04-28 21:06:35 | [diff] [blame] | 636 | return NEW_POPUP; |
| 637 | } |
| 638 | |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 639 | FindBar* BrowserWindowCocoa::CreateFindBar() { |
| 640 | // We could push the AddFindBar() call into the FindBarBridge |
| 641 | // constructor or the FindBarCocoaController init, but that makes |
| 642 | // unit testing difficult, since we would also require a |
| 643 | // BrowserWindow object. |
[email protected] | 03d5af59 | 2013-03-21 12:30:25 | [diff] [blame] | 644 | FindBarBridge* bridge = new FindBarBridge(browser_); |
[email protected] | 632983f | 2011-08-08 22:51:24 | [diff] [blame] | 645 | AddFindBar(bridge->find_bar_cocoa_controller()); |
| 646 | return bridge; |
| 647 | } |
| 648 | |
[email protected] | e41d008 | 2013-05-16 04:37:54 | [diff] [blame] | 649 | web_modal::WebContentsModalDialogHost* |
[email protected] | 7519c52 | 2013-04-02 01:07:23 | [diff] [blame] | 650 | BrowserWindowCocoa::GetWebContentsModalDialogHost() { |
| 651 | return NULL; |
[email protected] | 6a15176 | 2012-10-03 22:33:19 | [diff] [blame] | 652 | } |
| 653 | |
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 654 | extensions::ActiveTabPermissionGranter* |
| 655 | BrowserWindowCocoa::GetActiveTabPermissionGranter() { |
[email protected] | 85293484 | 2012-12-10 16:50:13 | [diff] [blame] | 656 | WebContents* web_contents = |
| 657 | browser_->tab_strip_model()->GetActiveWebContents(); |
| 658 | if (!web_contents) |
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 659 | return NULL; |
| 660 | extensions::TabHelper* tab_helper = |
[email protected] | 85293484 | 2012-12-10 16:50:13 | [diff] [blame] | 661 | extensions::TabHelper::FromWebContents(web_contents); |
[email protected] | 78ce302 | 2012-09-24 01:48:48 | [diff] [blame] | 662 | return tab_helper ? tab_helper->active_tab_permission_granter() : NULL; |
| 663 | } |
| 664 | |
[email protected] | 165fe42 | 2013-03-27 06:34:03 | [diff] [blame] | 665 | void BrowserWindowCocoa::ModelChanged(const SearchModel::State& old_state, |
| 666 | const SearchModel::State& new_state) { |
[email protected] | e2395da | 2013-01-23 22:05:35 | [diff] [blame] | 667 | } |
| 668 | |
[email protected] | 7d79165 | 2010-12-01 16:34:49 | [diff] [blame] | 669 | void BrowserWindowCocoa::DestroyBrowser() { |
| 670 | [controller_ destroyBrowser]; |
| 671 | |
| 672 | // at this point the controller is dead (autoreleased), so |
| 673 | // make sure we don't try to reference it any more. |
| 674 | } |
| 675 | |
| 676 | NSWindow* BrowserWindowCocoa::window() const { |
| 677 | return [controller_ window]; |
| 678 | } |
| 679 | |
[email protected] | 0ec4898e | 2011-12-30 21:09:24 | [diff] [blame] | 680 | void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents, |
[email protected] | 2f733a0 | 2011-10-06 15:17:34 | [diff] [blame] | 681 | const gfx::Rect& rect) { |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 682 | NSPoint point = GetPointForBubble(web_contents, rect.right(), rect.bottom()); |
[email protected] | 2f733a0 | 2011-10-06 15:17:34 | [diff] [blame] | 683 | |
| 684 | // |menu| will automatically release itself on close. |
| 685 | AvatarMenuBubbleController* menu = |
| 686 | [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ |
| 687 | anchoredAt:point]; |
[email protected] | 51152d6d | 2011-11-07 01:55:12 | [diff] [blame] | 688 | [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; |
[email protected] | 2f733a0 | 2011-10-06 15:17:34 | [diff] [blame] | 689 | [menu showWindow:nil]; |
| 690 | } |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 691 | |
| 692 | void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() { |
[email protected] | 25d0b8b7 | 2014-01-23 22:12:12 | [diff] [blame] | 693 | AvatarBaseController* controller = [controller_ avatarButtonController]; |
[email protected] | 8d904e83 | 2013-06-17 19:19:14 | [diff] [blame] | 694 | [controller showAvatarBubble:[controller buttonView]]; |
[email protected] | 7d2d0815 | 2011-10-25 22:58:47 | [diff] [blame] | 695 | } |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 696 | |
| 697 | void BrowserWindowCocoa::ShowPasswordGenerationBubble( |
| 698 | const gfx::Rect& rect, |
[email protected] | e620d36 | 2013-09-09 08:01:53 | [diff] [blame] | 699 | const autofill::PasswordForm& form, |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 700 | autofill::PasswordGenerator* password_generator) { |
[email protected] | 617ee96 | 2013-01-29 20:49:12 | [diff] [blame] | 701 | WebContents* web_contents = |
| 702 | browser_->tab_strip_model()->GetActiveWebContents(); |
[email protected] | f5d230b3 | 2012-12-11 02:04:11 | [diff] [blame] | 703 | // We want to point to the middle of the rect instead of the right side. |
| 704 | NSPoint point = GetPointForBubble(web_contents, |
| 705 | rect.x() + rect.width()/2, |
| 706 | rect.bottom()); |
| 707 | |
| 708 | PasswordGenerationBubbleController* controller = |
| 709 | [[PasswordGenerationBubbleController alloc] |
| 710 | initWithWindow:browser_->window()->GetNativeWindow() |
| 711 | anchoredAt:point |
| 712 | renderViewHost:web_contents->GetRenderViewHost() |
| 713 | passwordManager:PasswordManager::FromWebContents(web_contents) |
| 714 | usingGenerator:password_generator |
| 715 | forForm:form]; |
| 716 | [controller showWindow:nil]; |
| 717 | } |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 718 | |
| 719 | int |
| 720 | BrowserWindowCocoa::GetRenderViewHeightInsetWithDetachedBookmarkBar() { |
| 721 | if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
| 722 | return 0; |
| 723 | // TODO(sail): please make this work with cocoa, then enable |
| 724 | // BrowserTest.GetSizeForNewRenderView and |
| 725 | // WebContentsImplBrowserTest.GetSizeForNewRenderView. |
| 726 | // This function should return the extra height of the render view when |
| 727 | // detached bookmark bar is hidden. |
| 728 | // However, I (kuan) return 0 for now to retain the original behavior, |
| 729 | // because I encountered the following problem on cocoa: |
| 730 | // 1) When a navigation is requested, |
| 731 | // WebContentsImpl::CreateRenderViewForRenderManager creates the new |
| 732 | // RenderWidgetHostView at the size specified by |
| 733 | // WebContentsDelegate::GetSizeForNewRenderView implemented by Browser. |
| 734 | // 2) When the pending navigation entry is committed, |
| 735 | // WebContentsImpl::UpdateRenderViewSizeForRenderManager udpates the size |
| 736 | // of WebContentsView to the size in (1). |
| 737 | // 3) WebContentsImpl::DidNavigateMainFramePostCommit() is called, where |
| 738 | // the detached bookmark bar is hidden, resulting in relayout of tab |
| 739 | // contents area. |
| 740 | // On cocoa, (2) causes RenderWidgetHostView to resize (enlarge) further. |
| 741 | // e.g. if size in (1) is size A, and this function returns height H, height |
| 742 | // of RenderWidgetHostView after (2) becomes A.height() + H; it's supposed to |
| 743 | // stay at A.height(). |
| 744 | // Then, in (3), WebContentsView and RenderWidgetHostView enlarge even |
| 745 | // further, both by another H, i.e. WebContentsView's height becomes |
| 746 | // A.height() + H and RenderWidgetHostView's height becomes A.height() + 2H. |
| 747 | // Strangely, the RenderWidgetHostView for the previous navigation entry also |
| 748 | // gets enlarged by H. |
| 749 | // I believe these "automatic" resizing are caused by setAutoresizingMask of |
| 750 | // of the cocoa view in WebContentsViewMac, which defeats the purpose of |
| 751 | // WebContentsDelegate::GetSizeForNewRenderView i.e. to prevent resizing of |
| 752 | // RenderWidgetHostView in (2) and (3). |
| 753 | return 0; |
| 754 | } |