Commit 3391a0dc authored by Patti's avatar Patti Committed by Commit Bot

Views/Vector Icons: views::TableView now passes the size required for icons.

Refactor TableView and TableModel so that the size of the icon requested is
provided when the TableView is retrieving the icon. This avoids duplicating the
icon size in places other than TableView, and fixes one specific issue where the
bluetooth connected icon used in the device chooser dialog did not specify any
size, triggering a DCHECK.

Bug: 838052
Change-Id: I14e7463b086c77615286e38100fe7e0f94d8fd34
Reviewed-on: https://chromium-review.googlesource.com/1036684
Commit-Queue: Patti <patricialor@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556368}
parent f9bbc3d1
......@@ -220,7 +220,7 @@ gfx::ImageSkia DeviceChooserContentView::GetIcon(int row) {
if (chooser_controller_->IsConnected(row))
return gfx::CreateVectorIcon(vector_icons::kBluetoothConnectedIcon,
gfx::kChromeIconGrey);
TableModel::kIconSize, gfx::kChromeIconGrey);
int level = chooser_controller_->GetSignalStrengthLevel(row);
......
......@@ -22,16 +22,19 @@ class TableModelObserver;
// The model driving the TableView.
class UI_BASE_EXPORT TableModel {
public:
// Size of the table row icon, if used.
static constexpr int kIconSize = 16;
// Number of rows in the model.
virtual int RowCount() = 0;
// Returns the value at a particular location in text.
virtual base::string16 GetText(int row, int column_id) = 0;
// Returns the small icon (16x16) that should be displayed in the first
// column before the text. This is only used when the TableView was created
// with the ICON_AND_TEXT table type. Returns an isNull() image if there is
// no image.
// Returns the small icon (|kIconSize| x |kIconSize|) that should be displayed
// in the first column before the text. This is only used when the TableView
// was created with the ICON_AND_TEXT table type. Returns an isNull() image if
// there is no image.
virtual gfx::ImageSkia GetIcon(int row);
// Returns the tooltip, if any, to show for a particular row. If there are
......
......@@ -31,15 +31,12 @@
#include "ui/views/layout/layout_provider.h"
#include "ui/views/style/typography.h"
// Size of images.
static const int kImageSize = 16;
static const int kGroupingIndicatorSize = 6;
namespace views {
namespace {
constexpr int kGroupingIndicatorSize = 6;
// Returns result, unless ascending is false in which case -result is returned.
int SwapCompareResult(int result, bool ascending) {
return ascending ? result : -result;
......@@ -588,14 +585,15 @@ void TableView::OnPaint(gfx::Canvas* canvas) {
if (j == 0 && table_type_ == ICON_AND_TEXT) {
gfx::ImageSkia image = model_->GetIcon(model_index);
if (!image.isNull()) {
int image_x = GetMirroredXWithWidthInView(text_x, kImageSize);
int image_x =
GetMirroredXWithWidthInView(text_x, ui::TableModel::kIconSize);
canvas->DrawImageInt(
image, 0, 0, image.width(), image.height(),
image_x,
cell_bounds.y() + (cell_bounds.height() - kImageSize) / 2,
kImageSize, kImageSize, true);
image, 0, 0, image.width(), image.height(), image_x,
cell_bounds.y() +
(cell_bounds.height() - ui::TableModel::kIconSize) / 2,
ui::TableModel::kIconSize, ui::TableModel::kIconSize, true);
}
text_x += kImageSize + cell_element_spacing;
text_x += ui::TableModel::kIconSize + cell_element_spacing;
}
if (text_x < cell_bounds.right() - cell_margin) {
canvas->DrawStringRectWithFlags(
......@@ -743,7 +741,7 @@ void TableView::AdjustCellBoundsForText(int visible_column_index,
if (grouper_)
text_x += kGroupingIndicatorSize + cell_element_spacing;
if (table_type_ == ICON_AND_TEXT)
text_x += kImageSize + cell_element_spacing;
text_x += ui::TableModel::kIconSize + cell_element_spacing;
}
bounds->set_x(text_x);
bounds->set_width(std::max(0, bounds->right() - cell_margin - text_x));
......@@ -770,7 +768,7 @@ void TableView::UpdateVisibleColumnSizes() {
const int cell_element_spacing = GetCellElementSpacing();
int first_column_padding = 0;
if (table_type_ == ICON_AND_TEXT && header_)
first_column_padding += kImageSize + cell_element_spacing;
first_column_padding += ui::TableModel::kIconSize + cell_element_spacing;
if (grouper_)
first_column_padding += kGroupingIndicatorSize + cell_element_spacing;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment