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

Side by Side Diff: ui/views/controls/label_unittest.cc

Issue 10695101: Remove code that forces text directionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and merge. Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/controls/label.cc ('k') | ui/views/controls/message_box_view.cc » ('j') | 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 "base/i18n/rtl.h" 5 #include "base/i18n/rtl.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/base/accessibility/accessible_view_state.h" 8 #include "ui/base/accessibility/accessible_view_state.h"
9 #include "ui/base/l10n/l10n_util.h" 9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 TEST(LabelTest, ColorProperty) { 58 TEST(LabelTest, ColorProperty) {
59 Label label; 59 Label label;
60 SkColor color = SkColorSetARGB(20, 40, 10, 5); 60 SkColor color = SkColorSetARGB(20, 40, 10, 5);
61 label.SetAutoColorReadabilityEnabled(false); 61 label.SetAutoColorReadabilityEnabled(false);
62 label.SetEnabledColor(color); 62 label.SetEnabledColor(color);
63 EXPECT_EQ(color, label.enabled_color()); 63 EXPECT_EQ(color, label.enabled_color());
64 } 64 }
65 65
66 TEST(LabelTest, AlignmentProperty) { 66 TEST(LabelTest, AlignmentProperty) {
67 Label label; 67 // The label's alignment should be flipped for RTL text.
68 bool reverse_alignment = base::i18n::IsRTL(); 68 Label label(WideToUTF16(L"\x05d0\x05d1\x05d2"));
69
70 label.SetHorizontalAlignment(Label::ALIGN_RIGHT); 69 label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
71 EXPECT_EQ( 70 EXPECT_EQ(Label::ALIGN_LEFT, label.horizontal_alignment());
72 reverse_alignment ? Label::ALIGN_LEFT : Label::ALIGN_RIGHT,
73 label.horizontal_alignment());
74 label.SetHorizontalAlignment(Label::ALIGN_LEFT); 71 label.SetHorizontalAlignment(Label::ALIGN_LEFT);
75 EXPECT_EQ( 72 EXPECT_EQ(Label::ALIGN_RIGHT, label.horizontal_alignment());
76 reverse_alignment ? Label::ALIGN_RIGHT : Label::ALIGN_LEFT,
77 label.horizontal_alignment());
78 label.SetHorizontalAlignment(Label::ALIGN_CENTER); 73 label.SetHorizontalAlignment(Label::ALIGN_CENTER);
79 EXPECT_EQ(Label::ALIGN_CENTER, label.horizontal_alignment()); 74 EXPECT_EQ(Label::ALIGN_CENTER, label.horizontal_alignment());
80 75
81 // The label's alignment should not be flipped if the directionality mode is 76 // The label's alignment should not be flipped for LTR text.
82 // AUTO_DETECT_DIRECTIONALITY. 77 label.SetText("abc");
83 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY);
84 label.SetHorizontalAlignment(Label::ALIGN_RIGHT); 78 label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
85 EXPECT_EQ(Label::ALIGN_RIGHT, label.horizontal_alignment()); 79 EXPECT_EQ(Label::ALIGN_RIGHT, label.horizontal_alignment());
86 label.SetHorizontalAlignment(Label::ALIGN_LEFT); 80 label.SetHorizontalAlignment(Label::ALIGN_LEFT);
87 EXPECT_EQ(Label::ALIGN_LEFT, label.horizontal_alignment()); 81 EXPECT_EQ(Label::ALIGN_LEFT, label.horizontal_alignment());
88 label.SetHorizontalAlignment(Label::ALIGN_CENTER); 82 label.SetHorizontalAlignment(Label::ALIGN_CENTER);
89 EXPECT_EQ(Label::ALIGN_CENTER, label.horizontal_alignment()); 83 EXPECT_EQ(Label::ALIGN_CENTER, label.horizontal_alignment());
90 } 84 }
91 85
92 TEST(LabelTest, DirectionalityModeProperty) {
93 Label label;
94 EXPECT_EQ(Label::USE_UI_DIRECTIONALITY, label.directionality_mode());
95
96 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY);
97 EXPECT_EQ(Label::AUTO_DETECT_DIRECTIONALITY, label.directionality_mode());
98
99 label.set_directionality_mode(Label::USE_UI_DIRECTIONALITY);
100 EXPECT_EQ(Label::USE_UI_DIRECTIONALITY, label.directionality_mode());
101 }
102
103 TEST(LabelTest, MultiLineProperty) { 86 TEST(LabelTest, MultiLineProperty) {
104 Label label; 87 Label label;
105 EXPECT_FALSE(label.is_multi_line()); 88 EXPECT_FALSE(label.is_multi_line());
106 label.SetMultiLine(true); 89 label.SetMultiLine(true);
107 EXPECT_TRUE(label.is_multi_line()); 90 EXPECT_TRUE(label.is_multi_line());
108 label.SetMultiLine(false); 91 label.SetMultiLine(false);
109 EXPECT_FALSE(label.is_multi_line()); 92 EXPECT_FALSE(label.is_multi_line());
110 } 93 }
111 94
112 TEST(LabelTest, TooltipProperty) { 95 TEST(LabelTest, TooltipProperty) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 254
272 // GetPreferredSize and borders. 255 // GetPreferredSize and borders.
273 label.SetBounds(0, 0, 0, 0); 256 label.SetBounds(0, 0, 0, 0);
274 gfx::Size required_size_with_border = label.GetPreferredSize(); 257 gfx::Size required_size_with_border = label.GetPreferredSize();
275 EXPECT_EQ(required_size_with_border.height(), 258 EXPECT_EQ(required_size_with_border.height(),
276 required_size.height() + border.height()); 259 required_size.height() + border.height());
277 EXPECT_EQ(required_size_with_border.width(), 260 EXPECT_EQ(required_size_with_border.width(),
278 required_size.width() + border.width()); 261 required_size.width() + border.width());
279 } 262 }
280 263
281 TEST(LabelTest, AutoDetectDirectionality) {
282 Label label;
283 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY);
284
285 // Test text starts with RTL character.
286 string16 test_text(WideToUTF16(L" \x5d0\x5d1\x5d2 abc"));
287 label.SetText(test_text);
288 gfx::Size required_size(label.GetPreferredSize());
289 gfx::Size extra(22, 8);
290 label.SetBounds(0,
291 0,
292 required_size.width() + extra.width(),
293 required_size.height() + extra.height());
294
295 string16 paint_text;
296 gfx::Rect text_bounds;
297 int flags;
298 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
299 EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, flags);
300
301 // Test text starts with LTR character.
302 test_text = (WideToUTF16(L"ltr \x5d0\x5d1\x5d2 abc"));
303 label.SetText(test_text);
304 required_size = label.GetPreferredSize();
305 label.SetBounds(0,
306 0,
307 required_size.width() + extra.width(),
308 required_size.height() + extra.height());
309
310 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
311 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags);
312 }
313
314 TEST(LabelTest, DrawSingleLineString) { 264 TEST(LabelTest, DrawSingleLineString) {
315 Label label; 265 Label label;
316 label.set_focusable(false); 266 label.set_focusable(false);
317 267
318 // Turn off mirroring so that we don't need to figure out if 268 // Turn off mirroring so that we don't need to figure out if
319 // align right really means align left. 269 // align right really means align left.
320 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); 270 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY);
321 271
322 string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); 272 string16 test_text(ASCIIToUTF16("Here's a string with no returns."));
323 label.SetText(test_text); 273 label.SetText(test_text);
(...skipping 10 matching lines...) Expand all
334 int flags; 284 int flags;
335 285
336 // Centered text. 286 // Centered text.
337 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 287 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
338 EXPECT_EQ(test_text, paint_text); 288 EXPECT_EQ(test_text, paint_text);
339 // The text should be centered horizontally and vertically. 289 // The text should be centered horizontally and vertically.
340 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 290 EXPECT_EQ(extra.width() / 2, text_bounds.x());
341 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); 291 EXPECT_EQ(extra.height() / 2 , text_bounds.y());
342 EXPECT_EQ(required_size.width(), text_bounds.width()); 292 EXPECT_EQ(required_size.width(), text_bounds.width());
343 EXPECT_EQ(required_size.height(), text_bounds.height()); 293 EXPECT_EQ(required_size.height(), text_bounds.height());
344 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); 294 EXPECT_EQ(0, flags);
345 295
346 // Left aligned text. 296 // Left aligned text.
347 label.SetHorizontalAlignment(Label::ALIGN_LEFT); 297 label.SetHorizontalAlignment(Label::ALIGN_LEFT);
348 paint_text.clear(); 298 paint_text.clear();
349 text_bounds.SetRect(0, 0, 0, 0); 299 text_bounds.SetRect(0, 0, 0, 0);
350 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 300 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
351 EXPECT_EQ(test_text, paint_text); 301 EXPECT_EQ(test_text, paint_text);
352 // The text should be left aligned horizontally and centered vertically. 302 // The text should be left aligned horizontally and centered vertically.
353 EXPECT_EQ(0, text_bounds.x()); 303 EXPECT_EQ(0, text_bounds.x());
354 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); 304 EXPECT_EQ(extra.height() / 2 , text_bounds.y());
355 EXPECT_EQ(required_size.width(), text_bounds.width()); 305 EXPECT_EQ(required_size.width(), text_bounds.width());
356 EXPECT_EQ(required_size.height(), text_bounds.height()); 306 EXPECT_EQ(required_size.height(), text_bounds.height());
357 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); 307 EXPECT_EQ(0, flags);
358 308
359 // Right aligned text. 309 // Right aligned text.
360 label.SetHorizontalAlignment(Label::ALIGN_RIGHT); 310 label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
361 paint_text.clear(); 311 paint_text.clear();
362 text_bounds.SetRect(0, 0, 0, 0); 312 text_bounds.SetRect(0, 0, 0, 0);
363 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 313 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
364 EXPECT_EQ(test_text, paint_text); 314 EXPECT_EQ(test_text, paint_text);
365 // The text should be right aligned horizontally and centered vertically. 315 // The text should be right aligned horizontally and centered vertically.
366 EXPECT_EQ(extra.width(), text_bounds.x()); 316 EXPECT_EQ(extra.width(), text_bounds.x());
367 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); 317 EXPECT_EQ(extra.height() / 2 , text_bounds.y());
368 EXPECT_EQ(required_size.width(), text_bounds.width()); 318 EXPECT_EQ(required_size.width(), text_bounds.width());
369 EXPECT_EQ(required_size.height(), text_bounds.height()); 319 EXPECT_EQ(required_size.height(), text_bounds.height());
370 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); 320 EXPECT_EQ(0, flags);
371 321
372 // Test single line drawing with a border. 322 // Test single line drawing with a border.
373 gfx::Insets border(39, 34, 8, 96); 323 gfx::Insets border(39, 34, 8, 96);
374 label.set_border(Border::CreateEmptyBorder(border.top(), 324 label.set_border(Border::CreateEmptyBorder(border.top(),
375 border.left(), 325 border.left(),
376 border.bottom(), 326 border.bottom(),
377 border.right())); 327 border.right()));
378 328
379 gfx::Size required_size_with_border(label.GetPreferredSize()); 329 gfx::Size required_size_with_border(label.GetPreferredSize());
380 EXPECT_EQ(required_size.width() + border.width(), 330 EXPECT_EQ(required_size.width() + border.width(),
381 required_size_with_border.width()); 331 required_size_with_border.width());
382 EXPECT_EQ(required_size.height() + border.height(), 332 EXPECT_EQ(required_size.height() + border.height(),
383 required_size_with_border.height()); 333 required_size_with_border.height());
384 label.SetBounds(0, 334 label.SetBounds(0,
385 0, 335 0,
386 required_size_with_border.width() + extra.width(), 336 required_size_with_border.width() + extra.width(),
387 required_size_with_border.height() + extra.height()); 337 required_size_with_border.height() + extra.height());
388 338
389 // Centered text with border. 339 // Centered text with border.
390 label.SetHorizontalAlignment(Label::ALIGN_CENTER); 340 label.SetHorizontalAlignment(Label::ALIGN_CENTER);
391 paint_text.clear(); 341 paint_text.clear();
392 text_bounds.SetRect(0, 0, 0, 0); 342 text_bounds.SetRect(0, 0, 0, 0);
393 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 343 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
394 EXPECT_EQ(test_text, paint_text); 344 EXPECT_EQ(test_text, paint_text);
395 // The text should be centered horizontally and vertically within the border. 345 // The text should be centered horizontally and vertically within the border.
396 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); 346 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x());
397 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); 347 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
398 EXPECT_EQ(required_size.width(), text_bounds.width()); 348 EXPECT_EQ(required_size.width(), text_bounds.width());
399 EXPECT_EQ(required_size.height(), text_bounds.height()); 349 EXPECT_EQ(required_size.height(), text_bounds.height());
400 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); 350 EXPECT_EQ(0, flags);
401 351
402 // Left aligned text with border. 352 // Left aligned text with border.
403 label.SetHorizontalAlignment(Label::ALIGN_LEFT); 353 label.SetHorizontalAlignment(Label::ALIGN_LEFT);
404 paint_text.clear(); 354 paint_text.clear();
405 text_bounds.SetRect(0, 0, 0, 0); 355 text_bounds.SetRect(0, 0, 0, 0);
406 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 356 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
407 EXPECT_EQ(test_text, paint_text); 357 EXPECT_EQ(test_text, paint_text);
408 // The text should be left aligned horizontally and centered vertically. 358 // The text should be left aligned horizontally and centered vertically.
409 EXPECT_EQ(border.left(), text_bounds.x()); 359 EXPECT_EQ(border.left(), text_bounds.x());
410 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); 360 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
411 EXPECT_EQ(required_size.width(), text_bounds.width()); 361 EXPECT_EQ(required_size.width(), text_bounds.width());
412 EXPECT_EQ(required_size.height(), text_bounds.height()); 362 EXPECT_EQ(required_size.height(), text_bounds.height());
413 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); 363 EXPECT_EQ(0, flags);
414 364
415 // Right aligned text. 365 // Right aligned text.
416 label.SetHorizontalAlignment(Label::ALIGN_RIGHT); 366 label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
417 paint_text.clear(); 367 paint_text.clear();
418 text_bounds.SetRect(0, 0, 0, 0); 368 text_bounds.SetRect(0, 0, 0, 0);
419 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 369 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
420 EXPECT_EQ(test_text, paint_text); 370 EXPECT_EQ(test_text, paint_text);
421 // The text should be right aligned horizontally and centered vertically. 371 // The text should be right aligned horizontally and centered vertically.
422 EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); 372 EXPECT_EQ(border.left() + extra.width(), text_bounds.x());
423 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); 373 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y());
424 EXPECT_EQ(required_size.width(), text_bounds.width()); 374 EXPECT_EQ(required_size.width(), text_bounds.width());
425 EXPECT_EQ(required_size.height(), text_bounds.height()); 375 EXPECT_EQ(required_size.height(), text_bounds.height());
426 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, flags); 376 EXPECT_EQ(0, flags);
427 } 377 }
428 378
429 // On Linux the underlying pango routines require a max height in order to 379 // On Linux the underlying pango routines require a max height in order to
430 // ellide multiline text. So until that can be resolved, we set all 380 // ellide multiline text. So until that can be resolved, we set all
431 // multiline lables to not ellide in Linux only. 381 // multiline lables to not ellide in Linux only.
432 TEST(LabelTest, DrawMultiLineString) { 382 TEST(LabelTest, DrawMultiLineString) {
433 Label label; 383 Label label;
434 label.set_focusable(false); 384 label.set_focusable(false);
435 385
436 // Turn off mirroring so that we don't need to figure out if 386 // Turn off mirroring so that we don't need to figure out if
(...skipping 13 matching lines...) Expand all
450 // Do some basic verifications for all three alignments. 400 // Do some basic verifications for all three alignments.
451 string16 paint_text; 401 string16 paint_text;
452 gfx::Rect text_bounds; 402 gfx::Rect text_bounds;
453 int flags; 403 int flags;
454 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 404 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
455 EXPECT_EQ(test_text, paint_text); 405 EXPECT_EQ(test_text, paint_text);
456 EXPECT_EQ(extra.width() / 2, text_bounds.x()); 406 EXPECT_EQ(extra.width() / 2, text_bounds.x());
457 EXPECT_EQ(extra.height() / 2, text_bounds.y()); 407 EXPECT_EQ(extra.height() / 2, text_bounds.y());
458 EXPECT_GT(text_bounds.width(), kMinTextDimension); 408 EXPECT_GT(text_bounds.width(), kMinTextDimension);
459 EXPECT_GT(text_bounds.height(), kMinTextDimension); 409 EXPECT_GT(text_bounds.height(), kMinTextDimension);
460 int expected_flags = gfx::Canvas::MULTI_LINE | 410 int expected_flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER;
461 gfx::Canvas::TEXT_ALIGN_CENTER |
462 gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
463 #if defined(OS_WIN) 411 #if defined(OS_WIN)
464 EXPECT_EQ(expected_flags, flags); 412 EXPECT_EQ(expected_flags, flags);
465 #else 413 #else
466 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); 414 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags);
467 #endif 415 #endif
468 gfx::Rect center_bounds(text_bounds); 416 gfx::Rect center_bounds(text_bounds);
469 417
470 label.SetHorizontalAlignment(Label::ALIGN_LEFT); 418 label.SetHorizontalAlignment(Label::ALIGN_LEFT);
471 paint_text.clear(); 419 paint_text.clear();
472 text_bounds.SetRect(0, 0, 0, 0); 420 text_bounds.SetRect(0, 0, 0, 0);
473 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 421 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
474 EXPECT_EQ(test_text, paint_text); 422 EXPECT_EQ(test_text, paint_text);
475 EXPECT_EQ(0, text_bounds.x()); 423 EXPECT_EQ(0, text_bounds.x());
476 EXPECT_EQ(extra.height() / 2, text_bounds.y()); 424 EXPECT_EQ(extra.height() / 2, text_bounds.y());
477 EXPECT_GT(text_bounds.width(), kMinTextDimension); 425 EXPECT_GT(text_bounds.width(), kMinTextDimension);
478 EXPECT_GT(text_bounds.height(), kMinTextDimension); 426 EXPECT_GT(text_bounds.height(), kMinTextDimension);
479 expected_flags = gfx::Canvas::MULTI_LINE | 427 expected_flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT;
480 gfx::Canvas::TEXT_ALIGN_LEFT |
481 gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
482 #if defined(OS_WIN) 428 #if defined(OS_WIN)
483 EXPECT_EQ(expected_flags, flags); 429 EXPECT_EQ(expected_flags, flags);
484 #else 430 #else
485 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); 431 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags);
486 #endif 432 #endif
487 433
488 label.SetHorizontalAlignment(Label::ALIGN_RIGHT); 434 label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
489 paint_text.clear(); 435 paint_text.clear();
490 text_bounds.SetRect(0, 0, 0, 0); 436 text_bounds.SetRect(0, 0, 0, 0);
491 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 437 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
492 EXPECT_EQ(test_text, paint_text); 438 EXPECT_EQ(test_text, paint_text);
493 EXPECT_EQ(extra.width(), text_bounds.x()); 439 EXPECT_EQ(extra.width(), text_bounds.x());
494 EXPECT_EQ(extra.height() / 2, text_bounds.y()); 440 EXPECT_EQ(extra.height() / 2, text_bounds.y());
495 EXPECT_GT(text_bounds.width(), kMinTextDimension); 441 EXPECT_GT(text_bounds.width(), kMinTextDimension);
496 EXPECT_GT(text_bounds.height(), kMinTextDimension); 442 EXPECT_GT(text_bounds.height(), kMinTextDimension);
497 expected_flags = gfx::Canvas::MULTI_LINE | 443 expected_flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT;
498 gfx::Canvas::TEXT_ALIGN_RIGHT |
499 gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
500 #if defined(OS_WIN) 444 #if defined(OS_WIN)
501 EXPECT_EQ(expected_flags, flags); 445 EXPECT_EQ(expected_flags, flags);
502 #else 446 #else
503 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); 447 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags);
504 #endif 448 #endif
505 449
506 // Test multiline drawing with a border. 450 // Test multiline drawing with a border.
507 gfx::Insets border(19, 92, 23, 2); 451 gfx::Insets border(19, 92, 23, 2);
508 label.set_border(Border::CreateEmptyBorder(border.top(), 452 label.set_border(Border::CreateEmptyBorder(border.top(),
509 border.left(), 453 border.left(),
510 border.bottom(), 454 border.bottom(),
511 border.right())); 455 border.right()));
512 label.SizeToFit(0); 456 label.SizeToFit(0);
513 label.SetBounds(label.x(), 457 label.SetBounds(label.x(),
514 label.y(), 458 label.y(),
515 label.width() + extra.width(), 459 label.width() + extra.width(),
516 label.height() + extra.height()); 460 label.height() + extra.height());
517 461
518 label.SetHorizontalAlignment(Label::ALIGN_CENTER); 462 label.SetHorizontalAlignment(Label::ALIGN_CENTER);
519 paint_text.clear(); 463 paint_text.clear();
520 text_bounds.SetRect(0, 0, 0, 0); 464 text_bounds.SetRect(0, 0, 0, 0);
521 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 465 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
522 EXPECT_EQ(test_text, paint_text); 466 EXPECT_EQ(test_text, paint_text);
523 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); 467 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x());
524 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); 468 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y());
525 EXPECT_EQ(center_bounds.width(), text_bounds.width()); 469 EXPECT_EQ(center_bounds.width(), text_bounds.width());
526 EXPECT_EQ(center_bounds.height(), text_bounds.height()); 470 EXPECT_EQ(center_bounds.height(), text_bounds.height());
527 expected_flags = gfx::Canvas::MULTI_LINE | 471 expected_flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER;
528 gfx::Canvas::TEXT_ALIGN_CENTER |
529 gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
530 #if defined(OS_WIN) 472 #if defined(OS_WIN)
531 EXPECT_EQ(expected_flags, flags); 473 EXPECT_EQ(expected_flags, flags);
532 #else 474 #else
533 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); 475 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags);
534 #endif 476 #endif
535 477
536 label.SetHorizontalAlignment(Label::ALIGN_LEFT); 478 label.SetHorizontalAlignment(Label::ALIGN_LEFT);
537 paint_text.clear(); 479 paint_text.clear();
538 text_bounds.SetRect(0, 0, 0, 0); 480 text_bounds.SetRect(0, 0, 0, 0);
539 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 481 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
540 EXPECT_EQ(test_text, paint_text); 482 EXPECT_EQ(test_text, paint_text);
541 EXPECT_EQ(border.left(), text_bounds.x()); 483 EXPECT_EQ(border.left(), text_bounds.x());
542 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); 484 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y());
543 EXPECT_EQ(center_bounds.width(), text_bounds.width()); 485 EXPECT_EQ(center_bounds.width(), text_bounds.width());
544 EXPECT_EQ(center_bounds.height(), text_bounds.height()); 486 EXPECT_EQ(center_bounds.height(), text_bounds.height());
545 expected_flags = gfx::Canvas::MULTI_LINE | 487 expected_flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT;
546 gfx::Canvas::TEXT_ALIGN_LEFT |
547 gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
548 #if defined(OS_WIN) 488 #if defined(OS_WIN)
549 EXPECT_EQ(expected_flags, flags); 489 EXPECT_EQ(expected_flags, flags);
550 #else 490 #else
551 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); 491 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags);
552 #endif 492 #endif
553 493
554 label.SetHorizontalAlignment(Label::ALIGN_RIGHT); 494 label.SetHorizontalAlignment(Label::ALIGN_RIGHT);
555 paint_text.clear(); 495 paint_text.clear();
556 text_bounds.SetRect(0, 0, 0, 0); 496 text_bounds.SetRect(0, 0, 0, 0);
557 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); 497 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags);
558 EXPECT_EQ(test_text, paint_text); 498 EXPECT_EQ(test_text, paint_text);
559 EXPECT_EQ(extra.width() + border.left(), text_bounds.x()); 499 EXPECT_EQ(extra.width() + border.left(), text_bounds.x());
560 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); 500 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y());
561 EXPECT_EQ(center_bounds.width(), text_bounds.width()); 501 EXPECT_EQ(center_bounds.width(), text_bounds.width());
562 EXPECT_EQ(center_bounds.height(), text_bounds.height()); 502 EXPECT_EQ(center_bounds.height(), text_bounds.height());
563 expected_flags = gfx::Canvas::MULTI_LINE | 503 expected_flags = gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT;
564 gfx::Canvas::TEXT_ALIGN_RIGHT |
565 gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
566 #if defined(OS_WIN) 504 #if defined(OS_WIN)
567 EXPECT_EQ(expected_flags, flags); 505 EXPECT_EQ(expected_flags, flags);
568 #else 506 #else
569 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); 507 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags);
570 #endif 508 #endif
571 } 509 }
572 510
573 TEST(LabelTest, DrawSingleLineStringInRTL) { 511 TEST(LabelTest, DrawSingleLineStringInRTL) {
574 Label label; 512 Label label;
575 label.set_focusable(false); 513 label.set_focusable(false);
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 EXPECT_EQ( 787 EXPECT_EQ(
850 0, label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING); 788 0, label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING);
851 789
852 label.SetBackgroundColor(SkColorSetARGB(64, 255, 255, 255)); 790 label.SetBackgroundColor(SkColorSetARGB(64, 255, 255, 255));
853 EXPECT_EQ( 791 EXPECT_EQ(
854 gfx::Canvas::NO_SUBPIXEL_RENDERING, 792 gfx::Canvas::NO_SUBPIXEL_RENDERING,
855 label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING); 793 label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING);
856 } 794 }
857 795
858 } // namespace views 796 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/label.cc ('k') | ui/views/controls/message_box_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698