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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 // Hit tests against the tab close button. Note that if the hit test | 351 // Hit tests against the tab close button. Note that if the hit test |
352 // source is a mouse, a hit test within the button's padding should fail. | 352 // source is a mouse, a hit test within the button's padding should fail. |
353 views::ImageButton* most_right_close = most_right_tab->close_button_; | 353 views::ImageButton* most_right_close = most_right_tab->close_button_; |
354 EXPECT_FALSE(most_right_close->HitTestRect(gfx::Rect(1, 1, 1, 1))); | 354 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))); | 355 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(1, 1, 2, 2))); |
356 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); | 356 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))); | 357 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))); | 358 EXPECT_TRUE(most_right_close->HitTestRect(gfx::Rect(-10, 10, 25, 35))); |
359 } | 359 } |
360 | 360 |
| 361 // Creates a tab strip in stacked layout mode and verifies the correctness |
| 362 // of hit tests against the visible/occluded region of a partially-occluded |
| 363 // tab close button. |
| 364 TEST_F(TabStripTest, ClippedTabCloseButton) { |
| 365 tab_strip_->SetBounds(0, 0, 220, 20); |
| 366 |
| 367 controller_->AddTab(0, false); |
| 368 controller_->AddTab(1, true); |
| 369 ASSERT_EQ(2, tab_strip_->tab_count()); |
| 370 |
| 371 Tab* left_tab = tab_strip_->tab_at(0); |
| 372 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); |
| 373 |
| 374 Tab* active_tab = tab_strip_->tab_at(1); |
| 375 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(180, 0), gfx::Size(200, 20))); |
| 376 ASSERT_TRUE(active_tab->IsActive()); |
| 377 |
| 378 // Switch to stacked layout mode and force a layout to ensure tabs stack. |
| 379 tab_strip_->SetLayoutType(TAB_STRIP_LAYOUT_STACKED, false); |
| 380 tab_strip_->DoLayout(); |
| 381 |
| 382 |
| 383 // Tests involving |left_tab|, which has part of its bounds and its tab |
| 384 // close button partially occluded by |active_tab|. |
| 385 |
| 386 // Bounds of the tab's hit test mask. |
| 387 gfx::Rect tab_bounds = GetTabHitTestMask(left_tab); |
| 388 EXPECT_EQ(gfx::Rect(6, 2, 91, 27).ToString(), tab_bounds.ToString()); |
| 389 |
| 390 // Bounds of the tab close button (without padding) in the tab's |
| 391 // coordinate space. |
| 392 gfx::Rect contents_bounds = GetTabCloseHitTestMask(left_tab, false); |
| 393 // TODO(tdanderson): Uncomment this line once crbug.com/311609 is resolved. |
| 394 //EXPECT_EQ(gfx::Rect(84, 8, 18, 18).ToString(), contents_bounds.ToString()); |
| 395 |
| 396 // Verify that the tab close button is only partially occluded. |
| 397 EXPECT_FALSE(tab_bounds.Contains(contents_bounds)); |
| 398 EXPECT_TRUE(tab_bounds.Intersects(contents_bounds)); |
| 399 |
| 400 views::ImageButton* left_close = left_tab->close_button_; |
| 401 |
| 402 // Hit tests from mouse should return true if and only if the location |
| 403 // is within a visible region. |
| 404 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(2, 15, 1, 1))); |
| 405 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(3, 15, 1, 1))); |
| 406 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(10, 10, 1, 1))); |
| 407 EXPECT_TRUE(left_close->HitTestRect(gfx::Rect(15, 12, 1, 1))); |
| 408 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 1, 1))); |
| 409 |
| 410 // All hit tests from touch should return false because the button is |
| 411 // not fully visible. |
| 412 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(2, 15, 2, 2))); |
| 413 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(3, 15, 25, 25))); |
| 414 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(10, 10, 4, 5))); |
| 415 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(15, 12, 2, 2))); |
| 416 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 20, 20))); |
| 417 } |
| 418 |
361 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { | 419 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { |
362 tab_strip_->SetBounds(0, 0, 1000, 20); | 420 tab_strip_->SetBounds(0, 0, 1000, 20); |
363 | 421 |
364 controller_->AddTab(0, false); | 422 controller_->AddTab(0, false); |
365 controller_->AddTab(1, true); | 423 controller_->AddTab(1, true); |
366 controller_->AddTab(2, false); | 424 controller_->AddTab(2, false); |
367 controller_->AddTab(3, false); | 425 controller_->AddTab(3, false); |
368 ASSERT_EQ(4, tab_strip_->tab_count()); | 426 ASSERT_EQ(4, tab_strip_->tab_count()); |
369 | 427 |
370 // Verify that the active tab will be a tooltip handler for points that hit | 428 // 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)); | 539 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); |
482 | 540 |
483 EXPECT_EQ( | 541 EXPECT_EQ( |
484 right_tab, | 542 right_tab, |
485 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); | 543 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); |
486 | 544 |
487 // Confirm that tab strip doe not return tooltip handler for points that | 545 // Confirm that tab strip doe not return tooltip handler for points that |
488 // don't hit it. | 546 // don't hit it. |
489 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); | 547 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); |
490 } | 548 } |
OLD | NEW |