| 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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1421 | 1424 |
| 1422 controller()->PerformDrop(drop_before, drop_index, url); | 1425 controller()->PerformDrop(drop_before, drop_index, url); |
| 1423 | 1426 |
| 1424 return GetDropEffect(event); | 1427 return GetDropEffect(event); |
| 1425 } | 1428 } |
| 1426 | 1429 |
| 1427 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { | 1430 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { |
| 1428 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 1431 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; |
| 1429 } | 1432 } |
| 1430 | 1433 |
| 1431 views::View* TabStrip::GetEventHandlerForPoint(const gfx::Point& point) { | 1434 views::View* TabStrip::GetEventHandlerForRect(const gfx::Rect& rect) { |
| 1435 if (!View::UsePointBasedTargeting(rect)) |
| 1436 return View::GetEventHandlerForRect(rect); |
| 1437 |
| 1432 if (!touch_layout_.get()) { | 1438 if (!touch_layout_.get()) { |
| 1433 // Return any view that isn't a Tab or this TabStrip immediately. We don't | 1439 // Return any view that isn't a Tab or this TabStrip immediately. We don't |
| 1434 // want to interfere. | 1440 // want to interfere. |
| 1435 views::View* v = View::GetEventHandlerForPoint(point); | 1441 views::View* v = View::GetEventHandlerForRect(rect); |
| 1436 if (v && v != this && strcmp(v->GetClassName(), Tab::kViewClassName)) | 1442 if (v && v != this && strcmp(v->GetClassName(), Tab::kViewClassName)) |
| 1437 return v; | 1443 return v; |
| 1438 | 1444 |
| 1439 views::View* tab = FindTabHitByPoint(point); | 1445 views::View* tab = FindTabHitByPoint(rect.CenterPoint()); |
| 1440 if (tab) | 1446 if (tab) |
| 1441 return tab; | 1447 return tab; |
| 1442 } else { | 1448 } else { |
| 1443 if (newtab_button_->visible()) { | 1449 if (newtab_button_->visible()) { |
| 1444 views::View* view = | 1450 views::View* view = |
| 1445 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); | 1451 ConvertRectToViewAndGetEventHandler(this, newtab_button_, rect); |
| 1446 if (view) | 1452 if (view) |
| 1447 return view; | 1453 return view; |
| 1448 } | 1454 } |
| 1449 Tab* tab = FindTabForEvent(point); | 1455 Tab* tab = FindTabForEvent(rect.CenterPoint()); |
| 1450 if (tab) | 1456 if (tab) |
| 1451 return ConvertPointToViewAndGetEventHandler(this, tab, point); | 1457 return ConvertRectToViewAndGetEventHandler(this, tab, rect); |
| 1452 } | 1458 } |
| 1453 return this; | 1459 return this; |
| 1454 } | 1460 } |
| 1455 | 1461 |
| 1456 views::View* TabStrip::GetTooltipHandlerForPoint(const gfx::Point& point) { | 1462 views::View* TabStrip::GetTooltipHandlerForPoint(const gfx::Point& point) { |
| 1457 if (!HitTestPoint(point)) | 1463 if (!HitTestPoint(point)) |
| 1458 return NULL; | 1464 return NULL; |
| 1459 | 1465 |
| 1460 if (!touch_layout_.get()) { | 1466 if (!touch_layout_.get()) { |
| 1461 // Return any view that isn't a Tab or this TabStrip immediately. We don't | 1467 // 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... |
| 2584 true); | 2590 true); |
| 2585 } | 2591 } |
| 2586 | 2592 |
| 2587 bool TabStrip::IsPointInTab(Tab* tab, | 2593 bool TabStrip::IsPointInTab(Tab* tab, |
| 2588 const gfx::Point& point_in_tabstrip_coords) { | 2594 const gfx::Point& point_in_tabstrip_coords) { |
| 2589 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 2595 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); |
| 2590 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); | 2596 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); |
| 2591 return tab->HitTestPoint(point_in_tab_coords); | 2597 return tab->HitTestPoint(point_in_tab_coords); |
| 2592 } | 2598 } |
| 2593 | 2599 |
| 2600 bool TabStrip::IsRectInTab(Tab* tab, |
| 2601 const gfx::Rect& rect_in_tabstrip_coords) { |
| 2602 gfx::Rect rect_in_tab_coords(rect_in_tabstrip_coords); |
| 2603 View::ConvertRectToTarget(this, tab, &rect_in_tab_coords); |
| 2604 return tab->HitTestRect(rect_in_tab_coords); |
| 2605 } |
| 2606 |
| 2594 int TabStrip::GetStartXForNormalTabs() const { | 2607 int TabStrip::GetStartXForNormalTabs() const { |
| 2595 int mini_tab_count = GetMiniTabCount(); | 2608 int mini_tab_count = GetMiniTabCount(); |
| 2596 if (mini_tab_count == 0) | 2609 if (mini_tab_count == 0) |
| 2597 return 0; | 2610 return 0; |
| 2598 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + | 2611 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + |
| 2599 kMiniToNonMiniGap; | 2612 kMiniToNonMiniGap; |
| 2600 } | 2613 } |
| 2601 | 2614 |
| 2602 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { | 2615 Tab* TabStrip::FindTabForEvent(const gfx::Point& point) { |
| 2603 if (touch_layout_.get()) { | 2616 if (touch_layout_.get()) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2722 if (!adjust_layout_) | 2735 if (!adjust_layout_) |
| 2723 return false; | 2736 return false; |
| 2724 | 2737 |
| 2725 #if !defined(OS_CHROMEOS) | 2738 #if !defined(OS_CHROMEOS) |
| 2726 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2739 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
| 2727 return false; | 2740 return false; |
| 2728 #endif | 2741 #endif |
| 2729 | 2742 |
| 2730 return true; | 2743 return true; |
| 2731 } | 2744 } |
| OLD | NEW |