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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 DISALLOW_COPY_AND_ASSIGN(ResetDraggingStateDelegate); | 258 DISALLOW_COPY_AND_ASSIGN(ResetDraggingStateDelegate); |
259 }; | 259 }; |
260 | 260 |
261 // If |dest| contains the point |point_in_source| the event handler from |dest| | 261 // If |dest| contains the point |point_in_source| the event handler from |dest| |
262 // is returned. Otherwise NULL is returned. | 262 // is returned. Otherwise NULL is returned. |
263 views::View* ConvertPointToViewAndGetEventHandler( | 263 views::View* ConvertPointToViewAndGetEventHandler( |
264 views::View* source, | 264 views::View* source, |
265 views::View* dest, | 265 views::View* dest, |
266 const gfx::Point& point_in_source) { | 266 const gfx::Point& point_in_source) { |
267 gfx::Point dest_point(point_in_source); | 267 gfx::Point dest_point(point_in_source); |
268 views::View::ConvertPointToView(source, dest, &dest_point); | 268 views::View::ConvertPointToTarget(source, dest, &dest_point); |
269 return dest->HitTestPoint(dest_point) ? | 269 return dest->HitTestPoint(dest_point) ? |
270 dest->GetEventHandlerForPoint(dest_point) : NULL; | 270 dest->GetEventHandlerForPoint(dest_point) : NULL; |
271 } | 271 } |
272 | 272 |
273 } // namespace | 273 } // namespace |
274 | 274 |
275 /////////////////////////////////////////////////////////////////////////////// | 275 /////////////////////////////////////////////////////////////////////////////// |
276 // NewTabButton | 276 // NewTabButton |
277 // | 277 // |
278 // A subclass of button that hit-tests to the shape of the new tab button and | 278 // A subclass of button that hit-tests to the shape of the new tab button and |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 | 855 |
856 // If there is no control at this location, claim the hit was in the title | 856 // If there is no control at this location, claim the hit was in the title |
857 // bar to get a move action. | 857 // bar to get a move action. |
858 if (v == this) | 858 if (v == this) |
859 return true; | 859 return true; |
860 | 860 |
861 // Check to see if the point is within the non-button parts of the new tab | 861 // Check to see if the point is within the non-button parts of the new tab |
862 // button. The button has a non-rectangular shape, so if it's not in the | 862 // button. The button has a non-rectangular shape, so if it's not in the |
863 // visual portions of the button we treat it as a click to the caption. | 863 // visual portions of the button we treat it as a click to the caption. |
864 gfx::Point point_in_newtab_coords(point); | 864 gfx::Point point_in_newtab_coords(point); |
865 View::ConvertPointToView(this, newtab_button_, &point_in_newtab_coords); | 865 View::ConvertPointToTarget(this, newtab_button_, &point_in_newtab_coords); |
866 if (newtab_button_->GetLocalBounds().Contains(point_in_newtab_coords) && | 866 if (newtab_button_->GetLocalBounds().Contains(point_in_newtab_coords) && |
867 !newtab_button_->HitTestPoint(point_in_newtab_coords)) { | 867 !newtab_button_->HitTestPoint(point_in_newtab_coords)) { |
868 return true; | 868 return true; |
869 } | 869 } |
870 | 870 |
871 // All other regions, including the new Tab button, should be considered part | 871 // All other regions, including the new Tab button, should be considered part |
872 // of the containing Window's client area so that regular events can be | 872 // of the containing Window's client area so that regular events can be |
873 // processed for them. | 873 // processed for them. |
874 return false; | 874 return false; |
875 } | 875 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 if (tab->closing()) | 962 if (tab->closing()) |
963 return false; | 963 return false; |
964 | 964 |
965 int model_index = GetModelIndexOfBaseTab(tab); | 965 int model_index = GetModelIndexOfBaseTab(tab); |
966 return IsValidModelIndex(model_index) && | 966 return IsValidModelIndex(model_index) && |
967 controller_->IsTabPinned(model_index); | 967 controller_->IsTabPinned(model_index); |
968 } | 968 } |
969 | 969 |
970 void TabStrip::MaybeStartDrag( | 970 void TabStrip::MaybeStartDrag( |
971 BaseTab* tab, | 971 BaseTab* tab, |
972 const views::LocatedEvent& event, | 972 const ui::LocatedEvent& event, |
973 const TabStripSelectionModel& original_selection) { | 973 const TabStripSelectionModel& original_selection) { |
974 // Don't accidentally start any drag operations during animations if the | 974 // Don't accidentally start any drag operations during animations if the |
975 // mouse is down... during an animation tabs are being resized automatically, | 975 // mouse is down... during an animation tabs are being resized automatically, |
976 // so the View system can misinterpret this easily if the mouse is down that | 976 // so the View system can misinterpret this easily if the mouse is down that |
977 // the user is dragging. | 977 // the user is dragging. |
978 if (IsAnimating() || tab->closing() || | 978 if (IsAnimating() || tab->closing() || |
979 controller_->HasAvailableDragActions() == 0) { | 979 controller_->HasAvailableDragActions() == 0) { |
980 return; | 980 return; |
981 } | 981 } |
982 int model_index = GetModelIndexOfBaseTab(tab); | 982 int model_index = GetModelIndexOfBaseTab(tab); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 if (!drag_controller_.get()) | 1056 if (!drag_controller_.get()) |
1057 return false; | 1057 return false; |
1058 bool started_drag = drag_controller_->started_drag(); | 1058 bool started_drag = drag_controller_->started_drag(); |
1059 drag_controller_->EndDrag(canceled); | 1059 drag_controller_->EndDrag(canceled); |
1060 return started_drag; | 1060 return started_drag; |
1061 } | 1061 } |
1062 | 1062 |
1063 BaseTab* TabStrip::GetTabAt(BaseTab* tab, | 1063 BaseTab* TabStrip::GetTabAt(BaseTab* tab, |
1064 const gfx::Point& tab_in_tab_coordinates) { | 1064 const gfx::Point& tab_in_tab_coordinates) { |
1065 gfx::Point local_point = tab_in_tab_coordinates; | 1065 gfx::Point local_point = tab_in_tab_coordinates; |
1066 ConvertPointToView(tab, this, &local_point); | 1066 ConvertPointToTarget(tab, this, &local_point); |
1067 | 1067 |
1068 views::View* view = GetEventHandlerForPoint(local_point); | 1068 views::View* view = GetEventHandlerForPoint(local_point); |
1069 if (!view) | 1069 if (!view) |
1070 return NULL; // No tab contains the point. | 1070 return NULL; // No tab contains the point. |
1071 | 1071 |
1072 // Walk up the view hierarchy until we find a tab, or the TabStrip. | 1072 // Walk up the view hierarchy until we find a tab, or the TabStrip. |
1073 while (view && view != this && view->id() != VIEW_ID_TAB) | 1073 while (view && view != this && view->id() != VIEW_ID_TAB) |
1074 view = view->parent(); | 1074 view = view->parent(); |
1075 | 1075 |
1076 return view && view->id() == VIEW_ID_TAB ? static_cast<BaseTab*>(view) : NULL; | 1076 return view && view->id() == VIEW_ID_TAB ? static_cast<BaseTab*>(view) : NULL; |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1824 case ui::ET_MOUSE_MOVED: { | 1824 case ui::ET_MOUSE_MOVED: { |
1825 #if !defined(OS_WIN) | 1825 #if !defined(OS_WIN) |
1826 SetLayoutType(TAB_STRIP_LAYOUT_SHRINK, true); | 1826 SetLayoutType(TAB_STRIP_LAYOUT_SHRINK, true); |
1827 break; | 1827 break; |
1828 #endif | 1828 #endif |
1829 // Switch to shrink if the mouse enters and it's not a synthesized event. | 1829 // Switch to shrink if the mouse enters and it's not a synthesized event. |
1830 // We ignore synthesized events as EF_FROM_TOUCH is not necessarily set | 1830 // We ignore synthesized events as EF_FROM_TOUCH is not necessarily set |
1831 // correctly (highlighting the close button doesn't set the flags | 1831 // correctly (highlighting the close button doesn't set the flags |
1832 // correctly). | 1832 // correctly). |
1833 gfx::Point location(event.location()); | 1833 gfx::Point location(event.location()); |
1834 ConvertPointToView(source, this, &location); | 1834 ConvertPointToTarget(source, this, &location); |
1835 if (location == last_mouse_move_location_) | 1835 if (location == last_mouse_move_location_) |
1836 return; // Ignore spurious moves. | 1836 return; // Ignore spurious moves. |
1837 last_mouse_move_location_ = location; | 1837 last_mouse_move_location_ = location; |
1838 if ((event.flags() & ui::EF_FROM_TOUCH) == 0 && | 1838 if ((event.flags() & ui::EF_FROM_TOUCH) == 0 && |
1839 (event.flags() & ui::EF_IS_SYNTHESIZED) == 0) { | 1839 (event.flags() & ui::EF_IS_SYNTHESIZED) == 0) { |
1840 if ((base::TimeTicks::Now() - last_mouse_move_time_).InMilliseconds() < | 1840 if ((base::TimeTicks::Now() - last_mouse_move_time_).InMilliseconds() < |
1841 kMouseMoveTimeMS) { | 1841 kMouseMoveTimeMS) { |
1842 if (mouse_move_count_++ == kMouseMoveCountBeforeConsiderReal) { | 1842 if (mouse_move_count_++ == kMouseMoveCountBeforeConsiderReal) { |
1843 SetLayoutType(TAB_STRIP_LAYOUT_SHRINK, true); | 1843 SetLayoutType(TAB_STRIP_LAYOUT_SHRINK, true); |
1844 // Don't notify the controller here. We only want to commit the | 1844 // Don't notify the controller here. We only want to commit the |
1845 // change to other tabstrips on a release. | 1845 // change to other tabstrips on a release. |
1846 } | 1846 } |
1847 } else { | 1847 } else { |
1848 mouse_move_count_ = 1; | 1848 mouse_move_count_ = 1; |
1849 last_mouse_move_time_ = base::TimeTicks::Now(); | 1849 last_mouse_move_time_ = base::TimeTicks::Now(); |
1850 } | 1850 } |
1851 } else { | 1851 } else { |
1852 last_mouse_move_time_ = base::TimeTicks(); | 1852 last_mouse_move_time_ = base::TimeTicks(); |
1853 } | 1853 } |
1854 break; | 1854 break; |
1855 } | 1855 } |
1856 | 1856 |
1857 case ui::ET_MOUSE_RELEASED: { | 1857 case ui::ET_MOUSE_RELEASED: { |
1858 gfx::Point location(event.location()); | 1858 gfx::Point location(event.location()); |
1859 ConvertPointToView(source, this, &location); | 1859 ConvertPointToTarget(source, this, &location); |
1860 last_mouse_move_location_ = location; | 1860 last_mouse_move_location_ = location; |
1861 | 1861 |
1862 mouse_move_count_ = 0; | 1862 mouse_move_count_ = 0; |
1863 last_mouse_move_time_ = base::TimeTicks(); | 1863 last_mouse_move_time_ = base::TimeTicks(); |
1864 | 1864 |
1865 if ((event.flags() & ui::EF_FROM_TOUCH) == ui::EF_FROM_TOUCH) | 1865 if ((event.flags() & ui::EF_FROM_TOUCH) == ui::EF_FROM_TOUCH) |
1866 SetLayoutType(TAB_STRIP_LAYOUT_STACKED, true); | 1866 SetLayoutType(TAB_STRIP_LAYOUT_STACKED, true); |
1867 else if (reset_to_shrink_on_release_) | 1867 else if (reset_to_shrink_on_release_) |
1868 SetLayoutType(TAB_STRIP_LAYOUT_SHRINK, true); | 1868 SetLayoutType(TAB_STRIP_LAYOUT_SHRINK, true); |
1869 controller_->LayoutTypeMaybeChanged(); | 1869 controller_->LayoutTypeMaybeChanged(); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2290 // ownership of RemoveTabDelegate. | 2290 // ownership of RemoveTabDelegate. |
2291 bounds_animator_.SetAnimationDelegate( | 2291 bounds_animator_.SetAnimationDelegate( |
2292 tab_closing, | 2292 tab_closing, |
2293 new RemoveTabDelegate(this, tab_closing), | 2293 new RemoveTabDelegate(this, tab_closing), |
2294 true); | 2294 true); |
2295 } | 2295 } |
2296 | 2296 |
2297 bool TabStrip::IsPointInTab(Tab* tab, | 2297 bool TabStrip::IsPointInTab(Tab* tab, |
2298 const gfx::Point& point_in_tabstrip_coords) { | 2298 const gfx::Point& point_in_tabstrip_coords) { |
2299 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); | 2299 gfx::Point point_in_tab_coords(point_in_tabstrip_coords); |
2300 View::ConvertPointToView(this, tab, &point_in_tab_coords); | 2300 View::ConvertPointToTarget(this, tab, &point_in_tab_coords); |
2301 return tab->HitTestPoint(point_in_tab_coords); | 2301 return tab->HitTestPoint(point_in_tab_coords); |
2302 } | 2302 } |
2303 | 2303 |
2304 int TabStrip::GetStartXForNormalTabs() const { | 2304 int TabStrip::GetStartXForNormalTabs() const { |
2305 int mini_tab_count = GetMiniTabCount(); | 2305 int mini_tab_count = GetMiniTabCount(); |
2306 if (mini_tab_count == 0) | 2306 if (mini_tab_count == 0) |
2307 return 0; | 2307 return 0; |
2308 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + | 2308 return mini_tab_count * (Tab::GetMiniWidth() + tab_h_offset()) + |
2309 kMiniToNonMiniGap; | 2309 kMiniToNonMiniGap; |
2310 } | 2310 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2360 | 2360 |
2361 int mini_tab_count = GetMiniTabCount(); | 2361 int mini_tab_count = GetMiniTabCount(); |
2362 int normal_count = tab_count() - mini_tab_count; | 2362 int normal_count = tab_count() - mini_tab_count; |
2363 if (normal_count <= 1 || normal_count == mini_tab_count) | 2363 if (normal_count <= 1 || normal_count == mini_tab_count) |
2364 return false; | 2364 return false; |
2365 int x = GetStartXForNormalTabs(); | 2365 int x = GetStartXForNormalTabs(); |
2366 int available_width = width() - x - new_tab_button_width(); | 2366 int available_width = width() - x - new_tab_button_width(); |
2367 return (Tab::GetTouchWidth() * normal_count + | 2367 return (Tab::GetTouchWidth() * normal_count + |
2368 tab_h_offset() * (normal_count - 1)) > available_width; | 2368 tab_h_offset() * (normal_count - 1)) > available_width; |
2369 } | 2369 } |
OLD | NEW |