Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 11821036: Fixes couple of bugs in the TabStrip that could cause tabs to dance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/tab_drag_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h" 5 #include "chrome/browser/ui/views/tabs/tab.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 if (!controller()) 860 if (!controller())
861 return false; 861 return false;
862 862
863 controller()->OnMouseEventInTab(this, event); 863 controller()->OnMouseEventInTab(this, event);
864 864
865 // Allow a right click from touch to drag, which corresponds to a long click. 865 // Allow a right click from touch to drag, which corresponds to a long click.
866 if (event.IsOnlyLeftMouseButton() || 866 if (event.IsOnlyLeftMouseButton() ||
867 (event.IsOnlyRightMouseButton() && event.flags() & ui::EF_FROM_TOUCH)) { 867 (event.IsOnlyRightMouseButton() && event.flags() & ui::EF_FROM_TOUCH)) {
868 ui::ListSelectionModel original_selection; 868 ui::ListSelectionModel original_selection;
869 original_selection.Copy(controller()->GetSelectionModel()); 869 original_selection.Copy(controller()->GetSelectionModel());
870 // Changing the selection may cause our bounds to change. If that happens
871 // the location of the event may no longer be valid. Create a copy of the
872 // event in the parents coordinate, which won't change, and recreate an
873 // event after changing so the coordinates are correct.
874 ui::MouseEvent event_in_parent(event, static_cast<View*>(this), parent());
870 if (controller()->SupportsMultipleSelection()) { 875 if (controller()->SupportsMultipleSelection()) {
871 if (event.IsShiftDown() && event.IsControlDown()) { 876 if (event.IsShiftDown() && event.IsControlDown()) {
872 controller()->AddSelectionFromAnchorTo(this); 877 controller()->AddSelectionFromAnchorTo(this);
873 } else if (event.IsShiftDown()) { 878 } else if (event.IsShiftDown()) {
874 controller()->ExtendSelectionTo(this); 879 controller()->ExtendSelectionTo(this);
875 } else if (event.IsControlDown()) { 880 } else if (event.IsControlDown()) {
876 controller()->ToggleSelected(this); 881 controller()->ToggleSelected(this);
877 if (!IsSelected()) { 882 if (!IsSelected()) {
878 // Don't allow dragging non-selected tabs. 883 // Don't allow dragging non-selected tabs.
879 return false; 884 return false;
880 } 885 }
881 } else if (!IsSelected()) { 886 } else if (!IsSelected()) {
882 controller()->SelectTab(this); 887 controller()->SelectTab(this);
883 } 888 }
884 } else if (!IsSelected()) { 889 } else if (!IsSelected()) {
885 controller()->SelectTab(this); 890 controller()->SelectTab(this);
886 } 891 }
887 controller()->MaybeStartDrag(this, event, original_selection); 892 ui::MouseEvent cloned_event(event_in_parent, parent(),
893 static_cast<View*>(this));
894 controller()->MaybeStartDrag(this, cloned_event, original_selection);
888 } 895 }
889 return true; 896 return true;
890 } 897 }
891 898
892 bool Tab::OnMouseDragged(const ui::MouseEvent& event) { 899 bool Tab::OnMouseDragged(const ui::MouseEvent& event) {
893 if (controller()) 900 if (controller())
894 controller()->ContinueDrag(this, event.location()); 901 controller()->ContinueDrag(this, event.location());
895 return true; 902 return true;
896 } 903 }
897 904
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 if (!controller()) { 963 if (!controller()) {
957 event->SetHandled(); 964 event->SetHandled();
958 return; 965 return;
959 } 966 }
960 967
961 switch (event->type()) { 968 switch (event->type()) {
962 case ui::ET_GESTURE_BEGIN: { 969 case ui::ET_GESTURE_BEGIN: {
963 if (event->details().touch_points() != 1) 970 if (event->details().touch_points() != 1)
964 return; 971 return;
965 972
973 // See comment in OnMousePressed() as to why we copy the event.
974 ui::GestureEvent event_in_parent(*event, static_cast<View*>(this),
975 parent());
966 ui::ListSelectionModel original_selection; 976 ui::ListSelectionModel original_selection;
967 original_selection.Copy(controller()->GetSelectionModel()); 977 original_selection.Copy(controller()->GetSelectionModel());
968 if (!IsSelected()) 978 if (!IsSelected())
969 controller()->SelectTab(this); 979 controller()->SelectTab(this);
970 gfx::Point loc(event->location()); 980 gfx::Point loc(event->location());
971 views::View::ConvertPointToScreen(this, &loc); 981 views::View::ConvertPointToScreen(this, &loc);
972 controller()->MaybeStartDrag(this, *event, original_selection); 982 ui::GestureEvent cloned_event(event_in_parent, parent(),
983 static_cast<View*>(this));
984 controller()->MaybeStartDrag(this, cloned_event, original_selection);
973 break; 985 break;
974 } 986 }
975 987
976 case ui::ET_GESTURE_END: 988 case ui::ET_GESTURE_END:
977 controller()->EndDrag(END_DRAG_COMPLETE); 989 controller()->EndDrag(END_DRAG_COMPLETE);
978 break; 990 break;
979 991
980 case ui::ET_GESTURE_SCROLL_UPDATE: 992 case ui::ET_GESTURE_SCROLL_UPDATE:
981 controller()->ContinueDrag(this, event->location()); 993 controller()->ContinueDrag(this, event->location());
982 break; 994 break;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 const gfx::ImageSkia& image) { 1625 const gfx::ImageSkia& image) {
1614 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1626 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1615 ImageCacheEntry entry; 1627 ImageCacheEntry entry;
1616 entry.resource_id = resource_id; 1628 entry.resource_id = resource_id;
1617 entry.scale_factor = scale_factor; 1629 entry.scale_factor = scale_factor;
1618 entry.image = image; 1630 entry.image = image;
1619 image_cache_->push_front(entry); 1631 image_cache_->push_front(entry);
1620 if (image_cache_->size() > kMaxImageCacheSize) 1632 if (image_cache_->size() > kMaxImageCacheSize)
1621 image_cache_->pop_back(); 1633 image_cache_->pop_back();
1622 } 1634 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/tabs/tab_drag_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698