| 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..5059fea95663ab763be00296b10607f12dc6bce4
|
| --- /dev/null
|
| +++ b/ash/common/system/tray/system_menu_toggle_button.h
|
| @@ -0,0 +1,74 @@
|
| +// 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.
|
| +class SystemMenuToggleButton : public views::Button,
|
| + public views::ButtonListener,
|
| + 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::ButtonListener:
|
| + void ButtonPressed(Button* sender, const ui::Event& event) 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::ButtonListener* listener_ = nullptr;
|
| + 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_
|
|
|