| 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 #ifndef ASH_LAUNCHER_LAUNCHER_BUTTON_H_ | 5 #ifndef ASH_LAUNCHER_LAUNCHER_BUTTON_H_ |
| 6 #define ASH_LAUNCHER_LAUNCHER_BUTTON_H_ | 6 #define ASH_LAUNCHER_LAUNCHER_BUTTON_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ui/gfx/shadow_value.h" | 9 #include "ui/gfx/shadow_value.h" |
| 10 #include "ui/views/controls/button/custom_button.h" | 10 #include "ui/views/controls/button/custom_button.h" |
| 11 #include "ui/views/controls/image_view.h" | 11 #include "ui/views/controls/image_view.h" |
| 12 | 12 |
| 13 namespace ash { | 13 namespace ash { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 class LauncherButtonHost; | 16 class ShelfButtonHost; |
| 17 class ShelfLayoutManager; | 17 class ShelfLayoutManager; |
| 18 | 18 |
| 19 // Button used for items on the launcher, except for the AppList. | 19 // Button used for items on the launcher, except for the AppList. |
| 20 class ASH_EXPORT LauncherButton : public views::CustomButton { | 20 class ASH_EXPORT LauncherButton : public views::CustomButton { |
| 21 public: | 21 public: |
| 22 // Used to indicate the current state of the button. | 22 // Used to indicate the current state of the button. |
| 23 enum State { | 23 enum State { |
| 24 // Nothing special. Usually represents an app shortcut item with no running | 24 // Nothing special. Usually represents an app shortcut item with no running |
| 25 // instance. | 25 // instance. |
| 26 STATE_NORMAL = 0, | 26 STATE_NORMAL = 0, |
| 27 // Button has mouse hovering on it. | 27 // Button has mouse hovering on it. |
| 28 STATE_HOVERED = 1 << 0, | 28 STATE_HOVERED = 1 << 0, |
| 29 // Underlying LauncherItem has a running instance. | 29 // Underlying LauncherItem has a running instance. |
| 30 STATE_RUNNING = 1 << 1, | 30 STATE_RUNNING = 1 << 1, |
| 31 // Underlying LauncherItem is active (i.e. has focus). | 31 // Underlying LauncherItem is active (i.e. has focus). |
| 32 STATE_ACTIVE = 1 << 2, | 32 STATE_ACTIVE = 1 << 2, |
| 33 // Underlying LauncherItem needs user's attention. | 33 // Underlying LauncherItem needs user's attention. |
| 34 STATE_ATTENTION = 1 << 3, | 34 STATE_ATTENTION = 1 << 3, |
| 35 STATE_FOCUSED = 1 << 4, | 35 STATE_FOCUSED = 1 << 4, |
| 36 // Hide the status (temporarily for some animations). | 36 // Hide the status (temporarily for some animations). |
| 37 STATE_HIDDEN = 1 << 5, | 37 STATE_HIDDEN = 1 << 5, |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 virtual ~LauncherButton(); | 40 virtual ~LauncherButton(); |
| 41 | 41 |
| 42 // Called to create an instance of a LauncherButton. | 42 // Called to create an instance of a LauncherButton. |
| 43 static LauncherButton* Create(views::ButtonListener* listener, | 43 static LauncherButton* Create(views::ButtonListener* listener, |
| 44 LauncherButtonHost* host, | 44 ShelfButtonHost* host, |
| 45 ShelfLayoutManager* shelf_layout_manager); | 45 ShelfLayoutManager* shelf_layout_manager); |
| 46 | 46 |
| 47 // Sets the image to display for this entry. | 47 // Sets the image to display for this entry. |
| 48 void SetImage(const gfx::ImageSkia& image); | 48 void SetImage(const gfx::ImageSkia& image); |
| 49 | 49 |
| 50 // Retrieve the image to show proxy operations. | 50 // Retrieve the image to show proxy operations. |
| 51 const gfx::ImageSkia& GetImage() const; | 51 const gfx::ImageSkia& GetImage() const; |
| 52 | 52 |
| 53 // |state| is or'd into the current state. | 53 // |state| is or'd into the current state. |
| 54 void AddState(State state); | 54 void AddState(State state); |
| 55 void ClearState(State state); | 55 void ClearState(State state); |
| 56 int state() const { return state_; } | 56 int state() const { return state_; } |
| 57 const ShelfLayoutManager* shelf_layout_manager() const { | 57 const ShelfLayoutManager* shelf_layout_manager() const { |
| 58 return shelf_layout_manager_; | 58 return shelf_layout_manager_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Returns the bounds of the icon. | 61 // Returns the bounds of the icon. |
| 62 gfx::Rect GetIconBounds() const; | 62 gfx::Rect GetIconBounds() const; |
| 63 | 63 |
| 64 // Overrides to views::CustomButton: | 64 // Overrides to views::CustomButton: |
| 65 virtual void ShowContextMenu(const gfx::Point& p, | 65 virtual void ShowContextMenu(const gfx::Point& p, |
| 66 ui::MenuSourceType source_type) OVERRIDE; | 66 ui::MenuSourceType source_type) OVERRIDE; |
| 67 | 67 |
| 68 // View override - needed by unit test. | 68 // View override - needed by unit test. |
| 69 virtual void OnMouseCaptureLost() OVERRIDE; | 69 virtual void OnMouseCaptureLost() OVERRIDE; |
| 70 | 70 |
| 71 protected: | 71 protected: |
| 72 LauncherButton(views::ButtonListener* listener, | 72 LauncherButton(views::ButtonListener* listener, |
| 73 LauncherButtonHost* host, | 73 ShelfButtonHost* host, |
| 74 ShelfLayoutManager* shelf_layout_manager); | 74 ShelfLayoutManager* shelf_layout_manager); |
| 75 | 75 |
| 76 // Class that draws the icon part of a button, so it can be animated | 76 // Class that draws the icon part of a button, so it can be animated |
| 77 // independently of the rest. This can be subclassed to provide a custom | 77 // independently of the rest. This can be subclassed to provide a custom |
| 78 // implementation, by overriding CreateIconView(). | 78 // implementation, by overriding CreateIconView(). |
| 79 class IconView : public views::ImageView { | 79 class IconView : public views::ImageView { |
| 80 public: | 80 public: |
| 81 IconView(); | 81 IconView(); |
| 82 virtual ~IconView(); | 82 virtual ~IconView(); |
| 83 | 83 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 111 // ui::EventHandler overrides: | 111 // ui::EventHandler overrides: |
| 112 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 112 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
| 113 | 113 |
| 114 // Sets the icon image with a shadow. | 114 // Sets the icon image with a shadow. |
| 115 void SetShadowedImage(const gfx::ImageSkia& bitmap); | 115 void SetShadowedImage(const gfx::ImageSkia& bitmap); |
| 116 // Override for custom initialization. | 116 // Override for custom initialization. |
| 117 virtual void Init(); | 117 virtual void Init(); |
| 118 // Override to subclass IconView. | 118 // Override to subclass IconView. |
| 119 virtual IconView* CreateIconView(); | 119 virtual IconView* CreateIconView(); |
| 120 IconView* icon_view() const { return icon_view_; } | 120 IconView* icon_view() const { return icon_view_; } |
| 121 LauncherButtonHost* host() const { return host_; } | 121 ShelfButtonHost* host() const { return host_; } |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 class BarView; | 124 class BarView; |
| 125 | 125 |
| 126 // Returns true if the shelf is horizontal. If this returns false the shelf is | 126 // Returns true if the shelf is horizontal. If this returns false the shelf is |
| 127 // vertical. | 127 // vertical. |
| 128 bool IsShelfHorizontal() const; | 128 bool IsShelfHorizontal() const; |
| 129 | 129 |
| 130 // Updates the parts of the button to reflect the current |state_| and | 130 // Updates the parts of the button to reflect the current |state_| and |
| 131 // alignment. This may add or remove views, layout and paint. | 131 // alignment. This may add or remove views, layout and paint. |
| 132 void UpdateState(); | 132 void UpdateState(); |
| 133 | 133 |
| 134 // Updates the status bar (bitmap, orientation, visibility). | 134 // Updates the status bar (bitmap, orientation, visibility). |
| 135 void UpdateBar(); | 135 void UpdateBar(); |
| 136 | 136 |
| 137 LauncherButtonHost* host_; | 137 ShelfButtonHost* host_; |
| 138 IconView* icon_view_; | 138 IconView* icon_view_; |
| 139 // Draws a bar underneath the image to represent the state of the application. | 139 // Draws a bar underneath the image to represent the state of the application. |
| 140 BarView* bar_; | 140 BarView* bar_; |
| 141 // The current state of the application, multiple values of AppState are or'd | 141 // The current state of the application, multiple values of AppState are or'd |
| 142 // together. | 142 // together. |
| 143 int state_; | 143 int state_; |
| 144 | 144 |
| 145 ShelfLayoutManager* shelf_layout_manager_; | 145 ShelfLayoutManager* shelf_layout_manager_; |
| 146 | 146 |
| 147 gfx::ShadowValues icon_shadows_; | 147 gfx::ShadowValues icon_shadows_; |
| 148 | 148 |
| 149 // If non-null the destuctor sets this to true. This is set while the menu is | 149 // If non-null the destuctor sets this to true. This is set while the menu is |
| 150 // showing and used to detect if the menu was deleted while running. | 150 // showing and used to detect if the menu was deleted while running. |
| 151 bool* destroyed_flag_; | 151 bool* destroyed_flag_; |
| 152 | 152 |
| 153 DISALLOW_COPY_AND_ASSIGN(LauncherButton); | 153 DISALLOW_COPY_AND_ASSIGN(LauncherButton); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 } // namespace internal | 156 } // namespace internal |
| 157 } // namespace ash | 157 } // namespace ash |
| 158 | 158 |
| 159 #endif // ASH_LAUNCHER_LAUNCHER_BUTTON_H_ | 159 #endif // ASH_LAUNCHER_LAUNCHER_BUTTON_H_ |
| OLD | NEW |