2020-02-10 19:26:01 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2022-01-12 16:33:31 +00:00
|
|
|
#ifndef mozilla_widget_Theme_h
|
|
|
|
#define mozilla_widget_Theme_h
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2020-07-31 12:04:29 +00:00
|
|
|
#include "Units.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/Rect.h"
|
|
|
|
#include "mozilla/gfx/Types.h"
|
2020-02-10 19:26:01 +00:00
|
|
|
#include "nsITheme.h"
|
|
|
|
#include "nsNativeTheme.h"
|
2021-11-15 12:39:38 +00:00
|
|
|
#include "ScrollbarDrawing.h"
|
2020-07-30 17:02:02 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2021-03-12 14:44:13 +00:00
|
|
|
|
|
|
|
enum class StyleSystemColor : uint8_t;
|
|
|
|
|
2022-01-12 16:33:31 +00:00
|
|
|
namespace widget {
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2022-01-12 16:33:31 +00:00
|
|
|
class Theme : protected nsNativeTheme, public nsITheme {
|
2020-10-05 21:15:18 +00:00
|
|
|
protected:
|
2022-01-12 16:33:31 +00:00
|
|
|
using sRGBColor = gfx::sRGBColor;
|
|
|
|
using DrawTarget = gfx::DrawTarget;
|
|
|
|
using Path = gfx::Path;
|
|
|
|
using Rect = gfx::Rect;
|
|
|
|
using Point = gfx::Point;
|
|
|
|
using RectCornerRadii = gfx::RectCornerRadii;
|
|
|
|
using Colors = ThemeColors;
|
|
|
|
using AccentColor = ThemeAccentColor;
|
2022-06-07 23:09:52 +00:00
|
|
|
using ElementState = dom::ElementState;
|
2020-07-31 12:04:29 +00:00
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
public:
|
2022-01-12 16:33:31 +00:00
|
|
|
explicit Theme(UniquePtr<ScrollbarDrawing>&& aScrollbarDrawing)
|
2021-11-15 12:39:39 +00:00
|
|
|
: mScrollbarDrawing(std::move(aScrollbarDrawing)) {
|
|
|
|
mScrollbarDrawing->RecomputeScrollbarParams();
|
|
|
|
}
|
2021-11-15 12:39:38 +00:00
|
|
|
|
2021-02-10 00:47:38 +00:00
|
|
|
static void Init();
|
|
|
|
static void Shutdown();
|
|
|
|
static void LookAndFeelChanged();
|
|
|
|
|
2022-01-12 16:33:31 +00:00
|
|
|
using DPIRatio = CSSToLayoutDeviceScale;
|
2020-11-30 04:48:07 +00:00
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
// The nsITheme interface.
|
2021-02-22 16:18:33 +00:00
|
|
|
NS_IMETHOD DrawWidgetBackground(gfxContext* aContext, nsIFrame*,
|
|
|
|
StyleAppearance, const nsRect& aRect,
|
2021-03-20 23:08:11 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
DrawOverflow) override;
|
2021-02-23 10:49:37 +00:00
|
|
|
|
|
|
|
bool CreateWebRenderCommandsForWidget(
|
2022-01-12 16:33:31 +00:00
|
|
|
wr::DisplayListBuilder& aBuilder, wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const layers::StackingContextHelper& aSc,
|
|
|
|
layers::RenderRootStateManager* aManager, nsIFrame*, StyleAppearance,
|
|
|
|
const nsRect& aRect) override;
|
2021-02-23 10:49:37 +00:00
|
|
|
|
|
|
|
// PaintBackendData will be either a DrawTarget, or a WebRenderBackendData.
|
|
|
|
//
|
|
|
|
// The return value represents whether the widget could be painted with the
|
|
|
|
// given back-end.
|
|
|
|
template <typename PaintBackendData>
|
|
|
|
bool DoDrawWidgetBackground(PaintBackendData&, nsIFrame*, StyleAppearance,
|
2021-03-20 23:08:11 +00:00
|
|
|
const nsRect&, DrawOverflow);
|
2021-02-23 10:49:37 +00:00
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
[[nodiscard]] LayoutDeviceIntMargin GetWidgetBorder(nsDeviceContext* aContext,
|
|
|
|
nsIFrame*,
|
|
|
|
StyleAppearance) override;
|
|
|
|
bool GetWidgetPadding(nsDeviceContext* aContext, nsIFrame*, StyleAppearance,
|
2020-12-02 23:11:32 +00:00
|
|
|
LayoutDeviceIntMargin* aResult) override;
|
2021-02-22 16:18:33 +00:00
|
|
|
bool GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame*, StyleAppearance,
|
2020-07-30 17:02:02 +00:00
|
|
|
nsRect* aOverflowRect) override;
|
Bug 1793689 - Make GetMinimumWidgetSize work properly on non-XUL flexbox. r=TYLin,layout-reviewers
The XUL behavior in nsBox.cpp is fairly different to what the non-XUL
layout code paths do. In particular, canOverride=false means that the
min-{width,height} properties cannot go under the min widget size of the
widget, but that doesn't mean that intrinsic sizes don't affect the
final size of the widget.
This is very visible if you turn on flex emulation on Windows or macOS,
where the toolbar has an appearance that returns
width=0,height=N,canOverride=false.
With flex emulation we'd collapse the item to be zero-width, which is
not good at all.
The good thing is that this is no longer exposed to the web
(non-native-theme always returns canOverride=true), and our front-end
code doesn't seem to rely on this, so we can just remove support for
canOverride=false.
Differential Revision: https://phabricator.services.mozilla.com/D158608
2022-10-05 19:09:29 +00:00
|
|
|
LayoutDeviceIntSize GetMinimumWidgetSize(nsPresContext*, nsIFrame*,
|
|
|
|
StyleAppearance) override;
|
2021-02-22 16:18:33 +00:00
|
|
|
Transparency GetWidgetTransparency(nsIFrame*, StyleAppearance) override;
|
2024-09-16 22:02:05 +00:00
|
|
|
bool WidgetAttributeChangeRequiresRepaint(StyleAppearance,
|
|
|
|
nsAtom* aAttribute) override;
|
2020-02-10 19:26:01 +00:00
|
|
|
NS_IMETHOD ThemeChanged() override;
|
2021-02-22 16:18:33 +00:00
|
|
|
bool WidgetAppearanceDependsOnWindowFocus(StyleAppearance) override;
|
2020-07-30 17:02:02 +00:00
|
|
|
/*bool NeedToClearBackgroundBehindWidget(
|
2021-02-22 16:18:33 +00:00
|
|
|
nsIFrame*, StyleAppearance) override;*/
|
|
|
|
ThemeGeometryType ThemeGeometryTypeForWidget(nsIFrame*,
|
|
|
|
StyleAppearance) override;
|
2021-03-09 00:05:51 +00:00
|
|
|
bool ThemeSupportsWidget(nsPresContext*, nsIFrame*, StyleAppearance) override;
|
2021-02-22 16:18:33 +00:00
|
|
|
bool WidgetIsContainer(StyleAppearance) override;
|
2021-11-17 00:55:26 +00:00
|
|
|
bool ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) override;
|
2020-02-10 19:26:01 +00:00
|
|
|
bool ThemeNeedsComboboxDropmarker() override;
|
2023-01-28 21:35:51 +00:00
|
|
|
|
|
|
|
LayoutDeviceIntCoord GetScrollbarSize(const nsPresContext*,
|
|
|
|
StyleScrollbarWidth, Overlay) final;
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2024-09-19 09:56:50 +00:00
|
|
|
CSSCoord GetCheckboxRadioPrefSize() override;
|
2021-02-20 00:13:10 +00:00
|
|
|
|
2022-01-12 16:33:31 +00:00
|
|
|
static UniquePtr<ScrollbarDrawing> ScrollbarStyle();
|
2021-11-15 12:39:39 +00:00
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
protected:
|
2022-01-12 16:33:31 +00:00
|
|
|
virtual ~Theme() = default;
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2023-01-28 21:35:51 +00:00
|
|
|
DPIRatio GetDPIRatio(nsIFrame*, StyleAppearance);
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2022-09-14 23:14:30 +00:00
|
|
|
std::tuple<sRGBColor, sRGBColor, sRGBColor> ComputeCheckboxColors(
|
|
|
|
const ElementState&, StyleAppearance, const Colors&);
|
2021-10-08 10:59:02 +00:00
|
|
|
enum class OutlineCoversBorder : bool { No, Yes };
|
2022-06-07 23:09:52 +00:00
|
|
|
sRGBColor ComputeBorderColor(const ElementState&, const Colors&,
|
2021-10-08 10:59:02 +00:00
|
|
|
OutlineCoversBorder);
|
2021-03-12 14:44:13 +00:00
|
|
|
|
2022-06-07 23:09:52 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor> ComputeButtonColors(const ElementState&,
|
2021-10-05 09:40:00 +00:00
|
|
|
const Colors&,
|
2021-03-12 14:44:13 +00:00
|
|
|
nsIFrame* = nullptr);
|
2022-06-07 23:09:52 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor> ComputeTextfieldColors(const ElementState&,
|
2021-10-08 10:59:02 +00:00
|
|
|
const Colors&,
|
|
|
|
OutlineCoversBorder);
|
2022-06-07 23:09:52 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor> ComputeRangeProgressColors(
|
|
|
|
const ElementState&, const Colors&);
|
|
|
|
std::pair<sRGBColor, sRGBColor> ComputeRangeTrackColors(const ElementState&,
|
2021-10-05 09:40:00 +00:00
|
|
|
const Colors&);
|
2022-06-07 23:09:52 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor> ComputeRangeThumbColors(const ElementState&,
|
2021-10-05 09:40:00 +00:00
|
|
|
const Colors&);
|
|
|
|
std::pair<sRGBColor, sRGBColor> ComputeProgressColors(const Colors&);
|
|
|
|
std::pair<sRGBColor, sRGBColor> ComputeProgressTrackColors(const Colors&);
|
2021-03-12 14:44:13 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor> ComputeMeterchunkColors(
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState& aMeterState, const Colors&);
|
2021-10-05 09:40:00 +00:00
|
|
|
std::array<sRGBColor, 3> ComputeFocusRectColors(const Colors&);
|
2021-03-12 14:44:13 +00:00
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintRoundedFocusRect(PaintBackendData&, const LayoutDeviceRect&,
|
2021-10-05 09:40:00 +00:00
|
|
|
const Colors&, DPIRatio, CSSCoord aRadius,
|
|
|
|
CSSCoord aOffset);
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintAutoStyleOutline(nsIFrame*, PaintBackendData&,
|
2021-10-05 09:40:00 +00:00
|
|
|
const LayoutDeviceRect&, const Colors&, DPIRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
void PaintCheckboxControl(DrawTarget& aDrawTarget, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, const Colors&, DPIRatio);
|
2022-09-14 23:14:30 +00:00
|
|
|
void PaintCheckMark(DrawTarget&, const LayoutDeviceRect&, const sRGBColor&);
|
2021-02-22 16:18:33 +00:00
|
|
|
void PaintIndeterminateMark(DrawTarget&, const LayoutDeviceRect&,
|
2022-09-14 23:14:30 +00:00
|
|
|
const sRGBColor&);
|
2021-02-23 23:22:19 +00:00
|
|
|
|
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintStrokedCircle(PaintBackendData&, const LayoutDeviceRect&,
|
|
|
|
const sRGBColor& aBackgroundColor,
|
|
|
|
const sRGBColor& aBorderColor,
|
|
|
|
const CSSCoord aBorderWidth, DPIRatio);
|
|
|
|
void PaintCircleShadow(DrawTarget&, const LayoutDeviceRect& aBoxRect,
|
|
|
|
const LayoutDeviceRect& aClipRect, float aShadowAlpha,
|
|
|
|
const CSSPoint& aShadowOffset,
|
|
|
|
CSSCoord aShadowBlurStdDev, DPIRatio);
|
|
|
|
void PaintCircleShadow(WebRenderBackendData&,
|
|
|
|
const LayoutDeviceRect& aBoxRect,
|
|
|
|
const LayoutDeviceRect& aClipRect, float aShadowAlpha,
|
|
|
|
const CSSPoint& aShadowOffset,
|
|
|
|
CSSCoord aShadowBlurStdDev, DPIRatio);
|
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintRadioControl(PaintBackendData&, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, const Colors&, DPIRatio);
|
2021-02-23 23:22:19 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintRadioCheckmark(PaintBackendData&, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, DPIRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintTextField(PaintBackendData&, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, const Colors&, DPIRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintListbox(PaintBackendData&, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, const Colors&, DPIRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintMenulist(PaintBackendData&, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, const Colors&, DPIRatio);
|
2023-10-11 19:37:40 +00:00
|
|
|
void PaintMenulistArrow(nsIFrame*, DrawTarget&, const LayoutDeviceRect&);
|
2021-02-22 16:18:33 +00:00
|
|
|
void PaintSpinnerButton(nsIFrame*, DrawTarget&, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, StyleAppearance, const Colors&,
|
2021-03-12 14:44:13 +00:00
|
|
|
DPIRatio);
|
2021-02-23 23:22:19 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintRange(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, const Colors&, DPIRatio,
|
2021-10-05 09:40:00 +00:00
|
|
|
bool aHorizontal);
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintProgress(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
|
2022-06-07 23:09:52 +00:00
|
|
|
const ElementState&, const Colors&, DPIRatio,
|
2021-10-05 09:40:00 +00:00
|
|
|
bool aIsMeter);
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void PaintButton(nsIFrame*, PaintBackendData&, const LayoutDeviceRect&,
|
2023-12-06 08:33:33 +00:00
|
|
|
StyleAppearance, const ElementState&, const Colors&,
|
|
|
|
DPIRatio);
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2021-11-15 12:39:39 +00:00
|
|
|
static void PrefChangedCallback(const char*, void*) {
|
|
|
|
LookAndFeel::NotifyChangedAllWindows(ThemeChangeKind::Layout);
|
|
|
|
}
|
2021-11-15 11:46:20 +00:00
|
|
|
|
2022-01-12 16:33:31 +00:00
|
|
|
void SetScrollbarDrawing(UniquePtr<ScrollbarDrawing>&& aScrollbarDrawing) {
|
2021-11-15 12:39:39 +00:00
|
|
|
mScrollbarDrawing = std::move(aScrollbarDrawing);
|
2022-01-25 21:31:43 +00:00
|
|
|
mScrollbarDrawing->RecomputeScrollbarParams();
|
2021-11-15 12:39:39 +00:00
|
|
|
}
|
2021-11-15 12:39:38 +00:00
|
|
|
ScrollbarDrawing& GetScrollbarDrawing() const { return *mScrollbarDrawing; }
|
2022-01-12 16:33:31 +00:00
|
|
|
UniquePtr<ScrollbarDrawing> mScrollbarDrawing;
|
2021-11-15 11:46:20 +00:00
|
|
|
|
2021-11-15 12:39:38 +00:00
|
|
|
bool ThemeSupportsScrollbarButtons() override;
|
2020-02-10 19:26:01 +00:00
|
|
|
};
|
|
|
|
|
2022-01-12 16:33:31 +00:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
#endif
|