accessible/src/html/HTMLListAccessible.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 file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "HTMLListAccessible.h"
michael@0 8
michael@0 9 #include "DocAccessible.h"
michael@0 10 #include "nsAccUtils.h"
michael@0 11 #include "Role.h"
michael@0 12 #include "States.h"
michael@0 13
michael@0 14 #include "nsBlockFrame.h"
michael@0 15 #include "nsBulletFrame.h"
michael@0 16
michael@0 17 using namespace mozilla;
michael@0 18 using namespace mozilla::a11y;
michael@0 19
michael@0 20 ////////////////////////////////////////////////////////////////////////////////
michael@0 21 // HTMLListAccessible
michael@0 22 ////////////////////////////////////////////////////////////////////////////////
michael@0 23
michael@0 24 NS_IMPL_ISUPPORTS_INHERITED0(HTMLListAccessible, HyperTextAccessible)
michael@0 25
michael@0 26 role
michael@0 27 HTMLListAccessible::NativeRole()
michael@0 28 {
michael@0 29 if (mContent->Tag() == nsGkAtoms::dl)
michael@0 30 return roles::DEFINITION_LIST;
michael@0 31
michael@0 32 return roles::LIST;
michael@0 33 }
michael@0 34
michael@0 35 uint64_t
michael@0 36 HTMLListAccessible::NativeState()
michael@0 37 {
michael@0 38 return HyperTextAccessibleWrap::NativeState() | states::READONLY;
michael@0 39 }
michael@0 40
michael@0 41
michael@0 42 ////////////////////////////////////////////////////////////////////////////////
michael@0 43 // HTMLLIAccessible
michael@0 44 ////////////////////////////////////////////////////////////////////////////////
michael@0 45
michael@0 46 HTMLLIAccessible::
michael@0 47 HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc) :
michael@0 48 HyperTextAccessibleWrap(aContent, aDoc), mBullet(nullptr)
michael@0 49 {
michael@0 50 mType = eHTMLLiType;
michael@0 51
michael@0 52 nsBlockFrame* blockFrame = do_QueryFrame(GetFrame());
michael@0 53 if (blockFrame && blockFrame->HasBullet()) {
michael@0 54 mBullet = new HTMLListBulletAccessible(mContent, mDoc);
michael@0 55 Document()->BindToDocument(mBullet, nullptr);
michael@0 56 }
michael@0 57 }
michael@0 58
michael@0 59 NS_IMPL_ISUPPORTS_INHERITED0(HTMLLIAccessible, HyperTextAccessible)
michael@0 60
michael@0 61 void
michael@0 62 HTMLLIAccessible::Shutdown()
michael@0 63 {
michael@0 64 mBullet = nullptr;
michael@0 65
michael@0 66 HyperTextAccessibleWrap::Shutdown();
michael@0 67 }
michael@0 68
michael@0 69 role
michael@0 70 HTMLLIAccessible::NativeRole()
michael@0 71 {
michael@0 72 if (mContent->Tag() == nsGkAtoms::dt)
michael@0 73 return roles::TERM;
michael@0 74
michael@0 75 return roles::LISTITEM;
michael@0 76 }
michael@0 77
michael@0 78 uint64_t
michael@0 79 HTMLLIAccessible::NativeState()
michael@0 80 {
michael@0 81 return HyperTextAccessibleWrap::NativeState() | states::READONLY;
michael@0 82 }
michael@0 83
michael@0 84 NS_IMETHODIMP
michael@0 85 HTMLLIAccessible::GetBounds(int32_t* aX, int32_t* aY,
michael@0 86 int32_t* aWidth, int32_t* aHeight)
michael@0 87 {
michael@0 88 nsresult rv = AccessibleWrap::GetBounds(aX, aY, aWidth, aHeight);
michael@0 89 if (NS_FAILED(rv) || !mBullet || mBullet->IsInside())
michael@0 90 return rv;
michael@0 91
michael@0 92 int32_t bulletX = 0, bulletY = 0, bulletWidth = 0, bulletHeight = 0;
michael@0 93 rv = mBullet->GetBounds(&bulletX, &bulletY, &bulletWidth, &bulletHeight);
michael@0 94 NS_ENSURE_SUCCESS(rv, rv);
michael@0 95
michael@0 96 *aWidth += *aX - bulletX;
michael@0 97 *aX = bulletX; // Move x coordinate of list item over to cover bullet as well
michael@0 98 return NS_OK;
michael@0 99 }
michael@0 100
michael@0 101 ////////////////////////////////////////////////////////////////////////////////
michael@0 102 // HTMLLIAccessible: public
michael@0 103
michael@0 104 void
michael@0 105 HTMLLIAccessible::UpdateBullet(bool aHasBullet)
michael@0 106 {
michael@0 107 if (aHasBullet == !!mBullet) {
michael@0 108 NS_NOTREACHED("Bullet and accessible are in sync already!");
michael@0 109 return;
michael@0 110 }
michael@0 111
michael@0 112 DocAccessible* document = Document();
michael@0 113 if (aHasBullet) {
michael@0 114 mBullet = new HTMLListBulletAccessible(mContent, mDoc);
michael@0 115 document->BindToDocument(mBullet, nullptr);
michael@0 116 InsertChildAt(0, mBullet);
michael@0 117 } else {
michael@0 118 RemoveChild(mBullet);
michael@0 119 document->UnbindFromDocument(mBullet);
michael@0 120 mBullet = nullptr;
michael@0 121 }
michael@0 122
michael@0 123 // XXXtodo: fire show/hide and reorder events. That's hard to make it
michael@0 124 // right now because coalescence happens by DOM node.
michael@0 125 }
michael@0 126
michael@0 127 ////////////////////////////////////////////////////////////////////////////////
michael@0 128 // HTMLLIAccessible: Accessible protected
michael@0 129
michael@0 130 void
michael@0 131 HTMLLIAccessible::CacheChildren()
michael@0 132 {
michael@0 133 if (mBullet)
michael@0 134 AppendChild(mBullet);
michael@0 135
michael@0 136 // Cache children from subtree.
michael@0 137 AccessibleWrap::CacheChildren();
michael@0 138 }
michael@0 139
michael@0 140 ////////////////////////////////////////////////////////////////////////////////
michael@0 141 // HTMLListBulletAccessible
michael@0 142 ////////////////////////////////////////////////////////////////////////////////
michael@0 143 HTMLListBulletAccessible::
michael@0 144 HTMLListBulletAccessible(nsIContent* aContent, DocAccessible* aDoc) :
michael@0 145 LeafAccessible(aContent, aDoc)
michael@0 146 {
michael@0 147 mStateFlags |= eSharedNode;
michael@0 148 }
michael@0 149
michael@0 150 ////////////////////////////////////////////////////////////////////////////////
michael@0 151 // HTMLListBulletAccessible: Accessible
michael@0 152
michael@0 153 nsIFrame*
michael@0 154 HTMLListBulletAccessible::GetFrame() const
michael@0 155 {
michael@0 156 nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
michael@0 157 return blockFrame ? blockFrame->GetBullet() : nullptr;
michael@0 158 }
michael@0 159
michael@0 160 ENameValueFlag
michael@0 161 HTMLListBulletAccessible::Name(nsString &aName)
michael@0 162 {
michael@0 163 aName.Truncate();
michael@0 164
michael@0 165 // Native anonymous content, ARIA can't be used. Get list bullet text.
michael@0 166 nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
michael@0 167 if (blockFrame) {
michael@0 168 blockFrame->GetBulletText(aName);
michael@0 169
michael@0 170 // Append space otherwise bullets are jammed up against list text.
michael@0 171 aName.Append(' ');
michael@0 172 }
michael@0 173
michael@0 174 return eNameOK;
michael@0 175 }
michael@0 176
michael@0 177 role
michael@0 178 HTMLListBulletAccessible::NativeRole()
michael@0 179 {
michael@0 180 return roles::STATICTEXT;
michael@0 181 }
michael@0 182
michael@0 183 uint64_t
michael@0 184 HTMLListBulletAccessible::NativeState()
michael@0 185 {
michael@0 186 return LeafAccessible::NativeState() | states::READONLY;
michael@0 187 }
michael@0 188
michael@0 189 void
michael@0 190 HTMLListBulletAccessible::AppendTextTo(nsAString& aText, uint32_t aStartOffset,
michael@0 191 uint32_t aLength)
michael@0 192 {
michael@0 193 nsAutoString bulletText;
michael@0 194 nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
michael@0 195 if (blockFrame)
michael@0 196 blockFrame->GetBulletText(bulletText);
michael@0 197
michael@0 198 aText.Append(Substring(bulletText, aStartOffset, aLength));
michael@0 199 }
michael@0 200
michael@0 201 ////////////////////////////////////////////////////////////////////////////////
michael@0 202 // HTMLListBulletAccessible: public
michael@0 203
michael@0 204 bool
michael@0 205 HTMLListBulletAccessible::IsInside() const
michael@0 206 {
michael@0 207 nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
michael@0 208 return blockFrame ? blockFrame->HasInsideBullet() : false;
michael@0 209 }

mercurial