summaryrefslogtreecommitdiffstats
path: root/views/controls
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-24 23:30:26 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-24 23:30:26 +0000
commita219f823813abcf778eceea2eb81f2d3967009a8 (patch)
treee1a9e06b697d539260472a9faa2ea86d5984a4bf /views/controls
parent755e1b73a0b4894ecc36401fd042c744e7837844 (diff)
downloadchromium_src-a219f823813abcf778eceea2eb81f2d3967009a8.zip
chromium_src-a219f823813abcf778eceea2eb81f2d3967009a8.tar.gz
chromium_src-a219f823813abcf778eceea2eb81f2d3967009a8.tar.bz2
Canvas refactoring part 3.
- Replace Canvas instance users with CanvasSkia users. - Rename Canvas2 to Canvas. - Delete Canvas subclass of CanvasSkia. This has created some ugliness around the fact that people that used SkCanvas methods on Canvas now have to go through AsCanvasSkia first. This is temporary ugliness that will be eradicated as I incrementally build out the new Canvas API. BUG=none TEST=none Review URL: http://codereview.chromium.org/2825018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50784 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r--views/controls/button/text_button.cc23
-rw-r--r--views/controls/label.cc6
-rw-r--r--views/controls/menu/menu_controller.cc4
-rw-r--r--views/controls/menu/menu_item_view_gtk.cc15
-rw-r--r--views/controls/menu/menu_item_view_win.cc14
-rw-r--r--views/controls/menu/menu_scroll_view_container.cc13
-rw-r--r--views/controls/menu/menu_separator_win.cc6
-rw-r--r--views/controls/progress_bar.cc6
-rw-r--r--views/controls/tabbed_pane/native_tabbed_pane_win.cc6
-rw-r--r--views/controls/table/table_view.cc4
10 files changed, 50 insertions, 47 deletions
diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc
index 98c69fe..f2b7613 100644
--- a/views/controls/button/text_button.cc
+++ b/views/controls/button/text_button.cc
@@ -8,7 +8,7 @@
#include "app/throb_animation.h"
#include "app/resource_bundle.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "views/controls/button/button.h"
#include "views/event.h"
#include "grit/app_resources.h"
@@ -256,12 +256,13 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) {
if (show_highlighted_ && hover_animation_->is_animating()) {
// Draw the hover bitmap into an offscreen buffer, then blend it
// back into the current canvas.
- canvas->saveLayerAlpha(NULL,
+ canvas->AsCanvasSkia()->saveLayerAlpha(NULL,
static_cast<int>(hover_animation_->GetCurrentValue() * 255),
SkCanvas::kARGB_NoClipLayer_SaveFlag);
- canvas->drawARGB(0, 255, 255, 255, SkXfermode::kClear_Mode);
+ canvas->AsCanvasSkia()->drawARGB(0, 255, 255, 255,
+ SkXfermode::kClear_Mode);
PaintBorder(canvas);
- canvas->restore();
+ canvas->AsCanvasSkia()->restore();
} else if ((show_highlighted_ &&
(state_ == BS_HOT || state_ == BS_PUSHED)) ||
(state_ == BS_NORMAL && normal_has_border_)) {
@@ -330,19 +331,17 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) {
else
text_color = color_;
- int draw_string_flags = gfx::Canvas::DefaultCanvasTextAlignment() |
+ int draw_string_flags = gfx::CanvasSkia::DefaultCanvasTextAlignment() |
PrefixTypeToCanvasType(prefix_type_);
if (for_drag) {
#if defined(OS_WIN)
// TODO(erg): Either port DrawStringWithHalo to linux or find an
// alternative here.
- canvas->DrawStringWithHalo(text_, font_, text_color, color_highlight_,
- text_bounds.x(),
- text_bounds.y(),
- text_bounds.width(),
- text_bounds.height(),
- draw_string_flags);
+ canvas->AsCanvasSkia()->DrawStringWithHalo(
+ text_, font_, text_color, color_highlight_, text_bounds.x(),
+ text_bounds.y(), text_bounds.width(), text_bounds.height(),
+ draw_string_flags);
#else
canvas->DrawStringInt(text_,
font_,
@@ -381,7 +380,7 @@ void TextButton::UpdateColor() {
void TextButton::UpdateTextSize() {
int width = 0, height = 0;
- gfx::Canvas::SizeStringInt(
+ gfx::CanvasSkia::SizeStringInt(
text_, font_, &width, &height,
gfx::Canvas::NO_ELLIPSIS | PrefixTypeToCanvasType(prefix_type_));
text_size_.SetSize(width, font_.height());
diff --git a/views/controls/label.cc b/views/controls/label.cc
index 88a755d..d30a62b 100644
--- a/views/controls/label.cc
+++ b/views/controls/label.cc
@@ -13,7 +13,7 @@
#include "base/i18n/rtl.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/color_utils.h"
#include "gfx/font.h"
#include "gfx/insets.h"
@@ -67,7 +67,7 @@ int Label::GetHeightForWidth(int w) {
w = std::max(0, w - GetInsets().width());
int h = font_.height();
- gfx::Canvas::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags());
+ gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, ComputeMultiLineFlags());
return h + GetInsets().height();
}
@@ -388,7 +388,7 @@ gfx::Size Label::GetTextSize() const {
int flags = ComputeMultiLineFlags();
if (!is_multi_line_)
flags |= gfx::Canvas::NO_ELLIPSIS;
- gfx::Canvas::SizeStringInt(text_, font_, &w, &h, flags);
+ gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags);
text_size_.SetSize(w, h);
text_size_valid_ = true;
}
diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc
index de31f02..955451a 100644
--- a/views/controls/menu/menu_controller.cc
+++ b/views/controls/menu/menu_controller.cc
@@ -9,7 +9,7 @@
#include "base/i18n/rtl.h"
#include "base/keyboard_codes.h"
#include "base/time.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/menu/menu_scroll_view_container.h"
#include "views/controls/menu/submenu_view.h"
@@ -470,7 +470,7 @@ void MenuController::OnMouseDragged(SubmenuView* source,
View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc);
View::ConvertPointToView(NULL, item, &press_loc);
// TODO(beng): Convert to CanvasSkia
- gfx::Canvas canvas(item->width(), item->height(), false);
+ gfx::CanvasSkia canvas(item->width(), item->height(), false);
item->Paint(&canvas, true);
OSExchangeData data;
diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc
index f3e7556..db21e01 100644
--- a/views/controls/menu/menu_item_view_gtk.cc
+++ b/views/controls/menu/menu_item_view_gtk.cc
@@ -5,7 +5,7 @@
#include "views/controls/menu/menu_item_view.h"
#include "app/resource_bundle.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/favicon_size.h"
#include "grit/app_resources.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
@@ -70,7 +70,8 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
// only need the background when we want it to look different, as when we're
// selected.
if (render_selection)
- canvas->drawColor(kSelectedBackgroundColor, SkXfermode::kSrc_Mode);
+ canvas->AsCanvasSkia()->drawColor(kSelectedBackgroundColor,
+ SkXfermode::kSrc_Mode);
// Render the check.
if (type_ == CHECKBOX && GetDelegate()->IsItemChecked(GetCommand())) {
@@ -103,13 +104,13 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
paint.setShader(shader);
shader->unref();
int radius = kIndicatorSize / 2;
- canvas->drawCircle(radius, radius, radius, paint);
+ canvas->AsCanvasSkia()->drawCircle(radius, radius, radius, paint);
paint.setStrokeWidth(SkIntToScalar(0));
paint.setShader(NULL);
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(kBaseStroke);
- canvas->drawCircle(radius, radius, radius, paint);
+ canvas->AsCanvasSkia()->drawCircle(radius, radius, radius, paint);
if (GetDelegate()->IsItemChecked(GetCommand())) {
SkPoint selected_gradient_points[2];
@@ -125,13 +126,15 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
paint.setShader(shader);
shader->unref();
paint.setStyle(SkPaint::kFill_Style);
- canvas->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint);
+ canvas->AsCanvasSkia()->drawCircle(radius, radius,
+ kSelectedIndicatorSize / 2, paint);
paint.setStrokeWidth(SkIntToScalar(0));
paint.setShader(NULL);
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(kIndicatorStroke);
- canvas->drawCircle(radius, radius, kSelectedIndicatorSize / 2, paint);
+ canvas->AsCanvasSkia()->drawCircle(radius, radius,
+ kSelectedIndicatorSize / 2, paint);
}
canvas->TranslateInt(
diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc
index 2ac0921..b491092 100644
--- a/views/controls/menu/menu_item_view_win.cc
+++ b/views/controls/menu/menu_item_view_win.cc
@@ -8,7 +8,7 @@
#include <Vssym32.h>
#include "app/l10n_util.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/native_theme_win.h"
#include "grit/app_strings.h"
#include "views/controls/menu/menu_config.h"
@@ -34,7 +34,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
GetChildViewCount() == 0);
int state = render_selection ? MPI_HOT :
(IsEnabled() ? MPI_NORMAL : MPI_DISABLED);
- HDC dc = canvas->beginPlatformPaint();
+ HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint();
// The gutter is rendered before the background.
if (config.render_gutter && !for_drag) {
@@ -87,10 +87,10 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
// foreground and background colors are for the text to draw the correct
// halo. Instead, just draw black on white, which will look good in most
// cases.
- canvas->DrawStringWithHalo(GetTitle(), font, 0x00000000, 0xFFFFFFFF,
- text_bounds.x(), text_bounds.y(),
- text_bounds.width(), text_bounds.height(),
- GetRootMenuItem()->GetDrawStringFlags());
+ canvas->AsCanvasSkia()->DrawStringWithHalo(
+ GetTitle(), font, 0x00000000, 0xFFFFFFFF, text_bounds.x(),
+ text_bounds.y(), text_bounds.width(), text_bounds.height(),
+ GetRootMenuItem()->GetDrawStringFlags());
} else {
canvas->DrawStringInt(GetTitle(), font, fg_color,
text_bounds.x(), text_bounds.y(), text_bounds.width(),
@@ -131,7 +131,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
NativeTheme::MENU, dc, MENU_POPUPSUBMENU, state_id, &arrow_rect,
arrow_direction, render_selection);
}
- canvas->endPlatformPaint();
+ canvas->AsCanvasSkia()->endPlatformPaint();
}
void MenuItemView::PaintCheck(HDC dc,
int state_id,
diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc
index b538f5b..d3a7ae8 100644
--- a/views/controls/menu/menu_scroll_view_container.cc
+++ b/views/controls/menu/menu_scroll_view_container.cc
@@ -10,7 +10,7 @@
#include <Vssym32.h>
#endif
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/color_utils.h"
#include "views/border.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
@@ -83,14 +83,14 @@ class MenuScrollButton : public View {
const MenuConfig& config = MenuConfig::instance();
#if defined(OS_WIN)
- HDC dc = canvas->beginPlatformPaint();
+ HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint();
// The background.
RECT item_bounds = { 0, 0, width(), height() };
NativeTheme::instance()->PaintMenuItemBackground(
NativeTheme::MENU, dc, MENU_POPUPITEM, MPI_NORMAL, false,
&item_bounds);
- canvas->endPlatformPaint();
+ canvas->AsCanvasSkia()->endPlatformPaint();
SkColor arrow_color = color_utils::GetSysSkColor(COLOR_MENUTEXT);
#else
@@ -185,11 +185,11 @@ void MenuScrollViewContainer::PaintBackground(gfx::Canvas* canvas) {
}
#if defined(OS_WIN)
- HDC dc = canvas->beginPlatformPaint();
+ HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint();
RECT bounds = {0, 0, width(), height()};
NativeTheme::instance()->PaintMenuBackground(
NativeTheme::MENU, dc, MENU_POPUPBACKGROUND, 0, &bounds);
- canvas->endPlatformPaint();
+ canvas->AsCanvasSkia()->endPlatformPaint();
#elif defined(OS_CHROMEOS)
static const SkColor kGradientColors[2] = {
SK_ColorWHITE,
@@ -220,7 +220,8 @@ void MenuScrollViewContainer::PaintBackground(gfx::Canvas* canvas) {
canvas->FillRectInt(0, 0, width(), height(), paint);
#else
// This is the same as COLOR_TOOLBAR.
- canvas->drawColor(SkColorSetRGB(210, 225, 246), SkXfermode::kSrc_Mode);
+ canvas->AsCanvasSkia()->drawColor(SkColorSetRGB(210, 225, 246),
+ SkXfermode::kSrc_Mode);
#endif
}
diff --git a/views/controls/menu/menu_separator_win.cc b/views/controls/menu/menu_separator_win.cc
index 58e2bb4..ed3f34f 100644
--- a/views/controls/menu/menu_separator_win.cc
+++ b/views/controls/menu/menu_separator_win.cc
@@ -8,7 +8,7 @@
#include <uxtheme.h>
#include <Vssym32.h>
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/native_theme_win.h"
#include "views/controls/menu/menu_config.h"
#include "views/controls/menu/menu_item_view.h"
@@ -20,7 +20,7 @@ void MenuSeparator::Paint(gfx::Canvas* canvas) {
// The gutter is rendered before the background.
int start_x = 0;
int start_y = height() / 3;
- HDC dc = canvas->beginPlatformPaint();
+ HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint();
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.
@@ -36,7 +36,7 @@ void MenuSeparator::Paint(gfx::Canvas* canvas) {
RECT separator_bounds = { start_x, start_y, width(), height() };
gfx::NativeTheme::instance()->PaintMenuSeparator(
dc, MENU_POPUPSEPARATOR, MPI_NORMAL, &separator_bounds);
- canvas->endPlatformPaint();
+ canvas->AsCanvasSkia()->endPlatformPaint();
}
gfx::Size MenuSeparator::GetPreferredSize() {
diff --git a/views/controls/progress_bar.cc b/views/controls/progress_bar.cc
index 19f10c5..1006acd 100644
--- a/views/controls/progress_bar.cc
+++ b/views/controls/progress_bar.cc
@@ -10,7 +10,7 @@
#include "app/resource_bundle.h"
#include "base/logging.h"
#include "base/string_util.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/color_utils.h"
#include "gfx/font.h"
#include "gfx/insets.h"
@@ -75,7 +75,7 @@ static void FillRoundRect(gfx::Canvas* canvas,
} else {
paint.setColor(gradient_start_color);
}
- canvas->drawPath(path, paint);
+ canvas->AsCanvasSkia()->drawPath(path, paint);
}
static void StrokeRoundRect(gfx::Canvas* canvas,
@@ -92,7 +92,7 @@ static void StrokeRoundRect(gfx::Canvas* canvas,
paint.setStyle(SkPaint::kStroke_Style);
paint.setFlags(SkPaint::kAntiAlias_Flag);
paint.setStrokeWidth(SkIntToScalar(stroke_width));
- canvas->drawPath(path, paint);
+ canvas->AsCanvasSkia()->drawPath(path, paint);
}
} // anonymous namespace
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc
index 87f2ebb..832d4a2 100644
--- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc
+++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc
@@ -10,7 +10,7 @@
#include "app/resource_bundle.h"
#include "base/logging.h"
#include "base/stl_util-inl.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/font.h"
#include "gfx/native_theme_win.h"
#include "views/controls/tabbed_pane/tabbed_pane.h"
@@ -36,10 +36,10 @@ class TabBackground : public Background {
virtual ~TabBackground() {}
virtual void Paint(gfx::Canvas* canvas, View* view) const {
- HDC dc = canvas->beginPlatformPaint();
+ HDC dc = canvas->AsCanvasSkia()->beginPlatformPaint();
RECT r = {0, 0, view->width(), view->height()};
gfx::NativeTheme::instance()->PaintTabPanelBackground(dc, &r);
- canvas->endPlatformPaint();
+ canvas->AsCanvasSkia()->endPlatformPaint();
}
private:
diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc
index 75425c2..8b86a6e 100644
--- a/views/controls/table/table_view.cc
+++ b/views/controls/table/table_view.cc
@@ -16,7 +16,7 @@
#include "base/i18n/rtl.h"
#include "base/string_util.h"
#include "base/win_util.h"
-#include "gfx/canvas.h"
+#include "gfx/canvas_skia.h"
#include "gfx/favicon_size.h"
#include "gfx/font.h"
#include "gfx/icon_util.h"
@@ -1157,7 +1157,7 @@ void TableView::PaintAltText() {
// Pad by 1 for halo.
canvas.DrawStringWithHalo(alt_text_, font, SK_ColorDKGRAY, SK_ColorWHITE, 1,
1, bounds.width() - 2, bounds.height() - 2,
- gfx::Canvas::DefaultCanvasTextAlignment());
+ gfx::CanvasSkia::DefaultCanvasTextAlignment());
canvas.getTopPlatformDevice().drawToHDC(dc, bounds.x(), bounds.y(), NULL);
ReleaseDC(GetNativeControlHWND(), dc);
}