summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 16:18:18 +0000
committerrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-12 16:18:18 +0000
commit44ddaa4757178992da4f9a1398d96438e76e26d0 (patch)
treedd3d37e8d5f115843a85caee7bc275b058cbe1f8 /views
parenta61c46f2a26bbe421345c48aaf2635bbf204a0d8 (diff)
downloadchromium_src-44ddaa4757178992da4f9a1398d96438e76e26d0.zip
chromium_src-44ddaa4757178992da4f9a1398d96438e76e26d0.tar.gz
chromium_src-44ddaa4757178992da4f9a1398d96438e76e26d0.tar.bz2
step 3 of native theme refactoring
Moved all calls to old menu drawing api to new NativeTheme::Paint(). Moved all calls to old push/radio/check button api to new NativePaint::Paint(). BUG=None TEST=Affects windows platform only. All menus in chrome, such as wrench menu, should look and behave as before, with no change. All pushbuttons, radiobuttons, and checkbox in web page forms should look and behave as before. Review URL: http://codereview.chromium.org/6825007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81257 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/menu/menu_item_view.h14
-rw-r--r--views/controls/menu/menu_item_view_win.cc93
-rw-r--r--views/controls/menu/menu_scroll_view_container.cc29
-rw-r--r--views/controls/menu/menu_separator_win.cc34
4 files changed, 81 insertions, 89 deletions
diff --git a/views/controls/menu/menu_item_view.h b/views/controls/menu/menu_item_view.h
index 936f857..980f2d6 100644
--- a/views/controls/menu/menu_item_view.h
+++ b/views/controls/menu/menu_item_view.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -18,7 +18,7 @@
#include "views/view.h"
#if defined(OS_WIN)
-#include "ui/gfx/native_theme_win.h"
+#include "ui/gfx/native_theme.h"
#endif
namespace ui {
@@ -32,6 +32,8 @@ class MenuController;
class MenuDelegate;
class SubmenuView;
+struct MenuConfig;
+
// MenuItemView --------------------------------------------------------------
// MenuItemView represents a single menu item with a label and optional icon.
@@ -334,11 +336,9 @@ class MenuItemView : public View {
#if defined(OS_WIN)
// Paints the check/radio button indicator. |part_id| is the id passed to the
// native theme drawing routines.
- void PaintCheck(HDC dc,
- int part_id,
- gfx::NativeThemeWin::ControlState control_state,
- int icon_width,
- int icon_height);
+ void PaintCheck(gfx::Canvas* canvas,
+ gfx::NativeTheme::State state,
+ const MenuConfig& config);
#endif
// Paints the accelerator.
diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc
index 41fdad8..e71f8c1 100644
--- a/views/controls/menu/menu_item_view_win.cc
+++ b/views/controls/menu/menu_item_view_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,7 +13,7 @@
#include "views/controls/menu/menu_config.h"
#include "views/controls/menu/submenu_view.h"
-using gfx::NativeThemeWin;
+using gfx::NativeTheme;
namespace views {
@@ -33,14 +33,13 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
!has_children());
int state = render_selection ? MPI_HOT :
(IsEnabled() ? MPI_NORMAL : MPI_DISABLED);
- HDC dc = canvas->BeginPlatformPaint();
- NativeThemeWin::ControlState control_state;
+ NativeTheme::State control_state;
if (!IsEnabled()) {
- control_state = NativeThemeWin::CONTROL_DISABLED;
+ control_state = NativeTheme::kDisabled;
} else {
- control_state = render_selection ? NativeThemeWin::CONTROL_HIGHLIGHTED :
- NativeThemeWin::CONTROL_NORMAL;
+ control_state = render_selection ? NativeTheme::kHovered:
+ NativeTheme::kNormal;
}
// The gutter is rendered before the background.
@@ -49,31 +48,30 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
config.gutter_width, 0, config.gutter_width,
height());
AdjustBoundsForRTLUI(&gutter_bounds);
- RECT gutter_rect = gutter_bounds.ToRECT();
- NativeThemeWin::instance()->PaintMenuGutter(dc, MENU_POPUPGUTTER,
- MPI_NORMAL, &gutter_rect);
+ NativeTheme::ExtraParams extra;
+ NativeTheme::instance()->Paint(canvas->AsCanvasSkia(),
+ NativeTheme::kMenuPopupGutter,
+ NativeTheme::kNormal,
+ gutter_bounds,
+ extra);
}
// Render the background.
if (mode == PB_NORMAL) {
gfx::Rect item_bounds(0, 0, width(), height());
+ NativeTheme::ExtraParams extra;
+ extra.menu_item.is_selected = render_selection;
AdjustBoundsForRTLUI(&item_bounds);
- RECT item_rect = item_bounds.ToRECT();
- NativeThemeWin::instance()->PaintMenuItemBackground(
- NativeThemeWin::MENU, dc, MENU_POPUPITEM, state, render_selection,
- &item_rect);
+ NativeTheme::instance()->Paint(canvas->AsCanvasSkia(),
+ NativeTheme::kMenuItemBackground, control_state, item_bounds, extra);
}
int top_margin = GetTopMargin();
int bottom_margin = GetBottomMargin();
- if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) {
- PaintCheck(dc,
- IsEnabled() ? MC_CHECKMARKNORMAL : MC_CHECKMARKDISABLED,
- control_state, config.check_height, config.check_width);
- } else if (type_ == RADIO && GetDelegate()->IsItemChecked(GetCommand())) {
- PaintCheck(dc, IsEnabled() ? MC_BULLETNORMAL : MC_BULLETDISABLED,
- control_state, config.radio_height, config.radio_width);
+ if ((type_ == RADIO || type_ == CHECKBOX) &&
+ GetDelegate()->IsItemChecked(GetCommand())) {
+ PaintCheck(canvas, control_state, config);
}
// Render the foreground.
@@ -81,8 +79,8 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
// get color.
int default_sys_color = render_selection ? COLOR_HIGHLIGHTTEXT :
(IsEnabled() ? COLOR_MENUTEXT : COLOR_GRAYTEXT);
- SkColor fg_color = NativeThemeWin::instance()->GetThemeColorWithDefault(
- NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR,
+ SkColor fg_color = gfx::NativeThemeWin::instance()->GetThemeColorWithDefault(
+ gfx::NativeThemeWin::MENU, MENU_POPUPITEM, state, TMT_TEXTCOLOR,
default_sys_color);
const gfx::Font& font = MenuConfig::instance().font;
int accel_width = parent_menu_item_->GetSubmenu()->max_accelerator_width();
@@ -127,45 +125,44 @@ void MenuItemView::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) {
// If our sub menus open from right to left (which is the case when the
// locale is RTL) then we should make sure the menu arrow points to the
// right direction.
- NativeThemeWin::MenuArrowDirection arrow_direction;
- if (base::i18n::IsRTL())
- arrow_direction = NativeThemeWin::LEFT_POINTING_ARROW;
- else
- arrow_direction = NativeThemeWin::RIGHT_POINTING_ARROW;
-
- RECT arrow_rect = arrow_bounds.ToRECT();
- NativeThemeWin::instance()->PaintMenuArrow(
- NativeThemeWin::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect,
- arrow_direction, control_state);
+ gfx::NativeTheme::ExtraParams extra;
+ extra.menu_arrow.pointing_right = !base::i18n::IsRTL();
+ gfx::NativeTheme::instance()->Paint(canvas->AsCanvasSkia(),
+ gfx::NativeTheme::kMenuPopupArrow, control_state, arrow_bounds, extra);
}
- canvas->EndPlatformPaint();
}
-void MenuItemView::PaintCheck(HDC dc,
- int state_id,
- NativeThemeWin::ControlState control_state,
- int icon_width,
- int icon_height) {
+void MenuItemView::PaintCheck(gfx::Canvas* canvas,
+ NativeTheme::State state,
+ const MenuConfig& config) {
+ int icon_width;
+ int icon_height;
+ if (type_ == RADIO) {
+ icon_width = config.radio_width;
+ icon_height = config.radio_height;
+ } else {
+ icon_width = config.check_width;
+ icon_height = config.check_height;
+ }
+
int top_margin = GetTopMargin();
int icon_x = MenuConfig::instance().item_left_margin;
int icon_y = top_margin +
(height() - top_margin - GetBottomMargin() - icon_height) / 2;
+ NativeTheme::ExtraParams extra;
+ extra.menu_check.is_radio = type_ == RADIO;
+
// Draw the background.
gfx::Rect bg_bounds(0, 0, icon_x + icon_width, height());
- int bg_state = IsEnabled() ? MCB_NORMAL : MCB_DISABLED;
AdjustBoundsForRTLUI(&bg_bounds);
- RECT bg_rect = bg_bounds.ToRECT();
- NativeThemeWin::instance()->PaintMenuCheckBackground(
- NativeThemeWin::MENU, dc, MENU_POPUPCHECKBACKGROUND, bg_state,
- &bg_rect);
+ NativeTheme::instance()->Paint(canvas->AsCanvasSkia(),
+ NativeTheme::kMenuCheckBackground, state, bg_bounds, extra);
// And the check.
gfx::Rect icon_bounds(icon_x / 2, icon_y, icon_width, icon_height);
AdjustBoundsForRTLUI(&icon_bounds);
- RECT icon_rect = icon_bounds.ToRECT();
- NativeThemeWin::instance()->PaintMenuCheck(
- NativeThemeWin::MENU, dc, MENU_POPUPCHECK, state_id, &icon_rect,
- control_state);
+ NativeTheme::instance()->Paint(canvas->AsCanvasSkia(),
+ NativeTheme::kMenuCheck, state, bg_bounds, extra);
}
} // namespace views
diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc
index 94bd75b..6aed7cf 100644
--- a/views/controls/menu/menu_scroll_view_container.cc
+++ b/views/controls/menu/menu_scroll_view_container.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -21,11 +21,9 @@
#include "views/controls/menu/submenu_view.h"
#if defined(OS_WIN)
-#include "ui/gfx/native_theme_win.h"
-#endif
+#include "ui/gfx/native_theme.h"
-#if defined(OS_WIN)
-using gfx::NativeThemeWin;
+using gfx::NativeTheme;
#endif
// Height of the scroll arrow.
@@ -84,15 +82,13 @@ class MenuScrollButton : public View {
const MenuConfig& config = MenuConfig::instance();
#if defined(OS_WIN)
- HDC dc = canvas->BeginPlatformPaint();
-
// The background.
- RECT item_bounds = { 0, 0, width(), height() };
- NativeThemeWin::instance()->PaintMenuItemBackground(
- NativeThemeWin::MENU, dc, MENU_POPUPITEM, MPI_NORMAL, false,
- &item_bounds);
- canvas->EndPlatformPaint();
-
+ gfx::Rect item_bounds(0, 0, width(), height());
+ NativeTheme::ExtraParams extra;
+ extra.menu_item.is_selected = false;
+ NativeTheme::instance()->Paint(canvas->AsCanvasSkia(),
+ NativeTheme::kMenuItemBackground,
+ NativeTheme::kNormal, item_bounds, extra);
SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT);
#else
SkColor arrow_color = SK_ColorBLACK;
@@ -188,9 +184,10 @@ void MenuScrollViewContainer::OnPaintBackground(gfx::Canvas* canvas) {
#if defined(OS_WIN)
HDC dc = canvas->BeginPlatformPaint();
- RECT bounds = {0, 0, width(), height()};
- NativeThemeWin::instance()->PaintMenuBackground(
- NativeThemeWin::MENU, dc, MENU_POPUPBACKGROUND, 0, &bounds);
+ gfx::Rect bounds(0, 0, width(), height());
+ NativeTheme::ExtraParams extra;
+ NativeTheme::instance()->Paint(canvas->AsCanvasSkia(),
+ NativeTheme::kMenuPopupBackground, NativeTheme::kNormal, bounds, extra);
canvas->EndPlatformPaint();
#elif defined(OS_CHROMEOS)
static const SkColor kGradientColors[2] = {
diff --git a/views/controls/menu/menu_separator_win.cc b/views/controls/menu/menu_separator_win.cc
index d997dbd..e089149 100644
--- a/views/controls/menu/menu_separator_win.cc
+++ b/views/controls/menu/menu_separator_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,8 @@
#include <Vssym32.h>
#include "ui/gfx/canvas_skia.h"
-#include "ui/gfx/native_theme_win.h"
+#include "ui/gfx/native_theme.h"
+#include "ui/gfx/rect.h"
#include "views/controls/menu/menu_config.h"
#include "views/controls/menu/menu_item_view.h"
@@ -19,27 +20,24 @@ void MenuSeparator::OnPaint(gfx::Canvas* canvas) {
const MenuConfig& config = MenuConfig::instance();
// The gutter is rendered before the background.
int start_x = 0;
- int start_y = height() / 3 + 1; // +1 makes separator centered.
- HDC dc = canvas->BeginPlatformPaint();
- const gfx::NativeThemeWin* theme = gfx::NativeThemeWin::instance();
- // Delta is needed for non-classic to move separator up slightly.
- int delta = theme->IsClassicTheme(gfx::NativeThemeWin::MENU) ? 0 : 1;
+ const gfx::NativeTheme* theme = gfx::NativeTheme::instance();
if (config.render_gutter) {
// If render_gutter is true, we're on Vista and need to render the
// gutter, then indent the separator from the gutter.
- RECT gutter_bounds = { MenuItemView::label_start() -
- config.gutter_to_label - config.gutter_width, 0, 0,
- height() };
- gutter_bounds.right = gutter_bounds.left + config.gutter_width;
- theme->PaintMenuGutter(dc, MENU_POPUPGUTTER, MPI_NORMAL, &gutter_bounds);
- start_x = gutter_bounds.left + config.gutter_width;
- start_y = -delta;
+ gfx::Rect gutter_bounds(MenuItemView::label_start() -
+ config.gutter_to_label - config.gutter_width, 0,
+ config.gutter_width, height());
+ gfx::NativeTheme::ExtraParams extra;
+ theme->Paint(canvas->AsCanvasSkia(), gfx::NativeTheme::kMenuPopupGutter,
+ gfx::NativeTheme::kNormal, gutter_bounds, extra);
+ start_x = gutter_bounds.x() + config.gutter_width;
}
- RECT separator_bounds = { start_x, start_y, width(), height() - delta };
- theme->PaintMenuSeparator(
- dc, MENU_POPUPSEPARATOR, MPI_NORMAL, &separator_bounds);
- canvas->EndPlatformPaint();
+ gfx::Rect separator_bounds(start_x, 0, width(), height());
+ gfx::NativeTheme::ExtraParams extra;
+ extra.menu_separator.has_gutter = config.render_gutter;
+ theme->Paint(canvas->AsCanvasSkia(), gfx::NativeTheme::kMenuPopupSeparator,
+ gfx::NativeTheme::kNormal, separator_bounds, extra);
}
gfx::Size MenuSeparator::GetPreferredSize() {