OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" | 5 #import "chrome/browser/ui/cocoa/web_dialog_window_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #import "chrome/browser/ui/browser_dialogs.h" | 10 #import "chrome/browser/ui/browser_dialogs.h" |
11 #import "chrome/browser/ui/cocoa/browser_command_executor.h" | |
12 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 11 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
13 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | 12 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
14 #include "content/public/browser/native_web_keyboard_event.h" | 13 #include "content/public/browser/native_web_keyboard_event.h" |
15 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_ui_message_handler.h" | 15 #include "content/public/browser/web_ui_message_handler.h" |
17 #include "ui/events/keycodes/keyboard_codes.h" | 16 #include "ui/events/keycodes/keyboard_codes.h" |
18 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
19 #include "ui/web_dialogs/web_dialog_delegate.h" | 18 #include "ui/web_dialogs/web_dialog_delegate.h" |
20 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" | 19 #include "ui/web_dialogs/web_dialog_web_contents_delegate.h" |
21 | 20 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 WebDialogDelegate* delegate_; // weak, owned by controller_ | 77 WebDialogDelegate* delegate_; // weak, owned by controller_ |
79 | 78 |
80 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out afterwards | 79 // Calls delegate_'s OnDialogClosed() exactly once, nulling it out afterwards |
81 // so that no other WebDialogDelegate calls are sent to it. Returns whether or | 80 // so that no other WebDialogDelegate calls are sent to it. Returns whether or |
82 // not the OnDialogClosed() was actually called on the delegate. | 81 // not the OnDialogClosed() was actually called on the delegate. |
83 bool DelegateOnDialogClosed(const std::string& json_retval); | 82 bool DelegateOnDialogClosed(const std::string& json_retval); |
84 | 83 |
85 DISALLOW_COPY_AND_ASSIGN(WebDialogWindowDelegateBridge); | 84 DISALLOW_COPY_AND_ASSIGN(WebDialogWindowDelegateBridge); |
86 }; | 85 }; |
87 | 86 |
88 // ChromeEventProcessingWindow expects its controller to implement the | |
89 // BrowserCommandExecutor protocol. | |
90 @interface WebDialogWindowController (InternalAPI) <BrowserCommandExecutor> | |
91 | |
92 // BrowserCommandExecutor methods. | |
93 - (void)executeCommand:(int)command; | |
94 | |
95 @end | |
96 | |
97 namespace chrome { | 87 namespace chrome { |
98 | 88 |
99 gfx::NativeWindow ShowWebDialog(gfx::NativeView parent, | 89 gfx::NativeWindow ShowWebDialog(gfx::NativeView parent, |
100 content::BrowserContext* context, | 90 content::BrowserContext* context, |
101 WebDialogDelegate* delegate) { | 91 WebDialogDelegate* delegate) { |
102 return [WebDialogWindowController showWebDialog:delegate | 92 return [WebDialogWindowController showWebDialog:delegate |
103 context:context]; | 93 context:context]; |
104 } | 94 } |
105 | 95 |
106 } // namespace chrome | 96 } // namespace chrome |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 [controller_ close]; | 264 [controller_ close]; |
275 return; | 265 return; |
276 } | 266 } |
277 | 267 |
278 ChromeEventProcessingWindow* event_window = | 268 ChromeEventProcessingWindow* event_window = |
279 static_cast<ChromeEventProcessingWindow*>([controller_ window]); | 269 static_cast<ChromeEventProcessingWindow*>([controller_ window]); |
280 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]); | 270 DCHECK([event_window isKindOfClass:[ChromeEventProcessingWindow class]]); |
281 [event_window redispatchKeyEvent:event.os_event]; | 271 [event_window redispatchKeyEvent:event.os_event]; |
282 } | 272 } |
283 | 273 |
284 @implementation WebDialogWindowController (InternalAPI) | |
285 | |
286 // This gets called whenever a chrome-specific keyboard shortcut is performed | |
287 // in the Web dialog window. We simply swallow all those events. | |
288 - (void)executeCommand:(int)command {} | |
289 | |
290 @end | |
291 | |
292 @implementation WebDialogWindowController | 274 @implementation WebDialogWindowController |
293 | 275 |
294 // NOTE(akalin): We'll probably have to add the parentWindow parameter back | 276 // NOTE(akalin): We'll probably have to add the parentWindow parameter back |
295 // in once we implement modal dialogs. | 277 // in once we implement modal dialogs. |
296 | 278 |
297 + (NSWindow*)showWebDialog:(WebDialogDelegate*)delegate | 279 + (NSWindow*)showWebDialog:(WebDialogDelegate*)delegate |
298 context:(content::BrowserContext*)context { | 280 context:(content::BrowserContext*)context { |
299 WebDialogWindowController* webDialogWindowController = | 281 WebDialogWindowController* webDialogWindowController = |
300 [[WebDialogWindowController alloc] initWithDelegate:delegate | 282 [[WebDialogWindowController alloc] initWithDelegate:delegate |
301 context:context]; | 283 context:context]; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 // TODO(akalin): Figure out why implementing (void)cancel:(id)sender | 340 // TODO(akalin): Figure out why implementing (void)cancel:(id)sender |
359 // to do the above doesn't work. | 341 // to do the above doesn't work. |
360 } | 342 } |
361 | 343 |
362 - (void)windowWillClose:(NSNotification*)notification { | 344 - (void)windowWillClose:(NSNotification*)notification { |
363 delegate_->WindowControllerClosed(); | 345 delegate_->WindowControllerClosed(); |
364 [self autorelease]; | 346 [self autorelease]; |
365 } | 347 } |
366 | 348 |
367 @end | 349 @end |
OLD | NEW |