Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
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 : /* service providing platform-specific native rendering for widgets */
8 :
9 : #ifndef nsITheme_h_
10 : #define nsITheme_h_
11 :
12 : #include "nsISupports.h"
13 : #include "nsCOMPtr.h"
14 : #include "nsColor.h"
15 : #include "Units.h"
16 :
17 : struct nsRect;
18 : class gfxContext;
19 : class nsAttrValue;
20 : class nsPresContext;
21 : class nsDeviceContext;
22 : class nsIFrame;
23 : class nsIAtom;
24 : class nsIWidget;
25 :
26 : // IID for the nsITheme interface
27 : // {7329f760-08cb-450f-8225-dae729096dec}
28 : #define NS_ITHEME_IID \
29 : { 0x7329f760, 0x08cb, 0x450f, \
30 : { 0x82, 0x25, 0xda, 0xe7, 0x29, 0x09, 0x6d, 0xec } }
31 : // {0ae05515-cf7a-45a8-9e02-6556de7685b1}
32 : #define NS_THEMERENDERER_CID \
33 : { 0x0ae05515, 0xcf7a, 0x45a8, \
34 : { 0x9e, 0x02, 0x65, 0x56, 0xde, 0x76, 0x85, 0xb1 } }
35 :
36 : /**
37 : * nsITheme is a service that provides platform-specific native
38 : * rendering for widgets. In other words, it provides the necessary
39 : * operations to draw a rendering object (an nsIFrame) as a native
40 : * widget.
41 : *
42 : * All the methods on nsITheme take a rendering context or device
43 : * context, a frame (the rendering object), and a widget type (one of
44 : * the constants in nsThemeConstants.h).
45 : */
46 2 : class nsITheme: public nsISupports {
47 : public:
48 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_ITHEME_IID)
49 :
50 : /**
51 : * Draw the actual theme background.
52 : * @param aContext the context to draw into
53 : * @param aFrame the frame for the widget that we're drawing
54 : * @param aWidgetType the -moz-appearance value to draw
55 : * @param aRect the rectangle defining the area occupied by the widget
56 : * @param aDirtyRect the rectangle that needs to be drawn
57 : */
58 : NS_IMETHOD DrawWidgetBackground(gfxContext* aContext,
59 : nsIFrame* aFrame,
60 : uint8_t aWidgetType,
61 : const nsRect& aRect,
62 : const nsRect& aDirtyRect) = 0;
63 :
64 : /**
65 : * Get the computed CSS border for the widget, in pixels.
66 : */
67 : NS_IMETHOD GetWidgetBorder(nsDeviceContext* aContext,
68 : nsIFrame* aFrame,
69 : uint8_t aWidgetType,
70 : nsIntMargin* aResult)=0;
71 :
72 : /**
73 : * This method can return false to indicate that the CSS padding
74 : * value should be used. Otherwise, it will fill in aResult with the
75 : * computed padding, in pixels, and return true.
76 : *
77 : * XXXldb This ought to be required to return true for non-containers
78 : * so that we don't let specified padding that has no effect change
79 : * the computed padding and potentially the size.
80 : */
81 : virtual bool GetWidgetPadding(nsDeviceContext* aContext,
82 : nsIFrame* aFrame,
83 : uint8_t aWidgetType,
84 : nsIntMargin* aResult) = 0;
85 :
86 : /**
87 : * On entry, *aResult is positioned at 0,0 and sized to the new size
88 : * of aFrame (aFrame->GetSize() may be stale and should not be used).
89 : * This method can return false to indicate that no special
90 : * overflow area is required by the native widget. Otherwise it will
91 : * fill in aResult with the desired overflow area, in appunits, relative
92 : * to the frame origin, and return true.
93 : *
94 : * This overflow area is used to determine what area needs to be
95 : * repainted when the widget changes. However, it does not affect the
96 : * widget's size or what area is reachable by scrollbars. (In other
97 : * words, in layout terms, it affects visual overflow but not
98 : * scrollable overflow.)
99 : */
100 0 : virtual bool GetWidgetOverflow(nsDeviceContext* aContext,
101 : nsIFrame* aFrame,
102 : uint8_t aWidgetType,
103 : /*INOUT*/ nsRect* aOverflowRect)
104 0 : { return false; }
105 :
106 : /**
107 : * Get the minimum border-box size of a widget, in *pixels* (in
108 : * |aResult|). If |aIsOverridable| is set to true, this size is a
109 : * minimum size; if false, this size is the only valid size for the
110 : * widget.
111 : */
112 : NS_IMETHOD GetMinimumWidgetSize(nsPresContext* aPresContext,
113 : nsIFrame* aFrame,
114 : uint8_t aWidgetType,
115 : mozilla::LayoutDeviceIntSize* aResult,
116 : bool* aIsOverridable)=0;
117 :
118 :
119 : enum Transparency {
120 : eOpaque = 0,
121 : eTransparent,
122 : eUnknownTransparency
123 : };
124 :
125 : /**
126 : * Returns what we know about the transparency of the widget.
127 : */
128 0 : virtual Transparency GetWidgetTransparency(nsIFrame* aFrame, uint8_t aWidgetType)
129 0 : { return eUnknownTransparency; }
130 :
131 : /**
132 : * Sets |*aShouldRepaint| to indicate whether an attribute or content state
133 : * change should trigger a repaint. Call with null |aAttribute| (and
134 : * null |aOldValue|) for content state changes.
135 : */
136 : NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, uint8_t aWidgetType,
137 : nsIAtom* aAttribute, bool* aShouldRepaint,
138 : const nsAttrValue* aOldValue)=0;
139 :
140 : NS_IMETHOD ThemeChanged()=0;
141 :
142 44 : virtual bool WidgetAppearanceDependsOnWindowFocus(uint8_t aWidgetType)
143 44 : { return false; }
144 :
145 81 : virtual bool NeedToClearBackgroundBehindWidget(nsIFrame* aFrame,
146 : uint8_t aWidgetType)
147 81 : { return false; }
148 :
149 0 : virtual bool WidgetProvidesFontSmoothingBackgroundColor(nsIFrame* aFrame,
150 : uint8_t aWidgetType, nscolor* aColor)
151 0 : { return false; }
152 :
153 : /**
154 : * ThemeGeometryType values are used for describing themed nsIFrames in
155 : * calls to nsIWidget::UpdateThemeGeometries. We don't simply pass the
156 : * -moz-appearance value ("widget type") of the frame because the widget may
157 : * want to treat different frames with the same -moz-appearance differently
158 : * based on other properties of the frame. So we give the theme a first look
159 : * at the frame in nsITheme::ThemeGeometryTypeForWidget and pass the
160 : * returned ThemeGeometryType along to the widget.
161 : * Each theme backend defines the ThemeGeometryType values it needs in its
162 : * own nsITheme subclass. eThemeGeometryTypeUnknown is the only value that's
163 : * shared between backends.
164 : */
165 : typedef uint8_t ThemeGeometryType;
166 : enum {
167 : eThemeGeometryTypeUnknown = 0
168 : };
169 :
170 : /**
171 : * Returns the theme geometry type that should be used in the ThemeGeometry
172 : * array that's passed to the widget using nsIWidget::UpdateThemeGeometries.
173 : * A return value of eThemeGeometryTypeUnknown means that this frame will
174 : * not be included in the ThemeGeometry array.
175 : */
176 81 : virtual ThemeGeometryType ThemeGeometryTypeForWidget(nsIFrame* aFrame,
177 : uint8_t aWidgetType)
178 81 : { return eThemeGeometryTypeUnknown; }
179 :
180 : /**
181 : * Can the nsITheme implementation handle this widget?
182 : */
183 : virtual bool ThemeSupportsWidget(nsPresContext* aPresContext,
184 : nsIFrame* aFrame,
185 : uint8_t aWidgetType)=0;
186 :
187 : virtual bool WidgetIsContainer(uint8_t aWidgetType)=0;
188 :
189 : /**
190 : * Does the nsITheme implementation draw its own focus ring for this widget?
191 : */
192 : virtual bool ThemeDrawsFocusForWidget(uint8_t aWidgetType)=0;
193 :
194 : /**
195 : * Should we insert a dropmarker inside of combobox button?
196 : */
197 : virtual bool ThemeNeedsComboboxDropmarker()=0;
198 :
199 : /**
200 : * Should we hide scrollbars?
201 : */
202 462 : virtual bool ShouldHideScrollbars()
203 462 : { return false; }
204 : };
205 :
206 : NS_DEFINE_STATIC_IID_ACCESSOR(nsITheme, NS_ITHEME_IID)
207 :
208 : // Creator function
209 : extern nsresult NS_NewNativeTheme(nsISupports *aOuter, REFNSIID aIID, void **aResult);
210 :
211 : #endif
|