cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ash / shelf / shelf_button.h
blob2cd7da84a61605fc5fbba1ef86f660c73c46f61f
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.
5 #ifndef ASH_SHELF_SHELF_BUTTON_H_
6 #define ASH_SHELF_SHELF_BUTTON_H_
8 #include "ash/ash_export.h"
9 #include "ui/gfx/shadow_value.h"
10 #include "ui/views/controls/button/custom_button.h"
11 #include "ui/views/controls/image_view.h"
13 namespace ash {
14 class ShelfButtonHost;
15 class ShelfLayoutManager;
17 // Button used for items on the launcher, except for the AppList.
18 class ASH_EXPORT ShelfButton : public views::CustomButton {
19 public:
20 static const char kViewClassName[];
22 // Used to indicate the current state of the button.
23 enum State {
24 // Nothing special. Usually represents an app shortcut item with no running
25 // instance.
26 STATE_NORMAL = 0,
27 // Button has mouse hovering on it.
28 STATE_HOVERED = 1 << 0,
29 // Underlying ShelfItem has a running instance.
30 STATE_RUNNING = 1 << 1,
31 // Underlying ShelfItem is active (i.e. has focus).
32 STATE_ACTIVE = 1 << 2,
33 // Underlying ShelfItem needs user's attention.
34 STATE_ATTENTION = 1 << 3,
35 STATE_FOCUSED = 1 << 4,
36 // Hide the status (temporarily for some animations).
37 STATE_HIDDEN = 1 << 5,
40 ~ShelfButton() override;
42 // Called to create an instance of a ShelfButton.
43 static ShelfButton* Create(views::ButtonListener* listener,
44 ShelfButtonHost* host,
45 ShelfLayoutManager* shelf_layout_manager);
47 // Sets the image to display for this entry.
48 void SetImage(const gfx::ImageSkia& image);
50 // Retrieve the image to show proxy operations.
51 const gfx::ImageSkia& GetImage() const;
53 // |state| is or'd into the current state.
54 void AddState(State state);
55 void ClearState(State state);
56 int state() const { return state_; }
57 const ShelfLayoutManager* shelf_layout_manager() const {
58 return shelf_layout_manager_;
61 // Returns the bounds of the icon.
62 gfx::Rect GetIconBounds() const;
64 // Overrides to views::CustomButton:
65 void ShowContextMenu(const gfx::Point& p,
66 ui::MenuSourceType source_type) override;
68 // View override - needed by unit test.
69 void OnMouseCaptureLost() override;
71 protected:
72 ShelfButton(views::ButtonListener* listener,
73 ShelfButtonHost* host,
74 ShelfLayoutManager* shelf_layout_manager);
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
78 // implementation, by overriding CreateIconView().
79 class IconView : public views::ImageView {
80 public:
81 IconView();
82 ~IconView() override;
84 void set_icon_size(int icon_size) { icon_size_ = icon_size; }
85 int icon_size() const { return icon_size_; }
87 private:
88 // Set to non-zero to force icons to be resized to fit within a square,
89 // while maintaining original proportions.
90 int icon_size_;
92 DISALLOW_COPY_AND_ASSIGN(IconView);
95 // View overrides:
96 const char* GetClassName() const override;
97 bool OnMousePressed(const ui::MouseEvent& event) override;
98 void OnMouseReleased(const ui::MouseEvent& event) override;
99 bool OnMouseDragged(const ui::MouseEvent& event) override;
100 void OnMouseMoved(const ui::MouseEvent& event) override;
101 void OnMouseEntered(const ui::MouseEvent& event) override;
102 void OnMouseExited(const ui::MouseEvent& event) override;
103 void GetAccessibleState(ui::AXViewState* state) override;
104 void Layout() override;
105 void ChildPreferredSizeChanged(views::View* child) override;
106 void OnFocus() override;
107 void OnBlur() override;
108 void OnPaint(gfx::Canvas* canvas) override;
110 // ui::EventHandler overrides:
111 void OnGestureEvent(ui::GestureEvent* event) override;
113 // Sets the icon image with a shadow.
114 void SetShadowedImage(const gfx::ImageSkia& bitmap);
115 // Override for custom initialization.
116 virtual void Init();
117 // Override to subclass IconView.
118 virtual IconView* CreateIconView();
119 IconView* icon_view() const { return icon_view_; }
120 ShelfButtonHost* host() const { return host_; }
122 private:
123 class BarView;
125 // Returns true if the shelf is horizontal. If this returns false the shelf is
126 // vertical.
127 bool IsShelfHorizontal() const;
129 // Updates the parts of the button to reflect the current |state_| and
130 // alignment. This may add or remove views, layout and paint.
131 void UpdateState();
133 // Updates the status bar (bitmap, orientation, visibility).
134 void UpdateBar();
136 ShelfButtonHost* host_;
137 IconView* icon_view_;
138 // Draws a bar underneath the image to represent the state of the application.
139 BarView* bar_;
140 // The current state of the application, multiple values of AppState are or'd
141 // together.
142 int state_;
144 ShelfLayoutManager* shelf_layout_manager_;
146 gfx::ShadowValues icon_shadows_;
148 // If non-null the destuctor sets this to true. This is set while the menu is
149 // showing and used to detect if the menu was deleted while running.
150 bool* destroyed_flag_;
152 DISALLOW_COPY_AND_ASSIGN(ShelfButton);
155 } // namespace ash
157 #endif // ASH_SHELF_SHELF_BUTTON_H_