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: #ifndef nsImageBoxFrame_h___ michael@0: #define nsImageBoxFrame_h___ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsLeafBoxFrame.h" michael@0: michael@0: #include "imgILoader.h" michael@0: #include "imgIRequest.h" michael@0: #include "imgIContainer.h" michael@0: #include "imgINotificationObserver.h" michael@0: #include "imgIOnloadBlocker.h" michael@0: michael@0: class imgRequestProxy; michael@0: class nsImageBoxFrame; michael@0: michael@0: class nsDisplayXULImage; michael@0: michael@0: class nsImageBoxListener : public imgINotificationObserver, michael@0: public imgIOnloadBlocker michael@0: { michael@0: public: michael@0: nsImageBoxListener(); michael@0: virtual ~nsImageBoxListener(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_IMGINOTIFICATIONOBSERVER michael@0: NS_DECL_IMGIONLOADBLOCKER michael@0: michael@0: void SetFrame(nsImageBoxFrame *frame) { mFrame = frame; } michael@0: michael@0: private: michael@0: nsImageBoxFrame *mFrame; michael@0: }; michael@0: michael@0: class nsImageBoxFrame : public nsLeafBoxFrame michael@0: { michael@0: public: michael@0: typedef mozilla::layers::LayerManager LayerManager; michael@0: michael@0: friend class nsDisplayXULImage; michael@0: NS_DECL_FRAMEARENA_HELPERS michael@0: michael@0: virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; michael@0: virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE; michael@0: michael@0: nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData); michael@0: michael@0: friend nsIFrame* NS_NewImageBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); michael@0: michael@0: virtual void Init(nsIContent* aContent, michael@0: nsIFrame* aParent, michael@0: nsIFrame* asPrevInFlow) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) MOZ_OVERRIDE; michael@0: michael@0: virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; michael@0: michael@0: virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; michael@0: michael@0: virtual nsIAtom* GetType() const MOZ_OVERRIDE; michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: /** michael@0: * Update mUseSrcAttr from appropriate content attributes or from michael@0: * style, throw away the current image, and load the appropriate michael@0: * image. michael@0: * */ michael@0: void UpdateImage(); michael@0: michael@0: /** michael@0: * Update mLoadFlags from content attributes. Does not attempt to reload the michael@0: * image using the new load flags. michael@0: */ michael@0: void UpdateLoadFlags(); michael@0: michael@0: virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) MOZ_OVERRIDE; michael@0: michael@0: virtual ~nsImageBoxFrame(); michael@0: michael@0: void PaintImage(nsRenderingContext& aRenderingContext, michael@0: const nsRect& aDirtyRect, michael@0: nsPoint aPt, uint32_t aFlags); michael@0: michael@0: already_AddRefed GetContainer(LayerManager* aManager); michael@0: protected: michael@0: nsImageBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext); michael@0: michael@0: virtual void GetImageSize(); michael@0: michael@0: private: michael@0: nsresult OnStartContainer(imgIRequest *request, imgIContainer *image); michael@0: nsresult OnStopDecode(imgIRequest *request); michael@0: nsresult OnStopRequest(imgIRequest *request, nsresult status); michael@0: nsresult OnImageIsAnimated(imgIRequest* aRequest); michael@0: nsresult FrameChanged(imgIRequest *aRequest); michael@0: michael@0: nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used. michael@0: nsSize mIntrinsicSize; michael@0: nsSize mImageSize; michael@0: michael@0: // Boolean variable to determine if the current image request has been michael@0: // registered with the refresh driver. michael@0: bool mRequestRegistered; michael@0: michael@0: nsRefPtr mImageRequest; michael@0: nsCOMPtr mListener; michael@0: michael@0: int32_t mLoadFlags; michael@0: michael@0: bool mUseSrcAttr; ///< Whether or not the image src comes from an attribute. michael@0: bool mSuppressStyleCheck; michael@0: bool mFireEventOnDecode; michael@0: }; // class nsImageBoxFrame michael@0: michael@0: class nsDisplayXULImage : public nsDisplayImageContainer { michael@0: public: michael@0: nsDisplayXULImage(nsDisplayListBuilder* aBuilder, michael@0: nsImageBoxFrame* aFrame) : michael@0: nsDisplayImageContainer(aBuilder, aFrame) { michael@0: MOZ_COUNT_CTOR(nsDisplayXULImage); michael@0: } michael@0: #ifdef NS_BUILD_REFCNT_LOGGING michael@0: virtual ~nsDisplayXULImage() { michael@0: MOZ_COUNT_DTOR(nsDisplayXULImage); michael@0: } michael@0: #endif michael@0: michael@0: virtual already_AddRefed GetContainer(LayerManager* aManager, michael@0: nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE; michael@0: virtual void ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset) MOZ_OVERRIDE; michael@0: virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE michael@0: { michael@0: *aSnap = true; michael@0: return nsRect(ToReferenceFrame(), Frame()->GetSize()); michael@0: } michael@0: virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder, michael@0: const nsDisplayItemGeometry* aGeometry, michael@0: nsRegion* aInvalidRegion) MOZ_OVERRIDE; michael@0: // Doesn't handle HitTest because nsLeafBoxFrame already creates an michael@0: // event receiver for us michael@0: virtual void Paint(nsDisplayListBuilder* aBuilder, michael@0: nsRenderingContext* aCtx) MOZ_OVERRIDE; michael@0: NS_DISPLAY_DECL_NAME("XULImage", TYPE_XUL_IMAGE) michael@0: }; michael@0: michael@0: #endif /* nsImageBoxFrame_h___ */