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

Side by Side Diff: ash/launcher/launcher_view.cc

Issue 12096094: Finalizing the 'OnClick' behavior of the Launcher items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Corrected Windows Created 7 years, 10 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 | « no previous file | ui/native_theme/native_theme.h » ('j') | ui/views/controls/menu/menu_delegate.h » ('J')
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/launcher/launcher_view.h" 5 #include "ash/launcher/launcher_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 13 matching lines...) Expand all
24 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
25 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
26 #include "grit/ash_resources.h" 26 #include "grit/ash_resources.h"
27 #include "ui/aura/window.h" 27 #include "ui/aura/window.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/models/simple_menu_model.h" 29 #include "ui/base/models/simple_menu_model.h"
30 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/compositor/layer.h" 31 #include "ui/compositor/layer.h"
32 #include "ui/compositor/layer_animator.h" 32 #include "ui/compositor/layer_animator.h"
33 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
34 #include "ui/native_theme/native_theme.h"
34 #include "ui/views/animation/bounds_animator.h" 35 #include "ui/views/animation/bounds_animator.h"
35 #include "ui/views/border.h" 36 #include "ui/views/border.h"
36 #include "ui/views/controls/menu/menu_model_adapter.h" 37 #include "ui/views/controls/menu/menu_model_adapter.h"
37 #include "ui/views/controls/menu/menu_runner.h" 38 #include "ui/views/controls/menu/menu_runner.h"
38 #include "ui/views/focus/focus_search.h" 39 #include "ui/views/focus/focus_search.h"
39 #include "ui/views/focus_border.h" 40 #include "ui/views/focus_border.h"
40 #include "ui/views/view_model.h" 41 #include "ui/views/view_model.h"
41 #include "ui/views/view_model_utils.h" 42 #include "ui/views/view_model_utils.h"
42 #include "ui/views/widget/widget.h" 43 #include "ui/views/widget/widget.h"
43 44
(...skipping 16 matching lines...) Expand all
60 const int kHorizontalIconSpacing = 8; 61 const int kHorizontalIconSpacing = 8;
61 62
62 // The proportion of the launcher space reserved for non-panel icons. Panels 63 // The proportion of the launcher space reserved for non-panel icons. Panels
63 // may flow into this space but will be put into the overflow bubble if there 64 // may flow into this space but will be put into the overflow bubble if there
64 // is contention for the space. 65 // is contention for the space.
65 const float kReservedNonPanelIconProportion = 0.67f; 66 const float kReservedNonPanelIconProportion = 0.67f;
66 67
67 // This is the command id of the menu item which contains the name of the menu. 68 // This is the command id of the menu item which contains the name of the menu.
68 const int kCommandIdOfMenuName = 0; 69 const int kCommandIdOfMenuName = 0;
69 70
71 // This is the command id of the active menu item.
72 const int kCommandIdOfActiveName = 1;
73
70 namespace { 74 namespace {
71 75
72 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to 76 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to
73 // our requirements. 77 // our requirements.
74 class LauncherMenuModelAdapter 78 class LauncherMenuModelAdapter
75 : public views::MenuModelAdapter { 79 : public views::MenuModelAdapter {
76 public: 80 public:
77 explicit LauncherMenuModelAdapter(ui::MenuModel* menu_model); 81 explicit LauncherMenuModelAdapter(ui::MenuModel* menu_model);
78 82
79 // Overriding MenuModelAdapter's MenuDelegate implementation. 83 // Overriding MenuModelAdapter's MenuDelegate implementation.
80 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE; 84 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE;
81 virtual void GetHorizontalIconMargins(int id, 85 virtual void GetHorizontalIconMargins(int id,
82 int icon_size, 86 int icon_size,
83 int* left_margin, 87 int* left_margin,
84 int* right_margin) const OVERRIDE; 88 int* right_margin) const OVERRIDE;
85 89 virtual bool GetBackgroundColor(int command_id,
90 bool is_hovered,
91 SkColor* override_color) const OVERRIDE;
86 private: 92 private:
87 93
88 DISALLOW_COPY_AND_ASSIGN(LauncherMenuModelAdapter); 94 DISALLOW_COPY_AND_ASSIGN(LauncherMenuModelAdapter);
89 }; 95 };
90 96
91 97
92 LauncherMenuModelAdapter::LauncherMenuModelAdapter(ui::MenuModel* menu_model) 98 LauncherMenuModelAdapter::LauncherMenuModelAdapter(ui::MenuModel* menu_model)
93 : MenuModelAdapter(menu_model) {} 99 : MenuModelAdapter(menu_model) {}
94 100
95 const gfx::Font* LauncherMenuModelAdapter::GetLabelFont( 101 const gfx::Font* LauncherMenuModelAdapter::GetLabelFont(
96 int command_id) const { 102 int command_id) const {
97 if (command_id != kCommandIdOfMenuName) 103 if (command_id != kCommandIdOfMenuName)
98 return MenuModelAdapter::GetLabelFont(command_id); 104 return MenuModelAdapter::GetLabelFont(command_id);
99 105
100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
101 return &rb.GetFont(ui::ResourceBundle::BoldFont); 107 return &rb.GetFont(ui::ResourceBundle::BoldFont);
102 } 108 }
103 109
110 bool LauncherMenuModelAdapter::GetBackgroundColor(
111 int command_id,
112 bool is_hovered,
113 SkColor *override_color) const {
114 if (command_id != kCommandIdOfActiveName)
115 return false;
116
117 ui::NativeTheme* native_theme = ui::NativeTheme::instance();
118 *override_color = native_theme->GetSystemColor(is_hovered ?
119 ui::NativeTheme::kColorId_FocusedSelectedMenuItemBackground :
120 ui::NativeTheme::kColorId_SelectedMenuItemBackground);
121 return true;
122 }
123
104 void LauncherMenuModelAdapter::GetHorizontalIconMargins( 124 void LauncherMenuModelAdapter::GetHorizontalIconMargins(
105 int command_id, 125 int command_id,
106 int icon_size, 126 int icon_size,
107 int* left_margin, 127 int* left_margin,
108 int* right_margin) const { 128 int* right_margin) const {
109 *left_margin = kHorizontalIconSpacing; 129 *left_margin = kHorizontalIconSpacing;
110 *right_margin = (command_id != kCommandIdOfMenuName) ? 130 *right_margin = (command_id != kCommandIdOfMenuName) ?
111 kHorizontalIconSpacing : -icon_size; 131 kHorizontalIconSpacing : -icon_size;
112 } 132 }
113 133
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 return; 1202 return;
1183 } 1203 }
1184 1204
1185 int view_index = view_model_->GetIndexOfView(sender); 1205 int view_index = view_model_->GetIndexOfView(sender);
1186 // May be -1 while in the process of animating closed. 1206 // May be -1 while in the process of animating closed.
1187 if (view_index == -1) 1207 if (view_index == -1)
1188 return; 1208 return;
1189 1209
1190 tooltip_->Close(); 1210 tooltip_->Close();
1191 1211
1212 if (event.IsShiftDown())
sky 2013/01/31 21:15:02 This code is fragile (I know I've added some too),
Mr4D (OOO till 08-26) 2013/01/31 22:38:52 Done.
1213 ui::LayerAnimator::set_slow_animation_mode(true);
1214
1192 // Collect usage statistics before we decide what to do with the click. 1215 // Collect usage statistics before we decide what to do with the click.
1193 switch (model_->items()[view_index].type) { 1216 switch (model_->items()[view_index].type) {
1194 case TYPE_APP_SHORTCUT: 1217 case TYPE_APP_SHORTCUT:
1195 case TYPE_PLATFORM_APP: 1218 case TYPE_PLATFORM_APP:
1196 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1219 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1197 UMA_LAUNCHER_CLICK_ON_APP); 1220 UMA_LAUNCHER_CLICK_ON_APP);
1221 delegate_->ItemClicked(model_->items()[view_index], event.flags());
1222 // Fallthrough
1223 case TYPE_TABBED:
1224 case TYPE_APP_PANEL:
1198 break; 1225 break;
1199 1226
1200 case TYPE_APP_LIST: 1227 case TYPE_APP_LIST:
1201 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1228 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1202 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); 1229 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
1230 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView());
1203 break; 1231 break;
1204 1232
1205 case TYPE_BROWSER_SHORTCUT: 1233 case TYPE_BROWSER_SHORTCUT:
1206 // Click on browser icon is counted in app clicks. 1234 // Click on browser icon is counted in app clicks.
1207 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1235 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1208 UMA_LAUNCHER_CLICK_ON_APP); 1236 UMA_LAUNCHER_CLICK_ON_APP);
1209 break; 1237 delegate_->OnBrowserShortcutClicked(event.flags());
1210
1211 case TYPE_TABBED:
1212 case TYPE_APP_PANEL:
1213 break; 1238 break;
1214 } 1239 }
1215 1240
1216 // If the item is already active we show a menu - otherwise we activate 1241 if (event.IsShiftDown())
1217 // the item dependent on its type. 1242 ui::LayerAnimator::set_slow_animation_mode(false);
1218 // Note that the old launcher has no menu and falls back automatically to 1243
1219 // the click action. 1244 if (model_->items()[view_index].type != TYPE_APP_LIST) {
1220 bool call_object_handler = model_->items()[view_index].type == TYPE_APP_LIST; 1245 // ShowListMenuForView only returns true if the menu was shown.
1221 if (!call_object_handler) { 1246 if (ShowListMenuForView(model_->items()[view_index],
1222 call_object_handler = 1247 sender)) {
1223 model_->items()[view_index].status != ash::STATUS_ACTIVE; 1248 // When the menu was shown it is possible that this got deleted.
1224 if (!call_object_handler) { 1249 return;
1225 // ShowListMenuForView only returns true if the menu was shown.
1226 if (ShowListMenuForView(model_->items()[view_index],
1227 sender)) {
1228 // When the menu was shown it is possible that this got deleted.
1229 return;
1230 }
1231 call_object_handler = true;
1232 } 1250 }
1233 } 1251 }
1234
1235 if (call_object_handler) {
1236 if (event.IsShiftDown())
1237 ui::LayerAnimator::set_slow_animation_mode(true);
1238 // The menu was not shown and the objects click handler should be called.
1239 switch (model_->items()[view_index].type) {
1240 case TYPE_TABBED:
1241 case TYPE_APP_PANEL:
1242 case TYPE_APP_SHORTCUT:
1243 case TYPE_PLATFORM_APP:
1244 delegate_->ItemClicked(model_->items()[view_index], event.flags());
1245 break;
1246 case TYPE_APP_LIST:
1247 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView());
1248 break;
1249 case TYPE_BROWSER_SHORTCUT:
1250 delegate_->OnBrowserShortcutClicked(event.flags());
1251 break;
1252 }
1253 if (event.IsShiftDown())
1254 ui::LayerAnimator::set_slow_animation_mode(false);
1255 }
1256
1257 } 1252 }
1258 1253
1259 bool LauncherView::ShowListMenuForView(const LauncherItem& item, 1254 bool LauncherView::ShowListMenuForView(const LauncherItem& item,
1260 views::View* source) { 1255 views::View* source) {
1261 scoped_ptr<ui::MenuModel> menu_model; 1256 scoped_ptr<ui::MenuModel> menu_model;
1262 menu_model.reset(delegate_->CreateApplicationMenu(item)); 1257 menu_model.reset(delegate_->CreateApplicationMenu(item));
1263 1258
1264 // Make sure we have a menu and it has at least one item in addition to the 1259 // Make sure we have a menu and it has at least two items in addition to the
1265 // application title. 1260 // application title and the 2 spacing separators.
1266 if (!menu_model.get() || menu_model->GetItemCount() <= 1) 1261 if (!menu_model.get() || menu_model->GetItemCount() <= 4)
1267 return false; 1262 return false;
1268 1263
1269 ShowMenu(menu_model.get(), source, gfx::Point(), false); 1264 ShowMenu(menu_model.get(), source, gfx::Point(), false);
1270 return true; 1265 return true;
1271 } 1266 }
1272 1267
1273 void LauncherView::ShowContextMenuForView(views::View* source, 1268 void LauncherView::ShowContextMenuForView(views::View* source,
1274 const gfx::Point& point) { 1269 const gfx::Point& point) {
1275 int view_index = view_model_->GetIndexOfView(source); 1270 int view_index = view_model_->GetIndexOfView(source);
1276 if (view_index != -1 && 1271 if (view_index != -1 &&
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, 1345 FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
1351 OnLauncherIconPositionsChanged()); 1346 OnLauncherIconPositionsChanged());
1352 PreferredSizeChanged(); 1347 PreferredSizeChanged();
1353 } 1348 }
1354 1349
1355 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { 1350 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
1356 } 1351 }
1357 1352
1358 } // namespace internal 1353 } // namespace internal
1359 } // namespace ash 1354 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/native_theme/native_theme.h » ('j') | ui/views/controls/menu/menu_delegate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698