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

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: added signal strength indicator icon to WebBluetooth chooser 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..3a128430abd721a8a5fdc6b97e90e05c6d900cfe 100644
--- a/chrome/browser/ui/views/chooser_content_view.cc
+++ b/chrome/browser/ui/views/chooser_content_view.cc
@@ -5,7 +5,11 @@
#include "chrome/browser/ui/views/chooser_content_view.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/gfx/image/image_skia_operations.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,9 @@ const int kChooserHeight = 220;
const int kThrobberDiameter = 24;
+// Images for strength bars.
+const int kNumStrengthBarImages = 5;
+
} // namespace
ChooserContentView::ChooserContentView(
@@ -29,8 +36,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_->HasIconBeforeText()
+ ? 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);
@@ -80,6 +90,34 @@ base::string16 ChooserContentView::GetText(int row, int column_id) {
void ChooserContentView::SetObserver(ui::TableModelObserver* observer) {}
+gfx::ImageSkia ChooserContentView::GetIcon(int row) {
+ if (!chooser_controller_->HasIconBeforeText())
msw 2016/08/12 23:08:49 nit: can we DCHECK this instead? TableView probabl
juncai 2016/08/15 21:53:19 Done.
+ return gfx::ImageSkia();
+
+ int num_options = static_cast<int>(chooser_controller_->NumOptions());
msw 2016/08/12 23:08:49 nit: avoid this static cast.
juncai 2016/08/15 21:53:19 Use base::checked_cast instead of static_cast. Do
+ 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();
+
+ gfx::ImageSkia* images =
+ ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_NETWORK_BARS_DARK);
+ int width = images->width();
+ int height = images->height() / kNumStrengthBarImages;
+ return gfx::ImageSkiaOperations::ExtractSubset(
msw 2016/08/12 23:08:49 The icons look a bit squished in the screenshot, c
juncai 2016/08/15 21:53:19 I update and use icons from: https://icons.googlep
+ *images, gfx::Rect(0, level * height, width, height));
msw 2016/08/12 23:08:49 interesting! perhaps add a comment?
juncai 2016/08/15 21:53:19 I borrowed the idea from: https://cs.chromium.org/
+}
+
void ChooserContentView::OnOptionsInitialized() {
table_view_->OnModelChanged();
UpdateTableView();

Powered by Google App Engine
This is Rietveld 408576698