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

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: Addressed 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_item_view.cc » ('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
76 // An object which turns slow animations on during its lifetime.
77 class SlowAnimations {
sky 2013/02/01 00:17:33 ScopedAnimationSetter -> and this should be promot
Mr4D (OOO till 08-26) 2013/02/01 15:48:28 Done.
78 public:
79 explicit SlowAnimations() {
80 ui::LayerAnimator::set_slow_animation_mode(true);
81 }
82 ~SlowAnimations() {
83 ui::LayerAnimator::set_slow_animation_mode(false);
84 }
85 private:
86
87 DISALLOW_COPY_AND_ASSIGN(SlowAnimations);
88 };
89
72 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to 90 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to
73 // our requirements. 91 // our requirements.
74 class LauncherMenuModelAdapter 92 class LauncherMenuModelAdapter
75 : public views::MenuModelAdapter { 93 : public views::MenuModelAdapter {
76 public: 94 public:
77 explicit LauncherMenuModelAdapter(ui::MenuModel* menu_model); 95 explicit LauncherMenuModelAdapter(ui::MenuModel* menu_model);
78 96
79 // Overriding MenuModelAdapter's MenuDelegate implementation. 97 // Overriding MenuModelAdapter's MenuDelegate implementation.
80 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE; 98 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE;
81 virtual void GetHorizontalIconMargins(int id, 99 virtual void GetHorizontalIconMargins(int id,
82 int icon_size, 100 int icon_size,
83 int* left_margin, 101 int* left_margin,
84 int* right_margin) const OVERRIDE; 102 int* right_margin) const OVERRIDE;
85 103 virtual bool GetBackgroundColor(int command_id,
104 bool is_hovered,
105 SkColor* override_color) const OVERRIDE;
86 private: 106 private:
87 107
88 DISALLOW_COPY_AND_ASSIGN(LauncherMenuModelAdapter); 108 DISALLOW_COPY_AND_ASSIGN(LauncherMenuModelAdapter);
89 }; 109 };
90 110
91 111
92 LauncherMenuModelAdapter::LauncherMenuModelAdapter(ui::MenuModel* menu_model) 112 LauncherMenuModelAdapter::LauncherMenuModelAdapter(ui::MenuModel* menu_model)
93 : MenuModelAdapter(menu_model) {} 113 : MenuModelAdapter(menu_model) {}
94 114
95 const gfx::Font* LauncherMenuModelAdapter::GetLabelFont( 115 const gfx::Font* LauncherMenuModelAdapter::GetLabelFont(
96 int command_id) const { 116 int command_id) const {
97 if (command_id != kCommandIdOfMenuName) 117 if (command_id != kCommandIdOfMenuName)
98 return MenuModelAdapter::GetLabelFont(command_id); 118 return MenuModelAdapter::GetLabelFont(command_id);
99 119
100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 120 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
101 return &rb.GetFont(ui::ResourceBundle::BoldFont); 121 return &rb.GetFont(ui::ResourceBundle::BoldFont);
102 } 122 }
103 123
124 bool LauncherMenuModelAdapter::GetBackgroundColor(
125 int command_id,
126 bool is_hovered,
127 SkColor *override_color) const {
128 if (command_id != kCommandIdOfActiveName)
129 return false;
130
131 ui::NativeTheme* native_theme = ui::NativeTheme::instance();
132 *override_color = native_theme->GetSystemColor(is_hovered ?
133 ui::NativeTheme::kColorId_FocusedSelectedMenuItemBackground :
134 ui::NativeTheme::kColorId_SelectedMenuItemBackground);
135 return true;
136 }
137
104 void LauncherMenuModelAdapter::GetHorizontalIconMargins( 138 void LauncherMenuModelAdapter::GetHorizontalIconMargins(
105 int command_id, 139 int command_id,
106 int icon_size, 140 int icon_size,
107 int* left_margin, 141 int* left_margin,
108 int* right_margin) const { 142 int* right_margin) const {
109 *left_margin = kHorizontalIconSpacing; 143 *left_margin = kHorizontalIconSpacing;
110 *right_margin = (command_id != kCommandIdOfMenuName) ? 144 *right_margin = (command_id != kCommandIdOfMenuName) ?
111 kHorizontalIconSpacing : -icon_size; 145 kHorizontalIconSpacing : -icon_size;
112 } 146 }
113 147
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 return; 1216 return;
1183 } 1217 }
1184 1218
1185 int view_index = view_model_->GetIndexOfView(sender); 1219 int view_index = view_model_->GetIndexOfView(sender);
1186 // May be -1 while in the process of animating closed. 1220 // May be -1 while in the process of animating closed.
1187 if (view_index == -1) 1221 if (view_index == -1)
1188 return; 1222 return;
1189 1223
1190 tooltip_->Close(); 1224 tooltip_->Close();
1191 1225
1192 // Collect usage statistics before we decide what to do with the click. 1226 {
1193 switch (model_->items()[view_index].type) { 1227 // Slow down activation animations if shift key is pressed.
1194 case TYPE_APP_SHORTCUT: 1228 scoped_ptr<SlowAnimations> slowing_animations;
1195 case TYPE_PLATFORM_APP: 1229 if (event.IsShiftDown())
1196 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1230 slowing_animations.reset(new SlowAnimations());
1197 UMA_LAUNCHER_CLICK_ON_APP);
1198 break;
1199 1231
1200 case TYPE_APP_LIST: 1232 // Collect usage statistics before we decide what to do with the click.
1201 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1233 switch (model_->items()[view_index].type) {
1202 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); 1234 case TYPE_APP_SHORTCUT:
1203 break; 1235 case TYPE_PLATFORM_APP:
1236 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1237 UMA_LAUNCHER_CLICK_ON_APP);
1238 delegate_->ItemClicked(model_->items()[view_index], event.flags());
1239 // Fallthrough
1240 case TYPE_TABBED:
1241 case TYPE_APP_PANEL:
1242 break;
1204 1243
1205 case TYPE_BROWSER_SHORTCUT: 1244 case TYPE_APP_LIST:
1206 // Click on browser icon is counted in app clicks. 1245 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1207 Shell::GetInstance()->delegate()->RecordUserMetricsAction( 1246 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
1208 UMA_LAUNCHER_CLICK_ON_APP); 1247 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView());
1209 break; 1248 break;
1210 1249
1211 case TYPE_TABBED: 1250 case TYPE_BROWSER_SHORTCUT:
1212 case TYPE_APP_PANEL: 1251 // Click on browser icon is counted in app clicks.
1213 break; 1252 Shell::GetInstance()->delegate()->RecordUserMetricsAction(
1214 } 1253 UMA_LAUNCHER_CLICK_ON_APP);
1215 1254 delegate_->OnBrowserShortcutClicked(event.flags());
1216 // If the item is already active we show a menu - otherwise we activate 1255 break;
1217 // the item dependent on its type.
1218 // Note that the old launcher has no menu and falls back automatically to
1219 // the click action.
1220 bool call_object_handler = model_->items()[view_index].type == TYPE_APP_LIST;
1221 if (!call_object_handler) {
1222 call_object_handler =
1223 model_->items()[view_index].status != ash::STATUS_ACTIVE;
1224 if (!call_object_handler) {
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 } 1256 }
1233 } 1257 }
1234 1258
1235 if (call_object_handler) { 1259 if (model_->items()[view_index].type != TYPE_APP_LIST)
1236 if (event.IsShiftDown()) 1260 ShowListMenuForView(model_->items()[view_index], sender);
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 } 1261 }
1258 1262
1259 bool LauncherView::ShowListMenuForView(const LauncherItem& item, 1263 bool LauncherView::ShowListMenuForView(const LauncherItem& item,
1260 views::View* source) { 1264 views::View* source) {
1261 scoped_ptr<ui::MenuModel> menu_model; 1265 scoped_ptr<ui::MenuModel> menu_model;
1262 menu_model.reset(delegate_->CreateApplicationMenu(item)); 1266 menu_model.reset(delegate_->CreateApplicationMenu(item));
1263 1267
1264 // Make sure we have a menu and it has at least one item in addition to the 1268 // Make sure we have a menu and it has at least two items in addition to the
1265 // application title. 1269 // application title and the 2 spacing separators.
1266 if (!menu_model.get() || menu_model->GetItemCount() <= 1) 1270 if (!menu_model.get() || menu_model->GetItemCount() <= 4)
1267 return false; 1271 return false;
1268 1272
1269 ShowMenu(menu_model.get(), source, gfx::Point(), false); 1273 ShowMenu(menu_model.get(), source, gfx::Point(), false);
1270 return true; 1274 return true;
1271 } 1275 }
1272 1276
1273 void LauncherView::ShowContextMenuForView(views::View* source, 1277 void LauncherView::ShowContextMenuForView(views::View* source,
1274 const gfx::Point& point) { 1278 const gfx::Point& point) {
1275 int view_index = view_model_->GetIndexOfView(source); 1279 int view_index = view_model_->GetIndexOfView(source);
1276 if (view_index != -1 && 1280 if (view_index != -1 &&
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, 1354 FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
1351 OnLauncherIconPositionsChanged()); 1355 OnLauncherIconPositionsChanged());
1352 PreferredSizeChanged(); 1356 PreferredSizeChanged();
1353 } 1357 }
1354 1358
1355 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { 1359 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
1356 } 1360 }
1357 1361
1358 } // namespace internal 1362 } // namespace internal
1359 } // namespace ash 1363 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ui/native_theme/native_theme.h » ('j') | ui/views/controls/menu/menu_item_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698