| 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/chooser_content_view.h" | 5 #include "chrome/browser/ui/views/chooser_content_view.h" |
| 6 | 6 |
| 7 #include "base/numerics/safe_conversions.h" |
| 7 #include "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 8 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 9 #include "ui/views/controls/link.h" | 10 #include "ui/views/controls/link.h" |
| 10 #include "ui/views/controls/styled_label.h" | 11 #include "ui/views/controls/styled_label.h" |
| 11 #include "ui/views/controls/table/table_view.h" | 12 #include "ui/views/controls/table/table_view.h" |
| 12 #include "ui/views/controls/throbber.h" | 13 #include "ui/views/controls/throbber.h" |
| 13 #include "ui/views/layout/fill_layout.h" | 14 #include "ui/views/layout/fill_layout.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 discovery_state_->set_listener(nullptr); | 57 discovery_state_->set_listener(nullptr); |
| 57 } | 58 } |
| 58 | 59 |
| 59 gfx::Size ChooserContentView::GetPreferredSize() const { | 60 gfx::Size ChooserContentView::GetPreferredSize() const { |
| 60 return gfx::Size(kChooserWidth, kChooserHeight); | 61 return gfx::Size(kChooserWidth, kChooserHeight); |
| 61 } | 62 } |
| 62 | 63 |
| 63 int ChooserContentView::RowCount() { | 64 int ChooserContentView::RowCount() { |
| 64 // When there are no devices, the table contains a message saying there | 65 // When there are no devices, the table contains a message saying there |
| 65 // are no devices, so the number of rows is always at least 1. | 66 // are no devices, so the number of rows is always at least 1. |
| 66 return std::max(static_cast<int>(chooser_controller_->NumOptions()), 1); | 67 return std::max(base::checked_cast<int>(chooser_controller_->NumOptions()), |
| 68 1); |
| 67 } | 69 } |
| 68 | 70 |
| 69 base::string16 ChooserContentView::GetText(int row, int column_id) { | 71 base::string16 ChooserContentView::GetText(int row, int column_id) { |
| 70 int num_options = static_cast<int>(chooser_controller_->NumOptions()); | 72 int num_options = base::checked_cast<int>(chooser_controller_->NumOptions()); |
| 71 if (num_options == 0) { | 73 if (num_options == 0) { |
| 72 DCHECK_EQ(0, row); | 74 DCHECK_EQ(0, row); |
| 73 return chooser_controller_->GetNoOptionsText(); | 75 return chooser_controller_->GetNoOptionsText(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 DCHECK_GE(row, 0); | 78 DCHECK_GE(row, 0); |
| 77 DCHECK_LT(row, num_options); | 79 DCHECK_LT(row, num_options); |
| 78 return chooser_controller_->GetOption(static_cast<size_t>(row)); | 80 return chooser_controller_->GetOption(static_cast<size_t>(row)); |
| 79 } | 81 } |
| 80 | 82 |
| 81 void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {} | 83 void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {} |
| 82 | 84 |
| 83 void ChooserContentView::OnOptionsInitialized() { | 85 void ChooserContentView::OnOptionsInitialized() { |
| 84 table_view_->OnModelChanged(); | 86 table_view_->OnModelChanged(); |
| 85 UpdateTableView(); | 87 UpdateTableView(); |
| 86 } | 88 } |
| 87 | 89 |
| 88 void ChooserContentView::OnOptionAdded(size_t index) { | 90 void ChooserContentView::OnOptionAdded(size_t index) { |
| 89 table_view_->OnItemsAdded(static_cast<int>(index), 1); | 91 table_view_->OnItemsAdded(base::checked_cast<int>(index), 1); |
| 90 UpdateTableView(); | 92 UpdateTableView(); |
| 91 table_view_->SetVisible(true); | 93 table_view_->SetVisible(true); |
| 92 throbber_->SetVisible(false); | 94 throbber_->SetVisible(false); |
| 93 throbber_->Stop(); | 95 throbber_->Stop(); |
| 94 } | 96 } |
| 95 | 97 |
| 96 void ChooserContentView::OnOptionRemoved(size_t index) { | 98 void ChooserContentView::OnOptionRemoved(size_t index) { |
| 97 table_view_->OnItemsRemoved(static_cast<int>(index), 1); | 99 table_view_->OnItemsRemoved(base::checked_cast<int>(index), 1); |
| 98 UpdateTableView(); | 100 UpdateTableView(); |
| 99 } | 101 } |
| 100 | 102 |
| 103 void ChooserContentView::OnOptionUpdated(size_t index) { |
| 104 table_view_->OnItemsChanged(base::checked_cast<int>(index), 1); |
| 105 UpdateTableView(); |
| 106 } |
| 107 |
| 101 void ChooserContentView::OnAdapterEnabledChanged(bool enabled) { | 108 void ChooserContentView::OnAdapterEnabledChanged(bool enabled) { |
| 102 // No row is selected since the adapter status has changed. | 109 // No row is selected since the adapter status has changed. |
| 103 // This will also disable the OK button if it was enabled because | 110 // This will also disable the OK button if it was enabled because |
| 104 // of a previously selected row. | 111 // of a previously selected row. |
| 105 table_view_->Select(-1); | 112 table_view_->Select(-1); |
| 106 UpdateTableView(); | 113 UpdateTableView(); |
| 107 table_view_->SetVisible(true); | 114 table_view_->SetVisible(true); |
| 108 | 115 |
| 109 throbber_->Stop(); | 116 throbber_->Stop(); |
| 110 throbber_->SetVisible(false); | 117 throbber_->SetVisible(false); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 209 } |
| 203 | 210 |
| 204 void ChooserContentView::UpdateTableView() { | 211 void ChooserContentView::UpdateTableView() { |
| 205 if (chooser_controller_->NumOptions() == 0) { | 212 if (chooser_controller_->NumOptions() == 0) { |
| 206 table_view_->OnModelChanged(); | 213 table_view_->OnModelChanged(); |
| 207 table_view_->SetEnabled(false); | 214 table_view_->SetEnabled(false); |
| 208 } else { | 215 } else { |
| 209 table_view_->SetEnabled(true); | 216 table_view_->SetEnabled(true); |
| 210 } | 217 } |
| 211 } | 218 } |
| OLD | NEW |