| 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/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(SharePickerResult)>& 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(SharePickerResult)>& close_callback) |
| 39 : targets_(targets), close_callback_(close_callback) { |
| 40 views::BoxLayout* layout = new views::BoxLayout( |
| 41 views::BoxLayout::kVertical, views::kPanelHorizMargin, |
| 42 views::kPanelVertMargin, views::kRelatedControlVerticalSpacing); |
| 43 SetLayoutManager(layout); |
| 44 |
| 45 views::Label* overview_label = new views::Label( |
| 46 l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_LABEL)); |
| 47 AddChildView(overview_label); |
| 48 |
| 49 std::vector<ui::TableColumn> table_columns{ui::TableColumn()}; |
| 50 views::TableView* table = |
| 51 new views::TableView(this, table_columns, views::TEXT_ONLY, true); |
| 52 // Select the first row. |
| 53 if (RowCount() > 0) |
| 54 table->Select(0); |
| 55 |
| 56 // Create the table parent (a ScrollView which includes the scroll bars and |
| 57 // border). We add this parent (not the table itself) to the dialog. |
| 58 views::View* table_parent = table->CreateParentIfNecessary(); |
| 59 AddChildView(table_parent); |
| 60 // Make the table expand to fill the space. |
| 61 layout->SetFlexForView(table_parent, 1); |
| 62 } |
| 63 |
| 64 WebShareTargetPickerView::~WebShareTargetPickerView() {} |
| 65 |
| 66 gfx::Size WebShareTargetPickerView::GetPreferredSize() const { |
| 67 return gfx::Size(kDialogWidth, kDialogHeight); |
| 68 } |
| 69 |
| 70 ui::ModalType WebShareTargetPickerView::GetModalType() const { |
| 71 return ui::MODAL_TYPE_WINDOW; |
| 72 } |
| 73 |
| 74 base::string16 WebShareTargetPickerView::GetWindowTitle() const { |
| 75 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_TITLE); |
| 76 } |
| 77 |
| 78 bool WebShareTargetPickerView::Cancel() { |
| 79 if (!close_callback_.is_null()) |
| 80 close_callback_.Run(SharePickerResult::CANCEL); |
| 81 |
| 82 return true; |
| 83 } |
| 84 |
| 85 bool WebShareTargetPickerView::Accept() { |
| 86 if (!close_callback_.is_null()) |
| 87 close_callback_.Run(SharePickerResult::SHARE); |
| 88 |
| 89 return true; |
| 90 } |
| 91 |
| 92 base::string16 WebShareTargetPickerView::GetDialogButtonLabel( |
| 93 ui::DialogButton button) const { |
| 94 if (button == ui::DIALOG_BUTTON_OK) |
| 95 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_COMMIT); |
| 96 |
| 97 return views::DialogDelegateView::GetDialogButtonLabel(button); |
| 98 } |
| 99 |
| 100 int WebShareTargetPickerView::RowCount() { |
| 101 return targets_.size(); |
| 102 } |
| 103 |
| 104 base::string16 WebShareTargetPickerView::GetText(int row, int /*column_id*/) { |
| 105 return targets_[row]; |
| 106 } |
| 107 |
| 108 void WebShareTargetPickerView::SetObserver(ui::TableModelObserver* observer) {} |
| OLD | NEW |