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

Side by Side Diff: ash/shelf/shelf_view.cc

Issue 338833008: Require the cursor to move a minimum distance after the mouse press before initiating a mouse drag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('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 "ash/shelf/shelf_view.h" 5 #include "ash/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 ShelfLayoutManager* manager) 372 ShelfLayoutManager* manager)
373 : model_(model), 373 : model_(model),
374 delegate_(delegate), 374 delegate_(delegate),
375 view_model_(new views::ViewModel), 375 view_model_(new views::ViewModel),
376 first_visible_index_(0), 376 first_visible_index_(0),
377 last_visible_index_(-1), 377 last_visible_index_(-1),
378 overflow_button_(NULL), 378 overflow_button_(NULL),
379 owner_overflow_bubble_(NULL), 379 owner_overflow_bubble_(NULL),
380 drag_pointer_(NONE), 380 drag_pointer_(NONE),
381 drag_view_(NULL), 381 drag_view_(NULL),
382 drag_offset_(0),
383 start_drag_index_(-1), 382 start_drag_index_(-1),
384 context_menu_id_(0), 383 context_menu_id_(0),
385 leading_inset_(kDefaultLeadingInset), 384 leading_inset_(kDefaultLeadingInset),
386 cancelling_drag_model_changed_(false), 385 cancelling_drag_model_changed_(false),
387 last_hidden_index_(0), 386 last_hidden_index_(0),
388 closing_event_time_(base::TimeDelta()), 387 closing_event_time_(base::TimeDelta()),
389 got_deleted_(NULL), 388 got_deleted_(NULL),
390 drag_and_drop_item_pinned_(false), 389 drag_and_drop_item_pinned_(false),
391 drag_and_drop_shelf_id_(0), 390 drag_and_drop_shelf_id_(0),
392 dragged_off_shelf_(false), 391 dragged_off_shelf_(false),
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 int first_drag_index = indices.first; 962 int first_drag_index = indices.first;
964 int last_drag_index = indices.second; 963 int last_drag_index = indices.second;
965 // If the last index isn't valid, we're overflowing. Constrain to the app list 964 // If the last index isn't valid, we're overflowing. Constrain to the app list
966 // (which is the last visible item). 965 // (which is the last visible item).
967 if (first_drag_index < model_->FirstPanelIndex() && 966 if (first_drag_index < model_->FirstPanelIndex() &&
968 last_drag_index > last_visible_index_) 967 last_drag_index > last_visible_index_)
969 last_drag_index = last_visible_index_; 968 last_drag_index = last_visible_index_;
970 int x = 0, y = 0; 969 int x = 0, y = 0;
971 if (layout_manager_->IsHorizontalAlignment()) { 970 if (layout_manager_->IsHorizontalAlignment()) {
972 x = std::max(view_model_->ideal_bounds(indices.first).x(), 971 x = std::max(view_model_->ideal_bounds(indices.first).x(),
973 drag_point.x() - drag_offset_); 972 drag_point.x() - drag_origin_.x());
974 x = std::min(view_model_->ideal_bounds(last_drag_index).right() - 973 x = std::min(view_model_->ideal_bounds(last_drag_index).right() -
975 view_model_->ideal_bounds(current_index).width(), 974 view_model_->ideal_bounds(current_index).width(),
976 x); 975 x);
977 if (drag_view_->x() == x) 976 if (drag_view_->x() == x)
978 return; 977 return;
979 drag_view_->SetX(x); 978 drag_view_->SetX(x);
980 } else { 979 } else {
981 y = std::max(view_model_->ideal_bounds(indices.first).y(), 980 y = std::max(view_model_->ideal_bounds(indices.first).y(),
982 drag_point.y() - drag_offset_); 981 drag_point.y() - drag_origin_.y());
983 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() - 982 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() -
984 view_model_->ideal_bounds(current_index).height(), 983 view_model_->ideal_bounds(current_index).height(),
985 y); 984 y);
986 if (drag_view_->y() == y) 985 if (drag_view_->y() == y)
987 return; 986 return;
988 drag_view_->SetY(y); 987 drag_view_->SetY(y);
989 } 988 }
990 989
991 int target_index = 990 int target_index =
992 views::ViewModelUtils::DetermineMoveIndex( 991 views::ViewModelUtils::DetermineMoveIndex(
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 int index = view_model_->GetIndexOfView(view); 1566 int index = view_model_->GetIndexOfView(view);
1568 if (index == -1) 1567 if (index == -1)
1569 return; 1568 return;
1570 1569
1571 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( 1570 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1572 model_->items()[index].id); 1571 model_->items()[index].id);
1573 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable()) 1572 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable())
1574 return; // View is being deleted or not draggable, ignore request. 1573 return; // View is being deleted or not draggable, ignore request.
1575 1574
1576 drag_view_ = view; 1575 drag_view_ = view;
1577 drag_offset_ = layout_manager_->PrimaryAxisValue(event.x(), event.y()); 1576 drag_origin_ = gfx::Point(event.x(), event.y());
1578 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", 1577 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage",
1579 layout_manager_->SelectValueForShelfAlignment( 1578 layout_manager_->SelectValueForShelfAlignment(
1580 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, 1579 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM,
1581 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, 1580 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT,
1582 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT, 1581 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT,
1583 -1), 1582 -1),
1584 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); 1583 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT);
1585 } 1584 }
1586 1585
1587 void ShelfView::PointerDraggedOnButton(views::View* view, 1586 void ShelfView::PointerDraggedOnButton(views::View* view,
1588 Pointer pointer, 1587 Pointer pointer,
1589 const ui::LocatedEvent& event) { 1588 const ui::LocatedEvent& event) {
1590 // To prepare all drag types (moving an item in the shelf and dragging off), 1589 // To prepare all drag types (moving an item in the shelf and dragging off),
1591 // we should check the x-axis and y-axis offset. 1590 // we should check the x-axis and y-axis offset.
1592 if (!dragging() && drag_view_ && 1591 if (!dragging() && drag_view_ &&
1593 ((std::abs(event.x() - drag_offset_) >= kMinimumDragDistance) || 1592 ((std::abs(event.x() - drag_origin_.x()) >= kMinimumDragDistance) ||
1594 (std::abs(event.y() - drag_offset_) >= kMinimumDragDistance))) { 1593 (std::abs(event.y() - drag_origin_.y()) >= kMinimumDragDistance))) {
1595 PrepareForDrag(pointer, event); 1594 PrepareForDrag(pointer, event);
1596 } 1595 }
1597 if (drag_pointer_ == pointer) 1596 if (drag_pointer_ == pointer)
1598 ContinueDrag(event); 1597 ContinueDrag(event);
1599 } 1598 }
1600 1599
1601 void ShelfView::PointerReleasedOnButton(views::View* view, 1600 void ShelfView::PointerReleasedOnButton(views::View* view,
1602 Pointer pointer, 1601 Pointer pointer,
1603 bool canceled) { 1602 bool canceled) {
1604 if (canceled) { 1603 if (canceled) {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 distance = bounds.x() - coordinate.x(); 1917 distance = bounds.x() - coordinate.x();
1919 break; 1918 break;
1920 case SHELF_ALIGNMENT_TOP: 1919 case SHELF_ALIGNMENT_TOP:
1921 distance = coordinate.y() - bounds.bottom(); 1920 distance = coordinate.y() - bounds.bottom();
1922 break; 1921 break;
1923 } 1922 }
1924 return distance > 0 ? distance : 0; 1923 return distance > 0 ? distance : 0;
1925 } 1924 }
1926 1925
1927 } // namespace ash 1926 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698