LCOV - code coverage report
Current view: directory - accessible/src/xul - nsXULTextAccessible.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 83 0 0.0 %
Date: 2012-06-02 Functions: 23 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Aaron Leventhal (aaronl@netscape.com)
      24                 :  *   Kyle Yuan (kyle.yuan@sun.com)
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : // NOTE: groups are alphabetically ordered
      41                 : #include "nsXULTextAccessible.h"
      42                 : 
      43                 : #include "nsAccUtils.h"
      44                 : #include "nsBaseWidgetAccessible.h"
      45                 : #include "nsCoreUtils.h"
      46                 : #include "nsTextEquivUtils.h"
      47                 : #include "Relation.h"
      48                 : #include "Role.h"
      49                 : #include "States.h"
      50                 : 
      51                 : #include "nsIAccessibleRelation.h"
      52                 : #include "nsIDOMXULDescriptionElement.h"
      53                 : #include "nsINameSpaceManager.h"
      54                 : #include "nsString.h"
      55                 : #include "nsNetUtil.h"
      56                 : 
      57                 : using namespace mozilla::a11y;
      58                 : 
      59                 : ////////////////////////////////////////////////////////////////////////////////
      60                 : // nsXULTextAccessible
      61                 : ////////////////////////////////////////////////////////////////////////////////
      62                 : 
      63               0 : nsXULTextAccessible::
      64                 :   nsXULTextAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
      65               0 :   nsHyperTextAccessibleWrap(aContent, aDoc)
      66                 : {
      67               0 : }
      68                 : 
      69                 : nsresult
      70               0 : nsXULTextAccessible::GetNameInternal(nsAString& aName)
      71                 : {
      72                 :   // if the value attr doesn't exist, the screen reader must get the accessible text
      73                 :   // from the accessible text interface or from the children
      74               0 :   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
      75               0 :   return NS_OK;
      76                 : }
      77                 : 
      78                 : role
      79               0 : nsXULTextAccessible::NativeRole()
      80                 : {
      81               0 :   return roles::LABEL;
      82                 : }
      83                 : 
      84                 : PRUint64
      85               0 : nsXULTextAccessible::NativeState()
      86                 : {
      87                 :   // Labels and description have read only state
      88                 :   // They are not focusable or selectable
      89               0 :   return nsHyperTextAccessibleWrap::NativeState() | states::READONLY;
      90                 : }
      91                 : 
      92                 : Relation
      93               0 : nsXULTextAccessible::RelationByType(PRUint32 aType)
      94                 : {
      95               0 :   Relation rel = nsHyperTextAccessibleWrap::RelationByType(aType);
      96               0 :   if (aType == nsIAccessibleRelation::RELATION_LABEL_FOR) {
      97                 :     // Caption is the label for groupbox
      98               0 :     nsIContent *parent = mContent->GetParent();
      99               0 :     if (parent && parent->Tag() == nsGkAtoms::caption) {
     100               0 :       nsAccessible* parent = Parent();
     101               0 :       if (parent && parent->Role() == roles::GROUPING)
     102               0 :         rel.AppendTarget(parent);
     103                 :     }
     104                 :   }
     105                 : 
     106                 :   return rel;
     107                 : }
     108                 : 
     109                 : 
     110                 : ////////////////////////////////////////////////////////////////////////////////
     111                 : // nsXULTooltipAccessible
     112                 : ////////////////////////////////////////////////////////////////////////////////
     113                 : 
     114               0 : nsXULTooltipAccessible::
     115                 :   nsXULTooltipAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
     116               0 :   nsLeafAccessible(aContent, aDoc)
     117                 : {
     118               0 : }
     119                 : 
     120                 : PRUint64
     121               0 : nsXULTooltipAccessible::NativeState()
     122                 : {
     123               0 :   PRUint64 states = nsLeafAccessible::NativeState();
     124                 : 
     125               0 :   states &= ~states::FOCUSABLE;
     126               0 :   states |= states::READONLY;
     127               0 :   return states;
     128                 : }
     129                 : 
     130                 : role
     131               0 : nsXULTooltipAccessible::NativeRole()
     132                 : {
     133               0 :   return roles::TOOLTIP;
     134                 : }
     135                 : 
     136                 : 
     137                 : ////////////////////////////////////////////////////////////////////////////////
     138                 : // nsXULLinkAccessible
     139                 : ////////////////////////////////////////////////////////////////////////////////
     140                 : 
     141               0 : nsXULLinkAccessible::
     142                 :   nsXULLinkAccessible(nsIContent* aContent, nsDocAccessible* aDoc) :
     143               0 :   nsHyperTextAccessibleWrap(aContent, aDoc)
     144                 : {
     145               0 : }
     146                 : 
     147                 : // Expose nsIAccessibleHyperLink unconditionally
     148               0 : NS_IMPL_ISUPPORTS_INHERITED1(nsXULLinkAccessible, nsHyperTextAccessibleWrap,
     149                 :                              nsIAccessibleHyperLink)
     150                 : 
     151                 : ////////////////////////////////////////////////////////////////////////////////
     152                 : // nsXULLinkAccessible. nsIAccessible
     153                 : 
     154                 : NS_IMETHODIMP
     155               0 : nsXULLinkAccessible::GetValue(nsAString& aValue)
     156                 : {
     157               0 :   aValue.Truncate();
     158                 : 
     159               0 :   if (IsDefunct())
     160               0 :     return NS_ERROR_FAILURE;
     161                 : 
     162               0 :   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, aValue);
     163               0 :   return NS_OK;
     164                 : }
     165                 : 
     166                 : nsresult
     167               0 : nsXULLinkAccessible::GetNameInternal(nsAString& aName)
     168                 : {
     169               0 :   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::value, aName);
     170               0 :   if (!aName.IsEmpty())
     171               0 :     return NS_OK;
     172                 : 
     173               0 :   return nsTextEquivUtils::GetNameFromSubtree(this, aName);
     174                 : }
     175                 : 
     176                 : role
     177               0 : nsXULLinkAccessible::NativeRole()
     178                 : {
     179               0 :   return roles::LINK;
     180                 : }
     181                 : 
     182                 : 
     183                 : PRUint64
     184               0 : nsXULLinkAccessible::NativeState()
     185                 : {
     186               0 :   return nsHyperTextAccessible::NativeState() | states::LINKED;
     187                 : }
     188                 : 
     189                 : PRUint8
     190               0 : nsXULLinkAccessible::ActionCount()
     191                 : {
     192               0 :   return 1;
     193                 : }
     194                 : 
     195                 : NS_IMETHODIMP
     196               0 : nsXULLinkAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
     197                 : {
     198               0 :   aName.Truncate();
     199                 : 
     200               0 :   if (aIndex != eAction_Jump)
     201               0 :     return NS_ERROR_INVALID_ARG;
     202                 :   
     203               0 :   aName.AssignLiteral("jump");
     204               0 :   return NS_OK;
     205                 : }
     206                 : 
     207                 : NS_IMETHODIMP
     208               0 : nsXULLinkAccessible::DoAction(PRUint8 aIndex)
     209                 : {
     210               0 :   if (aIndex != eAction_Jump)
     211               0 :     return NS_ERROR_INVALID_ARG;
     212                 : 
     213               0 :   if (IsDefunct())
     214               0 :     return NS_ERROR_FAILURE;
     215                 : 
     216               0 :   DoCommand();
     217               0 :   return NS_OK;
     218                 : }
     219                 : 
     220                 : ////////////////////////////////////////////////////////////////////////////////
     221                 : // nsXULLinkAccessible: HyperLinkAccessible
     222                 : 
     223                 : bool
     224               0 : nsXULLinkAccessible::IsLink()
     225                 : {
     226                 :   // Expose HyperLinkAccessible unconditionally.
     227               0 :   return true;
     228                 : }
     229                 : 
     230                 : PRUint32
     231               0 : nsXULLinkAccessible::StartOffset()
     232                 : {
     233                 :   // If XUL link accessible is not contained by hypertext accessible then
     234                 :   // start offset matches index in parent because the parent doesn't contains
     235                 :   // a text.
     236                 :   // XXX: accessible parent of XUL link accessible should be a hypertext
     237                 :   // accessible.
     238               0 :   if (nsAccessible::IsLink())
     239               0 :     return nsAccessible::StartOffset();
     240               0 :   return IndexInParent();
     241                 : }
     242                 : 
     243                 : PRUint32
     244               0 : nsXULLinkAccessible::EndOffset()
     245                 : {
     246               0 :   if (nsAccessible::IsLink())
     247               0 :     return nsAccessible::EndOffset();
     248               0 :   return IndexInParent() + 1;
     249                 : }
     250                 : 
     251                 : already_AddRefed<nsIURI>
     252               0 : nsXULLinkAccessible::AnchorURIAt(PRUint32 aAnchorIndex)
     253                 : {
     254               0 :   if (aAnchorIndex != 0)
     255               0 :     return nsnull;
     256                 : 
     257               0 :   nsAutoString href;
     258               0 :   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
     259                 : 
     260               0 :   nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
     261               0 :   nsIDocument* document = mContent->OwnerDoc();
     262                 : 
     263               0 :   nsIURI* anchorURI = nsnull;
     264                 :   NS_NewURI(&anchorURI, href,
     265               0 :             document->GetDocumentCharacterSet().get(),
     266               0 :             baseURI);
     267                 : 
     268               0 :   return anchorURI;
     269                 : }

Generated by: LCOV version 1.7