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/. */
7 /* code for HTML client-side image maps */
12 #include "mozilla/gfx/2D.h"
16 #include "nsStubMutationObserver.h"
17 #include "nsIDOMEventListener.h"
28 class HTMLAreaElement
;
30 } // namespace mozilla
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
;
41 void Init(nsImageFrame
* aImageFrame
, nsIContent
* aMap
);
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.
47 mozilla::dom::HTMLAreaElement
* GetArea(const mozilla::CSSIntPoint
& aPt
) const;
50 * Return area elements count associated with the image map.
52 uint32_t AreaCount() const { return mAreas
.Length(); }
55 * Return area element at the given index.
57 mozilla::dom::HTMLAreaElement
* GetAreaAt(uint32_t aIndex
) const;
59 void Draw(nsIFrame
* aFrame
, DrawTarget
& aDrawTarget
,
60 const ColorPattern
& aColor
,
61 const StrokeOptions
& aStrokeOptions
= StrokeOptions());
64 * Called just before the nsImageFrame releases us.
65 * Used to break the cycle caused by the DOM listener.
72 // nsIMutationObserver
73 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
74 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
75 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
76 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
77 NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
79 // nsIDOMEventListener
80 NS_DECL_NSIDOMEVENTLISTENER
82 nsresult
GetBoundsForAreaContent(nsIContent
* aContent
, nsRect
& aBounds
);
84 using AreaList
= AutoTArray
<mozilla::UniquePtr
<Area
>, 8>;
87 virtual ~nsImageMap();
93 void SearchForAreas(nsIContent
* aParent
);
95 void AddArea(mozilla::dom::HTMLAreaElement
* aArea
);
96 void AreaRemoved(mozilla::dom::HTMLAreaElement
* aArea
);
98 void MaybeUpdateAreas(nsIContent
* aContent
);
100 nsImageFrame
* mImageFrame
; // the frame that owns us
101 nsCOMPtr
<nsIContent
> mMap
;
103 // almost always has some entries
106 // This is set when we search for all area children and tells us whether we
107 // should consider the whole subtree or just direct children when we get
108 // content notifications about changes inside the map subtree.
109 bool mConsiderWholeSubtree
;
112 #endif /* nsImageMap_h */