Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/views/extensions/chooser_dialog_view.h" | 5 #include "chrome/browser/ui/views/extensions/chooser_dialog_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/chooser_controller/chooser_controller.h" | 8 #include "chrome/browser/chooser_controller/chooser_controller.h" |
| 9 #include "chrome/browser/extensions/chrome_extension_chooser_dialog.h" | 9 #include "chrome/browser/extensions/chrome_extension_chooser_dialog.h" |
| 10 #include "chrome/browser/ui/views/chooser_content_view.h" | 10 #include "chrome/browser/ui/views/chooser_content_view.h" |
| 11 #include "components/constrained_window/constrained_window_views.h" | 11 #include "components/constrained_window/constrained_window_views.h" |
| 12 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 12 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "ui/gfx/geometry/insets.h" | |
| 14 #include "ui/views/controls/link.h" | 15 #include "ui/views/controls/link.h" |
| 15 #include "ui/views/controls/styled_label.h" | 16 #include "ui/views/controls/styled_label.h" |
| 17 #include "ui/views/layout/layout_constants.h" | |
| 16 #include "ui/views/window/dialog_client_view.h" | 18 #include "ui/views/window/dialog_client_view.h" |
| 17 | 19 |
| 18 ChooserDialogView::ChooserDialogView( | 20 ChooserDialogView::ChooserDialogView( |
| 19 std::unique_ptr<ChooserController> chooser_controller) { | 21 std::unique_ptr<ChooserController> chooser_controller) { |
| 20 // ------------------------------------ | 22 // ------------------------------------ |
| 21 // | Chooser dialog title | | 23 // | Chooser dialog title | |
| 22 // | -------------------------------- | | 24 // | -------------------------------- | |
| 23 // | | option 0 | | | 25 // | | option 0 | | |
| 24 // | | option 1 | | | 26 // | | option 1 | | |
| 25 // | | option 2 | | | 27 // | | option 2 | | |
| 26 // | | | | | 28 // | | | | |
| 27 // | | | | | 29 // | | | | |
| 28 // | | | | | 30 // | | | | |
| 29 // | -------------------------------- | | 31 // | -------------------------------- | |
| 30 // | [ Connect ] [ Cancel ] | | 32 // | [ Connect ] [ Cancel ] | |
| 31 // |----------------------------------| | 33 // |----------------------------------| |
| 32 // | Get help | | 34 // | Get help | |
| 33 // ------------------------------------ | 35 // ------------------------------------ |
| 34 | 36 |
| 35 DCHECK(chooser_controller); | 37 DCHECK(chooser_controller); |
| 36 chooser_content_view_ = | 38 footnote_link_.reset(new views::StyledLabel(base::string16(), nullptr)); |
|
sky
2016/11/09 17:55:47
Use MakeUnique (see threads on chromium-dev for re
juncai
2016/11/09 20:25:02
Done.
| |
| 37 new ChooserContentView(this, std::move(chooser_controller)); | 39 chooser_content_view_ = new ChooserContentView( |
| 40 this, std::move(chooser_controller), footnote_link_.get()); | |
| 38 } | 41 } |
| 39 | 42 |
| 40 ChooserDialogView::~ChooserDialogView() {} | 43 ChooserDialogView::~ChooserDialogView() {} |
| 41 | 44 |
| 42 base::string16 ChooserDialogView::GetWindowTitle() const { | 45 base::string16 ChooserDialogView::GetWindowTitle() const { |
| 43 return chooser_content_view_->GetWindowTitle(); | 46 return chooser_content_view_->GetWindowTitle(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 bool ChooserDialogView::ShouldShowCloseButton() const { | 49 bool ChooserDialogView::ShouldShowCloseButton() const { |
| 47 return false; | 50 return false; |
| 48 } | 51 } |
| 49 | 52 |
| 50 ui::ModalType ChooserDialogView::GetModalType() const { | 53 ui::ModalType ChooserDialogView::GetModalType() const { |
| 51 return ui::MODAL_TYPE_CHILD; | 54 return ui::MODAL_TYPE_CHILD; |
| 52 } | 55 } |
| 53 | 56 |
| 54 base::string16 ChooserDialogView::GetDialogButtonLabel( | 57 base::string16 ChooserDialogView::GetDialogButtonLabel( |
| 55 ui::DialogButton button) const { | 58 ui::DialogButton button) const { |
| 56 return chooser_content_view_->GetDialogButtonLabel(button); | 59 return chooser_content_view_->GetDialogButtonLabel(button); |
| 57 } | 60 } |
| 58 | 61 |
| 59 bool ChooserDialogView::IsDialogButtonEnabled(ui::DialogButton button) const { | 62 bool ChooserDialogView::IsDialogButtonEnabled(ui::DialogButton button) const { |
| 60 return chooser_content_view_->IsDialogButtonEnabled(button); | 63 return chooser_content_view_->IsDialogButtonEnabled(button); |
| 61 } | 64 } |
| 62 | 65 |
| 63 views::View* ChooserDialogView::CreateFootnoteView() { | 66 views::View* ChooserDialogView::CreateFootnoteView() { |
| 64 return chooser_content_view_->CreateFootnoteView(); | 67 DCHECK(footnote_link_); |
| 68 return footnote_link_.release(); | |
| 69 } | |
| 70 | |
| 71 views::ClientView* ChooserDialogView::CreateClientView(views::Widget* widget) { | |
| 72 views::DialogClientView* client = | |
| 73 new views::DialogClientView(widget, GetContentsView()); | |
| 74 client->set_button_row_insets(gfx::Insets()); | |
| 75 return client; | |
| 76 } | |
| 77 | |
| 78 views::NonClientFrameView* ChooserDialogView::CreateNonClientFrameView( | |
| 79 views::Widget* widget) { | |
| 80 DCHECK(ShouldUseCustomFrame()); | |
|
sky
2016/11/09 17:55:47
Please document why there is the DCHECK. I'm think
juncai
2016/11/09 20:25:02
Done.
| |
| 81 return views::DialogDelegate::CreateDialogFrameView( | |
| 82 widget, gfx::Insets(views::kPanelVertMargin, views::kPanelHorizMargin, | |
| 83 views::kPanelVertMargin, views::kPanelHorizMargin)); | |
| 65 } | 84 } |
| 66 | 85 |
| 67 bool ChooserDialogView::Accept() { | 86 bool ChooserDialogView::Accept() { |
| 68 chooser_content_view_->Accept(); | 87 chooser_content_view_->Accept(); |
| 69 return true; | 88 return true; |
| 70 } | 89 } |
| 71 | 90 |
| 72 bool ChooserDialogView::Cancel() { | 91 bool ChooserDialogView::Cancel() { |
| 73 chooser_content_view_->Cancel(); | 92 chooser_content_view_->Cancel(); |
| 74 return true; | 93 return true; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 104 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 123 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 105 DCHECK(chooser_controller); | 124 DCHECK(chooser_controller); |
| 106 | 125 |
| 107 web_modal::WebContentsModalDialogManager* manager = | 126 web_modal::WebContentsModalDialogManager* manager = |
| 108 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_); | 127 web_modal::WebContentsModalDialogManager::FromWebContents(web_contents_); |
| 109 if (manager) { | 128 if (manager) { |
| 110 constrained_window::ShowWebModalDialogViews( | 129 constrained_window::ShowWebModalDialogViews( |
| 111 new ChooserDialogView(std::move(chooser_controller)), web_contents_); | 130 new ChooserDialogView(std::move(chooser_controller)), web_contents_); |
| 112 } | 131 } |
| 113 } | 132 } |
| OLD | NEW |