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

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

Issue 1760743002: Add simple mash context menu support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove chrome delegation; address other comments. Created 4 years, 9 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
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | mash/screenlock/screenlock.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 "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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 view_model_->ideal_bounds(target_index).bottom()) < 496 view_model_->ideal_bounds(target_index).bottom()) <
497 shelf_->PrimaryAxisValue(midpoint_in_view.x(), 497 shelf_->PrimaryAxisValue(midpoint_in_view.x(),
498 midpoint_in_view.y())) { 498 midpoint_in_view.y())) {
499 ++target_index; 499 ++target_index;
500 } 500 }
501 if (current_index != target_index) 501 if (current_index != target_index)
502 model_->Move(current_index, target_index); 502 model_->Move(current_index, target_index);
503 } 503 }
504 504
505 bool ShelfView::IsShowingMenu() const { 505 bool ShelfView::IsShowingMenu() const {
506 return (launcher_menu_runner_.get() && 506 return launcher_menu_runner_.get() && launcher_menu_runner_->IsRunning();
507 launcher_menu_runner_->IsRunning());
508 } 507 }
509 508
510 bool ShelfView::IsShowingOverflowBubble() const { 509 bool ShelfView::IsShowingOverflowBubble() const {
511 return overflow_bubble_.get() && overflow_bubble_->IsShowing(); 510 return overflow_bubble_.get() && overflow_bubble_->IsShowing();
512 } 511 }
513 512
514 views::View* ShelfView::GetAppListButtonView() const { 513 views::View* ShelfView::GetAppListButtonView() const {
515 for (int i = 0; i < model_->item_count(); ++i) { 514 for (int i = 0; i < model_->item_count(); ++i) {
516 if (model_->items()[i].type == TYPE_APP_LIST) 515 if (model_->items()[i].type == TYPE_APP_LIST)
517 return view_model_->view_at(i); 516 return view_model_->view_at(i);
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 ->ItemSelected(event); 1755 ->ItemSelected(event);
1757 1756
1758 shelf_button_pressed_metric_tracker_.ButtonPressed(event, sender, 1757 shelf_button_pressed_metric_tracker_.ButtonPressed(event, sender,
1759 performed_action); 1758 performed_action);
1760 1759
1761 if (performed_action != ShelfItemDelegate::kNewWindowCreated) 1760 if (performed_action != ShelfItemDelegate::kNewWindowCreated)
1762 ShowListMenuForView(model_->items()[view_index], sender, event); 1761 ShowListMenuForView(model_->items()[view_index], sender, event);
1763 } 1762 }
1764 } 1763 }
1765 1764
1766 bool ShelfView::ShowListMenuForView(const ShelfItem& item, 1765 void ShelfView::ShowListMenuForView(const ShelfItem& item,
1767 views::View* source, 1766 views::View* source,
1768 const ui::Event& event) { 1767 const ui::Event& event) {
1769 ShelfItemDelegate* item_delegate = 1768 ShelfItemDelegate* item_delegate =
1770 item_manager_->GetShelfItemDelegate(item.id); 1769 item_manager_->GetShelfItemDelegate(item.id);
1771 scoped_ptr<ui::MenuModel> list_menu_model( 1770 scoped_ptr<ui::MenuModel> list_menu_model(
1772 item_delegate->CreateApplicationMenu(event.flags())); 1771 item_delegate->CreateApplicationMenu(event.flags()));
1773 1772
1774 // Make sure we have a menu and it has at least two items in addition to the 1773 // Make sure we have a menu and it has at least two items in addition to the
1775 // application title and the 3 spacing separators. 1774 // application title and the 3 spacing separators.
1776 if (!list_menu_model.get() || list_menu_model->GetItemCount() <= 5) 1775 if (!list_menu_model.get() || list_menu_model->GetItemCount() <= 5)
1777 return false; 1776 return;
1778 1777
1779 ShowMenu(list_menu_model.get(), 1778 context_menu_id_ = item.id;
1780 source, 1779 ShowMenu(list_menu_model.get(), source, gfx::Point(), false,
1781 gfx::Point(),
1782 false,
1783 ui::GetMenuSourceTypeForEvent(event)); 1780 ui::GetMenuSourceTypeForEvent(event));
1784 return true;
1785 } 1781 }
1786 1782
1787 void ShelfView::ShowContextMenuForView(views::View* source, 1783 void ShelfView::ShowContextMenuForView(views::View* source,
1788 const gfx::Point& point, 1784 const gfx::Point& point,
1789 ui::MenuSourceType source_type) { 1785 ui::MenuSourceType source_type) {
1790 int view_index = view_model_->GetIndexOfView(source); 1786 const ShelfItem* item = ShelfItemForView(source);
1791 if (view_index == -1) { 1787 if (!item) {
1792 Shell::GetInstance()->ShowContextMenu(point, source_type); 1788 Shell::GetInstance()->ShowContextMenu(point, source_type);
1793 return; 1789 return;
1794 } 1790 }
1795 1791
1796 context_menu_model_.reset(Shell::GetInstance()->delegate()->CreateContextMenu( 1792 scoped_ptr<ui::MenuModel> context_menu_model(
1797 shelf_, &model_->items()[view_index])); 1793 Shell::GetInstance()->delegate()->CreateContextMenu(shelf_, item));
1798 if (!context_menu_model_) 1794 if (!context_menu_model)
1799 return; 1795 return;
1800 1796
1801 base::AutoReset<ShelfID> reseter( 1797 context_menu_id_ = item ? item->id : 0;
1802 &context_menu_id_, 1798 ShowMenu(context_menu_model.get(), source, point, true, source_type);
1803 view_index == -1 ? 0 : model_->items()[view_index].id);
1804
1805 ShowMenu(context_menu_model_.get(),
1806 source,
1807 point,
1808 true,
1809 source_type);
1810 } 1799 }
1811 1800
1812 void ShelfView::ShowMenu(ui::MenuModel* menu_model, 1801 void ShelfView::ShowMenu(ui::MenuModel* menu_model,
1813 views::View* source, 1802 views::View* source,
1814 const gfx::Point& click_point, 1803 const gfx::Point& click_point,
1815 bool context_menu, 1804 bool context_menu,
1816 ui::MenuSourceType source_type) { 1805 ui::MenuSourceType source_type) {
1817 closing_event_time_ = base::TimeDelta(); 1806 closing_event_time_ = base::TimeDelta();
1818 launcher_menu_runner_.reset(new views::MenuRunner( 1807 launcher_menu_runner_.reset(new views::MenuRunner(
1819 menu_model, context_menu ? views::MenuRunner::CONTEXT_MENU : 0)); 1808 menu_model, context_menu ? views::MenuRunner::CONTEXT_MENU : 0));
1820 1809
1821 ScopedTargetRootWindow scoped_target( 1810 aura::Window* window = source->GetWidget()->GetNativeWindow();
1822 source->GetWidget()->GetNativeView()->GetRootWindow()); 1811 ScopedTargetRootWindow scoped_target(window->GetRootWindow());
1823 1812
1824 // Determine the menu alignment dependent on the shelf.
1825 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; 1813 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT;
1826 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size()); 1814 gfx::Rect anchor = gfx::Rect(click_point, gfx::Size());
1827 1815
1828 if (!context_menu) { 1816 if (!context_menu) {
1829 // Application lists use a bubble. 1817 // Application lists use a bubble.
1830 ShelfAlignment align = shelf_->alignment();
1831 anchor_point = source->GetBoundsInScreen();
1832
1833 // It is possible to invoke the menu while it is sliding into view. To cover 1818 // It is possible to invoke the menu while it is sliding into view. To cover
1834 // that case, the screen coordinates are offsetted by the animation delta. 1819 // that case, the screen coordinates are offsetted by the animation delta.
1835 gfx::Vector2d offset = 1820 anchor = source->GetBoundsInScreen() +
1836 source->GetWidget()->GetNativeWindow()->bounds().origin() - 1821 (window->GetTargetBounds().origin() - window->bounds().origin());
1837 source->GetWidget()->GetNativeWindow()->GetTargetBounds().origin();
1838 anchor_point.set_x(anchor_point.x() - offset.x());
1839 anchor_point.set_y(anchor_point.y() - offset.y());
1840 1822
1841 // Shelf items can have an asymmetrical border for spacing reasons. 1823 // Adjust the anchor location for shelf items with asymmetrical borders.
1842 // Adjust anchor location for this.
1843 if (source->border()) 1824 if (source->border())
1844 anchor_point.Inset(source->border()->GetInsets()); 1825 anchor.Inset(source->border()->GetInsets());
1845 1826
1846 switch (align) { 1827 // Determine the menu alignment dependent on the shelf.
1847 case SHELF_ALIGNMENT_BOTTOM: 1828 menu_alignment = shelf_->SelectValueForShelfAlignment(
1848 menu_alignment = views::MENU_ANCHOR_BUBBLE_ABOVE; 1829 views::MENU_ANCHOR_BUBBLE_ABOVE, views::MENU_ANCHOR_BUBBLE_RIGHT,
1849 break; 1830 views::MENU_ANCHOR_BUBBLE_LEFT, views::MENU_ANCHOR_BUBBLE_BELOW);
1850 case SHELF_ALIGNMENT_LEFT:
1851 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT;
1852 break;
1853 case SHELF_ALIGNMENT_RIGHT:
1854 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT;
1855 break;
1856 case SHELF_ALIGNMENT_TOP:
1857 menu_alignment = views::MENU_ANCHOR_BUBBLE_BELOW;
1858 break;
1859 }
1860 } 1831 }
1861 // If this gets deleted while we are in the menu, the shelf will be gone 1832 // If this is deleted while the menu is running, the shelf will also be gone.
1862 // as well.
1863 bool got_deleted = false; 1833 bool got_deleted = false;
1864 got_deleted_ = &got_deleted; 1834 got_deleted_ = &got_deleted;
1865 1835
1866 ShelfWidget* shelf_widget = shelf_->shelf_widget(); 1836 ShelfWidget* shelf_widget = shelf_->shelf_widget();
1867 shelf_widget->ForceUndimming(true); 1837 shelf_widget->ForceUndimming(true);
1868 // NOTE: if you convert to HAS_MNEMONICS be sure and update menu building 1838 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code.
1869 // code. 1839 if (launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor,
1870 if (launcher_menu_runner_->RunMenuAt(source->GetWidget(), 1840 menu_alignment, source_type) ==
1871 NULL,
1872 anchor_point,
1873 menu_alignment,
1874 source_type) ==
1875 views::MenuRunner::MENU_DELETED) { 1841 views::MenuRunner::MENU_DELETED) {
1876 if (!got_deleted) { 1842 if (!got_deleted) {
sky 2016/03/21 16:55:57 I don't understand why we have this branch at all.
msw 2016/03/21 17:05:47 Acknowledged.
1877 got_deleted_ = NULL; 1843 got_deleted_ = nullptr;
1844 context_menu_id_ = 0;
1878 shelf_widget->ForceUndimming(false); 1845 shelf_widget->ForceUndimming(false);
1879 } 1846 }
1880 return; 1847 return;
1881 } 1848 }
1882 got_deleted_ = NULL; 1849 got_deleted_ = nullptr;
1850 context_menu_id_ = 0;
1883 shelf_widget->ForceUndimming(false); 1851 shelf_widget->ForceUndimming(false);
1884 1852
1885 // If it is a context menu and we are showing overflow bubble 1853 // Hide the hide overflow bubble after showing a context menu for its items.
1886 // we want to hide overflow bubble.
1887 if (owner_overflow_bubble_) 1854 if (owner_overflow_bubble_)
1888 owner_overflow_bubble_->HideBubbleAndRefreshButton(); 1855 owner_overflow_bubble_->HideBubbleAndRefreshButton();
1889 1856
1890 // Unpinning an item will reset the |launcher_menu_runner_| before coming 1857 // Unpinning an item will reset |launcher_menu_runner_| before coming here.
1891 // here.
1892 if (launcher_menu_runner_) 1858 if (launcher_menu_runner_)
1893 closing_event_time_ = launcher_menu_runner_->closing_event_time(); 1859 closing_event_time_ = launcher_menu_runner_->closing_event_time();
1894 Shell::GetInstance()->UpdateShelfVisibility(); 1860 Shell::GetInstance()->UpdateShelfVisibility();
1895 } 1861 }
1896 1862
1897 void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) { 1863 void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) {
1898 FOR_EACH_OBSERVER(ShelfIconObserver, observers_, 1864 FOR_EACH_OBSERVER(ShelfIconObserver, observers_,
1899 OnShelfIconPositionsChanged()); 1865 OnShelfIconPositionsChanged());
1900 PreferredSizeChanged(); 1866 PreferredSizeChanged();
1901 } 1867 }
(...skipping 25 matching lines...) Expand all
1927 1893
1928 base::TimeDelta delta = 1894 base::TimeDelta delta =
1929 base::TimeDelta(event.time_stamp() - closing_event_time_); 1895 base::TimeDelta(event.time_stamp() - closing_event_time_);
1930 closing_event_time_ = base::TimeDelta(); 1896 closing_event_time_ = base::TimeDelta();
1931 // If the current (press down) event is a repost event, the time stamp of 1897 // If the current (press down) event is a repost event, the time stamp of
1932 // these two events should be the same. 1898 // these two events should be the same.
1933 return (delta.InMilliseconds() == 0); 1899 return (delta.InMilliseconds() == 0);
1934 } 1900 }
1935 1901
1936 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const { 1902 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const {
1937 int view_index = view_model_->GetIndexOfView(view); 1903 const int view_index = view_model_->GetIndexOfView(view);
1938 if (view_index == -1) 1904 return (view_index < 0) ? nullptr : &(model_->items()[view_index]);
1939 return NULL;
1940 return &(model_->items()[view_index]);
1941 } 1905 }
1942 1906
1943 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const { 1907 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const {
1944 if (view == GetAppListButtonView() && 1908 if (view == GetAppListButtonView() &&
1945 Shell::GetInstance()->GetAppListWindow()) 1909 Shell::GetInstance()->GetAppListWindow())
1946 return false; 1910 return false;
1947 const ShelfItem* item = ShelfItemForView(view); 1911 const ShelfItem* item = ShelfItemForView(view);
1948 if (!item) 1912 if (!item)
1949 return true; 1913 return true;
1950 ShelfItemDelegate* item_delegate = 1914 ShelfItemDelegate* item_delegate =
1951 item_manager_->GetShelfItemDelegate(item->id); 1915 item_manager_->GetShelfItemDelegate(item->id);
1952 return item_delegate->ShouldShowTooltip(); 1916 return item_delegate->ShouldShowTooltip();
1953 } 1917 }
1954 1918
1955 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1919 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1956 const gfx::Rect bounds = GetBoundsInScreen(); 1920 const gfx::Rect bounds = GetBoundsInScreen();
1957 int distance = shelf_->SelectValueForShelfAlignment( 1921 int distance = shelf_->SelectValueForShelfAlignment(
1958 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1922 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1959 bounds.x() - coordinate.x(), coordinate.y() - bounds.bottom()); 1923 bounds.x() - coordinate.x(), coordinate.y() - bounds.bottom());
1960 return distance > 0 ? distance : 0; 1924 return distance > 0 ? distance : 0;
1961 } 1925 }
1962 1926
1963 } // namespace ash 1927 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | mash/screenlock/screenlock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698