Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2058)

Unified Diff: chrome/browser/ui/views/chooser_content_view.cc

Issue 2245603003: Add signal strength indicator icon to WebBluetooth chooser on non-Mac desktops (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: removed unused include file Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/chooser_content_view.cc
diff --git a/chrome/browser/ui/views/chooser_content_view.cc b/chrome/browser/ui/views/chooser_content_view.cc
index 6ae3d32f4a50e61d2ff570234140d02958829013..91d56ba1bbe2c53268a561aa5300aac1205347de 100644
--- a/chrome/browser/ui/views/chooser_content_view.cc
+++ b/chrome/browser/ui/views/chooser_content_view.cc
@@ -4,8 +4,12 @@
#include "chrome/browser/ui/views/chooser_content_view.h"
+#include "base/numerics/safe_conversions.h"
#include "chrome/grit/generated_resources.h"
+#include "grit/ui_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image_skia.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/controls/table/table_view.h"
@@ -20,6 +24,11 @@ const int kChooserHeight = 220;
const int kThrobberDiameter = 24;
+// The lookup table for strength bar image.
+const int strength_bar_ids[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR,
+ IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR,
+ IDR_SIGNAL_4_BAR};
+
} // namespace
ChooserContentView::ChooserContentView(
@@ -29,8 +38,11 @@ ChooserContentView::ChooserContentView(
chooser_controller_->set_view(this);
std::vector<ui::TableColumn> table_columns;
table_columns.push_back(ui::TableColumn());
- table_view_ =
- new views::TableView(this, table_columns, views::TEXT_ONLY, true);
+ table_view_ = new views::TableView(
+ this, table_columns,
+ chooser_controller_->ShouldShowIconBeforeText() ? views::ICON_AND_TEXT
+ : views::TEXT_ONLY,
+ true /* single_selection */);
table_view_->set_select_on_remove(false);
table_view_->SetObserver(table_view_observer);
table_view_->SetEnabled(chooser_controller_->NumOptions() > 0);
@@ -63,11 +75,12 @@ gfx::Size ChooserContentView::GetPreferredSize() const {
int ChooserContentView::RowCount() {
// When there are no devices, the table contains a message saying there
// are no devices, so the number of rows is always at least 1.
- return std::max(static_cast<int>(chooser_controller_->NumOptions()), 1);
+ return std::max(base::checked_cast<int>(chooser_controller_->NumOptions()),
+ 1);
}
base::string16 ChooserContentView::GetText(int row, int column_id) {
- int num_options = static_cast<int>(chooser_controller_->NumOptions());
+ int num_options = base::checked_cast<int>(chooser_controller_->NumOptions());
if (num_options == 0) {
DCHECK_EQ(0, row);
return chooser_controller_->GetNoOptionsText();
@@ -80,13 +93,35 @@ base::string16 ChooserContentView::GetText(int row, int column_id) {
void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {}
+gfx::ImageSkia ChooserContentView::GetIcon(int row) {
+ DCHECK(chooser_controller_->ShouldShowIconBeforeText());
+
+ int num_options = base::checked_cast<int>(chooser_controller_->NumOptions());
msw 2016/08/16 16:51:18 nit: Avoid casting to compare with 0. Instead, you
juncai 2016/08/16 17:49:52 Done.
+ if (num_options == 0) {
+ DCHECK_EQ(0, row);
+ return gfx::ImageSkia();
+ }
+
+ DCHECK_GE(row, 0);
+ DCHECK_LT(row, num_options);
+
+ int level =
+ chooser_controller_->GetSignalStrengthLevel(static_cast<size_t>(row));
+
+ if (level == -1)
+ return gfx::ImageSkia();
+
+ return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ strength_bar_ids[level]);
msw 2016/08/16 16:51:18 nit: CHECK that the level is in the range of the a
juncai 2016/08/16 17:49:52 Done.
+}
+
void ChooserContentView::OnOptionsInitialized() {
table_view_->OnModelChanged();
UpdateTableView();
}
void ChooserContentView::OnOptionAdded(size_t index) {
- table_view_->OnItemsAdded(static_cast<int>(index), 1);
+ table_view_->OnItemsAdded(base::checked_cast<int>(index), 1);
UpdateTableView();
table_view_->SetVisible(true);
throbber_->SetVisible(false);
@@ -94,7 +129,7 @@ void ChooserContentView::OnOptionAdded(size_t index) {
}
void ChooserContentView::OnOptionRemoved(size_t index) {
- table_view_->OnItemsRemoved(static_cast<int>(index), 1);
+ table_view_->OnItemsRemoved(base::checked_cast<int>(index), 1);
UpdateTableView();
}

Powered by Google App Engine
This is Rietveld 408576698