| 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 "base/numerics/safe_conversions.h" |
| 8 #include "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/color_palette.h" |
| 11 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
| 13 #include "ui/gfx/paint_vector_icon.h" |
| 14 #include "ui/gfx/vector_icons_public.h" |
| 12 #include "ui/resources/grit/ui_resources.h" | 15 #include "ui/resources/grit/ui_resources.h" |
| 13 #include "ui/views/controls/link.h" | 16 #include "ui/views/controls/link.h" |
| 14 #include "ui/views/controls/styled_label.h" | 17 #include "ui/views/controls/styled_label.h" |
| 15 #include "ui/views/controls/table/table_view.h" | 18 #include "ui/views/controls/table/table_view.h" |
| 16 #include "ui/views/controls/throbber.h" | 19 #include "ui/views/controls/throbber.h" |
| 17 #include "ui/views/layout/fill_layout.h" | 20 #include "ui/views/layout/fill_layout.h" |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 const int kChooserWidth = 330; | 24 const int kChooserWidth = 330; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 84 |
| 82 base::string16 ChooserContentView::GetText(int row, int column_id) { | 85 base::string16 ChooserContentView::GetText(int row, int column_id) { |
| 83 int num_options = base::checked_cast<int>(chooser_controller_->NumOptions()); | 86 int num_options = base::checked_cast<int>(chooser_controller_->NumOptions()); |
| 84 if (num_options == 0) { | 87 if (num_options == 0) { |
| 85 DCHECK_EQ(0, row); | 88 DCHECK_EQ(0, row); |
| 86 return chooser_controller_->GetNoOptionsText(); | 89 return chooser_controller_->GetNoOptionsText(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 DCHECK_GE(row, 0); | 92 DCHECK_GE(row, 0); |
| 90 DCHECK_LT(row, num_options); | 93 DCHECK_LT(row, num_options); |
| 91 return chooser_controller_->GetOption(static_cast<size_t>(row)); | 94 base::string16 text = |
| 95 chooser_controller_->GetOption(static_cast<size_t>(row)); |
| 96 return chooser_controller_->IsPaired(row) |
| 97 ? l10n_util::GetStringFUTF16( |
| 98 IDS_DEVICE_CHOOSER_DEVICE_NAME_AND_PAIRED_STATUS_TEXT, text) |
| 99 : text; |
| 92 } | 100 } |
| 93 | 101 |
| 94 void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {} | 102 void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {} |
| 95 | 103 |
| 96 gfx::ImageSkia ChooserContentView::GetIcon(int row) { | 104 gfx::ImageSkia ChooserContentView::GetIcon(int row) { |
| 97 DCHECK(chooser_controller_->ShouldShowIconBeforeText()); | 105 DCHECK(chooser_controller_->ShouldShowIconBeforeText()); |
| 98 | 106 |
| 99 size_t num_options = chooser_controller_->NumOptions(); | 107 size_t num_options = chooser_controller_->NumOptions(); |
| 100 if (num_options == 0) { | 108 if (num_options == 0) { |
| 101 DCHECK_EQ(0, row); | 109 DCHECK_EQ(0, row); |
| 102 return gfx::ImageSkia(); | 110 return gfx::ImageSkia(); |
| 103 } | 111 } |
| 104 | 112 |
| 105 DCHECK_GE(row, 0); | 113 DCHECK_GE(row, 0); |
| 106 DCHECK_LT(row, base::checked_cast<int>(num_options)); | 114 DCHECK_LT(row, base::checked_cast<int>(num_options)); |
| 107 | 115 |
| 116 if (chooser_controller_->IsConnected(row)) { |
| 117 return gfx::CreateVectorIcon(gfx::VectorIconId::BLUETOOTH_CONNECTED, |
| 118 gfx::kChromeIconGrey); |
| 119 } |
| 120 |
| 108 int level = chooser_controller_->GetSignalStrengthLevel(row); | 121 int level = chooser_controller_->GetSignalStrengthLevel(row); |
| 109 | 122 |
| 110 if (level == -1) | 123 if (level == -1) |
| 111 return gfx::ImageSkia(); | 124 return gfx::ImageSkia(); |
| 112 | 125 |
| 113 DCHECK_GE(level, 0); | 126 DCHECK_GE(level, 0); |
| 114 DCHECK_LT(level, static_cast<int>(arraysize(kSignalStrengthLevelImageIds))); | 127 DCHECK_LT(level, static_cast<int>(arraysize(kSignalStrengthLevelImageIds))); |
| 115 | 128 |
| 116 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 129 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 117 kSignalStrengthLevelImageIds[level]); | 130 kSignalStrengthLevelImageIds[level]); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 257 } |
| 245 | 258 |
| 246 void ChooserContentView::UpdateTableView() { | 259 void ChooserContentView::UpdateTableView() { |
| 247 if (chooser_controller_->NumOptions() == 0) { | 260 if (chooser_controller_->NumOptions() == 0) { |
| 248 table_view_->OnModelChanged(); | 261 table_view_->OnModelChanged(); |
| 249 table_view_->SetEnabled(false); | 262 table_view_->SetEnabled(false); |
| 250 } else { | 263 } else { |
| 251 table_view_->SetEnabled(true); | 264 table_view_->SetEnabled(true); |
| 252 } | 265 } |
| 253 } | 266 } |
| OLD | NEW |