Commit 6113970f authored by David Jacobo's avatar David Jacobo Committed by Commit Bot

Improves TouchSelectionMenuRunnerChromeOS readability

This CL is a follow-up for improving overall readability for
TouchSelectionMenuRUnnerChromeOS.

Bug: b/119794258
Test: Build.
Change-Id: I5ec16deac092e8fb1a493634e871f5ef683fb6da
Reviewed-on: https://chromium-review.googlesource.com/c/1351388Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: David Jacobo <djacobo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611415}
parent 38143a83
...@@ -46,31 +46,31 @@ void TouchSelectionMenuRunnerChromeOS::OpenMenuWithTextSelectionAction( ...@@ -46,31 +46,31 @@ void TouchSelectionMenuRunnerChromeOS::OpenMenuWithTextSelectionAction(
ShowMenu(menu, anchor_rect, handle_image_size); ShowMenu(menu, anchor_rect, handle_image_size);
} }
void TouchSelectionMenuRunnerChromeOS::OpenMenu( bool TouchSelectionMenuRunnerChromeOS::RequestTextSelection(
ui::TouchSelectionMenuClient* client, ui::TouchSelectionMenuClient* client,
const gfx::Rect& anchor_rect, const gfx::Rect& anchor_rect,
const gfx::Size& handle_image_size, const gfx::Size& handle_image_size,
aura::Window* context) { aura::Window* context) {
views::TouchSelectionMenuRunnerViews::CloseMenu(); if (!base::FeatureList::IsEnabled(arc::kSmartTextSelectionFeature))
return false;
if (!views::TouchSelectionMenuRunnerViews::IsMenuAvailable(client))
return;
if (base::FeatureList::IsEnabled(arc::kSmartTextSelectionFeature)) {
const std::string converted_text = const std::string converted_text =
base::UTF16ToUTF8(client->GetSelectedText()); base::UTF16ToUTF8(client->GetSelectedText());
if (converted_text.empty())
return false;
if (!converted_text.empty()) {
auto* arc_service_manager = arc::ArcServiceManager::Get(); auto* arc_service_manager = arc::ArcServiceManager::Get();
if (arc_service_manager) { if (!arc_service_manager)
arc::mojom::IntentHelperInstance* instance = return false;
ARC_GET_INSTANCE_FOR_METHOD(
arc::mojom::IntentHelperInstance* instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_service_manager->arc_bridge_service()->intent_helper(), arc_service_manager->arc_bridge_service()->intent_helper(),
RequestTextSelectionActions); RequestTextSelectionActions);
if (!instance)
return false;
if (instance) { // aura::WindowTracker is used since the newly created menu may need to know
// aura::WindowTracker is used since the newly created menu may need // about the parent window.
// to know about the parent window.
std::unique_ptr<aura::WindowTracker> tracker = std::unique_ptr<aura::WindowTracker> tracker =
std::make_unique<aura::WindowTracker>(); std::make_unique<aura::WindowTracker>();
tracker->Add(context); tracker->Add(context);
...@@ -81,18 +81,28 @@ void TouchSelectionMenuRunnerChromeOS::OpenMenu( ...@@ -81,18 +81,28 @@ void TouchSelectionMenuRunnerChromeOS::OpenMenu(
// Fetch actions for selected text and then show quick menu. // Fetch actions for selected text and then show quick menu.
instance->RequestTextSelectionActions( instance->RequestTextSelectionActions(
converted_text, converted_text,
arc::mojom::ScaleFactor(screen->GetDisplayNearestWindow(context) arc::mojom::ScaleFactor(
.device_scale_factor()), screen->GetDisplayNearestWindow(context).device_scale_factor()),
base::BindOnce(&TouchSelectionMenuRunnerChromeOS:: base::BindOnce(
OpenMenuWithTextSelectionAction, &TouchSelectionMenuRunnerChromeOS::OpenMenuWithTextSelectionAction,
weak_ptr_factory_.GetWeakPtr(), client, weak_ptr_factory_.GetWeakPtr(), client, anchor_rect,
anchor_rect, handle_image_size, handle_image_size, std::move(tracker)));
std::move(tracker))); return true;
}
void TouchSelectionMenuRunnerChromeOS::OpenMenu(
ui::TouchSelectionMenuClient* client,
const gfx::Rect& anchor_rect,
const gfx::Size& handle_image_size,
aura::Window* context) {
views::TouchSelectionMenuRunnerViews::CloseMenu();
// If there are no commands to show in the menu finish right away. Also if
// classification is possible delegate creating/showing a new menu.
if (!views::TouchSelectionMenuRunnerViews::IsMenuAvailable(client) ||
RequestTextSelection(client, anchor_rect, handle_image_size, context)) {
return; return;
} }
}
}
}
// The menu manages its own lifetime and deletes itself when closed. // The menu manages its own lifetime and deletes itself when closed.
TouchSelectionMenuChromeOS* menu = TouchSelectionMenuChromeOS* menu =
......
...@@ -35,6 +35,13 @@ class TouchSelectionMenuRunnerChromeOS ...@@ -35,6 +35,13 @@ class TouchSelectionMenuRunnerChromeOS
std::unique_ptr<aura::WindowTracker> tracker, std::unique_ptr<aura::WindowTracker> tracker,
std::vector<arc::mojom::TextSelectionActionPtr> actions); std::vector<arc::mojom::TextSelectionActionPtr> actions);
// Tries to establish connection with ARC to perform text classification. True
// if a query to ARC was made, false otherwise.
bool RequestTextSelection(ui::TouchSelectionMenuClient* client,
const gfx::Rect& anchor_rect,
const gfx::Size& handle_image_size,
aura::Window* context);
// views::TouchSelectionMenuRunnerViews. // views::TouchSelectionMenuRunnerViews.
void OpenMenu(ui::TouchSelectionMenuClient* client, void OpenMenu(ui::TouchSelectionMenuClient* client,
const gfx::Rect& anchor_rect, const gfx::Rect& anchor_rect,
......
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