michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* code for HTML client-side image maps */ michael@0: michael@0: #ifndef nsImageMap_h michael@0: #define nsImageMap_h michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCoord.h" michael@0: #include "nsTArray.h" michael@0: #include "nsStubMutationObserver.h" michael@0: #include "nsIDOMEventListener.h" michael@0: michael@0: class Area; michael@0: class nsRenderingContext; michael@0: class nsImageFrame; michael@0: class nsIFrame; michael@0: class nsIContent; michael@0: struct nsRect; michael@0: michael@0: class nsImageMap : public nsStubMutationObserver, michael@0: public nsIDOMEventListener michael@0: { michael@0: public: michael@0: nsImageMap(); michael@0: michael@0: nsresult Init(nsImageFrame* aImageFrame, nsIContent* aMap); michael@0: michael@0: /** michael@0: * Return the first area element (in content order) for the given aX,aY pixel michael@0: * coordinate or nullptr if the coordinate is outside all areas. michael@0: */ michael@0: nsIContent* GetArea(nscoord aX, nscoord aY) const; michael@0: michael@0: /** michael@0: * Return area elements count associated with the image map. michael@0: */ michael@0: uint32_t AreaCount() const { return mAreas.Length(); } michael@0: michael@0: /** michael@0: * Return area element at the given index. michael@0: */ michael@0: nsIContent* GetAreaAt(uint32_t aIndex) const; michael@0: michael@0: void Draw(nsIFrame* aFrame, nsRenderingContext& aRC); michael@0: michael@0: /** michael@0: * Called just before the nsImageFrame releases us. michael@0: * Used to break the cycle caused by the DOM listener. michael@0: */ michael@0: void Destroy(); michael@0: michael@0: // nsISupports michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsIMutationObserver michael@0: NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED michael@0: NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED michael@0: michael@0: //nsIDOMEventListener michael@0: NS_DECL_NSIDOMEVENTLISTENER michael@0: michael@0: nsresult GetBoundsForAreaContent(nsIContent *aContent, michael@0: nsRect& aBounds); michael@0: michael@0: protected: michael@0: virtual ~nsImageMap(); michael@0: michael@0: void FreeAreas(); michael@0: michael@0: nsresult UpdateAreas(); michael@0: nsresult SearchForAreas(nsIContent* aParent, bool& aFoundArea, michael@0: bool& aFoundAnchor); michael@0: michael@0: nsresult AddArea(nsIContent* aArea); michael@0: michael@0: void MaybeUpdateAreas(nsIContent *aContent); michael@0: michael@0: nsImageFrame* mImageFrame; // the frame that owns us michael@0: nsCOMPtr mMap; michael@0: nsAutoTArray mAreas; // almost always has some entries michael@0: bool mContainsBlockContents; michael@0: }; michael@0: michael@0: #endif /* nsImageMap_h */