Skip to content

Commit eb5d159

Browse files
Pascal Abreschpulkomandy
Pascal Abresch
authored andcommitted
Haiku: support rendering dark/light controls
This commit adds support to rendering light controls in a light document even if the OS is in a dark mode This is done by picking the default color from the OS The same is done with dark controls this is based on the color-scheme css property. This commit makes controls use the configured OS colors. Aswell as using the configured OS background color for the :root element In addition this commit also provides default color values for css constants based on the OS Settings This makes light buttons get a dark text per default and dark buttons get a light text by default. This commit also enabled hover interactions for controls. This commit fixes white screens between page loads.
1 parent 98be67f commit eb5d159

File tree

6 files changed

+120
-19
lines changed

6 files changed

+120
-19
lines changed

Source/WTF/wtf/PlatformHave.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@
418418
#define HAVE_FOUNDATION_WITH_SAME_SITE_COOKIE_SUPPORT 1
419419
#endif
420420

421-
#if PLATFORM(MAC) || PLATFORM(IOS) || PLATFORM(MACCATALYST) || PLATFORM(GTK) || PLATFORM(WPE)
421+
#if PLATFORM(MAC) || PLATFORM(IOS) || PLATFORM(MACCATALYST) || PLATFORM(GTK) || PLATFORM(WPE) || PLATFORM(HAIKU)
422422
#define HAVE_OS_DARK_MODE_SUPPORT 1
423423
#endif
424424

Source/WebCore/platform/haiku/RenderThemeHaiku.cpp

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
#include "InputTypeNames.h"
3434
#include "NotImplemented.h"
3535
#include "PaintInfo.h"
36+
#include "RenderBox.h"
3637
#include "RenderElement.h"
3738
#include "UserAgentScripts.h"
3839
#include "UserAgentStyleSheets.h"
3940
#include <ControlLook.h>
4041
#include <View.h>
42+
#include <private/interface/DefaultColors.h>
4143

4244
#include <wtf/text/StringBuilder.h>
4345

@@ -80,7 +82,7 @@ bool RenderThemeHaiku::supportsFocusRing(const RenderStyle& style) const
8082

8183
bool RenderThemeHaiku::paintSliderTrack(const RenderObject& object, const PaintInfo& info, const IntRect& intRect)
8284
{
83-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
85+
rgb_color base = colorForValue(B_CONTROL_BACKGROUND_COLOR, object.useDarkAppearance());
8486
rgb_color background = base;
8587
// TODO: From PaintInfo?
8688
BRect rect = intRect;
@@ -156,7 +158,7 @@ bool RenderThemeHaiku::supportsDataListUI(const AtomString& type) const
156158

157159
bool RenderThemeHaiku::paintSliderThumb(const RenderObject& object, const PaintInfo& info, const IntRect& intRect)
158160
{
159-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
161+
rgb_color base = colorForValue(B_CONTROL_BACKGROUND_COLOR, object.useDarkAppearance());
160162
BRect rect = intRect;
161163
BView* view = info.context().platformContext();
162164
unsigned flags = flagsForObject(object);
@@ -201,7 +203,7 @@ bool RenderThemeHaiku::paintCheckbox(const RenderObject& object, const PaintInfo
201203
if (!be_control_look)
202204
return true;
203205

204-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
206+
rgb_color base = colorForValue(B_CONTROL_BACKGROUND_COLOR, object.useDarkAppearance());
205207
BRect rect = floatRect;
206208
BView* view = info.context().platformContext();
207209
unsigned flags = flagsForObject(object);
@@ -237,7 +239,7 @@ bool RenderThemeHaiku::paintRadio(const RenderObject& object, const PaintInfo& i
237239
if (!be_control_look)
238240
return true;
239241

240-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
242+
rgb_color base = colorForValue(B_CONTROL_BACKGROUND_COLOR, object.useDarkAppearance());
241243
BRect rect = floatRect;
242244
BView* view = info.context().platformContext();
243245
unsigned flags = flagsForObject(object);
@@ -262,7 +264,7 @@ bool RenderThemeHaiku::paintButton(const RenderObject& object, const PaintInfo&
262264
if (!be_control_look)
263265
return true;
264266

265-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
267+
rgb_color base = colorForValue(B_CONTROL_BACKGROUND_COLOR, object.useDarkAppearance());
266268
rgb_color background = base;
267269
// TODO: From PaintInfo?
268270
BRect rect = intRect;
@@ -293,7 +295,7 @@ bool RenderThemeHaiku::paintTextField(const RenderObject& object, const PaintInf
293295
if (!be_control_look)
294296
return true;
295297

296-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
298+
rgb_color base = colorForValue(B_CONTROL_BACKGROUND_COLOR, object.useDarkAppearance());
297299
//rgb_color background = base;
298300
// TODO: From PaintInfo?
299301
BRect rect(intRect);
@@ -321,7 +323,7 @@ void RenderThemeHaiku::adjustMenuListStyle(RenderStyle& style, const Element* el
321323
adjustMenuListButtonStyle(style, element);
322324
}
323325

324-
void RenderThemeHaiku::adjustMenuListButtonStyle(RenderStyle& style, const Element* element) const
326+
void RenderThemeHaiku::adjustMenuListButtonStyle(RenderStyle& style, const Element*) const
325327
{
326328
style.resetBorder();
327329
style.resetBorderRadius();
@@ -352,21 +354,19 @@ void RenderThemeHaiku::paintMenuListButtonDecorations(const RenderBox& object, c
352354
if (!be_control_look)
353355
return;
354356

355-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
357+
rgb_color base = colorForValue(B_CONTROL_BACKGROUND_COLOR, object.firstChild()->useDarkAppearance());
356358
// TODO get the color from PaintInfo?
357359
BRect rect = floatRect;
358360
BView* view = info.context().platformContext();
359-
unsigned flags = BControlLook::B_BLEND_FRAME;
360-
// TODO unfortunately we don't get access to the RenderObject here so
361-
// we can't use flagsForObject(object) & ~BControlLook::B_CLICKED;
362-
361+
unsigned flags = flagsForObject(*object.firstChild()) & ~BControlLook::B_CLICKED;
362+
363363
view->PushState();
364364
be_control_look->DrawMenuFieldFrame(view, rect, rect, base, base, flags);
365365
be_control_look->DrawMenuFieldBackground(view, rect, rect, base, true, flags);
366366
view->PopState();
367367
}
368368

369-
bool RenderThemeHaiku::paintMenuList(const RenderObject& object, const PaintInfo& info, const FloatRect& intRect)
369+
bool RenderThemeHaiku::paintMenuList(const RenderObject&, const PaintInfo&, const FloatRect&)
370370
{
371371
// This is never called: the list is handled natively as a BMenu.
372372
return true;
@@ -383,7 +383,79 @@ unsigned RenderThemeHaiku::flagsForObject(const RenderObject& object) const
383383
flags |= BControlLook::B_CLICKED;
384384
if (isChecked(object))
385385
flags |= BControlLook::B_ACTIVATED;
386+
if (isHovered(object))
387+
flags |= BControlLook::B_HOVER;
386388
return flags;
387389
}
388390

391+
392+
rgb_color RenderThemeHaiku::colorForValue(color_which colorConstant, bool useDarkAppearance) const
393+
{
394+
rgb_color systemColor = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
395+
if (useDarkAppearance) {
396+
if (systemColor.Brightness() > 127) // system is in light mode, but we need a dark color
397+
return BPrivate::GetSystemColor(colorConstant, true);
398+
} else {
399+
if (systemColor.Brightness() < 127) // system is in dark mode but we need a light color
400+
return BPrivate::GetSystemColor(colorConstant, false);
401+
}
402+
return ui_color(colorConstant);
403+
}
404+
405+
406+
Color RenderThemeHaiku::systemColor(CSSValueID cssValueID, OptionSet<StyleColorOptions> options) const
407+
{
408+
const bool useDarkAppearance = options.contains(StyleColorOptions::UseDarkAppearance);
409+
410+
switch (cssValueID) {
411+
case CSSValueButtonface:
412+
return colorForValue(B_CONTROL_BACKGROUND_COLOR, useDarkAppearance);
413+
414+
// Doesn't exist?
415+
//case CSSValueButtonborder:
416+
// return colorForValue(B_CONTROL_BORDER_COLOR, useDarkAppearence);
417+
418+
case CSSValueActivebuttontext:
419+
case CSSValueButtontext:
420+
return colorForValue(B_CONTROL_TEXT_COLOR, useDarkAppearance);
421+
422+
case CSSValueField:
423+
case CSSValueCanvas:
424+
case CSSValueWindow:
425+
return colorForValue(B_DOCUMENT_BACKGROUND_COLOR, useDarkAppearance);
426+
427+
case CSSValueCanvastext:
428+
case CSSValueFieldtext:
429+
return colorForValue(B_DOCUMENT_TEXT_COLOR, useDarkAppearance);
430+
431+
case CSSValueWebkitFocusRingColor:
432+
case CSSValueActiveborder:
433+
case CSSValueHighlight:
434+
return colorForValue(B_CONTROL_HIGHLIGHT_COLOR, useDarkAppearance);
435+
436+
case CSSValueHighlighttext:
437+
return colorForValue(B_CONTROL_TEXT_COLOR, useDarkAppearance);
438+
439+
case CSSValueWebkitLink:
440+
case CSSValueLinktext:
441+
return colorForValue(B_LINK_TEXT_COLOR, useDarkAppearance);
442+
443+
case CSSValueVisitedtext:
444+
return colorForValue(B_LINK_VISITED_COLOR, useDarkAppearance);
445+
446+
// case CSSValueWebkitActivetext:
447+
case CSSValueWebkitActivelink:
448+
return colorForValue(B_LINK_ACTIVE_COLOR, useDarkAppearance);
449+
450+
/* is there any haiku colors that make sense to use here?
451+
case CSSValueSelecteditem:
452+
case CSSValueSelecteditemtext:
453+
case CSSValueMark:
454+
case CSSValueMarkText:
455+
*/
456+
default:
457+
return RenderTheme::systemColor(cssValueID, options);
458+
}
459+
}
460+
389461
} // namespace WebCore

Source/WebCore/platform/haiku/RenderThemeHaiku.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ class RenderThemeHaiku : public RenderTheme {
9191

9292
bool paintSliderThumb(const RenderObject&, const PaintInfo&, const IntRect&) override;
9393

94+
Color systemColor(CSSValueID, OptionSet<StyleColorOptions>) const override;
95+
9496
private:
9597
unsigned flagsForObject(const RenderObject&) const;
98+
rgb_color colorForControl(const RenderObject&) const;
99+
rgb_color colorForValue(color_which, bool useDarkAppearance) const;
100+
96101
};
97102

98103
} // namespace WebCore

Source/WebCore/platform/haiku/ScrollbarThemeHaiku.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030

3131
#include "GraphicsContext.h"
3232
#include "Scrollbar.h"
33+
#include "ScrollableArea.h"
3334
#include <ControlLook.h>
3435
#include <InterfaceDefs.h>
3536
#include <Shape.h>
37+
#include <private/interface/DefaultColors.h>
3638

3739

3840
static int buttonWidth(int scrollbarWidth, int thickness)
@@ -126,15 +128,17 @@ IntRect ScrollbarThemeHaiku::trackRect(Scrollbar& scrollbar, bool)
126128
return IntRect(scrollbar.x(), scrollbar.y() + thickness, thickness, scrollbar.height() - 2 * thickness - 1);
127129
}
128130

129-
void ScrollbarThemeHaiku::paintScrollCorner(ScrollableArea&, GraphicsContext& context, const IntRect& rect)
131+
void ScrollbarThemeHaiku::paintScrollCorner(ScrollableArea& scrollArea, GraphicsContext& context, const IntRect& rect)
130132
{
131133
if (rect.width() == 0 || rect.height() == 0)
132134
return;
133135

134136
BRect drawRect = BRect(rect);
135137
BView* view = context.platformContext();
136138
view->PushState();
137-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
139+
rgb_color base = colorForScrollbar(B_CONTROL_BACKGROUND_COLOR,
140+
scrollArea.useDarkAppearanceForScrollbars());
141+
138142
if (!m_drawOuterFrame) {
139143
view->SetHighColor(tint_color(base, B_DARKEN_2_TINT));
140144
view->StrokeLine(drawRect.LeftBottom(), drawRect.LeftTop());
@@ -153,7 +157,8 @@ void ScrollbarThemeHaiku::paintScrollbarBackground(GraphicsContext& context, Scr
153157
if (!be_control_look)
154158
return;
155159

156-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
160+
rgb_color base = colorForScrollbar(B_CONTROL_BACKGROUND_COLOR,
161+
scrollbar.scrollableArea().useDarkAppearanceForScrollbars());
157162
BRect rect = trackRect(scrollbar, false);
158163
BView* view = context.platformContext();
159164
view->SetHighColor(tint_color(base, B_DARKEN_2_TINT));
@@ -196,7 +201,8 @@ void ScrollbarThemeHaiku::paintButton(GraphicsContext& context, Scrollbar& scrol
196201
BView* view = context.platformContext();
197202
bool down = scrollbar.pressedPart() == part;
198203

199-
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
204+
rgb_color base = colorForScrollbar(B_CONTROL_BACKGROUND_COLOR,
205+
scrollbar.scrollableArea().useDarkAppearanceForScrollbars());
200206
rgb_color dark2 = tint_color(base, B_DARKEN_2_TINT);
201207

202208
enum orientation orientation;
@@ -236,7 +242,8 @@ void ScrollbarThemeHaiku::paintThumb(GraphicsContext& context, Scrollbar& scroll
236242

237243
BRect drawRect = BRect(rect);
238244
BView* view = context.platformContext();
239-
rgb_color base = ui_color(B_SCROLL_BAR_THUMB_COLOR);
245+
rgb_color base = colorForScrollbar(B_SCROLL_BAR_THUMB_COLOR,
246+
scrollbar.scrollableArea().useDarkAppearanceForScrollbars());
240247
rgb_color dark2 = tint_color(base, B_DARKEN_2_TINT);
241248
rgb_color dark3 = tint_color(base, B_DARKEN_3_TINT);
242249

@@ -274,6 +281,18 @@ void ScrollbarThemeHaiku::paintThumb(GraphicsContext& context, Scrollbar& scroll
274281
view->PopState();
275282
}
276283

284+
rgb_color ScrollbarThemeHaiku::colorForScrollbar(color_which controlColor, bool darkMode) const
285+
{
286+
rgb_color systemColor = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
287+
if (darkMode) {
288+
if (systemColor.Brightness() > 127) // system is in light mode, but we need dark
289+
return BPrivate::GetSystemColor(controlColor, true);
290+
} else {
291+
if (systemColor.Brightness() < 127) // system is in dark mode but we need light
292+
return BPrivate::GetSystemColor(controlColor, false);
293+
}
294+
return ui_color(controlColor);
295+
}
277296

278297
} // namespace WebCore
279298

Source/WebCore/platform/haiku/ScrollbarThemeHaiku.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class ScrollbarThemeHaiku : public ScrollbarThemeComposite {
5555

5656
private:
5757
bool m_drawOuterFrame;
58+
rgb_color colorForScrollbar(color_which base, const bool darkMode) const;
5859
};
5960

6061
}

Source/WebKitLegacy/haiku/API/WebView.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ BWebView::BWebView(const char* name, BPrivate::Network::BUrlContext* urlContext)
9494
rgb_color background = ui_color(B_DOCUMENT_BACKGROUND_COLOR);
9595
if (background.Brightness() < 127)
9696
fWebPage->page()->effectiveAppearanceDidChange(true, false);
97+
98+
// doesn't seem to affect the "background" for css, but it does fix the glaring
99+
// white screen between page loads (or when no page is open)
100+
fWebPage->page()->mainFrame().view()->setBaseBackgroundColor(background);
97101
}
98102

99103
BWebView::~BWebView()

0 commit comments

Comments
 (0)