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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" | 12 #include "chrome/browser/ui/webui/chrome_web_contents_handler.h" |
| 13 #include "components/constrained_window/constrained_window_views.h" | 13 #include "components/constrained_window/constrained_window_views.h" |
| 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 14 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 15 #include "content/public/browser/native_web_keyboard_event.h" | 15 #include "content/public/browser/native_web_keyboard_event.h" |
| 16 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 18 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
| 19 #include "ui/views/controls/webview/webview.h" | 19 #include "ui/views/controls/webview/webview.h" |
| 20 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/window/dialog_delegate.h" | 22 #include "ui/views/window/dialog_delegate.h" |
| 23 #include "ui/web_dialogs/web_dialog_delegate.h" | 23 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 24 #include "ui/web_dialogs/web_dialog_ui.h" | 24 #include "ui/web_dialogs/web_dialog_ui.h" |
| 25 | 25 |
| 26 #if defined(OS_WIN) | |
| 27 #include "ui/base/win/shell.h" | |
| 28 #endif | |
| 29 | |
| 26 namespace { | 30 namespace { |
| 27 | 31 |
| 28 // WebContentsObserver that tracks the lifetime of the WebContents to avoid | 32 // WebContentsObserver that tracks the lifetime of the WebContents to avoid |
| 29 // potential use after destruction. | 33 // potential use after destruction. |
| 30 class InitiatorWebContentsObserver | 34 class InitiatorWebContentsObserver |
| 31 : public content::WebContentsObserver { | 35 : public content::WebContentsObserver { |
| 32 public: | 36 public: |
| 33 explicit InitiatorWebContentsObserver(content::WebContents* web_contents) | 37 explicit InitiatorWebContentsObserver(content::WebContents* web_contents) |
| 34 : content::WebContentsObserver(web_contents) { | 38 : content::WebContentsObserver(web_contents) { |
| 35 } | 39 } |
| 36 | 40 |
| 37 private: | 41 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(InitiatorWebContentsObserver); | 42 DISALLOW_COPY_AND_ASSIGN(InitiatorWebContentsObserver); |
| 39 }; | 43 }; |
| 40 | 44 |
| 41 class WebDialogWebContentsDelegateViews | 45 class WebDialogWebContentsDelegateViews |
| 42 : public ui::WebDialogWebContentsDelegate { | 46 : public ui::WebDialogWebContentsDelegate { |
| 43 public: | 47 public: |
| 44 WebDialogWebContentsDelegateViews(content::BrowserContext* browser_context, | 48 WebDialogWebContentsDelegateViews(content::BrowserContext* browser_context, |
| 45 InitiatorWebContentsObserver* observer, | 49 InitiatorWebContentsObserver* observer, |
| 46 views::WebView* web_view) | 50 views::WebView* web_view) |
| 47 : ui::WebDialogWebContentsDelegate(browser_context, | 51 : ui::WebDialogWebContentsDelegate(browser_context, |
| 48 new ChromeWebContentsHandler()), | 52 new ChromeWebContentsHandler()), |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 class ConstrainedWebDialogDelegateViewViews | 141 class ConstrainedWebDialogDelegateViewViews |
| 138 : public views::WebView, | 142 : public views::WebView, |
| 139 public ConstrainedWebDialogDelegate, | 143 public ConstrainedWebDialogDelegate, |
| 140 public views::WidgetDelegate { | 144 public views::WidgetDelegate { |
| 141 public: | 145 public: |
| 142 ConstrainedWebDialogDelegateViewViews( | 146 ConstrainedWebDialogDelegateViewViews( |
| 143 content::BrowserContext* browser_context, | 147 content::BrowserContext* browser_context, |
| 144 ui::WebDialogDelegate* delegate, | 148 ui::WebDialogDelegate* delegate, |
| 145 content::WebContents* web_contents, | 149 content::WebContents* web_contents, |
| 146 const gfx::Size& min_size, | 150 const gfx::Size& min_size, |
| 147 const gfx::Size& max_size) | 151 const gfx::Size& max_size, |
| 152 bool independent_bounds) | |
|
Mike Wittman
2016/08/16 01:07:07
is_nonclipped, to be consistent with the terminolo
rbpotter
2016/08/16 18:49:44
Done. Should the naming on the native windows (kHa
| |
| 148 : views::WebView(browser_context), | 153 : views::WebView(browser_context), |
| 149 initiator_observer_(web_contents), | 154 initiator_observer_(web_contents), |
| 150 impl_(new ConstrainedWebDialogDelegateViews(browser_context, delegate, | 155 impl_(new ConstrainedWebDialogDelegateViews(browser_context, |
| 156 delegate, | |
| 151 &initiator_observer_, | 157 &initiator_observer_, |
| 152 this)), | 158 this)), |
| 153 min_size_(min_size), | 159 min_size_(min_size), |
| 154 max_size_(max_size) { | 160 max_size_(max_size), |
| 161 independent_bounds_(independent_bounds) { | |
| 155 SetWebContents(GetWebContents()); | 162 SetWebContents(GetWebContents()); |
| 156 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 163 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 157 if (!max_size_.IsEmpty()) | 164 if (!max_size_.IsEmpty()) |
| 158 EnableAutoResize(); | 165 EnableAutoResize(); |
| 159 } | 166 } |
| 160 ~ConstrainedWebDialogDelegateViewViews() override {} | 167 ~ConstrainedWebDialogDelegateViewViews() override {} |
| 161 | 168 |
| 162 // ConstrainedWebDialogDelegate: | 169 // ConstrainedWebDialogDelegate: |
| 163 const ui::WebDialogDelegate* GetWebDialogDelegate() const override { | 170 const ui::WebDialogDelegate* GetWebDialogDelegate() const override { |
| 164 return impl_->GetWebDialogDelegate(); | 171 return impl_->GetWebDialogDelegate(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 if (!max_size_.IsEmpty()) | 238 if (!max_size_.IsEmpty()) |
| 232 EnableAutoResize(); | 239 EnableAutoResize(); |
| 233 } | 240 } |
| 234 void RenderViewHostChanged(content::RenderViewHost* old_host, | 241 void RenderViewHostChanged(content::RenderViewHost* old_host, |
| 235 content::RenderViewHost* new_host) override { | 242 content::RenderViewHost* new_host) override { |
| 236 if (!max_size_.IsEmpty()) | 243 if (!max_size_.IsEmpty()) |
| 237 EnableAutoResize(); | 244 EnableAutoResize(); |
| 238 } | 245 } |
| 239 void DocumentOnLoadCompletedInMainFrame() override { | 246 void DocumentOnLoadCompletedInMainFrame() override { |
| 240 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) { | 247 if (!max_size_.IsEmpty() && initiator_observer_.web_contents()) { |
| 241 web_modal::WebContentsModalDialogManager::FromWebContents( | 248 if (GetIndependentBounds()) { |
|
Mike Wittman
2016/08/16 01:07:07
the member variable can be used directly since it'
rbpotter
2016/08/16 18:49:44
Done.
| |
| 242 initiator_observer_.web_contents()) | 249 web_modal::WebContentsModalDialogManager::FromWebContents( |
| 243 ->ShowModalDialog(GetWidget()->GetNativeWindow()); | 250 initiator_observer_.web_contents()) |
| 251 ->ShowNonClippedModalDialog(GetWidget()->GetNativeWindow()); | |
| 252 } else { | |
| 253 web_modal::WebContentsModalDialogManager::FromWebContents( | |
| 254 initiator_observer_.web_contents()) | |
| 255 ->ShowModalDialog(GetWidget()->GetNativeWindow()); | |
| 256 } | |
| 244 } | 257 } |
| 245 } | 258 } |
| 246 | 259 |
| 247 private: | 260 private: |
| 248 void EnableAutoResize() { | 261 void EnableAutoResize() { |
| 249 content::RenderViewHost* render_view_host = | 262 content::RenderViewHost* render_view_host = |
| 250 GetWebContents()->GetRenderViewHost(); | 263 GetWebContents()->GetRenderViewHost(); |
| 251 render_view_host->EnableAutoResize(min_size_, max_size_); | 264 render_view_host->EnableAutoResize(min_size_, max_size_); |
| 252 } | 265 } |
| 253 | 266 |
| 267 bool GetIndependentBounds() { return independent_bounds_; } | |
| 268 | |
| 254 InitiatorWebContentsObserver initiator_observer_; | 269 InitiatorWebContentsObserver initiator_observer_; |
| 255 | 270 |
| 256 std::unique_ptr<ConstrainedWebDialogDelegateViews> impl_; | 271 std::unique_ptr<ConstrainedWebDialogDelegateViews> impl_; |
| 257 | 272 |
| 258 // Minimum and maximum sizes to determine dialog bounds for auto-resizing. | 273 // Minimum and maximum sizes to determine dialog bounds for auto-resizing. |
| 259 const gfx::Size min_size_; | 274 const gfx::Size min_size_; |
| 260 const gfx::Size max_size_; | 275 const gfx::Size max_size_; |
| 261 | 276 |
| 277 // If true, dialog has bounds that are not constrained by the parent window's | |
| 278 // bounds, so can extend outside of the parent window when resized | |
| 279 bool independent_bounds_; | |
|
Mike Wittman
2016/08/16 01:07:07
const
rbpotter
2016/08/16 18:49:44
Done.
| |
| 280 | |
| 262 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); | 281 DISALLOW_COPY_AND_ASSIGN(ConstrainedWebDialogDelegateViewViews); |
| 263 }; | 282 }; |
| 264 | 283 |
| 265 } // namespace | 284 } // namespace |
| 266 | 285 |
| 267 ConstrainedWebDialogDelegate* ShowConstrainedWebDialog( | 286 ConstrainedWebDialogDelegate* ShowConstrainedWebDialog( |
| 268 content::BrowserContext* browser_context, | 287 content::BrowserContext* browser_context, |
| 269 ui::WebDialogDelegate* delegate, | 288 ui::WebDialogDelegate* delegate, |
| 270 content::WebContents* web_contents) { | 289 content::WebContents* web_contents) { |
| 271 ConstrainedWebDialogDelegateViewViews* dialog = | 290 ConstrainedWebDialogDelegateViewViews* dialog = |
| 272 new ConstrainedWebDialogDelegateViewViews( | 291 new ConstrainedWebDialogDelegateViewViews(browser_context, delegate, |
| 273 browser_context, delegate, web_contents, | 292 web_contents, gfx::Size(), |
| 274 gfx::Size(), gfx::Size()); | 293 gfx::Size(), false); |
| 275 constrained_window::ShowWebModalDialogViews(dialog, web_contents); | 294 constrained_window::ShowWebModalDialogViews(dialog, web_contents); |
| 276 return dialog; | 295 return dialog; |
| 277 } | 296 } |
| 278 | 297 |
| 298 ConstrainedWebDialogDelegate* ShowNonClippedConstrainedWebDialog( | |
| 299 content::BrowserContext* browser_context, | |
| 300 ui::WebDialogDelegate* delegate, | |
| 301 content::WebContents* web_contents) { | |
| 302 ConstrainedWebDialogDelegateViewViews* dialog = | |
| 303 new ConstrainedWebDialogDelegateViewViews(browser_context, delegate, | |
| 304 web_contents, gfx::Size(), | |
| 305 gfx::Size(), true); | |
| 306 constrained_window::ShowNonClippedWebModalDialogViews(dialog, web_contents); | |
| 307 return dialog; | |
| 308 } | |
| 309 | |
| 279 ConstrainedWebDialogDelegate* ShowConstrainedWebDialogWithAutoResize( | 310 ConstrainedWebDialogDelegate* ShowConstrainedWebDialogWithAutoResize( |
| 280 content::BrowserContext* browser_context, | 311 content::BrowserContext* browser_context, |
| 281 ui::WebDialogDelegate* delegate, | 312 ui::WebDialogDelegate* delegate, |
| 282 content::WebContents* web_contents, | 313 content::WebContents* web_contents, |
| 283 const gfx::Size& min_size, | 314 const gfx::Size& min_size, |
| 284 const gfx::Size& max_size) { | 315 const gfx::Size& max_size) { |
| 285 DCHECK(!min_size.IsEmpty()); | 316 DCHECK(!min_size.IsEmpty()); |
| 286 DCHECK(!max_size.IsEmpty()); | 317 DCHECK(!max_size.IsEmpty()); |
| 287 ConstrainedWebDialogDelegateViewViews* dialog = | 318 ConstrainedWebDialogDelegateViewViews* dialog = |
| 288 new ConstrainedWebDialogDelegateViewViews( | 319 new ConstrainedWebDialogDelegateViewViews( |
| 289 browser_context, delegate, web_contents, | 320 browser_context, delegate, web_contents, min_size, max_size, false); |
| 290 min_size, max_size); | |
| 291 constrained_window::CreateWebModalDialogViews(dialog, web_contents); | 321 constrained_window::CreateWebModalDialogViews(dialog, web_contents); |
| 292 return dialog; | 322 return dialog; |
| 293 } | 323 } |
| OLD | NEW |