Chromium Code Reviews| 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( |
| 68 base::checked_cast<int, size_t>(chooser_controller_->NumOptions()), 1); | |
|
Jeffrey Yasskin
2016/08/15 21:33:53
Don't specify the second template parameter to che
juncai
2016/08/15 23:53:34
Done.
| |
| 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 = |
| 73 base::checked_cast<int, size_t>(chooser_controller_->NumOptions()); | |
| 71 if (num_options == 0) { | 74 if (num_options == 0) { |
| 72 DCHECK_EQ(0, row); | 75 DCHECK_EQ(0, row); |
| 73 return chooser_controller_->GetNoOptionsText(); | 76 return chooser_controller_->GetNoOptionsText(); |
| 74 } | 77 } |
| 75 | 78 |
| 76 DCHECK_GE(row, 0); | 79 DCHECK_GE(row, 0); |
| 77 DCHECK_LT(row, num_options); | 80 DCHECK_LT(row, num_options); |
| 78 return chooser_controller_->GetOption(static_cast<size_t>(row)); | 81 return chooser_controller_->GetOption(static_cast<size_t>(row)); |
| 79 } | 82 } |
| 80 | 83 |
| 81 void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {} | 84 void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {} |
| 82 | 85 |
| 83 void ChooserContentView::OnOptionsInitialized() { | 86 void ChooserContentView::OnOptionsInitialized() { |
| 84 table_view_->OnModelChanged(); | 87 table_view_->OnModelChanged(); |
| 85 UpdateTableView(); | 88 UpdateTableView(); |
| 86 } | 89 } |
| 87 | 90 |
| 88 void ChooserContentView::OnOptionAdded(size_t index) { | 91 void ChooserContentView::OnOptionAdded(size_t index) { |
| 89 table_view_->OnItemsAdded(static_cast<int>(index), 1); | 92 table_view_->OnItemsAdded(base::checked_cast<int, size_t>(index), 1); |
| 90 UpdateTableView(); | 93 UpdateTableView(); |
| 91 table_view_->SetVisible(true); | 94 table_view_->SetVisible(true); |
| 92 throbber_->SetVisible(false); | 95 throbber_->SetVisible(false); |
| 93 throbber_->Stop(); | 96 throbber_->Stop(); |
| 94 } | 97 } |
| 95 | 98 |
| 96 void ChooserContentView::OnOptionRemoved(size_t index) { | 99 void ChooserContentView::OnOptionRemoved(size_t index) { |
| 97 table_view_->OnItemsRemoved(static_cast<int>(index), 1); | 100 table_view_->OnItemsRemoved(base::checked_cast<int, size_t>(index), 1); |
| 98 UpdateTableView(); | 101 UpdateTableView(); |
| 99 } | 102 } |
| 100 | 103 |
| 104 void ChooserContentView::OnOptionUpdated(size_t index) { | |
| 105 table_view_->OnItemsChanged(base::checked_cast<int, size_t>(index), 1); | |
| 106 UpdateTableView(); | |
| 107 } | |
| 108 | |
| 101 void ChooserContentView::OnAdapterEnabledChanged(bool enabled) { | 109 void ChooserContentView::OnAdapterEnabledChanged(bool enabled) { |
| 102 // No row is selected since the adapter status has changed. | 110 // No row is selected since the adapter status has changed. |
| 103 // This will also disable the OK button if it was enabled because | 111 // This will also disable the OK button if it was enabled because |
| 104 // of a previously selected row. | 112 // of a previously selected row. |
| 105 table_view_->Select(-1); | 113 table_view_->Select(-1); |
| 106 UpdateTableView(); | 114 UpdateTableView(); |
| 107 table_view_->SetVisible(true); | 115 table_view_->SetVisible(true); |
| 108 | 116 |
| 109 throbber_->Stop(); | 117 throbber_->Stop(); |
| 110 throbber_->SetVisible(false); | 118 throbber_->SetVisible(false); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 } | 210 } |
| 203 | 211 |
| 204 void ChooserContentView::UpdateTableView() { | 212 void ChooserContentView::UpdateTableView() { |
| 205 if (chooser_controller_->NumOptions() == 0) { | 213 if (chooser_controller_->NumOptions() == 0) { |
| 206 table_view_->OnModelChanged(); | 214 table_view_->OnModelChanged(); |
| 207 table_view_->SetEnabled(false); | 215 table_view_->SetEnabled(false); |
| 208 } else { | 216 } else { |
| 209 table_view_->SetEnabled(true); | 217 table_view_->SetEnabled(true); |
| 210 } | 218 } |
| 211 } | 219 } |
| OLD | NEW |