Chromium Code Reviews| 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 "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 Loading... | |
| 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_repost_event_(false), | |
| 394 last_index_at_repost_(-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 Loading... | |
| 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 (IsRepostEvent(event)) | |
| 1577 is_repost_event_ = true; | |
|
Mr4D (OOO till 08-26)
2014/12/05 20:57:13
As stated above: You might want to do
is_repost_e
| |
| 1578 | |
| 1574 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); | 1579 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); |
| 1575 drag_view_ = static_cast<ShelfButton*>(view); | 1580 drag_view_ = static_cast<ShelfButton*>(view); |
| 1576 drag_origin_ = gfx::Point(event.x(), event.y()); | 1581 drag_origin_ = gfx::Point(event.x(), event.y()); |
| 1577 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", | 1582 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", |
| 1578 layout_manager_->SelectValueForShelfAlignment( | 1583 layout_manager_->SelectValueForShelfAlignment( |
| 1579 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, | 1584 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, |
| 1580 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, | 1585 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, |
| 1581 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT, | 1586 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT, |
| 1582 -1), | 1587 -1), |
| 1583 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); | 1588 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1656 if (sender == overflow_button_) { | 1661 if (sender == overflow_button_) { |
| 1657 ToggleOverflowBubble(); | 1662 ToggleOverflowBubble(); |
| 1658 return; | 1663 return; |
| 1659 } | 1664 } |
| 1660 | 1665 |
| 1661 int view_index = view_model_->GetIndexOfView(sender); | 1666 int view_index = view_model_->GetIndexOfView(sender); |
| 1662 // May be -1 while in the process of animating closed. | 1667 // May be -1 while in the process of animating closed. |
| 1663 if (view_index == -1) | 1668 if (view_index == -1) |
| 1664 return; | 1669 return; |
| 1665 | 1670 |
| 1666 // If the previous menu was closed by the same event as this one, we ignore | 1671 // If the menu was just closed by the same event as this one, we ignore |
| 1667 // the call. | 1672 // the call and don't open the menu again. See crbug.com/343005 for more |
| 1668 if (!IsUsableEvent(event)) | 1673 // detail. |
| 1674 if (is_repost_event_ && (view_index == last_index_at_repost_)) { | |
|
Mr4D (OOO till 08-26)
2014/12/05 20:57:13
line 1674 - 1683 could then be replaced with this:
| |
| 1675 is_repost_event_ = false; | |
| 1669 return; | 1676 return; |
| 1677 } | |
| 1678 | |
| 1679 // Reset the |is_repost_event_ | to false and record the | |
| 1680 // |last_index_at_repost_|. | |
| 1681 is_repost_event_ = false; | |
| 1682 last_index_at_repost_ = view_index; | |
| 1670 | 1683 |
| 1671 // Don't activate the item twice on double-click. Otherwise the window starts | 1684 // 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 | 1685 // 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 | 1686 // the second click. The user most likely intended to open or minimize the |
| 1674 // item once, not do both. | 1687 // item once, not do both. |
| 1675 if (event.flags() & ui::EF_IS_DOUBLE_CLICK) | 1688 if (event.flags() & ui::EF_IS_DOUBLE_CLICK) |
| 1676 return; | 1689 return; |
| 1677 | 1690 |
| 1678 { | 1691 { |
| 1679 ScopedTargetRootWindow scoped_target( | 1692 ScopedTargetRootWindow scoped_target( |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1870 ShelfButton* button = static_cast<ShelfButton*>(view); | 1883 ShelfButton* button = static_cast<ShelfButton*>(view); |
| 1871 button->ClearState(ShelfButton::STATE_HIDDEN); | 1884 button->ClearState(ShelfButton::STATE_HIDDEN); |
| 1872 break; | 1885 break; |
| 1873 } | 1886 } |
| 1874 } | 1887 } |
| 1875 snap_back_from_rip_off_view_ = NULL; | 1888 snap_back_from_rip_off_view_ = NULL; |
| 1876 } | 1889 } |
| 1877 } | 1890 } |
| 1878 } | 1891 } |
| 1879 | 1892 |
| 1880 bool ShelfView::IsUsableEvent(const ui::Event& event) { | 1893 bool ShelfView::IsRepostEvent(const ui::Event& event) { |
| 1881 if (closing_event_time_ == base::TimeDelta()) | 1894 if (closing_event_time_ == base::TimeDelta()) |
| 1882 return true; | 1895 return false; |
| 1883 | 1896 |
| 1884 base::TimeDelta delta = | 1897 base::TimeDelta delta = |
| 1885 base::TimeDelta(event.time_stamp() - closing_event_time_); | 1898 base::TimeDelta(event.time_stamp() - closing_event_time_); |
| 1886 closing_event_time_ = base::TimeDelta(); | 1899 closing_event_time_ = base::TimeDelta(); |
| 1887 // TODO(skuhne): This time seems excessive, but it appears that the reposting | 1900 // If the current (press down) event is a repost event, the time stamp of |
| 1888 // takes that long. Need to come up with a better way of doing this. | 1901 // these two events should be the same. |
| 1889 return (delta.InMilliseconds() < 0 || delta.InMilliseconds() > 130); | 1902 return (delta.InMilliseconds() == 0); |
| 1890 } | 1903 } |
| 1891 | 1904 |
| 1892 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const { | 1905 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const { |
| 1893 int view_index = view_model_->GetIndexOfView(view); | 1906 int view_index = view_model_->GetIndexOfView(view); |
| 1894 if (view_index == -1) | 1907 if (view_index == -1) |
| 1895 return NULL; | 1908 return NULL; |
| 1896 return &(model_->items()[view_index]); | 1909 return &(model_->items()[view_index]); |
| 1897 } | 1910 } |
| 1898 | 1911 |
| 1899 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const { | 1912 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1925 distance = bounds.x() - coordinate.x(); | 1938 distance = bounds.x() - coordinate.x(); |
| 1926 break; | 1939 break; |
| 1927 case SHELF_ALIGNMENT_TOP: | 1940 case SHELF_ALIGNMENT_TOP: |
| 1928 distance = coordinate.y() - bounds.bottom(); | 1941 distance = coordinate.y() - bounds.bottom(); |
| 1929 break; | 1942 break; |
| 1930 } | 1943 } |
| 1931 return distance > 0 ? distance : 0; | 1944 return distance > 0 ? distance : 0; |
| 1932 } | 1945 } |
| 1933 | 1946 |
| 1934 } // namespace ash | 1947 } // namespace ash |
| OLD | NEW |