1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/*
* Copyright (C) 2008 Nuanti Ltd.
* Copyright (C) 2009 Jan Alonzo
* Copyright (C) 2009, 2012 Igalia S.L.
*
* Portions from Mozilla a11y, copyright as follows:
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Sun Microsystems, Inc.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "WebKitAccessibleInterfaceComponent.h"
#if ENABLE(ACCESSIBILITY)
#include "AccessibilityObject.h"
#include "FrameView.h"
#include "IntRect.h"
#include "RenderLayer.h"
#include "WebKitAccessible.h"
#include "WebKitAccessibleUtil.h"
using namespace WebCore;
static IntPoint atkToContents(const AccessibilityObject& coreObject, AtkCoordType coordType, gint x, gint y)
{
auto* frameView = coreObject.documentFrameView();
if (!frameView)
return { x, y };
switch (coordType) {
case ATK_XY_SCREEN:
return frameView->screenToContents({ x, y });
case ATK_XY_WINDOW:
return frameView->windowToContents({ x, y });
#if ATK_CHECK_VERSION(2, 30, 0)
case ATK_XY_PARENT:
RELEASE_ASSERT_NOT_REACHED();
#endif
}
return { x, y };
}
static AtkObject* webkitAccessibleComponentRefAccessibleAtPoint(AtkComponent* component, gint x, gint y, AtkCoordType coordType)
{
auto* accessible = WEBKIT_ACCESSIBLE(component);
returnValIfWebKitAccessibleIsInvalid(accessible, nullptr);
auto& coreObject = webkitAccessibleGetAccessibilityObject(accessible);
auto* target = downcast<AccessibilityObject>(coreObject.accessibilityHitTest(atkToContents(coreObject, coordType, x, y)));
if (!target)
return nullptr;
if (auto* wrapper = target->wrapper())
return ATK_OBJECT(g_object_ref(wrapper));
return nullptr;
}
static void webkitAccessibleComponentGetExtents(AtkComponent* component, gint* x, gint* y, gint* width, gint* height, AtkCoordType coordType)
{
auto* accessible = WEBKIT_ACCESSIBLE(component);
returnIfWebKitAccessibleIsInvalid(accessible);
auto& coreObject = webkitAccessibleGetAccessibilityObject(accessible);
contentsRelativeToAtkCoordinateType(&coreObject, coordType, snappedIntRect(coreObject.elementRect()), x, y, width, height);
}
static gboolean webkitAccessibleComponentGrabFocus(AtkComponent* component)
{
auto* accessible = WEBKIT_ACCESSIBLE(component);
returnValIfWebKitAccessibleIsInvalid(accessible, FALSE);
auto& coreObject = webkitAccessibleGetAccessibilityObject(accessible);
coreObject.setFocused(true);
return coreObject.isFocused();
}
#if ATK_CHECK_VERSION(2, 30, 0)
static gboolean webkitAccessibleComponentScrollTo(AtkComponent* component, AtkScrollType scrollType)
{
auto* accessible = WEBKIT_ACCESSIBLE(component);
returnValIfWebKitAccessibleIsInvalid(accessible, FALSE);
ScrollAlignment alignX;
ScrollAlignment alignY;
switch (scrollType) {
case ATK_SCROLL_TOP_LEFT:
alignX = ScrollAlignment::alignLeftAlways;
alignY = ScrollAlignment::alignTopAlways;
break;
case ATK_SCROLL_BOTTOM_RIGHT:
alignX = ScrollAlignment::alignRightAlways;
alignY = ScrollAlignment::alignBottomAlways;
break;
case ATK_SCROLL_TOP_EDGE:
case ATK_SCROLL_BOTTOM_EDGE:
// Align to a particular edge is not supported, it's always the closest edge.
alignX = ScrollAlignment::alignCenterIfNeeded;
alignY = ScrollAlignment::alignToEdgeIfNeeded;
break;
case ATK_SCROLL_LEFT_EDGE:
case ATK_SCROLL_RIGHT_EDGE:
// Align to a particular edge is not supported, it's always the closest edge.
alignX = ScrollAlignment::alignToEdgeIfNeeded;
alignY = ScrollAlignment::alignCenterIfNeeded;
break;
case ATK_SCROLL_ANYWHERE:
alignX = ScrollAlignment::alignCenterIfNeeded;
alignY = ScrollAlignment::alignCenterIfNeeded;
break;
}
auto& coreObject = webkitAccessibleGetAccessibilityObject(accessible);
coreObject.scrollToMakeVisible({ SelectionRevealMode::Reveal, alignX, alignY, ShouldAllowCrossOriginScrolling::Yes });
return TRUE;
}
static gboolean webkitAccessibleComponentScrollToPoint(AtkComponent* component, AtkCoordType coordType, gint x, gint y)
{
auto* accessible = WEBKIT_ACCESSIBLE(component);
returnValIfWebKitAccessibleIsInvalid(accessible, FALSE);
auto& coreObject = webkitAccessibleGetAccessibilityObject(accessible);
IntPoint point(x, y);
if (coordType == ATK_XY_SCREEN) {
if (auto* frameView = coreObject.documentFrameView())
point = frameView->contentsToWindow(frameView->screenToContents(point));
}
coreObject.scrollToGlobalPoint(point);
return TRUE;
}
#endif
void webkitAccessibleComponentInterfaceInit(AtkComponentIface* iface)
{
iface->ref_accessible_at_point = webkitAccessibleComponentRefAccessibleAtPoint;
iface->get_extents = webkitAccessibleComponentGetExtents;
iface->grab_focus = webkitAccessibleComponentGrabFocus;
#if ATK_CHECK_VERSION(2, 30, 0)
iface->scroll_to = webkitAccessibleComponentScrollTo;
iface->scroll_to_point = webkitAccessibleComponentScrollToPoint;
#endif
}
#endif // ENABLE(ACCESSIBILITY)
|