1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsImageMap.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* code for HTML client-side image maps */ 1.10 + 1.11 +#ifndef nsImageMap_h 1.12 +#define nsImageMap_h 1.13 + 1.14 +#include "nsCOMPtr.h" 1.15 +#include "nsCoord.h" 1.16 +#include "nsTArray.h" 1.17 +#include "nsStubMutationObserver.h" 1.18 +#include "nsIDOMEventListener.h" 1.19 + 1.20 +class Area; 1.21 +class nsRenderingContext; 1.22 +class nsImageFrame; 1.23 +class nsIFrame; 1.24 +class nsIContent; 1.25 +struct nsRect; 1.26 + 1.27 +class nsImageMap : public nsStubMutationObserver, 1.28 + public nsIDOMEventListener 1.29 +{ 1.30 +public: 1.31 + nsImageMap(); 1.32 + 1.33 + nsresult Init(nsImageFrame* aImageFrame, nsIContent* aMap); 1.34 + 1.35 + /** 1.36 + * Return the first area element (in content order) for the given aX,aY pixel 1.37 + * coordinate or nullptr if the coordinate is outside all areas. 1.38 + */ 1.39 + nsIContent* GetArea(nscoord aX, nscoord aY) const; 1.40 + 1.41 + /** 1.42 + * Return area elements count associated with the image map. 1.43 + */ 1.44 + uint32_t AreaCount() const { return mAreas.Length(); } 1.45 + 1.46 + /** 1.47 + * Return area element at the given index. 1.48 + */ 1.49 + nsIContent* GetAreaAt(uint32_t aIndex) const; 1.50 + 1.51 + void Draw(nsIFrame* aFrame, nsRenderingContext& aRC); 1.52 + 1.53 + /** 1.54 + * Called just before the nsImageFrame releases us. 1.55 + * Used to break the cycle caused by the DOM listener. 1.56 + */ 1.57 + void Destroy(); 1.58 + 1.59 + // nsISupports 1.60 + NS_DECL_ISUPPORTS 1.61 + 1.62 + // nsIMutationObserver 1.63 + NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED 1.64 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED 1.65 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED 1.66 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED 1.67 + NS_DECL_NSIMUTATIONOBSERVER_PARENTCHAINCHANGED 1.68 + 1.69 + //nsIDOMEventListener 1.70 + NS_DECL_NSIDOMEVENTLISTENER 1.71 + 1.72 + nsresult GetBoundsForAreaContent(nsIContent *aContent, 1.73 + nsRect& aBounds); 1.74 + 1.75 +protected: 1.76 + virtual ~nsImageMap(); 1.77 + 1.78 + void FreeAreas(); 1.79 + 1.80 + nsresult UpdateAreas(); 1.81 + nsresult SearchForAreas(nsIContent* aParent, bool& aFoundArea, 1.82 + bool& aFoundAnchor); 1.83 + 1.84 + nsresult AddArea(nsIContent* aArea); 1.85 + 1.86 + void MaybeUpdateAreas(nsIContent *aContent); 1.87 + 1.88 + nsImageFrame* mImageFrame; // the frame that owns us 1.89 + nsCOMPtr<nsIContent> mMap; 1.90 + nsAutoTArray<Area*, 8> mAreas; // almost always has some entries 1.91 + bool mContainsBlockContents; 1.92 +}; 1.93 + 1.94 +#endif /* nsImageMap_h */