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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/render_text_harfbuzz.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/label.h" 5 #include "ui/views/controls/label.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 label()->OnPaint(&canvas); 222 label()->OnPaint(&canvas);
223 } 223 }
224 224
225 gfx::Point GetCursorPoint(int index) { 225 gfx::Point GetCursorPoint(int index) {
226 SimulatePaint(); 226 SimulatePaint();
227 gfx::RenderText* render_text = 227 gfx::RenderText* render_text =
228 label()->GetRenderTextForSelectionController(); 228 label()->GetRenderTextForSelectionController();
229 const std::vector<gfx::Rect> bounds = 229 const std::vector<gfx::Rect> bounds =
230 render_text->GetSubstringBoundsForTesting(gfx::Range(index, index + 1)); 230 render_text->GetSubstringBoundsForTesting(gfx::Range(index, index + 1));
231 DCHECK_EQ(1u, bounds.size()); 231 DCHECK_EQ(1u, bounds.size());
232 const int mid_y = bounds[0].y() + bounds[0].height() / 2;
232 233
234 // For single-line text, use the glyph bounds since it's a better
235 // representation of the midpoint between glyphs when considering selection.
236 // TODO(tapted): When GetGlyphBounds() supports returning a vertical range
237 // as well as a horizontal range, just use that here.
238 if (!render_text->multiline())
239 return gfx::Point(render_text->GetGlyphBounds(index).start(), mid_y);
240
241 // Otherwise, GetGlyphBounds() will give incorrect results. Multiline
242 // editing is not supported (http://crbug.com/248597) so there hasn't been
243 // a need to draw a cursor. Instead, derive a point from the selection
244 // bounds, which always rounds up to an integer after the end of a glyph.
245 // This rounding differs to the glyph bounds, which rounds to nearest
246 // integer. See http://crbug.com/735346.
233 const bool rtl = 247 const bool rtl =
234 render_text->GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT; 248 render_text->GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT;
235 // Return Point corresponding to the leading edge of the character. 249 // Return Point corresponding to the leading edge of the character.
236 return gfx::Point(rtl ? bounds[0].right() - 1 : bounds[0].x() + 1, 250 return gfx::Point(rtl ? bounds[0].right() - 1 : bounds[0].x() + 1, mid_y);
237 bounds[0].y() + bounds[0].height() / 2);
238 } 251 }
239 252
240 size_t GetLineCount() { 253 size_t GetLineCount() {
241 SimulatePaint(); 254 SimulatePaint();
242 return label()->GetRenderTextForSelectionController()->GetNumLines(); 255 return label()->GetRenderTextForSelectionController()->GetNumLines();
243 } 256 }
244 257
245 base::string16 GetSelectedText() { return label()->GetSelectedText(); } 258 base::string16 GetSelectedText() { return label()->GetSelectedText(); }
246 259
247 ui::test::EventGenerator* event_generator() { return event_generator_.get(); } 260 ui::test::EventGenerator* event_generator() { return event_generator_.get(); }
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 EXPECT_FALSE(IsMenuCommandEnabled(IDS_APP_SELECT_ALL)); 1321 EXPECT_FALSE(IsMenuCommandEnabled(IDS_APP_SELECT_ALL));
1309 } 1322 }
1310 1323
1311 INSTANTIATE_TEST_CASE_P(, 1324 INSTANTIATE_TEST_CASE_P(,
1312 MDLabelTest, 1325 MDLabelTest,
1313 ::testing::Values(SecondaryUiMode::MD, 1326 ::testing::Values(SecondaryUiMode::MD,
1314 SecondaryUiMode::NON_MD), 1327 SecondaryUiMode::NON_MD),
1315 &SecondaryUiModeToString); 1328 &SecondaryUiModeToString);
1316 1329
1317 } // namespace views 1330 } // namespace views
OLDNEW
« 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