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" |
11 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" | 11 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" |
12 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" | 12 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "ui/gfx/path.h" | 15 #include "ui/gfx/path.h" |
16 #include "ui/gfx/rect_conversions.h" | 16 #include "ui/gfx/rect_conversions.h" |
17 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
18 #include "ui/views/test/views_test_base.h" | 18 #include "ui/views/test/views_test_base.h" |
19 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| 20 #include "ui/views/view_targeter.h" |
20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Walks up the views hierarchy until it finds a tab view. It returns the | 25 // Walks up the views hierarchy until it finds a tab view. It returns the |
25 // found tab view, on NULL if none is found. | 26 // found tab view, on NULL if none is found. |
26 views::View* FindTabView(views::View* view) { | 27 views::View* FindTabView(views::View* view) { |
27 views::View* current = view; | 28 views::View* current = view; |
28 while (current && strcmp(current->GetClassName(), Tab::kViewClassName)) { | 29 while (current && strcmp(current->GetClassName(), Tab::kViewClassName)) { |
29 current = current->parent(); | 30 current = current->parent(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 120 |
120 virtual void TearDown() OVERRIDE { | 121 virtual void TearDown() OVERRIDE { |
121 widget_.reset(); | 122 widget_.reset(); |
122 views::ViewsTestBase::TearDown(); | 123 views::ViewsTestBase::TearDown(); |
123 } | 124 } |
124 | 125 |
125 protected: | 126 protected: |
126 // Returns the rectangular hit test region of |tab| in |tab|'s local | 127 // Returns the rectangular hit test region of |tab| in |tab|'s local |
127 // coordinate space. | 128 // coordinate space. |
128 gfx::Rect GetTabHitTestMask(Tab* tab) { | 129 gfx::Rect GetTabHitTestMask(Tab* tab) { |
| 130 views::ViewTargeter* targeter = tab->targeter(); |
| 131 DCHECK(targeter); |
| 132 views::MaskedTargeterDelegate* delegate = |
| 133 static_cast<views::MaskedTargeterDelegate*>(tab); |
| 134 |
129 gfx::Path mask; | 135 gfx::Path mask; |
130 tab->GetHitTestMaskDeprecated(views::View::HIT_TEST_SOURCE_TOUCH, &mask); | 136 bool valid_mask = delegate->GetHitTestMask(&mask); |
| 137 DCHECK(valid_mask); |
| 138 |
131 return gfx::ToEnclosingRect((gfx::SkRectToRectF(mask.getBounds()))); | 139 return gfx::ToEnclosingRect((gfx::SkRectToRectF(mask.getBounds()))); |
132 } | 140 } |
133 | 141 |
134 // Returns the rectangular hit test region of the tab close button of | 142 // Returns the rectangular hit test region of the tab close button of |
135 // |tab| in |tab|'s coordinate space (including padding if |padding| | 143 // |tab| in |tab|'s coordinate space (including padding if |padding| |
136 // is true). | 144 // is true). |
137 gfx::Rect GetTabCloseHitTestMask(Tab* tab, bool padding) { | 145 gfx::Rect GetTabCloseHitTestMask(Tab* tab, bool padding) { |
138 gfx::RectF bounds_f = tab->close_button_->GetContentsBounds(); | 146 gfx::RectF bounds_f = tab->close_button_->GetContentsBounds(); |
139 if (padding) | 147 if (padding) |
140 bounds_f = tab->close_button_->GetLocalBounds(); | 148 bounds_f = tab->close_button_->GetLocalBounds(); |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); | 631 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); |
624 | 632 |
625 EXPECT_EQ( | 633 EXPECT_EQ( |
626 right_tab, | 634 right_tab, |
627 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); | 635 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); |
628 | 636 |
629 // Confirm that tab strip doe not return tooltip handler for points that | 637 // Confirm that tab strip doe not return tooltip handler for points that |
630 // don't hit it. | 638 // don't hit it. |
631 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); | 639 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); |
632 } | 640 } |
OLD | NEW |