| 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 "chrome/browser/ui/views/tabs/tab_strip.h" | 5 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h" | 8 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h" |
| 9 #include "chrome/browser/ui/views/tabs/tab.h" | 9 #include "chrome/browser/ui/views/tabs/tab.h" |
| 10 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 10 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 Tab* most_right_tab = tab_strip_->tab_at(3); | 250 Tab* most_right_tab = tab_strip_->tab_at(3); |
| 251 most_right_tab->SetBoundsRect(gfx::Rect(gfx::Point(450, 0), | 251 most_right_tab->SetBoundsRect(gfx::Rect(gfx::Point(450, 0), |
| 252 gfx::Size(200, 20))); | 252 gfx::Size(200, 20))); |
| 253 | 253 |
| 254 // Switch to stacked layout mode and force a layout to ensure tabs stack. | 254 // Switch to stacked layout mode and force a layout to ensure tabs stack. |
| 255 tab_strip_->SetLayoutType(TAB_STRIP_LAYOUT_STACKED, false); | 255 tab_strip_->SetLayoutType(TAB_STRIP_LAYOUT_STACKED, false); |
| 256 tab_strip_->DoLayout(); | 256 tab_strip_->DoLayout(); |
| 257 | 257 |
| 258 | 258 |
| 259 // Tests involving |left_tab|, which has part of its bounds and its tab | 259 // Tests involving |left_tab|, which has part of its bounds and its tab |
| 260 // close button occluded by |active_tab|. | 260 // close button completely occluded by |active_tab|. |
| 261 | 261 |
| 262 // Bounds of the tab's hit test mask. | 262 // Bounds of the tab's hit test mask. |
| 263 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); | 263 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); |
| 264 EXPECT_EQ(gfx::Rect(6, 2, 61, 27).ToString(), tab_bounds.ToString()); | 264 EXPECT_EQ(gfx::Rect(6, 2, 61, 27).ToString(), tab_bounds.ToString()); |
| 265 | 265 |
| 266 // Bounds of the tab close button (without padding) in the tab's | 266 // Bounds of the tab close button (without padding) in the tab's |
| 267 // coordinate space. | 267 // coordinate space. |
| 268 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false); | 268 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false); |
| 269 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. | 269 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. |
| 270 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); | 270 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); |
| 271 | 271 |
| 272 // Verify that the tab close button is occluded. | 272 // Verify that the tab close button is completely occluded. |
| 273 EXPECT_FALSE(tab_bounds.Contains(contents_bounds)); | 273 EXPECT_FALSE(tab_bounds.Contains(contents_bounds)); |
| 274 | 274 |
| 275 // Hit tests in the non-occuluded region of the tab. | 275 // Hit tests in the non-occuluded region of the tab. |
| 276 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 2, 2))); | 276 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 2, 2))); |
| 277 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 1, 1))); | 277 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(6, 2, 1, 1))); |
| 278 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); | 278 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); |
| 279 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 25, 35))); | 279 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(30, 15, 25, 35))); |
| 280 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(-10, -5, 20, 30))); | 280 EXPECT_TRUE(left_tab->HitTestRect(gfx::Rect(-10, -5, 20, 30))); |
| 281 | 281 |
| 282 // Hit tests in the occluded region of the tab. | 282 // Hit tests in the occluded region of the tab. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 310 | 310 |
| 311 // Bounds of the tab close button (without padding) in the tab's | 311 // Bounds of the tab close button (without padding) in the tab's |
| 312 // coordinate space. | 312 // coordinate space. |
| 313 gfx::Rect local_bounds = GetTabCloseHitTestMask(active_tab, true); | 313 gfx::Rect local_bounds = GetTabCloseHitTestMask(active_tab, true); |
| 314 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString()); | 314 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString()); |
| 315 | 315 |
| 316 // Hit tests within the tab. | 316 // Hit tests within the tab. |
| 317 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); | 317 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 1, 1))); |
| 318 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 2, 2))); | 318 EXPECT_TRUE(active_tab->HitTestRect(gfx::Rect(30, 15, 2, 2))); |
| 319 | 319 |
| 320 // Hit tests against the tab close button. Note that if the hit test | 320 // Hit tests against the tab close button. Note that hit tests from either |
| 321 // source is a mouse, a hit test within the button's padding should fail. | 321 // mouse or touch should both fail if they are strictly contained within |
| 322 // the button's padding. |
| 322 views::ImageButton* active_close = active_tab->close_button_; | 323 views::ImageButton* active_close = active_tab->close_button_; |
| 323 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); | 324 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); |
| 324 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); | 325 EXPECT_FALSE(active_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); |
| 325 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); | 326 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); |
| 326 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 25, 35))); | 327 EXPECT_TRUE(active_close->HitTestRect(gfx::Rect(10, 10, 25, 35))); |
| 327 | 328 |
| 328 | 329 |
| 329 // Tests involving |most_right_tab|, which has part of its bounds occluded | 330 // Tests involving |most_right_tab|, which has part of its bounds occluded |
| 330 // by |right_tab| but has its tab close button completely visible. | 331 // by |right_tab| but has its tab close button completely visible. |
| 331 | 332 |
| 332 tab_bounds = GetTabHitTestMask(most_right_tab); | 333 tab_bounds = GetTabHitTestMask(most_right_tab); |
| 333 EXPECT_EQ(gfx::Rect(84, 2, 30, 27).ToString(), tab_bounds.ToString()); | 334 EXPECT_EQ(gfx::Rect(84, 2, 30, 27).ToString(), tab_bounds.ToString()); |
| 334 contents_bounds = GetTabCloseHitTestMask(active_tab, false); | 335 contents_bounds = GetTabCloseHitTestMask(active_tab, false); |
| 335 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. | 336 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. |
| 336 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); | 337 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); |
| 337 local_bounds = GetTabCloseHitTestMask(active_tab, true); | 338 local_bounds = GetTabCloseHitTestMask(active_tab, true); |
| 338 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString()); | 339 EXPECT_EQ(gfx::Rect(81, 0, 39, 29).ToString(), local_bounds.ToString()); |
| 339 | 340 |
| 340 // Verify that the tab close button is not occluded. | 341 // Verify that the tab close button is not occluded. |
| 341 EXPECT_TRUE(tab_bounds.Contains(contents_bounds)); | 342 EXPECT_TRUE(tab_bounds.Contains(contents_bounds)); |
| 342 | 343 |
| 343 // Hit tests in the occluded region of the tab. | 344 // Hit tests in the occluded region of the tab. |
| 344 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 1, 1))); | 345 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 1, 1))); |
| 345 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 5, 6))); | 346 EXPECT_FALSE(most_right_tab->HitTestRect(gfx::Rect(20, 15, 5, 6))); |
| 346 | 347 |
| 347 // Hit tests in the non-occluded region of the tab. | 348 // Hit tests in the non-occluded region of the tab. |
| 348 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 1, 1))); | 349 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 1, 1))); |
| 349 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 2, 2))); | 350 EXPECT_TRUE(most_right_tab->HitTestRect(gfx::Rect(85, 15, 2, 2))); |
| 350 | 351 |
| 351 // Hit tests against the tab close button. Note that if the hit test | 352 // Hit tests against the tab close button. Note that hit tests from either |
| 352 // source is a mouse, a hit test within the button's padding should fail. | 353 // mouse or touch should both fail if they are strictly contained within |
| 354 // the button's padding. |
| 353 views::ImageButton* most_right_close = most_right_tab->close_button_; | 355 views::ImageButton* most_right_close = most_right_tab->close_button_; |
| 354 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); | 356 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); |
| 355 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); | 357 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); |
| 356 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); | 358 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); |
| 357 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 25, 35))); | 359 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 25, 35))); |
| 358 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(-10, 10, 25, 35))); | 360 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(-10, 10, 25, 35))); |
| 359 } | 361 } |
| 360 | 362 |
| 363 // Creates a tab strip in stacked layout mode and verifies the correctness |
| 364 // of hit tests against the visible/occluded region of a partially-occluded |
| 365 // tab close button. |
| 366 TEST_F(TabStripTest, ClippedTabCloseButton) { |
| 367 tab_strip_->SetBounds(0, 0, 220, 20); |
| 368 |
| 369 controller_->AddTab(0, false); |
| 370 controller_->AddTab(1, true); |
| 371 ASSERT_EQ(2, tab_strip_->tab_count()); |
| 372 |
| 373 Tab* left_tab = tab_strip_->tab_at(0); |
| 374 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); |
| 375 |
| 376 Tab* active_tab = tab_strip_->tab_at(1); |
| 377 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(180, 0), gfx::Size(200, 20))); |
| 378 ASSERT_TRUE(active_tab->IsActive()); |
| 379 |
| 380 // Switch to stacked layout mode and force a layout to ensure tabs stack. |
| 381 tab_strip_->SetLayoutType(TAB_STRIP_LAYOUT_STACKED, false); |
| 382 tab_strip_->DoLayout(); |
| 383 |
| 384 |
| 385 // Tests involving |left_tab|, which has part of its bounds and its tab |
| 386 // close button partially occluded by |active_tab|. |
| 387 |
| 388 // Bounds of the tab's hit test mask. |
| 389 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); |
| 390 EXPECT_EQ(gfx::Rect(6, 2, 91, 27).ToString(), tab_bounds.ToString()); |
| 391 |
| 392 // Bounds of the tab close button (without padding) in the tab's |
| 393 // coordinate space. |
| 394 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false); |
| 395 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. |
| 396 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); |
| 397 |
| 398 // Verify that the tab close button is only partially occluded. |
| 399 EXPECT_FALSE(tab_bounds.Contains(contents_bounds)); |
| 400 EXPECT_TRUE(tab_bounds.Intersects(contents_bounds)); |
| 401 |
| 402 views::ImageButton* left_close = left_tab->close_button_; |
| 403 |
| 404 // Hit tests from mouse should return true if and only if the location |
| 405 // is within a visible region. |
| 406 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(2, 15, 1, 1))); |
| 407 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(3, 15, 1, 1))); |
| 408 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); |
| 409 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(15, 12, 1, 1))); |
| 410 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 1, 1))); |
| 411 |
| 412 // All hit tests from touch should return false because the button is |
| 413 // not fully visible. |
| 414 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(2, 15, 2, 2))); |
| 415 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(3, 15, 25, 25))); |
| 416 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(10, 10, 4, 5))); |
| 417 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(15, 12, 2, 2))); |
| 418 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 20, 20))); |
| 419 } |
| 420 |
| 361 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { | 421 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { |
| 362 tab_strip_->SetBounds(0, 0, 1000, 20); | 422 tab_strip_->SetBounds(0, 0, 1000, 20); |
| 363 | 423 |
| 364 controller_->AddTab(0, false); | 424 controller_->AddTab(0, false); |
| 365 controller_->AddTab(1, true); | 425 controller_->AddTab(1, true); |
| 366 controller_->AddTab(2, false); | 426 controller_->AddTab(2, false); |
| 367 controller_->AddTab(3, false); | 427 controller_->AddTab(3, false); |
| 368 ASSERT_EQ(4, tab_strip_->tab_count()); | 428 ASSERT_EQ(4, tab_strip_->tab_count()); |
| 369 | 429 |
| 370 // Verify that the active tab will be a tooltip handler for points that hit | 430 // Verify that the active tab will be a tooltip handler for points that hit |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); | 541 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); |
| 482 | 542 |
| 483 EXPECT_EQ( | 543 EXPECT_EQ( |
| 484 right_tab, | 544 right_tab, |
| 485 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); | 545 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); |
| 486 | 546 |
| 487 // Confirm that tab strip doe not return tooltip handler for points that | 547 // Confirm that tab strip doe not return tooltip handler for points that |
| 488 // don't hit it. | 548 // don't hit it. |
| 489 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); | 549 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); |
| 490 } | 550 } |
| OLD | NEW |