accessible/src/atk/nsMaiInterfaceComponent.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "InterfaceInitFuncs.h"
michael@0 8
michael@0 9 #include "AccessibleWrap.h"
michael@0 10 #include "nsAccUtils.h"
michael@0 11 #include "nsCoreUtils.h"
michael@0 12 #include "nsMai.h"
michael@0 13 #include "mozilla/Likely.h"
michael@0 14
michael@0 15 using namespace mozilla::a11y;
michael@0 16
michael@0 17 extern "C" {
michael@0 18
michael@0 19 static AtkObject*
michael@0 20 refAccessibleAtPointCB(AtkComponent* aComponent, gint aAccX, gint aAccY,
michael@0 21 AtkCoordType aCoordType)
michael@0 22 {
michael@0 23 return refAccessibleAtPointHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)),
michael@0 24 aAccX, aAccY, aCoordType);
michael@0 25 }
michael@0 26
michael@0 27 static void
michael@0 28 getExtentsCB(AtkComponent* aComponent, gint* aX, gint* aY,
michael@0 29 gint* aWidth, gint* aHeight, AtkCoordType aCoordType)
michael@0 30 {
michael@0 31 getExtentsHelper(GetAccessibleWrap(ATK_OBJECT(aComponent)),
michael@0 32 aX, aY, aWidth, aHeight, aCoordType);
michael@0 33 }
michael@0 34
michael@0 35 static gboolean
michael@0 36 grabFocusCB(AtkComponent* aComponent)
michael@0 37 {
michael@0 38 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aComponent));
michael@0 39 if (!accWrap)
michael@0 40 return FALSE;
michael@0 41
michael@0 42 nsresult rv = accWrap->TakeFocus();
michael@0 43 return (NS_FAILED(rv)) ? FALSE : TRUE;
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 AtkObject*
michael@0 48 refAccessibleAtPointHelper(AccessibleWrap* aAccWrap, gint aX, gint aY,
michael@0 49 AtkCoordType aCoordType)
michael@0 50 {
michael@0 51 if (!aAccWrap || aAccWrap->IsDefunct() || nsAccUtils::MustPrune(aAccWrap))
michael@0 52 return nullptr;
michael@0 53
michael@0 54 // Accessible::ChildAtPoint(x,y) is in screen pixels.
michael@0 55 if (aCoordType == ATK_XY_WINDOW) {
michael@0 56 nsIntPoint winCoords =
michael@0 57 nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode());
michael@0 58 aX += winCoords.x;
michael@0 59 aY += winCoords.y;
michael@0 60 }
michael@0 61
michael@0 62 Accessible* accAtPoint = aAccWrap->ChildAtPoint(aX, aY,
michael@0 63 Accessible::eDirectChild);
michael@0 64 if (!accAtPoint)
michael@0 65 return nullptr;
michael@0 66
michael@0 67 AtkObject* atkObj = AccessibleWrap::GetAtkObject(accAtPoint);
michael@0 68 if (atkObj)
michael@0 69 g_object_ref(atkObj);
michael@0 70 return atkObj;
michael@0 71 }
michael@0 72
michael@0 73 void
michael@0 74 getExtentsHelper(AccessibleWrap* aAccWrap,
michael@0 75 gint* aX, gint* aY, gint* aWidth, gint* aHeight,
michael@0 76 AtkCoordType aCoordType)
michael@0 77 {
michael@0 78 *aX = *aY = *aWidth = *aHeight = 0;
michael@0 79
michael@0 80 if (!aAccWrap || aAccWrap->IsDefunct())
michael@0 81 return;
michael@0 82
michael@0 83 int32_t x = 0, y = 0, width = 0, height = 0;
michael@0 84 // Returned in screen coordinates
michael@0 85 nsresult rv = aAccWrap->GetBounds(&x, &y, &width, &height);
michael@0 86 if (NS_FAILED(rv))
michael@0 87 return;
michael@0 88
michael@0 89 if (aCoordType == ATK_XY_WINDOW) {
michael@0 90 nsIntPoint winCoords =
michael@0 91 nsCoreUtils::GetScreenCoordsForWindow(aAccWrap->GetNode());
michael@0 92 x -= winCoords.x;
michael@0 93 y -= winCoords.y;
michael@0 94 }
michael@0 95
michael@0 96 *aX = x;
michael@0 97 *aY = y;
michael@0 98 *aWidth = width;
michael@0 99 *aHeight = height;
michael@0 100 }
michael@0 101
michael@0 102 void
michael@0 103 componentInterfaceInitCB(AtkComponentIface* aIface)
michael@0 104 {
michael@0 105 NS_ASSERTION(aIface, "Invalid Interface");
michael@0 106 if(MOZ_UNLIKELY(!aIface))
michael@0 107 return;
michael@0 108
michael@0 109 /*
michael@0 110 * Use default implementation in atk for contains, get_position,
michael@0 111 * and get_size
michael@0 112 */
michael@0 113 aIface->ref_accessible_at_point = refAccessibleAtPointCB;
michael@0 114 aIface->get_extents = getExtentsCB;
michael@0 115 aIface->grab_focus = grabFocusCB;
michael@0 116 }

mercurial