| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/gfx/chrome_canvas.h" | 5 #include "app/gfx/canvas.h" |
| 6 #include "app/l10n_util.h" | 6 #include "app/l10n_util.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "views/border.h" | 9 #include "views/border.h" |
| 10 #include "views/controls/label.h" | 10 #include "views/controls/label.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 | 13 |
| 14 // All text sizing measurements (width and height) should be greater than this. | 14 // All text sizing measurements (width and height) should be greater than this. |
| 15 const int kMinTextDimension = 4; | 15 const int kMinTextDimension = 4; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // Do some basic verifications for all three alignments. | 387 // Do some basic verifications for all three alignments. |
| 388 std::wstring paint_text; | 388 std::wstring paint_text; |
| 389 gfx::Rect text_bounds; | 389 gfx::Rect text_bounds; |
| 390 int flags; | 390 int flags; |
| 391 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 391 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 392 EXPECT_STREQ(test_text.c_str(), paint_text.c_str()); | 392 EXPECT_STREQ(test_text.c_str(), paint_text.c_str()); |
| 393 EXPECT_EQ(0, text_bounds.x()); | 393 EXPECT_EQ(0, text_bounds.x()); |
| 394 EXPECT_EQ(0, text_bounds.y()); | 394 EXPECT_EQ(0, text_bounds.y()); |
| 395 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 395 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 396 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 396 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 397 EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_CENTER, flags); | 397 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); |
| 398 gfx::Rect center_bounds(text_bounds); | 398 gfx::Rect center_bounds(text_bounds); |
| 399 | 399 |
| 400 label.SetHorizontalAlignment(Label::ALIGN_LEFT); | 400 label.SetHorizontalAlignment(Label::ALIGN_LEFT); |
| 401 paint_text.clear(); | 401 paint_text.clear(); |
| 402 text_bounds.SetRect(0, 0, 0, 0); | 402 text_bounds.SetRect(0, 0, 0, 0); |
| 403 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 403 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 404 EXPECT_STREQ(test_text.c_str(), paint_text.c_str()); | 404 EXPECT_STREQ(test_text.c_str(), paint_text.c_str()); |
| 405 EXPECT_EQ(0, text_bounds.x()); | 405 EXPECT_EQ(0, text_bounds.x()); |
| 406 EXPECT_EQ(0, text_bounds.y()); | 406 EXPECT_EQ(0, text_bounds.y()); |
| 407 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 407 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 408 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 408 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 409 EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_LEFT, flags); | 409 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); |
| 410 | 410 |
| 411 label.SetHorizontalAlignment(Label::ALIGN_RIGHT); | 411 label.SetHorizontalAlignment(Label::ALIGN_RIGHT); |
| 412 paint_text.clear(); | 412 paint_text.clear(); |
| 413 text_bounds.SetRect(0, 0, 0, 0); | 413 text_bounds.SetRect(0, 0, 0, 0); |
| 414 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 414 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 415 EXPECT_STREQ(test_text.c_str(), paint_text.c_str()); | 415 EXPECT_STREQ(test_text.c_str(), paint_text.c_str()); |
| 416 EXPECT_EQ(0, text_bounds.x()); | 416 EXPECT_EQ(0, text_bounds.x()); |
| 417 EXPECT_EQ(0, text_bounds.y()); | 417 EXPECT_EQ(0, text_bounds.y()); |
| 418 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 418 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 419 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 419 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 420 EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_RIGHT, flags); | 420 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); |
| 421 | 421 |
| 422 // Test multiline drawing with a border. | 422 // Test multiline drawing with a border. |
| 423 gfx::Insets border(19, 92, 23, 2); | 423 gfx::Insets border(19, 92, 23, 2); |
| 424 label.set_border(Border::CreateEmptyBorder(border.top(), | 424 label.set_border(Border::CreateEmptyBorder(border.top(), |
| 425 border.left(), | 425 border.left(), |
| 426 border.bottom(), | 426 border.bottom(), |
| 427 border.right())); | 427 border.right())); |
| 428 label.SizeToFit(0); | 428 label.SizeToFit(0); |
| 429 label.SetHorizontalAlignment(Label::ALIGN_CENTER); | 429 label.SetHorizontalAlignment(Label::ALIGN_CENTER); |
| 430 paint_text.clear(); | 430 paint_text.clear(); |
| 431 text_bounds.SetRect(0, 0, 0, 0); | 431 text_bounds.SetRect(0, 0, 0, 0); |
| 432 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 432 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 433 EXPECT_STREQ(test_text.c_str(), paint_text.c_str()); | 433 EXPECT_STREQ(test_text.c_str(), paint_text.c_str()); |
| 434 EXPECT_EQ(center_bounds.x() + border.left(), text_bounds.x()); | 434 EXPECT_EQ(center_bounds.x() + border.left(), text_bounds.x()); |
| 435 EXPECT_EQ(center_bounds.y() + border.top(), text_bounds.y()); | 435 EXPECT_EQ(center_bounds.y() + border.top(), text_bounds.y()); |
| 436 EXPECT_EQ(center_bounds.width(), text_bounds.width()); | 436 EXPECT_EQ(center_bounds.width(), text_bounds.width()); |
| 437 EXPECT_EQ(center_bounds.height(), text_bounds.height()); | 437 EXPECT_EQ(center_bounds.height(), text_bounds.height()); |
| 438 EXPECT_EQ(ChromeCanvas::MULTI_LINE | ChromeCanvas::TEXT_ALIGN_CENTER, flags); | 438 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); |
| 439 } | 439 } |
| 440 | 440 |
| 441 } // namespace views | 441 } // namespace views |
| OLD | NEW |