| 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) |
| 60 table->Select(0); |
| 61 // Manually create the "table parent" (which includes the border and scroll |
| 62 // bars and border). We add this parent (not the table itself) to the dialog. |
| 63 views::View* table_parent = table->CreateParentIfNecessary(); |
| 64 AddChildView(table_parent); |
| 65 // Make the table expand to fill the space. |
| 66 layout->SetFlexForView(table_parent, 1); |
| 67 } |
| 68 |
| 69 gfx::Size WebShareTargetPickerView::GetPreferredSize() const { |
| 70 return gfx::Size(kDialogWidth, kDialogHeight); |
| 71 } |
| 72 |
| 73 ui::ModalType WebShareTargetPickerView::GetModalType() const { |
| 74 return ui::MODAL_TYPE_WINDOW; |
| 75 } |
| 76 |
| 77 base::string16 WebShareTargetPickerView::GetWindowTitle() const { |
| 78 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_TITLE); |
| 79 } |
| 80 |
| 81 bool WebShareTargetPickerView::Cancel() { |
| 82 if (!close_callback_.is_null()) |
| 83 close_callback_.Run(false); |
| 84 |
| 85 return true; |
| 86 } |
| 87 |
| 88 bool WebShareTargetPickerView::Accept() { |
| 89 if (!close_callback_.is_null()) |
| 90 close_callback_.Run(true); |
| 91 |
| 92 return true; |
| 93 } |
| 94 |
| 95 base::string16 WebShareTargetPickerView::GetDialogButtonLabel( |
| 96 ui::DialogButton button) const { |
| 97 if (button == ui::DIALOG_BUTTON_OK) |
| 98 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_COMMIT); |
| 99 |
| 100 return views::DialogDelegateView::GetDialogButtonLabel(button); |
| 101 } |
| 102 |
| 103 int WebShareTargetPickerView::RowCount() { |
| 104 return targets_.size(); |
| 105 } |
| 106 |
| 107 base::string16 WebShareTargetPickerView::GetText(int row, int /*column_id*/) { |
| 108 return targets_[row]; |
| 109 } |
| 110 |
| 111 void WebShareTargetPickerView::SetObserver(ui::TableModelObserver* observer) {} |
| OLD | NEW |