Commit 9fe94ea6 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Reland: Makes magnifier observe AXEventManager for focus changes

 Bug: 865575

Reland of https://chromium-review.googlesource.com/c/chromium/src/+/1852414

This change differs in:
- only show the viewport widget once all associated state is ready to respond to events. This fixes a potential crash.
- only observe focus events on controls.

Change-Id: I1addbfb4a9d89e738ca6992c3ccd1f88e9546104
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876688
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708721}
parent fd17c462
...@@ -713,8 +713,6 @@ void DockedMagnifierControllerImpl::CreateMagnifierViewport() { ...@@ -713,8 +713,6 @@ void DockedMagnifierControllerImpl::CreateMagnifierViewport() {
GetViewportParentContainerForRoot(current_source_root_window_); GetViewportParentContainerForRoot(current_source_root_window_);
params.name = kDockedMagnifierViewportWindowName; params.name = kDockedMagnifierViewportWindowName;
viewport_widget_->Init(std::move(params)); viewport_widget_->Init(std::move(params));
viewport_widget_->Show();
viewport_widget_->AddObserver(this);
// 2- Create the separator layer right below the viwport widget, parented to // 2- Create the separator layer right below the viwport widget, parented to
// the layer of the root window. // the layer of the root window.
...@@ -760,6 +758,11 @@ void DockedMagnifierControllerImpl::CreateMagnifierViewport() { ...@@ -760,6 +758,11 @@ void DockedMagnifierControllerImpl::CreateMagnifierViewport() {
// 6- Confine the mouse cursor within the remaining part of the display. // 6- Confine the mouse cursor within the remaining part of the display.
ConfineMouseCursorOutsideViewport(); ConfineMouseCursorOutsideViewport();
// 7- Show the widget, which can trigger events to request movement of the
// viewport now that all internal state has been created.
viewport_widget_->AddObserver(this);
viewport_widget_->Show();
} }
void DockedMagnifierControllerImpl::MaybeCachePointOfInterestMinimumHeight( void DockedMagnifierControllerImpl::MaybeCachePointOfInterestMinimumHeight(
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "ui/accessibility/ax_role_properties.h"
#include "ui/views/accessibility/ax_event_manager.h"
#include "ui/views/accessibility/view_accessibility.h"
namespace chromeos { namespace chromeos {
...@@ -98,6 +101,25 @@ void MagnificationManager::OnProfileWillBeDestroyed(Profile* profile) { ...@@ -98,6 +101,25 @@ void MagnificationManager::OnProfileWillBeDestroyed(Profile* profile) {
SetProfile(nullptr); SetProfile(nullptr);
} }
void MagnificationManager::OnViewEvent(views::View* view,
ax::mojom::Event event_type) {
if (!fullscreen_magnifier_enabled_ && !IsDockedMagnifierEnabled())
return;
if (event_type != ax::mojom::Event::kFocus &&
event_type != ax::mojom::Event::kSelection) {
return;
}
ui::AXNodeData data;
view->GetViewAccessibility().GetAccessibleNodeData(&data);
// Disallow focus on large containers, which probably should not move the
// magnified viewport to the center of the view.
if (ui::IsControl(data.role))
HandleFocusChanged(view->GetBoundsInScreen(), false);
}
void MagnificationManager::SetProfileForTest(Profile* profile) { void MagnificationManager::SetProfileForTest(Profile* profile) {
SetProfile(profile); SetProfile(profile);
} }
...@@ -110,10 +132,12 @@ MagnificationManager::MagnificationManager() { ...@@ -110,10 +132,12 @@ MagnificationManager::MagnificationManager() {
registrar_.Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE, registrar_.Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
user_manager::UserManager::Get()->AddSessionStateObserver(this); user_manager::UserManager::Get()->AddSessionStateObserver(this);
views::AXEventManager::Get()->AddObserver(this);
} }
MagnificationManager::~MagnificationManager() { MagnificationManager::~MagnificationManager() {
CHECK(this == g_magnification_manager); CHECK(this == g_magnification_manager);
views::AXEventManager::Get()->RemoveObserver(this);
user_manager::UserManager::Get()->RemoveSessionStateObserver(this); user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
} }
...@@ -281,17 +305,22 @@ void MagnificationManager::HandleFocusChangedInPage( ...@@ -281,17 +305,22 @@ void MagnificationManager::HandleFocusChangedInPage(
if (node_details->is_editable_node) if (node_details->is_editable_node)
return; return;
const gfx::Rect& bounds_in_screen = node_details->node_bounds_in_screen; HandleFocusChanged(node_details->node_bounds_in_screen,
node_details->is_editable_node);
}
void MagnificationManager::HandleFocusChanged(const gfx::Rect& bounds_in_screen,
bool is_editable) {
if (bounds_in_screen.IsEmpty()) if (bounds_in_screen.IsEmpty())
return; return;
// Fullscreen magnifier and docked magnifier are mutually exclusive. // Fullscreen magnifier and docked magnifier are mutually exclusive.
if (fullscreen_magnifier_enabled_) { if (fullscreen_magnifier_enabled_) {
ash::Shell::Get()->magnification_controller()->HandleFocusedNodeChanged( ash::Shell::Get()->magnification_controller()->HandleFocusedNodeChanged(
node_details->is_editable_node, node_details->node_bounds_in_screen); is_editable, bounds_in_screen);
return; return;
} }
DCHECK(docked_magnifier_enabled); DCHECK(IsDockedMagnifierEnabled());
ash::DockedMagnifierController::Get()->CenterOnPoint( ash::DockedMagnifierController::Get()->CenterOnPoint(
bounds_in_screen.CenterPoint()); bounds_in_screen.CenterPoint());
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "ui/views/accessibility/ax_event_observer.h"
class PrefChangeRegistrar; class PrefChangeRegistrar;
...@@ -33,7 +34,8 @@ namespace chromeos { ...@@ -33,7 +34,8 @@ namespace chromeos {
class MagnificationManager class MagnificationManager
: public content::NotificationObserver, : public content::NotificationObserver,
public user_manager::UserManager::UserSessionStateObserver, public user_manager::UserManager::UserSessionStateObserver,
public ProfileObserver { public ProfileObserver,
public views::AXEventObserver {
public: public:
// Creates an instance of MagnificationManager. This should be called once. // Creates an instance of MagnificationManager. This should be called once.
static void Initialize(); static void Initialize();
...@@ -65,6 +67,9 @@ class MagnificationManager ...@@ -65,6 +67,9 @@ class MagnificationManager
// ProfileObserver: // ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override; void OnProfileWillBeDestroyed(Profile* profile) override;
// views::AXEventObserver:
void OnViewEvent(views::View* view, ax::mojom::Event event_type) override;
void SetProfileForTest(Profile* profile); void SetProfileForTest(Profile* profile);
private: private:
...@@ -91,6 +96,9 @@ class MagnificationManager ...@@ -91,6 +96,9 @@ class MagnificationManager
// Called when received content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE. // Called when received content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE.
void HandleFocusChangedInPage(const content::NotificationDetails& details); void HandleFocusChangedInPage(const content::NotificationDetails& details);
// Called in response to AXEventObserver.
void HandleFocusChanged(const gfx::Rect& bounds_in_screen, bool is_editable);
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
ScopedObserver<Profile, ProfileObserver> profile_observer_{this}; ScopedObserver<Profile, ProfileObserver> profile_observer_{this};
......
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