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

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

Issue 97173003: ash: Rename more Launcher classes to Shelf*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: link chrome Created 7 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 | 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"
11 #include "ash/drag_drop/drag_image_view.h" 11 #include "ash/drag_drop/drag_image_view.h"
12 #include "ash/launcher/launcher_delegate.h" 12 #include "ash/launcher/launcher_delegate.h"
13 #include "ash/launcher/launcher_item_delegate.h"
14 #include "ash/launcher/launcher_item_delegate_manager.h"
15 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
16 #include "ash/scoped_target_root_window.h" 14 #include "ash/scoped_target_root_window.h"
17 #include "ash/shelf/alternate_app_list_button.h" 15 #include "ash/shelf/alternate_app_list_button.h"
18 #include "ash/shelf/app_list_button.h" 16 #include "ash/shelf/app_list_button.h"
19 #include "ash/shelf/overflow_bubble.h" 17 #include "ash/shelf/overflow_bubble.h"
20 #include "ash/shelf/overflow_bubble_view.h" 18 #include "ash/shelf/overflow_bubble_view.h"
21 #include "ash/shelf/overflow_button.h" 19 #include "ash/shelf/overflow_button.h"
22 #include "ash/shelf/shelf_button.h" 20 #include "ash/shelf/shelf_button.h"
23 #include "ash/shelf/shelf_icon_observer.h" 21 #include "ash/shelf/shelf_icon_observer.h"
22 #include "ash/shelf/shelf_item_delegate.h"
23 #include "ash/shelf/shelf_item_delegate_manager.h"
24 #include "ash/shelf/shelf_layout_manager.h" 24 #include "ash/shelf/shelf_layout_manager.h"
25 #include "ash/shelf/shelf_menu_model.h"
25 #include "ash/shelf/shelf_model.h" 26 #include "ash/shelf/shelf_model.h"
26 #include "ash/shelf/shelf_tooltip_manager.h" 27 #include "ash/shelf/shelf_tooltip_manager.h"
27 #include "ash/shelf/shelf_widget.h" 28 #include "ash/shelf/shelf_widget.h"
28 #include "ash/shell_delegate.h" 29 #include "ash/shell_delegate.h"
29 #include "ash/wm/coordinate_conversion.h" 30 #include "ash/wm/coordinate_conversion.h"
30 #include "base/auto_reset.h" 31 #include "base/auto_reset.h"
31 #include "base/memory/scoped_ptr.h" 32 #include "base/memory/scoped_ptr.h"
32 #include "base/metrics/histogram.h" 33 #include "base/metrics/histogram.h"
33 #include "grit/ash_resources.h" 34 #include "grit/ash_resources.h"
34 #include "grit/ash_strings.h" 35 #include "grit/ash_strings.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // separates. 112 // separates.
112 const int kRipOffDistance = 48; 113 const int kRipOffDistance = 48;
113 114
114 // The rip off drag and drop proxy image should get scaled by this factor. 115 // The rip off drag and drop proxy image should get scaled by this factor.
115 const float kDragAndDropProxyScale = 1.5f; 116 const float kDragAndDropProxyScale = 1.5f;
116 117
117 namespace { 118 namespace {
118 119
119 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to 120 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to
120 // our requirements. 121 // our requirements.
121 class LauncherMenuModelAdapter 122 class ShelfMenuModelAdapter : public views::MenuModelAdapter {
122 : public views::MenuModelAdapter {
123 public: 123 public:
124 explicit LauncherMenuModelAdapter(ash::LauncherMenuModel* menu_model); 124 explicit ShelfMenuModelAdapter(ShelfMenuModel* menu_model);
125 125
126 // Overriding MenuModelAdapter's MenuDelegate implementation. 126 // views::MenuModelAdapter:
127 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE; 127 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE;
128 virtual bool IsCommandEnabled(int id) const OVERRIDE; 128 virtual bool IsCommandEnabled(int id) const OVERRIDE;
129 virtual void GetHorizontalIconMargins(int id, 129 virtual void GetHorizontalIconMargins(int id,
130 int icon_size, 130 int icon_size,
131 int* left_margin, 131 int* left_margin,
132 int* right_margin) const OVERRIDE; 132 int* right_margin) const OVERRIDE;
133 virtual bool GetForegroundColor(int command_id, 133 virtual bool GetForegroundColor(int command_id,
134 bool is_hovered, 134 bool is_hovered,
135 SkColor* override_color) const OVERRIDE; 135 SkColor* override_color) const OVERRIDE;
136 virtual bool GetBackgroundColor(int command_id, 136 virtual bool GetBackgroundColor(int command_id,
137 bool is_hovered, 137 bool is_hovered,
138 SkColor* override_color) const OVERRIDE; 138 SkColor* override_color) const OVERRIDE;
139 virtual int GetMaxWidthForMenu(views::MenuItemView* menu) OVERRIDE; 139 virtual int GetMaxWidthForMenu(views::MenuItemView* menu) OVERRIDE;
140 virtual bool ShouldReserveSpaceForSubmenuIndicator() const OVERRIDE; 140 virtual bool ShouldReserveSpaceForSubmenuIndicator() const OVERRIDE;
141 141
142 private: 142 private:
143 ash::LauncherMenuModel* launcher_menu_model_; 143 ShelfMenuModel* menu_model_;
144 144
145 DISALLOW_COPY_AND_ASSIGN(LauncherMenuModelAdapter); 145 DISALLOW_COPY_AND_ASSIGN(ShelfMenuModelAdapter);
146 }; 146 };
147 147
148 LauncherMenuModelAdapter::LauncherMenuModelAdapter( 148 ShelfMenuModelAdapter::ShelfMenuModelAdapter(ShelfMenuModel* menu_model)
149 ash::LauncherMenuModel* menu_model)
150 : MenuModelAdapter(menu_model), 149 : MenuModelAdapter(menu_model),
151 launcher_menu_model_(menu_model) {} 150 menu_model_(menu_model) {
151 }
152 152
153 const gfx::Font* LauncherMenuModelAdapter::GetLabelFont( 153 const gfx::Font* ShelfMenuModelAdapter::GetLabelFont(int command_id) const {
154 int command_id) const {
155 if (command_id != kCommandIdOfMenuName) 154 if (command_id != kCommandIdOfMenuName)
156 return MenuModelAdapter::GetLabelFont(command_id); 155 return MenuModelAdapter::GetLabelFont(command_id);
157 156
158 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 157 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
159 return &rb.GetFont(ui::ResourceBundle::BoldFont); 158 return &rb.GetFont(ui::ResourceBundle::BoldFont);
160 } 159 }
161 160
162 bool LauncherMenuModelAdapter::IsCommandEnabled(int id) const { 161 bool ShelfMenuModelAdapter::IsCommandEnabled(int id) const {
163 return id != kCommandIdOfMenuName; 162 return id != kCommandIdOfMenuName;
164 } 163 }
165 164
166 bool LauncherMenuModelAdapter::GetForegroundColor( 165 bool ShelfMenuModelAdapter::GetForegroundColor(int command_id,
167 int command_id, 166 bool is_hovered,
168 bool is_hovered, 167 SkColor* override_color) const {
169 SkColor* override_color) const {
170 if (command_id != kCommandIdOfMenuName) 168 if (command_id != kCommandIdOfMenuName)
171 return false; 169 return false;
172 170
173 *override_color = kCaptionItemForegroundColor; 171 *override_color = kCaptionItemForegroundColor;
174 return true; 172 return true;
175 } 173 }
176 174
177 bool LauncherMenuModelAdapter::GetBackgroundColor( 175 bool ShelfMenuModelAdapter::GetBackgroundColor(int command_id,
178 int command_id, 176 bool is_hovered,
179 bool is_hovered, 177 SkColor* override_color) const {
180 SkColor* override_color) const { 178 if (!menu_model_->IsCommandActive(command_id))
181 if (!launcher_menu_model_->IsCommandActive(command_id))
182 return false; 179 return false;
183 180
184 *override_color = is_hovered ? kFocusedActiveListItemBackgroundColor : 181 *override_color = is_hovered ? kFocusedActiveListItemBackgroundColor :
185 kActiveListItemBackgroundColor; 182 kActiveListItemBackgroundColor;
186 return true; 183 return true;
187 } 184 }
188 185
189 void LauncherMenuModelAdapter::GetHorizontalIconMargins( 186 void ShelfMenuModelAdapter::GetHorizontalIconMargins(int command_id,
190 int command_id, 187 int icon_size,
191 int icon_size, 188 int* left_margin,
192 int* left_margin, 189 int* right_margin) const {
193 int* right_margin) const {
194 *left_margin = kHorizontalIconSpacing; 190 *left_margin = kHorizontalIconSpacing;
195 *right_margin = (command_id != kCommandIdOfMenuName) ? 191 *right_margin = (command_id != kCommandIdOfMenuName) ?
196 kHorizontalIconSpacing : -(icon_size + kHorizontalNoIconInsetSpacing); 192 kHorizontalIconSpacing : -(icon_size + kHorizontalNoIconInsetSpacing);
197 } 193 }
198 194
199 int LauncherMenuModelAdapter::GetMaxWidthForMenu(views::MenuItemView* menu) { 195 int ShelfMenuModelAdapter::GetMaxWidthForMenu(views::MenuItemView* menu) {
200 return kMaximumAppMenuItemLength; 196 return kMaximumAppMenuItemLength;
201 } 197 }
202 198
203 bool LauncherMenuModelAdapter::ShouldReserveSpaceForSubmenuIndicator() const { 199 bool ShelfMenuModelAdapter::ShouldReserveSpaceForSubmenuIndicator() const {
204 return false; 200 return false;
205 } 201 }
206 202
207 // Custom FocusSearch used to navigate the launcher in the order items are in 203 // Custom FocusSearch used to navigate the launcher in the order items are in
208 // the ViewModel. 204 // the ViewModel.
209 class LauncherFocusSearch : public views::FocusSearch { 205 class LauncherFocusSearch : public views::FocusSearch {
210 public: 206 public:
211 explicit LauncherFocusSearch(views::ViewModel* view_model) 207 explicit LauncherFocusSearch(views::ViewModel* view_model)
212 : FocusSearch(NULL, true, true), 208 : FocusSearch(NULL, true, true),
213 view_model_(view_model) {} 209 view_model_(view_model) {}
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 context_menu_id_(0), 366 context_menu_id_(0),
371 leading_inset_(kDefaultLeadingInset), 367 leading_inset_(kDefaultLeadingInset),
372 cancelling_drag_model_changed_(false), 368 cancelling_drag_model_changed_(false),
373 last_hidden_index_(0), 369 last_hidden_index_(0),
374 closing_event_time_(base::TimeDelta()), 370 closing_event_time_(base::TimeDelta()),
375 got_deleted_(NULL), 371 got_deleted_(NULL),
376 drag_and_drop_item_pinned_(false), 372 drag_and_drop_item_pinned_(false),
377 drag_and_drop_launcher_id_(0), 373 drag_and_drop_launcher_id_(0),
378 dragged_off_shelf_(false), 374 dragged_off_shelf_(false),
379 snap_back_from_rip_off_view_(NULL), 375 snap_back_from_rip_off_view_(NULL),
380 item_manager_(Shell::GetInstance()->launcher_item_delegate_manager()), 376 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()),
381 layout_manager_(shelf_layout_manager), 377 layout_manager_(shelf_layout_manager),
382 overflow_mode_(false) { 378 overflow_mode_(false) {
383 DCHECK(model_); 379 DCHECK(model_);
384 bounds_animator_.reset(new views::BoundsAnimator(this)); 380 bounds_animator_.reset(new views::BoundsAnimator(this));
385 bounds_animator_->AddObserver(this); 381 bounds_animator_->AddObserver(this);
386 set_context_menu_controller(this); 382 set_context_menu_controller(this);
387 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); 383 focus_search_.reset(new LauncherFocusSearch(view_model_.get()));
388 tooltip_.reset(new ShelfTooltipManager(shelf_layout_manager, this)); 384 tooltip_.reset(new ShelfTooltipManager(shelf_layout_manager, this));
389 } 385 }
390 386
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 DCHECK(drag_view_); 954 DCHECK(drag_view_);
959 drag_pointer_ = pointer; 955 drag_pointer_ = pointer;
960 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); 956 start_drag_index_ = view_model_->GetIndexOfView(drag_view_);
961 957
962 if (start_drag_index_== -1) { 958 if (start_drag_index_== -1) {
963 CancelDrag(-1); 959 CancelDrag(-1);
964 return; 960 return;
965 } 961 }
966 962
967 // If the item is no longer draggable, bail out. 963 // If the item is no longer draggable, bail out.
968 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 964 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
969 model_->items()[start_drag_index_].id); 965 model_->items()[start_drag_index_].id);
970 if (!item_delegate->IsDraggable()) { 966 if (!item_delegate->IsDraggable()) {
971 CancelDrag(-1); 967 CancelDrag(-1);
972 return; 968 return;
973 } 969 }
974 970
975 // Move the view to the front so that it appears on top of other views. 971 // Move the view to the front so that it appears on top of other views.
976 ReorderChildView(drag_view_, -1); 972 ReorderChildView(drag_view_, -1);
977 bounds_animator_->StopAnimatingView(drag_view_); 973 bounds_animator_->StopAnimatingView(drag_view_);
978 } 974 }
979 975
980 void ShelfView::ContinueDrag(const ui::LocatedEvent& event) { 976 void ShelfView::ContinueDrag(const ui::LocatedEvent& event) {
981 // Due to a syncing operation the application might have been removed. 977 // Due to a syncing operation the application might have been removed.
982 // Bail if it is gone. 978 // Bail if it is gone.
983 int current_index = view_model_->GetIndexOfView(drag_view_); 979 int current_index = view_model_->GetIndexOfView(drag_view_);
984 DCHECK_NE(-1, current_index); 980 DCHECK_NE(-1, current_index);
985 981
986 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 982 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
987 model_->items()[current_index].id); 983 model_->items()[current_index].id);
988 if (!item_delegate->IsDraggable()) { 984 if (!item_delegate->IsDraggable()) {
989 CancelDrag(-1); 985 CancelDrag(-1);
990 return; 986 return;
991 } 987 }
992 988
993 // If this is not a drag and drop host operation and not the app list item, 989 // If this is not a drag and drop host operation and not the app list item,
994 // check if the item got ripped off the shelf - if it did we are done. 990 // check if the item got ripped off the shelf - if it did we are done.
995 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() && 991 if (!drag_and_drop_launcher_id_ && ash::switches::UseDragOffShelf() &&
996 RemovableByRipOff(current_index) != NOT_REMOVABLE) { 992 RemovableByRipOff(current_index) != NOT_REMOVABLE) {
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 void ShelfView::PointerPressedOnButton(views::View* view, 1589 void ShelfView::PointerPressedOnButton(views::View* view,
1594 Pointer pointer, 1590 Pointer pointer,
1595 const ui::LocatedEvent& event) { 1591 const ui::LocatedEvent& event) {
1596 if (drag_view_) 1592 if (drag_view_)
1597 return; 1593 return;
1598 1594
1599 int index = view_model_->GetIndexOfView(view); 1595 int index = view_model_->GetIndexOfView(view);
1600 if (index == -1) 1596 if (index == -1)
1601 return; 1597 return;
1602 1598
1603 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1599 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1604 model_->items()[index].id); 1600 model_->items()[index].id);
1605 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable()) 1601 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable())
1606 return; // View is being deleted or not draggable, ignore request. 1602 return; // View is being deleted or not draggable, ignore request.
1607 1603
1608 drag_view_ = view; 1604 drag_view_ = view;
1609 drag_offset_ = layout_manager_->PrimaryAxisValue(event.x(), event.y()); 1605 drag_offset_ = layout_manager_->PrimaryAxisValue(event.x(), event.y());
1610 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", 1606 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage",
1611 layout_manager_->SelectValueForShelfAlignment( 1607 layout_manager_->SelectValueForShelfAlignment(
1612 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, 1608 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM,
1613 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, 1609 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 if (!tooltip_->IsVisible()) 1665 if (!tooltip_->IsVisible())
1670 tooltip_->StopTimer(); 1666 tooltip_->StopTimer();
1671 } 1667 }
1672 1668
1673 base::string16 ShelfView::GetAccessibleName(const views::View* view) { 1669 base::string16 ShelfView::GetAccessibleName(const views::View* view) {
1674 int view_index = view_model_->GetIndexOfView(view); 1670 int view_index = view_model_->GetIndexOfView(view);
1675 // May be -1 while in the process of animating closed. 1671 // May be -1 while in the process of animating closed.
1676 if (view_index == -1) 1672 if (view_index == -1)
1677 return base::string16(); 1673 return base::string16();
1678 1674
1679 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1675 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1680 model_->items()[view_index].id); 1676 model_->items()[view_index].id);
1681 return item_delegate->GetTitle(); 1677 return item_delegate->GetTitle();
1682 } 1678 }
1683 1679
1684 void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) { 1680 void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) {
1685 // Do not handle mouse release during drag. 1681 // Do not handle mouse release during drag.
1686 if (dragging()) 1682 if (dragging())
1687 return; 1683 return;
1688 1684
1689 if (sender == overflow_button_) { 1685 if (sender == overflow_button_) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 break; 1723 break;
1728 1724
1729 case TYPE_APP_PANEL: 1725 case TYPE_APP_PANEL:
1730 break; 1726 break;
1731 1727
1732 case TYPE_UNDEFINED: 1728 case TYPE_UNDEFINED:
1733 NOTREACHED() << "LauncherItemType must be set."; 1729 NOTREACHED() << "LauncherItemType must be set.";
1734 break; 1730 break;
1735 } 1731 }
1736 1732
1737 LauncherItemDelegate* item_delegate = 1733 ShelfItemDelegate* item_delegate =
1738 item_manager_->GetLauncherItemDelegate( 1734 item_manager_->GetShelfItemDelegate(model_->items()[view_index].id);
1739 model_->items()[view_index].id);
1740 if (!item_delegate->ItemSelected(event)) 1735 if (!item_delegate->ItemSelected(event))
1741 ShowListMenuForView(model_->items()[view_index], sender, event); 1736 ShowListMenuForView(model_->items()[view_index], sender, event);
1742 } 1737 }
1743 } 1738 }
1744 1739
1745 bool ShelfView::ShowListMenuForView(const LauncherItem& item, 1740 bool ShelfView::ShowListMenuForView(const LauncherItem& item,
1746 views::View* source, 1741 views::View* source,
1747 const ui::Event& event) { 1742 const ui::Event& event) {
1748 scoped_ptr<ash::LauncherMenuModel> menu_model; 1743 scoped_ptr<ShelfMenuModel> menu_model;
1749 LauncherItemDelegate* item_delegate = 1744 ShelfItemDelegate* item_delegate =
1750 item_manager_->GetLauncherItemDelegate(item.id); 1745 item_manager_->GetShelfItemDelegate(item.id);
1751 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags())); 1746 menu_model.reset(item_delegate->CreateApplicationMenu(event.flags()));
1752 1747
1753 // Make sure we have a menu and it has at least two items in addition to the 1748 // Make sure we have a menu and it has at least two items in addition to the
1754 // application title and the 3 spacing separators. 1749 // application title and the 3 spacing separators.
1755 if (!menu_model.get() || menu_model->GetItemCount() <= 5) 1750 if (!menu_model.get() || menu_model->GetItemCount() <= 5)
1756 return false; 1751 return false;
1757 1752
1758 ShowMenu(scoped_ptr<views::MenuModelAdapter>( 1753 ShowMenu(scoped_ptr<views::MenuModelAdapter>(
1759 new LauncherMenuModelAdapter(menu_model.get())), 1754 new ShelfMenuModelAdapter(menu_model.get())),
1760 source, 1755 source,
1761 gfx::Point(), 1756 gfx::Point(),
1762 false, 1757 false,
1763 ui::GetMenuSourceTypeForEvent(event)); 1758 ui::GetMenuSourceTypeForEvent(event));
1764 return true; 1759 return true;
1765 } 1760 }
1766 1761
1767 void ShelfView::ShowContextMenuForView(views::View* source, 1762 void ShelfView::ShowContextMenuForView(views::View* source,
1768 const gfx::Point& point, 1763 const gfx::Point& point,
1769 ui::MenuSourceType source_type) { 1764 ui::MenuSourceType source_type) {
1770 int view_index = view_model_->GetIndexOfView(source); 1765 int view_index = view_model_->GetIndexOfView(source);
1771 // TODO(simon.hong81): Create LauncherContextMenu for applist in its 1766 // TODO(simon.hong81): Create LauncherContextMenu for applist in its
1772 // LauncherItemDelegate. 1767 // ShelfItemDelegate.
1773 if (view_index != -1 && 1768 if (view_index != -1 && model_->items()[view_index].type == TYPE_APP_LIST) {
1774 model_->items()[view_index].type == TYPE_APP_LIST) {
1775 view_index = -1; 1769 view_index = -1;
1776 } 1770 }
1777 1771
1778 if (view_index == -1) { 1772 if (view_index == -1) {
1779 Shell::GetInstance()->ShowContextMenu(point, source_type); 1773 Shell::GetInstance()->ShowContextMenu(point, source_type);
1780 return; 1774 return;
1781 } 1775 }
1782 scoped_ptr<ui::MenuModel> menu_model; 1776 scoped_ptr<ui::MenuModel> menu_model;
1783 LauncherItemDelegate* item_delegate = item_manager_->GetLauncherItemDelegate( 1777 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1784 model_->items()[view_index].id); 1778 model_->items()[view_index].id);
1785 menu_model.reset(item_delegate->CreateContextMenu( 1779 menu_model.reset(item_delegate->CreateContextMenu(
1786 source->GetWidget()->GetNativeView()->GetRootWindow())); 1780 source->GetWidget()->GetNativeView()->GetRootWindow()));
1787 if (!menu_model) 1781 if (!menu_model)
1788 return; 1782 return;
1789 1783
1790 base::AutoReset<LauncherID> reseter( 1784 base::AutoReset<LauncherID> reseter(
1791 &context_menu_id_, 1785 &context_menu_id_,
1792 view_index == -1 ? 0 : model_->items()[view_index].id); 1786 view_index == -1 ? 0 : model_->items()[view_index].id);
1793 1787
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 return &(model_->items()[view_index]); 1928 return &(model_->items()[view_index]);
1935 } 1929 }
1936 1930
1937 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const { 1931 bool ShelfView::ShouldShowTooltipForView(const views::View* view) const {
1938 if (view == GetAppListButtonView() && 1932 if (view == GetAppListButtonView() &&
1939 Shell::GetInstance()->GetAppListWindow()) 1933 Shell::GetInstance()->GetAppListWindow())
1940 return false; 1934 return false;
1941 const LauncherItem* item = LauncherItemForView(view); 1935 const LauncherItem* item = LauncherItemForView(view);
1942 if (!item) 1936 if (!item)
1943 return true; 1937 return true;
1944 LauncherItemDelegate* item_delegate = 1938 ShelfItemDelegate* item_delegate =
1945 item_manager_->GetLauncherItemDelegate(item->id); 1939 item_manager_->GetShelfItemDelegate(item->id);
1946 return item_delegate->ShouldShowTooltip(); 1940 return item_delegate->ShouldShowTooltip();
1947 } 1941 }
1948 1942
1949 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1943 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1950 ShelfWidget* shelf = RootWindowController::ForLauncher( 1944 ShelfWidget* shelf = RootWindowController::ForLauncher(
1951 GetWidget()->GetNativeView())->shelf(); 1945 GetWidget()->GetNativeView())->shelf();
1952 ash::ShelfAlignment align = shelf->GetAlignment(); 1946 ash::ShelfAlignment align = shelf->GetAlignment();
1953 const gfx::Rect bounds = GetBoundsInScreen(); 1947 const gfx::Rect bounds = GetBoundsInScreen();
1954 int distance = 0; 1948 int distance = 0;
1955 switch (align) { 1949 switch (align) {
1956 case ash::SHELF_ALIGNMENT_BOTTOM: 1950 case ash::SHELF_ALIGNMENT_BOTTOM:
1957 distance = bounds.y() - coordinate.y(); 1951 distance = bounds.y() - coordinate.y();
1958 break; 1952 break;
1959 case ash::SHELF_ALIGNMENT_LEFT: 1953 case ash::SHELF_ALIGNMENT_LEFT:
1960 distance = coordinate.x() - bounds.right(); 1954 distance = coordinate.x() - bounds.right();
1961 break; 1955 break;
1962 case ash::SHELF_ALIGNMENT_RIGHT: 1956 case ash::SHELF_ALIGNMENT_RIGHT:
1963 distance = bounds.x() - coordinate.x(); 1957 distance = bounds.x() - coordinate.x();
1964 break; 1958 break;
1965 case ash::SHELF_ALIGNMENT_TOP: 1959 case ash::SHELF_ALIGNMENT_TOP:
1966 distance = coordinate.y() - bounds.bottom(); 1960 distance = coordinate.y() - bounds.bottom();
1967 break; 1961 break;
1968 } 1962 }
1969 return distance > 0 ? distance : 0; 1963 return distance > 0 ? distance : 0;
1970 } 1964 }
1971 1965
1972 } // namespace internal 1966 } // namespace internal
1973 } // namespace ash 1967 } // 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