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

Unified Diff: ui/gfx/canvas_skia.cc

Issue 14322007: Add line height setting to views::Label & use it for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 8 months 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/gfx/canvas_mac.mm ('k') | ui/gfx/canvas_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/canvas_skia.cc
diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc
index 2d995cfb8664f7367d398250342e4d9bc55f60b3..baed1dd571ba7767fe9f4f58d486bfea104fef4d 100644
--- a/ui/gfx/canvas_skia.cc
+++ b/ui/gfx/canvas_skia.cc
@@ -169,6 +169,7 @@ int AdjustPlatformSpecificFlags(const string16& text, int flags) {
void Canvas::SizeStringInt(const string16& text,
const Font& font,
int* width, int* height,
+ int line_height,
int flags) {
DCHECK_GE(*width, 0);
DCHECK_GE(*height, 0);
@@ -201,7 +202,7 @@ void Canvas::SizeStringInt(const string16& text,
render_text->SetText(strings[i]);
const Size string_size = render_text->GetStringSize();
w = std::max(w, string_size.width());
- h += string_size.height();
+ h += (i > 0 && line_height > 0) ? line_height : string_size.height();
}
*width = w;
*height = h;
@@ -228,6 +229,7 @@ void Canvas::DrawStringWithShadows(const string16& text,
const Font& font,
SkColor color,
const Rect& text_bounds,
+ int line_height,
int flags,
const ShadowValues& shadows) {
if (!IntersectsClipRect(text_bounds))
@@ -268,18 +270,22 @@ void Canvas::DrawStringWithShadows(const string16& text,
for (size_t i = 0; i < strings.size(); i++) {
ui::Range range = StripAcceleratorChars(flags, &strings[i]);
UpdateRenderText(rect, strings[i], font, flags, color, render_text.get());
- const int line_height = render_text->GetStringSize().height();
+ int line_padding = 0;
+ if (line_height > 0)
+ line_padding = line_height - render_text->GetStringSize().height();
+ else
+ line_height = render_text->GetStringSize().height();
// TODO(msw|asvitkine): Center Windows multi-line text: crbug.com/107357
#if !defined(OS_WIN)
if (i == 0) {
// TODO(msw|asvitkine): Support multi-line text with varied heights.
- const int aggregate_height = strings.size() * line_height;
- rect += Vector2d(0, (text_bounds.height() - aggregate_height) / 2);
+ const int text_height = strings.size() * line_height - line_padding;
+ rect += Vector2d(0, (text_bounds.height() - text_height) / 2);
}
#endif
- rect.set_height(line_height);
+ rect.set_height(line_height - line_padding);
if (range.IsValid())
render_text->ApplyStyle(UNDERLINE, true, range);
@@ -313,10 +319,10 @@ void Canvas::DrawStringWithShadows(const string16& text,
UpdateRenderText(rect, adjusted_text, font, flags, color,
render_text.get());
- const int line_height = render_text->GetStringSize().height();
+ const int text_height = render_text->GetStringSize().height();
// Center the text vertically.
- rect += Vector2d(0, (text_bounds.height() - line_height) / 2);
- rect.set_height(line_height);
+ rect += Vector2d(0, (text_bounds.height() - text_height) / 2);
+ rect.set_height(text_height);
render_text->SetDisplayRect(rect);
if (range.IsValid())
render_text->ApplyStyle(UNDERLINE, true, range);
« no previous file with comments | « ui/gfx/canvas_mac.mm ('k') | ui/gfx/canvas_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698