diff options
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/render_text.cc | 2 | ||||
-rw-r--r-- | ui/gfx/render_text.h | 1 | ||||
-rw-r--r-- | ui/gfx/render_text_unittest.cc | 31 |
3 files changed, 33 insertions, 1 deletions
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 4695245..47ee948 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -649,7 +649,7 @@ Point RenderText::GetOriginForSkiaDrawing() { Point origin(ToViewPoint(Point())); // TODO(msw): Establish a vertical baseline for strings of mixed font heights. const Font& font = GetFont(); - size_t height = font.GetHeight(); + int height = font.GetHeight(); // Center the text vertically in the display area. origin.Offset(0, (display_rect().height() - height) / 2); // Offset by the font size to account for Skia expecting y to be the bottom. diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h index 217f846..5b9c15a 100644 --- a/ui/gfx/render_text.h +++ b/ui/gfx/render_text.h @@ -298,6 +298,7 @@ class UI_EXPORT RenderText { FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SelectionModels); + FRIEND_TEST_ALL_PREFIXES(RenderTextTest, OriginForSkiaDrawing); // Return an index belonging to the |next| or previous logical grapheme. // If |next| is false and |IsCursorablePosition(index)| is true, the result diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc index 40f872b..bc35d6a 100644 --- a/ui/gfx/render_text_unittest.cc +++ b/ui/gfx/render_text_unittest.cc @@ -883,4 +883,35 @@ TEST_F(RenderTextTest, StringWidthTest) { #endif +TEST_F(RenderTextTest, OriginForSkiaDrawing) { + scoped_ptr<RenderText> render_text(RenderText::CreateRenderText()); + render_text->SetText(ASCIIToUTF16("abcdefg")); + render_text->SetFontList(FontList("Arial, 13px")); + + // Set display area's height equals to font height. + int font_height = render_text->GetFont().GetHeight(); + Rect display_rect(0, 0, 100, font_height); + render_text->SetDisplayRect(display_rect); + + Point origin = render_text->GetOriginForSkiaDrawing(); + EXPECT_EQ(origin.x(), 0); + EXPECT_EQ(origin.y(), 13); + + // Set display area's height greater than font height. + display_rect = Rect(0, 0, 100, font_height + 2); + render_text->SetDisplayRect(display_rect); + + origin = render_text->GetOriginForSkiaDrawing(); + EXPECT_EQ(origin.x(), 0); + EXPECT_EQ(origin.y(), 14); + + // Set display area's height less than font height. + display_rect = Rect(0, 0, 100, font_height - 2); + render_text->SetDisplayRect(display_rect); + + origin = render_text->GetOriginForSkiaDrawing(); + EXPECT_EQ(origin.x(), 0); + EXPECT_EQ(origin.y(), 12); +} + } // namespace gfx |