| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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_SYSTEM_MENU_TOGGLE_BUTTON_H_ |
| 6 #define ASH_COMMON_SYSTEM_TRAY_SYSTEM_MENU_TOGGLE_BUTTON_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "ui/views/controls/button/button.h" |
| 10 #include "ui/views/focus/focus_manager.h" |
| 11 |
| 12 namespace views { |
| 13 |
| 14 class Painter; |
| 15 class ToggleButton; |
| 16 |
| 17 } // namespace views; |
| 18 |
| 19 namespace ash { |
| 20 |
| 21 // A 48x48 toggle button with a focus rectangle, which can be used across Ash |
| 22 // material design native UI menus. |
| 23 class SystemMenuToggleButton : public views::Button, |
| 24 public views::ButtonListener, |
| 25 public views::FocusChangeListener { |
| 26 public: |
| 27 // Constructs the button with |listener| and a centered toggle button |
| 28 // |accessible_name_id| corresponds to the string in ui::ResourceBundle to use |
| 29 // for the button's accessible and tooltip text. |
| 30 SystemMenuToggleButton(views::ButtonListener* listener, |
| 31 int accessible_name_id); |
| 32 ~SystemMenuToggleButton() override; |
| 33 |
| 34 // This class passes on state management to the embedded ToggleView. |
| 35 void SetIsOn(bool is_on, bool animate); |
| 36 bool is_on() const; |
| 37 |
| 38 protected: |
| 39 views::Painter* focus_painter() { return focus_painter_.get(); } |
| 40 |
| 41 // views::View: |
| 42 void NativeViewHierarchyChanged() override; |
| 43 void ViewHierarchyChanged( |
| 44 const ViewHierarchyChangedDetails& details) override; |
| 45 gfx::Size GetPreferredSize() const override; |
| 46 int GetHeightForWidth(int w) const override; |
| 47 void OnPaint(gfx::Canvas* canvas) override; |
| 48 |
| 49 // views::ButtonListener: |
| 50 void ButtonPressed(Button* sender, const ui::Event& event) override; |
| 51 |
| 52 // views::FocusChangeListener: |
| 53 void OnWillChangeFocus(View* focused_before, View* focused_now) override; |
| 54 void OnDidChangeFocus(View* focused_before, View* focused_now) override; |
| 55 |
| 56 private: |
| 57 // Registers this class as a focus observer to obtain focus activations on |
| 58 // |toggle_|. |
| 59 void RegisterFocusObserver(); |
| 60 |
| 61 // Unregisters this class as a focus observer. |
| 62 void UnregisterFocusObserver(); |
| 63 |
| 64 std::unique_ptr<views::Painter> focus_painter_; |
| 65 views::ButtonListener* listener_ = nullptr; |
| 66 views::FocusManager* focus_manager_ = nullptr; |
| 67 views::ToggleButton* toggle_ = nullptr; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(SystemMenuToggleButton); |
| 70 }; |
| 71 |
| 72 } // namespace ash |
| 73 |
| 74 #endif // ASH_COMMON_SYSTEM_TRAY_SYSTEM_MENU_TOGGLE_BUTTON_H_ |
| OLD | NEW |