summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 16:26:44 +0000
committerskuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 16:26:44 +0000
commit02615ee37469bb43e4febbf18b2cba47ba35644b (patch)
treea642f7f28c56f006d9053009bd405cb5e9f9e0c6
parent9eee621222e2c1d419725f058d69277ac026ff46 (diff)
downloadchromium_src-02615ee37469bb43e4febbf18b2cba47ba35644b.zip
chromium_src-02615ee37469bb43e4febbf18b2cba47ba35644b.tar.gz
chromium_src-02615ee37469bb43e4febbf18b2cba47ba35644b.tar.bz2
Finalizing the 'OnClick' behavior of the Launcher items.
BUG=173233 TEST=visual Review URL: https://chromiumcodereview.appspot.com/12096094 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180421 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/launcher/launcher_view.cc108
-rw-r--r--ui/views/controls/menu/menu_delegate.cc6
-rw-r--r--ui/views/controls/menu/menu_delegate.h7
-rw-r--r--ui/views/controls/menu/menu_item_view.cc8
4 files changed, 78 insertions, 51 deletions
diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc
index 2c762e1..7a19ab6 100644
--- a/ash/launcher/launcher_view.cc
+++ b/ash/launcher/launcher_view.cc
@@ -67,8 +67,32 @@ const float kReservedNonPanelIconProportion = 0.67f;
// This is the command id of the menu item which contains the name of the menu.
const int kCommandIdOfMenuName = 0;
+// This is the command id of the active menu item.
+const int kCommandIdOfActiveName = 1;
+
+// The background color of the active item in the list.
+const SkColor kActiveListItemBackgroundColor = SkColorSetRGB(203 , 219, 241);
+
+// The background color ot the active & hovered item in the list.
+const SkColor kFocusedActiveListItemBackgroundColor =
+ SkColorSetRGB(193, 211, 236);
+
namespace {
+// An object which turns slow animations on during its lifetime.
+class ScopedAnimationSetter {
+ public:
+ explicit ScopedAnimationSetter() {
+ ui::LayerAnimator::set_slow_animation_mode(true);
+ }
+ ~ScopedAnimationSetter() {
+ ui::LayerAnimator::set_slow_animation_mode(false);
+ }
+ private:
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedAnimationSetter);
+};
+
// The MenuModelAdapter gets slightly changed to adapt the menu appearance to
// our requirements.
class LauncherMenuModelAdapter
@@ -82,7 +106,9 @@ class LauncherMenuModelAdapter
int icon_size,
int* left_margin,
int* right_margin) const OVERRIDE;
-
+ virtual bool GetBackgroundColor(int command_id,
+ bool is_hovered,
+ SkColor* override_color) const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(LauncherMenuModelAdapter);
@@ -101,6 +127,18 @@ const gfx::Font* LauncherMenuModelAdapter::GetLabelFont(
return &rb.GetFont(ui::ResourceBundle::BoldFont);
}
+bool LauncherMenuModelAdapter::GetBackgroundColor(
+ int command_id,
+ bool is_hovered,
+ SkColor *override_color) const {
+ if (command_id != kCommandIdOfActiveName)
+ return false;
+
+ *override_color = is_hovered ? kFocusedActiveListItemBackgroundColor :
+ kActiveListItemBackgroundColor;
+ return true;
+}
+
void LauncherMenuModelAdapter::GetHorizontalIconMargins(
int command_id,
int icon_size,
@@ -1189,71 +1227,41 @@ void LauncherView::ButtonPressed(views::Button* sender,
tooltip_->Close();
+ {
+ // Slow down activation animations if shift key is pressed.
+ scoped_ptr<ScopedAnimationSetter> slowing_animations;
+ if (event.IsShiftDown())
+ slowing_animations.reset(new ScopedAnimationSetter());
+
// Collect usage statistics before we decide what to do with the click.
switch (model_->items()[view_index].type) {
case TYPE_APP_SHORTCUT:
case TYPE_PLATFORM_APP:
Shell::GetInstance()->delegate()->RecordUserMetricsAction(
UMA_LAUNCHER_CLICK_ON_APP);
- break;
-
- case TYPE_APP_LIST:
- Shell::GetInstance()->delegate()->RecordUserMetricsAction(
- UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
- break;
-
- case TYPE_BROWSER_SHORTCUT:
- // Click on browser icon is counted in app clicks.
- Shell::GetInstance()->delegate()->RecordUserMetricsAction(
- UMA_LAUNCHER_CLICK_ON_APP);
- break;
-
+ // Fallthrough
case TYPE_TABBED:
case TYPE_APP_PANEL:
+ delegate_->ItemClicked(model_->items()[view_index], event);
break;
- }
-
- // If the item is already active we show a menu - otherwise we activate
- // the item dependent on its type.
- // Note that the old launcher has no menu and falls back automatically to
- // the click action.
- bool call_object_handler = model_->items()[view_index].type == TYPE_APP_LIST;
- if (!call_object_handler) {
- call_object_handler =
- model_->items()[view_index].status != ash::STATUS_ACTIVE;
- if (!call_object_handler) {
- // ShowListMenuForView only returns true if the menu was shown.
- if (ShowListMenuForView(model_->items()[view_index],
- sender)) {
- // When the menu was shown it is possible that this got deleted.
- return;
- }
- call_object_handler = true;
- }
- }
- if (call_object_handler) {
- if (event.IsShiftDown())
- ui::LayerAnimator::set_slow_animation_mode(true);
- // The menu was not shown and the objects click handler should be called.
- switch (model_->items()[view_index].type) {
- case TYPE_TABBED:
- case TYPE_APP_PANEL:
- case TYPE_APP_SHORTCUT:
- case TYPE_PLATFORM_APP:
- delegate_->ItemClicked(model_->items()[view_index], event);
- break;
case TYPE_APP_LIST:
+ Shell::GetInstance()->delegate()->RecordUserMetricsAction(
+ UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
Shell::GetInstance()->ToggleAppList(GetWidget()->GetNativeView());
break;
+
case TYPE_BROWSER_SHORTCUT:
+ // Click on browser icon is counted in app clicks.
+ Shell::GetInstance()->delegate()->RecordUserMetricsAction(
+ UMA_LAUNCHER_CLICK_ON_APP);
delegate_->OnBrowserShortcutClicked(event.flags());
break;
}
- if (event.IsShiftDown())
- ui::LayerAnimator::set_slow_animation_mode(false);
}
+ if (model_->items()[view_index].type != TYPE_APP_LIST)
+ ShowListMenuForView(model_->items()[view_index], sender);
}
bool LauncherView::ShowListMenuForView(const LauncherItem& item,
@@ -1261,9 +1269,9 @@ bool LauncherView::ShowListMenuForView(const LauncherItem& item,
scoped_ptr<ui::MenuModel> menu_model;
menu_model.reset(delegate_->CreateApplicationMenu(item));
- // Make sure we have a menu and it has at least one item in addition to the
- // application title.
- if (!menu_model.get() || menu_model->GetItemCount() <= 1)
+ // Make sure we have a menu and it has at least two items in addition to the
+ // application title and the 2 spacing separators.
+ if (!menu_model.get() || menu_model->GetItemCount() <= 4)
return false;
ShowMenu(menu_model.get(), source, gfx::Point(), false);
diff --git a/ui/views/controls/menu/menu_delegate.cc b/ui/views/controls/menu/menu_delegate.cc
index 85b6170..79a43dc 100644
--- a/ui/views/controls/menu/menu_delegate.cc
+++ b/ui/views/controls/menu/menu_delegate.cc
@@ -21,6 +21,12 @@ const gfx::Font* MenuDelegate::GetLabelFont(int id) const {
return NULL;
}
+bool MenuDelegate::GetBackgroundColor(int command_id,
+ bool is_hovered,
+ SkColor* override_color) const {
+ return false;
+}
+
string16 MenuDelegate::GetTooltipText(int id,
const gfx::Point& screen_loc) const {
return string16();
diff --git a/ui/views/controls/menu/menu_delegate.h b/ui/views/controls/menu/menu_delegate.h
index d3eee19..1967468 100644
--- a/ui/views/controls/menu/menu_delegate.h
+++ b/ui/views/controls/menu/menu_delegate.h
@@ -71,6 +71,13 @@ class VIEWS_EXPORT MenuDelegate {
// The font for the menu item label.
virtual const gfx::Font* GetLabelFont(int id) const;
+ // Override the background color of a given menu item dependent on the
+ // |command_id| and its |is_hovered| state. Returns true if it chooses to
+ // override the color.
+ virtual bool GetBackgroundColor(int command_id,
+ bool is_hovered,
+ SkColor* override_color) const;
+
// The tooltip shown for the menu item. This is invoked when the user
// hovers over the item, and no tooltip text has been set for that item.
virtual string16 GetTooltipText(int id, const gfx::Point& screen_loc) const;
diff --git a/ui/views/controls/menu/menu_item_view.cc b/ui/views/controls/menu/menu_item_view.cc
index eb19fbb..dc49ea9 100644
--- a/ui/views/controls/menu/menu_item_view.cc
+++ b/ui/views/controls/menu/menu_item_view.cc
@@ -776,7 +776,13 @@ void MenuItemView::PaintButtonCommon(gfx::Canvas* canvas,
// only need the background when we want it to look different, as when we're
// selected.
ui::NativeTheme* native_theme = GetNativeTheme();
- if (render_selection) {
+ SkColor override_color;
+ if (GetDelegate() &&
+ GetDelegate()->GetBackgroundColor(GetCommand(),
+ render_selection,
+ &override_color)) {
+ canvas->DrawColor(override_color);
+ } else if (render_selection) {
if (ui::NativeTheme::IsNewMenuStyleEnabled()) {
gfx::Rect item_bounds(0, 0, width(), height());
AdjustBoundsForRTLUI(&item_bounds);