1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /* rendering object for list-item bullets */
8 
9 #ifndef nsBulletFrame_h___
10 #define nsBulletFrame_h___
11 
12 #include "mozilla/Attributes.h"
13 #include "nsFrame.h"
14 
15 #include "imgIContainer.h"
16 #include "imgINotificationObserver.h"
17 
18 class imgIContainer;
19 class imgRequestProxy;
20 
21 class nsBulletFrame;
22 class BulletRenderer;
23 
24 class nsBulletListener final : public imgINotificationObserver {
25  public:
26   nsBulletListener();
27 
28   NS_DECL_ISUPPORTS
29   NS_DECL_IMGINOTIFICATIONOBSERVER
30 
SetFrame(nsBulletFrame * frame)31   void SetFrame(nsBulletFrame* frame) { mFrame = frame; }
32 
33  private:
34   virtual ~nsBulletListener();
35 
36   nsBulletFrame* mFrame;
37 };
38 
39 /**
40  * A simple class that manages the layout and rendering of html bullets.
41  * This class also supports the CSS list-style properties.
42  */
43 class nsBulletFrame final : public nsFrame {
44   typedef mozilla::image::ImgDrawResult ImgDrawResult;
45 
46  public:
NS_DECL_FRAMEARENA_HELPERS(nsBulletFrame)47   NS_DECL_FRAMEARENA_HELPERS(nsBulletFrame)
48 #ifdef DEBUG
49   NS_DECL_QUERYFRAME
50 #endif
51 
52   explicit nsBulletFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
53       : nsFrame(aStyle, aPresContext, kClassID),
54         mPadding(GetWritingMode()),
55         mIntrinsicSize(GetWritingMode()),
56         mRequestRegistered(false) {}
57 
58   virtual ~nsBulletFrame();
59 
60   void Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aData);
61 
62   // nsIFrame
63   virtual void DestroyFrom(nsIFrame* aDestructRoot,
64                            PostDestroyData& aPostDestroyData) override;
65   virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
66                                 const nsDisplayListSet& aLists) override;
67   virtual void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
68 #ifdef DEBUG_FRAME_DUMP
69   virtual nsresult GetFrameName(nsAString& aResult) const override;
70 #endif
71 
72   virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aMetrics,
73                       const ReflowInput& aReflowInput,
74                       nsReflowStatus& aStatus) override;
75   virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
76   virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
77   void AddInlineMinISize(gfxContext* aRenderingContext,
78                          nsIFrame::InlineMinISizeData* aData) override;
79   void AddInlinePrefISize(gfxContext* aRenderingContext,
80                           nsIFrame::InlinePrefISizeData* aData) override;
81 
IsFrameOfType(uint32_t aFlags)82   virtual bool IsFrameOfType(uint32_t aFlags) const override {
83     if (aFlags & (eSupportsCSSTransforms | eSupportsContainLayoutAndPaint)) {
84       return false;
85     }
86     return nsFrame::IsFrameOfType(aFlags & ~nsIFrame::eLineParticipant);
87   }
88 
89   // nsBulletFrame
90 
91   /* get list item text, with prefix & suffix */
92   static void GetListItemText(mozilla::CounterStyle*, mozilla::WritingMode,
93                               int32_t aOrdinal, nsAString& aResult);
94 
95 #ifdef ACCESSIBILITY
96   void GetSpokenText(nsAString& aText);
97 #endif
98 
99   Maybe<BulletRenderer> CreateBulletRenderer(gfxContext& aRenderingContext,
100                                              nsPoint aPt);
101   ImgDrawResult PaintBullet(gfxContext& aRenderingContext, nsPoint aPt,
102                             const nsRect& aDirtyRect, uint32_t aFlags,
103                             bool aDisableSubpixelAA);
104 
105   virtual bool IsEmpty() override;
106   virtual bool IsSelfEmpty() override;
107 
108   // XXXmats note that this method returns a non-standard baseline that includes
109   // the ::marker block-start margin.  New code should probably use
110   // GetNaturalBaselineBOffset instead, which returns a normal baseline offset
111   // as documented in nsIFrame.h.
112   virtual nscoord GetLogicalBaseline(
113       mozilla::WritingMode aWritingMode) const override;
114 
115   bool GetNaturalBaselineBOffset(mozilla::WritingMode aWM,
116                                  BaselineSharingGroup aBaselineGroup,
117                                  nscoord* aBaseline) const override;
118 
119   float GetFontSizeInflation() const;
HasFontSizeInflation()120   bool HasFontSizeInflation() const {
121     return (GetStateBits() & BULLET_FRAME_HAS_FONT_INFLATION) != 0;
122   }
123   void SetFontSizeInflation(float aInflation);
124 
Ordinal()125   int32_t Ordinal() const { return mOrdinal; }
126   void SetOrdinal(int32_t aOrdinal, bool aNotify);
127 
128   already_AddRefed<imgIContainer> GetImage() const;
129 
130  protected:
131   void OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
132 
133   void AppendSpacingToPadding(nsFontMetrics* aFontMetrics,
134                               mozilla::LogicalMargin* aPadding);
135   void GetDesiredSize(nsPresContext* aPresContext,
136                       gfxContext* aRenderingContext, ReflowOutput& aMetrics,
137                       float aFontSizeInflation,
138                       mozilla::LogicalMargin* aPadding);
139 
140   void GetLoadGroup(nsPresContext* aPresContext, nsILoadGroup** aLoadGroup);
141   mozilla::dom::Document* GetOurCurrentDoc() const;
142 
143   mozilla::LogicalMargin mPadding;
144   RefPtr<imgRequestProxy> mImageRequest;
145   RefPtr<nsBulletListener> mListener;
146 
147   mozilla::LogicalSize mIntrinsicSize;
148 
149  private:
150   mozilla::CounterStyle* ResolveCounterStyle();
151   nscoord GetListStyleAscent() const;
152   void RegisterImageRequest(bool aKnownToBeAnimated);
153   void DeregisterAndCancelImageRequest();
154 
155   // Requires being set via SetOrdinal.
156   int32_t mOrdinal = 0;
157 
158   // This is a boolean flag indicating whether or not the current image request
159   // has been registered with the refresh driver.
160   bool mRequestRegistered : 1;
161 };
162 
163 #endif /* nsBulletFrame_h___ */
164