Skip to content

Commit

Permalink
arc/gio: Clear the label focus when moving ActionView
Browse files Browse the repository at this point in the history
Clear the label focus when touchscreen or mouse pressing down the touch
point by setting the focus to a different view.

Move ResetFocus function to util so it can be used in different classes.

Bug: b/260868602
Test: manual test by focusing on one label and dragging move ActionView
Test: manual check if the tab key works after reset focus
Change-Id: Idd347214e40eb55a56f3f51c866feaaa4ebbd5ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4243009
Auto-Submit: Cici Ruan <cuicuiruan@google.com>
Commit-Queue: Cici Ruan <cuicuiruan@google.com>
Reviewed-by: David Jacobo <djacobo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1106075}
  • Loading branch information
Cici Ruan authored and Chromium LUCI CQ committed Feb 16, 2023
1 parent 8962183 commit e232e86
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions chrome/browser/ash/arc/input_overlay/ui/action_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ void ActionView::UpdateTrashButtonPosition() {

void ActionView::OnDragStart(const ui::LocatedEvent& event) {
start_drag_event_pos_ = event.location();
ResetFocusTo(this);
}

bool ActionView::OnDragUpdate(const ui::LocatedEvent& event) {
Expand Down
14 changes: 2 additions & 12 deletions chrome/browser/ash/arc/input_overlay/ui/edit_finish_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,6 @@ bool EditFinishView::OnKeyReleased(const ui::KeyEvent& event) {
return true;
}

void EditFinishView::ResetFocus() {
auto* focus_manager = GetFocusManager();
if (!focus_manager)
return;
focus_manager->ClearFocus();
// When it has to clear focus explicitly, set focused view back to its parent,
// so it can find the focused view when Tab traversal key is pressed.
focus_manager->SetFocusedView(parent());
}

void EditFinishView::OnDragStart(const ui::LocatedEvent& event) {
start_drag_event_pos_ = event.location();
start_drag_view_pos_ = origin();
Expand All @@ -331,9 +321,9 @@ void EditFinishView::OnResetButtonPressed() {
if (!display_overlay_controller_)
return;
display_overlay_controller_->OnCustomizeRestore();
if (reset_button_->HasFocus())
if (reset_button_->HasFocus() || !parent())
return;
ResetFocus();
ResetFocusTo(parent());
}

void EditFinishView::OnSaveButtonPressed() {
Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/ash/arc/input_overlay/ui/edit_finish_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class EditFinishView : public views::View {
void OnSaveButtonPressed();
void OnCancelButtonPressed();

void ResetFocus();

// Drag operations.
void OnDragStart(const ui::LocatedEvent& event);
void OnDragUpdate(const ui::LocatedEvent& event);
Expand Down
10 changes: 10 additions & 0 deletions chrome/browser/ash/arc/input_overlay/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "chrome/browser/ash/arc/input_overlay/actions/action.h"
#include "chrome/browser/ash/arc/input_overlay/actions/input_element.h"
#include "chrome/browser/ash/arc/input_overlay/constants.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/view.h"

namespace arc::input_overlay {

Expand Down Expand Up @@ -80,6 +82,14 @@ absl::optional<std::string> GetCurrentSystemVersion() {
: absl::nullopt;
}

void ResetFocusTo(views::View* view) {
DCHECK(view);
auto* focus_manager = view->GetFocusManager();
if (!focus_manager)
return;
focus_manager->SetFocusedView(view);
}

bool AllowReposition() {
return ash::features::IsArcInputOverlayAlphaV2Enabled() ||
ash::features::IsArcInputOverlayBetaEnabled();
Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/ash/arc/input_overlay/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"

namespace views {
class View;
} // namespace views

namespace arc::input_overlay {

class Action;
Expand All @@ -39,6 +43,9 @@ void ClampPosition(gfx::Point& position,
// Alpha version. Otherwise, it is AlphaV2+ version.
absl::optional<std::string> GetCurrentSystemVersion();

// Reset the focus to |view|.
void ResetFocusTo(views::View* view);

// TODO(b/260937747): Update or remove when removing flags
// |kArcInputOverlayAlphaV2| or |kArcInputOverlayBeta|.
bool AllowReposition();
Expand Down

0 comments on commit e232e86

Please sign in to comment.