Chromium Code Reviews| Index: ash/common/system/tray/system_menu_toggle_button.h |
| diff --git a/ash/common/system/tray/system_menu_toggle_button.h b/ash/common/system/tray/system_menu_toggle_button.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3176ed220a97cc686a36fe96e1f5436949343ad3 |
| --- /dev/null |
| +++ b/ash/common/system/tray/system_menu_toggle_button.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef ASH_COMMON_SYSTEM_TRAY_SYSTEM_MENU_TOGGLE_BUTTON_H_ |
| +#define ASH_COMMON_SYSTEM_TRAY_SYSTEM_MENU_TOGGLE_BUTTON_H_ |
| + |
| +#include "base/macros.h" |
| +#include "ui/views/controls/button/button.h" |
| +#include "ui/views/focus/focus_manager.h" |
| + |
| +namespace views { |
| + |
| +class Painter; |
| +class ToggleButton; |
| + |
| +} // namespace views; |
| + |
| +namespace ash { |
| + |
| +// A 48x48 toggle button with a focus rectangle, which can be used across Ash |
| +// material design native UI menus. |
| +// TODO(tdanderson): Deprecate TrayPopupHeaderButton in favor of |
| +// SystemMenuButton once material design is enabled by default. See |
| +// crbug.com/614453. |
|
varkha
2016/11/17 01:51:48
self review - remove the 3 lines above.
|
| +class SystemMenuToggleButton : public views::Button, |
| + public views::FocusChangeListener { |
| + public: |
| + // Constructs the button with |listener| and a centered toggle button |
| + // |accessible_name_id| corresponds to the string in ui::ResourceBundle to use |
| + // for the button's accessible and tooltip text. |
| + SystemMenuToggleButton(views::ButtonListener* listener, |
| + int accessible_name_id); |
| + ~SystemMenuToggleButton() override; |
| + |
| + // This class passes on state management to the embedded ToggleView. |
| + void SetIsOn(bool is_on, bool animate); |
| + bool is_on() const; |
| + |
| + protected: |
| + views::Painter* focus_painter() { return focus_painter_.get(); } |
| + |
| + // views::View: |
| + void NativeViewHierarchyChanged() override; |
| + void ViewHierarchyChanged( |
| + const ViewHierarchyChangedDetails& details) override; |
| + gfx::Size GetPreferredSize() const override; |
| + int GetHeightForWidth(int w) const override; |
| + void OnPaint(gfx::Canvas* canvas) override; |
| + |
| + // views::FocusChangeListener: |
| + void OnWillChangeFocus(View* focused_before, View* focused_now) override; |
| + void OnDidChangeFocus(View* focused_before, View* focused_now) override; |
| + |
| + private: |
| + // Registers this class as a focus observer to obtain focus activations on |
| + // |toggle_|. |
| + void RegisterFocusObserver(); |
| + |
| + // Unregisters this class as a focus observer. |
| + void UnregisterFocusObserver(); |
| + |
| + std::unique_ptr<views::Painter> focus_painter_; |
| + views::FocusManager* focus_manager_ = nullptr; |
| + views::ToggleButton* toggle_ = nullptr; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SystemMenuToggleButton); |
| +}; |
| + |
| +} // namespace ash |
| + |
| +#endif // ASH_COMMON_SYSTEM_TRAY_SYSTEM_MENU_TOGGLE_BUTTON_H_ |