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

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: rebase and added code to update RSSI 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 6d087eadfbd37c96b6bafd5fd56dd7c4ef363fee..76d76353e2f476bfed2bea2afda2c2ac09a42fa6 100644
--- a/chrome/browser/ui/views/chooser_content_view.cc
+++ b/chrome/browser/ui/views/chooser_content_view.cc
@@ -6,7 +6,10 @@
#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"
@@ -21,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,
Jeffrey Yasskin 2016/08/19 17:46:54 Name this kStrengthBarIds: https://google.github.i
juncai 2016/08/19 22:59:17 Done.
+ IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR,
+ IDR_SIGNAL_4_BAR};
+
} // namespace
ChooserContentView::ChooserContentView(
@@ -30,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 */);
Jeffrey Yasskin 2016/08/19 17:46:54 Thanks for the comment about what the boolean mean
juncai 2016/08/19 22:59:17 Acknowledged.
table_view_->set_select_on_remove(false);
table_view_->SetObserver(table_view_observer);
table_view_->SetEnabled(chooser_controller_->NumOptions() > 0);
@@ -82,6 +93,31 @@ 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());
+
+ size_t num_options = chooser_controller_->NumOptions();
+ if (num_options == 0) {
+ DCHECK_EQ(0, row);
+ return gfx::ImageSkia();
+ }
+
+ DCHECK_GE(row, 0);
+ DCHECK_LT(row, base::checked_cast<int>(num_options));
+
+ int level =
+ chooser_controller_->GetSignalStrengthLevel(static_cast<size_t>(row));
Jeffrey Yasskin 2016/08/19 17:46:54 You can let this be an implicit cast. The DCHECK_G
juncai 2016/08/19 22:59:17 Done.
+
+ if (level == -1)
+ return gfx::ImageSkia();
+
+ DCHECK_GE(level, 0);
+ DCHECK_LT(level, base::checked_cast<int>(arraysize(strength_bar_ids)));
Jeffrey Yasskin 2016/08/19 17:46:54 You can omit the checked_cast here: you know this
juncai 2016/08/19 22:59:17 Changed to static_cast<int> here, since if not usi
+
+ return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
Jeffrey Yasskin 2016/08/19 17:46:54 Can GetImageSkiaNamed ever return null?
juncai 2016/08/19 22:59:17 From: https://cs.chromium.org/chromium/src/ui/base
+ strength_bar_ids[level]);
+}
+
void ChooserContentView::OnOptionsInitialized() {
table_view_->OnModelChanged();
UpdateTableView();

Powered by Google App Engine
This is Rietveld 408576698