nsImageBoxFrame.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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___
  7. #include "mozilla/Attributes.h"
  8. #include "nsLeafBoxFrame.h"
  9. #include "imgILoader.h"
  10. #include "imgIRequest.h"
  11. #include "imgIContainer.h"
  12. #include "imgINotificationObserver.h"
  13. #include "imgIOnloadBlocker.h"
  14. class imgRequestProxy;
  15. class nsImageBoxFrame;
  16. class nsDisplayXULImage;
  17. class nsImageBoxListener final : public imgINotificationObserver,
  18. public imgIOnloadBlocker
  19. {
  20. public:
  21. nsImageBoxListener();
  22. NS_DECL_ISUPPORTS
  23. NS_DECL_IMGINOTIFICATIONOBSERVER
  24. NS_DECL_IMGIONLOADBLOCKER
  25. void SetFrame(nsImageBoxFrame *frame) { mFrame = frame; }
  26. private:
  27. virtual ~nsImageBoxListener();
  28. nsImageBoxFrame *mFrame;
  29. };
  30. class nsImageBoxFrame final : public nsLeafBoxFrame
  31. {
  32. public:
  33. typedef mozilla::image::DrawResult DrawResult;
  34. typedef mozilla::layers::ImageContainer ImageContainer;
  35. typedef mozilla::layers::LayerManager LayerManager;
  36. friend class nsDisplayXULImage;
  37. NS_DECL_FRAMEARENA_HELPERS
  38. virtual nsSize GetXULPrefSize(nsBoxLayoutState& aBoxLayoutState) override;
  39. virtual nsSize GetXULMinSize(nsBoxLayoutState& aBoxLayoutState) override;
  40. virtual nscoord GetXULBoxAscent(nsBoxLayoutState& aBoxLayoutState) override;
  41. virtual void MarkIntrinsicISizesDirty() override;
  42. nsresult Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData);
  43. friend nsIFrame* NS_NewImageBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
  44. virtual void Init(nsIContent* aContent,
  45. nsContainerFrame* aParent,
  46. nsIFrame* asPrevInFlow) override;
  47. virtual nsresult AttributeChanged(int32_t aNameSpaceID,
  48. nsIAtom* aAttribute,
  49. int32_t aModType) override;
  50. virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
  51. virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
  52. virtual nsIAtom* GetType() const override;
  53. #ifdef DEBUG_FRAME_DUMP
  54. virtual nsresult GetFrameName(nsAString& aResult) const override;
  55. #endif
  56. /**
  57. * Update mUseSrcAttr from appropriate content attributes or from
  58. * style, throw away the current image, and load the appropriate
  59. * image.
  60. * */
  61. void UpdateImage();
  62. /**
  63. * Update mLoadFlags from content attributes. Does not attempt to reload the
  64. * image using the new load flags.
  65. */
  66. void UpdateLoadFlags();
  67. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  68. const nsDisplayListSet& aLists) override;
  69. virtual ~nsImageBoxFrame();
  70. DrawResult PaintImage(nsRenderingContext& aRenderingContext,
  71. const nsRect& aDirtyRect,
  72. nsPoint aPt, uint32_t aFlags);
  73. bool CanOptimizeToImageLayer();
  74. protected:
  75. explicit nsImageBoxFrame(nsStyleContext* aContext);
  76. virtual void GetImageSize();
  77. private:
  78. nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
  79. nsresult OnDecodeComplete(imgIRequest* aRequest);
  80. nsresult OnLoadComplete(imgIRequest* aRequest, nsresult aStatus);
  81. nsresult OnImageIsAnimated(imgIRequest* aRequest);
  82. nsresult OnFrameUpdate(imgIRequest* aRequest);
  83. nsRect mSubRect; ///< If set, indicates that only the portion of the image specified by the rect should be used.
  84. nsSize mIntrinsicSize;
  85. nsSize mImageSize;
  86. RefPtr<imgRequestProxy> mImageRequest;
  87. nsCOMPtr<imgINotificationObserver> mListener;
  88. int32_t mLoadFlags;
  89. // Boolean variable to determine if the current image request has been
  90. // registered with the refresh driver.
  91. bool mRequestRegistered;
  92. bool mUseSrcAttr; ///< Whether or not the image src comes from an attribute.
  93. bool mSuppressStyleCheck;
  94. }; // class nsImageBoxFrame
  95. class nsDisplayXULImage : public nsDisplayImageContainer {
  96. public:
  97. nsDisplayXULImage(nsDisplayListBuilder* aBuilder,
  98. nsImageBoxFrame* aFrame) :
  99. nsDisplayImageContainer(aBuilder, aFrame) {
  100. MOZ_COUNT_CTOR(nsDisplayXULImage);
  101. }
  102. #ifdef NS_BUILD_REFCNT_LOGGING
  103. virtual ~nsDisplayXULImage() {
  104. MOZ_COUNT_DTOR(nsDisplayXULImage);
  105. }
  106. #endif
  107. virtual bool CanOptimizeToImageLayer(LayerManager* aManager,
  108. nsDisplayListBuilder* aBuilder) override;
  109. virtual already_AddRefed<imgIContainer> GetImage() override;
  110. virtual nsRect GetDestRect() override;
  111. virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override
  112. {
  113. *aSnap = true;
  114. return nsRect(ToReferenceFrame(), Frame()->GetSize());
  115. }
  116. virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) override;
  117. virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
  118. const nsDisplayItemGeometry* aGeometry,
  119. nsRegion* aInvalidRegion) override;
  120. // Doesn't handle HitTest because nsLeafBoxFrame already creates an
  121. // event receiver for us
  122. virtual void Paint(nsDisplayListBuilder* aBuilder,
  123. nsRenderingContext* aCtx) override;
  124. NS_DISPLAY_DECL_NAME("XULImage", TYPE_XUL_IMAGE)
  125. };
  126. #endif /* nsImageBoxFrame_h___ */