|
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 "imgINotificationObserver.h" |
|
15 |
|
16 class imgIContainer; |
|
17 class imgRequestProxy; |
|
18 |
|
19 class nsBulletFrame; |
|
20 |
|
21 class nsBulletListener : public imgINotificationObserver |
|
22 { |
|
23 public: |
|
24 nsBulletListener(); |
|
25 virtual ~nsBulletListener(); |
|
26 |
|
27 NS_DECL_ISUPPORTS |
|
28 NS_DECL_IMGINOTIFICATIONOBSERVER |
|
29 |
|
30 void SetFrame(nsBulletFrame *frame) { mFrame = frame; } |
|
31 |
|
32 private: |
|
33 nsBulletFrame *mFrame; |
|
34 }; |
|
35 |
|
36 /** |
|
37 * A simple class that manages the layout and rendering of html bullets. |
|
38 * This class also supports the CSS list-style properties. |
|
39 */ |
|
40 class nsBulletFrame : public nsFrame { |
|
41 public: |
|
42 NS_DECL_FRAMEARENA_HELPERS |
|
43 #ifdef DEBUG |
|
44 NS_DECL_QUERYFRAME_TARGET(nsBulletFrame) |
|
45 NS_DECL_QUERYFRAME |
|
46 #endif |
|
47 |
|
48 nsBulletFrame(nsStyleContext* aContext) |
|
49 : nsFrame(aContext) |
|
50 { |
|
51 } |
|
52 virtual ~nsBulletFrame(); |
|
53 |
|
54 NS_IMETHOD Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData); |
|
55 |
|
56 // nsIFrame |
|
57 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
|
58 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
|
59 const nsRect& aDirtyRect, |
|
60 const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
|
61 virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
|
62 virtual void DidSetStyleContext(nsStyleContext* aOldStyleContext) MOZ_OVERRIDE; |
|
63 #ifdef DEBUG_FRAME_DUMP |
|
64 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE; |
|
65 #endif |
|
66 |
|
67 // nsIHTMLReflow |
|
68 virtual nsresult Reflow(nsPresContext* aPresContext, |
|
69 nsHTMLReflowMetrics& aMetrics, |
|
70 const nsHTMLReflowState& aReflowState, |
|
71 nsReflowStatus& aStatus) MOZ_OVERRIDE; |
|
72 virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; |
|
73 virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE; |
|
74 |
|
75 // nsBulletFrame |
|
76 int32_t SetListItemOrdinal(int32_t aNextOrdinal, bool* aChanged, |
|
77 int32_t aIncrement); |
|
78 |
|
79 |
|
80 /* get list item text, without '.' */ |
|
81 static void AppendCounterText(int32_t aListStyleType, |
|
82 int32_t aOrdinal, |
|
83 nsString& aResult, |
|
84 bool& aIsRTL); |
|
85 |
|
86 /* get suffix of list item */ |
|
87 static void GetListItemSuffix(int32_t aListStyleType, |
|
88 nsString& aResult, |
|
89 bool& aSuppressPadding); |
|
90 |
|
91 /* get list item text, with '.' */ |
|
92 void GetListItemText(const nsStyleList& aStyleList, nsString& aResult); |
|
93 |
|
94 void PaintBullet(nsRenderingContext& aRenderingContext, nsPoint aPt, |
|
95 const nsRect& aDirtyRect, uint32_t aFlags); |
|
96 |
|
97 virtual bool IsEmpty() MOZ_OVERRIDE; |
|
98 virtual bool IsSelfEmpty() MOZ_OVERRIDE; |
|
99 virtual nscoord GetBaseline() const MOZ_OVERRIDE; |
|
100 |
|
101 float GetFontSizeInflation() const; |
|
102 bool HasFontSizeInflation() const { |
|
103 return (GetStateBits() & BULLET_FRAME_HAS_FONT_INFLATION) != 0; |
|
104 } |
|
105 void SetFontSizeInflation(float aInflation); |
|
106 |
|
107 int32_t GetOrdinal() { return mOrdinal; } |
|
108 |
|
109 already_AddRefed<imgIContainer> GetImage() const; |
|
110 |
|
111 protected: |
|
112 nsresult OnStartContainer(imgIRequest *aRequest, imgIContainer *aImage); |
|
113 |
|
114 void GetDesiredSize(nsPresContext* aPresContext, |
|
115 nsRenderingContext *aRenderingContext, |
|
116 nsHTMLReflowMetrics& aMetrics, |
|
117 float aFontSizeInflation); |
|
118 |
|
119 void GetLoadGroup(nsPresContext *aPresContext, nsILoadGroup **aLoadGroup); |
|
120 |
|
121 nsMargin mPadding; |
|
122 nsRefPtr<imgRequestProxy> mImageRequest; |
|
123 nsRefPtr<nsBulletListener> mListener; |
|
124 |
|
125 nsSize mIntrinsicSize; |
|
126 int32_t mOrdinal; |
|
127 bool mTextIsRTL; |
|
128 |
|
129 // If set to true, any padding of bullet defined in the UA style sheet will |
|
130 // be suppressed. This is used for some CJK numbering styles where extra |
|
131 // space after the suffix is not desired. Note that, any author-specified |
|
132 // padding overriding the default style will NOT be suppressed. |
|
133 bool mSuppressPadding; |
|
134 |
|
135 private: |
|
136 |
|
137 // This is a boolean flag indicating whether or not the current image request |
|
138 // has been registered with the refresh driver. |
|
139 bool mRequestRegistered; |
|
140 }; |
|
141 |
|
142 #endif /* nsBulletFrame_h___ */ |