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

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

Issue 772963002: Make the second click on the app shelf icon close the window-list bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compare the time stamp when the mouse is pressed down. Created 6 years 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
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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 closing_event_time_(base::TimeDelta()), 382 closing_event_time_(base::TimeDelta()),
383 got_deleted_(NULL), 383 got_deleted_(NULL),
384 drag_and_drop_item_pinned_(false), 384 drag_and_drop_item_pinned_(false),
385 drag_and_drop_shelf_id_(0), 385 drag_and_drop_shelf_id_(0),
386 dragged_off_shelf_(false), 386 dragged_off_shelf_(false),
387 snap_back_from_rip_off_view_(NULL), 387 snap_back_from_rip_off_view_(NULL),
388 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()), 388 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()),
389 layout_manager_(manager), 389 layout_manager_(manager),
390 overflow_mode_(false), 390 overflow_mode_(false),
391 main_shelf_(NULL), 391 main_shelf_(NULL),
392 dragged_off_from_overflow_to_shelf_(false) { 392 dragged_off_from_overflow_to_shelf_(false),
393 is_usable_event_(true),
394 last_view_index_(-1) {
393 DCHECK(model_); 395 DCHECK(model_);
394 bounds_animator_.reset(new views::BoundsAnimator(this)); 396 bounds_animator_.reset(new views::BoundsAnimator(this));
395 bounds_animator_->AddObserver(this); 397 bounds_animator_->AddObserver(this);
396 set_context_menu_controller(this); 398 set_context_menu_controller(this);
397 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); 399 focus_search_.reset(new ShelfFocusSearch(view_model_.get()));
398 tooltip_.reset(new ShelfTooltipManager(manager, this)); 400 tooltip_.reset(new ShelfTooltipManager(manager, this));
399 } 401 }
400 402
401 ShelfView::~ShelfView() { 403 ShelfView::~ShelfView() {
402 bounds_animator_->RemoveObserver(this); 404 bounds_animator_->RemoveObserver(this);
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 1566
1565 int index = view_model_->GetIndexOfView(view); 1567 int index = view_model_->GetIndexOfView(view);
1566 if (index == -1) 1568 if (index == -1)
1567 return; 1569 return;
1568 1570
1569 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( 1571 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1570 model_->items()[index].id); 1572 model_->items()[index].id);
1571 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable()) 1573 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable())
1572 return; // View is being deleted or not draggable, ignore request. 1574 return; // View is being deleted or not draggable, ignore request.
1573 1575
1576 if (!IsUsableEvent(event)) {
Mr4D (OOO till 08-26) 2014/12/05 15:21:47 No {}'s
Mr4D (OOO till 08-26) 2014/12/05 15:21:47 Aha! Nice find! Yes, this is much better then the
1577 is_usable_event_ = false;
1578 }
1579
1574 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); 1580 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName());
1575 drag_view_ = static_cast<ShelfButton*>(view); 1581 drag_view_ = static_cast<ShelfButton*>(view);
1576 drag_origin_ = gfx::Point(event.x(), event.y()); 1582 drag_origin_ = gfx::Point(event.x(), event.y());
1577 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", 1583 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage",
1578 layout_manager_->SelectValueForShelfAlignment( 1584 layout_manager_->SelectValueForShelfAlignment(
1579 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, 1585 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM,
1580 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, 1586 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT,
1581 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT, 1587 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT,
1582 -1), 1588 -1),
1583 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); 1589 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT);
1584 } 1590 }
1585 1591
1586 void ShelfView::PointerDraggedOnButton(views::View* view, 1592 void ShelfView::PointerDraggedOnButton(views::View* view,
1587 Pointer pointer, 1593 Pointer pointer,
1588 const ui::LocatedEvent& event) { 1594 const ui::LocatedEvent& event) {
1589 // To prepare all drag types (moving an item in the shelf and dragging off), 1595 // To prepare all drag types (moving an item in the shelf and dragging off),
1590 // we should check the x-axis and y-axis offset. 1596 // we should check the x-axis and y-axis offset.
1591 if (!dragging() && drag_view_ && 1597 if (!dragging() && drag_view_ &&
1592 ((std::abs(event.x() - drag_origin_.x()) >= kMinimumDragDistance) || 1598 ((std::abs(event.x() - drag_origin_.x()) >= kMinimumDragDistance) ||
1593 (std::abs(event.y() - drag_origin_.y()) >= kMinimumDragDistance))) { 1599 (std::abs(event.y() - drag_origin_.y()) >= kMinimumDragDistance))) {
1594 PrepareForDrag(pointer, event); 1600 PrepareForDrag(pointer, event);
1595 } 1601 }
1596 if (drag_pointer_ == pointer) 1602 if (drag_pointer_ == pointer)
1597 ContinueDrag(event); 1603 ContinueDrag(event);
1598 } 1604 }
1599 1605
1600 void ShelfView::PointerReleasedOnButton(views::View* view, 1606 void ShelfView::PointerReleasedOnButton(views::View* view,
1601 Pointer pointer, 1607 Pointer pointer,
1602 bool canceled) { 1608 bool canceled) {
Mr4D (OOO till 08-26) 2014/12/05 15:21:47 Reset the variable. (Note: If you would not do it
xdai1 2014/12/05 19:01:46 I reset the variable at line 1675 and line 1680. I
Mr4D (OOO till 08-26) 2014/12/05 20:57:13 It's not enough. This could be failing: Click on
1603 if (canceled) { 1609 if (canceled) {
1604 CancelDrag(-1); 1610 CancelDrag(-1);
1605 } else if (drag_pointer_ == pointer) { 1611 } else if (drag_pointer_ == pointer) {
1606 FinalizeRipOffDrag(false); 1612 FinalizeRipOffDrag(false);
1607 drag_pointer_ = NONE; 1613 drag_pointer_ = NONE;
1608 AnimateToIdealBounds(); 1614 AnimateToIdealBounds();
1609 } 1615 }
1610 // If the drag pointer is NONE, no drag operation is going on and the 1616 // If the drag pointer is NONE, no drag operation is going on and the
1611 // drag_view can be released. 1617 // drag_view can be released.
1612 if (drag_pointer_ == NONE) 1618 if (drag_pointer_ == NONE)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 if (sender == overflow_button_) { 1662 if (sender == overflow_button_) {
1657 ToggleOverflowBubble(); 1663 ToggleOverflowBubble();
1658 return; 1664 return;
1659 } 1665 }
1660 1666
1661 int view_index = view_model_->GetIndexOfView(sender); 1667 int view_index = view_model_->GetIndexOfView(sender);
1662 // May be -1 while in the process of animating closed. 1668 // May be -1 while in the process of animating closed.
1663 if (view_index == -1) 1669 if (view_index == -1)
1664 return; 1670 return;
1665 1671
1666 // If the previous menu was closed by the same event as this one, we ignore 1672 // If the menu was just closed by the same event as this one, we ignore
1667 // the call. 1673 // the call. See crbug.com/343005 for more detail.
1668 if (!IsUsableEvent(event)) 1674 if (!is_usable_event_ && (view_index == last_view_index_)) {
Mr4D (OOO till 08-26) 2014/12/05 15:21:47 The index does not need to be checked since we are
xdai1 2014/12/05 19:01:46 I think we still need to check the index because o
1675 is_usable_event_ = true;
1669 return; 1676 return;
1677 }
1678
1679 // Reset the |is_usable_event_| to true and record the |view_index|.
1680 is_usable_event_ = true;
1681 last_view_index_ = view_index;
1670 1682
1671 // Don't activate the item twice on double-click. Otherwise the window starts 1683 // Don't activate the item twice on double-click. Otherwise the window starts
1672 // animating open due to the first click, then immediately minimizes due to 1684 // animating open due to the first click, then immediately minimizes due to
1673 // the second click. The user most likely intended to open or minimize the 1685 // the second click. The user most likely intended to open or minimize the
1674 // item once, not do both. 1686 // item once, not do both.
1675 if (event.flags() & ui::EF_IS_DOUBLE_CLICK) 1687 if (event.flags() & ui::EF_IS_DOUBLE_CLICK)
1676 return; 1688 return;
1677 1689
1678 { 1690 {
1679 ScopedTargetRootWindow scoped_target( 1691 ScopedTargetRootWindow scoped_target(
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 ShelfButton* button = static_cast<ShelfButton*>(view); 1882 ShelfButton* button = static_cast<ShelfButton*>(view);
1871 button->ClearState(ShelfButton::STATE_HIDDEN); 1883 button->ClearState(ShelfButton::STATE_HIDDEN);
1872 break; 1884 break;
1873 } 1885 }
1874 } 1886 }
1875 snap_back_from_rip_off_view_ = NULL; 1887 snap_back_from_rip_off_view_ = NULL;
1876 } 1888 }
1877 } 1889 }
1878 } 1890 }
1879 1891
1880 bool ShelfView::IsUsableEvent(const ui::Event& event) { 1892 bool ShelfView::IsUsableEvent(const ui::Event& event) {
Mr4D (OOO till 08-26) 2014/12/05 15:21:47 Rename to IsRepostEvent() (and negate the logic ac
1881 if (closing_event_time_ == base::TimeDelta()) 1893 if (closing_event_time_ == base::TimeDelta())
1882 return true; 1894 return true;
1883 1895
1884 base::TimeDelta delta = 1896 base::TimeDelta delta =
1885 base::TimeDelta(event.time_stamp() - closing_event_time_); 1897 base::TimeDelta(event.time_stamp() - closing_event_time_);
1886 closing_event_time_ = base::TimeDelta(); 1898 closing_event_time_ = base::TimeDelta();
1887 // TODO(skuhne): This time seems excessive, but it appears that the reposting 1899 // If the current (press down) event is a reposted event, the time stamp of
1888 // takes that long. Need to come up with a better way of doing this. 1900 // these two events should be the same.
1889 return (delta.InMilliseconds() < 0 || delta.InMilliseconds() > 130); 1901 return (delta.InMilliseconds() != 0);
Mr4D (OOO till 08-26) 2014/12/05 15:21:47 Ahhhh! Much better!
1890 } 1902 }
1891 1903
1892 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const { 1904 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const {
1893 int view_index = view_model_->GetIndexOfView(view); 1905 int view_index = view_model_->GetIndexOfView(view);
1894 if (view_index == -1) 1906 if (view_index == -1)
1895 return NULL; 1907 return NULL;
1896 return &(model_->items()[view_index]); 1908 return &(model_->items()[view_index]);
1897 } 1909 }
1898 1910
1899 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const { 1911 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const {
(...skipping 25 matching lines...) Expand all
1925 distance = bounds.x() - coordinate.x(); 1937 distance = bounds.x() - coordinate.x();
1926 break; 1938 break;
1927 case SHELF_ALIGNMENT_TOP: 1939 case SHELF_ALIGNMENT_TOP:
1928 distance = coordinate.y() - bounds.bottom(); 1940 distance = coordinate.y() - bounds.bottom();
1929 break; 1941 break;
1930 } 1942 }
1931 return distance > 0 ? distance : 0; 1943 return distance > 0 ? distance : 0;
1932 } 1944 }
1933 1945
1934 } // namespace ash 1946 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698