Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/webshare/target_picker_view.h" | |
| 6 | |
| 7 #include "chrome/grit/generated_resources.h" | |
| 8 #include "components/constrained_window/constrained_window_views.h" | |
| 9 #include "ui/base/l10n/l10n_util.h" | |
| 10 #include "ui/gfx/native_widget_types.h" | |
| 11 #include "ui/views/controls/label.h" | |
| 12 #include "ui/views/controls/table/table_view.h" | |
| 13 #include "ui/views/layout/box_layout.h" | |
| 14 #include "ui/views/layout/layout_constants.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 int kDialogWidth = 500; | |
| 19 int kDialogHeight = 400; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 namespace chrome { | |
| 24 | |
| 25 void ShowWebShareTargetPickerDialog( | |
| 26 gfx::NativeWindow parent_window, | |
| 27 const std::vector<base::string16>& targets, | |
| 28 const base::Callback<void(bool)>& callback) { | |
| 29 constrained_window::CreateBrowserModalDialogViews( | |
| 30 new WebShareTargetPickerView(targets, callback), parent_window) | |
| 31 ->Show(); | |
| 32 } | |
| 33 | |
| 34 } // namespace chrome | |
| 35 | |
| 36 WebShareTargetPickerView::WebShareTargetPickerView( | |
| 37 const std::vector<base::string16>& targets, | |
| 38 const base::Callback<void(bool)>& close_callback) | |
| 39 : targets_(targets), close_callback_(close_callback) { | |
| 40 InitControls(); | |
| 41 } | |
| 42 | |
| 43 WebShareTargetPickerView::~WebShareTargetPickerView() {} | |
| 44 | |
| 45 void WebShareTargetPickerView::InitControls() { | |
| 46 views::BoxLayout* layout = new views::BoxLayout( | |
| 47 views::BoxLayout::kVertical, views::kPanelHorizMargin, | |
| 48 views::kPanelVertMargin, views::kRelatedControlVerticalSpacing); | |
| 49 SetLayoutManager(layout); | |
| 50 | |
| 51 views::Label* overview_label = new views::Label( | |
| 52 l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_LABEL)); | |
| 53 AddChildView(overview_label); | |
| 54 | |
| 55 std::vector<ui::TableColumn> table_columns{ui::TableColumn()}; | |
| 56 views::TableView* table = | |
| 57 new views::TableView(this, table_columns, views::TEXT_ONLY, true); | |
| 58 // Select the first row. | |
| 59 if (RowCount() > 0) | |
|
sky
2017/01/23 16:38:55
I would think this would be a DCHECK, otherwise wh
Matt Giuca
2017/01/30 04:07:12
There might not be any targets, so this can't DCHE
| |
| 60 table->Select(0); | |
| 61 | |
| 62 // Create the table parent (a ScrollView which includes the scroll bars and | |
| 63 // border). We add this parent (not the table itself) to the dialog. | |
| 64 views::View* table_parent = table->CreateParentIfNecessary(); | |
| 65 AddChildView(table_parent); | |
| 66 // Make the table expand to fill the space. | |
| 67 layout->SetFlexForView(table_parent, 1); | |
| 68 } | |
| 69 | |
| 70 gfx::Size WebShareTargetPickerView::GetPreferredSize() const { | |
| 71 return gfx::Size(kDialogWidth, kDialogHeight); | |
| 72 } | |
| 73 | |
| 74 ui::ModalType WebShareTargetPickerView::GetModalType() const { | |
| 75 return ui::MODAL_TYPE_WINDOW; | |
| 76 } | |
| 77 | |
| 78 base::string16 WebShareTargetPickerView::GetWindowTitle() const { | |
| 79 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_TITLE); | |
| 80 } | |
| 81 | |
| 82 bool WebShareTargetPickerView::Cancel() { | |
| 83 if (!close_callback_.is_null()) | |
| 84 close_callback_.Run(false); | |
| 85 | |
| 86 return true; | |
| 87 } | |
| 88 | |
| 89 bool WebShareTargetPickerView::Accept() { | |
| 90 if (!close_callback_.is_null()) | |
| 91 close_callback_.Run(true); | |
| 92 | |
| 93 return true; | |
| 94 } | |
| 95 | |
| 96 base::string16 WebShareTargetPickerView::GetDialogButtonLabel( | |
| 97 ui::DialogButton button) const { | |
| 98 if (button == ui::DIALOG_BUTTON_OK) | |
| 99 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_COMMIT); | |
| 100 | |
| 101 return views::DialogDelegateView::GetDialogButtonLabel(button); | |
| 102 } | |
| 103 | |
| 104 int WebShareTargetPickerView::RowCount() { | |
| 105 return targets_.size(); | |
| 106 } | |
| 107 | |
| 108 base::string16 WebShareTargetPickerView::GetText(int row, int /*column_id*/) { | |
| 109 return targets_[row]; | |
| 110 } | |
| 111 | |
| 112 void WebShareTargetPickerView::SetObserver(ui::TableModelObserver* observer) {} | |
| OLD | NEW |