| 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" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 is_attempting_close_dialog_(false), | 47 is_attempting_close_dialog_(false), |
| 48 before_unload_fired_(false), | 48 before_unload_fired_(false), |
| 49 closed_via_webui_(false), | 49 closed_via_webui_(false), |
| 50 close_contents_called_(false) { | 50 close_contents_called_(false) { |
| 51 web_view_->set_allow_accelerators(true); | 51 web_view_->set_allow_accelerators(true); |
| 52 AddChildView(web_view_); | 52 AddChildView(web_view_); |
| 53 set_contents_view(web_view_); | 53 set_contents_view(web_view_); |
| 54 SetLayoutManager(new views::FillLayout); | 54 SetLayoutManager(new views::FillLayout); |
| 55 // Pressing the ESC key will close the dialog. | 55 // Pressing the ESC key will close the dialog. |
| 56 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 56 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 57 |
| 58 // For Chrome OS/CFM, Shift + Browser Back is mapped to hangup button, which |
| 59 // can be used to close the web dialog. |
| 60 ui::Accelerator shift_browser_back(ui::VKEY_BROWSER_BACK, ui::EF_SHIFT_DOWN); |
| 61 if (AdditionalAccelerator(shift_browser_back)) |
| 62 AddAccelerator(shift_browser_back); |
| 57 } | 63 } |
| 58 | 64 |
| 59 WebDialogView::~WebDialogView() { | 65 WebDialogView::~WebDialogView() { |
| 60 } | 66 } |
| 61 | 67 |
| 62 content::WebContents* WebDialogView::web_contents() { | 68 content::WebContents* WebDialogView::web_contents() { |
| 63 return web_view_->web_contents(); | 69 return web_view_->web_contents(); |
| 64 } | 70 } |
| 65 | 71 |
| 66 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
| 67 // WebDialogView, views::View implementation: | 73 // WebDialogView, views::View implementation: |
| 68 | 74 |
| 69 gfx::Size WebDialogView::GetPreferredSize() const { | 75 gfx::Size WebDialogView::GetPreferredSize() const { |
| 70 gfx::Size out; | 76 gfx::Size out; |
| 71 if (delegate_) | 77 if (delegate_) |
| 72 delegate_->GetDialogSize(&out); | 78 delegate_->GetDialogSize(&out); |
| 73 return out; | 79 return out; |
| 74 } | 80 } |
| 75 | 81 |
| 76 gfx::Size WebDialogView::GetMinimumSize() const { | 82 gfx::Size WebDialogView::GetMinimumSize() const { |
| 77 gfx::Size out; | 83 gfx::Size out; |
| 78 if (delegate_) | 84 if (delegate_) |
| 79 delegate_->GetMinimumDialogSize(&out); | 85 delegate_->GetMinimumDialogSize(&out); |
| 80 return out; | 86 return out; |
| 81 } | 87 } |
| 82 | 88 |
| 83 bool WebDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 89 bool WebDialogView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 84 // Pressing ESC closes the dialog. | 90 DCHECK(ui::VKEY_ESCAPE == accelerator.key_code() || |
| 85 DCHECK_EQ(ui::VKEY_ESCAPE, accelerator.key_code()); | 91 AdditionalAccelerator(accelerator)); |
| 86 if (GetWidget()) | 92 if (GetWidget()) |
| 87 GetWidget()->Close(); | 93 GetWidget()->Close(); |
| 88 return true; | 94 return true; |
| 89 } | 95 } |
| 90 | 96 |
| 91 void WebDialogView::ViewHierarchyChanged( | 97 void WebDialogView::ViewHierarchyChanged( |
| 92 const ViewHierarchyChangedDetails& details) { | 98 const ViewHierarchyChangedDetails& details) { |
| 93 if (details.is_add && GetWidget()) | 99 if (details.is_add && GetWidget()) |
| 94 InitDialog(); | 100 InitDialog(); |
| 95 } | 101 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 return true; | 264 return true; |
| 259 } | 265 } |
| 260 | 266 |
| 261 bool WebDialogView::HandleContextMenu( | 267 bool WebDialogView::HandleContextMenu( |
| 262 const content::ContextMenuParams& params) { | 268 const content::ContextMenuParams& params) { |
| 263 if (delegate_) | 269 if (delegate_) |
| 264 return delegate_->HandleContextMenu(params); | 270 return delegate_->HandleContextMenu(params); |
| 265 return WebDialogWebContentsDelegate::HandleContextMenu(params); | 271 return WebDialogWebContentsDelegate::HandleContextMenu(params); |
| 266 } | 272 } |
| 267 | 273 |
| 274 bool WebDialogView::AdditionalAccelerator( |
| 275 const ui::Accelerator& accelerator) const { |
| 276 if (delegate_) |
| 277 return delegate_->AdditionalAccelerator(accelerator); |
| 278 return false; |
| 279 } |
| 280 |
| 268 //////////////////////////////////////////////////////////////////////////////// | 281 //////////////////////////////////////////////////////////////////////////////// |
| 269 // content::WebContentsDelegate implementation: | 282 // content::WebContentsDelegate implementation: |
| 270 | 283 |
| 271 void WebDialogView::MoveContents(WebContents* source, const gfx::Rect& pos) { | 284 void WebDialogView::MoveContents(WebContents* source, const gfx::Rect& pos) { |
| 272 // The contained web page wishes to resize itself. We let it do this because | 285 // The contained web page wishes to resize itself. We let it do this because |
| 273 // if it's a dialog we know about, we trust it not to be mean to the user. | 286 // if it's a dialog we know about, we trust it not to be mean to the user. |
| 274 GetWidget()->SetBounds(pos); | 287 GetWidget()->SetBounds(pos); |
| 275 } | 288 } |
| 276 | 289 |
| 277 // A simplified version of BrowserView::HandleKeyboardEvent(). | 290 // A simplified version of BrowserView::HandleKeyboardEvent(). |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 web_contents->SetDelegate(this); | 373 web_contents->SetDelegate(this); |
| 361 | 374 |
| 362 // Set the delegate. This must be done before loading the page. See | 375 // Set the delegate. This must be done before loading the page. See |
| 363 // the comment above WebDialogUI in its header file for why. | 376 // the comment above WebDialogUI in its header file for why. |
| 364 WebDialogUI::SetDelegate(web_contents, this); | 377 WebDialogUI::SetDelegate(web_contents, this); |
| 365 | 378 |
| 366 web_view_->LoadInitialURL(GetDialogContentURL()); | 379 web_view_->LoadInitialURL(GetDialogContentURL()); |
| 367 } | 380 } |
| 368 | 381 |
| 369 } // namespace views | 382 } // namespace views |
| OLD | NEW |