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(
ShowMenu(menu, anchor_rect, handle_image_size);
}
void TouchSelectionMenuRunnerChromeOS::OpenMenu(
bool TouchSelectionMenuRunnerChromeOS::RequestTextSelection(
ui::TouchSelectionMenuClient* client,
const gfx::Rect& anchor_rect,
const gfx::Size& handle_image_size,
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 =
base::UTF16ToUTF8(client->GetSelectedText());
if (converted_text.empty())
return false;
if (!converted_text.empty()) {
auto* arc_service_manager = arc::ArcServiceManager::Get();
if (arc_service_manager) {
arc::mojom::IntentHelperInstance* instance =
ARC_GET_INSTANCE_FOR_METHOD(
if (!arc_service_manager)
return false;
arc::mojom::IntentHelperInstance* instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_service_manager->arc_bridge_service()->intent_helper(),
RequestTextSelectionActions);
if (!instance)
return false;
if (instance) {
// aura::WindowTracker is used since the newly created menu may need
// to know about the parent window.
// aura::WindowTracker is used since the newly created menu may need to know
// about the parent window.
std::unique_ptr<aura::WindowTracker> tracker =
std::make_unique<aura::WindowTracker>();
tracker->Add(context);
......@@ -81,18 +81,28 @@ void TouchSelectionMenuRunnerChromeOS::OpenMenu(
// Fetch actions for selected text and then show quick menu.
instance->RequestTextSelectionActions(
converted_text,
arc::mojom::ScaleFactor(screen->GetDisplayNearestWindow(context)
.device_scale_factor()),
base::BindOnce(&TouchSelectionMenuRunnerChromeOS::
OpenMenuWithTextSelectionAction,
weak_ptr_factory_.GetWeakPtr(), client,
anchor_rect, handle_image_size,
std::move(tracker)));
arc::mojom::ScaleFactor(
screen->GetDisplayNearestWindow(context).device_scale_factor()),
base::BindOnce(
&TouchSelectionMenuRunnerChromeOS::OpenMenuWithTextSelectionAction,
weak_ptr_factory_.GetWeakPtr(), client, anchor_rect,
handle_image_size, 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;
}
}
}
}
// The menu manages its own lifetime and deletes itself when closed.
TouchSelectionMenuChromeOS* menu =
......
......@@ -35,6 +35,13 @@ class TouchSelectionMenuRunnerChromeOS
std::unique_ptr<aura::WindowTracker> tracker,
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.
void OpenMenu(ui::TouchSelectionMenuClient* client,
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