Chromium Code Reviews| 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 "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" | 5 #include "chrome/browser/ui/webui/constrained_web_dialog_delegate_base.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/views/constrained_window_views.h" | 8 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 9 #include "content/public/browser/native_web_keyboard_event.h" | 9 #include "content/public/browser/native_web_keyboard_event.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 11 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
| 12 #include "ui/views/controls/webview/webview.h" | 12 #include "ui/views/controls/webview/webview.h" |
| 13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 14 #include "ui/views/window/dialog_delegate.h" | 14 #include "ui/views/window/dialog_delegate.h" |
| 15 #include "ui/web_dialogs/web_dialog_delegate.h" | 15 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 16 #include "ui/web_dialogs/web_dialog_ui.h" | 16 #include "ui/web_dialogs/web_dialog_ui.h" |
| 17 | 17 |
| 18 #if defined(USE_AURA) | |
| 19 #include "content/public/browser/render_widget_host_view.h" | |
| 20 #include "ui/aura/client/focus_change_observer.h" | |
| 21 #include "ui/aura/client/focus_client.h" | |
| 22 #endif | |
| 23 | |
| 18 using ui::WebDialogDelegate; | 24 using ui::WebDialogDelegate; |
| 19 using ui::WebDialogWebContentsDelegate; | 25 using ui::WebDialogWebContentsDelegate; |
| 20 | 26 |
| 21 namespace { | 27 namespace { |
| 22 | 28 |
| 23 class ConstrainedWebDialogDelegateViews | 29 class ConstrainedWebDialogDelegateViews |
| 24 : public ConstrainedWebDialogDelegateBase { | 30 : public ConstrainedWebDialogDelegateBase { |
| 25 public: | 31 public: |
| 26 ConstrainedWebDialogDelegateViews(content::BrowserContext* context, | 32 ConstrainedWebDialogDelegateViews(content::BrowserContext* context, |
| 27 WebDialogDelegate* delegate, | 33 WebDialogDelegate* delegate, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 52 | 58 |
| 53 private: | 59 private: |
| 54 // Converts keyboard events on the WebContents to accelerators. | 60 // Converts keyboard events on the WebContents to accelerators. |
| 55 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | 61 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; |
| 56 | 62 |
| 57 views::WebView* view_; | 63 views::WebView* view_; |
| 58 | 64 |
| 59 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); | 65 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViews); |
| 60 }; | 66 }; |
| 61 | 67 |
| 68 #if defined(USE_AURA) | |
| 69 // TODO(msw): Make this part of WebView? Modify various WebContentsDelegates? | |
| 70 class WebViewFocusHelper : public aura::client::FocusChangeObserver { | |
| 71 public: | |
| 72 explicit WebViewFocusHelper(views::WebView* web_view) | |
| 73 : web_view_(web_view), | |
| 74 native_view_(NULL), | |
| 75 focus_client_(NULL) { | |
| 76 if (web_view_ && web_view_->web_contents()) { | |
| 77 content::RenderWidgetHostView* host_view = | |
| 78 web_view_->web_contents()->GetRenderWidgetHostView(); | |
| 79 native_view_ = host_view ? host_view->GetNativeView() : NULL; | |
| 80 } | |
| 81 if (native_view_) | |
| 82 focus_client_ = aura::client::GetFocusClient(native_view_); | |
| 83 if (focus_client_) | |
| 84 focus_client_->AddObserver(this); | |
| 85 } | |
| 86 | |
| 87 virtual ~WebViewFocusHelper() { | |
| 88 if (focus_client_) | |
| 89 focus_client_->RemoveObserver(this); | |
| 90 } | |
| 91 | |
| 92 virtual void OnWindowFocused(aura::Window* gained_focus, | |
| 93 aura::Window* lost_focus) { | |
| 94 if (gained_focus == native_view_ && !web_view_->HasFocus()) | |
| 95 web_view_->RequestFocus(); | |
| 96 } | |
| 97 | |
| 98 private: | |
| 99 views::WebView* web_view_; | |
| 100 gfx::NativeView native_view_; | |
|
Ben Goodger (Google)
2014/07/31 18:20:15
may as well just use aura::Window* here
msw
2014/07/31 18:35:14
Done.
| |
| 101 aura::client::FocusClient* focus_client_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(WebViewFocusHelper); | |
| 104 }; | |
| 105 #endif | |
| 106 | |
| 62 class ConstrainedWebDialogDelegateViewViews | 107 class ConstrainedWebDialogDelegateViewViews |
| 63 : public views::WebView, | 108 : public views::WebView, |
| 64 public ConstrainedWebDialogDelegate, | 109 public ConstrainedWebDialogDelegate, |
| 65 public views::WidgetDelegate { | 110 public views::WidgetDelegate { |
| 66 public: | 111 public: |
| 67 ConstrainedWebDialogDelegateViewViews( | 112 ConstrainedWebDialogDelegateViewViews( |
| 68 content::BrowserContext* browser_context, | 113 content::BrowserContext* browser_context, |
| 69 WebDialogDelegate* delegate, | 114 WebDialogDelegate* delegate, |
| 70 WebDialogWebContentsDelegate* tab_delegate) | 115 WebDialogWebContentsDelegate* tab_delegate) |
| 71 : views::WebView(browser_context), | 116 : views::WebView(browser_context), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 gfx::Size size; | 185 gfx::Size size; |
| 141 if (!impl_->closed_via_webui()) | 186 if (!impl_->closed_via_webui()) |
| 142 GetWebDialogDelegate()->GetDialogSize(&size); | 187 GetWebDialogDelegate()->GetDialogSize(&size); |
| 143 return size; | 188 return size; |
| 144 } | 189 } |
| 145 virtual gfx::Size GetMinimumSize() const OVERRIDE { | 190 virtual gfx::Size GetMinimumSize() const OVERRIDE { |
| 146 // Return an empty size so that we can be made smaller. | 191 // Return an empty size so that we can be made smaller. |
| 147 return gfx::Size(); | 192 return gfx::Size(); |
| 148 } | 193 } |
| 149 | 194 |
| 195 void OnShow() { | |
| 196 #if defined(USE_AURA) | |
| 197 web_view_focus_helper_.reset(new WebViewFocusHelper(this)); | |
| 198 #endif | |
| 199 } | |
| 200 | |
| 150 private: | 201 private: |
| 151 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; | 202 scoped_ptr<ConstrainedWebDialogDelegateViews> impl_; |
| 203 #if defined(USE_AURA) | |
| 204 scoped_ptr<WebViewFocusHelper> web_view_focus_helper_; | |
| 205 #endif | |
| 152 | 206 |
| 153 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); | 207 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); |
| 154 }; | 208 }; |
| 155 | 209 |
| 156 } // namespace | 210 } // namespace |
| 157 | 211 |
| 158 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( | 212 ConstrainedWebDialogDelegate* CreateConstrainedWebDialog( |
| 159 content::BrowserContext* browser_context, | 213 content::BrowserContext* browser_context, |
| 160 WebDialogDelegate* delegate, | 214 WebDialogDelegate* delegate, |
| 161 WebDialogWebContentsDelegate* tab_delegate, | 215 WebDialogWebContentsDelegate* tab_delegate, |
| 162 content::WebContents* web_contents) { | 216 content::WebContents* web_contents) { |
| 163 ConstrainedWebDialogDelegateViewViews* dialog = | 217 ConstrainedWebDialogDelegateViewViews* dialog = |
| 164 new ConstrainedWebDialogDelegateViewViews( | 218 new ConstrainedWebDialogDelegateViewViews( |
| 165 browser_context, delegate, tab_delegate); | 219 browser_context, delegate, tab_delegate); |
| 166 ShowWebModalDialogViews(dialog, web_contents); | 220 ShowWebModalDialogViews(dialog, web_contents); |
| 221 dialog->OnShow(); | |
| 167 return dialog; | 222 return dialog; |
| 168 } | 223 } |
| OLD | NEW |