tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ImageAccessible.h (2862B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_a11y_ImageAccessible_h__
      7 #define mozilla_a11y_ImageAccessible_h__
      8 
      9 #include "BaseAccessibles.h"
     10 #include "imgINotificationObserver.h"
     11 
     12 namespace mozilla {
     13 namespace a11y {
     14 
     15 /* LocalAccessible for supporting images
     16 * supports:
     17 * - gets name, role
     18 * - support basic state
     19 */
     20 class ImageAccessible : public LinkableAccessible,
     21                        public imgINotificationObserver {
     22 public:
     23  ImageAccessible(nsIContent* aContent, DocAccessible* aDoc);
     24 
     25  NS_DECL_ISUPPORTS_INHERITED
     26  NS_DECL_IMGINOTIFICATIONOBSERVER
     27 
     28  // LocalAccessible
     29  virtual void Shutdown() override;
     30  virtual a11y::role NativeRole() const override;
     31  virtual uint64_t NativeState() const override;
     32  virtual already_AddRefed<AccAttributes> NativeAttributes() override;
     33 
     34  // ActionAccessible
     35  virtual uint8_t ActionCount() const override;
     36  virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;
     37  virtual bool DoAction(uint8_t aIndex) const override;
     38 
     39  // ImageAccessible
     40  LayoutDeviceIntPoint Position(uint32_t aCoordType);
     41  LayoutDeviceIntSize Size();
     42 
     43  /**
     44   * Return whether the element has a longdesc URI.
     45   */
     46  bool HasLongDesc() const {
     47    nsCOMPtr<nsIURI> uri = GetLongDescURI();
     48    return uri;
     49  }
     50 
     51 protected:
     52  virtual ~ImageAccessible();
     53 
     54  // LocalAccessible
     55  virtual ENameValueFlag NativeName(nsString& aName) const override;
     56 
     57  virtual void DOMAttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
     58                                   AttrModType aModType,
     59                                   const nsAttrValue* aOldValue,
     60                                   uint64_t aOldState) override;
     61 
     62 private:
     63  /**
     64   * Return an URI for showlongdesc action if any.
     65   */
     66  already_AddRefed<nsIURI> GetLongDescURI() const;
     67 
     68  /**
     69   * Used by ActionNameAt and DoAction to ensure the index for opening the
     70   * longdesc URL is valid.
     71   * It is always assumed that the highest possible index opens the longdesc.
     72   * This doesn't check that there is actually a longdesc, just that the index
     73   * would be correct if there was one.
     74   *
     75   * @param aIndex  The 0-based index to be tested.
     76   *
     77   * @returns  true if index is valid for longdesc action.
     78   */
     79  inline bool IsLongDescIndex(uint8_t aIndex) const;
     80 
     81  uint32_t mImageRequestStatus;
     82 };
     83 
     84 ////////////////////////////////////////////////////////////////////////////////
     85 // LocalAccessible downcasting method
     86 
     87 inline ImageAccessible* LocalAccessible::AsImage() {
     88  return IsImage() ? static_cast<ImageAccessible*>(this) : nullptr;
     89 }
     90 
     91 }  // namespace a11y
     92 }  // namespace mozilla
     93 
     94 #endif