Commit b4c01fe3 authored by Anatoliy Potapchuk's avatar Anatoliy Potapchuk Committed by Commit Bot

[Ash] Move buttons class from autoclick menu outside of .cc file

This CL moves out AutoclickMenuButton into a separate class so it can be
in the future reused by other menus that may want those buttons.

Bug: 1061068
Change-Id: Ie776231ea5f319f3405eb7d2b04c09497efe7b7a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2100792Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Commit-Queue: Anatoliy Potapchuk <apotapchuk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750634}
parent e14e1a34
...@@ -715,6 +715,8 @@ component("ash") { ...@@ -715,6 +715,8 @@ component("ash") {
"system/accessibility/autoclick_scroll_view.h", "system/accessibility/autoclick_scroll_view.h",
"system/accessibility/dictation_button_tray.cc", "system/accessibility/dictation_button_tray.cc",
"system/accessibility/dictation_button_tray.h", "system/accessibility/dictation_button_tray.h",
"system/accessibility/floating_menu_button.cc",
"system/accessibility/floating_menu_button.h",
"system/accessibility/select_to_speak_tray.cc", "system/accessibility/select_to_speak_tray.cc",
"system/accessibility/select_to_speak_tray.h", "system/accessibility/select_to_speak_tray.h",
"system/accessibility/tray_accessibility.cc", "system/accessibility/tray_accessibility.cc",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ash/system/accessibility/floating_menu_button.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/top_shortcut_button.h" #include "ash/system/unified/top_shortcut_button.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -31,107 +32,9 @@ namespace { ...@@ -31,107 +32,9 @@ namespace {
const int kPanelPositionButtonSize = 36; const int kPanelPositionButtonSize = 36;
const int kPanelPositionButtonPadding = 14; const int kPanelPositionButtonPadding = 14;
const int kSeparatorHeight = 16; const int kSeparatorHeight = 16;
const SkColor kAutoclickMenuButtonIconColorActive = SkColorSetRGB(32, 33, 36);
} // namespace } // namespace
// A button used in the Automatic clicks on-screen menu. The button is
// togglable.
class AutoclickMenuButton : public TopShortcutButton {
public:
AutoclickMenuButton(views::ButtonListener* listener,
const gfx::VectorIcon& icon,
int accessible_name_id,
int size = kTrayItemSize,
bool draw_highlight = true)
: TopShortcutButton(listener, accessible_name_id),
icon_(&icon),
size_(size),
draw_highlight_(draw_highlight) {
EnableCanvasFlippingForRTLUI(false);
SetPreferredSize(gfx::Size(size_, size_));
UpdateImage();
}
~AutoclickMenuButton() override = default;
// views::Button:
const char* GetClassName() const override { return "AutoclickMenuButton"; }
// Set the vector icon shown in a circle.
void SetVectorIcon(const gfx::VectorIcon& icon) {
icon_ = &icon;
UpdateImage();
}
// Change the toggle state.
void SetToggled(bool toggled) {
toggled_ = toggled;
UpdateImage();
SchedulePaint();
}
bool IsToggled() { return toggled_; }
// TopShortcutButton:
void PaintButtonContents(gfx::Canvas* canvas) override {
if (draw_highlight_) {
gfx::Rect rect(GetContentsBounds());
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(AshColorProvider::Get()->GetControlsLayerColor(
toggled_
? AshColorProvider::ControlsLayerType::kActiveControlBackground
: AshColorProvider::ControlsLayerType::kInactiveControlBackground,
AshColorProvider::AshColorMode::kDark));
flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->DrawCircle(gfx::PointF(rect.CenterPoint()), size_ / 2, flags);
}
views::ImageButton::PaintButtonContents(canvas);
}
gfx::Size CalculatePreferredSize() const override {
return gfx::Size(size_, size_);
}
void GetAccessibleNodeData(ui::AXNodeData* node_data) override {
if (!GetEnabled())
return;
TopShortcutButton::GetAccessibleNodeData(node_data);
node_data->role = ax::mojom::Role::kToggleButton;
node_data->SetCheckedState(toggled_ ? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse);
}
void SetId(AutoclickMenuView::ButtonId id) {
views::View::SetID(static_cast<int>(id));
}
private:
void UpdateImage() {
const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kDark);
SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(
*icon_,
toggled_ ? kAutoclickMenuButtonIconColorActive : icon_color));
SetImage(views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(
*icon_,
toggled_ ? kAutoclickMenuButtonIconColorActive : icon_color));
}
const gfx::VectorIcon* icon_;
// True if the button is currently toggled.
bool toggled_ = false;
int size_;
const bool draw_highlight_;
DISALLOW_COPY_AND_ASSIGN(AutoclickMenuButton);
};
// ------ AutoclickMenuBubbleView ------ // // ------ AutoclickMenuBubbleView ------ //
AutoclickMenuBubbleView::AutoclickMenuBubbleView( AutoclickMenuBubbleView::AutoclickMenuBubbleView(
...@@ -153,43 +56,49 @@ const char* AutoclickMenuBubbleView::GetClassName() const { ...@@ -153,43 +56,49 @@ const char* AutoclickMenuBubbleView::GetClassName() const {
AutoclickMenuView::AutoclickMenuView(AutoclickEventType type, AutoclickMenuView::AutoclickMenuView(AutoclickEventType type,
AutoclickMenuPosition position) AutoclickMenuPosition position)
: left_click_button_( : left_click_button_(
new AutoclickMenuButton(this, new FloatingMenuButton(this,
kAutoclickLeftClickIcon, kAutoclickLeftClickIcon,
IDS_ASH_AUTOCLICK_OPTION_LEFT_CLICK)), IDS_ASH_AUTOCLICK_OPTION_LEFT_CLICK,
false /* flip_for_rtl */)),
right_click_button_( right_click_button_(
new AutoclickMenuButton(this, new FloatingMenuButton(this,
kAutoclickRightClickIcon, kAutoclickRightClickIcon,
IDS_ASH_AUTOCLICK_OPTION_RIGHT_CLICK)), IDS_ASH_AUTOCLICK_OPTION_RIGHT_CLICK,
false /* flip_for_rtl */)),
double_click_button_( double_click_button_(
new AutoclickMenuButton(this, new FloatingMenuButton(this,
kAutoclickDoubleClickIcon, kAutoclickDoubleClickIcon,
IDS_ASH_AUTOCLICK_OPTION_DOUBLE_CLICK)), IDS_ASH_AUTOCLICK_OPTION_DOUBLE_CLICK,
false /* flip_for_rtl */)),
drag_button_( drag_button_(
new AutoclickMenuButton(this, new FloatingMenuButton(this,
kAutoclickDragIcon, kAutoclickDragIcon,
IDS_ASH_AUTOCLICK_OPTION_DRAG_AND_DROP)), IDS_ASH_AUTOCLICK_OPTION_DRAG_AND_DROP,
scroll_button_(new AutoclickMenuButton(this, false /* flip_for_rtl */)),
kAutoclickScrollIcon, scroll_button_(new FloatingMenuButton(this,
IDS_ASH_AUTOCLICK_OPTION_SCROLL)), kAutoclickScrollIcon,
pause_button_( IDS_ASH_AUTOCLICK_OPTION_SCROLL,
new AutoclickMenuButton(this, false /* flip_for_rtl */)),
kAutoclickPauseIcon, pause_button_(new FloatingMenuButton(this,
IDS_ASH_AUTOCLICK_OPTION_NO_ACTION)), kAutoclickPauseIcon,
IDS_ASH_AUTOCLICK_OPTION_NO_ACTION,
false /* flip_for_rtl */)),
position_button_( position_button_(
new AutoclickMenuButton(this, new FloatingMenuButton(this,
kAutoclickPositionBottomLeftIcon, kAutoclickPositionBottomLeftIcon,
IDS_ASH_AUTOCLICK_OPTION_CHANGE_POSITION, IDS_ASH_AUTOCLICK_OPTION_CHANGE_POSITION,
kPanelPositionButtonSize, false /* flip_for_rtl */,
false /* no highlight */)) { kPanelPositionButtonSize,
false /* no highlight */)) {
// Set view IDs for testing. // Set view IDs for testing.
left_click_button_->SetId(ButtonId::kLeftClick); left_click_button_->SetId(static_cast<int>(ButtonId::kLeftClick));
right_click_button_->SetId(ButtonId::kRightClick); right_click_button_->SetId(static_cast<int>(ButtonId::kRightClick));
double_click_button_->SetId(ButtonId::kDoubleClick); double_click_button_->SetId(static_cast<int>(ButtonId::kDoubleClick));
drag_button_->SetId(ButtonId::kDragAndDrop); drag_button_->SetId(static_cast<int>(ButtonId::kDragAndDrop));
pause_button_->SetId(ButtonId::kPause); pause_button_->SetId(static_cast<int>(ButtonId::kPause));
position_button_->SetId(ButtonId::kPosition); position_button_->SetId(static_cast<int>(ButtonId::kPosition));
if (scroll_button_) if (scroll_button_)
scroll_button_->SetId(ButtonId::kScroll); scroll_button_->SetId(static_cast<int>(ButtonId::kScroll));
std::unique_ptr<views::BoxLayout> layout = std::make_unique<views::BoxLayout>( std::unique_ptr<views::BoxLayout> layout = std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(), 0); views::BoxLayout::Orientation::kHorizontal, gfx::Insets(), 0);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace ash { namespace ash {
class AutoclickMenuButton; class FloatingMenuButton;
// View for the Automatic Clicks menu bubble, which holds the Automatic Clicks // View for the Automatic Clicks menu bubble, which holds the Automatic Clicks
// Menu. // Menu.
...@@ -59,13 +59,13 @@ class AutoclickMenuView : public views::View, public views::ButtonListener { ...@@ -59,13 +59,13 @@ class AutoclickMenuView : public views::View, public views::ButtonListener {
private: private:
// Unowned. Owned by views hierarchy. // Unowned. Owned by views hierarchy.
AutoclickMenuButton* left_click_button_; FloatingMenuButton* left_click_button_;
AutoclickMenuButton* right_click_button_; FloatingMenuButton* right_click_button_;
AutoclickMenuButton* double_click_button_; FloatingMenuButton* double_click_button_;
AutoclickMenuButton* drag_button_; FloatingMenuButton* drag_button_;
AutoclickMenuButton* scroll_button_ = nullptr; FloatingMenuButton* scroll_button_ = nullptr;
AutoclickMenuButton* pause_button_; FloatingMenuButton* pause_button_;
AutoclickMenuButton* position_button_; FloatingMenuButton* position_button_;
// 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
......
// Copyright 2020 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.
#include "ash/system/accessibility/floating_menu_button.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/tray/tray_constants.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop_mask.h"
namespace ash {
namespace {
const SkColor kFloatingMenuButtonIconColorActive = SkColorSetRGB(32, 33, 36);
}
FloatingMenuButton::FloatingMenuButton(views::ButtonListener* listener,
const gfx::VectorIcon& icon,
int accessible_name_id,
bool flip_for_rtl,
int size,
bool draw_highlight)
: TopShortcutButton(listener, accessible_name_id),
icon_(&icon),
size_(size),
draw_highlight_(draw_highlight) {
EnableCanvasFlippingForRTLUI(flip_for_rtl);
SetPreferredSize(gfx::Size(size_, size_));
UpdateImage();
}
FloatingMenuButton::~FloatingMenuButton() = default;
// views::Button:
const char* FloatingMenuButton::GetClassName() const {
return "FloatingMenuButton";
}
// Set the vector icon shown in a circle.
void FloatingMenuButton::SetVectorIcon(const gfx::VectorIcon& icon) {
icon_ = &icon;
UpdateImage();
}
// Change the toggle state.
void FloatingMenuButton::SetToggled(bool toggled) {
toggled_ = toggled;
UpdateImage();
SchedulePaint();
}
// TopShortcutButton:
void FloatingMenuButton::PaintButtonContents(gfx::Canvas* canvas) {
if (draw_highlight_) {
gfx::Rect rect(GetContentsBounds());
cc::PaintFlags flags;
flags.setAntiAlias(true);
flags.setColor(AshColorProvider::Get()->GetControlsLayerColor(
toggled_
? AshColorProvider::ControlsLayerType::kActiveControlBackground
: AshColorProvider::ControlsLayerType::kInactiveControlBackground,
AshColorProvider::AshColorMode::kDark));
flags.setStyle(cc::PaintFlags::kFill_Style);
canvas->DrawCircle(gfx::PointF(rect.CenterPoint()), size_ / 2, flags);
}
views::ImageButton::PaintButtonContents(canvas);
}
gfx::Size FloatingMenuButton::CalculatePreferredSize() const {
return gfx::Size(size_, size_);
}
void FloatingMenuButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
if (!GetEnabled())
return;
TopShortcutButton::GetAccessibleNodeData(node_data);
node_data->role = ax::mojom::Role::kToggleButton;
node_data->SetCheckedState(toggled_ ? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse);
}
void FloatingMenuButton::SetId(int id) {
views::View::SetID(id);
}
void FloatingMenuButton::UpdateImage() {
const SkColor icon_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconPrimary,
AshColorProvider::AshColorMode::kDark);
SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(
*icon_, toggled_ ? kFloatingMenuButtonIconColorActive : icon_color));
SetImage(
views::Button::STATE_DISABLED,
gfx::CreateVectorIcon(
*icon_, toggled_ ? kFloatingMenuButtonIconColorActive : icon_color));
}
} // namespace ash
// Copyright 2020 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_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_H_
#define ASH_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_H_
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/top_shortcut_button.h"
namespace views {
class InkDropMask;
}
namespace gfx {
struct VectorIcon;
class Size;
} // namespace gfx
namespace ash {
// Button view that is used in floating menu.
class FloatingMenuButton : public TopShortcutButton {
public:
FloatingMenuButton(views::ButtonListener* listener,
const gfx::VectorIcon& icon,
int accessible_name_id,
bool flip_for_rtl,
int size = kTrayItemSize,
bool draw_highlight = true);
~FloatingMenuButton() override;
// views::Button:
const char* GetClassName() const override;
// Set the vector icon shown in a circle.
void SetVectorIcon(const gfx::VectorIcon& icon);
// Change the toggle state.
void SetToggled(bool toggled);
bool IsToggled() { return toggled_; }
// TopShortcutButton:
void PaintButtonContents(gfx::Canvas* canvas) override;
gfx::Size CalculatePreferredSize() const override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
// Used in tests.
void SetId(int id);
private:
void UpdateImage();
const gfx::VectorIcon* icon_;
// True if the button is currently toggled.
bool toggled_ = false;
int size_;
const bool draw_highlight_;
DISALLOW_COPY_AND_ASSIGN(FloatingMenuButton);
};
} // namespace ash
#endif // ASH_SYSTEM_ACCESSIBILITY_FLOATING_MENU_BUTTON_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