layout/generic/nsImageMap.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:e8cb2a852f5e
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 /* code for HTML client-side image maps */
7
8 #ifndef nsImageMap_h
9 #define nsImageMap_h
10
11 #include "nsCOMPtr.h"
12 #include "nsCoord.h"
13 #include "nsTArray.h"
14 #include "nsStubMutationObserver.h"
15 #include "nsIDOMEventListener.h"
16
17 class Area;
18 class nsRenderingContext;
19 class nsImageFrame;
20 class nsIFrame;
21 class nsIContent;
22 struct nsRect;
23
24 class nsImageMap : public nsStubMutationObserver,
25 public nsIDOMEventListener
26 {
27 public:
28 nsImageMap();
29
30 nsresult Init(nsImageFrame* aImageFrame, nsIContent* aMap);
31
32 /**
33 * Return the first area element (in content order) for the given aX,aY pixel
34 * coordinate or nullptr if the coordinate is outside all areas.
35 */
36 nsIContent* GetArea(nscoord aX, nscoord aY) const;
37
38 /**
39 * Return area elements count associated with the image map.
40 */
41 uint32_t AreaCount() const { return mAreas.Length(); }
42
43 /**
44 * Return area element at the given index.
45 */
46 nsIContent* GetAreaAt(uint32_t aIndex) const;
47
48 void Draw(nsIFrame* aFrame, nsRenderingContext& aRC);
49
50 /**
51 * Called just before the nsImageFrame releases us.
52 * Used to break the cycle caused by the DOM listener.
53 */
54 void Destroy();
55
56 // nsISupports
57 NS_DECL_ISUPPORTS
58
59 // nsIMutationObserver
60 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
61 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
62 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
63 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
64 NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED
65
66 //nsIDOMEventListener
67 NS_DECL_NSIDOMEVENTLISTENER
68
69 nsresult GetBoundsForAreaContent(nsIContent *aContent,
70 nsRect& aBounds);
71
72 protected:
73 virtual ~nsImageMap();
74
75 void FreeAreas();
76
77 nsresult UpdateAreas();
78 nsresult SearchForAreas(nsIContent* aParent, bool& aFoundArea,
79 bool& aFoundAnchor);
80
81 nsresult AddArea(nsIContent* aArea);
82
83 void MaybeUpdateAreas(nsIContent *aContent);
84
85 nsImageFrame* mImageFrame; // the frame that owns us
86 nsCOMPtr<nsIContent> mMap;
87 nsAutoTArray<Area*, 8> mAreas; // almost always has some entries
88 bool mContainsBlockContents;
89 };
90
91 #endif /* nsImageMap_h */

mercurial