| 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 "ui/views/bubble/bubble_border.h" | 5 #include "ui/views/bubble/bubble_border.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d", | 302 SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d", |
| 303 static_cast<int>(i), cases[i].arrow)); | 303 static_cast<int>(i), cases[i].arrow)); |
| 304 | 304 |
| 305 border.set_arrow(cases[i].arrow); | 305 border.set_arrow(cases[i].arrow); |
| 306 | 306 |
| 307 border.set_paint_arrow(BubbleBorder::PAINT_NORMAL); | 307 border.set_paint_arrow(BubbleBorder::PAINT_NORMAL); |
| 308 EXPECT_EQ(cases[i].expected_with_arrow, | 308 EXPECT_EQ(cases[i].expected_with_arrow, |
| 309 border.GetSizeForContentsSize(cases[i].content)); | 309 border.GetSizeForContentsSize(cases[i].content)); |
| 310 | 310 |
| 311 border.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT); | 311 border.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT); |
| 312 EXPECT_EQ(cases[i].expected_with_arrow, | 312 EXPECT_EQ(cases[i].expected_without_arrow, |
| 313 border.GetSizeForContentsSize(cases[i].content)); | 313 border.GetSizeForContentsSize(cases[i].content)); |
| 314 | 314 |
| 315 border.set_paint_arrow(BubbleBorder::PAINT_NONE); | 315 border.set_paint_arrow(BubbleBorder::PAINT_NONE); |
| 316 EXPECT_EQ(cases[i].expected_without_arrow, | 316 EXPECT_EQ(cases[i].expected_without_arrow, |
| 317 border.GetSizeForContentsSize(cases[i].content)); | 317 border.GetSizeForContentsSize(cases[i].content)); |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 | 320 |
| 321 TEST_F(BubbleBorderTest, GetBoundsOriginTest) { | 321 TEST_F(BubbleBorderTest, GetBoundsOriginTest) { |
| 322 views::BubbleBorder border(BubbleBorder::TOP_LEFT, | 322 views::BubbleBorder border(BubbleBorder::TOP_LEFT, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 340 const gfx::Size kTotalSizeWithNoArrow = | 340 const gfx::Size kTotalSizeWithNoArrow = |
| 341 border.GetSizeForContentsSize(kContentSize); | 341 border.GetSizeForContentsSize(kContentSize); |
| 342 | 342 |
| 343 const int kBorderThickness = border.GetBorderThickness(); | 343 const int kBorderThickness = border.GetBorderThickness(); |
| 344 | 344 |
| 345 const int kArrowOffsetForHorizCenter = kTotalSizeWithHorizArrow.width() / 2; | 345 const int kArrowOffsetForHorizCenter = kTotalSizeWithHorizArrow.width() / 2; |
| 346 const int kArrowOffsetForVertCenter = kTotalSizeWithVertArrow.height() / 2; | 346 const int kArrowOffsetForVertCenter = kTotalSizeWithVertArrow.height() / 2; |
| 347 const int kArrowOffsetForNotCenter = | 347 const int kArrowOffsetForNotCenter = |
| 348 kImages->border_thickness + (kImages->arrow_width / 2); | 348 kImages->border_thickness + (kImages->arrow_width / 2); |
| 349 | 349 |
| 350 const int kArrowSize = | 350 const int kArrowThickness = kImages->arrow_interior_thickness; |
| 351 kImages->arrow_interior_thickness + BubbleBorder::kStroke - | 351 const int kArrowShift = |
| 352 kImages->arrow_thickness; | 352 kArrowThickness + BubbleBorder::kStroke - kImages->arrow_thickness; |
| 353 const int kHeightDifference = kTotalSizeWithHorizArrow.height() - |
| 354 kTotalSizeWithNoArrow.height(); |
| 355 const int kWidthDifference = kTotalSizeWithVertArrow.width() - |
| 356 kTotalSizeWithNoArrow.width(); |
| 357 EXPECT_EQ(kHeightDifference, kWidthDifference); |
| 358 EXPECT_EQ(kHeightDifference, kArrowThickness); |
| 353 | 359 |
| 354 const int kTopHorizArrowY = kAnchor.y() + kAnchor.height() + kArrowSize; | 360 const int kTopHorizArrowY = kAnchor.y() + kAnchor.height() + kArrowShift; |
| 355 const int kBottomHorizArrowY = | 361 const int kBottomHorizArrowY = |
| 356 kAnchor.y() - kArrowSize - kTotalSizeWithHorizArrow.height(); | 362 kAnchor.y() - kArrowShift - kTotalSizeWithHorizArrow.height(); |
| 357 | 363 const int kLeftVertArrowX = kAnchor.x() + kAnchor.width() + kArrowShift; |
| 358 const int kLeftVertArrowX = kAnchor.x() + kAnchor.width() + kArrowSize; | |
| 359 const int kRightVertArrowX = | 364 const int kRightVertArrowX = |
| 360 kAnchor.x() - kArrowSize - kTotalSizeWithVertArrow.width(); | 365 kAnchor.x() - kArrowShift - kTotalSizeWithVertArrow.width(); |
| 361 | 366 |
| 362 struct TestCase { | 367 struct TestCase { |
| 363 BubbleBorder::Arrow arrow; | 368 BubbleBorder::Arrow arrow; |
| 364 BubbleBorder::BubbleAlignment alignment; | 369 BubbleBorder::BubbleAlignment alignment; |
| 365 int expected_x; | 370 int expected_x; |
| 366 int expected_y; | 371 int expected_y; |
| 367 }; | 372 }; |
| 368 | 373 |
| 369 TestCase cases[] = { | 374 TestCase cases[] = { |
| 370 // Horizontal arrow tests. | 375 // Horizontal arrow tests. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 401 kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, | 406 kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, |
| 402 kAnchor.y() + kAnchor.height() }, | 407 kAnchor.y() + kAnchor.height() }, |
| 403 { BubbleBorder::FLOAT, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, | 408 { BubbleBorder::FLOAT, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, |
| 404 kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, | 409 kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, |
| 405 kAnchor.y() + (kAnchor.height() - kTotalSizeWithNoArrow.height()) / 2 }, | 410 kAnchor.y() + (kAnchor.height() - kTotalSizeWithNoArrow.height()) / 2 }, |
| 406 }; | 411 }; |
| 407 | 412 |
| 408 for (size_t i = 0; i < arraysize(cases); ++i) { | 413 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 409 SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d alignment=%d", | 414 SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d alignment=%d", |
| 410 static_cast<int>(i), cases[i].arrow, cases[i].alignment)); | 415 static_cast<int>(i), cases[i].arrow, cases[i].alignment)); |
| 411 border.set_arrow(cases[i].arrow); | 416 const BubbleBorder::Arrow arrow = cases[i].arrow; |
| 417 border.set_arrow(arrow); |
| 412 border.set_alignment(cases[i].alignment); | 418 border.set_alignment(cases[i].alignment); |
| 413 | 419 |
| 420 border.set_paint_arrow(BubbleBorder::PAINT_NORMAL); |
| 414 gfx::Point origin = border.GetBounds(kAnchor, kContentSize).origin(); | 421 gfx::Point origin = border.GetBounds(kAnchor, kContentSize).origin(); |
| 415 EXPECT_EQ(cases[i].expected_x, origin.x()); | 422 int expected_x = cases[i].expected_x; |
| 416 EXPECT_EQ(cases[i].expected_y, origin.y()); | 423 int expected_y = cases[i].expected_y; |
| 424 EXPECT_EQ(expected_x, origin.x()); |
| 425 EXPECT_EQ(expected_y, origin.y()); |
| 426 |
| 427 border.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT); |
| 428 origin = border.GetBounds(kAnchor, kContentSize).origin(); |
| 429 if (border.is_arrow_on_horizontal(arrow)) { |
| 430 expected_y += BubbleBorder::is_arrow_on_top(arrow) |
| 431 ? kArrowThickness : (-kArrowThickness + kHeightDifference); |
| 432 } else if (BubbleBorder::has_arrow(arrow)) { |
| 433 expected_x += BubbleBorder::is_arrow_on_left(arrow) |
| 434 ? kArrowThickness : (-kArrowThickness + kWidthDifference); |
| 435 } |
| 436 EXPECT_EQ(expected_x, origin.x()); |
| 437 EXPECT_EQ(expected_y, origin.y()); |
| 438 |
| 439 border.set_paint_arrow(BubbleBorder::PAINT_NONE); |
| 440 origin = border.GetBounds(kAnchor, kContentSize).origin(); |
| 441 expected_x = cases[i].expected_x; |
| 442 expected_y = cases[i].expected_y; |
| 443 if (border.is_arrow_on_horizontal(arrow) && |
| 444 !BubbleBorder::is_arrow_on_top(arrow)) { |
| 445 expected_y += kHeightDifference; |
| 446 } else if (BubbleBorder::has_arrow(arrow) && |
| 447 !border.is_arrow_on_horizontal(arrow) && |
| 448 !BubbleBorder::is_arrow_on_left(arrow)) { |
| 449 expected_x += kWidthDifference; |
| 450 } |
| 451 EXPECT_EQ(expected_x, origin.x()); |
| 452 EXPECT_EQ(expected_y, origin.y()); |
| 417 } | 453 } |
| 418 } | 454 } |
| 419 | 455 |
| 420 // Ensure all the shadow types pass some size validation and paint sanely. | 456 // Ensure all the shadow types pass some size validation and paint sanely. |
| 421 TEST_F(BubbleBorderTest, ShadowTypes) { | 457 TEST_F(BubbleBorderTest, ShadowTypes) { |
| 422 const gfx::Rect rect(0, 0, 320, 200); | 458 const gfx::Rect rect(0, 0, 320, 200); |
| 423 View paint_view; | 459 View paint_view; |
| 424 paint_view.SetBoundsRect(rect); | 460 paint_view.SetBoundsRect(rect); |
| 425 | 461 |
| 426 for (int i = 0; i < BubbleBorder::SHADOW_COUNT; ++i) { | 462 for (int i = 0; i < BubbleBorder::SHADOW_COUNT; ++i) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 440 EXPECT_GE(border_images->border_thickness, | 476 EXPECT_GE(border_images->border_thickness, |
| 441 border_images->border_interior_thickness); | 477 border_images->border_interior_thickness); |
| 442 | 478 |
| 443 // For a TOP_LEFT arrow, the x-offset always matches the border thickness. | 479 // For a TOP_LEFT arrow, the x-offset always matches the border thickness. |
| 444 EXPECT_EQ(border.GetArrowRect(rect).x(), border_images->border_thickness); | 480 EXPECT_EQ(border.GetArrowRect(rect).x(), border_images->border_thickness); |
| 445 border.Paint(paint_view, &canvas); | 481 border.Paint(paint_view, &canvas); |
| 446 } | 482 } |
| 447 } | 483 } |
| 448 | 484 |
| 449 } // namespace views | 485 } // namespace views |
| OLD | NEW |