Commit 2e971546 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: ui/views/touchui/

Bug: 772945
Change-Id: Ibfb794373df3f30e88c645ae7678cd3ccb3f9fdd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485040Reviewed-by: default avatarMohsen Izadi <mohsen@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819029}
parent 3dbbd29e
...@@ -51,10 +51,10 @@ void TouchSelectionMenuChromeOS::SetActionsForTesting( ...@@ -51,10 +51,10 @@ void TouchSelectionMenuChromeOS::SetActionsForTesting(
void TouchSelectionMenuChromeOS::CreateButtons() { void TouchSelectionMenuChromeOS::CreateButtons() {
if (action_) { if (action_) {
views::LabelButton* button = views::LabelButton* button = CreateButton(
CreateButton(base::UTF8ToUTF16(action_->title)); base::UTF8ToUTF16(action_->title),
button->set_tag(kSmartTextSelectionActionTag); base::BindRepeating(&TouchSelectionMenuChromeOS::ActionButtonPressed,
base::Unretained(this)));
if (action_->bitmap_icon) { if (action_->bitmap_icon) {
gfx::ImageSkia original( gfx::ImageSkia original(
gfx::ImageSkia::CreateFrom1xBitmap(action_->bitmap_icon.value())); gfx::ImageSkia::CreateFrom1xBitmap(action_->bitmap_icon.value()));
...@@ -63,20 +63,21 @@ void TouchSelectionMenuChromeOS::CreateButtons() { ...@@ -63,20 +63,21 @@ void TouchSelectionMenuChromeOS::CreateButtons() {
gfx::Size(kSmallIconSizeInDip, kSmallIconSizeInDip)); gfx::Size(kSmallIconSizeInDip, kSmallIconSizeInDip));
button->SetImage(views::Button::ButtonState::STATE_NORMAL, icon); button->SetImage(views::Button::ButtonState::STATE_NORMAL, icon);
} }
AddChildView(button);
} }
views::TouchSelectionMenuViews::CreateButtons(); views::TouchSelectionMenuViews::CreateButtons();
} }
void TouchSelectionMenuChromeOS::ButtonPressed(views::Button* sender, void TouchSelectionMenuChromeOS::OnBeforeBubbleWidgetInit(
const ui::Event& event) { views::Widget::InitParams* params,
if (sender->tag() != kSmartTextSelectionActionTag) { views::Widget* widget) const {
views::TouchSelectionMenuViews::ButtonPressed(sender, event); ash_util::SetupWidgetInitParamsForContainer(
return; params, ash::kShellWindowId_SettingBubbleContainer);
} }
TouchSelectionMenuChromeOS::~TouchSelectionMenuChromeOS() = default;
void TouchSelectionMenuChromeOS::ActionButtonPressed() {
auto* arc_service_manager = arc::ArcServiceManager::Get(); auto* arc_service_manager = arc::ArcServiceManager::Get();
if (!arc_service_manager) if (!arc_service_manager)
return; return;
...@@ -88,12 +89,3 @@ void TouchSelectionMenuChromeOS::ButtonPressed(views::Button* sender, ...@@ -88,12 +89,3 @@ void TouchSelectionMenuChromeOS::ButtonPressed(views::Button* sender,
instance->HandleIntent(std::move(action_->action_intent), instance->HandleIntent(std::move(action_->action_intent),
std::move(action_->activity)); std::move(action_->activity));
} }
void TouchSelectionMenuChromeOS::OnBeforeBubbleWidgetInit(
views::Widget::InitParams* params,
views::Widget* widget) const {
ash_util::SetupWidgetInitParamsForContainer(
params, ash::kShellWindowId_SettingBubbleContainer);
}
TouchSelectionMenuChromeOS::~TouchSelectionMenuChromeOS() = default;
...@@ -19,10 +19,6 @@ class TouchSelectionMenuRunnerViews; ...@@ -19,10 +19,6 @@ class TouchSelectionMenuRunnerViews;
// user's text selection. // user's text selection.
class TouchSelectionMenuChromeOS : public views::TouchSelectionMenuViews { class TouchSelectionMenuChromeOS : public views::TouchSelectionMenuViews {
public: public:
// Tag used to mark added actions/buttons as generated by the smart text
// selection feature.
enum { kSmartTextSelectionActionTag = -2 };
TouchSelectionMenuChromeOS(views::TouchSelectionMenuRunnerViews* owner, TouchSelectionMenuChromeOS(views::TouchSelectionMenuRunnerViews* owner,
ui::TouchSelectionMenuClient* client, ui::TouchSelectionMenuClient* client,
aura::Window* context, aura::Window* context,
...@@ -34,13 +30,14 @@ class TouchSelectionMenuChromeOS : public views::TouchSelectionMenuViews { ...@@ -34,13 +30,14 @@ class TouchSelectionMenuChromeOS : public views::TouchSelectionMenuViews {
protected: protected:
// views:TouchSelectionMenuViews. // views:TouchSelectionMenuViews.
void CreateButtons() override; void CreateButtons() override;
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
views::Widget* widget) const override; views::Widget* widget) const override;
private: private:
~TouchSelectionMenuChromeOS() override; ~TouchSelectionMenuChromeOS() override;
void ActionButtonPressed();
arc::mojom::TextSelectionActionPtr action_; arc::mojom::TextSelectionActionPtr action_;
int64_t display_id_; int64_t display_id_;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ui/views/touchui/touch_selection_menu_views.h" #include "ui/views/touchui/touch_selection_menu_views.h"
#include <memory> #include <memory>
#include <utility>
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -123,27 +124,33 @@ TouchSelectionMenuViews::~TouchSelectionMenuViews() = default; ...@@ -123,27 +124,33 @@ TouchSelectionMenuViews::~TouchSelectionMenuViews() = default;
void TouchSelectionMenuViews::CreateButtons() { void TouchSelectionMenuViews::CreateButtons() {
for (const auto& command : kMenuCommands) { for (const auto& command : kMenuCommands) {
if (!client_->IsCommandIdEnabled(command.command_id)) if (client_->IsCommandIdEnabled(command.command_id)) {
continue; CreateButton(
l10n_util::GetStringUTF16(command.message_id),
Button* button = base::BindRepeating(&TouchSelectionMenuViews::ButtonPressed,
CreateButton(l10n_util::GetStringUTF16(command.message_id)); base::Unretained(this), command.command_id));
button->set_tag(command.command_id); }
AddChildView(button);
} }
// Finally, add ellipsis button. // Finally, add ellipsis button.
LabelButton* ellipsis_button = CreateButton(base::ASCIIToUTF16("...")); CreateButton(base::ASCIIToUTF16("..."),
ellipsis_button->SetID(ButtonViewId::kEllipsisButton); base::BindRepeating(
AddChildView(ellipsis_button); [](TouchSelectionMenuViews* menu) {
menu->CloseMenu();
menu->client_->RunContextMenu();
},
base::Unretained(this)))
->SetID(ButtonViewId::kEllipsisButton);
InvalidateLayout(); InvalidateLayout();
} }
LabelButton* TouchSelectionMenuViews::CreateButton( LabelButton* TouchSelectionMenuViews::CreateButton(
const base::string16& title) { const base::string16& title,
Button::PressedCallback callback) {
base::string16 label = base::string16 label =
gfx::RemoveAcceleratorChar(title, '&', nullptr, nullptr); gfx::RemoveAcceleratorChar(title, '&', nullptr, nullptr);
LabelButton* button = new LabelButton(this, label, style::CONTEXT_TOUCH_MENU); auto* button = AddChildView(std::make_unique<LabelButton>(
std::move(callback), label, style::CONTEXT_TOUCH_MENU));
constexpr gfx::Size kMenuButtonMinSize = gfx::Size(63, 38); constexpr gfx::Size kMenuButtonMinSize = gfx::Size(63, 38);
button->SetMinSize(kMenuButtonMinSize); button->SetMinSize(kMenuButtonMinSize);
button->SetFocusForPlatform(); button->SetFocusForPlatform();
...@@ -179,13 +186,10 @@ void TouchSelectionMenuViews::WindowClosing() { ...@@ -179,13 +186,10 @@ void TouchSelectionMenuViews::WindowClosing() {
DisconnectOwner(); DisconnectOwner();
} }
void TouchSelectionMenuViews::ButtonPressed(Button* sender, void TouchSelectionMenuViews::ButtonPressed(int command,
const ui::Event& event) { const ui::Event& event) {
CloseMenu(); CloseMenu();
if (sender->GetID() != ButtonViewId::kEllipsisButton) client_->ExecuteCommand(command, event.flags());
client_->ExecuteCommand(sender->tag(), event.flags());
else
client_->RunContextMenu();
} }
BEGIN_METADATA(TouchSelectionMenuViews, BubbleDialogDelegateView) BEGIN_METADATA(TouchSelectionMenuViews, BubbleDialogDelegateView)
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/touchui/touch_selection_menu_runner_views.h" #include "ui/views/touchui/touch_selection_menu_runner_views.h"
namespace ui { namespace ui {
...@@ -19,8 +18,7 @@ class LabelButton; ...@@ -19,8 +18,7 @@ class LabelButton;
// A bubble that contains actions available for the selected text. An object of // A bubble that contains actions available for the selected text. An object of
// this type, as a BubbleDialogDelegateView, manages its own lifetime. // this type, as a BubbleDialogDelegateView, manages its own lifetime.
class VIEWS_EXPORT TouchSelectionMenuViews : public BubbleDialogDelegateView, class VIEWS_EXPORT TouchSelectionMenuViews : public BubbleDialogDelegateView {
public ButtonListener {
public: public:
METADATA_HEADER(TouchSelectionMenuViews); METADATA_HEADER(TouchSelectionMenuViews);
...@@ -47,14 +45,14 @@ class VIEWS_EXPORT TouchSelectionMenuViews : public BubbleDialogDelegateView, ...@@ -47,14 +45,14 @@ class VIEWS_EXPORT TouchSelectionMenuViews : public BubbleDialogDelegateView,
virtual void CreateButtons(); virtual void CreateButtons();
// Helper method to create a single button. // Helper method to create a single button.
LabelButton* CreateButton(const base::string16& title); LabelButton* CreateButton(const base::string16& title,
Button::PressedCallback callback);
// ButtonListener:
void ButtonPressed(Button* sender, const ui::Event& event) override;
private: private:
friend class TouchSelectionMenuRunnerViews::TestApi; friend class TouchSelectionMenuRunnerViews::TestApi;
void ButtonPressed(int command, const ui::Event& event);
// Helper to disconnect this menu object from its owning menu runner. // Helper to disconnect this menu object from its owning menu runner.
void DisconnectOwner(); void DisconnectOwner();
......
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