Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: ui/native_theme/native_theme_base.cc

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/native_theme/native_theme_base.h ('k') | ui/native_theme/native_theme_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/native_theme/native_theme_base.cc
diff --git a/ui/native_theme/native_theme_base.cc b/ui/native_theme/native_theme_base.cc
index b9d2827db8961cd0c240bcf7c01f23fde6359027..0e2c1287bdeccbe9f62056afcd47aadcfc586484 100644
--- a/ui/native_theme/native_theme_base.cc
+++ b/ui/native_theme/native_theme_base.cc
@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/logging.h"
+#include "skia/ext/cdl_paint.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
@@ -156,7 +157,7 @@ gfx::Size NativeThemeBase::GetPartSize(Part part,
return gfx::Size();
}
-void NativeThemeBase::Paint(SkCanvas* canvas,
+void NativeThemeBase::Paint(CdlCanvas* canvas,
Part part,
State state,
const gfx::Rect& rect,
@@ -250,10 +251,11 @@ NativeThemeBase::NativeThemeBase()
NativeThemeBase::~NativeThemeBase() {
}
-void NativeThemeBase::PaintArrowButton(
- SkCanvas* canvas,
- const gfx::Rect& rect, Part direction, State state) const {
- SkPaint paint;
+void NativeThemeBase::PaintArrowButton(CdlCanvas* canvas,
+ const gfx::Rect& rect,
+ Part direction,
+ State state) const {
+ CdlPaint paint;
// Calculate button color.
SkScalar trackHSV[3];
@@ -317,12 +319,12 @@ void NativeThemeBase::PaintArrowButton(
}
outline.close();
- paint.setStyle(SkPaint::kFill_Style);
+ paint.setStyle(CdlPaint::kFill_Style);
paint.setColor(buttonColor);
canvas->drawPath(outline, paint);
paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStyle(CdlPaint::kStroke_Style);
SkScalar thumbHSV[3];
SkColorToHSV(thumb_inactive_color_, thumbHSV);
paint.setColor(OutlineColor(trackHSV, thumbHSV));
@@ -331,11 +333,11 @@ void NativeThemeBase::PaintArrowButton(
PaintArrow(canvas, rect, direction, GetArrowColor(state));
}
-void NativeThemeBase::PaintArrow(SkCanvas* gc,
+void NativeThemeBase::PaintArrow(CdlCanvas* gc,
const gfx::Rect& rect,
Part direction,
SkColor color) const {
- SkPaint paint;
+ CdlPaint paint;
paint.setColor(color);
SkPath path = PathForArrow(rect, direction);
@@ -388,12 +390,13 @@ gfx::Rect NativeThemeBase::BoundingRectForArrow(const gfx::Rect& rect) const {
side_length, side_length);
}
-void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas,
+void NativeThemeBase::PaintScrollbarTrack(
+ CdlCanvas* canvas,
Part part,
State state,
const ScrollbarTrackExtraParams& extra_params,
const gfx::Rect& rect) const {
- SkPaint paint;
+ CdlPaint paint;
SkIRect skrect;
skrect.set(rect.x(), rect.y(), rect.right(), rect.bottom());
@@ -409,7 +412,7 @@ void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas,
DrawBox(canvas, rect, paint);
}
-void NativeThemeBase::PaintScrollbarThumb(SkCanvas* canvas,
+void NativeThemeBase::PaintScrollbarThumb(CdlCanvas* canvas,
Part part,
State state,
const gfx::Rect& rect,
@@ -422,7 +425,7 @@ void NativeThemeBase::PaintScrollbarThumb(SkCanvas* canvas,
SkScalar thumb[3];
SkColorToHSV(hovered ? thumb_active_color_ : thumb_inactive_color_, thumb);
- SkPaint paint;
+ CdlPaint paint;
paint.setColor(SaturateAndBrighten(thumb, 0, 0.02f));
SkIRect skrect;
@@ -489,12 +492,11 @@ void NativeThemeBase::PaintScrollbarThumb(SkCanvas* canvas,
}
}
-void NativeThemeBase::PaintScrollbarCorner(SkCanvas* canvas,
+void NativeThemeBase::PaintScrollbarCorner(CdlCanvas* canvas,
State state,
- const gfx::Rect& rect) const {
-}
+ const gfx::Rect& rect) const {}
-void NativeThemeBase::PaintCheckbox(SkCanvas* canvas,
+void NativeThemeBase::PaintCheckbox(CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button) const {
@@ -502,9 +504,9 @@ void NativeThemeBase::PaintCheckbox(SkCanvas* canvas,
SkIntToScalar(2));
if (!skrect.isEmpty()) {
// Draw the checkmark / dash.
- SkPaint paint;
+ CdlPaint paint;
paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStyle(CdlPaint::kStroke_Style);
if (state == kDisabled)
paint.setColor(kCheckboxStrokeDisabledColor);
else
@@ -533,11 +535,10 @@ void NativeThemeBase::PaintCheckbox(SkCanvas* canvas,
// Returns the rectangle within which any additional decorations should be
// drawn, or empty if none.
SkRect NativeThemeBase::PaintCheckboxRadioCommon(
- SkCanvas* canvas,
+ CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const SkScalar borderRadius) const {
-
SkRect skrect = gfx::RectToSkRect(rect);
// Use the largest square that fits inside the provided rectangle.
@@ -552,9 +553,9 @@ SkRect NativeThemeBase::PaintCheckboxRadioCommon(
// to have to worry about '- 1' and '+ 1' calculations below having overflow
// or underflow.
if (skrect.width() <= 2) {
- SkPaint paint;
+ CdlPaint paint;
paint.setColor(kCheckboxTinyColor);
- paint.setStyle(SkPaint::kFill_Style);
+ paint.setStyle(CdlPaint::kFill_Style);
canvas->drawRect(skrect, paint);
// Too small to draw anything more.
return SkRect::MakeEmpty();
@@ -565,7 +566,7 @@ SkRect NativeThemeBase::PaintCheckboxRadioCommon(
// Draw the drop shadow below the widget.
if (state != kPressed) {
- SkPaint paint;
+ CdlPaint paint;
paint.setAntiAlias(true);
SkRect shadowRect = skrect;
shadowRect.offset(0, 1);
@@ -575,7 +576,7 @@ SkRect NativeThemeBase::PaintCheckboxRadioCommon(
paint.setColor(kCheckboxShadowHoveredColor);
else
paint.setColor(kCheckboxShadowColor);
- paint.setStyle(SkPaint::kFill_Style);
+ paint.setStyle(CdlPaint::kFill_Style);
canvas->drawRoundRect(shadowRect, borderRadius, borderRadius, paint);
}
@@ -594,11 +595,11 @@ SkRect NativeThemeBase::PaintCheckboxRadioCommon(
else /* kNormal */
startEndColors = kCheckboxGradientColors;
SkColor colors[3] = {startEndColors[0], startEndColors[0], startEndColors[1]};
- SkPaint paint;
+ CdlPaint paint;
paint.setAntiAlias(true);
- paint.setShader(SkGradientShader::MakeLinear(gradient_bounds, colors, NULL, 3,
- SkShader::kClamp_TileMode));
- paint.setStyle(SkPaint::kFill_Style);
+ paint.setShader(WrapSkShader(SkGradientShader::MakeLinear(
+ gradient_bounds, colors, NULL, 3, SkShader::kClamp_TileMode)));
+ paint.setStyle(CdlPaint::kFill_Style);
canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint);
paint.setShader(NULL);
@@ -609,7 +610,7 @@ SkRect NativeThemeBase::PaintCheckboxRadioCommon(
paint.setColor(kCheckboxBorderDisabledColor);
else
paint.setColor(kCheckboxBorderColor);
- paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStyle(CdlPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(1));
skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f));
canvas->drawRoundRect(skrect, borderRadius, borderRadius, paint);
@@ -619,11 +620,10 @@ SkRect NativeThemeBase::PaintCheckboxRadioCommon(
return skrect;
}
-void NativeThemeBase::PaintRadio(SkCanvas* canvas,
- State state,
- const gfx::Rect& rect,
- const ButtonExtraParams& button) const {
-
+void NativeThemeBase::PaintRadio(CdlCanvas* canvas,
+ State state,
+ const gfx::Rect& rect,
+ const ButtonExtraParams& button) const {
// Most of a radio button is the same as a checkbox, except the the rounded
// square is a circle (i.e. border radius >= 100%).
const SkScalar radius = SkFloatToScalar(
@@ -631,9 +631,9 @@ void NativeThemeBase::PaintRadio(SkCanvas* canvas,
SkRect skrect = PaintCheckboxRadioCommon(canvas, state, rect, radius);
if (!skrect.isEmpty() && button.checked) {
// Draw the dot.
- SkPaint paint;
+ CdlPaint paint;
paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kFill_Style);
+ paint.setStyle(CdlPaint::kFill_Style);
if (state == kDisabled)
paint.setColor(kRadioDotDisabledColor);
else
@@ -645,11 +645,11 @@ void NativeThemeBase::PaintRadio(SkCanvas* canvas,
}
}
-void NativeThemeBase::PaintButton(SkCanvas* canvas,
+void NativeThemeBase::PaintButton(CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button) const {
- SkPaint paint;
+ CdlPaint paint;
SkRect skrect = gfx::RectToSkRect(rect);
SkColor base_color = button.background_color;
@@ -676,11 +676,10 @@ void NativeThemeBase::PaintButton(SkCanvas* canvas,
std::swap(gradient_bounds[0], gradient_bounds[1]);
SkColor colors[2] = { light_color, base_color };
- paint.setStyle(SkPaint::kFill_Style);
+ paint.setStyle(CdlPaint::kFill_Style);
paint.setAntiAlias(true);
- paint.setShader(
- SkGradientShader::MakeLinear(
- gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode));
+ paint.setShader(WrapSkShader(SkGradientShader::MakeLinear(
+ gradient_bounds, colors, NULL, 2, SkShader::kClamp_TileMode)));
canvas->drawRoundRect(skrect, SkIntToScalar(1), SkIntToScalar(1), paint);
paint.setShader(NULL);
@@ -691,7 +690,7 @@ void NativeThemeBase::PaintButton(SkCanvas* canvas,
border_alpha = 0xff;
paint.setColor(GetSystemColor(kColorId_FocusedBorderColor));
}
- paint.setStyle(SkPaint::kStroke_Style);
+ paint.setStyle(CdlPaint::kStroke_Style);
paint.setStrokeWidth(SkIntToScalar(1));
paint.setAlpha(border_alpha);
skrect.inset(SkFloatToScalar(.5f), SkFloatToScalar(.5f));
@@ -699,28 +698,28 @@ void NativeThemeBase::PaintButton(SkCanvas* canvas,
}
}
-void NativeThemeBase::PaintTextField(SkCanvas* canvas,
+void NativeThemeBase::PaintTextField(CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const TextFieldExtraParams& text) const {
SkRect bounds;
bounds.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
- SkPaint fill_paint;
- fill_paint.setStyle(SkPaint::kFill_Style);
+ CdlPaint fill_paint;
+ fill_paint.setStyle(CdlPaint::kFill_Style);
fill_paint.setColor(text.background_color);
canvas->drawRect(bounds, fill_paint);
// Text INPUT, listbox SELECT, and TEXTAREA have consistent borders.
// border: 1px solid #a9a9a9
- SkPaint stroke_paint;
- stroke_paint.setStyle(SkPaint::kStroke_Style);
+ CdlPaint stroke_paint;
+ stroke_paint.setStyle(CdlPaint::kStroke_Style);
stroke_paint.setColor(kTextBorderColor);
canvas->drawRect(bounds, stroke_paint);
}
void NativeThemeBase::PaintMenuList(
- SkCanvas* canvas,
+ CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list) const {
@@ -733,10 +732,10 @@ void NativeThemeBase::PaintMenuList(
PaintButton(canvas, state, rect, button);
}
- SkPaint paint;
+ CdlPaint paint;
paint.setColor(menu_list.arrow_color);
paint.setAntiAlias(true);
- paint.setStyle(SkPaint::kFill_Style);
+ paint.setStyle(CdlPaint::kFill_Style);
int arrow_size = menu_list.arrow_size;
gfx::Rect arrow(
@@ -757,28 +756,28 @@ void NativeThemeBase::PaintMenuList(
}
void NativeThemeBase::PaintMenuPopupBackground(
- SkCanvas* canvas,
+ CdlCanvas* canvas,
const gfx::Size& size,
const MenuBackgroundExtraParams& menu_background) const {
canvas->drawColor(kMenuPopupBackgroundColor, SkBlendMode::kSrc);
}
void NativeThemeBase::PaintMenuItemBackground(
- SkCanvas* canvas,
+ CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuItemExtraParams& menu_item) const {
// By default don't draw anything over the normal background.
}
-void NativeThemeBase::PaintSliderTrack(SkCanvas* canvas,
+void NativeThemeBase::PaintSliderTrack(CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const SliderExtraParams& slider) const {
const int kMidX = rect.x() + rect.width() / 2;
const int kMidY = rect.y() + rect.height() / 2;
- SkPaint paint;
+ CdlPaint paint;
paint.setColor(kSliderTrackBackgroundColor);
SkRect skrect;
@@ -796,7 +795,7 @@ void NativeThemeBase::PaintSliderTrack(SkCanvas* canvas,
canvas->drawRect(skrect, paint);
}
-void NativeThemeBase::PaintSliderThumb(SkCanvas* canvas,
+void NativeThemeBase::PaintSliderThumb(CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const SliderExtraParams& slider) const {
@@ -804,7 +803,7 @@ void NativeThemeBase::PaintSliderThumb(SkCanvas* canvas,
const int kMidX = rect.x() + rect.width() / 2;
const int kMidY = rect.y() + rect.height() / 2;
- SkPaint paint;
+ CdlPaint paint;
paint.setColor(hovered ? SK_ColorWHITE : kSliderThumbLightGrey);
SkIRect skrect;
@@ -834,7 +833,8 @@ void NativeThemeBase::PaintSliderThumb(SkCanvas* canvas,
}
}
-void NativeThemeBase::PaintInnerSpinButton(SkCanvas* canvas,
+void NativeThemeBase::PaintInnerSpinButton(
+ CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const InnerSpinButtonExtraParams& spin_button) const {
@@ -857,7 +857,7 @@ void NativeThemeBase::PaintInnerSpinButton(SkCanvas* canvas,
}
void NativeThemeBase::PaintProgressBar(
- SkCanvas* canvas,
+ CdlCanvas* canvas,
State state,
const gfx::Rect& rect,
const ProgressBarExtraParams& progress_bar) const {
@@ -876,9 +876,9 @@ void NativeThemeBase::PaintProgressBar(
path.moveTo(rect.x() + i * tick_spacing, rect.y());
path.rLineTo(0, rect.height());
}
- SkPaint stroke_paint;
+ CdlPaint stroke_paint;
stroke_paint.setColor(kProgressTickColor);
- stroke_paint.setStyle(SkPaint::kStroke_Style);
+ stroke_paint.setStyle(CdlPaint::kStroke_Style);
stroke_paint.setStrokeWidth(stroke_width);
canvas->drawPath(path, stroke_paint);
@@ -886,9 +886,9 @@ void NativeThemeBase::PaintProgressBar(
gfx::Rect progress_rect(progress_bar.value_rect_x, progress_bar.value_rect_y,
progress_bar.value_rect_width,
progress_bar.value_rect_height);
- SkPaint progress_paint;
+ CdlPaint progress_paint;
progress_paint.setColor(kProgressValueColor);
- progress_paint.setStyle(SkPaint::kFill_Style);
+ progress_paint.setStyle(CdlPaint::kFill_Style);
canvas->drawRect(gfx::RectToSkRect(progress_rect), progress_paint);
// Draw the border.
@@ -924,29 +924,29 @@ SkColor NativeThemeBase::GetArrowColor(State state) const {
return OutlineColor(track_hsv, thumb_hsv);
}
-void NativeThemeBase::DrawVertLine(SkCanvas* canvas,
+void NativeThemeBase::DrawVertLine(CdlCanvas* canvas,
int x,
int y1,
int y2,
- const SkPaint& paint) const {
+ const CdlPaint& paint) const {
SkIRect skrect;
skrect.set(x, y1, x + 1, y2 + 1);
canvas->drawIRect(skrect, paint);
}
-void NativeThemeBase::DrawHorizLine(SkCanvas* canvas,
+void NativeThemeBase::DrawHorizLine(CdlCanvas* canvas,
int x1,
int x2,
int y,
- const SkPaint& paint) const {
+ const CdlPaint& paint) const {
SkIRect skrect;
skrect.set(x1, y, x2 + 1, y + 1);
canvas->drawIRect(skrect, paint);
}
-void NativeThemeBase::DrawBox(SkCanvas* canvas,
+void NativeThemeBase::DrawBox(CdlCanvas* canvas,
const gfx::Rect& rect,
- const SkPaint& paint) const {
+ const CdlPaint& paint) const {
const int right = rect.x() + rect.width() - 1;
const int bottom = rect.y() + rect.height() - 1;
DrawHorizLine(canvas, rect.x(), right, rect.y(), paint);
« no previous file with comments | « ui/native_theme/native_theme_base.h ('k') | ui/native_theme/native_theme_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698