| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SHELF_SHELF_BUTTON_H_ | 5 #ifndef ASH_SHELF_SHELF_BUTTON_H_ |
| 6 #define ASH_SHELF_SHELF_BUTTON_H_ | 6 #define ASH_SHELF_SHELF_BUTTON_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "ui/gfx/shadow_value.h" | 10 #include "ui/gfx/shadow_value.h" |
| 11 #include "ui/views/controls/button/custom_button.h" | 11 #include "ui/views/controls/button/custom_button.h" |
| 12 #include "ui/views/controls/image_view.h" | 12 #include "ui/views/controls/image_view.h" |
| 13 | 13 |
| 14 namespace ash { | 14 namespace ash { |
| 15 class InkDropButtonListener; |
| 15 class ShelfView; | 16 class ShelfView; |
| 16 | 17 |
| 17 // Button used for items on the launcher, except for the AppList. | 18 // Button used for items on the launcher, except for the AppList. |
| 18 class ASH_EXPORT ShelfButton : public views::CustomButton { | 19 class ASH_EXPORT ShelfButton : public views::CustomButton { |
| 19 public: | 20 public: |
| 20 static const char kViewClassName[]; | 21 static const char kViewClassName[]; |
| 21 | 22 |
| 22 // Used to indicate the current state of the button. | 23 // Used to indicate the current state of the button. |
| 23 enum State { | 24 enum State { |
| 24 // Nothing special. Usually represents an app shortcut item with no running | 25 // Nothing special. Usually represents an app shortcut item with no running |
| 25 // instance. | 26 // instance. |
| 26 STATE_NORMAL = 0, | 27 STATE_NORMAL = 0, |
| 27 // Button has mouse hovering on it. | 28 // Button has mouse hovering on it. |
| 28 STATE_HOVERED = 1 << 0, | 29 STATE_HOVERED = 1 << 0, |
| 29 // Underlying ShelfItem has a running instance. | 30 // Underlying ShelfItem has a running instance. |
| 30 STATE_RUNNING = 1 << 1, | 31 STATE_RUNNING = 1 << 1, |
| 31 // Underlying ShelfItem is active (i.e. has focus). | 32 // Underlying ShelfItem is active (i.e. has focus). |
| 32 STATE_ACTIVE = 1 << 2, | 33 STATE_ACTIVE = 1 << 2, |
| 33 // Underlying ShelfItem needs user's attention. | 34 // Underlying ShelfItem needs user's attention. |
| 34 STATE_ATTENTION = 1 << 3, | 35 STATE_ATTENTION = 1 << 3, |
| 35 STATE_FOCUSED = 1 << 4, | 36 STATE_FOCUSED = 1 << 4, |
| 36 // Hide the status (temporarily for some animations). | 37 // Hide the status (temporarily for some animations). |
| 37 STATE_HIDDEN = 1 << 5, | 38 STATE_HIDDEN = 1 << 5, |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 explicit ShelfButton(ShelfView* shelf_view); | 41 ShelfButton(InkDropButtonListener* listener, ShelfView* shelf_view); |
| 41 ~ShelfButton() override; | 42 ~ShelfButton() override; |
| 42 | 43 |
| 43 // Sets the image to display for this entry. | 44 // Sets the image to display for this entry. |
| 44 void SetImage(const gfx::ImageSkia& image); | 45 void SetImage(const gfx::ImageSkia& image); |
| 45 | 46 |
| 46 // Retrieve the image to show proxy operations. | 47 // Retrieve the image to show proxy operations. |
| 47 const gfx::ImageSkia& GetImage() const; | 48 const gfx::ImageSkia& GetImage() const; |
| 48 | 49 |
| 49 // |state| is or'd into the current state. | 50 // |state| is or'd into the current state. |
| 50 void AddState(State state); | 51 void AddState(State state); |
| 51 void ClearState(State state); | 52 void ClearState(State state); |
| 52 int state() const { return state_; } | 53 int state() const { return state_; } |
| 53 | 54 |
| 54 // Returns the bounds of the icon. | 55 // Returns the bounds of the icon. |
| 55 gfx::Rect GetIconBounds() const; | 56 gfx::Rect GetIconBounds() const; |
| 56 | 57 |
| 58 // Called when user started dragging the shelf button. |
| 59 void OnDragStarted(); |
| 60 |
| 57 // Overrides to views::CustomButton: | 61 // Overrides to views::CustomButton: |
| 58 void ShowContextMenu(const gfx::Point& p, | 62 void ShowContextMenu(const gfx::Point& p, |
| 59 ui::MenuSourceType source_type) override; | 63 ui::MenuSourceType source_type) override; |
| 60 | 64 |
| 61 // View override - needed by unit test. | 65 // View override - needed by unit test. |
| 62 void OnMouseCaptureLost() override; | 66 void OnMouseCaptureLost() override; |
| 63 | 67 |
| 64 protected: | 68 protected: |
| 65 // View overrides: | 69 // View overrides: |
| 66 const char* GetClassName() const override; | 70 const char* GetClassName() const override; |
| 67 bool OnMousePressed(const ui::MouseEvent& event) override; | 71 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 68 void OnMouseReleased(const ui::MouseEvent& event) override; | 72 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 69 bool OnMouseDragged(const ui::MouseEvent& event) override; | 73 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 70 void GetAccessibleState(ui::AXViewState* state) override; | 74 void GetAccessibleState(ui::AXViewState* state) override; |
| 71 void Layout() override; | 75 void Layout() override; |
| 72 void ChildPreferredSizeChanged(views::View* child) override; | 76 void ChildPreferredSizeChanged(views::View* child) override; |
| 73 void OnFocus() override; | 77 void OnFocus() override; |
| 74 void OnBlur() override; | 78 void OnBlur() override; |
| 75 void OnPaint(gfx::Canvas* canvas) override; | 79 void OnPaint(gfx::Canvas* canvas) override; |
| 76 | 80 |
| 77 // ui::EventHandler overrides: | 81 // ui::EventHandler overrides: |
| 78 void OnGestureEvent(ui::GestureEvent* event) override; | 82 void OnGestureEvent(ui::GestureEvent* event) override; |
| 79 | 83 |
| 84 // views::CustomButton overrides: |
| 85 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; |
| 86 bool ShouldEnterPushedState(const ui::Event& event) override; |
| 87 bool ShouldShowInkDropHighlight() const override; |
| 88 void NotifyClick(const ui::Event& event) override; |
| 89 |
| 80 // Sets the icon image with a shadow. | 90 // Sets the icon image with a shadow. |
| 81 void SetShadowedImage(const gfx::ImageSkia& bitmap); | 91 void SetShadowedImage(const gfx::ImageSkia& bitmap); |
| 82 | 92 |
| 83 private: | 93 private: |
| 84 class BarView; | 94 class BarView; |
| 85 | 95 |
| 86 // Updates the parts of the button to reflect the current |state_| and | 96 // Updates the parts of the button to reflect the current |state_| and |
| 87 // alignment. This may add or remove views, layout and paint. | 97 // alignment. This may add or remove views, layout and paint. |
| 88 void UpdateState(); | 98 void UpdateState(); |
| 89 | 99 |
| 90 // Updates the status bar (bitmap, orientation, visibility). | 100 // Updates the status bar (bitmap, orientation, visibility). |
| 91 void UpdateBar(); | 101 void UpdateBar(); |
| 92 | 102 |
| 103 InkDropButtonListener* listener_; |
| 104 |
| 93 // The shelf view hosting this button. | 105 // The shelf view hosting this button. |
| 94 ShelfView* shelf_view_; | 106 ShelfView* shelf_view_; |
| 95 | 107 |
| 96 // The icon part of a button can be animated independently of the rest. | 108 // The icon part of a button can be animated independently of the rest. |
| 97 views::ImageView* icon_view_; | 109 views::ImageView* icon_view_; |
| 98 | 110 |
| 99 // Draws a bar underneath the image to represent the state of the application. | 111 // Draws a bar underneath the image to represent the state of the application. |
| 100 BarView* bar_; | 112 BarView* bar_; |
| 101 | 113 |
| 102 // The current application state, a bitfield of State enum values. | 114 // The current application state, a bitfield of State enum values. |
| 103 int state_; | 115 int state_; |
| 104 | 116 |
| 105 gfx::ShadowValues icon_shadows_; | 117 gfx::ShadowValues icon_shadows_; |
| 106 | 118 |
| 107 // If non-null the destuctor sets this to true. This is set while the menu is | 119 // If non-null the destuctor sets this to true. This is set while the menu is |
| 108 // showing and used to detect if the menu was deleted while running. | 120 // showing and used to detect if the menu was deleted while running. |
| 109 bool* destroyed_flag_; | 121 bool* destroyed_flag_; |
| 110 | 122 |
| 111 DISALLOW_COPY_AND_ASSIGN(ShelfButton); | 123 DISALLOW_COPY_AND_ASSIGN(ShelfButton); |
| 112 }; | 124 }; |
| 113 | 125 |
| 114 } // namespace ash | 126 } // namespace ash |
| 115 | 127 |
| 116 #endif // ASH_SHELF_SHELF_BUTTON_H_ | 128 #endif // ASH_SHELF_SHELF_BUTTON_H_ |
| OLD | NEW |