layout/xul/nsImageBoxFrame.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef nsImageBoxFrame_h___
     6 #define nsImageBoxFrame_h___
     8 #include "mozilla/Attributes.h"
     9 #include "nsLeafBoxFrame.h"
    11 #include "imgILoader.h"
    12 #include "imgIRequest.h"
    13 #include "imgIContainer.h"
    14 #include "imgINotificationObserver.h"
    15 #include "imgIOnloadBlocker.h"
    17 class imgRequestProxy;
    18 class nsImageBoxFrame;
    20 class nsDisplayXULImage;
    22 class nsImageBoxListener : public imgINotificationObserver,
    23                            public imgIOnloadBlocker
    24 {
    25 public:
    26   nsImageBoxListener();
    27   virtual ~nsImageBoxListener();
    29   NS_DECL_ISUPPORTS
    30   NS_DECL_IMGINOTIFICATIONOBSERVER
    31   NS_DECL_IMGIONLOADBLOCKER
    33   void SetFrame(nsImageBoxFrame *frame) { mFrame = frame; }
    35 private:
    36   nsImageBoxFrame *mFrame;
    37 };
    39 class nsImageBoxFrame : public nsLeafBoxFrame
    40 {
    41 public:
    42   typedef mozilla::layers::LayerManager LayerManager;
    44   friend class nsDisplayXULImage;
    45   NS_DECL_FRAMEARENA_HELPERS
    47   virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    48   virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    49   virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    50   virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE;
    52   nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData);
    54   friend nsIFrame* NS_NewImageBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    56   virtual void Init(nsIContent*      aContent,
    57                     nsIFrame*        aParent,
    58                     nsIFrame*        asPrevInFlow) MOZ_OVERRIDE;
    60   virtual nsresult AttributeChanged(int32_t aNameSpaceID,
    61                                     nsIAtom* aAttribute,
    62                                     int32_t aModType) MOZ_OVERRIDE;
    64   virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
    66   virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    68   virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    69 #ifdef DEBUG_FRAME_DUMP
    70   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
    71 #endif
    73   /** 
    74    * Update mUseSrcAttr from appropriate content attributes or from
    75    * style, throw away the current image, and load the appropriate
    76    * image.
    77    * */
    78   void UpdateImage();
    80   /**
    81    * Update mLoadFlags from content attributes. Does not attempt to reload the
    82    * image using the new load flags.
    83    */
    84   void UpdateLoadFlags();
    86   virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    87                                 const nsRect&           aDirtyRect,
    88                                 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
    90   virtual ~nsImageBoxFrame();
    92   void  PaintImage(nsRenderingContext& aRenderingContext,
    93                    const nsRect& aDirtyRect,
    94                    nsPoint aPt, uint32_t aFlags);
    96   already_AddRefed<mozilla::layers::ImageContainer> GetContainer(LayerManager* aManager);
    97 protected:
    98   nsImageBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext);
   100   virtual void GetImageSize();
   102 private:
   103   nsresult OnStartContainer(imgIRequest *request, imgIContainer *image);
   104   nsresult OnStopDecode(imgIRequest *request);
   105   nsresult OnStopRequest(imgIRequest *request, nsresult status);
   106   nsresult OnImageIsAnimated(imgIRequest* aRequest);
   107   nsresult FrameChanged(imgIRequest *aRequest);
   109   nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used.
   110   nsSize mIntrinsicSize;
   111   nsSize mImageSize;
   113   // Boolean variable to determine if the current image request has been
   114   // registered with the refresh driver.
   115   bool mRequestRegistered;
   117   nsRefPtr<imgRequestProxy> mImageRequest;
   118   nsCOMPtr<imgINotificationObserver> mListener;
   120   int32_t mLoadFlags;
   122   bool mUseSrcAttr; ///< Whether or not the image src comes from an attribute.
   123   bool mSuppressStyleCheck;
   124   bool mFireEventOnDecode;
   125 }; // class nsImageBoxFrame
   127 class nsDisplayXULImage : public nsDisplayImageContainer {
   128 public:
   129   nsDisplayXULImage(nsDisplayListBuilder* aBuilder,
   130                     nsImageBoxFrame* aFrame) :
   131     nsDisplayImageContainer(aBuilder, aFrame) {
   132     MOZ_COUNT_CTOR(nsDisplayXULImage);
   133   }
   134 #ifdef NS_BUILD_REFCNT_LOGGING
   135   virtual ~nsDisplayXULImage() {
   136     MOZ_COUNT_DTOR(nsDisplayXULImage);
   137   }
   138 #endif
   140   virtual already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager,
   141                                                         nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE;
   142   virtual void ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset) MOZ_OVERRIDE;
   143   virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE
   144   {
   145     *aSnap = true;
   146     return nsRect(ToReferenceFrame(), Frame()->GetSize());
   147   }
   148   virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
   149                                          const nsDisplayItemGeometry* aGeometry,
   150                                          nsRegion* aInvalidRegion) MOZ_OVERRIDE;
   151   // Doesn't handle HitTest because nsLeafBoxFrame already creates an
   152   // event receiver for us
   153   virtual void Paint(nsDisplayListBuilder* aBuilder,
   154                      nsRenderingContext* aCtx) MOZ_OVERRIDE;
   155   NS_DISPLAY_DECL_NAME("XULImage", TYPE_XUL_IMAGE)
   156 };
   158 #endif /* nsImageBoxFrame_h___ */

mercurial