diff options
Diffstat (limited to 'ui/gfx/canvas_skia.cc')
-rw-r--r-- | ui/gfx/canvas_skia.cc | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc index b790076..cdd4ec5 100644 --- a/ui/gfx/canvas_skia.cc +++ b/ui/gfx/canvas_skia.cc @@ -11,8 +11,10 @@ #include "ui/base/text/text_elider.h" #include "ui/gfx/font.h" #include "ui/gfx/font_list.h" +#include "ui/gfx/insets.h" #include "ui/gfx/rect.h" #include "ui/gfx/render_text.h" +#include "ui/gfx/shadow_value.h" #include "ui/gfx/skia_util.h" namespace { @@ -218,12 +220,13 @@ void Canvas::SizeStringInt(const string16& text, } } -void Canvas::DrawStringInt(const string16& text, - const gfx::Font& font, - SkColor color, - int x, int y, int w, int h, - int flags) { - if (!IntersectsClipRectInt(x, y, w, h)) +void Canvas::DrawStringWithShadows(const string16& text, + const gfx::Font& font, + SkColor color, + const gfx::Rect& text_bounds, + int flags, + const std::vector<ShadowValue>& shadows) { + if (!IntersectsClipRect(text_bounds)) return; flags = AdjustPlatformSpecificFlags(text, flags); @@ -237,10 +240,13 @@ void Canvas::DrawStringInt(const string16& text, } #endif - gfx::Rect rect(x, y, w, h); + gfx::Rect clip_rect(text_bounds); + clip_rect.Inset(ShadowValue::GetMargin(shadows)); + canvas_->save(SkCanvas::kClip_SaveFlag); - ClipRect(rect); + ClipRect(clip_rect); + gfx::Rect rect(text_bounds); string16 adjusted_text = text; #if defined(OS_WIN) @@ -249,6 +255,7 @@ void Canvas::DrawStringInt(const string16& text, #endif scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); + render_text->SetTextShadows(shadows); if (flags & MULTI_LINE) { ui::WordWrapBehavior wrap_behavior = ui::IGNORE_LONG_WORDS; @@ -258,7 +265,10 @@ void Canvas::DrawStringInt(const string16& text, wrap_behavior = ui::ELIDE_LONG_WORDS; std::vector<string16> strings; - ui::ElideRectangleText(adjusted_text, font, w, h, wrap_behavior, + ui::ElideRectangleText(adjusted_text, + font, + text_bounds.width(), text_bounds.height(), + wrap_behavior, &strings); for (size_t i = 0; i < strings.size(); i++) { @@ -269,8 +279,11 @@ void Canvas::DrawStringInt(const string16& text, // first line. This may not be correct if different lines in the text have // different heights, but avoids needing to do two passes. const int line_height = render_text->GetStringSize().height(); - if (i == 0) - rect.Offset(0, VAlignText(strings.size() * line_height, flags, h)); + if (i == 0) { + rect.Offset(0, VAlignText(strings.size() * line_height, + flags, + text_bounds.height())); + } rect.set_height(line_height); ApplyUnderlineStyle(range, render_text.get()); @@ -293,14 +306,18 @@ void Canvas::DrawStringInt(const string16& text, } #endif - if (elide_text) - ElideTextAndAdjustRange(font, w, &adjusted_text, &range); + if (elide_text) { + ElideTextAndAdjustRange(font, + text_bounds.width(), + &adjusted_text, + &range); + } UpdateRenderText(rect, adjusted_text, font, flags, color, render_text.get()); const int line_height = render_text->GetStringSize().height(); - rect.Offset(0, VAlignText(line_height, flags, h)); + rect.Offset(0, VAlignText(line_height, flags, text_bounds.height())); rect.set_height(line_height); render_text->SetDisplayRect(rect); |