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