Commit 86ef81d7 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Remove ButtonListener in favor of callbacks. Other cleanup.

Add metadata - remove manually overridden GetClassName.

Add view builders and update view tree construction to use the builder.

TBR=katie@chromium.org

Bug: 772945, 938501, 1130078
Change-Id: Id105b26afb15138ee6e70e7ade5e43be11671a47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505880Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Reviewed-by: default avatarTetsui Ohkubo <tetsui@chromium.org>
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Auto-Submit: Allen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824581}
parent 899eea0a
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#include "ash/public/cpp/accessibility_controller_enums.h" #include "ash/public/cpp/accessibility_controller_enums.h"
#include "ash/system/tray/tray_bubble_view.h" #include "ash/system/tray/tray_bubble_view.h"
#include "ui/views/controls/button/button.h" #include "ui/views/layout/box_layout_view.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/view_factory.h"
namespace ash { namespace ash {
...@@ -15,8 +17,10 @@ class FloatingMenuButton; ...@@ -15,8 +17,10 @@ class FloatingMenuButton;
// View for the Automatic Clicks Menu, which creates and manages // View for the Automatic Clicks Menu, which creates and manages
// individual buttons to control Automatic Clicks settings. // individual buttons to control Automatic Clicks settings.
class AutoclickMenuView : public views::View, public views::ButtonListener { class AutoclickMenuView : public views::BoxLayoutView {
public: public:
METADATA_HEADER(AutoclickMenuView);
// Used for testing. Start at 1 because a view IDs should not be 0. // Used for testing. Start at 1 because a view IDs should not be 0.
enum class ButtonId { enum class ButtonId {
kPosition = 1, kPosition = 1,
...@@ -29,35 +33,37 @@ class AutoclickMenuView : public views::View, public views::ButtonListener { ...@@ -29,35 +33,37 @@ class AutoclickMenuView : public views::View, public views::ButtonListener {
}; };
AutoclickMenuView(AutoclickEventType type, FloatingMenuPosition position); AutoclickMenuView(AutoclickEventType type, FloatingMenuPosition position);
AutoclickMenuView(const AutoclickMenuView&) = delete;
AutoclickMenuView& operator=(const AutoclickMenuView&) = delete;
~AutoclickMenuView() override = default; ~AutoclickMenuView() override = default;
void UpdateEventType(AutoclickEventType type); void UpdateEventType(AutoclickEventType type);
void UpdatePosition(FloatingMenuPosition position); void UpdatePosition(FloatingMenuPosition position);
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::View:
const char* GetClassName() const override;
private: private:
void OnAutoclickButtonPressed(views::Button* sender);
void OnPositionButtonPressed();
// Unowned. Owned by views hierarchy. // Unowned. Owned by views hierarchy.
FloatingMenuButton* left_click_button_; FloatingMenuButton* left_click_button_ = nullptr;
FloatingMenuButton* right_click_button_; FloatingMenuButton* right_click_button_ = nullptr;
FloatingMenuButton* double_click_button_; FloatingMenuButton* double_click_button_ = nullptr;
FloatingMenuButton* drag_button_; FloatingMenuButton* drag_button_ = nullptr;
FloatingMenuButton* scroll_button_ = nullptr; FloatingMenuButton* scroll_button_ = nullptr;
FloatingMenuButton* pause_button_; FloatingMenuButton* pause_button_ = nullptr;
FloatingMenuButton* position_button_; FloatingMenuButton* position_button_ = nullptr;
// The most recently selected event_type_ excluding kNoAction. This is used // The most recently selected event_type_ excluding kNoAction. This is used
// when the pause button is selected in order to unpause and reset to the // when the pause button is selected in order to unpause and reset to the
// previous state. // previous state.
AutoclickEventType event_type_ = AutoclickEventType::kLeftClick; AutoclickEventType event_type_ = AutoclickEventType::kLeftClick;
DISALLOW_COPY_AND_ASSIGN(AutoclickMenuView);
}; };
BEGIN_VIEW_BUILDER(/* no export */, AutoclickMenuView, views::BoxLayoutView)
END_VIEW_BUILDER
} // namespace ash } // namespace ash
DEFINE_VIEW_BUILDER(/* no export */, ash::AutoclickMenuView)
#endif // ASH_SYSTEM_ACCESSIBILITY_AUTOCLICK_MENU_VIEW_H_ #endif // ASH_SYSTEM_ACCESSIBILITY_AUTOCLICK_MENU_VIEW_H_
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/system/accessibility/autoclick_menu_bubble_controller.h" #include "ash/system/accessibility/autoclick_menu_bubble_controller.h"
#include "ash/system/accessibility/floating_menu_button.h" #include "ash/system/accessibility/floating_menu_button.h"
#include "ash/system/unified/custom_shape_button.h" #include "ash/system/unified/custom_shape_button.h"
#include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
...@@ -21,6 +22,8 @@ ...@@ -21,6 +22,8 @@
#include "ui/gfx/vector_icon_types.h" #include "ui/gfx/vector_icon_types.h"
#include "ui/views/controls/highlight_path_generator.h" #include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/masked_targeter_delegate.h" #include "ui/views/masked_targeter_delegate.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace ash { namespace ash {
...@@ -44,25 +47,30 @@ SkColor HoveredButtonColor() { ...@@ -44,25 +47,30 @@ SkColor HoveredButtonColor() {
} // namespace } // namespace
// The close button for the automatic clicks scroll bubble. // The close button for the automatic clicks scroll bubble.
class AutoclickScrollCloseButton : public FloatingMenuButton, class AutoclickScrollCloseButton : public FloatingMenuButton {
public views::ButtonListener {
public: public:
METADATA_HEADER(AutoclickScrollCloseButton);
AutoclickScrollCloseButton() AutoclickScrollCloseButton()
: FloatingMenuButton(this, : FloatingMenuButton(
kAutoclickCloseIcon, base::BindRepeating(&AutoclickScrollCloseButton::OnButtonPressed,
IDS_ASH_AUTOCLICK_SCROLL_CLOSE, base::Unretained(this)),
/*flip_for_rtl=*/false, kAutoclickCloseIcon,
kScrollButtonCloseSizeDips, IDS_ASH_AUTOCLICK_SCROLL_CLOSE,
/*draw_highlight=*/false, /*flip_for_rtl=*/false,
/*is_a11y_togglable=*/false) { kScrollButtonCloseSizeDips,
/*draw_highlight=*/false,
/*is_a11y_togglable=*/false) {
views::View::SetID( views::View::SetID(
static_cast<int>(AutoclickScrollView::ButtonId::kCloseScroll)); static_cast<int>(AutoclickScrollView::ButtonId::kCloseScroll));
} }
AutoclickScrollCloseButton(const AutoclickScrollCloseButton&) = delete;
AutoclickScrollCloseButton& operator=(const AutoclickScrollCloseButton&) =
delete;
~AutoclickScrollCloseButton() override = default; ~AutoclickScrollCloseButton() override = default;
// views::ButtonListener: void OnButtonPressed() {
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
Shell::Get()->autoclick_controller()->DoScrollAction( Shell::Get()->autoclick_controller()->DoScrollAction(
AutoclickController::ScrollPadAction::kScrollClose); AutoclickController::ScrollPadAction::kScrollClose);
base::RecordAction(base::UserMetricsAction( base::RecordAction(base::UserMetricsAction(
...@@ -94,28 +102,28 @@ class AutoclickScrollCloseButton : public FloatingMenuButton, ...@@ -94,28 +102,28 @@ class AutoclickScrollCloseButton : public FloatingMenuButton,
views::ImageButton::PaintButtonContents(canvas); views::ImageButton::PaintButtonContents(canvas);
} }
const char* GetClassName() const override {
return "AutoclickScrollCloseButton";
}
private: private:
bool hovered_ = false; bool hovered_ = false;
DISALLOW_COPY_AND_ASSIGN(AutoclickScrollCloseButton);
}; };
BEGIN_METADATA(AutoclickScrollCloseButton, FloatingMenuButton)
END_METADATA
// A single scroll button (up/down/left/right) for automatic clicks scroll // A single scroll button (up/down/left/right) for automatic clicks scroll
// bubble. Subclasses a MaskedTargeterDelegate in order to only get events over // bubble. Subclasses a MaskedTargeterDelegate in order to only get events over
// the button's custom shape, rather than over the whole rectangle which // the button's custom shape, rather than over the whole rectangle which
// encloses the button. // encloses the button.
class AutoclickScrollButton : public CustomShapeButton, class AutoclickScrollButton : public CustomShapeButton,
public views::MaskedTargeterDelegate, public views::MaskedTargeterDelegate {
public views::ButtonListener {
public: public:
METADATA_HEADER(AutoclickScrollButton);
AutoclickScrollButton(AutoclickController::ScrollPadAction action, AutoclickScrollButton(AutoclickController::ScrollPadAction action,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
int accessible_name_id, int accessible_name_id,
AutoclickScrollView::ButtonId id) AutoclickScrollView::ButtonId id)
: CustomShapeButton(PressedCallback(this, this)), : CustomShapeButton(
base::BindRepeating(&AutoclickScrollButton::OnButtonPressed,
base::Unretained(this))),
action_(action), action_(action),
icon_(icon) { icon_(icon) {
views::View::SetID(static_cast<int>(id)); views::View::SetID(static_cast<int>(id));
...@@ -145,6 +153,8 @@ class AutoclickScrollButton : public CustomShapeButton, ...@@ -145,6 +153,8 @@ class AutoclickScrollButton : public CustomShapeButton,
views::InstallRoundRectHighlightPathGenerator(this, gfx::Insets(), 0.f); views::InstallRoundRectHighlightPathGenerator(this, gfx::Insets(), 0.f);
} }
AutoclickScrollButton(const AutoclickScrollButton&) = delete;
AutoclickScrollButton& operator=(const AutoclickScrollButton&) = delete;
~AutoclickScrollButton() override { ~AutoclickScrollButton() override {
Shell::Get()->autoclick_controller()->OnExitedScrollButton(); Shell::Get()->autoclick_controller()->OnExitedScrollButton();
...@@ -180,10 +190,7 @@ class AutoclickScrollButton : public CustomShapeButton, ...@@ -180,10 +190,7 @@ class AutoclickScrollButton : public CustomShapeButton,
scroll_hover_timer_->Reset(); scroll_hover_timer_->Reset();
} }
// views::ButtonListener: void OnButtonPressed() { ProcessAction(action_); }
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
ProcessAction(action_);
}
// CustomShapeButton: // CustomShapeButton:
SkPath CreateCustomShapePath(const gfx::Rect& bounds) const override { SkPath CreateCustomShapePath(const gfx::Rect& bounds) const override {
...@@ -315,18 +322,17 @@ class AutoclickScrollButton : public CustomShapeButton, ...@@ -315,18 +322,17 @@ class AutoclickScrollButton : public CustomShapeButton,
SchedulePaint(); SchedulePaint();
} }
const char* GetClassName() const override { return "AutoclickScrollButton"; }
private: private:
const AutoclickController::ScrollPadAction action_; const AutoclickController::ScrollPadAction action_;
gfx::Size size_; gfx::Size size_;
std::unique_ptr<base::RetainingOneShotTimer> scroll_hover_timer_; std::unique_ptr<base::RetainingOneShotTimer> scroll_hover_timer_;
bool active_ = false; bool active_ = false;
const gfx::VectorIcon& icon_; const gfx::VectorIcon& icon_;
DISALLOW_COPY_AND_ASSIGN(AutoclickScrollButton);
}; };
BEGIN_METADATA(AutoclickScrollButton, CustomShapeButton)
END_METADATA
// ------ AutoclickScrollBubbleView ------ // // ------ AutoclickScrollBubbleView ------ //
AutoclickScrollBubbleView::AutoclickScrollBubbleView( AutoclickScrollBubbleView::AutoclickScrollBubbleView(
......
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
#include "ash/system/accessibility/select_to_speak_tray.h" #include "ash/system/accessibility/select_to_speak_tray.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/virtual_keyboard/virtual_keyboard_tray.h" #include "ash/system/virtual_keyboard/virtual_keyboard_tray.h"
#include "base/bind.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/separator.h" #include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
namespace ash { namespace ash {
...@@ -109,15 +111,11 @@ bool FloatingAccessibilityBubbleView::AcceleratorPressed( ...@@ -109,15 +111,11 @@ bool FloatingAccessibilityBubbleView::AcceleratorPressed(
return true; return true;
} }
const char* FloatingAccessibilityBubbleView::GetClassName() const { BEGIN_METADATA(FloatingAccessibilityBubbleView, TrayBubbleView)
return "FloatingAccessibilityBubbleView"; END_METADATA
}
FloatingAccessibilityView::FloatingAccessibilityView(Delegate* delegate) FloatingAccessibilityView::FloatingAccessibilityView(Delegate* delegate)
: delegate_(delegate) { : delegate_(delegate) {
std::unique_ptr<views::BoxLayout> layout = std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(), 0);
SetLayoutManager(std::move(layout));
Shelf* shelf = RootWindowController::ForTargetRootWindow()->shelf(); Shelf* shelf = RootWindowController::ForTargetRootWindow()->shelf();
std::unique_ptr<views::View> feature_buttons_container = std::unique_ptr<views::View> feature_buttons_container =
...@@ -136,7 +134,10 @@ FloatingAccessibilityView::FloatingAccessibilityView(Delegate* delegate) ...@@ -136,7 +134,10 @@ FloatingAccessibilityView::FloatingAccessibilityView(Delegate* delegate)
CreateButtonRowContainer(kUnifiedTopShortcutSpacing); CreateButtonRowContainer(kUnifiedTopShortcutSpacing);
a11y_tray_button_ = a11y_tray_button_ =
tray_button_container->AddChildView(std::make_unique<FloatingMenuButton>( tray_button_container->AddChildView(std::make_unique<FloatingMenuButton>(
this, kUnifiedMenuAccessibilityIcon, base::BindRepeating(
&FloatingAccessibilityView::OnA11yTrayButtonPressed,
base::Unretained(this)),
kUnifiedMenuAccessibilityIcon,
IDS_ASH_FLOATING_ACCESSIBILITY_DETAILED_MENU_OPEN, IDS_ASH_FLOATING_ACCESSIBILITY_DETAILED_MENU_OPEN,
/*flip_for_rtl*/ true)); /*flip_for_rtl*/ true));
...@@ -144,7 +145,10 @@ FloatingAccessibilityView::FloatingAccessibilityView(Delegate* delegate) ...@@ -144,7 +145,10 @@ FloatingAccessibilityView::FloatingAccessibilityView(Delegate* delegate)
CreateButtonRowContainer(kPanelPositionButtonPadding); CreateButtonRowContainer(kPanelPositionButtonPadding);
position_button_ = position_button_container->AddChildView( position_button_ = position_button_container->AddChildView(
std::make_unique<FloatingMenuButton>( std::make_unique<FloatingMenuButton>(
this, kAutoclickPositionBottomLeftIcon, base::BindRepeating(
&FloatingAccessibilityView::OnPositionButtonPressed,
base::Unretained(this)),
kAutoclickPositionBottomLeftIcon,
IDS_ASH_AUTOCLICK_OPTION_CHANGE_POSITION, /*flip_for_rtl*/ false, IDS_ASH_AUTOCLICK_OPTION_CHANGE_POSITION, /*flip_for_rtl*/ false,
kPanelPositionButtonSize, false, /* is_a11y_togglable */ false)); kPanelPositionButtonSize, false, /* is_a11y_togglable */ false));
...@@ -154,8 +158,8 @@ FloatingAccessibilityView::FloatingAccessibilityView(Delegate* delegate) ...@@ -154,8 +158,8 @@ FloatingAccessibilityView::FloatingAccessibilityView(Delegate* delegate)
AddChildView(std::move(position_button_container)); AddChildView(std::move(position_button_container));
// Set view IDs for testing. // Set view IDs for testing.
position_button_->SetId(static_cast<int>(ButtonId::kPosition)); position_button_->SetID(static_cast<int>(ButtonId::kPosition));
a11y_tray_button_->SetId(static_cast<int>(ButtonId::kSettingsList)); a11y_tray_button_->SetID(static_cast<int>(ButtonId::kSettingsList));
dictation_button_->SetID(static_cast<int>(ButtonId::kDictation)); dictation_button_->SetID(static_cast<int>(ButtonId::kDictation));
select_to_speak_button_->SetID(static_cast<int>(ButtonId::kSelectToSpeak)); select_to_speak_button_->SetID(static_cast<int>(ButtonId::kSelectToSpeak));
virtual_keyboard_button_->SetID(static_cast<int>(ButtonId::kVirtualKeyboard)); virtual_keyboard_button_->SetID(static_cast<int>(ButtonId::kVirtualKeyboard));
...@@ -203,47 +207,37 @@ void FloatingAccessibilityView::FocusOnDetailedViewButton() { ...@@ -203,47 +207,37 @@ void FloatingAccessibilityView::FocusOnDetailedViewButton() {
a11y_tray_button_->RequestFocus(); a11y_tray_button_->RequestFocus();
} }
void FloatingAccessibilityView::ButtonPressed(views::Button* sender, void FloatingAccessibilityView::OnA11yTrayButtonPressed() {
const ui::Event& event) { delegate_->OnDetailedMenuEnabled(!a11y_tray_button_->GetToggled());
if (sender == a11y_tray_button_) {
delegate_->OnDetailedMenuEnabled(!a11y_tray_button_->IsToggled());
return;
}
if (sender == position_button_) {
FloatingMenuPosition new_position;
// Rotate clockwise throughout the screen positions.
switch (
Shell::Get()->accessibility_controller()->GetFloatingMenuPosition()) {
case FloatingMenuPosition::kBottomRight:
new_position = FloatingMenuPosition::kBottomLeft;
break;
case FloatingMenuPosition::kBottomLeft:
new_position = FloatingMenuPosition::kTopLeft;
break;
case FloatingMenuPosition::kTopLeft:
new_position = FloatingMenuPosition::kTopRight;
break;
case FloatingMenuPosition::kTopRight:
new_position = FloatingMenuPosition::kBottomRight;
break;
case FloatingMenuPosition::kSystemDefault:
new_position = base::i18n::IsRTL() ? FloatingMenuPosition::kTopLeft
: FloatingMenuPosition::kBottomLeft;
break;
}
Shell::Get()->accessibility_controller()->SetFloatingMenuPosition(
new_position);
Shell::Get()
->accessibility_controller()
->TriggerAccessibilityAlertWithMessage(
GetDescriptionForMovedToPosition(new_position));
}
return;
} }
const char* FloatingAccessibilityView::GetClassName() const { void FloatingAccessibilityView::OnPositionButtonPressed() {
return "AccessiblityFloatingView"; FloatingMenuPosition new_position;
// Rotate clockwise throughout the screen positions.
switch (Shell::Get()->accessibility_controller()->GetFloatingMenuPosition()) {
case FloatingMenuPosition::kBottomRight:
new_position = FloatingMenuPosition::kBottomLeft;
break;
case FloatingMenuPosition::kBottomLeft:
new_position = FloatingMenuPosition::kTopLeft;
break;
case FloatingMenuPosition::kTopLeft:
new_position = FloatingMenuPosition::kTopRight;
break;
case FloatingMenuPosition::kTopRight:
new_position = FloatingMenuPosition::kBottomRight;
break;
case FloatingMenuPosition::kSystemDefault:
new_position = base::i18n::IsRTL() ? FloatingMenuPosition::kTopLeft
: FloatingMenuPosition::kBottomLeft;
break;
}
Shell::Get()->accessibility_controller()->SetFloatingMenuPosition(
new_position);
Shell::Get()
->accessibility_controller()
->TriggerAccessibilityAlertWithMessage(
GetDescriptionForMovedToPosition(new_position));
} }
void FloatingAccessibilityView::OnViewVisibilityChanged( void FloatingAccessibilityView::OnViewVisibilityChanged(
...@@ -254,4 +248,7 @@ void FloatingAccessibilityView::OnViewVisibilityChanged( ...@@ -254,4 +248,7 @@ void FloatingAccessibilityView::OnViewVisibilityChanged(
delegate_->OnLayoutChanged(); delegate_->OnLayoutChanged();
} }
BEGIN_METADATA(FloatingAccessibilityView, views::BoxLayoutView)
END_METADATA
} // namespace ash } // namespace ash
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
#include "ash/shell_observer.h" #include "ash/shell_observer.h"
#include "ash/system/tray/tray_bubble_view.h" #include "ash/system/tray/tray_bubble_view.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/view_factory.h"
namespace ash { namespace ash {
...@@ -19,6 +22,8 @@ class TrayBackgroundView; ...@@ -19,6 +22,8 @@ class TrayBackgroundView;
class FloatingAccessibilityBubbleView : public TrayBubbleView { class FloatingAccessibilityBubbleView : public TrayBubbleView {
public: public:
METADATA_HEADER(FloatingAccessibilityBubbleView);
explicit FloatingAccessibilityBubbleView( explicit FloatingAccessibilityBubbleView(
const TrayBubbleView::InitParams& init_params); const TrayBubbleView::InitParams& init_params);
FloatingAccessibilityBubbleView(const FloatingAccessibilityBubbleView&) = FloatingAccessibilityBubbleView(const FloatingAccessibilityBubbleView&) =
...@@ -30,21 +35,24 @@ class FloatingAccessibilityBubbleView : public TrayBubbleView { ...@@ -30,21 +35,24 @@ class FloatingAccessibilityBubbleView : public TrayBubbleView {
// TrayBubbleView: // TrayBubbleView:
bool IsAnchoredToStatusArea() const override; bool IsAnchoredToStatusArea() const override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override; bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
// views::View:
const char* GetClassName() const override;
}; };
BEGIN_VIEW_BUILDER(/* no export */,
FloatingAccessibilityBubbleView,
TrayBubbleView)
END_VIEW_BUILDER
// This floating view displays the currently enabled accessibility options, // This floating view displays the currently enabled accessibility options,
// along with buttons to configure them. // along with buttons to configure them.
// ---- Layout: // ---- Layout:
// ---- ?[Dictation] ?[SelectToSpeak] ?[VirtualKeyboard] // ---- ?[Dictation] ?[SelectToSpeak] ?[VirtualKeyboard]
// ---- | [Open settings list] // ---- | [Open settings list]
// ---- | [Change menu location] // ---- | [Change menu location]
class FloatingAccessibilityView : public views::View, class FloatingAccessibilityView : public views::BoxLayoutView,
public views::ButtonListener,
public views::ViewObserver { public views::ViewObserver {
public: public:
METADATA_HEADER(FloatingAccessibilityView);
// Used for testing. Starts 1 because views IDs should not be 0. // Used for testing. Starts 1 because views IDs should not be 0.
enum ButtonId { enum ButtonId {
kPosition = 1, kPosition = 1,
...@@ -79,11 +87,8 @@ class FloatingAccessibilityView : public views::View, ...@@ -79,11 +87,8 @@ class FloatingAccessibilityView : public views::View,
void FocusOnDetailedViewButton(); void FocusOnDetailedViewButton();
private: private:
// views::ButtonListener: void OnA11yTrayButtonPressed();
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void OnPositionButtonPressed();
// views::View:
const char* GetClassName() const override;
// views::ViewObserver: // views::ViewObserver:
void OnViewVisibilityChanged(views::View* observed_view, void OnViewVisibilityChanged(views::View* observed_view,
...@@ -101,6 +106,14 @@ class FloatingAccessibilityView : public views::View, ...@@ -101,6 +106,14 @@ class FloatingAccessibilityView : public views::View,
Delegate* const delegate_; Delegate* const delegate_;
}; };
BEGIN_VIEW_BUILDER(/* no export */,
FloatingAccessibilityView,
views::BoxLayoutView)
END_VIEW_BUILDER
} // namespace ash } // namespace ash
DEFINE_VIEW_BUILDER(/* no export */, ash::FloatingAccessibilityBubbleView)
DEFINE_VIEW_BUILDER(/* no export */, ash::FloatingAccessibilityView)
#endif // ASH_SYSTEM_ACCESSIBILITY_FLOATING_ACCESSIBILITY_VIEW_H_ #endif // ASH_SYSTEM_ACCESSIBILITY_FLOATING_ACCESSIBILITY_VIEW_H_
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "ash/system/accessibility/floating_menu_button.h" #include "ash/system/accessibility/floating_menu_button.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_utils.h" #include "ash/system/tray/tray_popup_utils.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -18,14 +17,23 @@ ...@@ -18,14 +17,23 @@
#include "ui/views/animation/ink_drop_impl.h" #include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h" #include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/controls/highlight_path_generator.h" #include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/metadata/metadata_impl_macros.h"
namespace ash { namespace ash {
FloatingMenuButton::FloatingMenuButton(views::ButtonListener* listener, FloatingMenuButton::FloatingMenuButton() {
SetImageHorizontalAlignment(ALIGN_CENTER);
SetImageVerticalAlignment(ALIGN_MIDDLE);
SetFlipCanvasOnPaintForRTLUI(false);
TrayPopupUtils::ConfigureTrayPopupButton(this);
views::InstallCircleHighlightPathGenerator(this);
}
FloatingMenuButton::FloatingMenuButton(views::Button::PressedCallback callback,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
int accessible_name_id, int accessible_name_id,
bool flip_for_rtl) bool flip_for_rtl)
: FloatingMenuButton(listener, : FloatingMenuButton(callback,
icon, icon,
accessible_name_id, accessible_name_id,
flip_for_rtl, flip_for_rtl,
...@@ -33,14 +41,14 @@ FloatingMenuButton::FloatingMenuButton(views::ButtonListener* listener, ...@@ -33,14 +41,14 @@ FloatingMenuButton::FloatingMenuButton(views::ButtonListener* listener,
/*draw_highlight=*/true, /*draw_highlight=*/true,
/*is_a11y_togglable=*/true) {} /*is_a11y_togglable=*/true) {}
FloatingMenuButton::FloatingMenuButton(views::ButtonListener* listener, FloatingMenuButton::FloatingMenuButton(views::Button::PressedCallback callback,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
int accessible_name_id, int accessible_name_id,
bool flip_for_rtl, bool flip_for_rtl,
int size, int size,
bool draw_highlight, bool draw_highlight,
bool is_a11y_togglable) bool is_a11y_togglable)
: views::ImageButton(listener), : views::ImageButton(callback),
icon_(&icon), icon_(&icon),
size_(size), size_(size),
draw_highlight_(draw_highlight), draw_highlight_(draw_highlight),
...@@ -57,14 +65,44 @@ FloatingMenuButton::FloatingMenuButton(views::ButtonListener* listener, ...@@ -57,14 +65,44 @@ FloatingMenuButton::FloatingMenuButton(views::ButtonListener* listener,
FloatingMenuButton::~FloatingMenuButton() = default; FloatingMenuButton::~FloatingMenuButton() = default;
void FloatingMenuButton::SetVectorIcon(const gfx::VectorIcon& icon) { void FloatingMenuButton::SetVectorIcon(const gfx::VectorIcon& icon) {
if (icon_ == &icon)
return;
icon_ = &icon; icon_ = &icon;
UpdateImage(); UpdateImage();
} }
bool FloatingMenuButton::GetA11yTogglable() const {
return is_a11y_togglable_;
}
void FloatingMenuButton::SetA11yTogglable(bool a11y_togglable) {
if (a11y_togglable == is_a11y_togglable_)
return;
is_a11y_togglable_ = a11y_togglable;
OnPropertyChanged(&is_a11y_togglable_, views::kPropertyEffectsPaint);
}
bool FloatingMenuButton::GetDrawHighlight() const {
return draw_highlight_;
}
void FloatingMenuButton::SetDrawHighlight(bool draw_highlight) {
if (draw_highlight_ == draw_highlight)
return;
draw_highlight_ = draw_highlight;
OnPropertyChanged(&draw_highlight_, views::kPropertyEffectsPaint);
}
bool FloatingMenuButton::GetToggled() const {
return toggled_;
}
void FloatingMenuButton::SetToggled(bool toggled) { void FloatingMenuButton::SetToggled(bool toggled) {
if (toggled_ == toggled)
return;
toggled_ = toggled; toggled_ = toggled;
UpdateImage(); UpdateImage();
SchedulePaint(); OnPropertyChanged(&toggled_, views::PropertyEffects::kPropertyEffectsPaint);
} }
void FloatingMenuButton::PaintButtonContents(gfx::Canvas* canvas) { void FloatingMenuButton::PaintButtonContents(gfx::Canvas* canvas) {
...@@ -99,10 +137,6 @@ void FloatingMenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -99,10 +137,6 @@ void FloatingMenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
: ax::mojom::CheckedState::kFalse); : ax::mojom::CheckedState::kFalse);
} }
const char* FloatingMenuButton::GetClassName() const {
return "FloatingMenuButton";
}
std::unique_ptr<views::InkDrop> FloatingMenuButton::CreateInkDrop() { std::unique_ptr<views::InkDrop> FloatingMenuButton::CreateInkDrop() {
return TrayPopupUtils::CreateInkDrop(this); return TrayPopupUtils::CreateInkDrop(this);
} }
...@@ -127,14 +161,16 @@ void FloatingMenuButton::OnThemeChanged() { ...@@ -127,14 +161,16 @@ void FloatingMenuButton::OnThemeChanged() {
SchedulePaint(); SchedulePaint();
} }
void FloatingMenuButton::SetId(int id) {
views::View::SetID(id);
}
void FloatingMenuButton::UpdateImage() { void FloatingMenuButton::UpdateImage() {
DCHECK(icon_); DCHECK(icon_);
AshColorProvider::Get()->DecorateIconButton( AshColorProvider::Get()->DecorateIconButton(
this, *icon_, toggled_, GetDefaultSizeOfVectorIcon(*icon_)); this, *icon_, toggled_, GetDefaultSizeOfVectorIcon(*icon_));
} }
BEGIN_METADATA(FloatingMenuButton, views::ImageButton)
ADD_PROPERTY_METADATA(bool, A11yTogglable)
ADD_PROPERTY_METADATA(bool, DrawHighlight)
ADD_PROPERTY_METADATA(bool, Toggled)
END_METADATA
} // namespace ash } // namespace ash
...@@ -5,7 +5,11 @@ ...@@ -5,7 +5,11 @@
#ifndef ASH_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_H_ #ifndef ASH_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_H_
#define ASH_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_H_ #define ASH_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_H_
#include "ash/system/tray/tray_constants.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/view_factory.h"
namespace gfx { namespace gfx {
struct VectorIcon; struct VectorIcon;
...@@ -18,57 +22,70 @@ namespace ash { ...@@ -18,57 +22,70 @@ namespace ash {
class FloatingMenuButton : public views::ImageButton { class FloatingMenuButton : public views::ImageButton {
public: public:
FloatingMenuButton(views::ButtonListener* listener, METADATA_HEADER(FloatingMenuButton);
FloatingMenuButton();
FloatingMenuButton(views::Button::PressedCallback callback,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
int accessible_name_id, int accessible_name_id,
bool flip_for_rtl); bool flip_for_rtl);
FloatingMenuButton(views::ButtonListener* listener, FloatingMenuButton(views::Button::PressedCallback callback,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
int accessible_name_id, int accessible_name_id,
bool flip_for_rtl, bool flip_for_rtl,
int size, int size,
bool draw_highlight, bool draw_highlight,
bool is_a11y_togglable); bool is_a11y_togglable);
FloatingMenuButton(const FloatingMenuButton&) = delete;
FloatingMenuButton& operator=(const FloatingMenuButton&) = delete;
~FloatingMenuButton() override; ~FloatingMenuButton() override;
// Set the vector icon shown in a circle. // Set the vector icon shown in a circle.
void SetVectorIcon(const gfx::VectorIcon& icon); void SetVectorIcon(const gfx::VectorIcon& icon);
// Change the toggle state. bool GetA11yTogglable() const;
void SetToggled(bool toggled); void SetA11yTogglable(bool a11y_togglable);
bool IsToggled() { return toggled_; } bool GetDrawHighlight() const;
void SetDrawHighlight(bool draw_highlight);
// Toggle state property.
bool GetToggled() const;
void SetToggled(bool toggled);
// views::ImageButton: // views::ImageButton:
void PaintButtonContents(gfx::Canvas* canvas) override; void PaintButtonContents(gfx::Canvas* canvas) override;
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
const char* GetClassName() const override;
std::unique_ptr<views::InkDrop> CreateInkDrop() override; std::unique_ptr<views::InkDrop> CreateInkDrop() override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override; std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight() std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override; const override;
void OnThemeChanged() override; void OnThemeChanged() override;
// Used in tests.
void SetId(int id);
private: private:
void UpdateImage(); void UpdateImage();
const gfx::VectorIcon* icon_; const gfx::VectorIcon* icon_;
// True if the button is currently toggled. // True if the button is currently toggled.
bool toggled_ = false; bool toggled_ = false;
int size_; int size_ = kTrayItemSize;
const bool draw_highlight_; bool draw_highlight_ = true;
// Whether this button will be described as togglable to screen reading tools. // Whether this button will be described as togglable to screen reading tools.
const bool is_a11y_togglable_; bool is_a11y_togglable_ = true;
DISALLOW_COPY_AND_ASSIGN(FloatingMenuButton);
}; };
BEGIN_VIEW_BUILDER(/* no export */, FloatingMenuButton, views::ImageButton)
VIEW_BUILDER_PROPERTY(bool, A11yTogglable)
VIEW_BUILDER_PROPERTY(bool, DrawHighlight)
VIEW_BUILDER_PROPERTY(bool, Toggled)
VIEW_BUILDER_PROPERTY(const gfx::VectorIcon&, VectorIcon)
END_VIEW_BUILDER
} // namespace ash } // namespace ash
DEFINE_VIEW_BUILDER(/* no export */, ash::FloatingMenuButton)
#endif // ASH_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_H_ #endif // ASH_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_H_
...@@ -8,15 +8,18 @@ ...@@ -8,15 +8,18 @@
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/accessibility/floating_menu_button.h" #include "ash/system/accessibility/floating_menu_button.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "base/bind.h"
#include "cc/paint/paint_flags.h" #include "cc/paint/paint_flags.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/mojom/ax_node_data.mojom-shared.h" #include "ui/accessibility/mojom/ax_node_data.mojom-shared.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
namespace ash { namespace ash {
...@@ -29,28 +32,29 @@ constexpr int kFocusRingBufferDp = 1; ...@@ -29,28 +32,29 @@ constexpr int kFocusRingBufferDp = 1;
constexpr int kRadiusDp = 18; constexpr int kRadiusDp = 18;
} // namespace } // namespace
SwitchAccessBackButtonView::SwitchAccessBackButtonView(bool for_menu) SwitchAccessBackButtonView::SwitchAccessBackButtonView(bool for_menu) {
: back_button_(new FloatingMenuButton(
this,
for_menu ? kSwitchAccessCloseIcon : kSwitchAccessBackIcon,
IDS_ASH_SWITCH_ACCESS_BACK_BUTTON_DESCRIPTION,
/*flip_for_rtl=*/false,
2 * kRadiusDp,
/*draw_highlight=*/true,
/*is_a11y_togglable=*/false)) {
views::BoxLayout* layout =
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets()));
layout->set_main_axis_alignment(views::BoxLayout::MainAxisAlignment::kCenter);
AddChildView(back_button_);
// Calculate the side length of the bounding box, with room for the two-color // Calculate the side length of the bounding box, with room for the two-color
// focus ring on either side. // focus ring on either side.
int focus_ring_width_per_side = int focus_ring_width_per_side =
2 * kFocusRingSingleColorWidthDp + kFocusRingBufferDp; 2 * kFocusRingSingleColorWidthDp + kFocusRingBufferDp;
int side_length = 2 * (kRadiusDp + focus_ring_width_per_side); int side_length = 2 * (kRadiusDp + focus_ring_width_per_side);
gfx::Size size(side_length, side_length);
SetSize(size); views::Builder<SwitchAccessBackButtonView>(this)
.SetMainAxisAlignment(views::BoxLayout::MainAxisAlignment::kCenter)
.AddChildren(
{views::Builder<FloatingMenuButton>()
.CopyAddressTo(&back_button_)
.SetVectorIcon(for_menu ? kSwitchAccessCloseIcon
: kSwitchAccessBackIcon)
.SetTooltipText(l10n_util::GetStringUTF16(
IDS_ASH_SWITCH_ACCESS_BACK_BUTTON_DESCRIPTION))
.SetPreferredSize(gfx::Size(2 * kRadiusDp, 2 * kRadiusDp))
.SetDrawHighlight(true)
.SetCallback(base::BindRepeating(
&SwitchAccessBackButtonView::OnButtonPressed,
base::Unretained(this)))})
.SetSize(gfx::Size(side_length, side_length))
.BuildChildren();
} }
void SwitchAccessBackButtonView::SetFocusRing(bool should_show) { void SwitchAccessBackButtonView::SetFocusRing(bool should_show) {
...@@ -67,12 +71,6 @@ void SwitchAccessBackButtonView::SetForMenu(bool for_menu) { ...@@ -67,12 +71,6 @@ void SwitchAccessBackButtonView::SetForMenu(bool for_menu) {
back_button_->SetVectorIcon(kSwitchAccessBackIcon); back_button_->SetVectorIcon(kSwitchAccessBackIcon);
} }
void SwitchAccessBackButtonView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
NotifyAccessibilityEvent(ax::mojom::Event::kClicked,
/*send_native_event=*/false);
}
void SwitchAccessBackButtonView::GetAccessibleNodeData( void SwitchAccessBackButtonView::GetAccessibleNodeData(
ui::AXNodeData* node_data) { ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kButton; node_data->role = ax::mojom::Role::kButton;
...@@ -82,10 +80,6 @@ int SwitchAccessBackButtonView::GetHeightForWidth(int w) const { ...@@ -82,10 +80,6 @@ int SwitchAccessBackButtonView::GetHeightForWidth(int w) const {
return w; return w;
} }
const char* SwitchAccessBackButtonView::GetClassName() const {
return "SwitchAccessBackButtonView";
}
void SwitchAccessBackButtonView::OnPaint(gfx::Canvas* canvas) { void SwitchAccessBackButtonView::OnPaint(gfx::Canvas* canvas) {
gfx::Rect rect(GetContentsBounds()); gfx::Rect rect(GetContentsBounds());
cc::PaintFlags flags; cc::PaintFlags flags;
...@@ -108,4 +102,12 @@ void SwitchAccessBackButtonView::OnPaint(gfx::Canvas* canvas) { ...@@ -108,4 +102,12 @@ void SwitchAccessBackButtonView::OnPaint(gfx::Canvas* canvas) {
kRadiusDp + (2 * kFocusRingSingleColorWidthDp), flags); kRadiusDp + (2 * kFocusRingSingleColorWidthDp), flags);
} }
void SwitchAccessBackButtonView::OnButtonPressed() {
NotifyAccessibilityEvent(ax::mojom::Event::kClicked,
/*send_native_event=*/false);
}
BEGIN_METADATA(SwitchAccessBackButtonView, views::BoxLayoutView)
END_METADATA
} // namespace ash } // namespace ash
...@@ -5,7 +5,9 @@ ...@@ -5,7 +5,9 @@
#ifndef ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_BACK_BUTTON_VIEW_H_ #ifndef ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_BACK_BUTTON_VIEW_H_
#define ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_BACK_BUTTON_VIEW_H_ #define ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_BACK_BUTTON_VIEW_H_
#include "ui/views/controls/button/button.h" #include "ui/views/layout/box_layout_view.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/view_factory.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace ash { namespace ash {
...@@ -13,9 +15,10 @@ namespace ash { ...@@ -13,9 +15,10 @@ namespace ash {
class FloatingMenuButton; class FloatingMenuButton;
// View for the Switch Access Back Button. // View for the Switch Access Back Button.
class SwitchAccessBackButtonView : public views::View, class SwitchAccessBackButtonView : public views::BoxLayoutView {
public views::ButtonListener {
public: public:
METADATA_HEADER(SwitchAccessBackButtonView);
explicit SwitchAccessBackButtonView(bool for_menu); explicit SwitchAccessBackButtonView(bool for_menu);
~SwitchAccessBackButtonView() override = default; ~SwitchAccessBackButtonView() override = default;
...@@ -26,22 +29,27 @@ class SwitchAccessBackButtonView : public views::View, ...@@ -26,22 +29,27 @@ class SwitchAccessBackButtonView : public views::View,
void SetFocusRing(bool should_show); void SetFocusRing(bool should_show);
void SetForMenu(bool for_menu); void SetForMenu(bool for_menu);
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::View: // views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
int GetHeightForWidth(int w) const override; int GetHeightForWidth(int w) const override;
const char* GetClassName() const override;
void OnPaint(gfx::Canvas* canvas) override; void OnPaint(gfx::Canvas* canvas) override;
private: private:
void OnButtonPressed();
bool show_focus_ring_ = false; bool show_focus_ring_ = false;
// Owned by views hierarchy. // Owned by views hierarchy.
FloatingMenuButton* back_button_; FloatingMenuButton* back_button_;
}; };
BEGIN_VIEW_BUILDER(/* no export */,
SwitchAccessBackButtonView,
views::BoxLayoutView)
END_VIEW_BUILDER
} // namespace ash } // namespace ash
DEFINE_VIEW_BUILDER(/* no export */, ash::SwitchAccessBackButtonView)
#endif // ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_BACK_BUTTON_VIEW_H_ #endif // ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_BACK_BUTTON_VIEW_H_
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ash/system/accessibility/switch_access_menu_button.h" #include "ash/system/accessibility/switch_access_menu_button.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "base/bind.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/mojom/ax_node_data.mojom-shared.h" #include "ui/accessibility/mojom/ax_node_data.mojom-shared.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/style/typography.h" #include "ui/views/style/typography.h"
namespace ash { namespace ash {
...@@ -34,31 +36,36 @@ constexpr int kTextLineHeightDip = 20; ...@@ -34,31 +36,36 @@ constexpr int kTextLineHeightDip = 20;
SwitchAccessMenuButton::SwitchAccessMenuButton(std::string action_name, SwitchAccessMenuButton::SwitchAccessMenuButton(std::string action_name,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
int label_text_id) int label_text_id)
: views::Button(this), : views::Button(
action_name_(action_name), base::BindRepeating(&SwitchAccessMenuButton::OnButtonPressed,
image_view_(new views::ImageView()), base::Unretained(this))),
label_(new views::Label(l10n_util::GetStringUTF16(label_text_id), action_name_(action_name) {
views::style::CONTEXT_BUTTON)) {
SetFocusBehavior(views::View::FocusBehavior::ACCESSIBLE_ONLY);
std::unique_ptr<views::BoxLayout> layout = std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
gfx::Insets(kButtonTopPaddingDip, kLabelMinSidePaddingDip,
kButtonBottomPaddingDefaultDip, kLabelMinSidePaddingDip),
kLabelTopPaddingDefaultDip);
SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor( SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPrimary); AshColorProvider::ContentLayerType::kIconColorPrimary);
SkColor label_color = AshColorProvider::Get()->GetContentLayerColor( SkColor label_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary); AshColorProvider::ContentLayerType::kTextColorPrimary);
image_view_->SetImage(gfx::CreateVectorIcon(icon, kIconSizeDip, icon_color)); views::Builder<SwitchAccessMenuButton>(this)
label_->SetAutoColorReadabilityEnabled(false); .SetFocusBehavior(views::View::FocusBehavior::ACCESSIBLE_ONLY)
label_->SetEnabledColor(label_color); .AddChildren(
label_->SetMultiLine(true); {views::Builder<views::ImageView>()
label_->SetMaximumWidth(kLabelMaxWidthDip); .CopyAddressTo(&image_view_)
.SetImage(gfx::CreateVectorIcon(icon, kIconSizeDip, icon_color)),
views::Builder<views::Label>()
.CopyAddressTo(&label_)
.SetText(l10n_util::GetStringUTF16(label_text_id))
.SetTextContext(views::style::CONTEXT_BUTTON)
.SetAutoColorReadabilityEnabled(false)
.SetEnabledColor(label_color)
.SetMultiLine(true)
.SetMaximumWidth(kLabelMaxWidthDip)})
.BuildChildren();
AddChildView(image_view_); std::unique_ptr<views::BoxLayout> layout = std::make_unique<views::BoxLayout>(
AddChildView(label_); views::BoxLayout::Orientation::kVertical,
gfx::Insets(kButtonTopPaddingDip, kLabelMinSidePaddingDip,
kButtonBottomPaddingDefaultDip, kLabelMinSidePaddingDip),
kLabelTopPaddingDefaultDip);
// The layout padding changes with the size of the text label. // The layout padding changes with the size of the text label.
gfx::Size label_size = label_->CalculatePreferredSize(); gfx::Size label_size = label_->CalculatePreferredSize();
...@@ -75,16 +82,18 @@ SwitchAccessMenuButton::SwitchAccessMenuButton(std::string action_name, ...@@ -75,16 +82,18 @@ SwitchAccessMenuButton::SwitchAccessMenuButton(std::string action_name,
SetLayoutManager(std::move(layout)); SetLayoutManager(std::move(layout));
} }
void SwitchAccessMenuButton::ButtonPressed(views::Button* sender,
const ui::Event& event) {
NotifyAccessibilityEvent(ax::mojom::Event::kClicked,
/*send_native_event=*/false);
}
void SwitchAccessMenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { void SwitchAccessMenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
views::Button::GetAccessibleNodeData(node_data); views::Button::GetAccessibleNodeData(node_data);
node_data->AddStringAttribute(ax::mojom::StringAttribute::kValue, node_data->AddStringAttribute(ax::mojom::StringAttribute::kValue,
action_name_); action_name_);
} }
void SwitchAccessMenuButton::OnButtonPressed() {
NotifyAccessibilityEvent(ax::mojom::Event::kClicked,
/*send_native_event=*/false);
}
BEGIN_METADATA(SwitchAccessMenuButton, views::Button)
END_METADATA
} // namespace ash } // namespace ash
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#define ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_MENU_BUTTON_H_ #define ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_MENU_BUTTON_H_
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/view_factory.h"
namespace gfx { namespace gfx {
struct VectorIcon; struct VectorIcon;
...@@ -18,9 +20,10 @@ class Label; ...@@ -18,9 +20,10 @@ class Label;
namespace ash { namespace ash {
class SwitchAccessMenuButton : public views::Button, class SwitchAccessMenuButton : public views::Button {
public views::ButtonListener {
public: public:
METADATA_HEADER(SwitchAccessMenuButton);
SwitchAccessMenuButton(std::string action_name, SwitchAccessMenuButton(std::string action_name,
const gfx::VectorIcon& icon, const gfx::VectorIcon& icon,
int accessible_name_id); int accessible_name_id);
...@@ -31,15 +34,14 @@ class SwitchAccessMenuButton : public views::Button, ...@@ -31,15 +34,14 @@ class SwitchAccessMenuButton : public views::Button,
static constexpr int kWidthDip = 80; static constexpr int kWidthDip = 80;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::View: // views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
private: private:
friend class SwitchAccessMenuBubbleControllerTest; friend class SwitchAccessMenuBubbleControllerTest;
void OnButtonPressed();
std::string action_name_; std::string action_name_;
// Owned by the views hierarchy. // Owned by the views hierarchy.
...@@ -47,6 +49,11 @@ class SwitchAccessMenuButton : public views::Button, ...@@ -47,6 +49,11 @@ class SwitchAccessMenuButton : public views::Button,
views::Label* label_; views::Label* label_;
}; };
BEGIN_VIEW_BUILDER(/* no export */, SwitchAccessMenuButton, views::Button)
END_VIEW_BUILDER
} // namespace ash } // namespace ash
DEFINE_VIEW_BUILDER(/* no export */, ash::SwitchAccessMenuButton)
#endif // ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_MENU_BUTTON_H_ #endif // ASH_SYSTEM_ACCESSIBILITY_SWITCH_ACCESS_MENU_BUTTON_H_
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/views/bubble/bubble_frame_view.h" #include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/painter.h" #include "ui/views/painter.h"
#include "ui/views/views_delegate.h" #include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -463,10 +464,6 @@ void TrayBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) { ...@@ -463,10 +464,6 @@ void TrayBubbleView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
} }
} }
const char* TrayBubbleView::GetClassName() const {
return "TrayBubbleView";
}
void TrayBubbleView::OnThemeChanged() { void TrayBubbleView::OnThemeChanged() {
views::BubbleDialogDelegateView::OnThemeChanged(); views::BubbleDialogDelegateView::OnThemeChanged();
DCHECK(layer()); DCHECK(layer());
...@@ -499,4 +496,7 @@ void TrayBubbleView::CloseBubbleView() { ...@@ -499,4 +496,7 @@ void TrayBubbleView::CloseBubbleView() {
delegate_->HideBubble(this); delegate_->HideBubble(this);
} }
BEGIN_METADATA(TrayBubbleView, views::BubbleDialogDelegateView)
END_METADATA
} // namespace ash } // namespace ash
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/view_factory.h"
#include "ui/views/mouse_watcher.h" #include "ui/views/mouse_watcher.h"
namespace views { namespace views {
...@@ -35,6 +37,8 @@ namespace ash { ...@@ -35,6 +37,8 @@ namespace ash {
class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView, class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
public views::MouseWatcherListener { public views::MouseWatcherListener {
public: public:
METADATA_HEADER(TrayBubbleView);
class ASH_EXPORT Delegate { class ASH_EXPORT Delegate {
public: public:
Delegate() {} Delegate() {}
...@@ -101,6 +105,8 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView, ...@@ -101,6 +105,8 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
}; };
explicit TrayBubbleView(const InitParams& init_params); explicit TrayBubbleView(const InitParams& init_params);
TrayBubbleView(const TrayBubbleView&) = delete;
TrayBubbleView& operator=(const TrayBubbleView&) = delete;
~TrayBubbleView() override; ~TrayBubbleView() override;
// Sets up animations, and show the bubble. Must occur after CreateBubble() // Sets up animations, and show the bubble. Must occur after CreateBubble()
...@@ -172,7 +178,6 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView, ...@@ -172,7 +178,6 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
void OnMouseEntered(const ui::MouseEvent& event) override; void OnMouseEntered(const ui::MouseEvent& event) override;
void OnMouseExited(const ui::MouseEvent& event) override; void OnMouseExited(const ui::MouseEvent& event) override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
const char* GetClassName() const override;
void OnThemeChanged() override; void OnThemeChanged() override;
// views::MouseWatcherListener: // views::MouseWatcherListener:
...@@ -236,10 +241,13 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView, ...@@ -236,10 +241,13 @@ class ASH_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView,
base::Optional<StatusAreaWidget::ScopedTrayBubbleCounter> base::Optional<StatusAreaWidget::ScopedTrayBubbleCounter>
tray_bubble_counter_; tray_bubble_counter_;
DISALLOW_COPY_AND_ASSIGN(TrayBubbleView);
}; };
BEGIN_VIEW_BUILDER(ASH_EXPORT, TrayBubbleView, views::BubbleDialogDelegateView)
END_VIEW_BUILDER
} // namespace ash } // namespace ash
DEFINE_VIEW_BUILDER(ASH_EXPORT, ash::TrayBubbleView)
#endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "ui/base/class_property.h" #include "ui/base/class_property.h"
#include "ui/views/bubble/bubble_border.h" #include "ui/views/bubble/bubble_border.h"
#include "ui/views/bubble/bubble_frame_view.h" #include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/view_factory.h"
#include "ui/views/view_tracker.h" #include "ui/views/view_tracker.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h" #include "ui/views/widget/widget_observer.h"
...@@ -398,7 +400,8 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public BubbleDialogDelegate, ...@@ -398,7 +400,8 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public BubbleDialogDelegate,
View* anchor_view, View* anchor_view,
BubbleBorder::Arrow arrow, BubbleBorder::Arrow arrow,
BubbleBorder::Shadow shadow = BubbleBorder::DIALOG_SHADOW); BubbleBorder::Shadow shadow = BubbleBorder::DIALOG_SHADOW);
BubbleDialogDelegateView(const BubbleDialogDelegateView&) = delete;
BubbleDialogDelegateView& operator=(const BubbleDialogDelegateView&) = delete;
~BubbleDialogDelegateView() override; ~BubbleDialogDelegateView() override;
// BubbleDialogDelegate: // BubbleDialogDelegate:
...@@ -430,10 +433,13 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public BubbleDialogDelegate, ...@@ -430,10 +433,13 @@ class VIEWS_EXPORT BubbleDialogDelegateView : public BubbleDialogDelegate,
// Update the bubble color from the NativeTheme unless it was explicitly set. // Update the bubble color from the NativeTheme unless it was explicitly set.
void UpdateColorsFromTheme(); void UpdateColorsFromTheme();
DISALLOW_COPY_AND_ASSIGN(BubbleDialogDelegateView);
}; };
BEGIN_VIEW_BUILDER(VIEWS_EXPORT, BubbleDialogDelegateView, View)
END_VIEW_BUILDER
} // namespace views } // namespace views
DEFINE_VIEW_BUILDER(VIEWS_EXPORT, BubbleDialogDelegateView)
#endif // UI_VIEWS_BUBBLE_BUBBLE_DIALOG_DELEGATE_VIEW_H_ #endif // UI_VIEWS_BUBBLE_BUBBLE_DIALOG_DELEGATE_VIEW_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment