| OLD | NEW |
| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 gfx::Size extra(22, 8); | 297 gfx::Size extra(22, 8); |
| 298 label.SetBounds(0, | 298 label.SetBounds(0, |
| 299 0, | 299 0, |
| 300 required_size.width() + extra.width(), | 300 required_size.width() + extra.width(), |
| 301 required_size.height() + extra.height()); | 301 required_size.height() + extra.height()); |
| 302 | 302 |
| 303 string16 paint_text; | 303 string16 paint_text; |
| 304 gfx::Rect text_bounds; | 304 gfx::Rect text_bounds; |
| 305 int flags; | 305 int flags; |
| 306 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 306 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 307 EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY | | 307 EXPECT_EQ(gfx::Canvas::FORCE_RTL_DIRECTIONALITY, |
| 308 gfx::Canvas::TEXT_ALIGN_CENTER, flags); | 308 flags & (gfx::Canvas::FORCE_RTL_DIRECTIONALITY | |
| 309 gfx::Canvas::FORCE_LTR_DIRECTIONALITY)); |
| 309 | 310 |
| 310 // Test text starts with LTR character. | 311 // Test text starts with LTR character. |
| 311 test_text = (WideToUTF16(L"ltr \x5d0\x5d1\x5d2 abc")); | 312 test_text = (WideToUTF16(L"ltr \x5d0\x5d1\x5d2 abc")); |
| 312 label.SetText(test_text); | 313 label.SetText(test_text); |
| 313 required_size = label.GetPreferredSize(); | 314 required_size = label.GetPreferredSize(); |
| 314 label.SetBounds(0, | 315 label.SetBounds(0, |
| 315 0, | 316 0, |
| 316 required_size.width() + extra.width(), | 317 required_size.width() + extra.width(), |
| 317 required_size.height() + extra.height()); | 318 required_size.height() + extra.height()); |
| 318 | 319 |
| 319 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 320 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 320 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY | | 321 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY, |
| 321 gfx::Canvas::TEXT_ALIGN_CENTER, flags); | 322 flags & (gfx::Canvas::FORCE_RTL_DIRECTIONALITY | |
| 323 gfx::Canvas::FORCE_LTR_DIRECTIONALITY)); |
| 322 } | 324 } |
| 323 | 325 |
| 324 TEST(LabelTest, DrawSingleLineString) { | 326 TEST(LabelTest, DrawSingleLineString) { |
| 325 Label label; | 327 Label label; |
| 326 label.set_focusable(false); | 328 label.set_focusable(false); |
| 327 | 329 |
| 328 // Turn off mirroring so that we don't need to figure out if | 330 // Turn off mirroring so that we don't need to figure out if |
| 329 // align right really means align left. | 331 // align right really means align left. |
| 330 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); | 332 label.set_directionality_mode(Label::AUTO_DETECT_DIRECTIONALITY); |
| 331 | 333 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 344 int flags; | 346 int flags; |
| 345 | 347 |
| 346 // Centered text. | 348 // Centered text. |
| 347 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 349 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 348 EXPECT_EQ(test_text, paint_text); | 350 EXPECT_EQ(test_text, paint_text); |
| 349 // The text should be centered horizontally and vertically. | 351 // The text should be centered horizontally and vertically. |
| 350 EXPECT_EQ(extra.width() / 2, text_bounds.x()); | 352 EXPECT_EQ(extra.width() / 2, text_bounds.x()); |
| 351 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); | 353 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); |
| 352 EXPECT_EQ(required_size.width(), text_bounds.width()); | 354 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 353 EXPECT_EQ(required_size.height(), text_bounds.height()); | 355 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 354 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY | | 356 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_CENTER, |
| 355 gfx::Canvas::TEXT_ALIGN_CENTER, flags); | 357 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 358 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 359 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 356 | 360 |
| 357 // Left aligned text. | 361 // Left aligned text. |
| 358 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 362 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 359 paint_text.clear(); | 363 paint_text.clear(); |
| 360 text_bounds.SetRect(0, 0, 0, 0); | 364 text_bounds.SetRect(0, 0, 0, 0); |
| 361 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 365 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 362 EXPECT_EQ(test_text, paint_text); | 366 EXPECT_EQ(test_text, paint_text); |
| 363 // The text should be left aligned horizontally and centered vertically. | 367 // The text should be left aligned horizontally and centered vertically. |
| 364 EXPECT_EQ(0, text_bounds.x()); | 368 EXPECT_EQ(0, text_bounds.x()); |
| 365 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); | 369 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); |
| 366 EXPECT_EQ(required_size.width(), text_bounds.width()); | 370 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 367 EXPECT_EQ(required_size.height(), text_bounds.height()); | 371 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 368 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY | | 372 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_LEFT, |
| 369 gfx::Canvas::TEXT_ALIGN_LEFT, flags); | 373 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 374 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 375 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 370 | 376 |
| 371 // Right aligned text. | 377 // Right aligned text. |
| 372 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 378 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 373 paint_text.clear(); | 379 paint_text.clear(); |
| 374 text_bounds.SetRect(0, 0, 0, 0); | 380 text_bounds.SetRect(0, 0, 0, 0); |
| 375 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 381 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 376 EXPECT_EQ(test_text, paint_text); | 382 EXPECT_EQ(test_text, paint_text); |
| 377 // The text should be right aligned horizontally and centered vertically. | 383 // The text should be right aligned horizontally and centered vertically. |
| 378 EXPECT_EQ(extra.width(), text_bounds.x()); | 384 EXPECT_EQ(extra.width(), text_bounds.x()); |
| 379 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); | 385 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); |
| 380 EXPECT_EQ(required_size.width(), text_bounds.width()); | 386 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 381 EXPECT_EQ(required_size.height(), text_bounds.height()); | 387 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 382 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY | | 388 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, |
| 383 gfx::Canvas::TEXT_ALIGN_RIGHT, flags); | 389 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 390 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 391 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 384 | 392 |
| 385 // Test single line drawing with a border. | 393 // Test single line drawing with a border. |
| 386 gfx::Insets border(39, 34, 8, 96); | 394 gfx::Insets border(39, 34, 8, 96); |
| 387 label.set_border(Border::CreateEmptyBorder(border.top(), | 395 label.set_border(Border::CreateEmptyBorder(border.top(), |
| 388 border.left(), | 396 border.left(), |
| 389 border.bottom(), | 397 border.bottom(), |
| 390 border.right())); | 398 border.right())); |
| 391 | 399 |
| 392 gfx::Size required_size_with_border(label.GetPreferredSize()); | 400 gfx::Size required_size_with_border(label.GetPreferredSize()); |
| 393 EXPECT_EQ(required_size.width() + border.width(), | 401 EXPECT_EQ(required_size.width() + border.width(), |
| 394 required_size_with_border.width()); | 402 required_size_with_border.width()); |
| 395 EXPECT_EQ(required_size.height() + border.height(), | 403 EXPECT_EQ(required_size.height() + border.height(), |
| 396 required_size_with_border.height()); | 404 required_size_with_border.height()); |
| 397 label.SetBounds(0, | 405 label.SetBounds(0, |
| 398 0, | 406 0, |
| 399 required_size_with_border.width() + extra.width(), | 407 required_size_with_border.width() + extra.width(), |
| 400 required_size_with_border.height() + extra.height()); | 408 required_size_with_border.height() + extra.height()); |
| 401 | 409 |
| 402 // Centered text with border. | 410 // Centered text with border. |
| 403 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); | 411 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 404 paint_text.clear(); | 412 paint_text.clear(); |
| 405 text_bounds.SetRect(0, 0, 0, 0); | 413 text_bounds.SetRect(0, 0, 0, 0); |
| 406 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 414 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 407 EXPECT_EQ(test_text, paint_text); | 415 EXPECT_EQ(test_text, paint_text); |
| 408 // The text should be centered horizontally and vertically within the border. | 416 // The text should be centered horizontally and vertically within the border. |
| 409 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); | 417 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); |
| 410 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); | 418 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); |
| 411 EXPECT_EQ(required_size.width(), text_bounds.width()); | 419 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 412 EXPECT_EQ(required_size.height(), text_bounds.height()); | 420 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 413 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY | | 421 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_CENTER, |
| 414 gfx::Canvas::TEXT_ALIGN_CENTER, flags); | 422 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 423 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 424 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 415 | 425 |
| 416 // Left aligned text with border. | 426 // Left aligned text with border. |
| 417 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 427 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 418 paint_text.clear(); | 428 paint_text.clear(); |
| 419 text_bounds.SetRect(0, 0, 0, 0); | 429 text_bounds.SetRect(0, 0, 0, 0); |
| 420 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 430 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 421 EXPECT_EQ(test_text, paint_text); | 431 EXPECT_EQ(test_text, paint_text); |
| 422 // The text should be left aligned horizontally and centered vertically. | 432 // The text should be left aligned horizontally and centered vertically. |
| 423 EXPECT_EQ(border.left(), text_bounds.x()); | 433 EXPECT_EQ(border.left(), text_bounds.x()); |
| 424 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); | 434 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); |
| 425 EXPECT_EQ(required_size.width(), text_bounds.width()); | 435 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 426 EXPECT_EQ(required_size.height(), text_bounds.height()); | 436 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 427 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY | | 437 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_LEFT, |
| 428 gfx::Canvas::TEXT_ALIGN_LEFT, flags); | 438 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 439 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 440 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 429 | 441 |
| 430 // Right aligned text. | 442 // Right aligned text. |
| 431 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 443 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 432 paint_text.clear(); | 444 paint_text.clear(); |
| 433 text_bounds.SetRect(0, 0, 0, 0); | 445 text_bounds.SetRect(0, 0, 0, 0); |
| 434 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 446 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 435 EXPECT_EQ(test_text, paint_text); | 447 EXPECT_EQ(test_text, paint_text); |
| 436 // The text should be right aligned horizontally and centered vertically. | 448 // The text should be right aligned horizontally and centered vertically. |
| 437 EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); | 449 EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); |
| 438 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); | 450 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); |
| 439 EXPECT_EQ(required_size.width(), text_bounds.width()); | 451 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 440 EXPECT_EQ(required_size.height(), text_bounds.height()); | 452 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 441 EXPECT_EQ(gfx::Canvas::FORCE_LTR_DIRECTIONALITY | | 453 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, |
| 442 gfx::Canvas::TEXT_ALIGN_RIGHT, flags); | 454 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 455 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 456 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 443 } | 457 } |
| 444 | 458 |
| 445 // On Linux the underlying pango routines require a max height in order to | 459 // On Linux the underlying pango routines require a max height in order to |
| 446 // ellide multiline text. So until that can be resolved, we set all | 460 // ellide multiline text. So until that can be resolved, we set all |
| 447 // multiline lables to not ellide in Linux only. | 461 // multiline lables to not ellide in Linux only. |
| 448 TEST(LabelTest, DrawMultiLineString) { | 462 TEST(LabelTest, DrawMultiLineString) { |
| 449 Label label; | 463 Label label; |
| 450 label.set_focusable(false); | 464 label.set_focusable(false); |
| 451 | 465 |
| 452 // Turn off mirroring so that we don't need to figure out if | 466 // Turn off mirroring so that we don't need to figure out if |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 int flags; | 622 int flags; |
| 609 | 623 |
| 610 // Centered text. | 624 // Centered text. |
| 611 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 625 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 612 EXPECT_EQ(test_text, paint_text); | 626 EXPECT_EQ(test_text, paint_text); |
| 613 // The text should be centered horizontally and vertically. | 627 // The text should be centered horizontally and vertically. |
| 614 EXPECT_EQ(extra.width() / 2, text_bounds.x()); | 628 EXPECT_EQ(extra.width() / 2, text_bounds.x()); |
| 615 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); | 629 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); |
| 616 EXPECT_EQ(required_size.width(), text_bounds.width()); | 630 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 617 EXPECT_EQ(required_size.height(), text_bounds.height()); | 631 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 618 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_CENTER, flags); | 632 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_CENTER, |
| 633 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 634 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 635 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 619 | 636 |
| 620 // ALIGN_LEFT label. | 637 // ALIGN_LEFT label. |
| 621 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 638 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 622 paint_text.clear(); | 639 paint_text.clear(); |
| 623 text_bounds.SetRect(0, 0, 0, 0); | 640 text_bounds.SetRect(0, 0, 0, 0); |
| 624 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 641 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 625 EXPECT_EQ(test_text, paint_text); | 642 EXPECT_EQ(test_text, paint_text); |
| 626 // The text should be right aligned horizontally and centered vertically. | 643 // The text should be right aligned horizontally and centered vertically. |
| 627 EXPECT_EQ(extra.width(), text_bounds.x()); | 644 EXPECT_EQ(extra.width(), text_bounds.x()); |
| 628 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); | 645 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); |
| 629 EXPECT_EQ(required_size.width(), text_bounds.width()); | 646 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 630 EXPECT_EQ(required_size.height(), text_bounds.height()); | 647 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 631 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, flags); | 648 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, |
| 649 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 650 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 651 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 632 | 652 |
| 633 // ALIGN_RIGHT label. | 653 // ALIGN_RIGHT label. |
| 634 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 654 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 635 paint_text.clear(); | 655 paint_text.clear(); |
| 636 text_bounds.SetRect(0, 0, 0, 0); | 656 text_bounds.SetRect(0, 0, 0, 0); |
| 637 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 657 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 638 EXPECT_EQ(test_text, paint_text); | 658 EXPECT_EQ(test_text, paint_text); |
| 639 // The text should be left aligned horizontally and centered vertically. | 659 // The text should be left aligned horizontally and centered vertically. |
| 640 EXPECT_EQ(0, text_bounds.x()); | 660 EXPECT_EQ(0, text_bounds.x()); |
| 641 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); | 661 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); |
| 642 EXPECT_EQ(required_size.width(), text_bounds.width()); | 662 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 643 EXPECT_EQ(required_size.height(), text_bounds.height()); | 663 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 644 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_LEFT, flags); | 664 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_LEFT, |
| 665 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 666 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 667 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 645 | 668 |
| 646 | 669 |
| 647 // Test single line drawing with a border. | 670 // Test single line drawing with a border. |
| 648 gfx::Insets border(39, 34, 8, 96); | 671 gfx::Insets border(39, 34, 8, 96); |
| 649 label.set_border(Border::CreateEmptyBorder(border.top(), | 672 label.set_border(Border::CreateEmptyBorder(border.top(), |
| 650 border.left(), | 673 border.left(), |
| 651 border.bottom(), | 674 border.bottom(), |
| 652 border.right())); | 675 border.right())); |
| 653 | 676 |
| 654 gfx::Size required_size_with_border(label.GetPreferredSize()); | 677 gfx::Size required_size_with_border(label.GetPreferredSize()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 665 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); | 688 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 666 paint_text.clear(); | 689 paint_text.clear(); |
| 667 text_bounds.SetRect(0, 0, 0, 0); | 690 text_bounds.SetRect(0, 0, 0, 0); |
| 668 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 691 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 669 EXPECT_EQ(test_text, paint_text); | 692 EXPECT_EQ(test_text, paint_text); |
| 670 // The text should be centered horizontally and vertically within the border. | 693 // The text should be centered horizontally and vertically within the border. |
| 671 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); | 694 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); |
| 672 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); | 695 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); |
| 673 EXPECT_EQ(required_size.width(), text_bounds.width()); | 696 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 674 EXPECT_EQ(required_size.height(), text_bounds.height()); | 697 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 675 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_CENTER, flags); | 698 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_CENTER, |
| 699 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 700 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 701 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 676 | 702 |
| 677 // ALIGN_LEFT text with border. | 703 // ALIGN_LEFT text with border. |
| 678 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 704 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 679 paint_text.clear(); | 705 paint_text.clear(); |
| 680 text_bounds.SetRect(0, 0, 0, 0); | 706 text_bounds.SetRect(0, 0, 0, 0); |
| 681 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 707 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 682 EXPECT_EQ(test_text, paint_text); | 708 EXPECT_EQ(test_text, paint_text); |
| 683 // The text should be right aligned horizontally and centered vertically. | 709 // The text should be right aligned horizontally and centered vertically. |
| 684 EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); | 710 EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); |
| 685 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); | 711 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); |
| 686 EXPECT_EQ(required_size.width(), text_bounds.width()); | 712 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 687 EXPECT_EQ(required_size.height(), text_bounds.height()); | 713 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 688 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, flags); | 714 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, |
| 715 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 716 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 717 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 689 | 718 |
| 690 // ALIGN_RIGHT text. | 719 // ALIGN_RIGHT text. |
| 691 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 720 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 692 paint_text.clear(); | 721 paint_text.clear(); |
| 693 text_bounds.SetRect(0, 0, 0, 0); | 722 text_bounds.SetRect(0, 0, 0, 0); |
| 694 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 723 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 695 EXPECT_EQ(test_text, paint_text); | 724 EXPECT_EQ(test_text, paint_text); |
| 696 // The text should be left aligned horizontally and centered vertically. | 725 // The text should be left aligned horizontally and centered vertically. |
| 697 EXPECT_EQ(border.left(), text_bounds.x()); | 726 EXPECT_EQ(border.left(), text_bounds.x()); |
| 698 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); | 727 EXPECT_EQ(border.top() + extra.height() / 2 , text_bounds.y()); |
| 699 EXPECT_EQ(required_size.width(), text_bounds.width()); | 728 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 700 EXPECT_EQ(required_size.height(), text_bounds.height()); | 729 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 701 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_LEFT, flags); | 730 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_LEFT, |
| 731 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 732 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 733 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 702 | 734 |
| 703 // Reset locale. | 735 // Reset locale. |
| 704 base::i18n::SetICUDefaultLocale(locale); | 736 base::i18n::SetICUDefaultLocale(locale); |
| 705 } | 737 } |
| 706 | 738 |
| 707 // On Linux the underlying pango routines require a max height in order to | 739 // On Linux the underlying pango routines require a max height in order to |
| 708 // ellide multiline text. So until that can be resolved, we set all | 740 // ellide multiline text. So until that can be resolved, we set all |
| 709 // multiline lables to not ellide in Linux only. | 741 // multiline lables to not ellide in Linux only. |
| 710 TEST(LabelTest, DrawMultiLineStringInRTL) { | 742 TEST(LabelTest, DrawMultiLineStringInRTL) { |
| 711 Label label; | 743 Label label; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); | 926 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); |
| 895 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); | 927 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); |
| 896 | 928 |
| 897 // GetTooltipHandlerForPoint works should work in child bounds. | 929 // GetTooltipHandlerForPoint works should work in child bounds. |
| 898 label.SetBounds(2, 2, 10, 10); | 930 label.SetBounds(2, 2, 10, 10); |
| 899 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); | 931 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); |
| 900 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); | 932 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); |
| 901 } | 933 } |
| 902 | 934 |
| 903 } // namespace views | 935 } // namespace views |
| OLD | NEW |