OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/webshare/webshare_target_picker_view.h" | 5 #include "chrome/browser/ui/views/webshare/webshare_target_picker_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | 8 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
9 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
10 #include "components/constrained_window/constrained_window_views.h" | 10 #include "components/constrained_window/constrained_window_views.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 ")"); | 59 ")"); |
60 } | 60 } |
61 | 61 |
62 void TargetPickerTableModel::SetObserver(ui::TableModelObserver* observer) {} | 62 void TargetPickerTableModel::SetObserver(ui::TableModelObserver* observer) {} |
63 | 63 |
64 namespace chrome { | 64 namespace chrome { |
65 | 65 |
66 void ShowWebShareTargetPickerDialog( | 66 void ShowWebShareTargetPickerDialog( |
67 gfx::NativeWindow parent_window, | 67 gfx::NativeWindow parent_window, |
68 const std::vector<std::pair<base::string16, GURL>>& targets, | 68 const std::vector<std::pair<base::string16, GURL>>& targets, |
69 const base::Callback<void(base::Optional<std::string>)>& callback) { | 69 chrome::WebShareTargetPickerCallback callback) { |
70 constrained_window::CreateBrowserModalDialogViews( | 70 constrained_window::CreateBrowserModalDialogViews( |
71 new WebShareTargetPickerView(targets, callback), parent_window) | 71 new WebShareTargetPickerView(targets, std::move(callback)), parent_window) |
72 ->Show(); | 72 ->Show(); |
73 } | 73 } |
74 | 74 |
75 } // namespace chrome | 75 } // namespace chrome |
76 | 76 |
77 WebShareTargetPickerView::WebShareTargetPickerView( | 77 WebShareTargetPickerView::WebShareTargetPickerView( |
78 const std::vector<std::pair<base::string16, GURL>>& targets, | 78 const std::vector<std::pair<base::string16, GURL>>& targets, |
79 const base::Callback<void(base::Optional<std::string>)>& close_callback) | 79 chrome::WebShareTargetPickerCallback close_callback) |
80 : targets_(targets), | 80 : targets_(targets), |
81 table_model_(base::MakeUnique<TargetPickerTableModel>(&targets_)), | 81 table_model_(base::MakeUnique<TargetPickerTableModel>(&targets_)), |
82 close_callback_(close_callback) { | 82 close_callback_(std::move(close_callback)) { |
83 const int panel_margin = ChromeLayoutProvider::Get()->GetDistanceMetric( | 83 const int panel_margin = ChromeLayoutProvider::Get()->GetDistanceMetric( |
84 DISTANCE_PANEL_CONTENT_MARGIN); | 84 DISTANCE_PANEL_CONTENT_MARGIN); |
85 views::BoxLayout* layout = | 85 views::BoxLayout* layout = |
86 new views::BoxLayout(views::BoxLayout::kVertical, panel_margin, | 86 new views::BoxLayout(views::BoxLayout::kVertical, panel_margin, |
87 panel_margin, views::kRelatedControlVerticalSpacing); | 87 panel_margin, views::kRelatedControlVerticalSpacing); |
88 SetLayoutManager(layout); | 88 SetLayoutManager(layout); |
89 | 89 |
90 views::Label* overview_label = new views::Label( | 90 views::Label* overview_label = new views::Label( |
91 l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_LABEL)); | 91 l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_LABEL)); |
92 AddChildView(overview_label); | 92 AddChildView(overview_label); |
(...skipping 29 matching lines...) Expand all Loading... |
122 ui::ModalType WebShareTargetPickerView::GetModalType() const { | 122 ui::ModalType WebShareTargetPickerView::GetModalType() const { |
123 return ui::MODAL_TYPE_WINDOW; | 123 return ui::MODAL_TYPE_WINDOW; |
124 } | 124 } |
125 | 125 |
126 base::string16 WebShareTargetPickerView::GetWindowTitle() const { | 126 base::string16 WebShareTargetPickerView::GetWindowTitle() const { |
127 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_TITLE); | 127 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_TITLE); |
128 } | 128 } |
129 | 129 |
130 bool WebShareTargetPickerView::Cancel() { | 130 bool WebShareTargetPickerView::Cancel() { |
131 if (!close_callback_.is_null()) | 131 if (!close_callback_.is_null()) |
132 close_callback_.Run(base::nullopt); | 132 std::move(close_callback_).Run(base::nullopt); |
133 | 133 |
134 return true; | 134 return true; |
135 } | 135 } |
136 | 136 |
137 bool WebShareTargetPickerView::Accept() { | 137 bool WebShareTargetPickerView::Accept() { |
138 if (!close_callback_.is_null()) { | 138 if (!close_callback_.is_null()) { |
139 DCHECK(!table_->selection_model().empty()); | 139 DCHECK(!table_->selection_model().empty()); |
140 close_callback_.Run(targets_[table_->FirstSelectedRow()].second.spec()); | 140 std::move(close_callback_) |
| 141 .Run(targets_[table_->FirstSelectedRow()].second.spec()); |
141 } | 142 } |
142 | 143 |
143 return true; | 144 return true; |
144 } | 145 } |
145 | 146 |
146 base::string16 WebShareTargetPickerView::GetDialogButtonLabel( | 147 base::string16 WebShareTargetPickerView::GetDialogButtonLabel( |
147 ui::DialogButton button) const { | 148 ui::DialogButton button) const { |
148 if (button == ui::DIALOG_BUTTON_OK) | 149 if (button == ui::DIALOG_BUTTON_OK) |
149 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_COMMIT); | 150 return l10n_util::GetStringUTF16(IDS_WEBSHARE_TARGET_PICKER_COMMIT); |
150 | 151 |
151 return views::DialogDelegateView::GetDialogButtonLabel(button); | 152 return views::DialogDelegateView::GetDialogButtonLabel(button); |
152 } | 153 } |
153 | 154 |
154 bool WebShareTargetPickerView::IsDialogButtonEnabled( | 155 bool WebShareTargetPickerView::IsDialogButtonEnabled( |
155 ui::DialogButton button) const { | 156 ui::DialogButton button) const { |
156 // User shouldn't select OK button if they haven't selected a target. | 157 // User shouldn't select OK button if they haven't selected a target. |
157 if (button == ui::DIALOG_BUTTON_OK) | 158 if (button == ui::DIALOG_BUTTON_OK) |
158 return !table_->selection_model().empty(); | 159 return !table_->selection_model().empty(); |
159 | 160 |
160 return true; | 161 return true; |
161 } | 162 } |
162 | 163 |
163 void WebShareTargetPickerView::OnSelectionChanged() { | 164 void WebShareTargetPickerView::OnSelectionChanged() { |
164 GetDialogClientView()->UpdateDialogButtons(); | 165 GetDialogClientView()->UpdateDialogButtons(); |
165 } | 166 } |
166 | 167 |
167 void WebShareTargetPickerView::OnDoubleClick() { | 168 void WebShareTargetPickerView::OnDoubleClick() { |
168 GetDialogClientView()->AcceptWindow(); | 169 GetDialogClientView()->AcceptWindow(); |
169 } | 170 } |
OLD | NEW |