Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* code for HTML client-side image maps */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef nsImageMap_h |
michael@0 | 9 | #define nsImageMap_h |
michael@0 | 10 | |
michael@0 | 11 | #include "nsCOMPtr.h" |
michael@0 | 12 | #include "nsCoord.h" |
michael@0 | 13 | #include "nsTArray.h" |
michael@0 | 14 | #include "nsStubMutationObserver.h" |
michael@0 | 15 | #include "nsIDOMEventListener.h" |
michael@0 | 16 | |
michael@0 | 17 | class Area; |
michael@0 | 18 | class nsRenderingContext; |
michael@0 | 19 | class nsImageFrame; |
michael@0 | 20 | class nsIFrame; |
michael@0 | 21 | class nsIContent; |
michael@0 | 22 | struct nsRect; |
michael@0 | 23 | |
michael@0 | 24 | class nsImageMap : public nsStubMutationObserver, |
michael@0 | 25 | public nsIDOMEventListener |
michael@0 | 26 | { |
michael@0 | 27 | public: |
michael@0 | 28 | nsImageMap(); |
michael@0 | 29 | |
michael@0 | 30 | nsresult Init(nsImageFrame* aImageFrame, nsIContent* aMap); |
michael@0 | 31 | |
michael@0 | 32 | /** |
michael@0 | 33 | * Return the first area element (in content order) for the given aX,aY pixel |
michael@0 | 34 | * coordinate or nullptr if the coordinate is outside all areas. |
michael@0 | 35 | */ |
michael@0 | 36 | nsIContent* GetArea(nscoord aX, nscoord aY) const; |
michael@0 | 37 | |
michael@0 | 38 | /** |
michael@0 | 39 | * Return area elements count associated with the image map. |
michael@0 | 40 | */ |
michael@0 | 41 | uint32_t AreaCount() const { return mAreas.Length(); } |
michael@0 | 42 | |
michael@0 | 43 | /** |
michael@0 | 44 | * Return area element at the given index. |
michael@0 | 45 | */ |
michael@0 | 46 | nsIContent* GetAreaAt(uint32_t aIndex) const; |
michael@0 | 47 | |
michael@0 | 48 | void Draw(nsIFrame* aFrame, nsRenderingContext& aRC); |
michael@0 | 49 | |
michael@0 | 50 | /** |
michael@0 | 51 | * Called just before the nsImageFrame releases us. |
michael@0 | 52 | * Used to break the cycle caused by the DOM listener. |
michael@0 | 53 | */ |
michael@0 | 54 | void Destroy(); |
michael@0 | 55 | |
michael@0 | 56 | // nsISupports |
michael@0 | 57 | NS_DECL_ISUPPORTS |
michael@0 | 58 | |
michael@0 | 59 | // nsIMutationObserver |
michael@0 | 60 | NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED |
michael@0 | 61 | NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED |
michael@0 | 62 | NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED |
michael@0 | 63 | NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED |
michael@0 | 64 | NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED |
michael@0 | 65 | |
michael@0 | 66 | //nsIDOMEventListener |
michael@0 | 67 | NS_DECL_NSIDOMEVENTLISTENER |
michael@0 | 68 | |
michael@0 | 69 | nsresult GetBoundsForAreaContent(nsIContent *aContent, |
michael@0 | 70 | nsRect& aBounds); |
michael@0 | 71 | |
michael@0 | 72 | protected: |
michael@0 | 73 | virtual ~nsImageMap(); |
michael@0 | 74 | |
michael@0 | 75 | void FreeAreas(); |
michael@0 | 76 | |
michael@0 | 77 | nsresult UpdateAreas(); |
michael@0 | 78 | nsresult SearchForAreas(nsIContent* aParent, bool& aFoundArea, |
michael@0 | 79 | bool& aFoundAnchor); |
michael@0 | 80 | |
michael@0 | 81 | nsresult AddArea(nsIContent* aArea); |
michael@0 | 82 | |
michael@0 | 83 | void MaybeUpdateAreas(nsIContent *aContent); |
michael@0 | 84 | |
michael@0 | 85 | nsImageFrame* mImageFrame; // the frame that owns us |
michael@0 | 86 | nsCOMPtr<nsIContent> mMap; |
michael@0 | 87 | nsAutoTArray<Area*, 8> mAreas; // almost always has some entries |
michael@0 | 88 | bool mContainsBlockContents; |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | #endif /* nsImageMap_h */ |