Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsImageMap.h
blob79bda7daf7803accb5b4af771253492a3d85e05d
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 */
8 #ifndef nsImageMap_h
9 #define nsImageMap_h
11 #include "mozilla/gfx/2D.h"
12 #include "nsCOMPtr.h"
13 #include "nsCoord.h"
14 #include "nsTArray.h"
15 #include "nsStubMutationObserver.h"
16 #include "nsIDOMEventListener.h"
18 class Area;
19 class nsImageFrame;
20 class nsIFrame;
21 class nsIContent;
22 struct nsRect;
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;
31 public:
32 nsImageMap();
34 nsresult Init(nsImageFrame* aImageFrame, nsIContent* aMap);
36 /**
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;
42 /**
43 * Return area elements count associated with the image map.
45 uint32_t AreaCount() const { return mAreas.Length(); }
47 /**
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());
56 /**
57 * Called just before the nsImageFrame releases us.
58 * Used to break the cycle caused by the DOM listener.
60 void Destroy();
62 // nsISupports
63 NS_DECL_ISUPPORTS
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
72 //nsIDOMEventListener
73 NS_DECL_NSIDOMEVENTLISTENER
75 nsresult GetBoundsForAreaContent(nsIContent *aContent,
76 nsRect& aBounds);
78 protected:
79 virtual ~nsImageMap();
81 void FreeAreas();
83 nsresult UpdateAreas();
84 nsresult SearchForAreas(nsIContent* aParent, bool& aFoundArea,
85 bool& aFoundAnchor);
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 */