/src/mozilla-central/layout/generic/nsImageMap.h
Line | Count | Source (jump to first uncovered line) |
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 "mozilla/gfx/2D.h" |
13 | | #include "nsCOMPtr.h" |
14 | | #include "nsCoord.h" |
15 | | #include "nsTArray.h" |
16 | | #include "nsStubMutationObserver.h" |
17 | | #include "nsIDOMEventListener.h" |
18 | | |
19 | | class Area; |
20 | | class nsImageFrame; |
21 | | class nsIFrame; |
22 | | class nsIContent; |
23 | | struct nsRect; |
24 | | |
25 | | namespace mozilla { |
26 | | namespace dom { |
27 | | class HTMLAreaElement; |
28 | | } |
29 | | } |
30 | | |
31 | | class nsImageMap final : public nsStubMutationObserver, |
32 | | public nsIDOMEventListener |
33 | | { |
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 aX,aY pixel |
45 | | * coordinate or nullptr if the coordinate is outside all areas. |
46 | | */ |
47 | | nsIContent* GetArea(nscoord aX, nscoord aY) const; |
48 | | |
49 | | /** |
50 | | * Return area elements count associated with the image map. |
51 | | */ |
52 | 0 | uint32_t AreaCount() const { return mAreas.Length(); } |
53 | | |
54 | | /** |
55 | | * Return area element at the given index. |
56 | | */ |
57 | | nsIContent* GetAreaAt(uint32_t aIndex) const; |
58 | | |
59 | | void Draw(nsIFrame* aFrame, DrawTarget& aDrawTarget, |
60 | | const ColorPattern& aColor, |
61 | | const StrokeOptions& aStrokeOptions = StrokeOptions()); |
62 | | |
63 | | /** |
64 | | * Called just before the nsImageFrame releases us. |
65 | | * Used to break the cycle caused by the DOM listener. |
66 | | */ |
67 | | void Destroy(); |
68 | | |
69 | | // nsISupports |
70 | | NS_DECL_ISUPPORTS |
71 | | |
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 |
78 | | |
79 | | //nsIDOMEventListener |
80 | | NS_DECL_NSIDOMEVENTLISTENER |
81 | | |
82 | | nsresult GetBoundsForAreaContent(nsIContent *aContent, |
83 | | nsRect& aBounds); |
84 | | |
85 | | using AreaList = AutoTArray<mozilla::UniquePtr<Area>, 8>; |
86 | | |
87 | | protected: |
88 | | virtual ~nsImageMap(); |
89 | | |
90 | | void FreeAreas(); |
91 | | |
92 | | void UpdateAreas(); |
93 | | |
94 | | void SearchForAreas(nsIContent* aParent); |
95 | | |
96 | | void AddArea(mozilla::dom::HTMLAreaElement* aArea); |
97 | | void AreaRemoved(mozilla::dom::HTMLAreaElement* aArea); |
98 | | |
99 | | void MaybeUpdateAreas(nsIContent *aContent); |
100 | | |
101 | | nsImageFrame* mImageFrame; // the frame that owns us |
102 | | nsCOMPtr<nsIContent> mMap; |
103 | | |
104 | | // almost always has some entries |
105 | | AreaList mAreas; |
106 | | |
107 | | // This is set when we search for all area children and tells us whether we |
108 | | // should consider the whole subtree or just direct children when we get |
109 | | // content notifications about changes inside the map subtree. |
110 | | bool mConsiderWholeSubtree; |
111 | | }; |
112 | | |
113 | | #endif /* nsImageMap_h */ |