| 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_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_ | 5 #ifndef ASH_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_ |
| 6 #define ASH_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_ | 6 #define ASH_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_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/views/view.h" | 10 #include "ui/views/view.h" |
| 11 | 11 |
| 12 namespace ash { | 12 namespace ash { |
| 13 class SystemTrayItem; |
| 13 | 14 |
| 14 // A focusable view that performs an action when user clicks on it, or presses | 15 // A focusable view that performs an action when user clicks on it, or presses |
| 15 // enter or space when focused. Note that the action is triggered on mouse-up, | 16 // enter or space when focused. Note that the action is triggered on mouse-up, |
| 16 // instead of on mouse-down. So if user presses the mouse on the view, then | 17 // instead of on mouse-down. So if user presses the mouse on the view, then |
| 17 // moves the mouse out of the view and then releases, then the action will not | 18 // moves the mouse out of the view and then releases, then the action will not |
| 18 // be performed. | 19 // be performed. |
| 19 // Exported for SystemTray. | 20 // Exported for SystemTray. |
| 20 class ASH_EXPORT ActionableView : public views::View { | 21 class ASH_EXPORT ActionableView : public views::View { |
| 21 public: | 22 public: |
| 22 static const char kViewClassName[]; | 23 static const char kViewClassName[]; |
| 23 | 24 |
| 24 ActionableView(); | 25 // The owner is used to close the system tray bubble. Can be null if |
| 26 // the action will not close the bubble. |
| 27 explicit ActionableView(SystemTrayItem* owner); |
| 25 | 28 |
| 26 ~ActionableView() override; | 29 ~ActionableView() override; |
| 27 | 30 |
| 28 void SetAccessibleName(const base::string16& name); | 31 void SetAccessibleName(const base::string16& name); |
| 29 const base::string16& accessible_name() const { return accessible_name_; } | 32 const base::string16& accessible_name() const { return accessible_name_; } |
| 30 | 33 |
| 34 // Closes the system tray bubble. The |owner_| must not be nullptr. |
| 35 void CloseSystemBubble(); |
| 36 |
| 31 protected: | 37 protected: |
| 38 SystemTrayItem* owner() { return owner_; } |
| 39 |
| 32 void OnPaintFocus(gfx::Canvas* canvas); | 40 void OnPaintFocus(gfx::Canvas* canvas); |
| 33 | 41 |
| 34 // Returns the bounds to paint the focus rectangle in. | 42 // Returns the bounds to paint the focus rectangle in. |
| 35 virtual gfx::Rect GetFocusBounds(); | 43 virtual gfx::Rect GetFocusBounds(); |
| 36 | 44 |
| 37 // Performs an action when user clicks on the view (on mouse-press event), or | 45 // Performs an action when user clicks on the view (on mouse-press event), or |
| 38 // presses a key when this view is in focus. Returns true if the event has | 46 // presses a key when this view is in focus. Returns true if the event has |
| 39 // been handled and an action was performed. Returns false otherwise. | 47 // been handled and an action was performed. Returns false otherwise. |
| 40 virtual bool PerformAction(const ui::Event& event) = 0; | 48 virtual bool PerformAction(const ui::Event& event) = 0; |
| 41 | 49 |
| 42 // Overridden from views::View. | 50 // Overridden from views::View. |
| 43 const char* GetClassName() const override; | 51 const char* GetClassName() const override; |
| 44 bool OnKeyPressed(const ui::KeyEvent& event) override; | 52 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 45 bool OnMousePressed(const ui::MouseEvent& event) override; | 53 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 46 void OnMouseReleased(const ui::MouseEvent& event) override; | 54 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 47 void OnMouseCaptureLost() override; | 55 void OnMouseCaptureLost() override; |
| 48 void GetAccessibleState(ui::AXViewState* state) override; | 56 void GetAccessibleState(ui::AXViewState* state) override; |
| 49 void OnPaint(gfx::Canvas* canvas) override; | 57 void OnPaint(gfx::Canvas* canvas) override; |
| 50 void OnFocus() override; | 58 void OnFocus() override; |
| 51 void OnBlur() override; | 59 void OnBlur() override; |
| 52 | 60 |
| 53 // Overridden from ui::EventHandler. | 61 // Overridden from ui::EventHandler. |
| 54 void OnGestureEvent(ui::GestureEvent* event) override; | 62 void OnGestureEvent(ui::GestureEvent* event) override; |
| 55 | 63 |
| 56 private: | 64 private: |
| 65 SystemTrayItem* owner_; |
| 66 |
| 57 base::string16 accessible_name_; | 67 base::string16 accessible_name_; |
| 58 bool has_capture_; | 68 bool has_capture_; |
| 59 | 69 |
| 60 DISALLOW_COPY_AND_ASSIGN(ActionableView); | 70 DISALLOW_COPY_AND_ASSIGN(ActionableView); |
| 61 }; | 71 }; |
| 62 | 72 |
| 63 } // namespace ash | 73 } // namespace ash |
| 64 | 74 |
| 65 #endif // ASH_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_ | 75 #endif // ASH_COMMON_SYSTEM_TRAY_ACTIONABLE_VIEW_H_ |
| OLD | NEW |