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

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

Issue 295903006: Retain the menu models in the class along with the menu runner. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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') | no next file » | 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 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 ShelfItemDelegate* item_delegate = 1699 ShelfItemDelegate* item_delegate =
1700 item_manager_->GetShelfItemDelegate(model_->items()[view_index].id); 1700 item_manager_->GetShelfItemDelegate(model_->items()[view_index].id);
1701 if (!item_delegate->ItemSelected(event)) 1701 if (!item_delegate->ItemSelected(event))
1702 ShowListMenuForView(model_->items()[view_index], sender, event); 1702 ShowListMenuForView(model_->items()[view_index], sender, event);
1703 } 1703 }
1704 } 1704 }
1705 1705
1706 bool ShelfView::ShowListMenuForView(const ShelfItem& item, 1706 bool ShelfView::ShowListMenuForView(const ShelfItem& item,
1707 views::View* source, 1707 views::View* source,
1708 const ui::Event& event) { 1708 const ui::Event& event) {
1709 scoped_ptr<ShelfMenuModel> menu_model;
1710 ShelfItemDelegate* item_delegate = 1709 ShelfItemDelegate* item_delegate =
1711 item_manager_->GetShelfItemDelegate(item.id); 1710 item_manager_->GetShelfItemDelegate(item.id);
1712 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags())); 1711 list_menu_model_.reset(item_delegate->CreateApplicationMenu(event.flags()));
1713 1712
1714 // Make sure we have a menu and it has at least two items in addition to the 1713 // Make sure we have a menu and it has at least two items in addition to the
1715 // application title and the 3 spacing separators. 1714 // application title and the 3 spacing separators.
1716 if (!menu_model.get() || menu_model->GetItemCount() <= 5) 1715 if (!list_menu_model_.get() || list_menu_model_->GetItemCount() <= 5)
1717 return false; 1716 return false;
1718 1717
1719 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1718 ShowMenu(list_menu_model_.get(),
1720 new ShelfMenuModelAdapter(menu_model.get())),
1721 source, 1719 source,
1722 gfx::Point(), 1720 gfx::Point(),
1723 false, 1721 false,
1724 ui::GetMenuSourceTypeForEvent(event)); 1722 ui::GetMenuSourceTypeForEvent(event));
1725 return true; 1723 return true;
1726 } 1724 }
1727 1725
1728 void ShelfView::ShowContextMenuForView(views::View* source, 1726 void ShelfView::ShowContextMenuForView(views::View* source,
1729 const gfx::Point& point, 1727 const gfx::Point& point,
1730 ui::MenuSourceType source_type) { 1728 ui::MenuSourceType source_type) {
1731 int view_index = view_model_->GetIndexOfView(source); 1729 int view_index = view_model_->GetIndexOfView(source);
1732 if (view_index == -1) { 1730 if (view_index == -1) {
1733 Shell::GetInstance()->ShowContextMenu(point, source_type); 1731 Shell::GetInstance()->ShowContextMenu(point, source_type);
1734 return; 1732 return;
1735 } 1733 }
1736 1734
1737 scoped_ptr<ui::MenuModel> menu_model;
1738 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( 1735 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1739 model_->items()[view_index].id); 1736 model_->items()[view_index].id);
1740 menu_model.reset(item_delegate->CreateContextMenu( 1737 context_menu_model_.reset(item_delegate->CreateContextMenu(
1741 source->GetWidget()->GetNativeView()->GetRootWindow())); 1738 source->GetWidget()->GetNativeView()->GetRootWindow()));
1742 if (!menu_model) 1739 if (!context_menu_model_)
1743 return; 1740 return;
1744 1741
1745 base::AutoReset<ShelfID> reseter( 1742 base::AutoReset<ShelfID> reseter(
1746 &context_menu_id_, 1743 &context_menu_id_,
1747 view_index == -1 ? 0 : model_->items()[view_index].id); 1744 view_index == -1 ? 0 : model_->items()[view_index].id);
1748 1745
1749 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1746 ShowMenu(context_menu_model_.get(),
1750 new views::MenuModelAdapter(menu_model.get())),
1751 source, 1747 source,
1752 point, 1748 point,
1753 true, 1749 true,
1754 source_type); 1750 source_type);
1755 } 1751 }
1756 1752
1757 void ShelfView::ShowMenu(scoped_ptr<views::MenuModelAdapter> menu_model_adapter, 1753 void ShelfView::ShowMenu(ui::MenuModel* menu_model,
1758 views::View* source, 1754 views::View* source,
1759 const gfx::Point& click_point, 1755 const gfx::Point& click_point,
1760 bool context_menu, 1756 bool context_menu,
1761 ui::MenuSourceType source_type) { 1757 ui::MenuSourceType source_type) {
1762 closing_event_time_ = base::TimeDelta(); 1758 closing_event_time_ = base::TimeDelta();
1763 launcher_menu_runner_.reset( 1759 launcher_menu_runner_.reset(new views::MenuRunner(menu_model));
1764 new views::MenuRunner(menu_model_adapter->CreateMenu()));
1765 1760
1766 ScopedTargetRootWindow scoped_target( 1761 ScopedTargetRootWindow scoped_target(
1767 source->GetWidget()->GetNativeView()->GetRootWindow()); 1762 source->GetWidget()->GetNativeView()->GetRootWindow());
1768 1763
1769 // Determine the menu alignment dependent on the shelf. 1764 // Determine the menu alignment dependent on the shelf.
1770 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT; 1765 views::MenuAnchorPosition menu_alignment = views::MENU_ANCHOR_TOPLEFT;
1771 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size()); 1766 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size());
1772 1767
1773 ShelfWidget* shelf = RootWindowController::ForShelf( 1768 ShelfWidget* shelf = RootWindowController::ForShelf(
1774 GetWidget()->GetNativeView())->shelf(); 1769 GetWidget()->GetNativeView())->shelf();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 distance = bounds.x() - coordinate.x(); 1911 distance = bounds.x() - coordinate.x();
1917 break; 1912 break;
1918 case SHELF_ALIGNMENT_TOP: 1913 case SHELF_ALIGNMENT_TOP:
1919 distance = coordinate.y() - bounds.bottom(); 1914 distance = coordinate.y() - bounds.bottom();
1920 break; 1915 break;
1921 } 1916 }
1922 return distance > 0 ? distance : 0; 1917 return distance > 0 ? distance : 0;
1923 } 1918 }
1924 1919
1925 } // namespace ash 1920 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698