accessible/src/html/HTMLListAccessible.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/html/HTMLListAccessible.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,209 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "HTMLListAccessible.h"
    1.11 +
    1.12 +#include "DocAccessible.h"
    1.13 +#include "nsAccUtils.h"
    1.14 +#include "Role.h"
    1.15 +#include "States.h"
    1.16 +
    1.17 +#include "nsBlockFrame.h"
    1.18 +#include "nsBulletFrame.h"
    1.19 +
    1.20 +using namespace mozilla;
    1.21 +using namespace mozilla::a11y;
    1.22 +
    1.23 +////////////////////////////////////////////////////////////////////////////////
    1.24 +// HTMLListAccessible
    1.25 +////////////////////////////////////////////////////////////////////////////////
    1.26 +
    1.27 +NS_IMPL_ISUPPORTS_INHERITED0(HTMLListAccessible, HyperTextAccessible)
    1.28 +
    1.29 +role
    1.30 +HTMLListAccessible::NativeRole()
    1.31 +{
    1.32 +  if (mContent->Tag() == nsGkAtoms::dl)
    1.33 +    return roles::DEFINITION_LIST;
    1.34 +
    1.35 +  return roles::LIST;
    1.36 +}
    1.37 +
    1.38 +uint64_t
    1.39 +HTMLListAccessible::NativeState()
    1.40 +{
    1.41 +  return HyperTextAccessibleWrap::NativeState() | states::READONLY;
    1.42 +}
    1.43 +
    1.44 +
    1.45 +////////////////////////////////////////////////////////////////////////////////
    1.46 +// HTMLLIAccessible
    1.47 +////////////////////////////////////////////////////////////////////////////////
    1.48 +
    1.49 +HTMLLIAccessible::
    1.50 +  HTMLLIAccessible(nsIContent* aContent, DocAccessible* aDoc) :
    1.51 +  HyperTextAccessibleWrap(aContent, aDoc), mBullet(nullptr)
    1.52 +{
    1.53 +  mType = eHTMLLiType;
    1.54 +
    1.55 +  nsBlockFrame* blockFrame = do_QueryFrame(GetFrame());
    1.56 +  if (blockFrame && blockFrame->HasBullet()) {
    1.57 +    mBullet = new HTMLListBulletAccessible(mContent, mDoc);
    1.58 +    Document()->BindToDocument(mBullet, nullptr);
    1.59 +  }
    1.60 +}
    1.61 +
    1.62 +NS_IMPL_ISUPPORTS_INHERITED0(HTMLLIAccessible, HyperTextAccessible)
    1.63 +
    1.64 +void
    1.65 +HTMLLIAccessible::Shutdown()
    1.66 +{
    1.67 +  mBullet = nullptr;
    1.68 +
    1.69 +  HyperTextAccessibleWrap::Shutdown();
    1.70 +}
    1.71 +
    1.72 +role
    1.73 +HTMLLIAccessible::NativeRole()
    1.74 +{
    1.75 +  if (mContent->Tag() == nsGkAtoms::dt)
    1.76 +    return roles::TERM;
    1.77 +
    1.78 +  return roles::LISTITEM;
    1.79 +}
    1.80 +
    1.81 +uint64_t
    1.82 +HTMLLIAccessible::NativeState()
    1.83 +{
    1.84 +  return HyperTextAccessibleWrap::NativeState() | states::READONLY;
    1.85 +}
    1.86 +
    1.87 +NS_IMETHODIMP
    1.88 +HTMLLIAccessible::GetBounds(int32_t* aX, int32_t* aY,
    1.89 +                            int32_t* aWidth, int32_t* aHeight)
    1.90 +{
    1.91 +  nsresult rv = AccessibleWrap::GetBounds(aX, aY, aWidth, aHeight);
    1.92 +  if (NS_FAILED(rv) || !mBullet || mBullet->IsInside())
    1.93 +    return rv;
    1.94 +
    1.95 +  int32_t bulletX = 0, bulletY = 0, bulletWidth = 0, bulletHeight = 0;
    1.96 +  rv = mBullet->GetBounds(&bulletX, &bulletY, &bulletWidth, &bulletHeight);
    1.97 +  NS_ENSURE_SUCCESS(rv, rv);
    1.98 +
    1.99 +  *aWidth += *aX - bulletX;
   1.100 +  *aX = bulletX; // Move x coordinate of list item over to cover bullet as well
   1.101 +  return NS_OK;
   1.102 +}
   1.103 +
   1.104 +////////////////////////////////////////////////////////////////////////////////
   1.105 +// HTMLLIAccessible: public
   1.106 +
   1.107 +void
   1.108 +HTMLLIAccessible::UpdateBullet(bool aHasBullet)
   1.109 +{
   1.110 +  if (aHasBullet == !!mBullet) {
   1.111 +    NS_NOTREACHED("Bullet and accessible are in sync already!");
   1.112 +    return;
   1.113 +  }
   1.114 +
   1.115 +  DocAccessible* document = Document();
   1.116 +  if (aHasBullet) {
   1.117 +    mBullet = new HTMLListBulletAccessible(mContent, mDoc);
   1.118 +    document->BindToDocument(mBullet, nullptr);
   1.119 +    InsertChildAt(0, mBullet);
   1.120 +  } else {
   1.121 +    RemoveChild(mBullet);
   1.122 +    document->UnbindFromDocument(mBullet);
   1.123 +    mBullet = nullptr;
   1.124 +  }
   1.125 +
   1.126 +  // XXXtodo: fire show/hide and reorder events. That's hard to make it
   1.127 +  // right now because coalescence happens by DOM node.
   1.128 +}
   1.129 +
   1.130 +////////////////////////////////////////////////////////////////////////////////
   1.131 +// HTMLLIAccessible: Accessible protected
   1.132 +
   1.133 +void
   1.134 +HTMLLIAccessible::CacheChildren()
   1.135 +{
   1.136 +  if (mBullet)
   1.137 +    AppendChild(mBullet);
   1.138 +
   1.139 +  // Cache children from subtree.
   1.140 +  AccessibleWrap::CacheChildren();
   1.141 +}
   1.142 +
   1.143 +////////////////////////////////////////////////////////////////////////////////
   1.144 +// HTMLListBulletAccessible
   1.145 +////////////////////////////////////////////////////////////////////////////////
   1.146 +HTMLListBulletAccessible::
   1.147 +  HTMLListBulletAccessible(nsIContent* aContent, DocAccessible* aDoc) :
   1.148 +  LeafAccessible(aContent, aDoc)
   1.149 +{
   1.150 +  mStateFlags |= eSharedNode;
   1.151 +}
   1.152 +
   1.153 +////////////////////////////////////////////////////////////////////////////////
   1.154 +// HTMLListBulletAccessible: Accessible
   1.155 +
   1.156 +nsIFrame*
   1.157 +HTMLListBulletAccessible::GetFrame() const
   1.158 +{
   1.159 +  nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
   1.160 +  return blockFrame ? blockFrame->GetBullet() : nullptr;
   1.161 +}
   1.162 +
   1.163 +ENameValueFlag
   1.164 +HTMLListBulletAccessible::Name(nsString &aName)
   1.165 +{
   1.166 +  aName.Truncate();
   1.167 +
   1.168 +  // Native anonymous content, ARIA can't be used. Get list bullet text.
   1.169 +  nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
   1.170 +  if (blockFrame) {
   1.171 +    blockFrame->GetBulletText(aName);
   1.172 +
   1.173 +    // Append space otherwise bullets are jammed up against list text.
   1.174 +    aName.Append(' ');
   1.175 +  }
   1.176 +
   1.177 +  return eNameOK;
   1.178 +}
   1.179 +
   1.180 +role
   1.181 +HTMLListBulletAccessible::NativeRole()
   1.182 +{
   1.183 +  return roles::STATICTEXT;
   1.184 +}
   1.185 +
   1.186 +uint64_t
   1.187 +HTMLListBulletAccessible::NativeState()
   1.188 +{
   1.189 +  return LeafAccessible::NativeState() | states::READONLY;
   1.190 +}
   1.191 +
   1.192 +void
   1.193 +HTMLListBulletAccessible::AppendTextTo(nsAString& aText, uint32_t aStartOffset,
   1.194 +                                       uint32_t aLength)
   1.195 +{
   1.196 +  nsAutoString bulletText;
   1.197 +  nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
   1.198 +  if (blockFrame)
   1.199 +    blockFrame->GetBulletText(bulletText);
   1.200 +
   1.201 +  aText.Append(Substring(bulletText, aStartOffset, aLength));
   1.202 +}
   1.203 +
   1.204 +////////////////////////////////////////////////////////////////////////////////
   1.205 +// HTMLListBulletAccessible: public
   1.206 +
   1.207 +bool
   1.208 +HTMLListBulletAccessible::IsInside() const
   1.209 +{
   1.210 +  nsBlockFrame* blockFrame = do_QueryFrame(mContent->GetPrimaryFrame());
   1.211 +  return blockFrame ? blockFrame->HasInsideBullet() : false;
   1.212 +}

mercurial