tor-browser

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

nsImageMap.h (3314B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=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 /* code for HTML client-side image maps */
      8 
      9 #ifndef nsImageMap_h
     10 #define nsImageMap_h
     11 
     12 #include "Units.h"
     13 #include "mozilla/gfx/2D.h"
     14 #include "nsCOMPtr.h"
     15 #include "nsCoord.h"
     16 #include "nsIDOMEventListener.h"
     17 #include "nsStubMutationObserver.h"
     18 #include "nsTArray.h"
     19 
     20 class Area;
     21 class nsImageFrame;
     22 class nsIFrame;
     23 class nsIContent;
     24 struct nsRect;
     25 
     26 namespace mozilla {
     27 namespace dom {
     28 class HTMLAreaElement;
     29 }
     30 }  // namespace mozilla
     31 
     32 class nsImageMap final : public nsStubMutationObserver,
     33                         public nsIDOMEventListener {
     34  typedef mozilla::gfx::DrawTarget DrawTarget;
     35  typedef mozilla::gfx::ColorPattern ColorPattern;
     36  typedef mozilla::gfx::StrokeOptions StrokeOptions;
     37 
     38 public:
     39  nsImageMap();
     40 
     41  void Init(nsImageFrame* aImageFrame, nsIContent* aMap);
     42 
     43  /**
     44   * Return the first area element (in content order) for the given point in
     45   * CSS pixel coordinate or nullptr if the coordinate is outside all areas.
     46   */
     47  mozilla::dom::HTMLAreaElement* GetArea(const mozilla::CSSIntPoint& aPt) const;
     48 
     49  // Return area elements count associated with the image map.
     50  uint32_t AreaCount() const { return mAreas.Length(); }
     51 
     52  // Returns whether any of our area elements have focus, currently.
     53  bool HasFocus() const { return mHasFocus; }
     54 
     55  // Return area element at the given index.
     56  mozilla::dom::HTMLAreaElement* GetAreaAt(uint32_t aIndex) const;
     57 
     58  void DrawFocus(nsIFrame* aFrame, DrawTarget& aDrawTarget,
     59                 const ColorPattern& aColor,
     60                 const StrokeOptions& aStrokeOptions = StrokeOptions());
     61 
     62  /**
     63   * Called just before the nsImageFrame releases us.
     64   * Used to break the cycle caused by the DOM listener.
     65   */
     66  void Destroy();
     67 
     68  // nsISupports
     69  NS_DECL_ISUPPORTS
     70 
     71  // nsIMutationObserver
     72  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
     73  NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
     74  NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
     75  NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
     76  NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
     77 
     78  // nsIDOMEventListener
     79  NS_DECL_NSIDOMEVENTLISTENER
     80 
     81  nsresult GetBoundsForAreaContent(nsIContent* aContent, nsRect& aBounds);
     82 
     83  using AreaList = AutoTArray<mozilla::UniquePtr<Area>, 8>;
     84 
     85 protected:
     86  virtual ~nsImageMap();
     87 
     88  void FreeAreas();
     89 
     90  void UpdateAreas();
     91 
     92  void SearchForAreas(nsIContent* aParent);
     93 
     94  void AddArea(mozilla::dom::HTMLAreaElement* aArea);
     95  void AreaRemoved(mozilla::dom::HTMLAreaElement* aArea);
     96 
     97  void MaybeUpdateAreas(nsIContent* aContent);
     98 
     99  nsImageFrame* mImageFrame = nullptr;  // the frame that owns us
    100  nsCOMPtr<nsIContent> mMap;
    101 
    102  // almost always has some entries
    103  AreaList mAreas;
    104 
    105  // This is set when we search for all area children and tells us whether we
    106  // should consider the whole subtree or just direct children when we get
    107  // content notifications about changes inside the map subtree.
    108  bool mConsiderWholeSubtree = false;
    109 
    110  // Whether any of our areas has focus.
    111  bool mHasFocus = false;
    112 };
    113 
    114 #endif /* nsImageMap_h */