Line data Source code
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 :
6 : /* rendering object for list-item bullets */
7 :
8 : #ifndef nsBulletFrame_h___
9 : #define nsBulletFrame_h___
10 :
11 : #include "mozilla/Attributes.h"
12 : #include "nsFrame.h"
13 :
14 : #include "imgIContainer.h"
15 : #include "imgINotificationObserver.h"
16 : #include "imgIOnloadBlocker.h"
17 :
18 : class imgIContainer;
19 : class imgRequestProxy;
20 :
21 : class nsBulletFrame;
22 : class BulletRenderer;
23 :
24 : class nsBulletListener final : public imgINotificationObserver,
25 : public imgIOnloadBlocker
26 : {
27 : public:
28 : nsBulletListener();
29 :
30 : NS_DECL_ISUPPORTS
31 : NS_DECL_IMGINOTIFICATIONOBSERVER
32 : NS_DECL_IMGIONLOADBLOCKER
33 :
34 0 : void SetFrame(nsBulletFrame *frame) { mFrame = frame; }
35 :
36 : private:
37 : virtual ~nsBulletListener();
38 :
39 : nsBulletFrame *mFrame;
40 : };
41 :
42 : /**
43 : * A simple class that manages the layout and rendering of html bullets.
44 : * This class also supports the CSS list-style properties.
45 : */
46 : class nsBulletFrame final : public nsFrame {
47 : typedef mozilla::image::DrawResult DrawResult;
48 :
49 : public:
50 0 : NS_DECL_FRAMEARENA_HELPERS(nsBulletFrame)
51 : #ifdef DEBUG
52 : NS_DECL_QUERYFRAME
53 : #endif
54 :
55 0 : explicit nsBulletFrame(nsStyleContext* aContext)
56 0 : : nsFrame(aContext, kClassID)
57 : , mPadding(GetWritingMode())
58 : , mIntrinsicSize(GetWritingMode())
59 : , mOrdinal(0)
60 : , mRequestRegistered(false)
61 0 : , mBlockingOnload(false)
62 0 : {}
63 :
64 : virtual ~nsBulletFrame();
65 :
66 : NS_IMETHOD Notify(imgIRequest* aRequest, int32_t aType, const nsIntRect* aData);
67 : NS_IMETHOD BlockOnload(imgIRequest* aRequest);
68 : NS_IMETHOD UnblockOnload(imgIRequest* aRequest);
69 :
70 : // nsIFrame
71 : virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
72 : virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
73 : const nsRect& aDirtyRect,
74 : const nsDisplayListSet& aLists) override;
75 : virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) override;
76 : #ifdef DEBUG_FRAME_DUMP
77 : virtual nsresult GetFrameName(nsAString& aResult) const override;
78 : #endif
79 :
80 : virtual void Reflow(nsPresContext* aPresContext,
81 : ReflowOutput& aMetrics,
82 : const ReflowInput& aReflowInput,
83 : nsReflowStatus& aStatus) override;
84 : virtual nscoord GetMinISize(gfxContext *aRenderingContext) override;
85 : virtual nscoord GetPrefISize(gfxContext *aRenderingContext) override;
86 : void AddInlineMinISize(gfxContext* aRenderingContext,
87 : nsIFrame::InlineMinISizeData* aData) override;
88 : void AddInlinePrefISize(gfxContext* aRenderingContext,
89 : nsIFrame::InlinePrefISizeData* aData) override;
90 :
91 : // nsBulletFrame
92 : int32_t SetListItemOrdinal(int32_t aNextOrdinal, bool* aChanged,
93 : int32_t aIncrement);
94 :
95 : /* get list item text, with prefix & suffix */
96 : void GetListItemText(nsAString& aResult);
97 :
98 : void GetSpokenText(nsAString& aText);
99 :
100 : Maybe<BulletRenderer>
101 : CreateBulletRenderer(gfxContext& aRenderingContext, nsPoint aPt);
102 : DrawResult PaintBullet(gfxContext& aRenderingContext, nsPoint aPt,
103 : const nsRect& aDirtyRect, uint32_t aFlags,
104 : bool aDisableSubpixelAA);
105 :
106 : virtual bool IsEmpty() override;
107 : virtual bool IsSelfEmpty() override;
108 : virtual nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode) const override;
109 :
110 : float GetFontSizeInflation() const;
111 0 : bool HasFontSizeInflation() const {
112 0 : return (GetStateBits() & BULLET_FRAME_HAS_FONT_INFLATION) != 0;
113 : }
114 : void SetFontSizeInflation(float aInflation);
115 :
116 0 : int32_t GetOrdinal() { return mOrdinal; }
117 :
118 : already_AddRefed<imgIContainer> GetImage() const;
119 :
120 : protected:
121 : nsresult OnSizeAvailable(imgIRequest* aRequest, imgIContainer* aImage);
122 :
123 : void AppendSpacingToPadding(nsFontMetrics* aFontMetrics,
124 : mozilla::LogicalMargin* aPadding);
125 : void GetDesiredSize(nsPresContext* aPresContext,
126 : gfxContext *aRenderingContext,
127 : ReflowOutput& aMetrics,
128 : float aFontSizeInflation,
129 : mozilla::LogicalMargin* aPadding);
130 :
131 : void GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGroup);
132 : nsIDocument* GetOurCurrentDoc() const;
133 :
134 : mozilla::LogicalMargin mPadding;
135 : RefPtr<imgRequestProxy> mImageRequest;
136 : RefPtr<nsBulletListener> mListener;
137 :
138 : mozilla::LogicalSize mIntrinsicSize;
139 : int32_t mOrdinal;
140 :
141 : private:
142 : void RegisterImageRequest(bool aKnownToBeAnimated);
143 : void DeregisterAndCancelImageRequest();
144 :
145 : // This is a boolean flag indicating whether or not the current image request
146 : // has been registered with the refresh driver.
147 : bool mRequestRegistered : 1;
148 :
149 : // Whether we're currently blocking onload.
150 : bool mBlockingOnload : 1;
151 : };
152 :
153 : #endif /* nsBulletFrame_h___ */
|