diff options
-rw-r--r-- | ui/native_theme/native_theme.h | 16 | ||||
-rw-r--r-- | ui/native_theme/native_theme_aura.cc | 49 | ||||
-rw-r--r-- | ui/native_theme/native_theme_win.cc | 58 | ||||
-rw-r--r-- | ui/views/controls/table/table_view_views.cc | 44 | ||||
-rw-r--r-- | ui/views/controls/tree/tree_view_views.cc | 48 |
5 files changed, 183 insertions, 32 deletions
diff --git a/ui/native_theme/native_theme.h b/ui/native_theme/native_theme.h index 021cf3c..0c5499e 100644 --- a/ui/native_theme/native_theme.h +++ b/ui/native_theme/native_theme.h @@ -250,6 +250,22 @@ class NATIVE_THEME_EXPORT NativeTheme { kColorId_TextfieldSelectionColor, kColorId_TextfieldSelectionBackgroundFocused, kColorId_TextfieldSelectionBackgroundUnfocused, + // Tree + kColorId_TreeBackground, + kColorId_TreeText, + kColorId_TreeSelectedText, + kColorId_TreeSelectedTextUnfocused, + kColorId_TreeSelectionBackgroundFocused, + kColorId_TreeSelectionBackgroundUnfocused, + kColorId_TreeArrow, + // Table + kColorId_TableBackground, + kColorId_TableText, + kColorId_TableSelectedText, + kColorId_TableSelectedTextUnfocused, + kColorId_TableSelectionBackgroundFocused, + kColorId_TableSelectionBackgroundUnfocused, + kColorId_TableGroupingIndicatorColor, // TODO(benrg): move other hardcoded colors here. }; diff --git a/ui/native_theme/native_theme_aura.cc b/ui/native_theme/native_theme_aura.cc index ca1e3c2..6382593 100644 --- a/ui/native_theme/native_theme_aura.cc +++ b/ui/native_theme/native_theme_aura.cc @@ -53,6 +53,18 @@ const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; const SkColor kTextfieldSelectionColor = color_utils::AlphaBlend(SK_ColorBLACK, kTextfieldSelectionBackgroundFocused, 0xdd); +// Tree +const SkColor kTreeBackground = SK_ColorWHITE; +const SkColor kTreeTextColor = SK_ColorBLACK; +const SkColor kTreeSelectedTextColor = SK_ColorBLACK; +const SkColor kTreeSelectionBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); +const SkColor kTreeArrowColor = SkColorSetRGB(0x7A, 0x7A, 0x7A); +// Table +const SkColor kTableBackground = SK_ColorWHITE; +const SkColor kTableTextColor = SK_ColorBLACK; +const SkColor kTableSelectedTextColor = SK_ColorBLACK; +const SkColor kTableSelectionBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); +const SkColor kTableGroupingIndicatorColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); } // namespace @@ -80,10 +92,8 @@ NativeThemeAura::~NativeThemeAura() { SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { // This implementation returns hardcoded colors. SkColor color; - if (IsNewMenuStyleEnabled() && - CommonThemeGetSystemColor(color_id, &color)) { + if (IsNewMenuStyleEnabled() && CommonThemeGetSystemColor(color_id, &color)) return color; - } switch (color_id) { // Windows @@ -146,8 +156,37 @@ SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { case kColorId_TextfieldSelectionBackgroundUnfocused: return kTextfieldSelectionBackgroundUnfocused; - default: - NOTREACHED() << "Invalid color_id: " << color_id; + // Tree + case kColorId_TreeBackground: + return kTreeBackground; + case kColorId_TreeText: + return kTreeTextColor; + case kColorId_TreeSelectedText: + case kColorId_TreeSelectedTextUnfocused: + return kTreeSelectedTextColor; + case kColorId_TreeSelectionBackgroundFocused: + case kColorId_TreeSelectionBackgroundUnfocused: + return kTreeSelectionBackgroundColor; + case kColorId_TreeArrow: + return kTreeArrowColor; + + // Table + case kColorId_TableBackground: + return kTableBackground; + case kColorId_TableText: + return kTableTextColor; + case kColorId_TableSelectedText: + case kColorId_TableSelectedTextUnfocused: + return kTableSelectedTextColor; + case kColorId_TableSelectionBackgroundFocused: + case kColorId_TableSelectionBackgroundUnfocused: + return kTableSelectionBackgroundColor; + case kColorId_TableGroupingIndicatorColor: + return kTableGroupingIndicatorColor; + + case kColorId_MenuBackgroundColor: + case kColorId_MenuBorderColor: + NOTREACHED(); break; } diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc index 3869334..3e04dcb 100644 --- a/ui/native_theme/native_theme_win.cc +++ b/ui/native_theme/native_theme_win.cc @@ -28,6 +28,11 @@ #include "ui/gfx/rect.h" #include "ui/native_theme/common_theme.h" +// This was removed from Winvers.h but is still used. +#if !defined(COLOR_MENUHIGHLIGHT) +#define COLOR_MENUHIGHLIGHT 29 +#endif + namespace { // TODO: Obtain the correct colors using GetSysColor. @@ -49,6 +54,8 @@ const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(246, 249, 253); const SkColor kMenuSeparatorColor = SkColorSetARGB(50, 0, 0, 0); // Textfield: const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; +// Table: +const SkColor kTreeSelectionBackgroundUnfocused = SkColorSetRGB(240, 240, 240); // Windows system color IDs cached and updated by the native theme. const int kSystemColors[] = { @@ -60,6 +67,8 @@ const int kSystemColors[] = { COLOR_SCROLLBAR, COLOR_WINDOW, COLOR_WINDOWTEXT, + COLOR_BTNFACE, + COLOR_MENUHIGHLIGHT, }; void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) { @@ -117,6 +126,14 @@ RECT InsetRect(const RECT* rect, int size) { return result.ToRECT(); } +// Returns true if using a high contrast theme. +bool UsingHighContrastTheme() { + HIGHCONTRAST result; + result.cbSize = sizeof(HIGHCONTRAST); + return SystemParametersInfo(SPI_GETHIGHCONTRAST, result.cbSize, &result, 0) && + (result.dwFlags & HCF_HIGHCONTRASTON) == HCF_HIGHCONTRASTON; +} + } // namespace namespace ui { @@ -448,10 +465,8 @@ void NativeThemeWin::PaintDirect(SkCanvas* canvas, SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { SkColor color; - if (IsNewMenuStyleEnabled() && - CommonThemeGetSystemColor(color_id, &color)) { + if (IsNewMenuStyleEnabled() && CommonThemeGetSystemColor(color_id, &color)) return color; - } switch (color_id) { // Windows @@ -514,8 +529,43 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { case kColorId_TextfieldSelectionBackgroundUnfocused: return kTextfieldSelectionBackgroundUnfocused; + // Tree + // NOTE: these aren't right for all themes, but as close as I could get. + case kColorId_TreeBackground: + return system_colors_[COLOR_WINDOW]; + case kColorId_TreeText: + return system_colors_[COLOR_WINDOWTEXT]; + case kColorId_TreeSelectedText: + return system_colors_[COLOR_HIGHLIGHTTEXT]; + case kColorId_TreeSelectedTextUnfocused: + return system_colors_[COLOR_BTNTEXT]; + case kColorId_TreeSelectionBackgroundFocused: + return system_colors_[COLOR_HIGHLIGHT]; + case kColorId_TreeSelectionBackgroundUnfocused: + return system_colors_[UsingHighContrastTheme() ? + COLOR_MENUHIGHLIGHT : COLOR_BTNFACE]; + case kColorId_TreeArrow: + return system_colors_[COLOR_WINDOWTEXT]; + + // Table + case kColorId_TableBackground: + return system_colors_[COLOR_WINDOW]; + case kColorId_TableText: + return system_colors_[COLOR_WINDOWTEXT]; + case kColorId_TableSelectedText: + return system_colors_[COLOR_HIGHLIGHTTEXT]; + case kColorId_TableSelectedTextUnfocused: + return system_colors_[COLOR_BTNTEXT]; + case kColorId_TableSelectionBackgroundFocused: + return system_colors_[COLOR_HIGHLIGHT]; + case kColorId_TableSelectionBackgroundUnfocused: + return system_colors_[UsingHighContrastTheme() ? + COLOR_MENUHIGHLIGHT : COLOR_BTNFACE]; + case kColorId_TableGroupingIndicatorColor: + return system_colors_[COLOR_GRAYTEXT]; + default: - NOTREACHED() << "Invalid color_id: " << color_id; + NOTREACHED(); break; } return kInvalidColorIdColor; 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); } } } |