diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-18 01:19:47 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-18 01:19:47 +0000 |
commit | a33a118d016349a315d17fb33a144bb8ab2694e8 (patch) | |
tree | 3394da0e791a4172f9faff2879350b68dd795bb6 /ui/views | |
parent | 3594b0d8935f3625ac4b151c5af33b9196ac47d2 (diff) | |
download | chromium_src-a33a118d016349a315d17fb33a144bb8ab2694e8.zip chromium_src-a33a118d016349a315d17fb33a144bb8ab2694e8.tar.gz chromium_src-a33a118d016349a315d17fb33a144bb8ab2694e8.tar.bz2 |
Get views implementation of table and tree to use the right system colors.
BUG=170368 170370
TEST=none
R=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11967049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177566 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/controls/table/table_view_views.cc | 44 | ||||
-rw-r--r-- | ui/views/controls/tree/tree_view_views.cc | 48 |
2 files changed, 69 insertions, 23 deletions
diff --git a/ui/views/controls/table/table_view_views.cc b/ui/views/controls/table/table_view_views.cc index 9e59487..5506ff3 100644 --- a/ui/views/controls/table/table_view_views.cc +++ b/ui/views/controls/table/table_view_views.cc @@ -13,6 +13,7 @@ #include "ui/gfx/image/image_skia.h" #include "ui/gfx/rect_conversions.h" #include "ui/gfx/skia_util.h" +#include "ui/native_theme/native_theme.h" #include "ui/views/controls/scroll_view.h" #include "ui/views/controls/table/group_table_model.h" #include "ui/views/controls/table/table_grouper.h" @@ -25,11 +26,6 @@ static const int kTextVerticalPadding = 3; static const int kTextHorizontalPadding = 6; -// TODO: these should come from native theme or something. -static const SkColor kSelectedBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); -static const SkColor kTextColor = SK_ColorBLACK; -static const SkColor kGroupingIndicatorColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); - // Size of images. static const int kImageSize = 16; @@ -58,6 +54,20 @@ void GetModelIndexToRangeStart(TableGrouper* grouper, } } +// Returns the color id for the background of selected text. |has_focus| +// indicates if the table has focus. +ui::NativeTheme::ColorId text_background_color_id(bool has_focus) { + return has_focus ? + ui::NativeTheme::kColorId_TableSelectionBackgroundFocused : + ui::NativeTheme::kColorId_TableSelectionBackgroundUnfocused; +} + +// Returns the color id for text. |has_focus| indicates if the table has focus. +ui::NativeTheme::ColorId selected_text_color_id(bool has_focus) { + return has_focus ? ui::NativeTheme::kColorId_TableSelectedText : + ui::NativeTheme::kColorId_TableSelectedTextUnfocused; +} + } // namespace // Used as the comparator to sort the contents of the table. @@ -128,7 +138,6 @@ TableView::TableView(ui::TableModel* model, visible_columns_.push_back(visible_column); } set_focusable(true); - set_background(Background::CreateSolidBackground(SK_ColorWHITE)); SetModel(model); } @@ -425,7 +434,9 @@ gfx::Point TableView::GetKeyboardContextMenuLocation() { void TableView::OnPaint(gfx::Canvas* canvas) { // Don't invoke View::OnPaint so that we can render our own focus border. - OnPaintBackground(canvas); + + canvas->DrawColor(GetNativeTheme()->GetSystemColor( + ui::NativeTheme::kColorId_TableBackground)); if (!RowCount() || visible_columns_.empty()) return; @@ -434,11 +445,18 @@ void TableView::OnPaint(gfx::Canvas* canvas) { if (region.min_column == -1) return; // No need to paint anything. + const SkColor selected_bg_color = GetNativeTheme()->GetSystemColor( + text_background_color_id(HasFocus())); + const SkColor fg_color = GetNativeTheme()->GetSystemColor( + ui::NativeTheme::kColorId_TableText); + const SkColor selected_fg_color = GetNativeTheme()->GetSystemColor( + selected_text_color_id(HasFocus())); for (int i = region.min_row; i < region.max_row; ++i) { const int model_index = ViewToModel(i); - if (selection_model_.IsSelected(model_index)) { + const bool is_selected = selection_model_.IsSelected(model_index); + if (is_selected) { const gfx::Rect row_bounds(GetRowBounds(i)); - canvas->FillRect(row_bounds, kSelectedBackgroundColor); + canvas->FillRect(row_bounds, selected_bg_color); if (HasFocus() && !header_ && !grouper_) canvas->DrawFocusRect(row_bounds); } else if (row_background_painter_) { @@ -470,7 +488,7 @@ void TableView::OnPaint(gfx::Canvas* canvas) { if (text_x < cell_bounds.right() - kTextHorizontalPadding) { canvas->DrawStringInt( model_->GetText(model_index, visible_columns_[j].column.id), font_, - kTextColor, + is_selected ? selected_fg_color : fg_color, GetMirroredXWithWidthInView(text_x, cell_bounds.right() - text_x - kTextHorizontalPadding), cell_bounds.y() + kTextVerticalPadding, @@ -485,8 +503,10 @@ void TableView::OnPaint(gfx::Canvas* canvas) { if (!grouper_ || region.min_column > 0) return; + const SkColor grouping_color = GetNativeTheme()->GetSystemColor( + ui::NativeTheme::kColorId_TableGroupingIndicatorColor); SkPaint grouping_paint; - grouping_paint.setColor(kGroupingIndicatorColor); + grouping_paint.setColor(grouping_color); grouping_paint.setStyle(SkPaint::kFill_Style); grouping_paint.setAntiAlias(true); const int group_indicator_x = GetMirroredXInView(GetCellBounds(0, 0).x() + @@ -508,7 +528,7 @@ void TableView::OnPaint(gfx::Canvas* canvas) { start_cell_bounds.CenterPoint().y(), kGroupingIndicatorSize, last_cell_bounds.y() - start_cell_bounds.y()), - kGroupingIndicatorColor); + grouping_color); canvas->DrawCircle(gfx::Point(group_indicator_x, last_cell_bounds.CenterPoint().y()), kGroupingIndicatorSize / 2, grouping_paint); diff --git a/ui/views/controls/tree/tree_view_views.cc b/ui/views/controls/tree/tree_view_views.cc index 3473b52..784a1b3 100644 --- a/ui/views/controls/tree/tree_view_views.cc +++ b/ui/views/controls/tree/tree_view_views.cc @@ -17,7 +17,7 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/rect_conversions.h" #include "ui/gfx/skia_util.h" -#include "ui/views/background.h" +#include "ui/native_theme/native_theme.h" #include "ui/views/controls/scroll_view.h" #include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/tree/tree_view_controller.h" @@ -40,10 +40,28 @@ static const int kTextHorizontalPadding = 2; // How much children are indented from their parent. static const int kIndent = 20; -// TODO: these should come from native theme or something. -static const SkColor kArrowColor = SkColorSetRGB(0x7A, 0x7A, 0x7A); -static const SkColor kSelectedBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); -static const SkColor kTextColor = SK_ColorBLACK; +namespace { + +// Returns the color id for the background of selected text. |has_focus| +// indicates if the tree has focus. +ui::NativeTheme::ColorId text_background_color_id(bool has_focus) { + return has_focus ? + ui::NativeTheme::kColorId_TreeSelectionBackgroundFocused : + ui::NativeTheme::kColorId_TreeSelectionBackgroundUnfocused; +} + +// Returns the color id for text. |has_focus| indicates if the tree has focus +// and |is_selected| is true if the item is selected. +ui::NativeTheme::ColorId text_color_id(bool has_focus, bool is_selected) { + if (is_selected) { + if (has_focus) + return ui::NativeTheme::kColorId_TreeSelectedText; + return ui::NativeTheme::kColorId_TreeSelectedTextUnfocused; + } + return ui::NativeTheme::kColorId_TreeText; +} + +} // namespace TreeView::TreeView() : model_(NULL), @@ -57,7 +75,6 @@ TreeView::TreeView() has_custom_icons_(false), row_height_(font_.GetHeight() + kTextVerticalPadding * 2) { set_focusable(true); - set_background(Background::CreateSolidBackground(SK_ColorWHITE)); closed_icon_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( (base::i18n::IsRTL() ? IDR_FOLDER_CLOSED_RTL : IDR_FOLDER_CLOSED)).ToImageSkia(); @@ -157,6 +174,7 @@ void TreeView::CancelEdit() { focus_manager_ = NULL; } // WARNING: don't touch selected_node_, it may be bogus. + editor_->SetController(NULL); RemoveChildView(editor_); // Don't delete immediately as we may be servicing a callback from the editor. MessageLoop::current()->DeleteSoon(FROM_HERE, editor_); @@ -488,7 +506,8 @@ bool TreeView::OnKeyPressed(const ui::KeyEvent& event) { void TreeView::OnPaint(gfx::Canvas* canvas) { // Don't invoke View::OnPaint so that we can render our own focus border. - OnPaintBackground(canvas); + canvas->DrawColor(GetNativeTheme()->GetSystemColor( + ui::NativeTheme::kColorId_TreeBackground)); int min_y, max_y; { @@ -676,11 +695,16 @@ void TreeView::PaintRow(gfx::Canvas* canvas, if (base::i18n::IsRTL()) text_bounds.set_x(bounds.x()); if (node == selected_node_) { - canvas->FillRect(text_bounds, kSelectedBackgroundColor); + const SkColor bg_color = GetNativeTheme()->GetSystemColor( + text_background_color_id(HasFocus())); + canvas->FillRect(text_bounds, bg_color); if (HasFocus()) canvas->DrawFocusRect(text_bounds); } - canvas->DrawStringInt(node->model_node()->GetTitle(), font_, kTextColor, + const ui::NativeTheme::ColorId color_id = + text_color_id(HasFocus(), node == selected_node_); + canvas->DrawStringInt(node->model_node()->GetTitle(), font_, + GetNativeTheme()->GetSystemColor(color_id), text_bounds.x() + kTextHorizontalPadding, text_bounds.y() + kTextVerticalPadding, text_bounds.width() - kTextHorizontalPadding * 2, @@ -699,19 +723,21 @@ void TreeView::PaintExpandControl(gfx::Canvas* canvas, center_x = node_bounds.x() + (kArrowRegionSize - 4) / 2; } int center_y = node_bounds.y() + node_bounds.height() / 2; + const SkColor arrow_color = GetNativeTheme()->GetSystemColor( + ui::NativeTheme::kColorId_TreeArrow); // TODO: this should come from an image. if (!expanded) { int delta = base::i18n::IsRTL() ? 1 : -1; for (int i = 0; i < 4; ++i) { canvas->FillRect(gfx::Rect(center_x + delta * (2 - i), center_y - (3 - i), 1, (3 - i) * 2 + 1), - kArrowColor); + arrow_color); } } else { center_y -= 2; for (int i = 0; i < 4; ++i) { canvas->FillRect(gfx::Rect(center_x - (3 - i), center_y + i, - (3 - i) * 2 + 1, 1), kArrowColor); + (3 - i) * 2 + 1, 1), arrow_color); } } } |