layout/xul/nsImageBoxFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/nsImageBoxFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,158 @@
     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 +#ifndef nsImageBoxFrame_h___
     1.9 +#define nsImageBoxFrame_h___
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "nsLeafBoxFrame.h"
    1.13 +
    1.14 +#include "imgILoader.h"
    1.15 +#include "imgIRequest.h"
    1.16 +#include "imgIContainer.h"
    1.17 +#include "imgINotificationObserver.h"
    1.18 +#include "imgIOnloadBlocker.h"
    1.19 +
    1.20 +class imgRequestProxy;
    1.21 +class nsImageBoxFrame;
    1.22 +
    1.23 +class nsDisplayXULImage;
    1.24 +
    1.25 +class nsImageBoxListener : public imgINotificationObserver,
    1.26 +                           public imgIOnloadBlocker
    1.27 +{
    1.28 +public:
    1.29 +  nsImageBoxListener();
    1.30 +  virtual ~nsImageBoxListener();
    1.31 +
    1.32 +  NS_DECL_ISUPPORTS
    1.33 +  NS_DECL_IMGINOTIFICATIONOBSERVER
    1.34 +  NS_DECL_IMGIONLOADBLOCKER
    1.35 +
    1.36 +  void SetFrame(nsImageBoxFrame *frame) { mFrame = frame; }
    1.37 +
    1.38 +private:
    1.39 +  nsImageBoxFrame *mFrame;
    1.40 +};
    1.41 +
    1.42 +class nsImageBoxFrame : public nsLeafBoxFrame
    1.43 +{
    1.44 +public:
    1.45 +  typedef mozilla::layers::LayerManager LayerManager;
    1.46 +
    1.47 +  friend class nsDisplayXULImage;
    1.48 +  NS_DECL_FRAMEARENA_HELPERS
    1.49 +
    1.50 +  virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.51 +  virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.52 +  virtual nscoord GetBoxAscent(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
    1.53 +  virtual void MarkIntrinsicWidthsDirty() MOZ_OVERRIDE;
    1.54 +
    1.55 +  nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData);
    1.56 +
    1.57 +  friend nsIFrame* NS_NewImageBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.58 +
    1.59 +  virtual void Init(nsIContent*      aContent,
    1.60 +                    nsIFrame*        aParent,
    1.61 +                    nsIFrame*        asPrevInFlow) MOZ_OVERRIDE;
    1.62 +
    1.63 +  virtual nsresult AttributeChanged(int32_t aNameSpaceID,
    1.64 +                                    nsIAtom* aAttribute,
    1.65 +                                    int32_t aModType) MOZ_OVERRIDE;
    1.66 +
    1.67 +  virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE;
    1.68 +
    1.69 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    1.70 +
    1.71 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    1.72 +#ifdef DEBUG_FRAME_DUMP
    1.73 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
    1.74 +#endif
    1.75 +
    1.76 +  /** 
    1.77 +   * Update mUseSrcAttr from appropriate content attributes or from
    1.78 +   * style, throw away the current image, and load the appropriate
    1.79 +   * image.
    1.80 +   * */
    1.81 +  void UpdateImage();
    1.82 +
    1.83 +  /**
    1.84 +   * Update mLoadFlags from content attributes. Does not attempt to reload the
    1.85 +   * image using the new load flags.
    1.86 +   */
    1.87 +  void UpdateLoadFlags();
    1.88 +
    1.89 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.90 +                                const nsRect&           aDirtyRect,
    1.91 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
    1.92 +
    1.93 +  virtual ~nsImageBoxFrame();
    1.94 +
    1.95 +  void  PaintImage(nsRenderingContext& aRenderingContext,
    1.96 +                   const nsRect& aDirtyRect,
    1.97 +                   nsPoint aPt, uint32_t aFlags);
    1.98 +
    1.99 +  already_AddRefed<mozilla::layers::ImageContainer> GetContainer(LayerManager* aManager);
   1.100 +protected:
   1.101 +  nsImageBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext);
   1.102 +
   1.103 +  virtual void GetImageSize();
   1.104 +
   1.105 +private:
   1.106 +  nsresult OnStartContainer(imgIRequest *request, imgIContainer *image);
   1.107 +  nsresult OnStopDecode(imgIRequest *request);
   1.108 +  nsresult OnStopRequest(imgIRequest *request, nsresult status);
   1.109 +  nsresult OnImageIsAnimated(imgIRequest* aRequest);
   1.110 +  nsresult FrameChanged(imgIRequest *aRequest);
   1.111 +
   1.112 +  nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used.
   1.113 +  nsSize mIntrinsicSize;
   1.114 +  nsSize mImageSize;
   1.115 +
   1.116 +  // Boolean variable to determine if the current image request has been
   1.117 +  // registered with the refresh driver.
   1.118 +  bool mRequestRegistered;
   1.119 +
   1.120 +  nsRefPtr<imgRequestProxy> mImageRequest;
   1.121 +  nsCOMPtr<imgINotificationObserver> mListener;
   1.122 +
   1.123 +  int32_t mLoadFlags;
   1.124 +
   1.125 +  bool mUseSrcAttr; ///< Whether or not the image src comes from an attribute.
   1.126 +  bool mSuppressStyleCheck;
   1.127 +  bool mFireEventOnDecode;
   1.128 +}; // class nsImageBoxFrame
   1.129 +
   1.130 +class nsDisplayXULImage : public nsDisplayImageContainer {
   1.131 +public:
   1.132 +  nsDisplayXULImage(nsDisplayListBuilder* aBuilder,
   1.133 +                    nsImageBoxFrame* aFrame) :
   1.134 +    nsDisplayImageContainer(aBuilder, aFrame) {
   1.135 +    MOZ_COUNT_CTOR(nsDisplayXULImage);
   1.136 +  }
   1.137 +#ifdef NS_BUILD_REFCNT_LOGGING
   1.138 +  virtual ~nsDisplayXULImage() {
   1.139 +    MOZ_COUNT_DTOR(nsDisplayXULImage);
   1.140 +  }
   1.141 +#endif
   1.142 +
   1.143 +  virtual already_AddRefed<ImageContainer> GetContainer(LayerManager* aManager,
   1.144 +                                                        nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE;
   1.145 +  virtual void ConfigureLayer(ImageLayer* aLayer, const nsIntPoint& aOffset) MOZ_OVERRIDE;
   1.146 +  virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE
   1.147 +  {
   1.148 +    *aSnap = true;
   1.149 +    return nsRect(ToReferenceFrame(), Frame()->GetSize());
   1.150 +  }
   1.151 +  virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
   1.152 +                                         const nsDisplayItemGeometry* aGeometry,
   1.153 +                                         nsRegion* aInvalidRegion) MOZ_OVERRIDE;
   1.154 +  // Doesn't handle HitTest because nsLeafBoxFrame already creates an
   1.155 +  // event receiver for us
   1.156 +  virtual void Paint(nsDisplayListBuilder* aBuilder,
   1.157 +                     nsRenderingContext* aCtx) MOZ_OVERRIDE;
   1.158 +  NS_DISPLAY_DECL_NAME("XULImage", TYPE_XUL_IMAGE)
   1.159 +};
   1.160 +
   1.161 +#endif /* nsImageBoxFrame_h___ */

mercurial