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

Unified Diff: ui/views/controls/label_unittest.cc

Issue 2927953003: Use CTFontCreateForString for RenderTextHarfbuzz on Mac (Closed)
Patch Set: Fix views::Label tests Created 3 years, 6 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/render_text_harfbuzz.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/label_unittest.cc
diff --git a/ui/views/controls/label_unittest.cc b/ui/views/controls/label_unittest.cc
index 6f6927a1d0b78f531721de1647b0ec4ba6586002..f2dc0a59b498e70655a2dcacfa42bb7ce79731fa 100644
--- a/ui/views/controls/label_unittest.cc
+++ b/ui/views/controls/label_unittest.cc
@@ -229,12 +229,25 @@ class LabelSelectionTest : public LabelTest {
const std::vector<gfx::Rect> bounds =
render_text->GetSubstringBoundsForTesting(gfx::Range(index, index + 1));
DCHECK_EQ(1u, bounds.size());
-
+ const int mid_y = bounds[0].y() + bounds[0].height() / 2;
+
+ // For single-line text, use the glyph bounds since it's a better
+ // representation of the midpoint between glyphs when considering selection.
+ // TODO(tapted): When GetGlyphBounds() supports returning a vertical range
+ // as well as a horizontal range, just use that here.
+ if (!render_text->multiline())
+ return gfx::Point(render_text->GetGlyphBounds(index).start(), mid_y);
+
+ // Otherwise, GetGlyphBounds() will give incorrect results. Multiline
+ // editing is not supported (http://crbug.com/248597) so there hasn't been
+ // a need to draw a cursor. Instead, derive a point from the selection
+ // bounds, which always rounds up to an integer after the end of a glyph.
+ // This rounding differs to the glyph bounds, which rounds to nearest
+ // integer. See http://crbug.com/735346.
const bool rtl =
render_text->GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT;
// Return Point corresponding to the leading edge of the character.
- return gfx::Point(rtl ? bounds[0].right() - 1 : bounds[0].x() + 1,
- bounds[0].y() + bounds[0].height() / 2);
+ return gfx::Point(rtl ? bounds[0].right() - 1 : bounds[0].x() + 1, mid_y);
}
size_t GetLineCount() {
« no previous file with comments | « ui/gfx/render_text_harfbuzz.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698