Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: ash/common/system/tray/actionable_view.h

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/system/toast/toast_overlay.cc ('k') | ash/common/system/tray/actionable_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_
6 #define ASH_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_
7
8 #include "ash/ash_export.h"
9 #include "ash/common/system/tray/tray_popup_ink_drop_style.h"
10 #include "base/macros.h"
11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/views/controls/button/custom_button.h"
13
14 namespace ash {
15 class SystemTrayItem;
16
17 // A focusable view that performs an action when user clicks on it, or presses
18 // enter or space when focused. Note that the action is triggered on mouse-up,
19 // instead of on mouse-down. So if user presses the mouse on the view, then
20 // moves the mouse out of the view and then releases, then the action will not
21 // be performed.
22 // Exported for SystemTray.
23 //
24 // TODO(bruthig): Consider removing ActionableView and make clients use
25 // CustomButtons instead. (See crbug.com/614453)
26 class ASH_EXPORT ActionableView : public views::ButtonListener,
27 public views::CustomButton {
28 public:
29 static const char kViewClassName[];
30
31 // The owner is used to close the system tray bubble. Can be null if
32 // the action will not close the bubble.
33 ActionableView(SystemTrayItem* owner, TrayPopupInkDropStyle ink_drop_style);
34
35 ~ActionableView() override;
36
37 void SetAccessibleName(const base::string16& name);
38 const base::string16& accessible_name() const { return accessible_name_; }
39
40 // Closes the system tray bubble. The |owner_| must not be nullptr.
41 void CloseSystemBubble();
42
43 protected:
44 SystemTrayItem* owner() { return owner_; }
45
46 // Draws focus rectangle on the canvas.
47 // Default implementation draws the focus rectangle with certain inset and
48 // color. Subclasses can override to change the default settings.
49 virtual void OnPaintFocus(gfx::Canvas* canvas);
50
51 // Performs an action when user clicks on the view (on mouse-press event), or
52 // presses a key when this view is in focus. Returns true if the event has
53 // been handled and an action was performed. Returns false otherwise.
54 virtual bool PerformAction(const ui::Event& event) = 0;
55
56 // Called after PerformAction() to act upon its result, including showing
57 // appropriate ink drop ripple. This will not get called if the view is
58 // destroyed during PerformAction(). Default implementation shows triggered
59 // ripple if action is performed or hides existing ripple if no action is
60 // performed. Subclasses can override to change the default behavior.
61 virtual void HandlePerformActionResult(bool action_performed,
62 const ui::Event& event);
63
64 // Overridden from views::CustomButton.
65 const char* GetClassName() const override;
66 bool OnKeyPressed(const ui::KeyEvent& event) override;
67 void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
68 void OnPaint(gfx::Canvas* canvas) override;
69 void OnFocus() override;
70 void OnBlur() override;
71 std::unique_ptr<views::InkDrop> CreateInkDrop() override;
72 std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
73 std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
74 const override;
75 std::unique_ptr<views::InkDropMask> CreateInkDropMask() const override;
76
77 // Overridden from views::ButtonListener.
78 void ButtonPressed(Button* sender, const ui::Event& event) override;
79
80 private:
81 // Used by ButtonPressed() to determine whether |this| has been destroyed as a
82 // result of performing the associated action. This is necessary because in
83 // the not-destroyed case ButtonPressed() uses member variables.
84 bool* destroyed_;
85
86 SystemTrayItem* owner_;
87
88 base::string16 accessible_name_;
89
90 // Defines the flavor of ink drop ripple/highlight that should be constructed.
91 TrayPopupInkDropStyle ink_drop_style_;
92
93 DISALLOW_COPY_AND_ASSIGN(ActionableView);
94 };
95
96 // An ActionableView that can be used with a ButtonListener instead of having to
97 // extend ActionableView and override PerformAction().
98 class ASH_EXPORT ButtonListenerActionableView : public ActionableView {
99 public:
100 ButtonListenerActionableView(SystemTrayItem* owner,
101 TrayPopupInkDropStyle ink_drop_style,
102 views::ButtonListener* listener);
103
104 // ActionableView:
105 bool PerformAction(const ui::Event& event) override;
106
107 private:
108 views::ButtonListener* listener_;
109
110 DISALLOW_COPY_AND_ASSIGN(ButtonListenerActionableView);
111 };
112
113 } // namespace ash
114
115 #endif // ASH_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_
OLDNEW
« no previous file with comments | « ash/common/system/toast/toast_overlay.cc ('k') | ash/common/system/tray/actionable_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698