OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h
" | 5 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h
" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 : kSigninErrorDialogHeight; | 48 : kSigninErrorDialogHeight; |
49 } | 49 } |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 SigninViewControllerDelegateMac::SigninViewControllerDelegateMac( | 53 SigninViewControllerDelegateMac::SigninViewControllerDelegateMac( |
54 SigninViewController* signin_view_controller, | 54 SigninViewController* signin_view_controller, |
55 std::unique_ptr<content::WebContents> web_contents, | 55 std::unique_ptr<content::WebContents> web_contents, |
56 content::WebContents* host_web_contents, | 56 content::WebContents* host_web_contents, |
57 NSRect frame, | 57 NSRect frame, |
| 58 ui::ModalType dialog_modal_type, |
58 bool wait_for_size) | 59 bool wait_for_size) |
59 : SigninViewControllerDelegate(signin_view_controller, web_contents.get()), | 60 : SigninViewControllerDelegate(signin_view_controller, web_contents.get()), |
60 web_contents_(std::move(web_contents)), | 61 web_contents_(std::move(web_contents)), |
61 wait_for_size_(wait_for_size), | 62 wait_for_size_(wait_for_size), |
62 host_web_contents_(host_web_contents), | 63 host_web_contents_(host_web_contents), |
| 64 dialog_modal_type_(dialog_modal_type), |
63 window_frame_(frame) { | 65 window_frame_(frame) { |
64 if (!wait_for_size_) | 66 if (!wait_for_size_) |
65 DisplayModal(); | 67 DisplayModal(); |
66 } | 68 } |
67 | 69 |
68 SigninViewControllerDelegateMac::~SigninViewControllerDelegateMac() {} | 70 SigninViewControllerDelegateMac::~SigninViewControllerDelegateMac() {} |
69 | 71 |
70 void SigninViewControllerDelegateMac::OnConstrainedWindowClosed( | 72 void SigninViewControllerDelegateMac::OnConstrainedWindowClosed( |
71 ConstrainedWindowMac* window) { | 73 ConstrainedWindowMac* window) { |
72 ResetSigninViewControllerDelegate(); | 74 DeleteThis(); |
73 delete this; | |
74 } | 75 } |
75 | 76 |
76 // static | 77 // static |
77 std::unique_ptr<content::WebContents> | 78 std::unique_ptr<content::WebContents> |
78 SigninViewControllerDelegateMac::CreateGaiaWebContents( | 79 SigninViewControllerDelegateMac::CreateGaiaWebContents( |
79 content::WebContentsDelegate* delegate, | 80 content::WebContentsDelegate* delegate, |
80 profiles::BubbleViewMode mode, | 81 profiles::BubbleViewMode mode, |
81 Profile* profile, | 82 Profile* profile, |
82 signin_metrics::AccessPoint access_point) { | 83 signin_metrics::AccessPoint access_point) { |
83 GURL url = | 84 GURL url = |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | 139 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); |
139 | 140 |
140 NSView* webview = web_contents->GetNativeView(); | 141 NSView* webview = web_contents->GetNativeView(); |
141 [webview | 142 [webview |
142 setFrameSize:NSMakeSize(kModalDialogWidth, kSigninErrorDialogHeight)]; | 143 setFrameSize:NSMakeSize(kModalDialogWidth, kSigninErrorDialogHeight)]; |
143 | 144 |
144 return web_contents; | 145 return web_contents; |
145 } | 146 } |
146 | 147 |
147 void SigninViewControllerDelegateMac::PerformClose() { | 148 void SigninViewControllerDelegateMac::PerformClose() { |
148 if (constrained_window_.get()) | 149 switch (dialog_modal_type_) { |
149 constrained_window_->CloseWebContentsModalDialog(); | 150 case ui::MODAL_TYPE_CHILD: |
| 151 if (constrained_window_.get()) |
| 152 constrained_window_->CloseWebContentsModalDialog(); |
| 153 break; |
| 154 case ui::MODAL_TYPE_WINDOW: |
| 155 if (window_.get()) { |
| 156 [host_web_contents_->GetTopLevelNativeWindow() endSheet:window_]; |
| 157 window_.reset(nil); |
| 158 DeleteThis(); |
| 159 } |
| 160 break; |
| 161 default: |
| 162 NOTREACHED() << "Unsupported dialog modal type " << dialog_modal_type_; |
| 163 } |
150 } | 164 } |
151 | 165 |
152 void SigninViewControllerDelegateMac::ResizeNativeView(int height) { | 166 void SigninViewControllerDelegateMac::ResizeNativeView(int height) { |
153 if (wait_for_size_) { | 167 if (wait_for_size_) { |
154 [window_.get().contentView | 168 [window_.get().contentView |
155 setFrameSize:NSMakeSize(kModalDialogWidth, | 169 setFrameSize:NSMakeSize(kModalDialogWidth, |
156 height)]; | 170 height)]; |
157 window_frame_.size = NSMakeSize(kModalDialogWidth, height); | 171 window_frame_.size = NSMakeSize(kModalDialogWidth, height); |
158 DisplayModal(); | 172 DisplayModal(); |
159 } | 173 } |
160 } | 174 } |
161 | 175 |
162 void SigninViewControllerDelegateMac::DisplayModal() { | 176 void SigninViewControllerDelegateMac::DisplayModal() { |
163 window_.reset( | 177 window_.reset( |
164 [[ConstrainedWindowCustomWindow alloc] | 178 [[ConstrainedWindowCustomWindow alloc] |
165 initWithContentRect:window_frame_]); | 179 initWithContentRect:window_frame_]); |
166 | 180 |
167 window_.get().contentView = web_contents_->GetNativeView(); | 181 window_.get().contentView = web_contents_->GetNativeView(); |
168 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( | 182 base::scoped_nsobject<CustomConstrainedWindowSheet> sheet( |
169 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window_]); | 183 [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window_]); |
170 constrained_window_ = | 184 switch (dialog_modal_type_) { |
171 CreateAndShowWebModalDialogMac(this, host_web_contents_, sheet); | 185 case ui::MODAL_TYPE_CHILD: |
| 186 constrained_window_ = |
| 187 CreateAndShowWebModalDialogMac(this, host_web_contents_, sheet); |
| 188 break; |
| 189 case ui::MODAL_TYPE_WINDOW: |
| 190 [host_web_contents_->GetTopLevelNativeWindow() beginSheet:window_ |
| 191 completionHandler:nil]; |
| 192 break; |
| 193 default: |
| 194 NOTREACHED() << "Unsupported dialog modal type " << dialog_modal_type_; |
| 195 } |
172 } | 196 } |
173 | 197 |
174 void SigninViewControllerDelegateMac::HandleKeyboardEvent( | 198 void SigninViewControllerDelegateMac::HandleKeyboardEvent( |
175 content::WebContents* source, | 199 content::WebContents* source, |
176 const content::NativeWebKeyboardEvent& event) { | 200 const content::NativeWebKeyboardEvent& event) { |
177 int chrome_command_id = [BrowserWindowUtils getCommandId:event]; | 201 int chrome_command_id = [BrowserWindowUtils getCommandId:event]; |
178 bool can_handle_command = [BrowserWindowUtils isTextEditingEvent:event] || | 202 bool can_handle_command = [BrowserWindowUtils isTextEditingEvent:event] || |
179 chrome_command_id == IDC_CLOSE_WINDOW || | 203 chrome_command_id == IDC_CLOSE_WINDOW || |
180 chrome_command_id == IDC_EXIT; | 204 chrome_command_id == IDC_EXIT; |
181 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event] && | 205 if ([BrowserWindowUtils shouldHandleKeyboardEvent:event] && |
182 can_handle_command) { | 206 can_handle_command) { |
183 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; | 207 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; |
184 } | 208 } |
185 } | 209 } |
186 | 210 |
| 211 void SigninViewControllerDelegateMac::DeleteThis() { |
| 212 ResetSigninViewControllerDelegate(); |
| 213 delete this; |
| 214 } |
| 215 |
187 // static | 216 // static |
188 SigninViewControllerDelegate* | 217 SigninViewControllerDelegate* |
189 SigninViewControllerDelegate::CreateModalSigninDelegate( | 218 SigninViewControllerDelegate::CreateModalSigninDelegate( |
190 SigninViewController* signin_view_controller, | 219 SigninViewController* signin_view_controller, |
191 profiles::BubbleViewMode mode, | 220 profiles::BubbleViewMode mode, |
192 Browser* browser, | 221 Browser* browser, |
193 signin_metrics::AccessPoint access_point) { | 222 signin_metrics::AccessPoint access_point) { |
194 return new SigninViewControllerDelegateMac( | 223 return new SigninViewControllerDelegateMac( |
195 signin_view_controller, | 224 signin_view_controller, |
196 SigninViewControllerDelegateMac::CreateGaiaWebContents( | 225 SigninViewControllerDelegateMac::CreateGaiaWebContents( |
197 nullptr, mode, browser->profile(), access_point), | 226 nullptr, mode, browser->profile(), access_point), |
198 browser->tab_strip_model()->GetActiveWebContents(), | 227 browser->tab_strip_model()->GetActiveWebContents(), |
199 NSMakeRect(0, 0, kModalDialogWidth, kFixedGaiaViewHeight), | 228 NSMakeRect(0, 0, kModalDialogWidth, kFixedGaiaViewHeight), |
200 false); | 229 ui::MODAL_TYPE_CHILD, false); |
201 } | 230 } |
202 | 231 |
203 // static | 232 // static |
204 SigninViewControllerDelegate* | 233 SigninViewControllerDelegate* |
205 SigninViewControllerDelegate::CreateSyncConfirmationDelegate( | 234 SigninViewControllerDelegate::CreateSyncConfirmationDelegate( |
206 SigninViewController* signin_view_controller, | 235 SigninViewController* signin_view_controller, |
207 Browser* browser) { | 236 Browser* browser) { |
208 return new SigninViewControllerDelegateMac( | 237 return new SigninViewControllerDelegateMac( |
209 signin_view_controller, | 238 signin_view_controller, |
210 SigninViewControllerDelegateMac::CreateSyncConfirmationWebContents( | 239 SigninViewControllerDelegateMac::CreateSyncConfirmationWebContents( |
211 browser->profile()), | 240 browser->profile()), |
212 browser->tab_strip_model()->GetActiveWebContents(), | 241 browser->tab_strip_model()->GetActiveWebContents(), |
213 NSMakeRect(0, 0, kModalDialogWidth, | 242 NSMakeRect(0, 0, kModalDialogWidth, |
214 GetSyncConfirmationDialogPreferredHeight(browser->profile())), | 243 GetSyncConfirmationDialogPreferredHeight(browser->profile())), |
215 true); | 244 ui::MODAL_TYPE_WINDOW, true); |
216 } | 245 } |
217 | 246 |
218 // static | 247 // static |
219 SigninViewControllerDelegate* | 248 SigninViewControllerDelegate* |
220 SigninViewControllerDelegate::CreateSigninErrorDelegate( | 249 SigninViewControllerDelegate::CreateSigninErrorDelegate( |
221 SigninViewController* signin_view_controller, | 250 SigninViewController* signin_view_controller, |
222 Browser* browser) { | 251 Browser* browser) { |
223 return new SigninViewControllerDelegateMac( | 252 return new SigninViewControllerDelegateMac( |
224 signin_view_controller, | 253 signin_view_controller, |
225 SigninViewControllerDelegateMac::CreateSigninErrorWebContents( | 254 SigninViewControllerDelegateMac::CreateSigninErrorWebContents( |
226 browser->profile()), | 255 browser->profile()), |
227 browser->tab_strip_model()->GetActiveWebContents(), | 256 browser->tab_strip_model()->GetActiveWebContents(), |
228 NSMakeRect(0, 0, kModalDialogWidth, kSigninErrorDialogHeight), true); | 257 NSMakeRect(0, 0, kModalDialogWidth, kSigninErrorDialogHeight), |
| 258 ui::MODAL_TYPE_WINDOW, true); |
229 } | 259 } |
OLD | NEW |