LCOV - code coverage report
Current view: top level - accessible/base - AccessibleOrProxy.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 37 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef mozilla_a11y_AccessibleOrProxy_h
       8             : #define mozilla_a11y_AccessibleOrProxy_h
       9             : 
      10             : #include "mozilla/a11y/Accessible.h"
      11             : #include "mozilla/a11y/ProxyAccessible.h"
      12             : #include "mozilla/a11y/Role.h"
      13             : 
      14             : #include <stdint.h>
      15             : 
      16             : namespace mozilla {
      17             : namespace a11y {
      18             : 
      19             : /**
      20             :  * This class stores an Accessible* or a ProxyAccessible* in a safe manner
      21             :  * with size sizeof(void*).
      22             :  */
      23             : class AccessibleOrProxy
      24             : {
      25             : public:
      26           0 :   MOZ_IMPLICIT AccessibleOrProxy(Accessible* aAcc) :
      27           0 :     mBits(reinterpret_cast<uintptr_t>(aAcc)) {}
      28           0 :   MOZ_IMPLICIT AccessibleOrProxy(ProxyAccessible* aProxy) :
      29           0 :     mBits(aProxy ? (reinterpret_cast<uintptr_t>(aProxy) | IS_PROXY) : 0) {}
      30           0 :   MOZ_IMPLICIT AccessibleOrProxy(decltype(nullptr)) : mBits(0) {}
      31             : 
      32           0 :   bool IsProxy() const { return mBits & IS_PROXY; }
      33           0 :   ProxyAccessible* AsProxy() const
      34             :   {
      35           0 :     if (IsProxy()) {
      36           0 :       return reinterpret_cast<ProxyAccessible*>(mBits & ~IS_PROXY);
      37             :     }
      38             : 
      39           0 :     return nullptr;
      40             :   }
      41             : 
      42           0 :   bool IsAccessible() const { return !IsProxy(); }
      43           0 :   Accessible* AsAccessible() const
      44             :   {
      45           0 :     if (IsAccessible()) {
      46           0 :       return reinterpret_cast<Accessible*>(mBits);
      47             :     }
      48             : 
      49           0 :     return nullptr;
      50             :   }
      51             : 
      52           0 :   bool IsNull() const { return mBits == 0; }
      53             : 
      54           0 :   uint32_t ChildCount() const
      55             :   {
      56           0 :     if (IsProxy()) {
      57           0 :       return AsProxy()->ChildrenCount();
      58             :     }
      59             : 
      60           0 :     return AsAccessible()->ChildCount();
      61             :   }
      62             : 
      63             :   /**
      64             :    * Return the child object either an accessible or a proxied accessible at
      65             :    * the given index.
      66             :    */
      67           0 :   AccessibleOrProxy ChildAt(uint32_t aIdx)
      68             :   {
      69           0 :     if (IsProxy()) {
      70           0 :       return AsProxy()->ChildAt(aIdx);
      71             :     }
      72             : 
      73           0 :     return AsAccessible()->GetChildAt(aIdx);
      74             :   }
      75             : 
      76             :   /**
      77             :    * Return the first child object.
      78             :    */
      79           0 :   AccessibleOrProxy FirstChild()
      80             :   {
      81           0 :     if (IsProxy()) {
      82           0 :       return AsProxy()->FirstChild();
      83             :     }
      84             : 
      85           0 :     return AsAccessible()->FirstChild();
      86             :   }
      87             : 
      88             :   /**
      89             :    * Return the first child object.
      90             :    */
      91           0 :   AccessibleOrProxy LastChild()
      92             :   {
      93           0 :     if (IsProxy()) {
      94           0 :       return AsProxy()->LastChild();
      95             :     }
      96             : 
      97           0 :     return AsAccessible()->LastChild();
      98             :   }
      99             : 
     100           0 :   role Role() const
     101             :   {
     102           0 :     if (IsProxy()) {
     103           0 :       return AsProxy()->Role();
     104             :     }
     105             : 
     106           0 :     return AsAccessible()->Role();
     107             :   }
     108             : 
     109             :   AccessibleOrProxy Parent() const;
     110             : 
     111             :   // XXX these are implementation details that ideally would not be exposed.
     112             :   uintptr_t Bits() const { return mBits; }
     113           0 :   void SetBits(uintptr_t aBits) { mBits = aBits; }
     114             : 
     115             : private:
     116             :   uintptr_t mBits;
     117             :   static const uintptr_t IS_PROXY = 0x1;
     118             : };
     119             : 
     120             : }
     121             : }
     122             : 
     123             : #endif

Generated by: LCOV version 1.13