2020-02-10 22:26:01 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 40; 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 19:33:31 +03:00
|
|
|
#include "Theme.h"
|
|
|
|
#include "ThemeCocoa.h"
|
2020-02-10 22:26:01 +03:00
|
|
|
|
2021-01-26 04:35:04 +03:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2021-11-15 15:39:38 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2021-11-15 15:39:38 +03:00
|
|
|
#include "mozilla/dom/HTMLMeterElement.h"
|
|
|
|
#include "mozilla/dom/HTMLProgressElement.h"
|
2020-11-02 20:09:05 +03:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
|
|
|
#include "mozilla/gfx/Types.h"
|
|
|
|
#include "mozilla/gfx/Filters.h"
|
2021-02-04 19:15:27 +03:00
|
|
|
#include "mozilla/RelativeLuminanceUtils.h"
|
2021-02-10 03:47:38 +03:00
|
|
|
#include "mozilla/StaticPrefs_widget.h"
|
2021-02-23 13:49:37 +03:00
|
|
|
#include "mozilla/webrender/WebRenderAPI.h"
|
2020-10-15 07:54:41 +03:00
|
|
|
#include "nsCSSColorUtils.h"
|
2020-02-10 22:26:01 +03:00
|
|
|
#include "nsCSSRendering.h"
|
2022-05-13 02:21:05 +03:00
|
|
|
#include "nsScrollbarFrame.h"
|
|
|
|
#include "nsIScrollbarMediator.h"
|
2021-11-15 14:46:20 +03:00
|
|
|
#include "nsDeviceContext.h"
|
2021-11-15 15:39:38 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2021-11-15 14:46:20 +03:00
|
|
|
#include "nsRangeFrame.h"
|
2021-11-15 15:39:38 +03:00
|
|
|
#include "PathHelpers.h"
|
|
|
|
#include "ScrollbarDrawingAndroid.h"
|
|
|
|
#include "ScrollbarDrawingCocoa.h"
|
|
|
|
#include "ScrollbarDrawingGTK.h"
|
|
|
|
#include "ScrollbarDrawingWin.h"
|
2021-12-16 00:06:58 +03:00
|
|
|
#include "ScrollbarDrawingWin11.h"
|
2021-02-10 03:47:38 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
# include "mozilla/WindowsVersion.h"
|
|
|
|
#endif
|
|
|
|
|
2020-07-31 15:04:29 +03:00
|
|
|
using namespace mozilla;
|
2021-11-15 15:39:38 +03:00
|
|
|
using namespace mozilla::dom;
|
2021-11-15 14:46:20 +03:00
|
|
|
using namespace mozilla::gfx;
|
2021-11-15 15:39:38 +03:00
|
|
|
using namespace mozilla::widget;
|
2020-02-10 22:26:01 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
namespace {
|
2022-01-12 19:33:30 +03:00
|
|
|
|
|
|
|
static constexpr gfx::sRGBColor sColorGrey10(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xffe9e9ed));
|
|
|
|
static constexpr gfx::sRGBColor sColorGrey10Alpha50(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0x7fe9e9ed));
|
|
|
|
static constexpr gfx::sRGBColor sColorGrey20(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xffd0d0d7));
|
|
|
|
static constexpr gfx::sRGBColor sColorGrey30(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xffb1b1b9));
|
|
|
|
static constexpr gfx::sRGBColor sColorGrey40(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xff8f8f9d));
|
|
|
|
static constexpr gfx::sRGBColor sColorGrey40Alpha50(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0x7f8f8f9d));
|
|
|
|
static constexpr gfx::sRGBColor sColorGrey50(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xff676774));
|
|
|
|
static constexpr gfx::sRGBColor sColorGrey60(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xff484851));
|
|
|
|
|
|
|
|
static constexpr gfx::sRGBColor sColorMeterGreen10(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xff00ab60));
|
|
|
|
static constexpr gfx::sRGBColor sColorMeterGreen20(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xff056139));
|
|
|
|
static constexpr gfx::sRGBColor sColorMeterYellow10(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xffffbd4f));
|
|
|
|
static constexpr gfx::sRGBColor sColorMeterYellow20(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xffd2811e));
|
|
|
|
static constexpr gfx::sRGBColor sColorMeterRed10(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xffe22850));
|
|
|
|
static constexpr gfx::sRGBColor sColorMeterRed20(
|
|
|
|
gfx::sRGBColor::UnusualFromARGB(0xff810220));
|
|
|
|
|
|
|
|
static const CSSCoord kMinimumRangeThumbSize = 20.0f;
|
|
|
|
static const CSSCoord kMinimumDropdownArrowButtonWidth = 18.0f;
|
|
|
|
static const CSSCoord kMinimumSpinnerButtonWidth = 18.0f;
|
|
|
|
static const CSSCoord kMinimumSpinnerButtonHeight = 9.0f;
|
|
|
|
static const CSSCoord kButtonBorderWidth = 1.0f;
|
|
|
|
static const CSSCoord kMenulistBorderWidth = 1.0f;
|
|
|
|
static const CSSCoord kTextFieldBorderWidth = 1.0f;
|
|
|
|
static const CSSCoord kRangeHeight = 6.0f;
|
|
|
|
static const CSSCoord kProgressbarHeight = 6.0f;
|
|
|
|
static const CSSCoord kMeterHeight = 12.0f;
|
|
|
|
|
|
|
|
// nsCheckboxRadioFrame takes the bottom of the content box as the baseline.
|
|
|
|
// This border-width makes its baseline 2px under the bottom, which is nice.
|
|
|
|
static constexpr CSSCoord kCheckboxRadioBorderWidth = 2.0f;
|
|
|
|
|
2021-03-05 04:35:17 +03:00
|
|
|
static constexpr sRGBColor sTransparent = sRGBColor::White(0.0);
|
|
|
|
|
2021-01-23 22:31:33 +03:00
|
|
|
// This pushes and pops a clip rect to the draw target.
|
|
|
|
//
|
|
|
|
// This is done to reduce fuzz in places where we may have antialiasing,
|
|
|
|
// because skia is not clip-invariant: given different clips, it does not
|
|
|
|
// guarantee the same result, even if the painted content doesn't intersect
|
|
|
|
// the clips.
|
|
|
|
//
|
|
|
|
// This is a bit sad, overall, but...
|
|
|
|
struct MOZ_RAII AutoClipRect {
|
|
|
|
AutoClipRect(DrawTarget& aDt, const LayoutDeviceRect& aRect) : mDt(aDt) {
|
|
|
|
mDt.PushClipRect(aRect.ToUnknownRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoClipRect() { mDt.PopClip(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
DrawTarget& mDt;
|
|
|
|
};
|
|
|
|
|
2022-01-26 00:31:43 +03:00
|
|
|
static StaticRefPtr<Theme> gNativeInstance;
|
|
|
|
static StaticRefPtr<Theme> gNonNativeInstance;
|
|
|
|
static StaticRefPtr<Theme> gRDMInstance;
|
2021-11-15 15:39:39 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
} // namespace
|
|
|
|
|
2022-01-26 00:31:43 +03:00
|
|
|
#ifdef ANDROID
|
|
|
|
already_AddRefed<Theme> do_CreateNativeThemeDoNotUseDirectly() {
|
|
|
|
// Android doesn't have a native theme.
|
|
|
|
return do_AddRef(new Theme(Theme::ScrollbarStyle()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-11-15 15:39:39 +03:00
|
|
|
already_AddRefed<nsITheme> do_GetBasicNativeThemeDoNotUseDirectly() {
|
2022-01-26 00:31:43 +03:00
|
|
|
if (MOZ_UNLIKELY(!gNonNativeInstance)) {
|
2022-01-12 19:33:31 +03:00
|
|
|
UniquePtr<ScrollbarDrawing> scrollbarDrawing = Theme::ScrollbarStyle();
|
2021-11-15 15:39:39 +03:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2022-01-26 00:31:43 +03:00
|
|
|
gNonNativeInstance = new ThemeCocoa(std::move(scrollbarDrawing));
|
2021-11-15 15:39:39 +03:00
|
|
|
#else
|
2022-01-26 00:31:43 +03:00
|
|
|
gNonNativeInstance = new Theme(std::move(scrollbarDrawing));
|
2021-11-15 15:39:39 +03:00
|
|
|
#endif
|
2022-01-26 00:31:43 +03:00
|
|
|
ClearOnShutdown(&gNonNativeInstance);
|
2021-11-15 15:39:39 +03:00
|
|
|
}
|
2022-01-26 00:31:43 +03:00
|
|
|
return do_AddRef(gNonNativeInstance);
|
2021-11-15 15:39:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsITheme> do_GetNativeThemeDoNotUseDirectly() {
|
2022-01-26 00:31:43 +03:00
|
|
|
if (MOZ_UNLIKELY(!gNativeInstance)) {
|
|
|
|
gNativeInstance = do_CreateNativeThemeDoNotUseDirectly();
|
|
|
|
ClearOnShutdown(&gNativeInstance);
|
|
|
|
}
|
|
|
|
return do_AddRef(gNativeInstance);
|
2021-11-15 15:39:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsITheme> do_GetRDMThemeDoNotUseDirectly() {
|
|
|
|
if (MOZ_UNLIKELY(!gRDMInstance)) {
|
2022-01-12 19:33:31 +03:00
|
|
|
gRDMInstance = new Theme(MakeUnique<ScrollbarDrawingAndroid>());
|
2021-11-15 15:39:39 +03:00
|
|
|
ClearOnShutdown(&gRDMInstance);
|
|
|
|
}
|
|
|
|
return do_AddRef(gRDMInstance);
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
namespace mozilla::widget {
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(Theme, nsNativeTheme, nsITheme)
|
|
|
|
|
2021-03-18 22:12:49 +03:00
|
|
|
static constexpr nsLiteralCString kPrefs[] = {
|
|
|
|
"widget.non-native-theme.use-theme-accent"_ns,
|
|
|
|
"widget.non-native-theme.win.scrollbar.use-system-size"_ns,
|
2021-11-15 15:39:39 +03:00
|
|
|
"widget.non-native-theme.scrollbar.size.override"_ns,
|
|
|
|
"widget.non-native-theme.scrollbar.style"_ns,
|
2021-03-18 22:12:49 +03:00
|
|
|
};
|
2021-02-10 03:47:38 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::Init() {
|
2021-03-18 22:12:49 +03:00
|
|
|
for (const auto& pref : kPrefs) {
|
|
|
|
Preferences::RegisterCallback(PrefChangedCallback, pref);
|
|
|
|
}
|
|
|
|
LookAndFeelChanged();
|
2021-02-10 03:47:38 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::Shutdown() {
|
2021-03-18 22:12:49 +03:00
|
|
|
for (const auto& pref : kPrefs) {
|
|
|
|
Preferences::UnregisterCallback(PrefChangedCallback, pref);
|
|
|
|
}
|
2021-02-10 03:47:38 +03:00
|
|
|
}
|
|
|
|
|
2021-11-15 15:39:39 +03:00
|
|
|
/* static */
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::LookAndFeelChanged() {
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeColors::RecomputeAccentColors();
|
2022-01-26 00:31:43 +03:00
|
|
|
if (gNonNativeInstance) {
|
2022-01-26 00:31:44 +03:00
|
|
|
gNonNativeInstance->SetScrollbarDrawing(ScrollbarStyle());
|
|
|
|
}
|
|
|
|
if (gNativeInstance) {
|
|
|
|
gNativeInstance->SetScrollbarDrawing(ScrollbarStyle());
|
2021-11-15 15:39:39 +03:00
|
|
|
}
|
2021-01-29 01:11:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2022-01-12 19:33:31 +03:00
|
|
|
auto Theme::GetDPIRatio(nsPresContext* aPc, StyleAppearance aAppearance)
|
|
|
|
-> DPIRatio {
|
2021-01-27 00:34:35 +03:00
|
|
|
// Widgets react to zoom, except scrollbars.
|
2021-01-29 01:11:54 +03:00
|
|
|
if (IsWidgetScrollbarPart(aAppearance)) {
|
2021-11-15 15:39:38 +03:00
|
|
|
return ScrollbarDrawing::GetDPIRatioForScrollbarPart(aPc);
|
2021-01-29 01:11:54 +03:00
|
|
|
}
|
|
|
|
return DPIRatio(float(AppUnitsPerCSSPixel()) / aPc->AppUnitsPerDevPixel());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
2022-01-12 19:33:31 +03:00
|
|
|
auto Theme::GetDPIRatio(nsIFrame* aFrame, StyleAppearance aAppearance)
|
|
|
|
-> DPIRatio {
|
2021-01-29 01:11:54 +03:00
|
|
|
return GetDPIRatio(aFrame->PresContext(), aAppearance);
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:25:49 +03:00
|
|
|
// Checkbox and radio need to preserve aspect-ratio for compat. We also snap the
|
|
|
|
// size to exact device pixels to avoid snapping disorting the circles.
|
|
|
|
static LayoutDeviceRect CheckBoxRadioRect(const LayoutDeviceRect& aRect) {
|
|
|
|
// Place a square rect in the center of aRect.
|
|
|
|
auto size = std::trunc(std::min(aRect.width, aRect.height));
|
|
|
|
auto position = aRect.Center() - LayoutDevicePoint(size * 0.5, size * 0.5);
|
|
|
|
return LayoutDeviceRect(position, LayoutDeviceSize(size, size));
|
2020-02-16 19:04:31 +03:00
|
|
|
}
|
|
|
|
|
2022-09-15 02:14:30 +03:00
|
|
|
std::tuple<sRGBColor, sRGBColor, sRGBColor> Theme::ComputeCheckboxColors(
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, StyleAppearance aAppearance,
|
2021-10-11 16:52:27 +03:00
|
|
|
const Colors& aColors) {
|
|
|
|
MOZ_ASSERT(aAppearance == StyleAppearance::Checkbox ||
|
|
|
|
aAppearance == StyleAppearance::Radio);
|
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
bool isDisabled = aState.HasState(ElementState::DISABLED);
|
|
|
|
bool isChecked = aState.HasState(ElementState::CHECKED);
|
2021-10-11 16:52:27 +03:00
|
|
|
bool isIndeterminate = aAppearance == StyleAppearance::Checkbox &&
|
2022-06-08 02:09:52 +03:00
|
|
|
aState.HasState(ElementState::INDETERMINATE);
|
2021-10-11 15:45:01 +03:00
|
|
|
|
2021-10-11 16:52:27 +03:00
|
|
|
if (isChecked || isIndeterminate) {
|
2021-10-11 15:45:01 +03:00
|
|
|
if (isDisabled) {
|
2022-09-15 02:14:30 +03:00
|
|
|
auto bg = ComputeBorderColor(aState, aColors, OutlineCoversBorder::No);
|
|
|
|
auto fg = aColors.HighContrast()
|
|
|
|
? aColors.System(StyleSystemColor::Graytext)
|
|
|
|
: sRGBColor::White(.8f);
|
|
|
|
return std::make_tuple(bg, bg, fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
auto bg = aColors.System(StyleSystemColor::Selecteditem);
|
|
|
|
auto fg = aColors.System(StyleSystemColor::Selecteditemtext);
|
|
|
|
return std::make_tuple(bg, bg, fg);
|
2021-10-11 15:45:01 +03:00
|
|
|
}
|
2020-11-17 23:53:01 +03:00
|
|
|
|
2021-10-05 17:40:52 +03:00
|
|
|
bool isActive =
|
2022-06-08 02:09:52 +03:00
|
|
|
aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
|
|
|
|
bool isHovered = aState.HasState(ElementState::HOVER);
|
2022-09-15 02:14:30 +03:00
|
|
|
const auto& bg = isActive ? aColors.Accent().GetDarker()
|
|
|
|
: isHovered ? aColors.Accent().GetDark()
|
|
|
|
: aColors.Accent().Get();
|
|
|
|
const auto& fg = aColors.Accent().GetForeground();
|
|
|
|
return std::make_tuple(bg, bg, fg);
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
|
2022-09-15 02:14:30 +03:00
|
|
|
auto [bg, border] =
|
|
|
|
ComputeTextfieldColors(aState, aColors, OutlineCoversBorder::No);
|
|
|
|
// We don't paint a checkmark in this case so any color would do.
|
|
|
|
return std::make_tuple(bg, border, sTransparent);
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
sRGBColor Theme::ComputeBorderColor(const ElementState& aState,
|
2022-01-12 19:33:31 +03:00
|
|
|
const Colors& aColors,
|
|
|
|
OutlineCoversBorder aOutlineCoversBorder) {
|
2022-06-08 02:09:52 +03:00
|
|
|
bool isDisabled = aState.HasState(ElementState::DISABLED);
|
2021-10-05 17:40:52 +03:00
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return aColors.System(isDisabled ? StyleSystemColor::Graytext
|
|
|
|
: StyleSystemColor::Buttontext);
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
2020-11-17 23:53:01 +03:00
|
|
|
bool isActive =
|
2022-06-08 02:09:52 +03:00
|
|
|
aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
|
|
|
|
bool isHovered = aState.HasState(ElementState::HOVER);
|
|
|
|
bool isFocused = aState.HasState(ElementState::FOCUSRING);
|
2020-11-17 23:53:01 +03:00
|
|
|
if (isDisabled) {
|
|
|
|
return sColorGrey40Alpha50;
|
|
|
|
}
|
2021-10-08 13:59:02 +03:00
|
|
|
if (isFocused && aOutlineCoversBorder == OutlineCoversBorder::Yes) {
|
|
|
|
// If we draw the outline over the border, prevent issues where the border
|
|
|
|
// shows underneath if it snaps in the wrong direction by using a
|
|
|
|
// transparent border. An alternative to this is ensuring that we snap the
|
|
|
|
// offset in PaintRoundedFocusRect the same was a we snap border widths, so
|
|
|
|
// that negative offsets are guaranteed to cover the border.
|
|
|
|
// But this looks harder to mess up.
|
2021-03-05 04:35:17 +03:00
|
|
|
return sTransparent;
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
2021-10-05 17:40:52 +03:00
|
|
|
bool dark = aColors.IsDark();
|
2020-11-17 23:53:01 +03:00
|
|
|
if (isActive) {
|
2021-10-05 17:40:52 +03:00
|
|
|
return dark ? sColorGrey20 : sColorGrey60;
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
if (isHovered) {
|
2021-10-05 17:40:52 +03:00
|
|
|
return dark ? sColorGrey30 : sColorGrey50;
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
return sColorGrey40;
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::pair<sRGBColor, sRGBColor> Theme::ComputeButtonColors(
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors, nsIFrame* aFrame) {
|
2020-11-17 23:53:01 +03:00
|
|
|
bool isActive =
|
2022-06-08 02:09:52 +03:00
|
|
|
aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(ElementState::DISABLED);
|
|
|
|
bool isHovered = aState.HasState(ElementState::HOVER);
|
2020-11-17 23:53:01 +03:00
|
|
|
|
2021-12-10 19:51:28 +03:00
|
|
|
nscolor backgroundColor = [&] {
|
2020-11-17 23:53:01 +03:00
|
|
|
if (isDisabled) {
|
2021-12-10 19:51:28 +03:00
|
|
|
return aColors.SystemNs(StyleSystemColor::MozButtondisabledface);
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
if (isActive) {
|
2021-12-10 19:51:28 +03:00
|
|
|
return aColors.SystemNs(StyleSystemColor::MozButtonactiveface);
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
if (isHovered) {
|
2021-12-10 19:51:28 +03:00
|
|
|
return aColors.SystemNs(StyleSystemColor::MozButtonhoverface);
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
2021-12-10 19:51:28 +03:00
|
|
|
return aColors.SystemNs(StyleSystemColor::Buttonface);
|
2020-11-17 23:53:01 +03:00
|
|
|
}();
|
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::AUTOFILL)) {
|
2021-12-10 19:51:28 +03:00
|
|
|
backgroundColor = NS_ComposeColors(
|
|
|
|
backgroundColor,
|
|
|
|
aColors.SystemNs(StyleSystemColor::MozAutofillBackground));
|
|
|
|
}
|
|
|
|
|
2021-10-08 13:59:02 +03:00
|
|
|
const sRGBColor borderColor =
|
|
|
|
ComputeBorderColor(aState, aColors, OutlineCoversBorder::Yes);
|
2021-12-10 19:51:28 +03:00
|
|
|
return std::make_pair(sRGBColor::FromABGR(backgroundColor), borderColor);
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::pair<sRGBColor, sRGBColor> Theme::ComputeTextfieldColors(
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors,
|
2021-10-08 13:59:02 +03:00
|
|
|
OutlineCoversBorder aOutlineCoversBorder) {
|
2021-09-12 14:16:07 +03:00
|
|
|
nscolor backgroundColor = [&] {
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::DISABLED)) {
|
2021-10-05 17:40:52 +03:00
|
|
|
return aColors.SystemNs(StyleSystemColor::MozDisabledfield);
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
2021-10-05 17:40:52 +03:00
|
|
|
return aColors.SystemNs(StyleSystemColor::Field);
|
2021-03-12 17:44:13 +03:00
|
|
|
}();
|
2021-09-12 14:16:07 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::AUTOFILL)) {
|
2021-11-01 00:28:58 +03:00
|
|
|
backgroundColor = NS_ComposeColors(
|
|
|
|
backgroundColor,
|
|
|
|
aColors.SystemNs(StyleSystemColor::MozAutofillBackground));
|
2021-09-12 14:16:07 +03:00
|
|
|
}
|
|
|
|
|
2021-10-08 13:59:02 +03:00
|
|
|
const sRGBColor borderColor =
|
|
|
|
ComputeBorderColor(aState, aColors, aOutlineCoversBorder);
|
2021-09-12 14:16:07 +03:00
|
|
|
return std::make_pair(sRGBColor::FromABGR(backgroundColor), borderColor);
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::pair<sRGBColor, sRGBColor> Theme::ComputeRangeProgressColors(
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors) {
|
2021-10-05 17:40:52 +03:00
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return aColors.SystemPair(StyleSystemColor::Selecteditem,
|
|
|
|
StyleSystemColor::Buttontext);
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
|
|
|
|
2020-11-17 23:53:01 +03:00
|
|
|
bool isActive =
|
2022-06-08 02:09:52 +03:00
|
|
|
aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(ElementState::DISABLED);
|
|
|
|
bool isHovered = aState.HasState(ElementState::HOVER);
|
2020-11-17 23:53:01 +03:00
|
|
|
|
|
|
|
if (isDisabled) {
|
|
|
|
return std::make_pair(sColorGrey40Alpha50, sColorGrey40Alpha50);
|
|
|
|
}
|
|
|
|
if (isActive || isHovered) {
|
2021-10-05 12:40:00 +03:00
|
|
|
return std::make_pair(aColors.Accent().GetDark(),
|
|
|
|
aColors.Accent().GetDarker());
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
2021-10-05 12:40:00 +03:00
|
|
|
return std::make_pair(aColors.Accent().Get(), aColors.Accent().GetDark());
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::pair<sRGBColor, sRGBColor> Theme::ComputeRangeTrackColors(
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors) {
|
2021-10-05 17:40:52 +03:00
|
|
|
if (aColors.HighContrast()) {
|
2021-11-02 21:08:07 +03:00
|
|
|
return aColors.SystemPair(StyleSystemColor::Window,
|
2021-10-05 17:40:52 +03:00
|
|
|
StyleSystemColor::Buttontext);
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
2020-11-17 23:53:01 +03:00
|
|
|
bool isActive =
|
2022-06-08 02:09:52 +03:00
|
|
|
aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(ElementState::DISABLED);
|
|
|
|
bool isHovered = aState.HasState(ElementState::HOVER);
|
2020-11-17 23:53:01 +03:00
|
|
|
|
|
|
|
if (isDisabled) {
|
|
|
|
return std::make_pair(sColorGrey10Alpha50, sColorGrey40Alpha50);
|
|
|
|
}
|
|
|
|
if (isActive || isHovered) {
|
|
|
|
return std::make_pair(sColorGrey20, sColorGrey50);
|
|
|
|
}
|
|
|
|
return std::make_pair(sColorGrey10, sColorGrey40);
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::pair<sRGBColor, sRGBColor> Theme::ComputeRangeThumbColors(
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors) {
|
2021-10-05 17:40:52 +03:00
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return aColors.SystemPair(StyleSystemColor::Selecteditemtext,
|
|
|
|
StyleSystemColor::Selecteditem);
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
|
|
|
|
2020-11-17 23:53:01 +03:00
|
|
|
bool isActive =
|
2022-06-08 02:09:52 +03:00
|
|
|
aState.HasAllStates(ElementState::HOVER | ElementState::ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(ElementState::DISABLED);
|
|
|
|
bool isHovered = aState.HasState(ElementState::HOVER);
|
2020-11-17 23:53:01 +03:00
|
|
|
|
|
|
|
const sRGBColor& backgroundColor = [&] {
|
|
|
|
if (isDisabled) {
|
2021-02-24 02:22:19 +03:00
|
|
|
return sColorGrey40;
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
if (isActive) {
|
2021-10-05 12:40:00 +03:00
|
|
|
return aColors.Accent().Get();
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
if (isHovered) {
|
|
|
|
return sColorGrey60;
|
|
|
|
}
|
|
|
|
return sColorGrey50;
|
|
|
|
}();
|
|
|
|
|
2021-10-25 19:44:04 +03:00
|
|
|
const sRGBColor borderColor = sRGBColor::OpaqueWhite();
|
2020-11-17 23:53:01 +03:00
|
|
|
return std::make_pair(backgroundColor, borderColor);
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::pair<sRGBColor, sRGBColor> Theme::ComputeProgressColors(
|
2021-10-05 12:40:00 +03:00
|
|
|
const Colors& aColors) {
|
2021-10-05 17:40:52 +03:00
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return aColors.SystemPair(StyleSystemColor::Selecteditem,
|
|
|
|
StyleSystemColor::Buttontext);
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
2021-10-05 12:40:00 +03:00
|
|
|
return std::make_pair(aColors.Accent().Get(), aColors.Accent().GetDark());
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::pair<sRGBColor, sRGBColor> Theme::ComputeProgressTrackColors(
|
2021-10-05 12:40:00 +03:00
|
|
|
const Colors& aColors) {
|
2021-10-05 17:40:52 +03:00
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return aColors.SystemPair(StyleSystemColor::Buttonface,
|
|
|
|
StyleSystemColor::Buttontext);
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
2020-11-17 23:53:01 +03:00
|
|
|
return std::make_pair(sColorGrey10, sColorGrey40);
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::pair<sRGBColor, sRGBColor> Theme::ComputeMeterchunkColors(
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aMeterState, const Colors& aColors) {
|
2021-10-05 17:40:52 +03:00
|
|
|
if (aColors.HighContrast()) {
|
2021-10-05 12:40:00 +03:00
|
|
|
return ComputeProgressColors(aColors);
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
2020-11-17 23:53:01 +03:00
|
|
|
sRGBColor borderColor = sColorMeterGreen20;
|
|
|
|
sRGBColor chunkColor = sColorMeterGreen10;
|
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aMeterState.HasState(ElementState::SUB_OPTIMUM)) {
|
2021-01-06 09:00:28 +03:00
|
|
|
borderColor = sColorMeterYellow20;
|
|
|
|
chunkColor = sColorMeterYellow10;
|
2022-06-08 02:09:52 +03:00
|
|
|
} else if (aMeterState.HasState(ElementState::SUB_SUB_OPTIMUM)) {
|
2021-01-06 09:00:28 +03:00
|
|
|
borderColor = sColorMeterRed20;
|
|
|
|
chunkColor = sColorMeterRed10;
|
2020-11-17 23:53:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair(chunkColor, borderColor);
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
std::array<sRGBColor, 3> Theme::ComputeFocusRectColors(const Colors& aColors) {
|
2021-10-05 17:40:52 +03:00
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return {aColors.System(StyleSystemColor::Selecteditem),
|
|
|
|
aColors.System(StyleSystemColor::Buttontext),
|
2021-11-02 21:08:07 +03:00
|
|
|
aColors.System(StyleSystemColor::Window)};
|
2021-03-12 17:44:13 +03:00
|
|
|
}
|
2021-10-25 19:44:04 +03:00
|
|
|
const auto& accent = aColors.Accent();
|
|
|
|
const sRGBColor middle =
|
|
|
|
aColors.IsDark() ? sRGBColor::Black(.3f) : sRGBColor::White(.3f);
|
|
|
|
return {accent.Get(), middle, accent.GetLight()};
|
2021-10-05 12:40:00 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintRoundedFocusRect(PaintBackendData& aBackendData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
const Colors& aColors, DPIRatio aDpiRatio,
|
|
|
|
CSSCoord aRadius, CSSCoord aOffset) {
|
2021-01-29 01:11:54 +03:00
|
|
|
// NOTE(emilio): If the widths or offsets here change, make sure to tweak
|
|
|
|
// the GetWidgetOverflow path for FocusOutline.
|
2021-10-05 12:40:00 +03:00
|
|
|
auto [innerColor, middleColor, outerColor] = ComputeFocusRectColors(aColors);
|
2021-01-22 01:12:14 +03:00
|
|
|
|
2020-11-30 01:19:10 +03:00
|
|
|
LayoutDeviceRect focusRect(aRect);
|
2021-01-22 01:12:14 +03:00
|
|
|
|
|
|
|
// The focus rect is painted outside of the border area (aRect), see:
|
|
|
|
//
|
|
|
|
// data:text/html,<div style="border: 1px solid; outline: 2px solid
|
|
|
|
// red">Foobar</div>
|
|
|
|
//
|
|
|
|
// But some controls might provide a negative offset to cover the border, if
|
|
|
|
// necessary.
|
2022-07-20 14:43:35 +03:00
|
|
|
CSSCoord strokeWidth = 2.0f;
|
2021-03-05 04:35:17 +03:00
|
|
|
auto strokeWidthDevPx =
|
2021-11-15 15:39:38 +03:00
|
|
|
LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(strokeWidth, aDpiRatio));
|
2021-02-23 13:49:37 +03:00
|
|
|
CSSCoord strokeRadius = aRadius;
|
2021-03-05 04:35:17 +03:00
|
|
|
focusRect.Inflate(aOffset * aDpiRatio + strokeWidthDevPx);
|
2021-02-23 13:49:37 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(
|
|
|
|
aBackendData, focusRect, sTransparent, innerColor, strokeWidth,
|
|
|
|
strokeRadius, aDpiRatio);
|
2021-02-23 13:49:37 +03:00
|
|
|
|
|
|
|
strokeWidth = CSSCoord(1.0f);
|
2021-11-15 15:39:38 +03:00
|
|
|
strokeWidthDevPx =
|
|
|
|
LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(strokeWidth, aDpiRatio));
|
2021-02-23 13:49:37 +03:00
|
|
|
strokeRadius += strokeWidth;
|
2021-03-05 04:35:17 +03:00
|
|
|
focusRect.Inflate(strokeWidthDevPx);
|
2021-02-23 13:49:37 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(
|
|
|
|
aBackendData, focusRect, sTransparent, middleColor, strokeWidth,
|
|
|
|
strokeRadius, aDpiRatio);
|
2021-02-23 13:49:37 +03:00
|
|
|
|
|
|
|
strokeWidth = CSSCoord(2.0f);
|
2021-11-15 15:39:38 +03:00
|
|
|
strokeWidthDevPx =
|
|
|
|
LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(strokeWidth, aDpiRatio));
|
2021-02-23 13:49:37 +03:00
|
|
|
strokeRadius += strokeWidth;
|
2021-03-05 04:35:17 +03:00
|
|
|
focusRect.Inflate(strokeWidthDevPx);
|
2021-02-23 13:49:37 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(
|
|
|
|
aBackendData, focusRect, sTransparent, outerColor, strokeWidth,
|
|
|
|
strokeRadius, aDpiRatio);
|
2020-03-05 03:25:31 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintCheckboxControl(DrawTarget& aDrawTarget,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState,
|
2022-01-12 19:33:31 +03:00
|
|
|
const Colors& aColors, DPIRatio aDpiRatio) {
|
2022-09-15 02:14:30 +03:00
|
|
|
auto [backgroundColor, borderColor, checkColor] =
|
2021-10-11 16:52:27 +03:00
|
|
|
ComputeCheckboxColors(aState, StyleAppearance::Checkbox, aColors);
|
2021-03-12 15:28:44 +03:00
|
|
|
{
|
2021-03-20 20:56:27 +03:00
|
|
|
const CSSCoord radius = 2.0f;
|
2021-03-12 15:28:44 +03:00
|
|
|
CSSCoord borderWidth = kCheckboxRadioBorderWidth;
|
|
|
|
if (backgroundColor == borderColor) {
|
|
|
|
borderWidth = 0.0f;
|
|
|
|
}
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aDrawTarget, aRect,
|
|
|
|
backgroundColor, borderColor,
|
|
|
|
borderWidth, radius, aDpiRatio);
|
2021-03-12 15:28:44 +03:00
|
|
|
}
|
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::INDETERMINATE)) {
|
2022-09-15 02:14:30 +03:00
|
|
|
PaintIndeterminateMark(aDrawTarget, aRect, checkColor);
|
2022-06-08 02:09:52 +03:00
|
|
|
} else if (aState.HasState(ElementState::CHECKED)) {
|
2022-09-15 02:14:30 +03:00
|
|
|
PaintCheckMark(aDrawTarget, aRect, checkColor);
|
2021-03-12 15:28:44 +03:00
|
|
|
}
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::FOCUSRING)) {
|
2021-10-05 12:40:00 +03:00
|
|
|
PaintRoundedFocusRect(aDrawTarget, aRect, aColors, aDpiRatio, 5.0f, 1.0f);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-03-02 01:55:37 +03:00
|
|
|
constexpr CSSCoord kCheckboxRadioContentBoxSize = 10.0f;
|
|
|
|
constexpr CSSCoord kCheckboxRadioBorderBoxSize =
|
|
|
|
kCheckboxRadioContentBoxSize + kCheckboxRadioBorderWidth * 2.0f;
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintCheckMark(DrawTarget& aDrawTarget,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-09-15 02:14:30 +03:00
|
|
|
const sRGBColor& aColor) {
|
2021-03-02 01:55:37 +03:00
|
|
|
// Points come from the coordinates on a 14X14 (kCheckboxRadioBorderBoxSize)
|
|
|
|
// unit box centered at 0,0
|
2020-07-30 20:02:02 +03:00
|
|
|
const float checkPolygonX[] = {-4.5f, -1.5f, -0.5f, 5.0f, 4.75f,
|
|
|
|
3.5f, -0.5f, -1.5f, -3.5f};
|
|
|
|
const float checkPolygonY[] = {0.5f, 4.0f, 4.0f, -2.5f, -4.0f,
|
|
|
|
-4.0f, 1.0f, 1.25f, -1.0f};
|
2020-02-10 22:26:01 +03:00
|
|
|
const int32_t checkNumPoints = sizeof(checkPolygonX) / sizeof(float);
|
2021-11-15 15:39:38 +03:00
|
|
|
const float scale =
|
|
|
|
ThemeDrawing::ScaleToFillRect(aRect, kCheckboxRadioBorderBoxSize);
|
2020-11-30 01:19:10 +03:00
|
|
|
auto center = aRect.Center().ToUnknownPoint();
|
2020-02-16 19:04:31 +03:00
|
|
|
|
2021-02-22 19:18:33 +03:00
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
|
2020-07-30 20:02:02 +03:00
|
|
|
Point p = center + Point(checkPolygonX[0] * scale, checkPolygonY[0] * scale);
|
2020-02-10 22:26:01 +03:00
|
|
|
builder->MoveTo(p);
|
2020-07-30 20:02:02 +03:00
|
|
|
for (int32_t i = 1; i < checkNumPoints; i++) {
|
|
|
|
p = center + Point(checkPolygonX[i] * scale, checkPolygonY[i] * scale);
|
2020-02-10 22:26:01 +03:00
|
|
|
builder->LineTo(p);
|
|
|
|
}
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
2020-07-30 01:16:06 +03:00
|
|
|
|
2022-09-15 02:14:30 +03:00
|
|
|
aDrawTarget.Fill(path, ColorPattern(ToDeviceColor(aColor)));
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintIndeterminateMark(DrawTarget& aDrawTarget,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-09-15 02:14:30 +03:00
|
|
|
const sRGBColor& aColor) {
|
2020-07-30 20:02:02 +03:00
|
|
|
const CSSCoord borderWidth = 2.0f;
|
2021-11-15 15:39:38 +03:00
|
|
|
const float scale =
|
|
|
|
ThemeDrawing::ScaleToFillRect(aRect, kCheckboxRadioBorderBoxSize);
|
2020-02-10 22:26:01 +03:00
|
|
|
|
2020-11-30 01:19:10 +03:00
|
|
|
Rect rect = aRect.ToUnknownRect();
|
2020-07-30 20:02:02 +03:00
|
|
|
rect.y += (rect.height / 2) - (borderWidth * scale / 2);
|
|
|
|
rect.height = borderWidth * scale;
|
|
|
|
rect.x += (borderWidth * scale) + (borderWidth * scale / 8);
|
|
|
|
rect.width -= ((borderWidth * scale) + (borderWidth * scale / 8)) * 2;
|
2020-02-10 22:26:01 +03:00
|
|
|
|
2022-09-15 02:14:30 +03:00
|
|
|
aDrawTarget.FillRect(rect, ColorPattern(ToDeviceColor(aColor)));
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-24 02:22:19 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintStrokedCircle(PaintBackendData& aPaintData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
const sRGBColor& aBackgroundColor,
|
|
|
|
const sRGBColor& aBorderColor,
|
|
|
|
const CSSCoord aBorderWidth,
|
|
|
|
DPIRatio aDpiRatio) {
|
2021-02-24 02:22:19 +03:00
|
|
|
auto radius = LayoutDeviceCoord(aRect.Size().width) / aDpiRatio;
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, aRect, aBackgroundColor,
|
|
|
|
aBorderColor, aBorderWidth, radius,
|
|
|
|
aDpiRatio);
|
2021-02-24 02:22:19 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintCircleShadow(WebRenderBackendData& aWrData,
|
|
|
|
const LayoutDeviceRect& aBoxRect,
|
|
|
|
const LayoutDeviceRect& aClipRect,
|
|
|
|
float aShadowAlpha, const CSSPoint& aShadowOffset,
|
|
|
|
CSSCoord aShadowBlurStdDev, DPIRatio aDpiRatio) {
|
2021-02-24 02:22:19 +03:00
|
|
|
const bool kBackfaceIsVisible = true;
|
|
|
|
const LayoutDeviceCoord stdDev = aShadowBlurStdDev * aDpiRatio;
|
|
|
|
const LayoutDevicePoint shadowOffset = aShadowOffset * aDpiRatio;
|
|
|
|
const IntSize inflation =
|
|
|
|
gfxAlphaBoxBlur::CalculateBlurRadius(gfxPoint(stdDev, stdDev));
|
|
|
|
LayoutDeviceRect shadowRect = aBoxRect;
|
|
|
|
shadowRect.MoveBy(shadowOffset);
|
|
|
|
shadowRect.Inflate(inflation.width, inflation.height);
|
|
|
|
const auto boxRect = wr::ToLayoutRect(aBoxRect);
|
|
|
|
aWrData.mBuilder.PushBoxShadow(
|
|
|
|
wr::ToLayoutRect(shadowRect), wr::ToLayoutRect(aClipRect),
|
|
|
|
kBackfaceIsVisible, boxRect,
|
|
|
|
wr::ToLayoutVector2D(aShadowOffset * aDpiRatio),
|
|
|
|
wr::ToColorF(DeviceColor(0.0f, 0.0f, 0.0f, aShadowAlpha)), stdDev,
|
|
|
|
/* aSpread = */ 0.0f,
|
|
|
|
wr::ToBorderRadius(gfx::RectCornerRadii(aBoxRect.Size().width)),
|
|
|
|
wr::BoxShadowClipMode::Outset);
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintCircleShadow(DrawTarget& aDrawTarget,
|
|
|
|
const LayoutDeviceRect& aBoxRect,
|
|
|
|
const LayoutDeviceRect& aClipRect,
|
|
|
|
float aShadowAlpha, const CSSPoint& aShadowOffset,
|
|
|
|
CSSCoord aShadowBlurStdDev, DPIRatio aDpiRatio) {
|
2020-11-02 20:09:05 +03:00
|
|
|
Float stdDev = aShadowBlurStdDev * aDpiRatio;
|
2020-11-30 07:48:07 +03:00
|
|
|
Point offset = (aShadowOffset * aDpiRatio).ToUnknownPoint();
|
2020-11-02 20:09:05 +03:00
|
|
|
|
|
|
|
RefPtr<FilterNode> blurFilter =
|
2021-02-22 19:18:33 +03:00
|
|
|
aDrawTarget.CreateFilter(FilterType::GAUSSIAN_BLUR);
|
2020-11-02 20:09:05 +03:00
|
|
|
if (!blurFilter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
blurFilter->SetAttribute(ATT_GAUSSIAN_BLUR_STD_DEVIATION, stdDev);
|
|
|
|
|
|
|
|
IntSize inflation =
|
|
|
|
gfxAlphaBoxBlur::CalculateBlurRadius(gfxPoint(stdDev, stdDev));
|
2021-02-24 02:22:19 +03:00
|
|
|
Rect inflatedRect = aBoxRect.ToUnknownRect();
|
2020-11-02 20:09:05 +03:00
|
|
|
inflatedRect.Inflate(inflation.width, inflation.height);
|
2020-11-30 01:19:10 +03:00
|
|
|
Rect sourceRectInFilterSpace =
|
2021-02-24 02:22:19 +03:00
|
|
|
inflatedRect - aBoxRect.TopLeft().ToUnknownPoint();
|
2020-11-02 20:09:05 +03:00
|
|
|
Point destinationPointOfSourceRect = inflatedRect.TopLeft() + offset;
|
|
|
|
|
2021-02-24 02:22:19 +03:00
|
|
|
IntSize dtSize = RoundedToInt(aBoxRect.Size().ToUnknownSize());
|
2021-02-22 19:18:33 +03:00
|
|
|
RefPtr<DrawTarget> ellipseDT = aDrawTarget.CreateSimilarDrawTargetForFilter(
|
2020-11-02 20:09:05 +03:00
|
|
|
dtSize, SurfaceFormat::A8, blurFilter, blurFilter,
|
|
|
|
sourceRectInFilterSpace, destinationPointOfSourceRect);
|
|
|
|
if (!ellipseDT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-24 02:22:19 +03:00
|
|
|
AutoClipRect clipRect(aDrawTarget, aClipRect);
|
|
|
|
|
2020-11-02 20:09:05 +03:00
|
|
|
RefPtr<Path> ellipse = MakePathForEllipse(
|
2021-02-24 02:22:19 +03:00
|
|
|
*ellipseDT, (aBoxRect - aBoxRect.TopLeft()).Center().ToUnknownPoint(),
|
|
|
|
aBoxRect.Size().ToUnknownSize());
|
2020-11-02 20:09:05 +03:00
|
|
|
ellipseDT->Fill(ellipse,
|
|
|
|
ColorPattern(DeviceColor(0.0f, 0.0f, 0.0f, aShadowAlpha)));
|
|
|
|
RefPtr<SourceSurface> ellipseSurface = ellipseDT->Snapshot();
|
|
|
|
|
|
|
|
blurFilter->SetInput(IN_GAUSSIAN_BLUR_IN, ellipseSurface);
|
2021-02-22 19:18:33 +03:00
|
|
|
aDrawTarget.DrawFilter(blurFilter, sourceRectInFilterSpace,
|
|
|
|
destinationPointOfSourceRect);
|
2020-11-02 20:09:05 +03:00
|
|
|
}
|
|
|
|
|
2021-02-24 02:22:19 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintRadioControl(PaintBackendData& aPaintData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors,
|
2022-01-12 19:33:31 +03:00
|
|
|
DPIRatio aDpiRatio) {
|
2022-09-15 02:14:30 +03:00
|
|
|
auto [backgroundColor, borderColor, checkColor] =
|
2021-10-11 16:52:27 +03:00
|
|
|
ComputeCheckboxColors(aState, StyleAppearance::Radio, aColors);
|
2021-03-12 15:28:44 +03:00
|
|
|
{
|
|
|
|
CSSCoord borderWidth = kCheckboxRadioBorderWidth;
|
|
|
|
if (backgroundColor == borderColor) {
|
|
|
|
borderWidth = 0.0f;
|
|
|
|
}
|
|
|
|
PaintStrokedCircle(aPaintData, aRect, backgroundColor, borderColor,
|
|
|
|
borderWidth, aDpiRatio);
|
|
|
|
}
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::CHECKED)) {
|
2021-03-12 14:25:49 +03:00
|
|
|
LayoutDeviceRect rect(aRect);
|
2021-11-15 15:39:38 +03:00
|
|
|
auto width = LayoutDeviceCoord(
|
|
|
|
ThemeDrawing::SnapBorderWidth(kCheckboxRadioBorderWidth, aDpiRatio));
|
|
|
|
rect.Deflate(width);
|
2021-03-12 14:25:49 +03:00
|
|
|
|
|
|
|
PaintStrokedCircle(aPaintData, rect, backgroundColor, checkColor,
|
2021-03-12 15:28:44 +03:00
|
|
|
kCheckboxRadioBorderWidth, aDpiRatio);
|
2021-03-12 14:25:49 +03:00
|
|
|
}
|
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::FOCUSRING)) {
|
2021-10-05 12:40:00 +03:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio, 5.0f, 1.0f);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintTextField(PaintBackendData& aPaintData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors,
|
2022-01-12 19:33:31 +03:00
|
|
|
DPIRatio aDpiRatio) {
|
2021-10-08 13:59:02 +03:00
|
|
|
auto [backgroundColor, borderColor] =
|
|
|
|
ComputeTextfieldColors(aState, aColors, OutlineCoversBorder::Yes);
|
2020-03-05 03:25:31 +03:00
|
|
|
|
2020-07-30 20:02:02 +03:00
|
|
|
const CSSCoord radius = 2.0f;
|
2020-03-05 03:25:31 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, aRect, backgroundColor,
|
|
|
|
borderColor, kTextFieldBorderWidth,
|
|
|
|
radius, aDpiRatio);
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::FOCUSRING)) {
|
2021-10-05 12:40:00 +03:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio,
|
|
|
|
radius + kTextFieldBorderWidth,
|
2021-01-22 01:12:14 +03:00
|
|
|
-kTextFieldBorderWidth);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintListbox(PaintBackendData& aPaintData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors,
|
2022-01-12 19:33:31 +03:00
|
|
|
DPIRatio aDpiRatio) {
|
2020-07-30 20:02:02 +03:00
|
|
|
const CSSCoord radius = 2.0f;
|
2021-10-08 13:59:02 +03:00
|
|
|
auto [backgroundColor, borderColor] =
|
|
|
|
ComputeTextfieldColors(aState, aColors, OutlineCoversBorder::Yes);
|
2020-02-10 22:26:01 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, aRect, backgroundColor,
|
|
|
|
borderColor, kMenulistBorderWidth,
|
|
|
|
radius, aDpiRatio);
|
2020-03-06 20:54:04 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::FOCUSRING)) {
|
2021-10-05 12:40:00 +03:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio,
|
|
|
|
radius + kMenulistBorderWidth, -kMenulistBorderWidth);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintMenulist(PaintBackendData& aDrawTarget,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors,
|
2022-01-12 19:33:31 +03:00
|
|
|
DPIRatio aDpiRatio) {
|
2020-07-30 20:02:02 +03:00
|
|
|
const CSSCoord radius = 4.0f;
|
2021-10-05 12:40:00 +03:00
|
|
|
auto [backgroundColor, borderColor] = ComputeButtonColors(aState, aColors);
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aDrawTarget, aRect, backgroundColor,
|
|
|
|
borderColor, kMenulistBorderWidth,
|
|
|
|
radius, aDpiRatio);
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::FOCUSRING)) {
|
2021-10-05 12:40:00 +03:00
|
|
|
PaintRoundedFocusRect(aDrawTarget, aRect, aColors, aDpiRatio,
|
|
|
|
radius + kMenulistBorderWidth, -kMenulistBorderWidth);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintMenulistArrowButton(nsIFrame* aFrame, DrawTarget& aDrawTarget,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState) {
|
2022-06-02 18:11:01 +03:00
|
|
|
// not const: these may be negated in-place below
|
|
|
|
float polygonX[] = {-4.0f, -0.5f, 0.5f, 4.0f, 4.0f,
|
|
|
|
3.0f, 0.0f, 0.0f, -3.0f, -4.0f};
|
|
|
|
float polygonY[] = {-1, 3.0f, 3.0f, -1.0f, -2.0f,
|
|
|
|
-2.0f, 1.5f, 1.5f, -2.0f, -2.0f};
|
2021-03-02 01:55:37 +03:00
|
|
|
|
2021-03-02 03:48:36 +03:00
|
|
|
const float kPolygonSize = kMinimumDropdownArrowButtonWidth;
|
2021-03-02 01:55:37 +03:00
|
|
|
|
2022-06-02 18:11:01 +03:00
|
|
|
auto const [xs, ys] = [&] {
|
|
|
|
using Pair = std::pair<const float*, const float*>;
|
|
|
|
switch (aFrame->GetWritingMode().GetBlockDir()) {
|
|
|
|
case WritingMode::BlockDir::eBlockRL:
|
|
|
|
// rotate 90°: [[0,1],[-1,0]]
|
|
|
|
for (float& f : polygonY) {
|
|
|
|
f = -f;
|
|
|
|
}
|
|
|
|
return Pair(polygonY, polygonX);
|
|
|
|
|
|
|
|
case WritingMode::BlockDir::eBlockLR:
|
|
|
|
// rotate 270°: [[0,-1],[1,0]]
|
|
|
|
for (float& f : polygonX) {
|
|
|
|
f = -f;
|
|
|
|
}
|
|
|
|
return Pair(polygonY, polygonX);
|
|
|
|
|
|
|
|
case WritingMode::BlockDir::eBlockTB:
|
|
|
|
// rotate 0°: [[1,0],[0,1]]
|
|
|
|
return Pair(polygonX, polygonY);
|
|
|
|
}
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unhandled BlockDir");
|
|
|
|
return Pair(polygonX, polygonY);
|
|
|
|
}();
|
|
|
|
|
2021-05-17 15:11:15 +03:00
|
|
|
const auto arrowColor = sRGBColor::FromABGR(
|
|
|
|
nsLayoutUtils::GetColor(aFrame, &nsStyleText::mWebkitTextFillColor));
|
2022-06-02 18:11:01 +03:00
|
|
|
ThemeDrawing::PaintArrow(aDrawTarget, aRect, xs, ys, kPolygonSize,
|
|
|
|
ArrayLength(polygonX), arrowColor);
|
2020-07-30 02:58:03 +03:00
|
|
|
}
|
2020-07-30 01:16:06 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintSpinnerButton(nsIFrame* aFrame, DrawTarget& aDrawTarget,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState,
|
2022-01-12 19:33:31 +03:00
|
|
|
StyleAppearance aAppearance,
|
|
|
|
const Colors& aColors, DPIRatio aDpiRatio) {
|
2021-10-05 12:40:00 +03:00
|
|
|
auto [backgroundColor, borderColor] = ComputeButtonColors(aState, aColors);
|
2020-07-30 02:58:03 +03:00
|
|
|
|
2021-02-22 19:18:33 +03:00
|
|
|
aDrawTarget.FillRect(aRect.ToUnknownRect(),
|
|
|
|
ColorPattern(ToDeviceColor(backgroundColor)));
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2021-03-02 19:14:46 +03:00
|
|
|
const float kPolygonX[] = {-3.5f, -0.5f, 0.5f, 3.5f, 3.5f,
|
2021-03-02 03:48:36 +03:00
|
|
|
2.5f, 0.0f, 0.0f, -2.5f, -3.5f};
|
|
|
|
float polygonY[] = {-1.5f, 1.5f, 1.5f, -1.5f, -2.5f,
|
|
|
|
-2.5f, 0.0f, 0.0f, -2.5f, -2.5f};
|
|
|
|
|
|
|
|
const float kPolygonSize = kMinimumSpinnerButtonHeight;
|
|
|
|
if (aAppearance == StyleAppearance::SpinnerUpbutton) {
|
|
|
|
for (auto& coord : polygonY) {
|
|
|
|
coord = -coord;
|
|
|
|
}
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
2021-03-02 03:48:36 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintArrow(aDrawTarget, aRect, kPolygonX, polygonY,
|
|
|
|
kPolygonSize, ArrayLength(kPolygonX), borderColor);
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-24 02:22:19 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintRange(nsIFrame* aFrame, PaintBackendData& aPaintData,
|
2022-06-08 02:09:52 +03:00
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
const ElementState& aState, const Colors& aColors,
|
|
|
|
DPIRatio aDpiRatio, bool aHorizontal) {
|
2020-07-30 20:02:02 +03:00
|
|
|
nsRangeFrame* rangeFrame = do_QueryFrame(aFrame);
|
|
|
|
if (!rangeFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-27 02:17:57 +03:00
|
|
|
double progress = rangeFrame->GetValueAsFractionOfRange();
|
2020-11-30 01:19:10 +03:00
|
|
|
auto rect = aRect;
|
|
|
|
LayoutDeviceRect thumbRect(0, 0, kMinimumRangeThumbSize * aDpiRatio,
|
|
|
|
kMinimumRangeThumbSize * aDpiRatio);
|
2021-02-24 02:22:19 +03:00
|
|
|
LayoutDeviceRect progressClipRect(aRect);
|
|
|
|
LayoutDeviceRect trackClipRect(aRect);
|
2020-11-30 07:48:07 +03:00
|
|
|
const LayoutDeviceCoord verticalSize = kRangeHeight * aDpiRatio;
|
2020-07-30 20:02:02 +03:00
|
|
|
if (aHorizontal) {
|
|
|
|
rect.height = verticalSize;
|
2020-10-27 02:17:57 +03:00
|
|
|
rect.y = aRect.y + (aRect.height - rect.height) / 2;
|
|
|
|
thumbRect.y = aRect.y + (aRect.height - thumbRect.height) / 2;
|
2020-03-07 12:58:30 +03:00
|
|
|
|
2020-07-30 20:02:02 +03:00
|
|
|
if (IsFrameRTL(aFrame)) {
|
2020-10-27 02:17:57 +03:00
|
|
|
thumbRect.x =
|
|
|
|
aRect.x + (aRect.width - thumbRect.width) * (1.0 - progress);
|
2020-11-02 20:09:05 +03:00
|
|
|
float midPoint = thumbRect.Center().X();
|
2021-02-24 02:22:19 +03:00
|
|
|
trackClipRect.SetBoxX(aRect.X(), midPoint);
|
|
|
|
progressClipRect.SetBoxX(midPoint, aRect.XMost());
|
2020-07-30 20:02:02 +03:00
|
|
|
} else {
|
2020-10-27 02:17:57 +03:00
|
|
|
thumbRect.x = aRect.x + (aRect.width - thumbRect.width) * progress;
|
2020-11-02 20:09:05 +03:00
|
|
|
float midPoint = thumbRect.Center().X();
|
2021-02-24 02:22:19 +03:00
|
|
|
progressClipRect.SetBoxX(aRect.X(), midPoint);
|
|
|
|
trackClipRect.SetBoxX(midPoint, aRect.XMost());
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
2020-03-07 12:58:30 +03:00
|
|
|
} else {
|
2020-10-27 02:17:57 +03:00
|
|
|
rect.width = verticalSize;
|
|
|
|
rect.x = aRect.x + (aRect.width - rect.width) / 2;
|
|
|
|
thumbRect.x = aRect.x + (aRect.width - thumbRect.width) / 2;
|
|
|
|
|
2021-03-08 00:44:37 +03:00
|
|
|
thumbRect.y =
|
|
|
|
aRect.y + (aRect.height - thumbRect.height) * (1.0 - progress);
|
2020-11-02 20:09:05 +03:00
|
|
|
float midPoint = thumbRect.Center().Y();
|
2021-02-24 02:22:19 +03:00
|
|
|
trackClipRect.SetBoxY(aRect.Y(), midPoint);
|
|
|
|
progressClipRect.SetBoxY(midPoint, aRect.YMost());
|
2020-07-30 01:16:06 +03:00
|
|
|
}
|
|
|
|
|
2020-07-30 20:02:02 +03:00
|
|
|
const CSSCoord borderWidth = 1.0f;
|
2021-04-02 17:39:17 +03:00
|
|
|
const CSSCoord radius = 3.0f;
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2020-11-17 23:53:01 +03:00
|
|
|
auto [progressColor, progressBorderColor] =
|
2021-10-05 12:40:00 +03:00
|
|
|
ComputeRangeProgressColors(aState, aColors);
|
2021-03-12 17:44:13 +03:00
|
|
|
auto [trackColor, trackBorderColor] =
|
2021-10-05 12:40:00 +03:00
|
|
|
ComputeRangeTrackColors(aState, aColors);
|
2020-10-27 02:17:50 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, rect, progressClipRect,
|
|
|
|
progressColor, progressBorderColor,
|
|
|
|
borderWidth, radius, aDpiRatio);
|
2021-02-24 02:22:19 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, rect, trackClipRect,
|
|
|
|
trackColor, trackBorderColor,
|
|
|
|
borderWidth, radius, aDpiRatio);
|
2021-02-24 02:22:19 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (!aState.HasState(ElementState::DISABLED)) {
|
2021-02-24 02:22:19 +03:00
|
|
|
// Ensure the shadow doesn't expand outside of our overflow rect declared in
|
|
|
|
// GetWidgetOverflow().
|
|
|
|
auto overflowRect = aRect;
|
|
|
|
overflowRect.Inflate(CSSCoord(6.0f) * aDpiRatio);
|
|
|
|
// Thumb shadow
|
|
|
|
PaintCircleShadow(aPaintData, thumbRect, overflowRect, 0.3f,
|
|
|
|
CSSPoint(0.0f, 2.0f), 2.0f, aDpiRatio);
|
2020-10-27 02:18:00 +03:00
|
|
|
}
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2020-10-27 02:18:00 +03:00
|
|
|
// Draw the thumb on top.
|
|
|
|
const CSSCoord thumbBorderWidth = 2.0f;
|
2021-03-12 17:44:13 +03:00
|
|
|
auto [thumbColor, thumbBorderColor] =
|
2021-10-05 12:40:00 +03:00
|
|
|
ComputeRangeThumbColors(aState, aColors);
|
2020-10-27 02:18:00 +03:00
|
|
|
|
2021-02-24 02:22:19 +03:00
|
|
|
PaintStrokedCircle(aPaintData, thumbRect, thumbColor, thumbBorderColor,
|
|
|
|
thumbBorderWidth, aDpiRatio);
|
2020-10-27 02:18:00 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::FOCUSRING)) {
|
2021-10-05 12:40:00 +03:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio, radius, 1.0f);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
2020-07-30 01:16:06 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintProgress(nsIFrame* aFrame, PaintBackendData& aPaintData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors,
|
2022-01-12 19:33:31 +03:00
|
|
|
DPIRatio aDpiRatio, bool aIsMeter) {
|
2020-07-30 20:02:02 +03:00
|
|
|
const CSSCoord borderWidth = 1.0f;
|
2021-04-02 17:39:17 +03:00
|
|
|
const CSSCoord radius = aIsMeter ? 6.0f : 3.0f;
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2020-11-30 01:19:10 +03:00
|
|
|
LayoutDeviceRect rect(aRect);
|
2021-02-18 09:12:54 +03:00
|
|
|
const LayoutDeviceCoord thickness =
|
2021-01-28 23:58:39 +03:00
|
|
|
(aIsMeter ? kMeterHeight : kProgressbarHeight) * aDpiRatio;
|
2021-02-18 09:12:54 +03:00
|
|
|
|
|
|
|
const bool isHorizontal = !nsNativeTheme::IsVerticalProgress(aFrame);
|
|
|
|
if (isHorizontal) {
|
|
|
|
// Center it vertically.
|
|
|
|
rect.y += (rect.height - thickness) / 2;
|
|
|
|
rect.height = thickness;
|
|
|
|
} else {
|
|
|
|
// Center it horizontally.
|
|
|
|
rect.x += (rect.width - thickness) / 2;
|
|
|
|
rect.width = thickness;
|
|
|
|
}
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2021-03-16 00:01:08 +03:00
|
|
|
{
|
|
|
|
// Paint the track, unclipped.
|
2021-10-05 12:40:00 +03:00
|
|
|
auto [backgroundColor, borderColor] = ComputeProgressTrackColors(aColors);
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, rect, rect,
|
|
|
|
backgroundColor, borderColor,
|
|
|
|
borderWidth, radius, aDpiRatio);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
|
|
|
|
2021-03-16 00:01:08 +03:00
|
|
|
// Now paint the chunk, clipped as needed.
|
|
|
|
LayoutDeviceRect clipRect = rect;
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::INDETERMINATE)) {
|
2021-03-16 00:01:08 +03:00
|
|
|
// For indeterminate progress, we paint an animated chunk of 1/3 of the
|
|
|
|
// progress size.
|
|
|
|
//
|
|
|
|
// Animation speed and math borrowed from GTK.
|
|
|
|
const LayoutDeviceCoord size = isHorizontal ? rect.width : rect.height;
|
|
|
|
const LayoutDeviceCoord barSize = size * 0.3333f;
|
|
|
|
const LayoutDeviceCoord travel = 2.0f * (size - barSize);
|
|
|
|
|
|
|
|
// Period equals to travel / pixelsPerMillisecond where pixelsPerMillisecond
|
|
|
|
// equals progressSize / 1000.0. This is equivalent to 1600.
|
|
|
|
const unsigned kPeriod = 1600;
|
|
|
|
|
|
|
|
const int t = PR_IntervalToMilliseconds(PR_IntervalNow()) % kPeriod;
|
|
|
|
const LayoutDeviceCoord dx = travel * float(t) / float(kPeriod);
|
|
|
|
if (isHorizontal) {
|
|
|
|
rect.width = barSize;
|
|
|
|
rect.x += (dx < travel * .5f) ? dx : travel - dx;
|
|
|
|
} else {
|
|
|
|
rect.height = barSize;
|
|
|
|
rect.y += (dx < travel * .5f) ? dx : travel - dx;
|
|
|
|
}
|
|
|
|
clipRect = rect;
|
|
|
|
// Queue the next frame if needed.
|
|
|
|
if (!QueueAnimatedContentForRefresh(aFrame->GetContent(), 60)) {
|
|
|
|
NS_WARNING("Couldn't refresh indeterminate <progress>");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is the progress chunk, clip it to the right amount.
|
|
|
|
double position = [&] {
|
|
|
|
if (aIsMeter) {
|
|
|
|
auto* meter = dom::HTMLMeterElement::FromNode(aFrame->GetContent());
|
|
|
|
if (!meter) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
2021-12-22 21:16:21 +03:00
|
|
|
return meter->Position();
|
2021-03-16 00:01:08 +03:00
|
|
|
}
|
|
|
|
auto* progress = dom::HTMLProgressElement::FromNode(aFrame->GetContent());
|
|
|
|
if (!progress) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
2021-12-22 21:16:21 +03:00
|
|
|
return progress->Position();
|
2021-03-16 00:01:08 +03:00
|
|
|
}();
|
|
|
|
if (isHorizontal) {
|
|
|
|
double clipWidth = rect.width * position;
|
|
|
|
clipRect.width = clipWidth;
|
|
|
|
if (IsFrameRTL(aFrame)) {
|
|
|
|
clipRect.x += rect.width - clipWidth;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
double clipHeight = rect.height * position;
|
|
|
|
clipRect.height = clipHeight;
|
|
|
|
clipRect.y += rect.height - clipHeight;
|
|
|
|
}
|
2021-03-16 00:01:08 +03:00
|
|
|
}
|
2021-03-16 00:01:08 +03:00
|
|
|
|
|
|
|
auto [backgroundColor, borderColor] =
|
2021-10-05 12:40:00 +03:00
|
|
|
aIsMeter ? ComputeMeterchunkColors(aState, aColors)
|
|
|
|
: ComputeProgressColors(aColors);
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, rect, clipRect,
|
|
|
|
backgroundColor, borderColor,
|
|
|
|
borderWidth, radius, aDpiRatio);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintButton(nsIFrame* aFrame, PaintBackendData& aPaintData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
2022-06-08 02:09:52 +03:00
|
|
|
const ElementState& aState, const Colors& aColors,
|
2022-01-12 19:33:31 +03:00
|
|
|
DPIRatio aDpiRatio) {
|
2020-07-30 20:02:02 +03:00
|
|
|
const CSSCoord radius = 4.0f;
|
2021-03-12 17:44:13 +03:00
|
|
|
auto [backgroundColor, borderColor] =
|
2021-10-05 12:40:00 +03:00
|
|
|
ComputeButtonColors(aState, aColors, aFrame);
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, aRect, backgroundColor,
|
|
|
|
borderColor, kButtonBorderWidth,
|
|
|
|
radius, aDpiRatio);
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
if (aState.HasState(ElementState::FOCUSRING)) {
|
2021-10-05 12:40:00 +03:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aColors, aDpiRatio,
|
|
|
|
radius + kButtonBorderWidth, -kButtonBorderWidth);
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 22:26:01 +03:00
|
|
|
NS_IMETHODIMP
|
2022-01-12 19:33:31 +03:00
|
|
|
Theme::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance, const nsRect& aRect,
|
|
|
|
const nsRect& /* aDirtyRect */,
|
|
|
|
DrawOverflow aDrawOverflow) {
|
2021-02-23 13:49:37 +03:00
|
|
|
if (!DoDrawWidgetBackground(*aContext->GetDrawTarget(), aFrame, aAppearance,
|
2021-03-21 02:08:11 +03:00
|
|
|
aRect, aDrawOverflow)) {
|
2021-02-23 13:49:37 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2021-02-23 07:41:58 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::CreateWebRenderCommandsForWidget(
|
2021-02-23 13:49:37 +03:00
|
|
|
mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const mozilla::layers::StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::RenderRootStateManager* aManager, nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance, const nsRect& aRect) {
|
|
|
|
if (!StaticPrefs::widget_non_native_theme_webrender()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
WebRenderBackendData data{aBuilder, aResources, aSc, aManager};
|
2021-03-22 19:11:33 +03:00
|
|
|
return DoDrawWidgetBackground(data, aFrame, aAppearance, aRect,
|
|
|
|
DrawOverflow::Yes);
|
2021-02-23 13:49:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static LayoutDeviceRect ToSnappedRect(const nsRect& aRect,
|
|
|
|
nscoord aTwipsPerPixel, DrawTarget& aDt) {
|
|
|
|
return LayoutDeviceRect::FromUnknownRect(
|
|
|
|
NSRectToSnappedRect(aRect, aTwipsPerPixel, aDt));
|
|
|
|
}
|
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
static LayoutDeviceRect ToSnappedRect(const nsRect& aRect,
|
|
|
|
nscoord aTwipsPerPixel,
|
|
|
|
WebRenderBackendData& aDt) {
|
2021-02-23 13:49:37 +03:00
|
|
|
// TODO: Do we need to do any more snapping here?
|
|
|
|
return LayoutDeviceRect::FromAppUnits(aRect, aTwipsPerPixel);
|
|
|
|
}
|
|
|
|
|
2022-05-09 20:09:24 +03:00
|
|
|
static ScrollbarDrawing::ScrollbarKind ComputeScrollbarKind(
|
|
|
|
nsIFrame* aFrame, bool aIsHorizontal) {
|
|
|
|
if (aIsHorizontal) {
|
|
|
|
return ScrollbarDrawing::ScrollbarKind::Horizontal;
|
|
|
|
}
|
|
|
|
nsIFrame* scrollbar = ScrollbarDrawing::GetParentScrollbarFrame(aFrame);
|
|
|
|
if (NS_WARN_IF(!scrollbar)) {
|
|
|
|
return ScrollbarDrawing::ScrollbarKind::VerticalRight;
|
|
|
|
}
|
2022-05-13 02:21:05 +03:00
|
|
|
MOZ_ASSERT(scrollbar->IsScrollbarFrame());
|
|
|
|
nsIScrollbarMediator* sm =
|
|
|
|
static_cast<nsScrollbarFrame*>(scrollbar)->GetScrollbarMediator();
|
|
|
|
if (NS_WARN_IF(!sm)) {
|
2022-05-09 20:09:24 +03:00
|
|
|
return ScrollbarDrawing::ScrollbarKind::VerticalRight;
|
|
|
|
}
|
2022-05-13 02:21:05 +03:00
|
|
|
return sm->IsScrollbarOnRight()
|
2022-05-09 20:09:24 +03:00
|
|
|
? ScrollbarDrawing::ScrollbarKind::VerticalRight
|
|
|
|
: ScrollbarDrawing::ScrollbarKind::VerticalLeft;
|
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::DoDrawWidgetBackground(PaintBackendData& aPaintData,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
const nsRect& aRect,
|
|
|
|
DrawOverflow aDrawOverflow) {
|
2021-02-23 13:49:37 +03:00
|
|
|
static_assert(std::is_same_v<PaintBackendData, DrawTarget> ||
|
|
|
|
std::is_same_v<PaintBackendData, WebRenderBackendData>);
|
|
|
|
|
|
|
|
const nsPresContext* pc = aFrame->PresContext();
|
|
|
|
const nscoord twipsPerPixel = pc->AppUnitsPerDevPixel();
|
|
|
|
const auto devPxRect = ToSnappedRect(aRect, twipsPerPixel, aPaintData);
|
|
|
|
|
2022-06-08 02:09:52 +03:00
|
|
|
const DocumentState docState = pc->Document()->GetDocumentState();
|
2022-06-08 02:09:54 +03:00
|
|
|
ElementState elementState = GetContentState(aFrame, aAppearance);
|
2020-03-06 00:13:46 +03:00
|
|
|
if (aAppearance == StyleAppearance::MozMenulistArrowButton) {
|
2020-02-10 22:26:01 +03:00
|
|
|
bool isHTML = IsHTMLContent(aFrame);
|
|
|
|
nsIFrame* parentFrame = aFrame->GetParent();
|
|
|
|
bool isMenulist = !isHTML && parentFrame->IsMenuFrame();
|
|
|
|
// HTML select and XUL menulist dropdown buttons get state from the
|
|
|
|
// parent.
|
|
|
|
if (isHTML || isMenulist) {
|
|
|
|
aFrame = parentFrame;
|
2022-06-08 02:09:54 +03:00
|
|
|
elementState = GetContentState(parentFrame, aAppearance);
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-09 14:45:10 +03:00
|
|
|
// Paint the outline iff we're asked to draw overflow and we have
|
|
|
|
// outline-style: auto.
|
|
|
|
if (aDrawOverflow == DrawOverflow::Yes &&
|
|
|
|
aFrame->StyleOutline()->mOutlineStyle.IsAuto()) {
|
2022-06-08 02:09:54 +03:00
|
|
|
elementState |= ElementState::FOCUSRING;
|
2022-03-09 14:45:10 +03:00
|
|
|
} else {
|
2022-06-08 02:09:54 +03:00
|
|
|
elementState &= ~ElementState::FOCUSRING;
|
2021-03-21 02:08:11 +03:00
|
|
|
}
|
|
|
|
|
2021-01-23 22:31:33 +03:00
|
|
|
// Hack to avoid skia fuzziness: Add a dummy clip if the widget doesn't
|
|
|
|
// overflow devPxRect.
|
|
|
|
Maybe<AutoClipRect> maybeClipRect;
|
2021-02-23 13:49:37 +03:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, DrawTarget>) {
|
|
|
|
if (aAppearance != StyleAppearance::FocusOutline &&
|
|
|
|
aAppearance != StyleAppearance::Range &&
|
2022-06-08 02:09:54 +03:00
|
|
|
!elementState.HasState(ElementState::FOCUSRING)) {
|
2021-02-23 13:49:37 +03:00
|
|
|
maybeClipRect.emplace(aPaintData, devPxRect);
|
|
|
|
}
|
2021-01-23 22:31:33 +03:00
|
|
|
}
|
|
|
|
|
2022-02-09 14:27:16 +03:00
|
|
|
const Colors colors(aFrame, aAppearance);
|
2021-01-27 00:34:35 +03:00
|
|
|
DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
|
2020-02-10 22:26:01 +03:00
|
|
|
|
|
|
|
switch (aAppearance) {
|
2020-02-16 19:04:31 +03:00
|
|
|
case StyleAppearance::Radio: {
|
2021-03-12 14:25:49 +03:00
|
|
|
auto rect = CheckBoxRadioRect(devPxRect);
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintRadioControl(aPaintData, rect, elementState, colors, dpiRatio);
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
2020-02-16 19:04:31 +03:00
|
|
|
}
|
|
|
|
case StyleAppearance::Checkbox: {
|
2021-02-23 13:49:37 +03:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
|
|
|
|
// TODO: Need to figure out how to best draw this using WR.
|
|
|
|
return false;
|
|
|
|
} else {
|
2021-03-12 14:25:49 +03:00
|
|
|
auto rect = CheckBoxRadioRect(devPxRect);
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintCheckboxControl(aPaintData, rect, elementState, colors, dpiRatio);
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
break;
|
2020-02-16 19:04:31 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::NumberInput:
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintTextField(aPaintData, devPxRect, elementState, colors, dpiRatio);
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Listbox:
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintListbox(aPaintData, devPxRect, elementState, colors, dpiRatio);
|
2020-07-30 20:02:02 +03:00
|
|
|
break;
|
2020-07-30 02:58:03 +03:00
|
|
|
case StyleAppearance::MenulistButton:
|
2020-07-30 20:02:02 +03:00
|
|
|
case StyleAppearance::Menulist:
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintMenulist(aPaintData, devPxRect, elementState, colors, dpiRatio);
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
2020-03-06 00:13:46 +03:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2021-02-23 13:49:37 +03:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
|
|
|
|
// TODO: Need to figure out how to best draw this using WR.
|
|
|
|
return false;
|
|
|
|
} else {
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintMenulistArrowButton(aFrame, aPaintData, devPxRect, elementState);
|
2021-02-23 13:49:37 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
2022-10-24 12:05:31 +03:00
|
|
|
case StyleAppearance::Tooltip: {
|
|
|
|
const CSSCoord strokeWidth(1.0f);
|
|
|
|
const CSSCoord strokeRadius(2.0f);
|
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(
|
|
|
|
aPaintData, devPxRect,
|
|
|
|
colors.System(StyleSystemColor::Infobackground),
|
|
|
|
colors.System(StyleSystemColor::Infotext), strokeWidth, strokeRadius,
|
|
|
|
dpiRatio);
|
|
|
|
break;
|
|
|
|
}
|
2022-08-16 12:48:07 +03:00
|
|
|
case StyleAppearance::Menuitem: {
|
|
|
|
ThemeDrawing::FillRect(aPaintData, devPxRect, [&] {
|
|
|
|
if (CheckBooleanAttr(aFrame, nsGkAtoms::menuactive)) {
|
|
|
|
if (elementState.HasState(ElementState::DISABLED)) {
|
|
|
|
return colors.System(StyleSystemColor::MozMenuhoverdisabled);
|
|
|
|
}
|
|
|
|
return colors.System(StyleSystemColor::MozMenuhover);
|
|
|
|
}
|
|
|
|
return sTransparent;
|
|
|
|
}());
|
|
|
|
break;
|
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::SpinnerUpbutton:
|
|
|
|
case StyleAppearance::SpinnerDownbutton:
|
2021-02-23 13:49:37 +03:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
|
|
|
|
// TODO: Need to figure out how to best draw this using WR.
|
|
|
|
return false;
|
|
|
|
} else {
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintSpinnerButton(aFrame, aPaintData, devPxRect, elementState,
|
2021-10-05 12:40:00 +03:00
|
|
|
aAppearance, colors, dpiRatio);
|
2021-02-23 13:49:37 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Range:
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintRange(aFrame, aPaintData, devPxRect, elementState, colors, dpiRatio,
|
2021-10-05 12:40:00 +03:00
|
|
|
IsRangeHorizontal(aFrame));
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::RangeThumb:
|
2020-10-27 02:17:57 +03:00
|
|
|
// Painted as part of StyleAppearance::Range.
|
2020-07-30 20:02:02 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::ProgressBar:
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintProgress(aFrame, aPaintData, devPxRect, elementState, colors,
|
|
|
|
dpiRatio,
|
2021-03-16 00:01:08 +03:00
|
|
|
/* aIsMeter = */ false);
|
2020-07-30 20:02:02 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Progresschunk:
|
2021-03-16 00:01:08 +03:00
|
|
|
/* Painted as part of the progress bar */
|
2020-07-30 20:02:02 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Meter:
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintProgress(aFrame, aPaintData, devPxRect, elementState, colors,
|
|
|
|
dpiRatio,
|
2021-10-05 12:40:00 +03:00
|
|
|
/* aIsMeter = */ true);
|
2020-07-30 20:02:02 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Meterchunk:
|
2021-03-16 00:01:08 +03:00
|
|
|
/* Painted as part of the meter bar */
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarthumbHorizontal:
|
2020-10-27 18:27:31 +03:00
|
|
|
case StyleAppearance::ScrollbarthumbVertical: {
|
|
|
|
bool isHorizontal =
|
|
|
|
aAppearance == StyleAppearance::ScrollbarthumbHorizontal;
|
2022-05-09 20:09:24 +03:00
|
|
|
auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
|
2021-11-15 15:39:38 +03:00
|
|
|
return GetScrollbarDrawing().PaintScrollbarThumb(
|
2022-05-09 20:09:24 +03:00
|
|
|
aPaintData, devPxRect, kind, aFrame,
|
2022-06-08 02:09:54 +03:00
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame), elementState, docState,
|
2021-11-15 15:39:38 +03:00
|
|
|
colors, dpiRatio);
|
2020-10-27 18:27:31 +03:00
|
|
|
}
|
2020-11-02 20:09:00 +03:00
|
|
|
case StyleAppearance::ScrollbartrackHorizontal:
|
|
|
|
case StyleAppearance::ScrollbartrackVertical: {
|
|
|
|
bool isHorizontal =
|
|
|
|
aAppearance == StyleAppearance::ScrollbartrackHorizontal;
|
2022-05-09 20:09:24 +03:00
|
|
|
auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
|
2021-11-15 15:39:38 +03:00
|
|
|
return GetScrollbarDrawing().PaintScrollbarTrack(
|
2022-05-09 20:09:24 +03:00
|
|
|
aPaintData, devPxRect, kind, aFrame,
|
2021-11-15 15:39:38 +03:00
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame), docState, colors,
|
|
|
|
dpiRatio);
|
2020-11-02 20:09:00 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::ScrollbarHorizontal:
|
2020-10-27 18:27:31 +03:00
|
|
|
case StyleAppearance::ScrollbarVertical: {
|
|
|
|
bool isHorizontal = aAppearance == StyleAppearance::ScrollbarHorizontal;
|
2022-05-09 20:09:24 +03:00
|
|
|
auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
|
2021-11-15 15:39:38 +03:00
|
|
|
return GetScrollbarDrawing().PaintScrollbar(
|
2022-05-09 20:09:24 +03:00
|
|
|
aPaintData, devPxRect, kind, aFrame,
|
2022-06-08 02:09:54 +03:00
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame), elementState, docState,
|
2021-11-15 15:39:38 +03:00
|
|
|
colors, dpiRatio);
|
2020-10-27 18:27:31 +03:00
|
|
|
}
|
2022-05-09 20:09:24 +03:00
|
|
|
case StyleAppearance::Scrollcorner: {
|
|
|
|
auto kind = ComputeScrollbarKind(aFrame, false);
|
2021-11-15 15:39:38 +03:00
|
|
|
return GetScrollbarDrawing().PaintScrollCorner(
|
2022-05-09 20:09:24 +03:00
|
|
|
aPaintData, devPxRect, kind, aFrame,
|
2021-11-15 15:39:38 +03:00
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame), docState, colors,
|
|
|
|
dpiRatio);
|
2022-05-09 20:09:24 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
2022-05-09 20:09:24 +03:00
|
|
|
case StyleAppearance::ScrollbarbuttonRight: {
|
2021-01-21 00:54:58 +03:00
|
|
|
// For scrollbar-width:thin, we don't display the buttons.
|
2021-11-15 15:39:38 +03:00
|
|
|
if (!ScrollbarDrawing::IsScrollbarWidthThin(aFrame)) {
|
2021-02-23 13:49:37 +03:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
|
|
|
|
// TODO: Need to figure out how to best draw this using WR.
|
|
|
|
return false;
|
|
|
|
} else {
|
2022-05-09 20:09:24 +03:00
|
|
|
bool isHorizontal =
|
|
|
|
aAppearance == StyleAppearance::ScrollbarbuttonLeft ||
|
|
|
|
aAppearance == StyleAppearance::ScrollbarbuttonRight;
|
|
|
|
auto kind = ComputeScrollbarKind(aFrame, isHorizontal);
|
2021-11-15 15:39:38 +03:00
|
|
|
GetScrollbarDrawing().PaintScrollbarButton(
|
2022-05-09 20:09:24 +03:00
|
|
|
aPaintData, aAppearance, devPxRect, kind, aFrame,
|
2022-06-08 02:09:54 +03:00
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame), elementState, docState,
|
2021-12-27 21:53:31 +03:00
|
|
|
colors, dpiRatio);
|
2021-02-23 13:49:37 +03:00
|
|
|
}
|
2021-01-21 00:54:58 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
2022-05-09 20:09:24 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::Button:
|
2022-06-08 02:09:54 +03:00
|
|
|
PaintButton(aFrame, aPaintData, devPxRect, elementState, colors,
|
|
|
|
dpiRatio);
|
2020-02-10 22:26:01 +03:00
|
|
|
break;
|
2020-11-16 19:53:23 +03:00
|
|
|
case StyleAppearance::FocusOutline:
|
2021-10-05 12:40:00 +03:00
|
|
|
PaintAutoStyleOutline(aFrame, aPaintData, devPxRect, colors, dpiRatio);
|
2020-11-16 19:53:23 +03:00
|
|
|
break;
|
2020-02-10 22:26:01 +03:00
|
|
|
default:
|
2021-01-11 01:25:07 +03:00
|
|
|
// Various appearance values are used for XUL elements. Normally these
|
|
|
|
// will not be available in content documents (and thus in the content
|
2021-01-29 01:11:54 +03:00
|
|
|
// processes where the native basic theme can be used), but tests are
|
|
|
|
// run with the remote XUL pref enabled and so we can get in here. So
|
|
|
|
// we just return an error rather than assert.
|
2021-02-23 13:49:37 +03:00
|
|
|
return false;
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
return true;
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
template <typename PaintBackendData>
|
2022-01-12 19:33:31 +03:00
|
|
|
void Theme::PaintAutoStyleOutline(nsIFrame* aFrame,
|
|
|
|
PaintBackendData& aPaintData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
const Colors& aColors, DPIRatio aDpiRatio) {
|
2022-07-20 14:43:35 +03:00
|
|
|
const auto& accentColor = aColors.Accent();
|
|
|
|
const bool solid = StaticPrefs::widget_non_native_theme_solid_outline_style();
|
|
|
|
LayoutDeviceCoord strokeWidth(ThemeDrawing::SnapBorderWidth(2.0f, aDpiRatio));
|
2021-02-08 19:25:16 +03:00
|
|
|
|
2021-02-23 07:41:58 +03:00
|
|
|
LayoutDeviceRect rect(aRect);
|
2022-07-20 14:43:35 +03:00
|
|
|
rect.Inflate(strokeWidth);
|
2021-02-08 19:25:16 +03:00
|
|
|
|
2022-07-20 14:43:35 +03:00
|
|
|
const nscoord a2d = aFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
nscoord cssOffset = aFrame->StyleOutline()->mOutlineOffset.ToAppUnits();
|
|
|
|
nscoord cssRadii[8] = {0};
|
2021-02-08 19:25:16 +03:00
|
|
|
if (!aFrame->GetBorderRadii(cssRadii)) {
|
2022-07-20 14:43:35 +03:00
|
|
|
const auto twoPixels = 2 * AppUnitsPerCSSPixel();
|
|
|
|
const nscoord radius =
|
|
|
|
cssOffset >= 0 ? twoPixels : std::max(twoPixels + cssOffset, 0);
|
|
|
|
cssOffset = -twoPixels;
|
|
|
|
for (auto& r : cssRadii) {
|
|
|
|
r = radius;
|
|
|
|
}
|
2021-02-08 19:25:16 +03:00
|
|
|
}
|
|
|
|
|
2022-07-20 14:43:35 +03:00
|
|
|
auto offset = LayoutDeviceCoord::FromAppUnits(cssOffset, a2d);
|
2021-02-08 19:25:16 +03:00
|
|
|
RectCornerRadii innerRadii;
|
2022-07-20 14:43:35 +03:00
|
|
|
nsCSSRendering::ComputePixelRadii(cssRadii, a2d, &innerRadii);
|
2021-02-08 19:25:16 +03:00
|
|
|
|
2021-02-23 13:49:37 +03:00
|
|
|
// NOTE(emilio): This doesn't use PaintRoundedRectWithRadius because we need
|
|
|
|
// to support arbitrary radii.
|
2022-07-20 14:43:35 +03:00
|
|
|
auto DrawRect = [&](const sRGBColor& aColor) {
|
|
|
|
RectCornerRadii outerRadii;
|
|
|
|
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
|
|
|
|
const Float widths[4] = {strokeWidth + offset, strokeWidth + offset,
|
|
|
|
strokeWidth + offset, strokeWidth + offset};
|
|
|
|
nsCSSBorderRenderer::ComputeOuterRadii(innerRadii, widths, &outerRadii);
|
|
|
|
const auto dest = wr::ToLayoutRect(rect);
|
|
|
|
const auto side =
|
|
|
|
wr::ToBorderSide(ToDeviceColor(aColor), StyleBorderStyle::Solid);
|
|
|
|
const wr::BorderSide sides[4] = {side, side, side, side};
|
|
|
|
const bool kBackfaceIsVisible = true;
|
|
|
|
const auto wrWidths = wr::ToBorderWidths(strokeWidth, strokeWidth,
|
|
|
|
strokeWidth, strokeWidth);
|
|
|
|
const auto wrRadius = wr::ToBorderRadius(outerRadii);
|
|
|
|
aPaintData.mBuilder.PushBorder(dest, dest, kBackfaceIsVisible, wrWidths,
|
|
|
|
{sides, 4}, wrRadius);
|
|
|
|
} else {
|
|
|
|
const LayoutDeviceCoord halfWidth = strokeWidth * 0.5f;
|
|
|
|
const Float widths[4] = {halfWidth + offset, halfWidth + offset,
|
|
|
|
halfWidth + offset, halfWidth + offset};
|
|
|
|
nsCSSBorderRenderer::ComputeOuterRadii(innerRadii, widths, &outerRadii);
|
|
|
|
LayoutDeviceRect dest(rect);
|
|
|
|
dest.Deflate(halfWidth);
|
|
|
|
RefPtr<Path> path =
|
|
|
|
MakePathForRoundedRect(aPaintData, dest.ToUnknownRect(), outerRadii);
|
|
|
|
aPaintData.Stroke(path, ColorPattern(ToDeviceColor(aColor)),
|
|
|
|
StrokeOptions(strokeWidth));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DrawRect(accentColor.Get());
|
|
|
|
|
|
|
|
if (solid) {
|
|
|
|
return;
|
2021-02-23 13:49:37 +03:00
|
|
|
}
|
2022-07-20 14:43:35 +03:00
|
|
|
|
|
|
|
offset += strokeWidth;
|
|
|
|
|
|
|
|
strokeWidth =
|
|
|
|
LayoutDeviceCoord(ThemeDrawing::SnapBorderWidth(1.0f, aDpiRatio));
|
|
|
|
rect.Inflate(strokeWidth);
|
|
|
|
|
|
|
|
DrawRect(accentColor.GetForeground());
|
2021-02-23 13:49:37 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
LayoutDeviceIntMargin Theme::GetWidgetBorder(nsDeviceContext* aContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance) {
|
2020-03-11 04:52:51 +03:00
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::Textarea:
|
2021-01-30 00:18:54 +03:00
|
|
|
case StyleAppearance::NumberInput:
|
2020-03-11 04:52:51 +03:00
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::Menulist:
|
2021-01-30 00:18:54 +03:00
|
|
|
case StyleAppearance::MenulistButton:
|
|
|
|
case StyleAppearance::Button:
|
|
|
|
// Return the border size from the UA sheet, even though what we paint
|
|
|
|
// doesn't actually match that. We know this is the UA sheet border
|
|
|
|
// because we disable native theming when different border widths are
|
2022-01-12 19:33:31 +03:00
|
|
|
// specified by authors, see Theme::IsWidgetStyled.
|
2021-01-30 00:18:54 +03:00
|
|
|
//
|
|
|
|
// The Rounded() bit is technically redundant, but needed to appease the
|
|
|
|
// type system, we should always end up with full device pixels due to
|
|
|
|
// round_border_to_device_pixels at style time.
|
|
|
|
return LayoutDeviceIntMargin::FromAppUnits(
|
|
|
|
aFrame->StyleBorder()->GetComputedBorder(),
|
|
|
|
aFrame->PresContext()->AppUnitsPerDevPixel())
|
|
|
|
.Rounded();
|
2021-01-20 23:08:35 +03:00
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
case StyleAppearance::Radio: {
|
2021-01-30 00:18:54 +03:00
|
|
|
DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
|
2021-01-27 01:12:03 +03:00
|
|
|
LayoutDeviceIntCoord w =
|
2021-11-15 15:39:38 +03:00
|
|
|
ThemeDrawing::SnapBorderWidth(kCheckboxRadioBorderWidth, dpiRatio);
|
2021-01-20 23:08:35 +03:00
|
|
|
return LayoutDeviceIntMargin(w, w, w, w);
|
|
|
|
}
|
2020-03-11 04:52:51 +03:00
|
|
|
default:
|
2020-12-03 02:11:32 +03:00
|
|
|
return LayoutDeviceIntMargin();
|
2020-03-11 04:52:51 +03:00
|
|
|
}
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::GetWidgetPadding(nsDeviceContext* aContext, nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
LayoutDeviceIntMargin* aResult) {
|
2020-02-10 22:26:01 +03:00
|
|
|
switch (aAppearance) {
|
|
|
|
// Radios and checkboxes return a fixed size in GetMinimumWidgetSize
|
|
|
|
// and have a meaningful baseline, so they can't have
|
|
|
|
// author-specified padding.
|
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
aResult->SizeTo(0, 0, 0, 0);
|
|
|
|
return true;
|
2020-03-25 01:51:26 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-01-22 00:38:33 +03:00
|
|
|
return false;
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::GetWidgetOverflow(nsDeviceContext* aContext, nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
nsRect* aOverflowRect) {
|
2022-06-28 21:52:19 +03:00
|
|
|
CSSIntMargin overflow;
|
2020-07-30 20:02:02 +03:00
|
|
|
switch (aAppearance) {
|
2022-07-20 14:43:35 +03:00
|
|
|
case StyleAppearance::FocusOutline: {
|
|
|
|
// 2px * one segment, or 2px + 1px
|
|
|
|
const auto width =
|
|
|
|
StaticPrefs::widget_non_native_theme_solid_outline_style() ? 2 : 3;
|
|
|
|
overflow.SizeTo(width, width, width, width);
|
2020-11-16 19:53:23 +03:00
|
|
|
break;
|
2022-07-20 14:43:35 +03:00
|
|
|
}
|
2020-07-30 20:02:02 +03:00
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
case StyleAppearance::Range:
|
2021-02-24 02:22:19 +03:00
|
|
|
// 2px for each outline segment, plus 1px separation, plus we paint with a
|
|
|
|
// 1px extra offset, so 6px.
|
2020-07-30 20:02:02 +03:00
|
|
|
overflow.SizeTo(6, 6, 6, 6);
|
|
|
|
break;
|
2020-07-31 18:16:34 +03:00
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::NumberInput:
|
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::MenulistButton:
|
|
|
|
case StyleAppearance::Menulist:
|
|
|
|
case StyleAppearance::Button:
|
2021-01-29 01:11:54 +03:00
|
|
|
// 2px for each segment, plus 1px separation, but we paint 1px inside
|
|
|
|
// the border area so 4px overflow.
|
2020-07-30 20:02:02 +03:00
|
|
|
overflow.SizeTo(4, 4, 4, 4);
|
|
|
|
break;
|
2020-07-31 18:16:34 +03:00
|
|
|
default:
|
|
|
|
return false;
|
2020-07-30 20:02:02 +03:00
|
|
|
}
|
|
|
|
|
2020-11-02 20:09:05 +03:00
|
|
|
// TODO: This should convert from device pixels to app units, not from CSS
|
|
|
|
// pixels. And it should take the dpi ratio into account.
|
|
|
|
// Using CSS pixels can cause the overflow to be too small if the page is
|
|
|
|
// zoomed out.
|
2022-06-28 21:52:19 +03:00
|
|
|
aOverflowRect->Inflate(CSSPixel::ToAppUnits(overflow));
|
2020-07-30 20:02:02 +03:00
|
|
|
return true;
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
auto Theme::GetScrollbarSizes(nsPresContext* aPresContext,
|
|
|
|
StyleScrollbarWidth aWidth, Overlay aOverlay)
|
|
|
|
-> ScrollbarSizes {
|
2021-11-15 15:39:38 +03:00
|
|
|
return GetScrollbarDrawing().GetScrollbarSizes(aPresContext, aWidth,
|
|
|
|
aOverlay);
|
2021-01-29 01:11:54 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
nscoord Theme::GetCheckboxRadioPrefSize() {
|
2021-03-02 01:55:37 +03:00
|
|
|
return CSSPixel::ToAppUnits(kCheckboxRadioContentBoxSize);
|
2021-02-20 03:13:10 +03:00
|
|
|
}
|
|
|
|
|
2021-11-15 15:39:39 +03:00
|
|
|
/* static */
|
2022-01-12 19:33:31 +03:00
|
|
|
UniquePtr<ScrollbarDrawing> Theme::ScrollbarStyle() {
|
2021-11-15 15:39:39 +03:00
|
|
|
switch (StaticPrefs::widget_non_native_theme_scrollbar_style()) {
|
|
|
|
case 1:
|
|
|
|
return MakeUnique<ScrollbarDrawingCocoa>();
|
|
|
|
case 2:
|
|
|
|
return MakeUnique<ScrollbarDrawingGTK>();
|
|
|
|
case 3:
|
|
|
|
return MakeUnique<ScrollbarDrawingAndroid>();
|
|
|
|
case 4:
|
|
|
|
return MakeUnique<ScrollbarDrawingWin>();
|
2021-12-16 00:06:58 +03:00
|
|
|
case 5:
|
|
|
|
return MakeUnique<ScrollbarDrawingWin11>();
|
2021-11-15 15:39:39 +03:00
|
|
|
default:
|
2022-01-26 00:31:44 +03:00
|
|
|
break;
|
2021-11-15 15:39:39 +03:00
|
|
|
}
|
2022-01-31 20:00:21 +03:00
|
|
|
// Default to native scrollbar style for each platform.
|
2021-11-15 15:39:39 +03:00
|
|
|
#ifdef XP_WIN
|
2021-12-16 00:06:58 +03:00
|
|
|
if (IsWin11OrLater()) {
|
|
|
|
return MakeUnique<ScrollbarDrawingWin11>();
|
|
|
|
}
|
2021-11-15 15:39:39 +03:00
|
|
|
return MakeUnique<ScrollbarDrawingWin>();
|
|
|
|
#elif MOZ_WIDGET_COCOA
|
|
|
|
return MakeUnique<ScrollbarDrawingCocoa>();
|
|
|
|
#elif MOZ_WIDGET_GTK
|
|
|
|
return MakeUnique<ScrollbarDrawingGTK>();
|
|
|
|
#elif ANDROID
|
|
|
|
return MakeUnique<ScrollbarDrawingAndroid>();
|
|
|
|
#else
|
|
|
|
# error "Unknown platform, need scrollbar implementation."
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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 22:09:29 +03:00
|
|
|
LayoutDeviceIntSize Theme::GetMinimumWidgetSize(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance) {
|
2021-01-27 00:34:35 +03:00
|
|
|
DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
|
2020-07-30 20:02:02 +03:00
|
|
|
|
2021-11-15 15:39:38 +03:00
|
|
|
if (IsWidgetScrollbarPart(aAppearance)) {
|
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 22:09:29 +03:00
|
|
|
return GetScrollbarDrawing().GetMinimumWidgetSize(aPresContext, aAppearance,
|
|
|
|
aFrame);
|
2021-11-15 15:39:38 +03:00
|
|
|
}
|
|
|
|
|
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 22:09:29 +03:00
|
|
|
LayoutDeviceIntSize result;
|
2020-07-30 20:02:02 +03:00
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::RangeThumb:
|
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 22:09:29 +03:00
|
|
|
result.SizeTo((kMinimumRangeThumbSize * dpiRatio).Rounded(),
|
|
|
|
(kMinimumRangeThumbSize * dpiRatio).Rounded());
|
2020-07-30 20:02:02 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
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 22:09:29 +03:00
|
|
|
result.width = (kMinimumDropdownArrowButtonWidth * dpiRatio).Rounded();
|
2020-07-30 20:02:02 +03:00
|
|
|
break;
|
|
|
|
case StyleAppearance::SpinnerUpbutton:
|
|
|
|
case StyleAppearance::SpinnerDownbutton:
|
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 22:09:29 +03:00
|
|
|
result.width = (kMinimumSpinnerButtonWidth * dpiRatio).Rounded();
|
|
|
|
result.height = (kMinimumSpinnerButtonHeight * dpiRatio).Rounded();
|
2020-07-30 20:02:02 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
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 22:09:29 +03:00
|
|
|
return result;
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
nsITheme::Transparency Theme::GetWidgetTransparency(
|
2021-11-15 15:39:38 +03:00
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
|
|
|
return GetScrollbarDrawing()
|
|
|
|
.GetScrollbarPartTransparency(aFrame, aAppearance)
|
|
|
|
.valueOr(eUnknownTransparency);
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2022-01-12 19:33:31 +03:00
|
|
|
Theme::WidgetStateChanged(nsIFrame* aFrame, StyleAppearance aAppearance,
|
|
|
|
nsAtom* aAttribute, bool* aShouldRepaint,
|
|
|
|
const nsAttrValue* aOldValue) {
|
2020-02-10 22:26:01 +03:00
|
|
|
if (!aAttribute) {
|
|
|
|
// Hover/focus/active changed. Always repaint.
|
|
|
|
*aShouldRepaint = true;
|
|
|
|
} else {
|
|
|
|
// Check the attribute to see if it's relevant.
|
|
|
|
// disabled, checked, dlgtype, default, etc.
|
|
|
|
*aShouldRepaint = false;
|
2021-05-11 16:57:18 +03:00
|
|
|
if (aAttribute == nsGkAtoms::disabled || aAttribute == nsGkAtoms::checked ||
|
|
|
|
aAttribute == nsGkAtoms::selected ||
|
|
|
|
aAttribute == nsGkAtoms::visuallyselected ||
|
|
|
|
aAttribute == nsGkAtoms::menuactive ||
|
|
|
|
aAttribute == nsGkAtoms::sortDirection ||
|
|
|
|
aAttribute == nsGkAtoms::focused || aAttribute == nsGkAtoms::_default ||
|
|
|
|
aAttribute == nsGkAtoms::open || aAttribute == nsGkAtoms::hover) {
|
2020-02-10 22:26:01 +03:00
|
|
|
*aShouldRepaint = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2022-01-12 19:33:31 +03:00
|
|
|
Theme::ThemeChanged() { return NS_OK; }
|
2020-02-10 22:26:01 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::WidgetAppearanceDependsOnWindowFocus(StyleAppearance aAppearance) {
|
2020-10-15 07:54:41 +03:00
|
|
|
return IsWidgetScrollbarPart(aAppearance);
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
nsITheme::ThemeGeometryType Theme::ThemeGeometryTypeForWidget(
|
2020-02-10 22:26:01 +03:00
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
|
|
|
return eThemeGeometryTypeUnknown;
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::ThemeSupportsWidget(nsPresContext* aPresContext, nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance) {
|
2020-02-10 22:26:01 +03:00
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
2020-11-16 19:53:23 +03:00
|
|
|
case StyleAppearance::FocusOutline:
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::Range:
|
2020-03-06 20:54:04 +03:00
|
|
|
case StyleAppearance::RangeThumb:
|
2020-07-30 20:02:02 +03:00
|
|
|
case StyleAppearance::ProgressBar:
|
|
|
|
case StyleAppearance::Progresschunk:
|
|
|
|
case StyleAppearance::Meter:
|
|
|
|
case StyleAppearance::Meterchunk:
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
|
|
|
case StyleAppearance::ScrollbarthumbHorizontal:
|
|
|
|
case StyleAppearance::ScrollbarthumbVertical:
|
2020-11-02 20:09:00 +03:00
|
|
|
case StyleAppearance::ScrollbartrackHorizontal:
|
|
|
|
case StyleAppearance::ScrollbartrackVertical:
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::ScrollbarHorizontal:
|
|
|
|
case StyleAppearance::ScrollbarVertical:
|
|
|
|
case StyleAppearance::Scrollcorner:
|
|
|
|
case StyleAppearance::Button:
|
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::Menulist:
|
2020-02-19 17:48:43 +03:00
|
|
|
case StyleAppearance::MenulistButton:
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::NumberInput:
|
2020-03-06 00:13:46 +03:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::SpinnerUpbutton:
|
|
|
|
case StyleAppearance::SpinnerDownbutton:
|
2022-08-16 12:48:07 +03:00
|
|
|
case StyleAppearance::Menuitem:
|
2022-10-24 12:05:31 +03:00
|
|
|
case StyleAppearance::Tooltip:
|
2020-02-10 22:26:01 +03:00
|
|
|
return !IsWidgetStyled(aPresContext, aFrame, aAppearance);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::WidgetIsContainer(StyleAppearance aAppearance) {
|
2020-02-10 22:26:01 +03:00
|
|
|
switch (aAppearance) {
|
2020-03-06 00:13:46 +03:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2020-02-10 22:26:01 +03:00
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::ThemeDrawsFocusForWidget(nsIFrame*, StyleAppearance) {
|
2020-07-30 20:02:02 +03:00
|
|
|
return true;
|
2020-02-10 22:26:01 +03:00
|
|
|
}
|
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::ThemeNeedsComboboxDropmarker() { return true; }
|
2021-11-15 15:39:38 +03:00
|
|
|
|
2022-01-12 19:33:31 +03:00
|
|
|
bool Theme::ThemeSupportsScrollbarButtons() {
|
2021-11-15 15:39:38 +03:00
|
|
|
return GetScrollbarDrawing().ShouldDrawScrollbarButtons();
|
|
|
|
}
|
2022-01-12 19:33:31 +03:00
|
|
|
|
|
|
|
} // namespace mozilla::widget
|