Commit 8912e35e authored by Josiah K's avatar Josiah K Committed by Commit Bot

Create new accessibilityPrivate method to update magnifier viewport

Parent Tracking Bug: 1131153

Fixed: 1129711
AX-Relnotes: Add accessibilityPrivate method to update magnifier viewport and focus following highlight
Change-Id: Id5fa2c05e39f763b7a599e3445f40945a71f5e42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417457Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: Josiah Krutz <josiahk@google.com>
Cr-Commit-Position: refs/heads/master@{#812228}
parent 4f97ffeb
...@@ -266,6 +266,16 @@ void MagnificationController::HandleFocusedNodeChanged( ...@@ -266,6 +266,16 @@ void MagnificationController::HandleFocusedNodeChanged(
MoveMagnifierWindowFollowRect(node_bounds_in_root); MoveMagnifierWindowFollowRect(node_bounds_in_root);
} }
void MagnificationController::HandleMoveMagnifierToRect(
const gfx::Rect& rect_in_screen) {
gfx::Rect node_bounds_in_root = rect_in_screen;
::wm::ConvertRectFromScreen(root_window_, &node_bounds_in_root);
if (GetViewportRect().Contains(node_bounds_in_root))
return;
MoveMagnifierWindowFollowRect(node_bounds_in_root);
}
void MagnificationController::SwitchTargetRootWindow( void MagnificationController::SwitchTargetRootWindow(
aura::Window* new_root_window, aura::Window* new_root_window,
bool redraw_original_root_window) { bool redraw_original_root_window) {
......
...@@ -109,6 +109,15 @@ class ASH_EXPORT MagnificationController : public ui::EventHandler, ...@@ -109,6 +109,15 @@ class ASH_EXPORT MagnificationController : public ui::EventHandler,
void HandleFocusedNodeChanged(bool is_editable_node, void HandleFocusedNodeChanged(bool is_editable_node,
const gfx::Rect& node_bounds_in_screen); const gfx::Rect& node_bounds_in_screen);
// Move |rect_in_screen| within the magnifier viewport. If |rect_in_screen| is
// already completely within the viewport, do nothing. If any edge of
// |rect_in_screen| is outside the viewport (e.g. if rect is larger than or
// extends partially beyond the viewport), center the overflowing dimensions
// of the viewport on center of |rect_in_screen| (e.g. center viewport
// vertically if |rect| extends beyond bottom of screen). Called from
// Accessibility Common extension. Called from Accessibility Common extension.
void HandleMoveMagnifierToRect(const gfx::Rect& rect_in_screen);
// Switch the magnified root window to |new_root_window|. This does following: // Switch the magnified root window to |new_root_window|. This does following:
// - Unzoom the current root_window. // - Unzoom the current root_window.
// - Zoom the given new root_window |new_root_window|. // - Zoom the given new root_window |new_root_window|.
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
#include "chrome/browser/extensions/api/tabs/tabs_constants.h" #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
#include "chrome/browser/extensions/chrome_extension_function_details.h" #include "chrome/browser/extensions/chrome_extension_function_details.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
...@@ -409,6 +410,22 @@ AccessibilityPrivateHandleScrollableBoundsForPointFoundFunction::Run() { ...@@ -409,6 +410,22 @@ AccessibilityPrivateHandleScrollableBoundsForPointFoundFunction::Run() {
return RespondNow(NoArguments()); return RespondNow(NoArguments());
} }
ExtensionFunction::ResponseAction
AccessibilityPrivateMoveMagnifierToRectFunction::Run() {
std::unique_ptr<accessibility_private::MoveMagnifierToRect::Params> params =
accessibility_private::MoveMagnifierToRect::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params);
accessibility_private::ScreenRect rect = std::move(params->rect);
gfx::Rect bounds(rect.left, rect.top, rect.width, rect.height);
chromeos::MagnificationManager* magnification_manager =
chromeos::MagnificationManager::Get();
if (magnification_manager)
magnification_manager->HandleMoveMagnifierToRectIfEnabled(bounds);
return RespondNow(NoArguments());
}
ExtensionFunction::ResponseAction ExtensionFunction::ResponseAction
AccessibilityPrivateToggleDictationFunction::Run() { AccessibilityPrivateToggleDictationFunction::Run() {
ash::DictationToggleSource source = ash::DictationToggleSource::kChromevox; ash::DictationToggleSource source = ash::DictationToggleSource::kChromevox;
......
...@@ -120,6 +120,16 @@ class AccessibilityPrivateHandleScrollableBoundsForPointFoundFunction ...@@ -120,6 +120,16 @@ class AccessibilityPrivateHandleScrollableBoundsForPointFoundFunction
ACCESSIBILITY_PRIVATE_HANDLESCROLLABLEBOUNDSFORPOINTFOUND) ACCESSIBILITY_PRIVATE_HANDLESCROLLABLEBOUNDSFORPOINTFOUND)
}; };
// API function that is called by the Accessibility Common extension to center
// the magnifier viewport on a passed-in rect.
class AccessibilityPrivateMoveMagnifierToRectFunction
: public ExtensionFunction {
~AccessibilityPrivateMoveMagnifierToRectFunction() override {}
ResponseAction Run() override;
DECLARE_EXTENSION_FUNCTION("accessibilityPrivate.moveMagnifierToRect",
ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT)
};
// API function that is called when a user toggles Dictation from another // API function that is called when a user toggles Dictation from another
// acessibility feature. // acessibility feature.
class AccessibilityPrivateToggleDictationFunction : public ExtensionFunction { class AccessibilityPrivateToggleDictationFunction : public ExtensionFunction {
......
...@@ -108,6 +108,19 @@ void MagnificationManager::HandleFocusedRectChangedIfEnabled( ...@@ -108,6 +108,19 @@ void MagnificationManager::HandleFocusedRectChangedIfEnabled(
HandleFocusChanged(bounds_in_screen, is_editable); HandleFocusChanged(bounds_in_screen, is_editable);
} }
void MagnificationManager::HandleMoveMagnifierToRectIfEnabled(
const gfx::Rect& rect) {
// Fullscreen magnifier and docked magnifier are mutually exclusive.
if (fullscreen_magnifier_enabled_) {
ash::Shell::Get()->magnification_controller()->HandleMoveMagnifierToRect(
rect);
return;
}
if (IsDockedMagnifierEnabled()) {
ash::DockedMagnifierController::Get()->CenterOnPoint(rect.CenterPoint());
}
}
void MagnificationManager::OnViewEvent(views::View* view, void MagnificationManager::OnViewEvent(views::View* view,
ax::mojom::Event event_type) { ax::mojom::Event event_type) {
if (!fullscreen_magnifier_enabled_ && !IsDockedMagnifierEnabled()) if (!fullscreen_magnifier_enabled_ && !IsDockedMagnifierEnabled())
......
...@@ -68,6 +68,9 @@ class MagnificationManager ...@@ -68,6 +68,9 @@ class MagnificationManager
void HandleFocusedRectChangedIfEnabled(const gfx::Rect& bounds_in_screen, void HandleFocusedRectChangedIfEnabled(const gfx::Rect& bounds_in_screen,
bool is_editable); bool is_editable);
// Move magnifier to ensure rect is within viewport if a magnifier is enabled.
void HandleMoveMagnifierToRectIfEnabled(const gfx::Rect& rect);
// ProfileObserver: // ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override; void OnProfileWillBeDestroyed(Profile* profile) override;
......
...@@ -407,6 +407,19 @@ ...@@ -407,6 +407,19 @@
], ],
"platforms": ["chromeos"] "platforms": ["chromeos"]
}, },
{
"name": "moveMagnifierToRect",
"type": "function",
"description": "Called by the Accessibility Common extension to move |rect| within the magnifier viewport (e.g. when focus has changed). If |rect| is already completely within the viewport, magnifier doesn't move. If any edge of |rect| is outside the viewport (e.g. if rect is larger than or extends partially beyond the viewport), magnifier will center the overflowing dimensions of the viewport on center of |rect| (e.g. center viewport vertically if |rect| extends beyond bottom of screen).",
"parameters": [
{
"name": "rect",
"$ref": "ScreenRect",
"description": "Rect to ensure visible in the magnified viewport."
}
],
"platforms": ["chromeos"]
},
{ {
"name": "toggleDictation", "name": "toggleDictation",
"type": "function", "type": "function",
......
...@@ -1570,6 +1570,7 @@ enum HistogramValue { ...@@ -1570,6 +1570,7 @@ enum HistogramValue {
ACCESSIBILITY_PRIVATE_PERFORMACCELERATORACTION = 1507, ACCESSIBILITY_PRIVATE_PERFORMACCELERATORACTION = 1507,
DECLARATIVENETREQUEST_ISREGEXSUPPORTED = 1508, DECLARATIVENETREQUEST_ISREGEXSUPPORTED = 1508,
PASSWORDSPRIVATE_GETWEAKCREDENTIALS = 1509, PASSWORDSPRIVATE_GETWEAKCREDENTIALS = 1509,
ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT = 1510,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -314,6 +314,14 @@ chrome.accessibilityPrivate.setSelectToSpeakState = function(state) {}; ...@@ -314,6 +314,14 @@ chrome.accessibilityPrivate.setSelectToSpeakState = function(state) {};
*/ */
chrome.accessibilityPrivate.handleScrollableBoundsForPointFound = function(rect) {}; chrome.accessibilityPrivate.handleScrollableBoundsForPointFound = function(rect) {};
/**
* Called by the Accessibility Common extension to update the magnifier viewport
* (e.g. when focus has changed).
* @param {!chrome.accessibilityPrivate.ScreenRect} rect Rect to ensure visible
* in the magnified viewport.
*/
chrome.accessibilityPrivate.moveMagnifierToRect = function(rect) {};
/** /**
* Toggles dictation between active and inactive states. * Toggles dictation between active and inactive states.
*/ */
......
...@@ -24634,6 +24634,7 @@ Called by update_extension_histograms.py.--> ...@@ -24634,6 +24634,7 @@ Called by update_extension_histograms.py.-->
<int value="1507" label="ACCESSIBILITY_PRIVATE_PERFORMACCELERATORACTION"/> <int value="1507" label="ACCESSIBILITY_PRIVATE_PERFORMACCELERATORACTION"/>
<int value="1508" label="DECLARATIVENETREQUEST_ISREGEXSUPPORTED"/> <int value="1508" label="DECLARATIVENETREQUEST_ISREGEXSUPPORTED"/>
<int value="1509" label="PASSWORDSPRIVATE_GETWEAKCREDENTIALS"/> <int value="1509" label="PASSWORDSPRIVATE_GETWEAKCREDENTIALS"/>
<int value="1510" label="ACCESSIBILITY_PRIVATE_MOVEMAGNIFIERTORECT"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
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