accessible/src/atk/nsMaiInterfaceAction.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 "Accessible-inl.h"
michael@0 10 #include "nsMai.h"
michael@0 11 #include "Role.h"
michael@0 12 #include "mozilla/Likely.h"
michael@0 13
michael@0 14 #include "nsString.h"
michael@0 15
michael@0 16 using namespace mozilla::a11y;
michael@0 17
michael@0 18 extern "C" {
michael@0 19
michael@0 20 static gboolean
michael@0 21 doActionCB(AtkAction *aAction, gint aActionIndex)
michael@0 22 {
michael@0 23 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
michael@0 24 if (!accWrap)
michael@0 25 return FALSE;
michael@0 26
michael@0 27 nsresult rv = accWrap->DoAction(aActionIndex);
michael@0 28 return (NS_FAILED(rv)) ? FALSE : TRUE;
michael@0 29 }
michael@0 30
michael@0 31 static gint
michael@0 32 getActionCountCB(AtkAction *aAction)
michael@0 33 {
michael@0 34 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
michael@0 35 return accWrap ? accWrap->ActionCount() : 0;
michael@0 36 }
michael@0 37
michael@0 38 static const gchar*
michael@0 39 getActionDescriptionCB(AtkAction *aAction, gint aActionIndex)
michael@0 40 {
michael@0 41 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
michael@0 42 if (!accWrap)
michael@0 43 return nullptr;
michael@0 44
michael@0 45 nsAutoString description;
michael@0 46 nsresult rv = accWrap->GetActionDescription(aActionIndex, description);
michael@0 47 NS_ENSURE_SUCCESS(rv, nullptr);
michael@0 48 return AccessibleWrap::ReturnString(description);
michael@0 49 }
michael@0 50
michael@0 51 static const gchar*
michael@0 52 getActionNameCB(AtkAction *aAction, gint aActionIndex)
michael@0 53 {
michael@0 54 AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aAction));
michael@0 55 if (!accWrap)
michael@0 56 return nullptr;
michael@0 57
michael@0 58 nsAutoString autoStr;
michael@0 59 nsresult rv = accWrap->GetActionName(aActionIndex, autoStr);
michael@0 60 NS_ENSURE_SUCCESS(rv, nullptr);
michael@0 61 return AccessibleWrap::ReturnString(autoStr);
michael@0 62 }
michael@0 63
michael@0 64 static const gchar*
michael@0 65 getKeyBindingCB(AtkAction *aAction, gint aActionIndex)
michael@0 66 {
michael@0 67 AccessibleWrap* acc = GetAccessibleWrap(ATK_OBJECT(aAction));
michael@0 68 if (!acc)
michael@0 69 return nullptr;
michael@0 70
michael@0 71 // Return all key bindings including access key and keyboard shortcut.
michael@0 72 nsAutoString keyBindingsStr;
michael@0 73
michael@0 74 // Get access key.
michael@0 75 KeyBinding keyBinding = acc->AccessKey();
michael@0 76 if (!keyBinding.IsEmpty()) {
michael@0 77 keyBinding.AppendToString(keyBindingsStr, KeyBinding::eAtkFormat);
michael@0 78
michael@0 79 Accessible* parent = acc->Parent();
michael@0 80 roles::Role role = parent ? parent->Role() : roles::NOTHING;
michael@0 81 if (role == roles::PARENT_MENUITEM || role == roles::MENUITEM ||
michael@0 82 role == roles::RADIO_MENU_ITEM || role == roles::CHECK_MENU_ITEM) {
michael@0 83 // It is submenu, expose keyboard shortcuts from menu hierarchy like
michael@0 84 // "s;<Alt>f:s"
michael@0 85 nsAutoString keysInHierarchyStr = keyBindingsStr;
michael@0 86 do {
michael@0 87 KeyBinding parentKeyBinding = parent->AccessKey();
michael@0 88 if (!parentKeyBinding.IsEmpty()) {
michael@0 89 nsAutoString str;
michael@0 90 parentKeyBinding.ToString(str, KeyBinding::eAtkFormat);
michael@0 91 str.Append(':');
michael@0 92
michael@0 93 keysInHierarchyStr.Insert(str, 0);
michael@0 94 }
michael@0 95 } while ((parent = parent->Parent()) && parent->Role() != roles::MENUBAR);
michael@0 96
michael@0 97 keyBindingsStr.Append(';');
michael@0 98 keyBindingsStr.Append(keysInHierarchyStr);
michael@0 99 }
michael@0 100 } else {
michael@0 101 // No access key, add ';' to point this.
michael@0 102 keyBindingsStr.Append(';');
michael@0 103 }
michael@0 104
michael@0 105 // Get keyboard shortcut.
michael@0 106 keyBindingsStr.Append(';');
michael@0 107 keyBinding = acc->KeyboardShortcut();
michael@0 108 if (!keyBinding.IsEmpty()) {
michael@0 109 keyBinding.AppendToString(keyBindingsStr, KeyBinding::eAtkFormat);
michael@0 110 }
michael@0 111
michael@0 112 return AccessibleWrap::ReturnString(keyBindingsStr);
michael@0 113 }
michael@0 114 }
michael@0 115
michael@0 116 void
michael@0 117 actionInterfaceInitCB(AtkActionIface* aIface)
michael@0 118 {
michael@0 119 NS_ASSERTION(aIface, "Invalid aIface");
michael@0 120 if (MOZ_UNLIKELY(!aIface))
michael@0 121 return;
michael@0 122
michael@0 123 aIface->do_action = doActionCB;
michael@0 124 aIface->get_n_actions = getActionCountCB;
michael@0 125 aIface->get_description = getActionDescriptionCB;
michael@0 126 aIface->get_keybinding = getKeyBindingCB;
michael@0 127 aIface->get_name = getActionNameCB;
michael@0 128 }

mercurial