1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* Copyright 2012 Mozilla Foundation and Mozilla contributors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <QGuiApplication>
22 #include <QStyleFactory>
24 #include "nsLookAndFeel.h"
25 #include "nsStyleConsts.h"
27 #include "gfxFontConstants.h"
28 #include "mozilla/gfx/2D.h"
30 static const char16_t UNICODE_BULLET
= 0x2022;
32 #define QCOLOR_TO_NS_RGB(c) \
33 ((nscolor)NS_RGB(c.red(),c.green(),c.blue()))
35 nsLookAndFeel::nsLookAndFeel()
40 nsLookAndFeel::~nsLookAndFeel()
45 nsLookAndFeel::NativeGetColor(ColorID aID
, nscolor
&aColor
)
49 #define BG_PRELIGHT_COLOR NS_RGB(0xee,0xee,0xee)
50 #define FG_PRELIGHT_COLOR NS_RGB(0x77,0x77,0x77)
51 #define RED_COLOR NS_RGB(0xff,0x00,0x00)
53 QPalette palette
= QGuiApplication::palette();
56 // These colors don't seem to be used for anything anymore in Mozilla
57 // (except here at least TextSelectBackground and TextSelectForeground)
58 // The CSS2 colors below are used.
59 case eColorID_WindowBackground
:
60 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
62 case eColorID_WindowForeground
:
63 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::WindowText
));
65 case eColorID_WidgetBackground
:
66 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
68 case eColorID_WidgetForeground
:
69 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::WindowText
));
71 case eColorID_WidgetSelectBackground
:
72 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
74 case eColorID_WidgetSelectForeground
:
75 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::WindowText
));
77 case eColorID_Widget3DHighlight
:
78 aColor
= NS_RGB(0xa0,0xa0,0xa0);
80 case eColorID_Widget3DShadow
:
81 aColor
= NS_RGB(0x40,0x40,0x40);
83 case eColorID_TextBackground
:
85 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
87 case eColorID_TextForeground
:
89 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::WindowText
));
91 case eColorID_TextSelectBackground
:
92 case eColorID_IMESelectedRawTextBackground
:
93 case eColorID_IMESelectedConvertedTextBackground
:
95 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Highlight
));
97 case eColorID_TextSelectForeground
:
98 case eColorID_IMESelectedRawTextForeground
:
99 case eColorID_IMESelectedConvertedTextForeground
:
101 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::HighlightedText
));
103 case eColorID_IMERawInputBackground
:
104 case eColorID_IMEConvertedTextBackground
:
105 aColor
= NS_TRANSPARENT
;
107 case eColorID_IMERawInputForeground
:
108 case eColorID_IMEConvertedTextForeground
:
109 aColor
= NS_SAME_AS_FOREGROUND_COLOR
;
111 case eColorID_IMERawInputUnderline
:
112 case eColorID_IMEConvertedTextUnderline
:
113 aColor
= NS_SAME_AS_FOREGROUND_COLOR
;
115 case eColorID_IMESelectedRawTextUnderline
:
116 case eColorID_IMESelectedConvertedTextUnderline
:
117 aColor
= NS_TRANSPARENT
;
119 case eColorID_SpellCheckerUnderline
:
123 // css2 http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
124 case eColorID_activeborder
:
125 // active window border
126 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
128 case eColorID_activecaption
:
129 // active window caption background
130 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
132 case eColorID_appworkspace
:
133 // MDI background color
134 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
136 case eColorID_background
:
137 // desktop background
138 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
140 case eColorID_captiontext
:
141 // text in active window caption, size box, and scrollbar arrow box (!)
142 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Text
));
144 case eColorID_graytext
:
145 // disabled text in windows, menus, etc.
146 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Disabled
, QPalette::Text
));
148 case eColorID_highlight
:
149 // background of selected item
150 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Highlight
));
152 case eColorID_highlighttext
:
153 // text of selected item
154 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::HighlightedText
));
156 case eColorID_inactiveborder
:
157 // inactive window border
158 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Disabled
, QPalette::Window
));
160 case eColorID_inactivecaption
:
161 // inactive window caption
162 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Disabled
, QPalette::Window
));
164 case eColorID_inactivecaptiontext
:
165 // text in inactive window caption
166 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Disabled
, QPalette::Text
));
168 case eColorID_infobackground
:
169 // tooltip background color
170 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::ToolTipBase
));
172 case eColorID_infotext
:
173 // tooltip text color
174 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::ToolTipText
));
178 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
180 case eColorID_menutext
:
182 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Text
));
184 case eColorID_scrollbar
:
185 // scrollbar gray area
186 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Mid
));
189 case eColorID_threedface
:
190 case eColorID_buttonface
:
192 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Button
));
195 case eColorID_buttontext
:
196 // text on push buttons
197 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::ButtonText
));
200 case eColorID_buttonhighlight
:
201 // 3-D highlighted edge color
202 case eColorID_threedhighlight
:
203 // 3-D highlighted outer edge color
204 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Dark
));
207 case eColorID_threedlightshadow
:
208 // 3-D highlighted inner edge color
209 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Light
));
212 case eColorID_buttonshadow
:
213 // 3-D shadow edge color
214 case eColorID_threedshadow
:
215 // 3-D shadow inner edge color
216 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Dark
));
219 case eColorID_threeddarkshadow
:
220 // 3-D shadow outer edge color
221 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Shadow
));
224 case eColorID_window
:
225 case eColorID_windowframe
:
226 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
229 case eColorID_windowtext
:
230 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Text
));
233 case eColorID__moz_eventreerow
:
234 case eColorID__moz_field
:
235 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Base
));
237 case eColorID__moz_fieldtext
:
238 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Text
));
240 case eColorID__moz_dialog
:
241 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
243 case eColorID__moz_dialogtext
:
244 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::WindowText
));
246 case eColorID__moz_dragtargetzone
:
247 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Window
));
249 case eColorID__moz_buttondefault
:
250 // default button border color
251 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Button
));
253 case eColorID__moz_buttonhoverface
:
254 aColor
= BG_PRELIGHT_COLOR
;
256 case eColorID__moz_buttonhovertext
:
257 aColor
= FG_PRELIGHT_COLOR
;
259 case eColorID__moz_cellhighlight
:
260 case eColorID__moz_html_cellhighlight
:
261 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Highlight
));
263 case eColorID__moz_cellhighlighttext
:
264 case eColorID__moz_html_cellhighlighttext
:
265 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::HighlightedText
));
267 case eColorID__moz_menuhover
:
268 aColor
= BG_PRELIGHT_COLOR
;
270 case eColorID__moz_menuhovertext
:
271 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Text
));
273 case eColorID__moz_oddtreerow
:
274 aColor
= NS_TRANSPARENT
;
276 case eColorID__moz_nativehyperlinktext
:
277 aColor
= NS_SAME_AS_FOREGROUND_COLOR
;
279 case eColorID__moz_comboboxtext
:
280 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Text
));
282 case eColorID__moz_combobox
:
283 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Base
));
285 case eColorID__moz_menubartext
:
286 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Text
));
288 case eColorID__moz_menubarhovertext
:
289 aColor
= QCOLOR_TO_NS_RGB(palette
.color(QPalette::Normal
, QPalette::Text
));
292 /* default color is BLACK */
294 rv
= NS_ERROR_FAILURE
;
302 nsLookAndFeel::GetIntImpl(IntID aID
, int32_t &aResult
)
304 nsresult rv
= nsXPLookAndFeel::GetIntImpl(aID
, aResult
);
305 if (NS_SUCCEEDED(rv
))
311 case eIntID_CaretBlinkTime
:
315 case eIntID_CaretWidth
:
319 case eIntID_ShowCaretDuringSelection
:
323 case eIntID_SelectTextfieldsOnKeyFocus
:
324 // Select textfield content when focused by kbd
325 // used by EventStateManager::sTextfieldSelectModel
329 case eIntID_SubmenuDelay
:
333 case eIntID_TooltipDelay
:
337 case eIntID_MenusCanOverlapOSBar
:
338 // we want XUL popups to be able to overlap the task bar.
342 case eIntID_ScrollArrowStyle
:
343 aResult
= eScrollArrowStyle_Single
;
346 case eIntID_ScrollSliderStyle
:
347 aResult
= eScrollThumbStyle_Proportional
;
350 case eIntID_TouchEnabled
:
354 case eIntID_WindowsDefaultTheme
:
355 case eIntID_WindowsThemeIdentifier
:
356 case eIntID_OperatingSystemVersionIdentifier
:
358 rv
= NS_ERROR_NOT_IMPLEMENTED
;
361 case eIntID_IMERawInputUnderlineStyle
:
362 case eIntID_IMEConvertedTextUnderlineStyle
:
363 aResult
= NS_STYLE_TEXT_DECORATION_STYLE_SOLID
;
366 case eIntID_IMESelectedRawTextUnderlineStyle
:
367 case eIntID_IMESelectedConvertedTextUnderline
:
368 aResult
= NS_STYLE_TEXT_DECORATION_STYLE_NONE
;
371 case eIntID_SpellCheckerUnderlineStyle
:
372 aResult
= NS_STYLE_TEXT_DECORATION_STYLE_WAVY
;
375 case eIntID_ScrollbarButtonAutoRepeatBehavior
:
381 rv
= NS_ERROR_FAILURE
;
388 nsLookAndFeel::GetFloatImpl(FloatID aID
, float &aResult
)
390 nsresult res
= nsXPLookAndFeel::GetFloatImpl(aID
, aResult
);
391 if (NS_SUCCEEDED(res
))
396 case eFloatID_IMEUnderlineRelativeSize
:
399 case eFloatID_SpellCheckerUnderlineRelativeSize
:
404 res
= NS_ERROR_FAILURE
;
411 nsLookAndFeel::GetFontImpl(FontID aID
, nsString
& aFontName
,
412 gfxFontStyle
& aFontStyle
,
413 float aDevPixPerCSSPixel
)
415 QFont qFont
= QGuiApplication::font();
417 NS_NAMED_LITERAL_STRING(quote
, "\"");
418 nsString
family((char16_t
*)qFont
.family().data());
419 aFontName
= quote
+ family
+ quote
;
421 aFontStyle
.systemFont
= true;
422 aFontStyle
.style
= qFont
.style();
423 aFontStyle
.weight
= qFont
.weight();
424 aFontStyle
.stretch
= qFont
.stretch();
425 // use pixel size directly if it is set, otherwise compute from point size
426 if (qFont
.pixelSize() != -1) {
427 aFontStyle
.size
= qFont
.pixelSize();
429 aFontStyle
.size
= qFont
.pointSizeF() * qApp
->primaryScreen()->logicalDotsPerInch() / 72.0f
;
437 nsLookAndFeel::GetEchoPasswordImpl() {
443 nsLookAndFeel::GetPasswordMaskDelayImpl()
445 // Same value on Android framework
451 nsLookAndFeel::GetPasswordCharacterImpl()
453 return UNICODE_BULLET
;