| 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 #include "ui/views/controls/webview/web_dialog_view.h" | 5 #include "ui/views/controls/webview/web_dialog_view.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/native_web_keyboard_event.h" | 11 #include "content/public/browser/native_web_keyboard_event.h" |
| 12 #include "content/public/browser/notification_details.h" | 12 #include "content/public/browser/notification_details.h" |
| 13 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
| 14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "ui/events/event.h" |
| 17 #include "ui/events/keycodes/keyboard_codes.h" | 18 #include "ui/events/keycodes/keyboard_codes.h" |
| 18 #include "ui/views/controls/webview/webview.h" | 19 #include "ui/views/controls/webview/webview.h" |
| 19 #include "ui/views/layout/fill_layout.h" | 20 #include "ui/views/layout/fill_layout.h" |
| 21 #include "ui/views/widget/native_widget_aura.h" |
| 20 #include "ui/views/widget/root_view.h" | 22 #include "ui/views/widget/root_view.h" |
| 21 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 22 #include "ui/web_dialogs/web_dialog_delegate.h" | 24 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 23 #include "ui/web_dialogs/web_dialog_ui.h" | 25 #include "ui/web_dialogs/web_dialog_ui.h" |
| 24 | 26 |
| 25 #if defined(USE_AURA) | |
| 26 #include "ui/events/event.h" | |
| 27 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | |
| 28 #include "ui/views/widget/native_widget_aura.h" | |
| 29 #endif | |
| 30 | |
| 31 using content::NativeWebKeyboardEvent; | 27 using content::NativeWebKeyboardEvent; |
| 32 using content::WebContents; | 28 using content::WebContents; |
| 33 using content::WebUIMessageHandler; | 29 using content::WebUIMessageHandler; |
| 34 using ui::WebDialogDelegate; | 30 using ui::WebDialogDelegate; |
| 35 using ui::WebDialogUI; | 31 using ui::WebDialogUI; |
| 36 using ui::WebDialogWebContentsDelegate; | 32 using ui::WebDialogWebContentsDelegate; |
| 37 | 33 |
| 38 namespace views { | 34 namespace views { |
| 39 | 35 |
| 40 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 // The contained web page wishes to resize itself. We let it do this because | 271 // The contained web page wishes to resize itself. We let it do this because |
| 276 // if it's a dialog we know about, we trust it not to be mean to the user. | 272 // if it's a dialog we know about, we trust it not to be mean to the user. |
| 277 GetWidget()->SetBounds(pos); | 273 GetWidget()->SetBounds(pos); |
| 278 } | 274 } |
| 279 | 275 |
| 280 // A simplified version of BrowserView::HandleKeyboardEvent(). | 276 // A simplified version of BrowserView::HandleKeyboardEvent(). |
| 281 // We don't handle global keyboard shortcuts here, but that's fine since | 277 // We don't handle global keyboard shortcuts here, but that's fine since |
| 282 // they're all browser-specific. (This may change in the future.) | 278 // they're all browser-specific. (This may change in the future.) |
| 283 void WebDialogView::HandleKeyboardEvent(content::WebContents* source, | 279 void WebDialogView::HandleKeyboardEvent(content::WebContents* source, |
| 284 const NativeWebKeyboardEvent& event) { | 280 const NativeWebKeyboardEvent& event) { |
| 285 #if defined(USE_AURA) | |
| 286 if (!event.os_event) | 281 if (!event.os_event) |
| 287 return; | 282 return; |
| 288 ui::KeyEvent aura_event(event.os_event->native_event(), false); | 283 ui::KeyEvent aura_event(event.os_event->native_event(), false); |
| 289 ui::EventHandler* event_handler = | 284 ui::EventHandler* event_handler = |
| 290 GetWidget()->native_widget()->GetEventHandler(); | 285 GetWidget()->native_widget()->GetEventHandler(); |
| 291 | 286 |
| 292 DCHECK(event_handler); | 287 DCHECK(event_handler); |
| 293 if (event_handler) | 288 if (event_handler) |
| 294 event_handler->OnKeyEvent(&aura_event); | 289 event_handler->OnKeyEvent(&aura_event); |
| 295 | 290 |
| 296 #elif defined(OS_WIN) | |
| 297 // Any unhandled keyboard/character messages should be defproced. | |
| 298 // This allows stuff like F10, etc to work correctly. | |
| 299 DefWindowProc(event.os_event.hwnd, event.os_event.message, | |
| 300 event.os_event.wParam, event.os_event.lParam); | |
| 301 #endif | |
| 302 } | 291 } |
| 303 | 292 |
| 304 void WebDialogView::CloseContents(WebContents* source) { | 293 void WebDialogView::CloseContents(WebContents* source) { |
| 305 close_contents_called_ = true; | 294 close_contents_called_ = true; |
| 306 bool close_dialog = false; | 295 bool close_dialog = false; |
| 307 OnCloseContents(source, &close_dialog); | 296 OnCloseContents(source, &close_dialog); |
| 308 if (close_dialog) | 297 if (close_dialog) |
| 309 OnDialogClosed(closed_via_webui_ ? dialog_close_retval_ : std::string()); | 298 OnDialogClosed(closed_via_webui_ ? dialog_close_retval_ : std::string()); |
| 310 } | 299 } |
| 311 | 300 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 web_contents->SetDelegate(this); | 347 web_contents->SetDelegate(this); |
| 359 | 348 |
| 360 // Set the delegate. This must be done before loading the page. See | 349 // Set the delegate. This must be done before loading the page. See |
| 361 // the comment above WebDialogUI in its header file for why. | 350 // the comment above WebDialogUI in its header file for why. |
| 362 WebDialogUI::SetDelegate(web_contents, this); | 351 WebDialogUI::SetDelegate(web_contents, this); |
| 363 | 352 |
| 364 web_view_->LoadInitialURL(GetDialogContentURL()); | 353 web_view_->LoadInitialURL(GetDialogContentURL()); |
| 365 } | 354 } |
| 366 | 355 |
| 367 } // namespace views | 356 } // namespace views |
| OLD | NEW |