Chromium Code Reviews| 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 // TODO(tdanderson): Deprecate TrayPopupHeaderButton in favor of | |
| 24 // SystemMenuButton once material design is enabled by default. See | |
| 25 // crbug.com/614453. | |
|
varkha
2016/11/17 01:51:48
self review - remove the 3 lines above.
| |
| 26 class SystemMenuToggleButton : public views::Button, | |
| 27 public views::FocusChangeListener { | |
| 28 public: | |
| 29 // Constructs the button with |listener| and a centered toggle button | |
| 30 // |accessible_name_id| corresponds to the string in ui::ResourceBundle to use | |
| 31 // for the button's accessible and tooltip text. | |
| 32 SystemMenuToggleButton(views::ButtonListener* listener, | |
| 33 int accessible_name_id); | |
| 34 ~SystemMenuToggleButton() override; | |
| 35 | |
| 36 // This class passes on state management to the embedded ToggleView. | |
| 37 void SetIsOn(bool is_on, bool animate); | |
| 38 bool is_on() const; | |
| 39 | |
| 40 protected: | |
| 41 views::Painter* focus_painter() { return focus_painter_.get(); } | |
| 42 | |
| 43 // views::View: | |
| 44 void NativeViewHierarchyChanged() override; | |
| 45 void ViewHierarchyChanged( | |
| 46 const ViewHierarchyChangedDetails& details) override; | |
| 47 gfx::Size GetPreferredSize() const override; | |
| 48 int GetHeightForWidth(int w) const override; | |
| 49 void OnPaint(gfx::Canvas* canvas) override; | |
| 50 | |
| 51 // views::FocusChangeListener: | |
| 52 void OnWillChangeFocus(View* focused_before, View* focused_now) override; | |
| 53 void OnDidChangeFocus(View* focused_before, View* focused_now) override; | |
| 54 | |
| 55 private: | |
| 56 // Registers this class as a focus observer to obtain focus activations on | |
| 57 // |toggle_|. | |
| 58 void RegisterFocusObserver(); | |
| 59 | |
| 60 // Unregisters this class as a focus observer. | |
| 61 void UnregisterFocusObserver(); | |
| 62 | |
| 63 std::unique_ptr<views::Painter> focus_painter_; | |
| 64 views::FocusManager* focus_manager_ = nullptr; | |
| 65 views::ToggleButton* toggle_ = nullptr; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(SystemMenuToggleButton); | |
| 68 }; | |
| 69 | |
| 70 } // namespace ash | |
| 71 | |
| 72 #endif // ASH_COMMON_SYSTEM_TRAY_SYSTEM_MENU_TOGGLE_BUTTON_H_ | |
| OLD | NEW |