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/. */
6 /* code for HTML client-side image maps */
11 #include "mozilla/gfx/2D.h"
15 #include "nsStubMutationObserver.h"
16 #include "nsIDOMEventListener.h"
24 class nsImageMap MOZ_FINAL
: public nsStubMutationObserver
,
25 public nsIDOMEventListener
27 typedef mozilla::gfx::DrawTarget DrawTarget
;
28 typedef mozilla::gfx::ColorPattern ColorPattern
;
29 typedef mozilla::gfx::StrokeOptions StrokeOptions
;
34 nsresult
Init(nsImageFrame
* aImageFrame
, nsIContent
* aMap
);
37 * Return the first area element (in content order) for the given aX,aY pixel
38 * coordinate or nullptr if the coordinate is outside all areas.
40 nsIContent
* GetArea(nscoord aX
, nscoord aY
) const;
43 * Return area elements count associated with the image map.
45 uint32_t AreaCount() const { return mAreas
.Length(); }
48 * Return area element at the given index.
50 nsIContent
* GetAreaAt(uint32_t aIndex
) const;
52 void Draw(nsIFrame
* aFrame
, DrawTarget
& aDrawTarget
,
53 const ColorPattern
& aColor
,
54 const StrokeOptions
& aStrokeOptions
= StrokeOptions());
57 * Called just before the nsImageFrame releases us.
58 * Used to break the cycle caused by the DOM listener.
65 // nsIMutationObserver
66 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
67 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
68 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
69 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
70 NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
73 NS_DECL_NSIDOMEVENTLISTENER
75 nsresult
GetBoundsForAreaContent(nsIContent
*aContent
,
79 virtual ~nsImageMap();
83 nsresult
UpdateAreas();
84 nsresult
SearchForAreas(nsIContent
* aParent
, bool& aFoundArea
,
87 nsresult
AddArea(nsIContent
* aArea
);
89 void MaybeUpdateAreas(nsIContent
*aContent
);
91 nsImageFrame
* mImageFrame
; // the frame that owns us
92 nsCOMPtr
<nsIContent
> mMap
;
93 nsAutoTArray
<Area
*, 8> mAreas
; // almost always has some entries
94 bool mContainsBlockContents
;
97 #endif /* nsImageMap_h */