2011-04-27 17:42:18 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2011-05-28 02:37:24 +04:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "InterfaceInitFuncs.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2021-02-20 02:14:32 +03:00
|
|
|
#include "LocalAccessible-inl.h"
|
2012-05-29 05:18:45 +04:00
|
|
|
#include "AccessibleWrap.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
#include "nsAccUtils.h"
|
2012-03-20 08:02:50 +04:00
|
|
|
#include "nsMai.h"
|
2023-09-26 21:41:32 +03:00
|
|
|
#include "nsWindow.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2020-03-26 18:27:45 +03:00
|
|
|
#include "mozilla/a11y/DocAccessibleParent.h"
|
2021-02-20 02:14:33 +03:00
|
|
|
#include "mozilla/a11y/RemoteAccessible.h"
|
2020-03-26 18:27:45 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2023-09-26 21:41:32 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2023-05-19 05:56:48 +03:00
|
|
|
#include "nsAccessibilityService.h"
|
2010-04-27 10:52:03 +04:00
|
|
|
|
2023-04-19 19:17:31 +03:00
|
|
|
using namespace mozilla;
|
2012-11-18 06:01:44 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2012-03-20 08:02:50 +04:00
|
|
|
extern "C" {
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2011-04-27 17:42:18 +04:00
|
|
|
static AtkObject* refAccessibleAtPointCB(AtkComponent* aComponent, gint aAccX,
|
2003-05-06 06:23:50 +04:00
|
|
|
gint aAccY, AtkCoordType aCoordType) {
|
2015-09-02 00:57:57 +03:00
|
|
|
return refAccessibleAtPointHelper(ATK_OBJECT(aComponent), aAccX, aAccY,
|
2011-04-27 17:42:18 +04:00
|
|
|
aCoordType);
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
|
|
|
|
2011-04-27 17:42:18 +04:00
|
|
|
static void getExtentsCB(AtkComponent* aComponent, gint* aX, gint* aY,
|
|
|
|
gint* aWidth, gint* aHeight, AtkCoordType aCoordType) {
|
2015-09-02 00:57:57 +03:00
|
|
|
getExtentsHelper(ATK_OBJECT(aComponent), aX, aY, aWidth, aHeight, aCoordType);
|
2011-04-27 17:42:18 +04:00
|
|
|
}
|
2007-01-16 21:37:21 +03:00
|
|
|
|
2011-04-27 17:42:18 +04:00
|
|
|
static gboolean grabFocusCB(AtkComponent* aComponent) {
|
2015-09-02 00:57:57 +03:00
|
|
|
AtkObject* atkObject = ATK_OBJECT(aComponent);
|
2021-11-05 03:52:15 +03:00
|
|
|
Accessible* acc = GetInternalObj(atkObject);
|
|
|
|
if (acc) {
|
|
|
|
acc->TakeFocus();
|
2015-09-02 00:57:57 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
2018-05-02 16:55:33 +03:00
|
|
|
|
|
|
|
// ScrollType is compatible
|
2019-04-13 15:13:13 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2018-05-02 16:55:33 +03:00
|
|
|
static gboolean scrollToCB(AtkComponent* aComponent, AtkScrollType type) {
|
|
|
|
AtkObject* atkObject = ATK_OBJECT(aComponent);
|
2022-04-19 00:55:39 +03:00
|
|
|
if (Accessible* acc = GetInternalObj(atkObject)) {
|
|
|
|
acc->ScrollTo(type);
|
2018-05-02 16:55:33 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CoordType is compatible
|
|
|
|
static gboolean scrollToPointCB(AtkComponent* aComponent, AtkCoordType coords,
|
|
|
|
gint x, gint y) {
|
|
|
|
AtkObject* atkObject = ATK_OBJECT(aComponent);
|
|
|
|
AccessibleWrap* accWrap = GetAccessibleWrap(atkObject);
|
|
|
|
if (accWrap) {
|
|
|
|
accWrap->ScrollToPoint(coords, x, y);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-02-20 02:14:33 +03:00
|
|
|
RemoteAccessible* proxy = GetProxy(atkObject);
|
2018-05-02 16:55:33 +03:00
|
|
|
if (proxy) {
|
|
|
|
proxy->ScrollToPoint(coords, x, y);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-03-20 08:02:50 +04:00
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2015-09-02 00:57:57 +03:00
|
|
|
AtkObject* refAccessibleAtPointHelper(AtkObject* aAtkObj, gint aX, gint aY,
|
2011-04-27 17:42:18 +04:00
|
|
|
AtkCoordType aCoordType) {
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* acc = GetInternalObj(aAtkObj);
|
2023-05-25 00:36:00 +03:00
|
|
|
if (!acc) {
|
2020-03-26 18:27:45 +03:00
|
|
|
return nullptr;
|
2011-04-27 17:42:18 +04:00
|
|
|
}
|
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
// Accessible::ChildAtPoint(x,y) is in screen pixels.
|
2020-03-26 18:27:45 +03:00
|
|
|
if (aCoordType == ATK_XY_WINDOW) {
|
2022-01-19 02:31:21 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint winCoords =
|
2022-04-28 19:58:19 +03:00
|
|
|
nsAccUtils::GetScreenCoordsForWindow(acc);
|
2020-03-26 18:27:45 +03:00
|
|
|
aX += winCoords.x;
|
|
|
|
aY += winCoords.y;
|
2015-09-02 00:57:57 +03:00
|
|
|
}
|
2011-04-27 17:42:18 +04:00
|
|
|
|
2021-07-22 20:58:49 +03:00
|
|
|
Accessible* accAtPoint =
|
|
|
|
acc->ChildAtPoint(aX, aY, Accessible::EWhichChildAtPoint::DeepestChild);
|
|
|
|
if (!accAtPoint) {
|
2020-03-26 18:27:45 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2021-07-22 20:58:49 +03:00
|
|
|
roles::Role role = accAtPoint->Role();
|
2020-03-26 18:27:45 +03:00
|
|
|
if (role == roles::TEXT_LEAF || role == roles::STATICTEXT) {
|
|
|
|
// We don't include text leaf nodes in the ATK tree, so return the parent.
|
2021-07-22 20:58:49 +03:00
|
|
|
accAtPoint = accAtPoint->Parent();
|
|
|
|
MOZ_ASSERT(accAtPoint, "Text leaf should always have a parent");
|
2020-03-26 18:27:45 +03:00
|
|
|
}
|
|
|
|
AtkObject* atkObj = GetWrapperFor(accAtPoint);
|
|
|
|
if (atkObj) {
|
|
|
|
g_object_ref(atkObj);
|
|
|
|
}
|
|
|
|
return atkObj;
|
2011-04-27 17:42:18 +04:00
|
|
|
}
|
|
|
|
|
2023-09-26 21:41:32 +03:00
|
|
|
static double getScaleFactor(Accessible* aAccessible) {
|
|
|
|
DocAccessible* docAcc = nullptr;
|
|
|
|
if (LocalAccessible* localAcc = aAccessible->AsLocal()) {
|
|
|
|
docAcc = localAcc->Document();
|
|
|
|
} else {
|
|
|
|
RemoteAccessible* remote = aAccessible->AsRemote();
|
|
|
|
LocalAccessible* outerDoc = remote->OuterDocOfRemoteBrowser();
|
|
|
|
if (outerDoc) {
|
|
|
|
docAcc = outerDoc->Document();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!docAcc || !docAcc->DocumentNode()) {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> rootWidget =
|
|
|
|
nsContentUtils::WidgetForDocument(docAcc->DocumentNode());
|
|
|
|
if (!rootWidget) {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RefPtr<nsWindow> window =
|
|
|
|
static_cast<nsWindow*>(rootWidget->GetTopLevelWidget())) {
|
|
|
|
return window->FractionalScaleFactor();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2011-04-27 17:42:18 +04:00
|
|
|
void getExtentsHelper(AtkObject* aAtkObj, gint* aX, gint* aY, gint* aWidth,
|
|
|
|
gint* aHeight, AtkCoordType aCoordType) {
|
2019-08-21 01:42:49 +03:00
|
|
|
*aX = *aY = *aWidth = *aHeight = -1;
|
2011-04-27 17:42:18 +04:00
|
|
|
|
2023-04-19 19:17:31 +03:00
|
|
|
Accessible* acc = GetInternalObj(aAtkObj);
|
2023-05-25 00:36:00 +03:00
|
|
|
if (!acc) {
|
2023-04-19 19:17:31 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-09-02 00:57:57 +03:00
|
|
|
|
2023-04-19 19:17:31 +03:00
|
|
|
mozilla::LayoutDeviceIntRect screenRect = acc->Bounds();
|
|
|
|
if (screenRect.IsEmpty()) {
|
2011-04-27 17:42:18 +04:00
|
|
|
return;
|
|
|
|
}
|
2003-05-06 06:23:50 +04:00
|
|
|
|
2023-04-19 19:17:31 +03:00
|
|
|
if (aCoordType == ATK_XY_WINDOW) {
|
|
|
|
mozilla::LayoutDeviceIntPoint winCoords =
|
|
|
|
nsAccUtils::GetScreenCoordsForWindow(acc);
|
|
|
|
screenRect.x -= winCoords.x;
|
|
|
|
screenRect.y -= winCoords.y;
|
2015-09-02 00:57:57 +03:00
|
|
|
}
|
2023-04-19 19:17:31 +03:00
|
|
|
|
2023-09-26 21:41:32 +03:00
|
|
|
double scaleFactor = getScaleFactor(acc);
|
|
|
|
|
|
|
|
*aX = screenRect.x / scaleFactor;
|
|
|
|
*aY = screenRect.y / scaleFactor;
|
|
|
|
*aWidth = screenRect.width / scaleFactor;
|
|
|
|
*aHeight = screenRect.height / scaleFactor;
|
2003-05-06 06:23:50 +04:00
|
|
|
}
|
2012-03-20 08:02:50 +04:00
|
|
|
|
|
|
|
void componentInterfaceInitCB(AtkComponentIface* aIface) {
|
|
|
|
NS_ASSERTION(aIface, "Invalid Interface");
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(!aIface)) return;
|
2012-03-20 08:02:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Use default implementation in atk for contains, get_position,
|
|
|
|
* and get_size
|
|
|
|
*/
|
|
|
|
aIface->ref_accessible_at_point = refAccessibleAtPointCB;
|
|
|
|
aIface->get_extents = getExtentsCB;
|
|
|
|
aIface->grab_focus = grabFocusCB;
|
2018-05-02 16:55:33 +03:00
|
|
|
if (IsAtkVersionAtLeast(2, 30)) {
|
|
|
|
aIface->scroll_to = scrollToCB;
|
|
|
|
aIface->scroll_to_point = scrollToPointCB;
|
|
|
|
}
|
2012-03-20 08:02:50 +04:00
|
|
|
}
|