Commit 217c3a78 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Makes magnifier observe AXEventManager for focus changes

Bug: 865575
Change-Id: I8d8328a459d7621d6fc0a0d65e0f24f788b9767f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1852414
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704854}
parent 68d93953
......@@ -26,6 +26,7 @@
#include "content/public/browser/notification_source.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/views/accessibility/ax_event_manager.h"
namespace chromeos {
......@@ -94,6 +95,18 @@ double MagnificationManager::GetSavedScreenMagnifierScale() const {
ash::prefs::kAccessibilityScreenMagnifierScale);
}
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;
HandleFocusChanged(view->GetBoundsInScreen(), false);
}
void MagnificationManager::SetProfileForTest(Profile* profile) {
SetProfile(profile);
}
......@@ -108,10 +121,12 @@ MagnificationManager::MagnificationManager() {
registrar_.Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
content::NotificationService::AllSources());
user_manager::UserManager::Get()->AddSessionStateObserver(this);
views::AXEventManager::Get()->AddObserver(this);
}
MagnificationManager::~MagnificationManager() {
CHECK(this == g_magnification_manager);
views::AXEventManager::Get()->RemoveObserver(this);
user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
}
......@@ -280,17 +295,22 @@ void MagnificationManager::HandleFocusChangedInPage(
if (node_details->is_editable_node)
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())
return;
// Fullscreen magnifier and docked magnifier are mutually exclusive.
if (fullscreen_magnifier_enabled_) {
ash::Shell::Get()->magnification_controller()->HandleFocusedNodeChanged(
node_details->is_editable_node, node_details->node_bounds_in_screen);
is_editable, bounds_in_screen);
return;
}
DCHECK(docked_magnifier_enabled);
DCHECK(IsDockedMagnifierEnabled());
ash::DockedMagnifierController::Get()->CenterOnPoint(
bounds_in_screen.CenterPoint());
}
......
......@@ -10,6 +10,7 @@
#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/views/accessibility/ax_event_observer.h"
class PrefChangeRegistrar;
class Profile;
......@@ -30,7 +31,8 @@ namespace chromeos {
// either Fullscreen or Docked magnifier is enabled.
class MagnificationManager
: public content::NotificationObserver,
public user_manager::UserManager::UserSessionStateObserver {
public user_manager::UserManager::UserSessionStateObserver,
public views::AXEventObserver {
public:
// Creates an instance of MagnificationManager. This should be called once.
static void Initialize();
......@@ -59,6 +61,9 @@ class MagnificationManager
// Loads the Fullscreen magnifier scale from the pref.
double GetSavedScreenMagnifierScale() const;
// views::AXEventObserver:
void OnViewEvent(views::View* view, ax::mojom::Event event_type) override;
void SetProfileForTest(Profile* profile);
private:
......@@ -85,6 +90,9 @@ class MagnificationManager
// Called when received content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE.
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;
bool fullscreen_magnifier_enabled_ = false;
......
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