| OLD | NEW |
| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 const int kHorizontalIconSpacing = 8; | 60 const int kHorizontalIconSpacing = 8; |
| 61 | 61 |
| 62 // The proportion of the launcher space reserved for non-panel icons. Panels | 62 // 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 | 63 // may flow into this space but will be put into the overflow bubble if there |
| 64 // is contention for the space. | 64 // is contention for the space. |
| 65 const float kReservedNonPanelIconProportion = 0.67f; | 65 const float kReservedNonPanelIconProportion = 0.67f; |
| 66 | 66 |
| 67 // This is the command id of the menu item which contains the name of the menu. | 67 // This is the command id of the menu item which contains the name of the menu. |
| 68 const int kCommandIdOfMenuName = 0; | 68 const int kCommandIdOfMenuName = 0; |
| 69 | 69 |
| 70 // This is the command id of the active menu item. |
| 71 const int kCommandIdOfActiveName = 1; |
| 72 |
| 73 // The background color of the active item in the list. |
| 74 const SkColor kActiveListItemBackgroundColor = SkColorSetRGB(203 , 219, 241); |
| 75 |
| 76 // The background color ot the active & hovered item in the list. |
| 77 const SkColor kFocusedActiveListItemBackgroundColor = |
| 78 SkColorSetRGB(193, 211, 236); |
| 79 |
| 70 namespace { | 80 namespace { |
| 71 | 81 |
| 82 // An object which turns slow animations on during its lifetime. |
| 83 class ScopedAnimationSetter { |
| 84 public: |
| 85 explicit ScopedAnimationSetter() { |
| 86 ui::LayerAnimator::set_slow_animation_mode(true); |
| 87 } |
| 88 ~ScopedAnimationSetter() { |
| 89 ui::LayerAnimator::set_slow_animation_mode(false); |
| 90 } |
| 91 private: |
| 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(ScopedAnimationSetter); |
| 94 }; |
| 95 |
| 72 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to | 96 // The MenuModelAdapter gets slightly changed to adapt the menu appearance to |
| 73 // our requirements. | 97 // our requirements. |
| 74 class LauncherMenuModelAdapter | 98 class LauncherMenuModelAdapter |
| 75 : public views::MenuModelAdapter { | 99 : public views::MenuModelAdapter { |
| 76 public: | 100 public: |
| 77 explicit LauncherMenuModelAdapter(ui::MenuModel* menu_model); | 101 explicit LauncherMenuModelAdapter(ui::MenuModel* menu_model); |
| 78 | 102 |
| 79 // Overriding MenuModelAdapter's MenuDelegate implementation. | 103 // Overriding MenuModelAdapter's MenuDelegate implementation. |
| 80 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE; | 104 virtual const gfx::Font* GetLabelFont(int command_id) const OVERRIDE; |
| 81 virtual void GetHorizontalIconMargins(int id, | 105 virtual void GetHorizontalIconMargins(int id, |
| 82 int icon_size, | 106 int icon_size, |
| 83 int* left_margin, | 107 int* left_margin, |
| 84 int* right_margin) const OVERRIDE; | 108 int* right_margin) const OVERRIDE; |
| 85 | 109 virtual bool GetBackgroundColor(int command_id, |
| 110 bool is_hovered, |
| 111 SkColor* override_color) const OVERRIDE; |
| 86 private: | 112 private: |
| 87 | 113 |
| 88 DISALLOW_COPY_AND_ASSIGN(LauncherMenuModelAdapter); | 114 DISALLOW_COPY_AND_ASSIGN(LauncherMenuModelAdapter); |
| 89 }; | 115 }; |
| 90 | 116 |
| 91 | 117 |
| 92 LauncherMenuModelAdapter::LauncherMenuModelAdapter(ui::MenuModel* menu_model) | 118 LauncherMenuModelAdapter::LauncherMenuModelAdapter(ui::MenuModel* menu_model) |
| 93 : MenuModelAdapter(menu_model) {} | 119 : MenuModelAdapter(menu_model) {} |
| 94 | 120 |
| 95 const gfx::Font* LauncherMenuModelAdapter::GetLabelFont( | 121 const gfx::Font* LauncherMenuModelAdapter::GetLabelFont( |
| 96 int command_id) const { | 122 int command_id) const { |
| 97 if (command_id != kCommandIdOfMenuName) | 123 if (command_id != kCommandIdOfMenuName) |
| 98 return MenuModelAdapter::GetLabelFont(command_id); | 124 return MenuModelAdapter::GetLabelFont(command_id); |
| 99 | 125 |
| 100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 126 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 101 return &rb.GetFont(ui::ResourceBundle::BoldFont); | 127 return &rb.GetFont(ui::ResourceBundle::BoldFont); |
| 102 } | 128 } |
| 103 | 129 |
| 130 bool LauncherMenuModelAdapter::GetBackgroundColor( |
| 131 int command_id, |
| 132 bool is_hovered, |
| 133 SkColor *override_color) const { |
| 134 if (command_id != kCommandIdOfActiveName) |
| 135 return false; |
| 136 |
| 137 *override_color = is_hovered ? kFocusedActiveListItemBackgroundColor : |
| 138 kActiveListItemBackgroundColor; |
| 139 return true; |
| 140 } |
| 141 |
| 104 void LauncherMenuModelAdapter::GetHorizontalIconMargins( | 142 void LauncherMenuModelAdapter::GetHorizontalIconMargins( |
| 105 int command_id, | 143 int command_id, |
| 106 int icon_size, | 144 int icon_size, |
| 107 int* left_margin, | 145 int* left_margin, |
| 108 int* right_margin) const { | 146 int* right_margin) const { |
| 109 *left_margin = kHorizontalIconSpacing; | 147 *left_margin = kHorizontalIconSpacing; |
| 110 *right_margin = (command_id != kCommandIdOfMenuName) ? | 148 *right_margin = (command_id != kCommandIdOfMenuName) ? |
| 111 kHorizontalIconSpacing : -icon_size; | 149 kHorizontalIconSpacing : -icon_size; |
| 112 } | 150 } |
| 113 | 151 |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 return; | 1220 return; |
| 1183 } | 1221 } |
| 1184 | 1222 |
| 1185 int view_index = view_model_->GetIndexOfView(sender); | 1223 int view_index = view_model_->GetIndexOfView(sender); |
| 1186 // May be -1 while in the process of animating closed. | 1224 // May be -1 while in the process of animating closed. |
| 1187 if (view_index == -1) | 1225 if (view_index == -1) |
| 1188 return; | 1226 return; |
| 1189 | 1227 |
| 1190 tooltip_->Close(); | 1228 tooltip_->Close(); |
| 1191 | 1229 |
| 1230 { |
| 1231 // Slow down activation animations if shift key is pressed. |
| 1232 scoped_ptr<ScopedAnimationSetter> slowing_animations; |
| 1233 if (event.IsShiftDown()) |
| 1234 slowing_animations.reset(new ScopedAnimationSetter()); |
| 1235 |
| 1192 // Collect usage statistics before we decide what to do with the click. | 1236 // Collect usage statistics before we decide what to do with the click. |
| 1193 switch (model_->items()[view_index].type) { | 1237 switch (model_->items()[view_index].type) { |
| 1194 case TYPE_APP_SHORTCUT: | 1238 case TYPE_APP_SHORTCUT: |
| 1195 case TYPE_PLATFORM_APP: | 1239 case TYPE_PLATFORM_APP: |
| 1196 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 1240 Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
| 1197 UMA_LAUNCHER_CLICK_ON_APP); | 1241 UMA_LAUNCHER_CLICK_ON_APP); |
| 1242 // Fallthrough |
| 1243 case TYPE_TABBED: |
| 1244 case TYPE_APP_PANEL: |
| 1245 delegate_->ItemClicked(model_->items()[view_index], event); |
| 1198 break; | 1246 break; |
| 1199 | 1247 |
| 1200 case TYPE_APP_LIST: | 1248 case TYPE_APP_LIST: |
| 1201 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 1249 Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
| 1202 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); | 1250 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); |
| 1203 break; | 1251 Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView()); |
| 1252 break; |
| 1204 | 1253 |
| 1205 case TYPE_BROWSER_SHORTCUT: | 1254 case TYPE_BROWSER_SHORTCUT: |
| 1206 // Click on browser icon is counted in app clicks. | 1255 // Click on browser icon is counted in app clicks. |
| 1207 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 1256 Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
| 1208 UMA_LAUNCHER_CLICK_ON_APP); | 1257 UMA_LAUNCHER_CLICK_ON_APP); |
| 1209 break; | 1258 delegate_->OnBrowserShortcutClicked(event.flags()); |
| 1210 | 1259 break; |
| 1211 case TYPE_TABBED: | |
| 1212 case TYPE_APP_PANEL: | |
| 1213 break; | |
| 1214 } | |
| 1215 | |
| 1216 // If the item is already active we show a menu - otherwise we activate | |
| 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 } | 1260 } |
| 1233 } | 1261 } |
| 1234 | 1262 |
| 1235 if (call_object_handler) { | 1263 if (model_->items()[view_index].type != TYPE_APP_LIST) |
| 1236 if (event.IsShiftDown()) | 1264 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); | |
| 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 } | 1265 } |
| 1258 | 1266 |
| 1259 bool LauncherView::ShowListMenuForView(const LauncherItem& item, | 1267 bool LauncherView::ShowListMenuForView(const LauncherItem& item, |
| 1260 views::View* source) { | 1268 views::View* source) { |
| 1261 scoped_ptr<ui::MenuModel> menu_model; | 1269 scoped_ptr<ui::MenuModel> menu_model; |
| 1262 menu_model.reset(delegate_->CreateApplicationMenu(item)); | 1270 menu_model.reset(delegate_->CreateApplicationMenu(item)); |
| 1263 | 1271 |
| 1264 // Make sure we have a menu and it has at least one item in addition to the | 1272 // Make sure we have a menu and it has at least two items in addition to the |
| 1265 // application title. | 1273 // application title and the 2 spacing separators. |
| 1266 if (!menu_model.get() || menu_model->GetItemCount() <= 1) | 1274 if (!menu_model.get() || menu_model->GetItemCount() <= 4) |
| 1267 return false; | 1275 return false; |
| 1268 | 1276 |
| 1269 ShowMenu(menu_model.get(), source, gfx::Point(), false); | 1277 ShowMenu(menu_model.get(), source, gfx::Point(), false); |
| 1270 return true; | 1278 return true; |
| 1271 } | 1279 } |
| 1272 | 1280 |
| 1273 void LauncherView::ShowContextMenuForView(views::View* source, | 1281 void LauncherView::ShowContextMenuForView(views::View* source, |
| 1274 const gfx::Point& point) { | 1282 const gfx::Point& point) { |
| 1275 int view_index = view_model_->GetIndexOfView(source); | 1283 int view_index = view_model_->GetIndexOfView(source); |
| 1276 if (view_index != -1 && | 1284 if (view_index != -1 && |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, | 1358 FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
| 1351 OnLauncherIconPositionsChanged()); | 1359 OnLauncherIconPositionsChanged()); |
| 1352 PreferredSizeChanged(); | 1360 PreferredSizeChanged(); |
| 1353 } | 1361 } |
| 1354 | 1362 |
| 1355 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 1363 void LauncherView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
| 1356 } | 1364 } |
| 1357 | 1365 |
| 1358 } // namespace internal | 1366 } // namespace internal |
| 1359 } // namespace ash | 1367 } // namespace ash |
| OLD | NEW |