| 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(); |
| 353 | 357 |
| 354 const int kTopHorizArrowY = kAnchor.y() + kAnchor.height() + kArrowSize; | 358 const int kTopHorizArrowY = kAnchor.y() + kAnchor.height() + kArrowShift; |
| 355 const int kBottomHorizArrowY = | 359 const int kBottomHorizArrowY = |
| 356 kAnchor.y() - kArrowSize - kTotalSizeWithHorizArrow.height(); | 360 kAnchor.y() - kArrowShift - kTotalSizeWithHorizArrow.height(); |
| 357 | 361 const int kLeftVertArrowX = kAnchor.x() + kAnchor.width() + kArrowShift; |
| 358 const int kLeftVertArrowX = kAnchor.x() + kAnchor.width() + kArrowSize; | |
| 359 const int kRightVertArrowX = | 362 const int kRightVertArrowX = |
| 360 kAnchor.x() - kArrowSize - kTotalSizeWithVertArrow.width(); | 363 kAnchor.x() - kArrowShift - kTotalSizeWithVertArrow.width(); |
| 361 | 364 |
| 362 struct TestCase { | 365 struct TestCase { |
| 363 BubbleBorder::Arrow arrow; | 366 BubbleBorder::Arrow arrow; |
| 364 BubbleBorder::BubbleAlignment alignment; | 367 BubbleBorder::BubbleAlignment alignment; |
| 365 int expected_x; | 368 int expected_x; |
| 366 int expected_y; | 369 int expected_y; |
| 367 }; | 370 }; |
| 368 | 371 |
| 369 TestCase cases[] = { | 372 TestCase cases[] = { |
| 370 // Horizontal arrow tests. | 373 // Horizontal arrow tests. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 401 kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, | 404 kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, |
| 402 kAnchor.y() + kAnchor.height() }, | 405 kAnchor.y() + kAnchor.height() }, |
| 403 { BubbleBorder::FLOAT, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, | 406 { BubbleBorder::FLOAT, BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, |
| 404 kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, | 407 kAnchor.x() + (kAnchor.width() - kTotalSizeWithNoArrow.width()) / 2, |
| 405 kAnchor.y() + (kAnchor.height() - kTotalSizeWithNoArrow.height()) / 2 }, | 408 kAnchor.y() + (kAnchor.height() - kTotalSizeWithNoArrow.height()) / 2 }, |
| 406 }; | 409 }; |
| 407 | 410 |
| 408 for (size_t i = 0; i < arraysize(cases); ++i) { | 411 for (size_t i = 0; i < arraysize(cases); ++i) { |
| 409 SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d alignment=%d", | 412 SCOPED_TRACE(base::StringPrintf("i=%d arrow=%d alignment=%d", |
| 410 static_cast<int>(i), cases[i].arrow, cases[i].alignment)); | 413 static_cast<int>(i), cases[i].arrow, cases[i].alignment)); |
| 411 border.set_arrow(cases[i].arrow); | 414 const BubbleBorder::Arrow arrow = cases[i].arrow; |
| 415 border.set_arrow(arrow); |
| 412 border.set_alignment(cases[i].alignment); | 416 border.set_alignment(cases[i].alignment); |
| 413 | 417 |
| 418 border.set_paint_arrow(BubbleBorder::PAINT_NORMAL); |
| 414 gfx::Point origin = border.GetBounds(kAnchor, kContentSize).origin(); | 419 gfx::Point origin = border.GetBounds(kAnchor, kContentSize).origin(); |
| 415 EXPECT_EQ(cases[i].expected_x, origin.x()); | 420 int expected_x = cases[i].expected_x; |
| 416 EXPECT_EQ(cases[i].expected_y, origin.y()); | 421 int expected_y = cases[i].expected_y; |
| 422 EXPECT_EQ(expected_x, origin.x()); |
| 423 EXPECT_EQ(expected_y, origin.y()); |
| 424 |
| 425 border.set_paint_arrow(BubbleBorder::PAINT_TRANSPARENT); |
| 426 origin = border.GetBounds(kAnchor, kContentSize).origin(); |
| 427 if (border.is_arrow_on_horizontal(arrow)) { |
| 428 expected_y += BubbleBorder::is_arrow_on_top(arrow) |
| 429 ? kArrowThickness : (-kArrowThickness + kHeightDifference); |
| 430 } else if (BubbleBorder::has_arrow(arrow)) { |
| 431 expected_x += BubbleBorder::is_arrow_on_left(arrow) |
| 432 ? kArrowThickness : (-kArrowThickness + kWidthDifference); |
| 433 } |
| 434 EXPECT_EQ(expected_x, origin.x()); |
| 435 EXPECT_EQ(expected_y, origin.y()); |
| 436 |
| 437 border.set_paint_arrow(BubbleBorder::PAINT_NONE); |
| 438 origin = border.GetBounds(kAnchor, kContentSize).origin(); |
| 439 expected_x = cases[i].expected_x; |
| 440 expected_y = cases[i].expected_y; |
| 441 if (border.is_arrow_on_horizontal(arrow) && |
| 442 !BubbleBorder::is_arrow_on_top(arrow)) { |
| 443 expected_y += kHeightDifference; |
| 444 } else if (BubbleBorder::has_arrow(arrow) && |
| 445 !border.is_arrow_on_horizontal(arrow) && |
| 446 !BubbleBorder::is_arrow_on_left(arrow)) { |
| 447 expected_x += kWidthDifference; |
| 448 } |
| 449 EXPECT_EQ(expected_x, origin.x()); |
| 450 EXPECT_EQ(expected_y, origin.y()); |
| 417 } | 451 } |
| 418 } | 452 } |
| 419 | 453 |
| 420 // Ensure all the shadow types pass some size validation and paint sanely. | 454 // Ensure all the shadow types pass some size validation and paint sanely. |
| 421 TEST_F(BubbleBorderTest, ShadowTypes) { | 455 TEST_F(BubbleBorderTest, ShadowTypes) { |
| 422 const gfx::Rect rect(0, 0, 320, 200); | 456 const gfx::Rect rect(0, 0, 320, 200); |
| 423 View paint_view; | 457 View paint_view; |
| 424 paint_view.SetBoundsRect(rect); | 458 paint_view.SetBoundsRect(rect); |
| 425 | 459 |
| 426 for (int i = 0; i < BubbleBorder::SHADOW_COUNT; ++i) { | 460 for (int i = 0; i < BubbleBorder::SHADOW_COUNT; ++i) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 440 EXPECT_GE(border_images->border_thickness, | 474 EXPECT_GE(border_images->border_thickness, |
| 441 border_images->border_interior_thickness); | 475 border_images->border_interior_thickness); |
| 442 | 476 |
| 443 // For a TOP_LEFT arrow, the x-offset always matches the border thickness. | 477 // For a TOP_LEFT arrow, the x-offset always matches the border thickness. |
| 444 EXPECT_EQ(border.GetArrowRect(rect).x(), border_images->border_thickness); | 478 EXPECT_EQ(border.GetArrowRect(rect).x(), border_images->border_thickness); |
| 445 border.Paint(paint_view, &canvas); | 479 border.Paint(paint_view, &canvas); |
| 446 } | 480 } |
| 447 } | 481 } |
| 448 | 482 |
| 449 } // namespace views | 483 } // namespace views |
| OLD | NEW |