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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE { | 247 virtual void AnimationCanceled(const ui::Animation* animation) OVERRIDE { |
248 tab_->set_dragging(false); | 248 tab_->set_dragging(false); |
249 } | 249 } |
250 | 250 |
251 private: | 251 private: |
252 Tab* tab_; | 252 Tab* tab_; |
253 | 253 |
254 DISALLOW_COPY_AND_ASSIGN(ResetDraggingStateDelegate); | 254 DISALLOW_COPY_AND_ASSIGN(ResetDraggingStateDelegate); |
255 }; | 255 }; |
256 | 256 |
257 // If |dest| contains the point |point_in_source| the event handler from |dest| | 257 // If |dest| intersects the rect |rect_in_source| the event handler from |dest| |
258 // is returned. Otherwise NULL is returned. | 258 // is returned. Otherwise NULL is returned. |
259 views::View* ConvertPointToViewAndGetEventHandler( | 259 views::View* ConvertRectToViewAndGetEventHandler( |
260 views::View* source, | 260 views::View* source, |
261 views::View* dest, | 261 views::View* dest, |
262 const gfx::Point& point_in_source) { | 262 const gfx::Rect& rect_in_source) { |
263 gfx::Point dest_point(point_in_source); | 263 gfx::Rect dest_rect(rect_in_source); |
264 views::View::ConvertPointToTarget(source, dest, &dest_point); | 264 views::View::ConvertRectToTarget(source, dest, &dest_rect); |
265 return dest->HitTestPoint(dest_point) ? | 265 return dest->HitTestRect(dest_rect) ? |
266 dest->GetEventHandlerForPoint(dest_point) : NULL; | 266 dest->GetEventHandlerForRect(dest_rect) : NULL; |
267 } | 267 } |
268 | 268 |
269 // Gets a tooltip handler for |point_in_source| from |dest|. Note that |dest| | 269 // Gets a tooltip handler for |point_in_source| from |dest|. Note that |dest| |
270 // should return NULL if it does not contain the point. | 270 // should return NULL if it does not contain the point. |
271 views::View* ConvertPointToViewAndGetTooltipHandler( | 271 views::View* ConvertPointToViewAndGetTooltipHandler( |
272 views::View* source, | 272 views::View* source, |
273 views::View* dest, | 273 views::View* dest, |
274 const gfx::Point& point_in_source) { | 274 const gfx::Point& point_in_source) { |
275 gfx::Point dest_point(point_in_source); | 275 gfx::Point dest_point(point_in_source); |
276 views::View::ConvertPointToTarget(source, dest, &dest_point); | 276 views::View::ConvertPointToTarget(source, dest, &dest_point); |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
900 | 900 |
901 bool TabStrip::IsTabStripCloseable() const { | 901 bool TabStrip::IsTabStripCloseable() const { |
902 return !IsDragSessionActive(); | 902 return !IsDragSessionActive(); |
903 } | 903 } |
904 | 904 |
905 void TabStrip::UpdateLoadingAnimations() { | 905 void TabStrip::UpdateLoadingAnimations() { |
906 controller_->UpdateLoadingAnimations(); | 906 controller_->UpdateLoadingAnimations(); |
907 } | 907 } |
908 | 908 |
909 bool TabStrip::IsPositionInWindowCaption(const gfx::Point& point) { | 909 bool TabStrip::IsPositionInWindowCaption(const gfx::Point& point) { |
910 views::View* v = GetEventHandlerForPoint(point); | 910 return IsRectInWindowCaption(gfx::Rect(point, gfx::Size(1, 1))); |
911 } | |
912 | |
913 bool TabStrip::IsRectInWindowCaption(const gfx::Rect& rect) { | |
914 views::View* v = GetEventHandlerForRect(rect); | |
911 | 915 |
912 // If there is no control at this location, claim the hit was in the title | 916 // If there is no control at this location, claim the hit was in the title |
913 // bar to get a move action. | 917 // bar to get a move action. |
914 if (v == this) | 918 if (v == this) |
915 return true; | 919 return true; |
916 | 920 |
917 // Check to see if the point is within the non-button parts of the new tab | 921 // Check to see if the rect intersects the non-button parts of the new tab |
918 // button. The button has a non-rectangular shape, so if it's not in the | 922 // button. The button has a non-rectangular shape, so if it's not in the |
919 // visual portions of the button we treat it as a click to the caption. | 923 // visual portions of the button we treat it as a click to the caption. |
920 gfx::Point point_in_newtab_coords(point); | 924 gfx::Rect rect_in_newtab_coords(rect); |
921 View::ConvertPointToTarget(this, newtab_button_, &point_in_newtab_coords); | 925 View::ConvertRectToTarget(this, newtab_button_, &rect_in_newtab_coords); |
922 if (newtab_button_->GetLocalBounds().Contains(point_in_newtab_coords) && | 926 if (newtab_button_->GetLocalBounds().Intersects(rect_in_newtab_coords) && |
923 !newtab_button_->HitTestPoint(point_in_newtab_coords)) { | 927 !newtab_button_->HitTestRect(rect_in_newtab_coords)) |
924 return true; | 928 return true; |
925 } | |
926 | 929 |
927 // All other regions, including the new Tab button, should be considered part | 930 // All other regions, including the new Tab button, should be considered part |
928 // of the containing Window's client area so that regular events can be | 931 // of the containing Window's client area so that regular events can be |
929 // processed for them. | 932 // processed for them. |
930 return false; | 933 return false; |
931 } | 934 } |
932 | 935 |
933 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { | 936 void TabStrip::SetBackgroundOffset(const gfx::Point& offset) { |
934 for (int i = 0; i < tab_count(); ++i) | 937 for (int i = 0; i < tab_count(); ++i) |
935 tab_at(i)->set_background_offset(offset); | 938 tab_at(i)->set_background_offset(offset); |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 | 1414 |
1412 controller()->PerformDrop(drop_before, drop_index, url); | 1415 controller()->PerformDrop(drop_before, drop_index, url); |
1413 | 1416 |
1414 return GetDropEffect(event); | 1417 return GetDropEffect(event); |
1415 } | 1418 } |
1416 | 1419 |
1417 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { | 1420 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { |
1418 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 1421 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; |
1419 } | 1422 } |
1420 | 1423 |
1421 views::View* TabStrip::GetEventHandlerForPoint(const gfx::Point& point) { | 1424 views::View* TabStrip::GetEventHandlerForRect(const gfx::Rect& rect) { |
1425 if (!View::UsePointBasedTargeting(rect)) | |
1426 return View::GetEventHandlerForRect(rect); | |
1427 | |
1422 if (!touch_layout_.get()) { | 1428 if (!touch_layout_.get()) { |
1423 // Return any view that isn't a Tab or this TabStrip immediately. We don't | 1429 // Return any view that isn't a Tab or this TabStrip immediately. We don't |
1424 // want to interfere. | 1430 // want to interfere. |
1425 views::View* v = View::GetEventHandlerForPoint(point); | 1431 views::View* v = View::GetEventHandlerForRect(rect); |
1426 if (v && v != this && strcmp(v->GetClassName(), Tab::kViewClassName)) | 1432 if (v && v != this && strcmp(v->GetClassName(), Tab::kViewClassName)) |
1427 return v; | 1433 return v; |
1428 | 1434 |
1429 views::View* tab = FindTabHitByPoint(point); | 1435 views::View* tab = FindTabHitByPoint(rect.CenterPoint()); |
1430 if (tab) | 1436 if (tab) |
1431 return tab; | 1437 return tab; |
1432 } else { | 1438 } else { |
1433 if (newtab_button_->visible()) { | 1439 if (newtab_button_->visible()) { |
1434 views::View* view = | 1440 views::View* view = |
1435 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 1441 ConvertRectToViewAndGetEventHandler(this, newtab_button_, rect); |
1436 if (view) | 1442 if (view) |
1437 return view; | 1443 return view; |
1438 } | 1444 } |
1439 Tab* tab = FindTabForEvent(point); | 1445 Tab* tab = FindTabForEvent(rect.CenterPoint()); |
1440 if (tab) | 1446 if (tab) |
1441 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 1447 return ConvertRectToViewAndGetEventHandler(this, tab, rect); |
1442 } | 1448 } |
1443 return this; | 1449 return this; |
1444 } | 1450 } |
1445 | 1451 |
1446 views::View* TabStrip::GetTooltipHandlerForPoint(const gfx::Point& point) { | 1452 views::View* TabStrip::GetTooltipHandlerForPoint(const gfx::Point& point) { |
1447 if (!HitTestPoint(point)) | 1453 if (!HitTestPoint(point)) |
1448 return NULL; | 1454 return NULL; |
1449 | 1455 |
1450 if (!touch_layout_.get()) { | 1456 if (!touch_layout_.get()) { |
1451 // Return any view that isn't a Tab or this TabStrip immediately. We don't | 1457 // Return any view that isn't a Tab or this TabStrip immediately. We don't |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2574 true); | 2580 true); |
2575 } | 2581 } |
2576 | 2582 |
2577 bool TabStrip::IsPointInTab(Tab* tab, | 2583 bool TabStrip::IsPointInTab(Tab* tab, |
2578 const gfx::Point& point_in_tabstrip_coords) { | 2584 const gfx::Point& point_in_tabstrip_coords) { |
2579 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 2585 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); |
2580 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); | 2586 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); |
2581 return tab->HitTestPoint(point_in_tab_coords); | 2587 return tab->HitTestPoint(point_in_tab_coords); |
2582 } | 2588 } |
2583 | 2589 |
2590 bool TabStrip::IsRectInTab(Tab* tab, | |
sky
2013/09/10 16:47:41
You don't seem to use this.
tdanderson
2013/10/03 23:17:42
Removed.
| |
2591 const gfx::Rect& rect_in_tabstrip_coords) { | |
2592 gfx::Rect rect_in_tab_coords(rect_in_tabstrip_coords); | |
2593 View::ConvertRectToTarget(this, tab, &rect_in_tab_coords); | |
2594 return tab->HitTestRect(rect_in_tab_coords); | |
2595 } | |
2596 | |
2584 int TabStrip::GetStartXForNormalTabs() const { | 2597 int TabStrip::GetStartXForNormalTabs() const { |
2585 int mini_tab_count = GetMiniTabCount(); | 2598 int mini_tab_count = GetMiniTabCount(); |
2586 if (mini_tab_count == 0) | 2599 if (mini_tab_count == 0) |
2587 return 0; | 2600 return 0; |
2588 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + | 2601 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + |
2589 kMiniToNonMiniGap; | 2602 kMiniToNonMiniGap; |
2590 } | 2603 } |
2591 | 2604 |
2592 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { | 2605 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { |
2593 if (touch_layout_.get()) { | 2606 if (touch_layout_.get()) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2712 if (!adjust_layout_) | 2725 if (!adjust_layout_) |
2713 return false; | 2726 return false; |
2714 | 2727 |
2715 #if !defined(OS_CHROMEOS) | 2728 #if !defined(OS_CHROMEOS) |
2716 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2729 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
2717 return false; | 2730 return false; |
2718 #endif | 2731 #endif |
2719 | 2732 |
2720 return true; | 2733 return true; |
2721 } | 2734 } |
OLD | NEW |