2020-02-10 19:26:01 +00: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/. */
|
|
|
|
|
|
|
|
#include "nsNativeBasicTheme.h"
|
|
|
|
|
2020-11-02 17:09:05 +00:00
|
|
|
#include "gfxBlur.h"
|
2021-01-26 01:35:04 +00:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2020-11-02 17:09:05 +00:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
|
|
|
#include "mozilla/gfx/Types.h"
|
|
|
|
#include "mozilla/gfx/Filters.h"
|
2021-02-04 16:15:27 +00:00
|
|
|
#include "mozilla/RelativeLuminanceUtils.h"
|
2021-02-10 00:47:38 +00:00
|
|
|
#include "mozilla/StaticPrefs_widget.h"
|
2021-02-23 10:49:37 +00:00
|
|
|
#include "mozilla/webrender/WebRenderAPI.h"
|
2020-10-15 04:54:41 +00:00
|
|
|
#include "nsCSSColorUtils.h"
|
2020-02-10 19:26:01 +00:00
|
|
|
#include "nsCSSRendering.h"
|
2020-09-30 21:06:47 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2020-02-10 19:26:01 +00:00
|
|
|
#include "PathHelpers.h"
|
|
|
|
|
2021-02-10 00:47:38 +00:00
|
|
|
#include "nsDeviceContext.h"
|
|
|
|
|
|
|
|
#include "nsColorControlFrame.h"
|
|
|
|
#include "nsDateTimeControlFrame.h"
|
|
|
|
#include "nsMeterFrame.h"
|
|
|
|
#include "nsProgressFrame.h"
|
|
|
|
#include "nsRangeFrame.h"
|
|
|
|
#include "mozilla/dom/HTMLMeterElement.h"
|
|
|
|
#include "mozilla/dom/HTMLProgressElement.h"
|
|
|
|
|
2020-07-31 12:04:29 +00:00
|
|
|
using namespace mozilla;
|
2020-02-10 19:26:01 +00:00
|
|
|
using namespace mozilla::widget;
|
2020-07-31 12:04:29 +00:00
|
|
|
using namespace mozilla::gfx;
|
2020-02-10 19:26:01 +00:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsNativeBasicTheme, nsNativeTheme, nsITheme)
|
|
|
|
|
2021-01-23 19:31:33 +00:00
|
|
|
namespace {
|
|
|
|
|
2021-03-05 01:35:17 +00:00
|
|
|
static constexpr sRGBColor sTransparent = sRGBColor::White(0.0);
|
|
|
|
|
2021-01-23 19:31:33 +00: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;
|
|
|
|
};
|
|
|
|
|
2021-01-26 22:12:03 +00:00
|
|
|
static LayoutDeviceIntCoord SnapBorderWidth(
|
|
|
|
CSSCoord aCssWidth, nsNativeBasicTheme::DPIRatio aDpiRatio) {
|
|
|
|
if (aCssWidth == 0.0f) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return std::max(LayoutDeviceIntCoord(1), (aCssWidth * aDpiRatio).Truncated());
|
|
|
|
}
|
|
|
|
|
2021-02-10 00:47:38 +00:00
|
|
|
[[nodiscard]] static float ScaleLuminanceBy(float aLuminance, float aFactor) {
|
|
|
|
return aLuminance >= 0.18f ? aLuminance * aFactor : aLuminance / aFactor;
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:41:00 +00:00
|
|
|
struct ColorPalette {
|
|
|
|
ColorPalette(nscolor aAccent, nscolor aForeground);
|
|
|
|
|
|
|
|
constexpr ColorPalette(sRGBColor aAccent, sRGBColor aForeground,
|
|
|
|
sRGBColor aLight, sRGBColor aDark, sRGBColor aDarker)
|
|
|
|
: mAccent(aAccent),
|
|
|
|
mForeground(aForeground),
|
|
|
|
mAccentLight(aLight),
|
|
|
|
mAccentDark(aDark),
|
|
|
|
mAccentDarker(aDarker) {}
|
|
|
|
|
|
|
|
constexpr static ColorPalette Default() {
|
|
|
|
return ColorPalette(
|
2021-07-27 17:12:15 +00:00
|
|
|
sDefaultAccent, sDefaultAccentForeground,
|
2021-04-27 10:41:00 +00:00
|
|
|
sRGBColor::UnusualFromARGB(0x4d008deb), // Luminance: 25.04791%
|
|
|
|
sRGBColor::UnusualFromARGB(0xff0250bb), // Luminance: 9.33808%
|
|
|
|
sRGBColor::UnusualFromARGB(0xff054096) // Luminance: 5.90106%
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure accent color is opaque by blending with white. This serves two
|
|
|
|
// purposes: On one hand, it avoids surprises if we overdraw. On the other, it
|
|
|
|
// makes our math below make more sense, as we want to match the browser
|
|
|
|
// style, which has an opaque accent color.
|
|
|
|
static nscolor EnsureOpaque(nscolor aAccent) {
|
|
|
|
if (NS_GET_A(aAccent) != 0xff) {
|
|
|
|
return NS_ComposeColors(NS_RGB(0xff, 0xff, 0xff), aAccent);
|
|
|
|
}
|
|
|
|
return aAccent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscolor GetLight(nscolor aAccent) {
|
|
|
|
// The luminance from the light color divided by the one of the accent color
|
|
|
|
// in the default palette.
|
|
|
|
constexpr float kLightLuminanceScale = 25.048f / 13.693f;
|
|
|
|
const float lightLuminanceAdjust = ScaleLuminanceBy(
|
|
|
|
RelativeLuminanceUtils::Compute(aAccent), kLightLuminanceScale);
|
|
|
|
nscolor lightColor =
|
|
|
|
RelativeLuminanceUtils::Adjust(aAccent, lightLuminanceAdjust);
|
|
|
|
return NS_RGBA(NS_GET_R(lightColor), NS_GET_G(lightColor),
|
|
|
|
NS_GET_B(lightColor), 0x4d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscolor GetDark(nscolor aAccent) {
|
|
|
|
// Same deal as above (but without the alpha).
|
|
|
|
constexpr float kDarkLuminanceScale = 9.338f / 13.693f;
|
|
|
|
const float darkLuminanceAdjust = ScaleLuminanceBy(
|
|
|
|
RelativeLuminanceUtils::Compute(aAccent), kDarkLuminanceScale);
|
|
|
|
return RelativeLuminanceUtils::Adjust(aAccent, darkLuminanceAdjust);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscolor GetDarker(nscolor aAccent) {
|
|
|
|
// Same deal as above.
|
|
|
|
constexpr float kDarkerLuminanceScale = 5.901f / 13.693f;
|
|
|
|
const float darkerLuminanceAdjust = ScaleLuminanceBy(
|
|
|
|
RelativeLuminanceUtils::Compute(aAccent), kDarkerLuminanceScale);
|
|
|
|
return RelativeLuminanceUtils::Adjust(aAccent, darkerLuminanceAdjust);
|
|
|
|
}
|
|
|
|
|
|
|
|
sRGBColor mAccent;
|
|
|
|
sRGBColor mForeground;
|
|
|
|
|
|
|
|
// Note that depending on the exact accent color, lighter/darker might really
|
|
|
|
// be inverted.
|
|
|
|
sRGBColor mAccentLight;
|
|
|
|
sRGBColor mAccentDark;
|
|
|
|
sRGBColor mAccentDarker;
|
|
|
|
};
|
|
|
|
|
2021-02-11 16:36:54 +00:00
|
|
|
static nscolor ThemedAccentColor(bool aBackground) {
|
2021-02-22 20:05:35 +00:00
|
|
|
MOZ_ASSERT(StaticPrefs::widget_non_native_theme_use_theme_accent());
|
2021-04-02 12:22:14 +00:00
|
|
|
// TODO(emilio): In the future we should probably add dark-color-scheme
|
|
|
|
// support for non-native form controls.
|
2021-04-27 10:41:00 +00:00
|
|
|
return ColorPalette::EnsureOpaque(LookAndFeel::Color(
|
2021-02-11 16:36:54 +00:00
|
|
|
aBackground ? LookAndFeel::ColorID::MozAccentColor
|
2021-04-02 12:22:14 +00:00
|
|
|
: LookAndFeel::ColorID::MozAccentColorForeground,
|
2021-04-27 10:41:00 +00:00
|
|
|
LookAndFeel::ColorScheme::Light, LookAndFeel::UseStandins::No));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ColorPalette sDefaultPalette = ColorPalette::Default();
|
|
|
|
|
|
|
|
ColorPalette::ColorPalette(nscolor aAccent, nscolor aForeground) {
|
|
|
|
mAccent = sRGBColor::FromABGR(aAccent);
|
|
|
|
mForeground = sRGBColor::FromABGR(aForeground);
|
|
|
|
mAccentLight = sRGBColor::FromABGR(GetLight(aAccent));
|
|
|
|
mAccentDark = sRGBColor::FromABGR(GetDark(aAccent));
|
|
|
|
mAccentDarker = sRGBColor::FromABGR(GetDarker(aAccent));
|
2021-02-10 00:47:38 +00:00
|
|
|
}
|
|
|
|
|
2021-07-27 17:12:15 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
nscolor nsNativeBasicTheme::ComputeCustomAccentForeground(nscolor aColor) {
|
2021-07-24 13:30:25 +00:00
|
|
|
// Contrast ratio is defined in
|
|
|
|
// https://www.w3.org/TR/WCAG20/#contrast-ratiodef as:
|
|
|
|
//
|
|
|
|
// (L1 + 0.05) / (L2 + 0.05)
|
|
|
|
//
|
|
|
|
// Where L1 is the lighter color, and L2 is the darker one. So we determine
|
|
|
|
// whether we're dark or light and resolve the equation for the target ratio.
|
|
|
|
//
|
|
|
|
// So when lightening:
|
|
|
|
//
|
|
|
|
// L1 = k * (L2 + 0.05) - 0.05
|
|
|
|
//
|
|
|
|
// And when darkening:
|
|
|
|
//
|
|
|
|
// L2 = (L1 + 0.05) / k - 0.05
|
|
|
|
//
|
|
|
|
const float luminance = RelativeLuminanceUtils::Compute(aColor);
|
|
|
|
|
|
|
|
// We generally prefer white unless we can't because the color is really light
|
|
|
|
// and we can't provide reasonable contrast.
|
|
|
|
const float ratioWithWhite = 1.05f / (luminance + 0.05f);
|
|
|
|
const bool canBeWhite =
|
|
|
|
ratioWithWhite >=
|
|
|
|
StaticPrefs::layout_css_accent_color_min_contrast_ratio();
|
|
|
|
if (canBeWhite) {
|
|
|
|
return NS_RGB(0xff, 0xff, 0xff);
|
|
|
|
}
|
|
|
|
const float targetRatio =
|
|
|
|
StaticPrefs::layout_css_accent_color_darkening_target_contrast_ratio();
|
|
|
|
const float targetLuminance = (luminance + 0.05f) / targetRatio - 0.05f;
|
|
|
|
return RelativeLuminanceUtils::Adjust(aColor, targetLuminance);
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:41:00 +00:00
|
|
|
class nsNativeBasicTheme::AccentColor {
|
|
|
|
Maybe<nscolor> mAccentColor;
|
|
|
|
|
|
|
|
public:
|
|
|
|
AccentColor() = default;
|
|
|
|
|
|
|
|
explicit AccentColor(const ComputedStyle& aStyle) {
|
|
|
|
const auto& color = aStyle.StyleUI()->mAccentColor;
|
|
|
|
if (color.IsColor()) {
|
|
|
|
mAccentColor.emplace(
|
|
|
|
ColorPalette::EnsureOpaque(color.AsColor().CalcColor(aStyle)));
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(color.IsAuto());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sRGBColor Get() const {
|
|
|
|
if (!mAccentColor) {
|
|
|
|
return sDefaultPalette.mAccent;
|
|
|
|
}
|
|
|
|
return sRGBColor::FromABGR(*mAccentColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
sRGBColor GetForeground() const {
|
|
|
|
if (!mAccentColor) {
|
|
|
|
return sDefaultPalette.mForeground;
|
|
|
|
}
|
2021-07-24 13:30:25 +00:00
|
|
|
return sRGBColor::FromABGR(ComputeCustomAccentForeground(*mAccentColor));
|
2021-04-27 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sRGBColor GetLight() const {
|
|
|
|
if (!mAccentColor) {
|
|
|
|
return sDefaultPalette.mAccentLight;
|
|
|
|
}
|
|
|
|
return sRGBColor::FromABGR(ColorPalette::GetLight(*mAccentColor));
|
|
|
|
}
|
|
|
|
|
|
|
|
sRGBColor GetDark() const {
|
|
|
|
if (!mAccentColor) {
|
|
|
|
return sDefaultPalette.mAccentDark;
|
|
|
|
}
|
|
|
|
return sRGBColor::FromABGR(ColorPalette::GetDark(*mAccentColor));
|
|
|
|
}
|
|
|
|
|
|
|
|
sRGBColor GetDarker() const {
|
|
|
|
if (!mAccentColor) {
|
|
|
|
return sDefaultPalette.mAccentDarker;
|
|
|
|
}
|
|
|
|
return sRGBColor::FromABGR(ColorPalette::GetDarker(*mAccentColor));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-18 19:12:49 +00:00
|
|
|
CSSIntCoord nsNativeBasicTheme::sHorizontalScrollbarHeight = CSSIntCoord(0);
|
|
|
|
CSSIntCoord nsNativeBasicTheme::sVerticalScrollbarWidth = CSSIntCoord(0);
|
2021-03-30 03:31:21 +00:00
|
|
|
bool nsNativeBasicTheme::sOverlayScrollbars = false;
|
2021-03-18 19:12:49 +00:00
|
|
|
|
|
|
|
static constexpr nsLiteralCString kPrefs[] = {
|
|
|
|
"widget.non-native-theme.use-theme-accent"_ns,
|
|
|
|
"widget.non-native-theme.win.scrollbar.use-system-size"_ns,
|
|
|
|
"widget.non-native-theme.scrollbar.size"_ns,
|
|
|
|
};
|
2021-02-10 00:47:38 +00:00
|
|
|
|
|
|
|
void nsNativeBasicTheme::Init() {
|
2021-03-18 19:12:49 +00:00
|
|
|
for (const auto& pref : kPrefs) {
|
|
|
|
Preferences::RegisterCallback(PrefChangedCallback, pref);
|
|
|
|
}
|
|
|
|
LookAndFeelChanged();
|
2021-02-10 00:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsNativeBasicTheme::Shutdown() {
|
2021-03-18 19:12:49 +00:00
|
|
|
for (const auto& pref : kPrefs) {
|
|
|
|
Preferences::UnregisterCallback(PrefChangedCallback, pref);
|
|
|
|
}
|
2021-02-10 00:47:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 19:12:49 +00:00
|
|
|
void nsNativeBasicTheme::LookAndFeelChanged() {
|
|
|
|
RecomputeAccentColors();
|
2021-03-30 03:31:21 +00:00
|
|
|
RecomputeScrollbarParams();
|
2021-03-18 19:12:49 +00:00
|
|
|
}
|
2021-02-10 00:47:38 +00:00
|
|
|
|
|
|
|
void nsNativeBasicTheme::RecomputeAccentColors() {
|
|
|
|
MOZ_RELEASE_ASSERT(NS_IsMainThread());
|
|
|
|
|
2021-02-22 20:05:35 +00:00
|
|
|
if (!StaticPrefs::widget_non_native_theme_use_theme_accent()) {
|
2021-04-27 10:41:00 +00:00
|
|
|
sDefaultPalette = ColorPalette::Default();
|
2021-02-10 00:47:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:41:00 +00:00
|
|
|
sDefaultPalette =
|
|
|
|
ColorPalette(ThemedAccentColor(true), ThemedAccentColor(false));
|
2021-02-10 00:47:38 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 03:31:21 +00:00
|
|
|
void nsNativeBasicTheme::RecomputeScrollbarParams() {
|
|
|
|
sOverlayScrollbars =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::IntID::UseOverlayScrollbars);
|
|
|
|
|
2021-03-18 19:12:49 +00:00
|
|
|
uint32_t defaultSize = StaticPrefs::widget_non_native_theme_scrollbar_size();
|
|
|
|
if (StaticPrefs::widget_non_native_theme_win_scrollbar_use_system_size()) {
|
|
|
|
sHorizontalScrollbarHeight = LookAndFeel::GetInt(
|
|
|
|
LookAndFeel::IntID::SystemHorizontalScrollbarHeight, defaultSize);
|
|
|
|
sVerticalScrollbarWidth = LookAndFeel::GetInt(
|
|
|
|
LookAndFeel::IntID::SystemVerticalScrollbarWidth, defaultSize);
|
|
|
|
} else {
|
|
|
|
sHorizontalScrollbarHeight = sVerticalScrollbarWidth = defaultSize;
|
|
|
|
}
|
2021-03-22 16:11:33 +00:00
|
|
|
// On GTK, widgets don't account for text scale factor, but that's included
|
|
|
|
// in the usual DPI computations, so we undo that here, just like
|
|
|
|
// GetMonitorScaleFactor does it in nsNativeThemeGTK.
|
|
|
|
float scale =
|
|
|
|
LookAndFeel::GetFloat(LookAndFeel::FloatID::TextScaleFactor, 1.0f);
|
|
|
|
if (scale != 1.0f) {
|
|
|
|
sVerticalScrollbarWidth = float(sVerticalScrollbarWidth) / scale;
|
|
|
|
sHorizontalScrollbarHeight = float(sHorizontalScrollbarHeight) / scale;
|
|
|
|
}
|
2021-03-18 19:12:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 21:54:58 +00:00
|
|
|
static bool IsScrollbarWidthThin(nsIFrame* aFrame) {
|
|
|
|
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame);
|
|
|
|
auto scrollbarWidth = style->StyleUIReset()->mScrollbarWidth;
|
|
|
|
return scrollbarWidth == StyleScrollbarWidth::Thin;
|
|
|
|
}
|
|
|
|
|
2021-09-11 01:07:28 +00:00
|
|
|
static sRGBColor SystemColor(StyleSystemColor aColor) {
|
2021-04-02 12:22:14 +00:00
|
|
|
// TODO(emilio): We could not hardcode light appearance here with a bit of
|
|
|
|
// work, but doesn't matter for now.
|
2021-09-11 01:07:28 +00:00
|
|
|
return sRGBColor::FromABGR(LookAndFeel::Color(
|
|
|
|
aColor, LookAndFeel::ColorScheme::Light, LookAndFeel::UseStandins::No));
|
2021-04-02 12:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Compute>
|
|
|
|
static sRGBColor SystemColorOrElse(StyleSystemColor aColor, Compute aCompute) {
|
|
|
|
if (auto color =
|
|
|
|
LookAndFeel::GetColor(aColor, LookAndFeel::ColorScheme::Light,
|
|
|
|
LookAndFeel::UseStandins::No)) {
|
|
|
|
return sRGBColor::FromABGR(*color);
|
|
|
|
}
|
|
|
|
return aCompute();
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static std::pair<sRGBColor, sRGBColor> SystemColorPair(
|
|
|
|
StyleSystemColor aFirst, StyleSystemColor aSecond) {
|
|
|
|
return std::make_pair(SystemColor(aFirst), SystemColor(aSecond));
|
|
|
|
}
|
|
|
|
|
2020-07-30 17:02:02 +00:00
|
|
|
/* static */
|
2021-01-28 22:11:54 +00:00
|
|
|
auto nsNativeBasicTheme::GetDPIRatioForScrollbarPart(nsPresContext* aPc)
|
|
|
|
-> DPIRatio {
|
2021-08-30 19:54:39 +00:00
|
|
|
if (auto* rootPc = aPc->GetRootPresContext()) {
|
|
|
|
if (auto* widget = rootPc->GetRootWidget()) {
|
|
|
|
return widget->GetDefaultScale();
|
|
|
|
}
|
2021-08-30 18:01:44 +00:00
|
|
|
}
|
2021-01-28 22:11:54 +00:00
|
|
|
return DPIRatio(float(AppUnitsPerCSSPixel()) /
|
|
|
|
aPc->DeviceContext()->AppUnitsPerDevPixelAtUnitFullZoom());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
auto nsNativeBasicTheme::GetDPIRatio(nsPresContext* aPc,
|
2021-01-26 21:34:35 +00:00
|
|
|
StyleAppearance aAppearance) -> DPIRatio {
|
|
|
|
// Widgets react to zoom, except scrollbars.
|
2021-01-28 22:11:54 +00:00
|
|
|
if (IsWidgetScrollbarPart(aAppearance)) {
|
|
|
|
return GetDPIRatioForScrollbarPart(aPc);
|
|
|
|
}
|
|
|
|
return DPIRatio(float(AppUnitsPerCSSPixel()) / aPc->AppUnitsPerDevPixel());
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
auto nsNativeBasicTheme::GetDPIRatio(nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance) -> DPIRatio {
|
|
|
|
return GetDPIRatio(aFrame->PresContext(), aAppearance);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 17:02:02 +00:00
|
|
|
/* static */
|
|
|
|
bool nsNativeBasicTheme::IsDateTimeResetButton(nsIFrame* aFrame) {
|
|
|
|
if (!aFrame) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
nsIFrame* parent = aFrame->GetParent();
|
|
|
|
if (parent && (parent = parent->GetParent()) &&
|
|
|
|
(parent = parent->GetParent())) {
|
|
|
|
nsDateTimeControlFrame* dateTimeFrame = do_QueryFrame(parent);
|
|
|
|
if (dateTimeFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-30 17:02:02 +00:00
|
|
|
/* static */
|
|
|
|
bool nsNativeBasicTheme::IsColorPickerButton(nsIFrame* aFrame) {
|
|
|
|
nsColorControlFrame* colorPickerButton = do_QueryFrame(aFrame);
|
|
|
|
return colorPickerButton;
|
|
|
|
}
|
|
|
|
|
2021-03-12 11:25:49 +00: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 16:04:31 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 20:53:01 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeCheckboxColors(
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aState, StyleAppearance aAppearance,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent, UseSystemColors aUseSystemColors) {
|
2021-01-05 12:45:48 +00:00
|
|
|
MOZ_ASSERT(aAppearance == StyleAppearance::Checkbox ||
|
|
|
|
aAppearance == StyleAppearance::Radio);
|
2020-11-17 20:53:01 +00:00
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2021-04-01 19:02:18 +00:00
|
|
|
bool isPressed =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER);
|
2020-11-17 20:53:01 +00:00
|
|
|
bool isChecked = aState.HasState(NS_EVENT_STATE_CHECKED);
|
2021-01-05 12:45:48 +00:00
|
|
|
bool isIndeterminate = aAppearance == StyleAppearance::Checkbox &&
|
|
|
|
aState.HasState(NS_EVENT_STATE_INDETERMINATE);
|
2020-11-17 20:53:01 +00:00
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
2021-03-15 21:00:36 +00:00
|
|
|
sRGBColor backgroundColor = SystemColor(StyleSystemColor::Buttonface);
|
2021-03-12 14:44:13 +00:00
|
|
|
sRGBColor borderColor = SystemColor(StyleSystemColor::Buttontext);
|
|
|
|
if (isDisabled) {
|
|
|
|
borderColor = SystemColor(StyleSystemColor::Graytext);
|
|
|
|
if (isChecked || isIndeterminate) {
|
|
|
|
backgroundColor = borderColor;
|
|
|
|
}
|
|
|
|
} else if (isChecked || isIndeterminate) {
|
2021-03-15 21:00:36 +00:00
|
|
|
backgroundColor = borderColor = SystemColor(StyleSystemColor::Highlight);
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
|
|
|
return {backgroundColor, borderColor};
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:53:01 +00:00
|
|
|
sRGBColor backgroundColor = sColorWhite;
|
|
|
|
sRGBColor borderColor = sColorGrey40;
|
|
|
|
if (isDisabled) {
|
2021-04-01 19:02:19 +00:00
|
|
|
backgroundColor = sColorWhiteAlpha50;
|
|
|
|
borderColor = sColorGrey40Alpha50;
|
2020-12-15 01:42:10 +00:00
|
|
|
if (isChecked || isIndeterminate) {
|
2021-04-01 19:02:19 +00:00
|
|
|
backgroundColor = borderColor;
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
2021-04-01 19:02:19 +00:00
|
|
|
} else if (isChecked || isIndeterminate) {
|
2021-04-27 10:41:00 +00:00
|
|
|
const auto& color = isPressed ? aAccent.GetDarker()
|
|
|
|
: isHovered ? aAccent.GetDark()
|
|
|
|
: aAccent.Get();
|
2021-04-01 19:02:19 +00:00
|
|
|
backgroundColor = borderColor = color;
|
|
|
|
} else if (isPressed) {
|
|
|
|
backgroundColor = sColorGrey20;
|
|
|
|
borderColor = sColorGrey60;
|
|
|
|
} else if (isHovered) {
|
|
|
|
backgroundColor = sColorWhite;
|
|
|
|
borderColor = sColorGrey50;
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair(backgroundColor, borderColor);
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
sRGBColor nsNativeBasicTheme::ComputeCheckmarkColor(
|
2021-04-27 10:41:00 +00:00
|
|
|
const EventStates& aState, const AccentColor& aAccent,
|
|
|
|
UseSystemColors aUseSystemColors) {
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
2021-03-15 21:00:36 +00:00
|
|
|
return SystemColor(StyleSystemColor::Highlighttext);
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
2021-02-10 00:47:38 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_DISABLED)) {
|
2021-04-01 19:02:19 +00:00
|
|
|
return sColorWhiteAlpha80;
|
2021-02-10 00:47:38 +00:00
|
|
|
}
|
2021-04-27 10:41:00 +00:00
|
|
|
return aAccent.GetForeground();
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
sRGBColor nsNativeBasicTheme::ComputeBorderColor(
|
|
|
|
const EventStates& aState, UseSystemColors aUseSystemColors) {
|
2020-11-17 20:53:01 +00:00
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return SystemColor(isDisabled ? StyleSystemColor::Graytext
|
|
|
|
: StyleSystemColor::Buttontext);
|
|
|
|
}
|
2020-11-17 20:53:01 +00:00
|
|
|
bool isActive =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
2021-04-01 19:02:18 +00:00
|
|
|
bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER);
|
2020-11-19 02:15:44 +00:00
|
|
|
bool isFocused = aState.HasState(NS_EVENT_STATE_FOCUSRING);
|
2020-11-17 20:53:01 +00:00
|
|
|
if (isDisabled) {
|
|
|
|
return sColorGrey40Alpha50;
|
|
|
|
}
|
|
|
|
if (isFocused) {
|
2021-03-05 01:35:17 +00:00
|
|
|
// We draw the outline over the border for all controls that call into this,
|
|
|
|
// so to prevent issues where the border shows underneath if it snaps in the
|
|
|
|
// wrong direction, we use 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.
|
|
|
|
return sTransparent;
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
if (isActive) {
|
|
|
|
return sColorGrey60;
|
|
|
|
}
|
|
|
|
if (isHovered) {
|
|
|
|
return sColorGrey50;
|
|
|
|
}
|
|
|
|
return sColorGrey40;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeButtonColors(
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aState, UseSystemColors aUseSystemColors,
|
|
|
|
nsIFrame* aFrame) {
|
2020-11-17 20:53:01 +00:00
|
|
|
bool isActive =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2021-04-01 19:02:18 +00:00
|
|
|
bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER);
|
2020-11-17 20:53:01 +00:00
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
const sRGBColor backgroundColor = [&] {
|
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return SystemColor(StyleSystemColor::Buttonface);
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:53:01 +00:00
|
|
|
if (isDisabled) {
|
|
|
|
return sColorGrey10Alpha50;
|
|
|
|
}
|
|
|
|
if (IsDateTimeResetButton(aFrame)) {
|
|
|
|
return sColorWhite;
|
|
|
|
}
|
|
|
|
if (isActive) {
|
|
|
|
return sColorGrey30;
|
|
|
|
}
|
|
|
|
if (isHovered) {
|
|
|
|
return sColorGrey20;
|
|
|
|
}
|
|
|
|
return sColorGrey10;
|
|
|
|
}();
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
const sRGBColor borderColor = ComputeBorderColor(aState, aUseSystemColors);
|
2020-11-17 20:53:01 +00:00
|
|
|
return std::make_pair(backgroundColor, borderColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeTextfieldColors(
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aState, UseSystemColors aUseSystemColors) {
|
2021-09-11 01:07:28 +00:00
|
|
|
const sRGBColor backgroundColor = [&] {
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
2021-09-11 01:07:28 +00:00
|
|
|
return SystemColor(StyleSystemColor::TextBackground);
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
|
|
|
if (aState.HasState(NS_EVENT_STATE_DISABLED)) {
|
2021-09-11 01:07:28 +00:00
|
|
|
return sColorWhiteAlpha50;
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
2021-09-11 01:07:28 +00:00
|
|
|
return sColorWhite;
|
2021-03-12 14:44:13 +00:00
|
|
|
}();
|
|
|
|
const sRGBColor borderColor = ComputeBorderColor(aState, aUseSystemColors);
|
2021-09-11 01:07:28 +00:00
|
|
|
return std::make_pair(backgroundColor, borderColor);
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeProgressColors(
|
2021-04-27 10:41:00 +00:00
|
|
|
const EventStates& aState, const AccentColor& aAccent,
|
|
|
|
UseSystemColors aUseSystemColors) {
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return SystemColorPair(StyleSystemColor::Highlight,
|
|
|
|
StyleSystemColor::Buttontext);
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:53:01 +00:00
|
|
|
bool isActive =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2021-04-01 19:02:18 +00:00
|
|
|
bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER);
|
2020-11-17 20:53:01 +00:00
|
|
|
|
|
|
|
if (isDisabled) {
|
|
|
|
return std::make_pair(sColorGrey40Alpha50, sColorGrey40Alpha50);
|
|
|
|
}
|
|
|
|
if (isActive || isHovered) {
|
2021-04-27 10:41:00 +00:00
|
|
|
return std::make_pair(aAccent.GetDark(), aAccent.GetDarker());
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
2021-04-27 10:41:00 +00:00
|
|
|
return std::make_pair(aAccent.Get(), aAccent.GetDark());
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeTrackColors(
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aState, UseSystemColors aUseSystemColors) {
|
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return SystemColorPair(StyleSystemColor::TextBackground,
|
|
|
|
StyleSystemColor::Buttontext);
|
|
|
|
}
|
2020-11-17 20:53:01 +00:00
|
|
|
bool isActive =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2021-04-01 19:02:18 +00:00
|
|
|
bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER);
|
2020-11-17 20:53:01 +00:00
|
|
|
|
|
|
|
if (isDisabled) {
|
|
|
|
return std::make_pair(sColorGrey10Alpha50, sColorGrey40Alpha50);
|
|
|
|
}
|
|
|
|
if (isActive || isHovered) {
|
|
|
|
return std::make_pair(sColorGrey20, sColorGrey50);
|
|
|
|
}
|
|
|
|
return std::make_pair(sColorGrey10, sColorGrey40);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeRangeThumbColors(
|
2021-04-27 10:41:00 +00:00
|
|
|
const EventStates& aState, const AccentColor& aAccent,
|
|
|
|
UseSystemColors aUseSystemColors) {
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
2021-03-15 21:00:36 +00:00
|
|
|
return SystemColorPair(StyleSystemColor::Highlighttext,
|
2021-03-12 14:44:13 +00:00
|
|
|
StyleSystemColor::Highlight);
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:53:01 +00:00
|
|
|
bool isActive =
|
|
|
|
aState.HasAllStates(NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isDisabled = aState.HasState(NS_EVENT_STATE_DISABLED);
|
2021-04-01 19:02:18 +00:00
|
|
|
bool isHovered = aState.HasState(NS_EVENT_STATE_HOVER);
|
2020-11-17 20:53:01 +00:00
|
|
|
|
|
|
|
const sRGBColor& backgroundColor = [&] {
|
|
|
|
if (isDisabled) {
|
2021-02-23 23:22:19 +00:00
|
|
|
return sColorGrey40;
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
if (isActive) {
|
2021-04-27 10:41:00 +00:00
|
|
|
return aAccent.Get();
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
if (isHovered) {
|
|
|
|
return sColorGrey60;
|
|
|
|
}
|
|
|
|
return sColorGrey50;
|
|
|
|
}();
|
|
|
|
|
|
|
|
const sRGBColor borderColor = sColorWhite;
|
|
|
|
|
|
|
|
return std::make_pair(backgroundColor, borderColor);
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeProgressColors(
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent, UseSystemColors aUseSystemColors) {
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return SystemColorPair(StyleSystemColor::Highlight,
|
|
|
|
StyleSystemColor::Buttontext);
|
|
|
|
}
|
2021-04-27 10:41:00 +00:00
|
|
|
return std::make_pair(aAccent.Get(), aAccent.GetDark());
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeProgressTrackColors(
|
|
|
|
UseSystemColors aUseSystemColors) {
|
|
|
|
if (bool(aUseSystemColors)) {
|
2021-03-15 21:00:36 +00:00
|
|
|
return SystemColorPair(StyleSystemColor::Buttonface,
|
2021-03-12 14:44:13 +00:00
|
|
|
StyleSystemColor::Buttontext);
|
|
|
|
}
|
2020-11-17 20:53:01 +00:00
|
|
|
return std::make_pair(sColorGrey10, sColorGrey40);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<sRGBColor, sRGBColor> nsNativeBasicTheme::ComputeMeterchunkColors(
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aMeterState, UseSystemColors aUseSystemColors) {
|
|
|
|
if (bool(aUseSystemColors)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
// Accent color doesn't matter when using system colors.
|
|
|
|
return ComputeProgressColors(AccentColor(), aUseSystemColors);
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
2020-11-17 20:53:01 +00:00
|
|
|
sRGBColor borderColor = sColorMeterGreen20;
|
|
|
|
sRGBColor chunkColor = sColorMeterGreen10;
|
|
|
|
|
2021-01-06 06:00:28 +00:00
|
|
|
if (aMeterState.HasState(NS_EVENT_STATE_SUB_OPTIMUM)) {
|
|
|
|
borderColor = sColorMeterYellow20;
|
|
|
|
chunkColor = sColorMeterYellow10;
|
|
|
|
} else if (aMeterState.HasState(NS_EVENT_STATE_SUB_SUB_OPTIMUM)) {
|
|
|
|
borderColor = sColorMeterRed20;
|
|
|
|
chunkColor = sColorMeterRed10;
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_pair(chunkColor, borderColor);
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
std::array<sRGBColor, 3> nsNativeBasicTheme::ComputeFocusRectColors(
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent, UseSystemColors aUseSystemColors) {
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return {SystemColor(StyleSystemColor::Highlight),
|
|
|
|
SystemColor(StyleSystemColor::Buttontext),
|
|
|
|
SystemColor(StyleSystemColor::TextBackground)};
|
|
|
|
}
|
|
|
|
|
2021-04-27 10:41:00 +00:00
|
|
|
return {aAccent.Get(), sColorWhiteAlpha80, aAccent.GetLight()};
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 09:48:01 +00:00
|
|
|
sRGBColor nsNativeBasicTheme::ComputeScrollbarTrackColor(
|
2021-01-20 21:33:34 +00:00
|
|
|
nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aDocumentState, UseSystemColors aUseSystemColors) {
|
2020-11-17 20:53:01 +00:00
|
|
|
const nsStyleUI* ui = aStyle.StyleUI();
|
2021-03-12 14:44:13 +00:00
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return SystemColor(StyleSystemColor::TextBackground);
|
|
|
|
}
|
|
|
|
if (ShouldUseDarkScrollbar(aFrame, aStyle)) {
|
|
|
|
return sRGBColor::FromU8(20, 20, 25, 77);
|
|
|
|
}
|
2020-11-17 20:53:01 +00:00
|
|
|
if (ui->mScrollbarColor.IsColors()) {
|
2021-04-02 12:22:14 +00:00
|
|
|
return sRGBColor::FromABGR(
|
|
|
|
ui->mScrollbarColor.AsColors().track.CalcColor(aStyle));
|
2021-04-02 00:21:37 +00:00
|
|
|
}
|
2021-04-02 12:22:14 +00:00
|
|
|
if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
|
|
|
|
return SystemColorOrElse(StyleSystemColor::ThemedScrollbarInactive,
|
|
|
|
[] { return sScrollbarColor; });
|
|
|
|
}
|
|
|
|
return SystemColorOrElse(StyleSystemColor::ThemedScrollbar,
|
|
|
|
[] { return sScrollbarColor; });
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-04 16:15:27 +00:00
|
|
|
nscolor nsNativeBasicTheme::AdjustUnthemedScrollbarThumbColor(
|
|
|
|
nscolor aFaceColor, EventStates aStates) {
|
|
|
|
// In Windows 10, scrollbar thumb has the following colors:
|
|
|
|
//
|
|
|
|
// State | Color | Luminance
|
|
|
|
// -------+----------+----------
|
|
|
|
// Normal | Gray 205 | 61.0%
|
|
|
|
// Hover | Gray 166 | 38.1%
|
|
|
|
// Active | Gray 96 | 11.7%
|
|
|
|
//
|
|
|
|
// This function is written based on the ratios between the values.
|
|
|
|
bool isActive = aStates.HasState(NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isHover = aStates.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
if (!isActive && !isHover) {
|
|
|
|
return aFaceColor;
|
|
|
|
}
|
|
|
|
float luminance = RelativeLuminanceUtils::Compute(aFaceColor);
|
|
|
|
if (isActive) {
|
2021-02-10 00:47:38 +00:00
|
|
|
// 11.7 / 61.0
|
|
|
|
luminance = ScaleLuminanceBy(luminance, 0.192f);
|
2021-02-04 16:15:27 +00:00
|
|
|
} else {
|
2021-02-10 00:47:38 +00:00
|
|
|
// 38.1 / 61.0
|
|
|
|
luminance = ScaleLuminanceBy(luminance, 0.625f);
|
2021-02-04 16:15:27 +00:00
|
|
|
}
|
|
|
|
return RelativeLuminanceUtils::Adjust(aFaceColor, luminance);
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
/*static*/
|
|
|
|
nscolor nsNativeBasicTheme::GetScrollbarButtonColor(nscolor aTrackColor,
|
|
|
|
EventStates aStates) {
|
|
|
|
// See numbers in GetScrollbarArrowColor.
|
|
|
|
// This function is written based on ratios between values listed there.
|
|
|
|
|
|
|
|
bool isActive = aStates.HasState(NS_EVENT_STATE_ACTIVE);
|
|
|
|
bool isHover = aStates.HasState(NS_EVENT_STATE_HOVER);
|
|
|
|
if (!isActive && !isHover) {
|
|
|
|
return aTrackColor;
|
|
|
|
}
|
|
|
|
float luminance = RelativeLuminanceUtils::Compute(aTrackColor);
|
|
|
|
if (isActive) {
|
|
|
|
if (luminance >= 0.18f) {
|
|
|
|
luminance *= 0.134f;
|
|
|
|
} else {
|
|
|
|
luminance /= 0.134f;
|
|
|
|
luminance = std::min(luminance, 1.0f);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (luminance >= 0.18f) {
|
|
|
|
luminance *= 0.805f;
|
|
|
|
} else {
|
|
|
|
luminance /= 0.805f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RelativeLuminanceUtils::Adjust(aTrackColor, luminance);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/
|
2021-04-08 09:48:01 +00:00
|
|
|
Maybe<nscolor> nsNativeBasicTheme::GetScrollbarArrowColor(
|
|
|
|
nscolor aButtonColor) {
|
2021-03-12 14:44:13 +00:00
|
|
|
// In Windows 10 scrollbar, there are several gray colors used:
|
|
|
|
//
|
|
|
|
// State | Background (lum) | Arrow | Contrast
|
|
|
|
// -------+------------------+---------+---------
|
|
|
|
// Normal | Gray 240 (87.1%) | Gray 96 | 5.5
|
|
|
|
// Hover | Gray 218 (70.1%) | Black | 15.0
|
|
|
|
// Active | Gray 96 (11.7%) | White | 6.3
|
|
|
|
//
|
|
|
|
// Contrast value is computed based on the definition in
|
|
|
|
// https://www.w3.org/TR/WCAG20/#contrast-ratiodef
|
|
|
|
//
|
|
|
|
// This function is written based on these values.
|
|
|
|
|
2021-04-08 09:48:01 +00:00
|
|
|
if (NS_GET_A(aButtonColor) == 0) {
|
|
|
|
// If the button color is transparent, because of e.g.
|
|
|
|
// scrollbar-color: <something> transparent, then use
|
|
|
|
// the thumb color, which is expected to have enough
|
|
|
|
// contrast.
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
float luminance = RelativeLuminanceUtils::Compute(aButtonColor);
|
|
|
|
// Color with luminance larger than 0.72 has contrast ratio over 4.6
|
|
|
|
// to color with luminance of gray 96, so this value is chosen for
|
|
|
|
// this range. It is the luminance of gray 221.
|
|
|
|
if (luminance >= 0.72) {
|
|
|
|
// ComputeRelativeLuminanceFromComponents(96). That function cannot
|
|
|
|
// be constexpr because of std::pow.
|
|
|
|
const float GRAY96_LUMINANCE = 0.117f;
|
2021-04-08 09:48:01 +00:00
|
|
|
return Some(RelativeLuminanceUtils::Adjust(aButtonColor, GRAY96_LUMINANCE));
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
|
|
|
// The contrast ratio of a color to black equals that to white when its
|
|
|
|
// luminance is around 0.18, with a contrast ratio ~4.6 to both sides,
|
|
|
|
// thus the value below. It's the lumanince of gray 118.
|
2021-04-08 09:48:01 +00:00
|
|
|
//
|
|
|
|
// TODO(emilio): Maybe the button alpha is not the best thing to use here and
|
|
|
|
// we should use the thumb alpha? It seems weird that the color of the arrow
|
|
|
|
// depends on the opacity of the scrollbar thumb...
|
2021-03-12 14:44:13 +00:00
|
|
|
if (luminance >= 0.18) {
|
2021-04-08 09:48:01 +00:00
|
|
|
return Some(NS_RGBA(0, 0, 0, NS_GET_A(aButtonColor)));
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
2021-04-08 09:48:01 +00:00
|
|
|
return Some(NS_RGBA(255, 255, 255, NS_GET_A(aButtonColor)));
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::ShouldUseDarkScrollbar(nsIFrame* aFrame,
|
|
|
|
const ComputedStyle& aStyle) {
|
|
|
|
if (StaticPrefs::widget_disable_dark_scrollbar()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (aStyle.StyleUI()->mScrollbarColor.IsColors()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return nsNativeTheme::IsDarkBackground(aFrame);
|
|
|
|
}
|
|
|
|
|
2021-05-11 09:32:20 +00:00
|
|
|
// Don't use the theme color for dark scrollbars if it's not a color (if it's
|
|
|
|
// grey-ish), as that'd either lack enough contrast, or be close to what we'd do
|
|
|
|
// by default anyways.
|
|
|
|
static bool ShouldUseColorForActiveDarkScrollbarThumb(nscolor aColor) {
|
|
|
|
auto IsDifferentEnough = [](int32_t aChannel, int32_t aOtherChannel) {
|
|
|
|
return std::abs(aChannel - aOtherChannel) > 10;
|
|
|
|
};
|
|
|
|
return IsDifferentEnough(NS_GET_R(aColor), NS_GET_G(aColor)) ||
|
|
|
|
IsDifferentEnough(NS_GET_R(aColor), NS_GET_B(aColor));
|
|
|
|
}
|
|
|
|
|
2021-01-20 21:33:34 +00:00
|
|
|
sRGBColor nsNativeBasicTheme::ComputeScrollbarThumbColor(
|
|
|
|
nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
UseSystemColors aUseSystemColors) {
|
|
|
|
if (!bool(aUseSystemColors) && ShouldUseDarkScrollbar(aFrame, aStyle)) {
|
2021-05-11 09:32:20 +00:00
|
|
|
if (aElementState.HasState(NS_EVENT_STATE_ACTIVE) &&
|
|
|
|
StaticPrefs::widget_non_native_theme_scrollbar_active_always_themed()) {
|
|
|
|
auto color = LookAndFeel::GetColor(
|
|
|
|
StyleSystemColor::ThemedScrollbarThumbActive,
|
|
|
|
LookAndFeel::ColorScheme::Light, LookAndFeel::UseStandins::No);
|
|
|
|
if (color && ShouldUseColorForActiveDarkScrollbarThumb(*color)) {
|
|
|
|
return sRGBColor::FromABGR(*color);
|
|
|
|
}
|
2021-03-30 17:31:33 +00:00
|
|
|
}
|
2021-05-11 09:32:20 +00:00
|
|
|
return sRGBColor::FromABGR(AdjustUnthemedScrollbarThumbColor(
|
|
|
|
NS_RGBA(249, 249, 250, 102), aElementState));
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
2021-03-30 17:31:33 +00:00
|
|
|
|
2020-11-17 20:53:01 +00:00
|
|
|
const nsStyleUI* ui = aStyle.StyleUI();
|
|
|
|
if (ui->mScrollbarColor.IsColors()) {
|
2021-03-12 14:44:13 +00:00
|
|
|
return sRGBColor::FromABGR(AdjustUnthemedScrollbarThumbColor(
|
|
|
|
ui->mScrollbarColor.AsColors().thumb.CalcColor(aStyle), aElementState));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto systemColor = [&] {
|
|
|
|
if (aDocumentState.HasState(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
|
|
|
|
return StyleSystemColor::ThemedScrollbarThumbInactive;
|
|
|
|
}
|
|
|
|
if (aElementState.HasState(NS_EVENT_STATE_ACTIVE)) {
|
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return StyleSystemColor::Highlight;
|
|
|
|
}
|
|
|
|
return StyleSystemColor::ThemedScrollbarThumbActive;
|
|
|
|
}
|
|
|
|
if (aElementState.HasState(NS_EVENT_STATE_HOVER)) {
|
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return StyleSystemColor::Highlight;
|
|
|
|
}
|
|
|
|
return StyleSystemColor::ThemedScrollbarThumbHover;
|
|
|
|
}
|
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
return StyleSystemColor::TextForeground;
|
|
|
|
}
|
|
|
|
return StyleSystemColor::ThemedScrollbarThumb;
|
|
|
|
}();
|
|
|
|
|
2021-04-02 12:22:14 +00:00
|
|
|
return SystemColorOrElse(systemColor, [&] {
|
|
|
|
return sRGBColor::FromABGR(AdjustUnthemedScrollbarThumbColor(
|
|
|
|
sScrollbarThumbColor.ToABGR(), aElementState));
|
|
|
|
});
|
2020-11-17 20:53:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
std::pair<sRGBColor, sRGBColor>
|
|
|
|
nsNativeBasicTheme::ComputeScrollbarButtonColors(
|
2021-01-20 21:33:34 +00:00
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance, const ComputedStyle& aStyle,
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
UseSystemColors aUseSystemColors) {
|
|
|
|
if (bool(aUseSystemColors)) {
|
|
|
|
if (aElementState.HasAtLeastOneOfStates(NS_EVENT_STATE_ACTIVE |
|
|
|
|
NS_EVENT_STATE_HOVER)) {
|
|
|
|
return SystemColorPair(StyleSystemColor::Highlight,
|
|
|
|
StyleSystemColor::Buttonface);
|
2021-01-20 21:33:34 +00:00
|
|
|
}
|
2021-03-12 14:44:13 +00:00
|
|
|
return SystemColorPair(StyleSystemColor::TextBackground,
|
|
|
|
StyleSystemColor::TextForeground);
|
2021-01-20 21:33:34 +00:00
|
|
|
}
|
|
|
|
|
2021-04-08 09:48:01 +00:00
|
|
|
auto trackColor = ComputeScrollbarTrackColor(aFrame, aStyle, aDocumentState,
|
|
|
|
aUseSystemColors);
|
2021-03-12 14:44:13 +00:00
|
|
|
nscolor buttonColor =
|
|
|
|
GetScrollbarButtonColor(trackColor.ToABGR(), aElementState);
|
2021-04-08 09:48:01 +00:00
|
|
|
auto arrowColor =
|
|
|
|
GetScrollbarArrowColor(buttonColor)
|
|
|
|
.map(sRGBColor::FromABGR)
|
|
|
|
.valueOrFrom([&] {
|
|
|
|
return ComputeScrollbarThumbColor(aFrame, aStyle, aElementState,
|
|
|
|
aDocumentState, aUseSystemColors);
|
|
|
|
});
|
|
|
|
return {sRGBColor::FromABGR(buttonColor), arrowColor};
|
2021-01-20 21:33:34 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 16:25:16 +00:00
|
|
|
static const CSSCoord kInnerFocusOutlineWidth = 2.0f;
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
2021-04-27 10:41:00 +00:00
|
|
|
void nsNativeBasicTheme::PaintRoundedFocusRect(
|
|
|
|
PaintBackendData& aBackendData, const LayoutDeviceRect& aRect,
|
|
|
|
const AccentColor& aAccent, UseSystemColors aUseSystemColors,
|
|
|
|
DPIRatio aDpiRatio, CSSCoord aRadius, CSSCoord aOffset) {
|
2021-01-28 22:11:54 +00:00
|
|
|
// NOTE(emilio): If the widths or offsets here change, make sure to tweak
|
|
|
|
// the GetWidgetOverflow path for FocusOutline.
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [innerColor, middleColor, outerColor] =
|
2021-04-27 10:41:00 +00:00
|
|
|
ComputeFocusRectColors(aAccent, aUseSystemColors);
|
2021-01-21 22:12:14 +00:00
|
|
|
|
2020-11-29 22:19:10 +00:00
|
|
|
LayoutDeviceRect focusRect(aRect);
|
2021-01-21 22:12:14 +00: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.
|
2021-02-23 10:49:37 +00:00
|
|
|
CSSCoord strokeWidth = kInnerFocusOutlineWidth;
|
2021-03-05 01:35:17 +00:00
|
|
|
auto strokeWidthDevPx =
|
|
|
|
LayoutDeviceCoord(SnapBorderWidth(strokeWidth, aDpiRatio));
|
2021-02-23 10:49:37 +00:00
|
|
|
CSSCoord strokeRadius = aRadius;
|
2021-03-05 01:35:17 +00:00
|
|
|
focusRect.Inflate(aOffset * aDpiRatio + strokeWidthDevPx);
|
2021-02-23 10:49:37 +00:00
|
|
|
|
2021-03-05 01:35:17 +00:00
|
|
|
PaintRoundedRectWithRadius(aBackendData, focusRect, sTransparent, innerColor,
|
2021-02-23 10:49:37 +00:00
|
|
|
strokeWidth, strokeRadius, aDpiRatio);
|
|
|
|
|
|
|
|
strokeWidth = CSSCoord(1.0f);
|
2021-03-05 01:35:17 +00:00
|
|
|
strokeWidthDevPx = LayoutDeviceCoord(SnapBorderWidth(strokeWidth, aDpiRatio));
|
2021-02-23 10:49:37 +00:00
|
|
|
strokeRadius += strokeWidth;
|
2021-03-05 01:35:17 +00:00
|
|
|
focusRect.Inflate(strokeWidthDevPx);
|
2021-02-23 10:49:37 +00:00
|
|
|
|
2021-03-05 01:35:17 +00:00
|
|
|
PaintRoundedRectWithRadius(aBackendData, focusRect, sTransparent, middleColor,
|
2021-02-23 10:49:37 +00:00
|
|
|
strokeWidth, strokeRadius, aDpiRatio);
|
|
|
|
|
|
|
|
strokeWidth = CSSCoord(2.0f);
|
2021-03-05 01:35:17 +00:00
|
|
|
strokeWidthDevPx = LayoutDeviceCoord(SnapBorderWidth(strokeWidth, aDpiRatio));
|
2021-02-23 10:49:37 +00:00
|
|
|
strokeRadius += strokeWidth;
|
2021-03-05 01:35:17 +00:00
|
|
|
focusRect.Inflate(strokeWidthDevPx);
|
2021-02-23 10:49:37 +00:00
|
|
|
|
2021-03-05 01:35:17 +00:00
|
|
|
PaintRoundedRectWithRadius(aBackendData, focusRect, sTransparent, outerColor,
|
2021-02-23 10:49:37 +00:00
|
|
|
strokeWidth, strokeRadius, aDpiRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsNativeBasicTheme::PaintRoundedRectWithRadius(
|
|
|
|
WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
|
|
|
|
const LayoutDeviceRect& aClipRect, const sRGBColor& aBackgroundColor,
|
|
|
|
const sRGBColor& aBorderColor, CSSCoord aBorderWidth, CSSCoord aRadius,
|
|
|
|
DPIRatio aDpiRatio) {
|
|
|
|
const bool kBackfaceIsVisible = true;
|
|
|
|
const LayoutDeviceCoord borderWidth(SnapBorderWidth(aBorderWidth, aDpiRatio));
|
|
|
|
const LayoutDeviceCoord radius(aRadius * aDpiRatio);
|
|
|
|
const wr::LayoutRect dest = wr::ToLayoutRect(aRect);
|
|
|
|
const wr::LayoutRect clip = wr::ToLayoutRect(aClipRect);
|
|
|
|
|
|
|
|
// Push the background.
|
|
|
|
if (aBackgroundColor.a) {
|
|
|
|
auto backgroundColor = wr::ToColorF(ToDeviceColor(aBackgroundColor));
|
|
|
|
wr::LayoutRect backgroundRect = [&] {
|
|
|
|
LayoutDeviceRect bg = aRect;
|
|
|
|
bg.Deflate(borderWidth);
|
|
|
|
return wr::ToLayoutRect(bg);
|
|
|
|
}();
|
|
|
|
if (!radius) {
|
|
|
|
aWrData.mBuilder.PushRect(backgroundRect, clip, kBackfaceIsVisible,
|
|
|
|
backgroundColor);
|
|
|
|
} else {
|
|
|
|
// NOTE(emilio): This follows DisplayListBuilder::PushRoundedRect and
|
|
|
|
// draws the rounded fill as an extra thick rounded border instead of a
|
|
|
|
// rectangle that's clipped to a rounded clip. Refer to that method for a
|
|
|
|
// justification. See bug 1694269.
|
|
|
|
LayoutDeviceCoord backgroundRadius =
|
|
|
|
std::max(0.0f, float(radius) - float(borderWidth));
|
|
|
|
wr::BorderSide side = {backgroundColor, wr::BorderStyle::Solid};
|
|
|
|
const wr::BorderSide sides[4] = {side, side, side, side};
|
2021-06-11 13:33:10 +00:00
|
|
|
float h = backgroundRect.width() * 0.6f;
|
|
|
|
float v = backgroundRect.height() * 0.6f;
|
2021-02-23 10:49:37 +00:00
|
|
|
wr::LayoutSideOffsets widths = {v, h, v, h};
|
|
|
|
wr::BorderRadius radii = {{backgroundRadius, backgroundRadius},
|
|
|
|
{backgroundRadius, backgroundRadius},
|
|
|
|
{backgroundRadius, backgroundRadius},
|
|
|
|
{backgroundRadius, backgroundRadius}};
|
|
|
|
aWrData.mBuilder.PushBorder(backgroundRect, clip, kBackfaceIsVisible,
|
|
|
|
widths, {sides, 4}, radii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 01:35:17 +00:00
|
|
|
if (borderWidth && aBorderColor.a) {
|
|
|
|
// Push the border.
|
|
|
|
const auto borderColor = ToDeviceColor(aBorderColor);
|
|
|
|
const auto side = wr::ToBorderSide(borderColor, StyleBorderStyle::Solid);
|
|
|
|
const wr::BorderSide sides[4] = {side, side, side, side};
|
|
|
|
const LayoutDeviceSize sideRadius(radius, radius);
|
|
|
|
const auto widths =
|
|
|
|
wr::ToBorderWidths(borderWidth, borderWidth, borderWidth, borderWidth);
|
|
|
|
const auto wrRadius =
|
|
|
|
wr::ToBorderRadius(sideRadius, sideRadius, sideRadius, sideRadius);
|
|
|
|
aWrData.mBuilder.PushBorder(dest, clip, kBackfaceIsVisible, widths,
|
|
|
|
{sides, 4}, wrRadius);
|
|
|
|
}
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsNativeBasicTheme::FillRect(DrawTarget& aDt,
|
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
const sRGBColor& aColor) {
|
|
|
|
aDt.FillRect(aRect.ToUnknownRect(), ColorPattern(ToDeviceColor(aColor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsNativeBasicTheme::FillRect(WebRenderBackendData& aWrData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
const sRGBColor& aColor) {
|
|
|
|
const bool kBackfaceIsVisible = true;
|
|
|
|
auto dest = wr::ToLayoutRect(aRect);
|
|
|
|
aWrData.mBuilder.PushRect(dest, dest, kBackfaceIsVisible,
|
|
|
|
wr::ToColorF(ToDeviceColor(aColor)));
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
2020-07-29 23:58:03 +00:00
|
|
|
|
2021-01-28 20:58:39 +00:00
|
|
|
void nsNativeBasicTheme::PaintRoundedRectWithRadius(
|
2021-02-22 16:18:33 +00:00
|
|
|
DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect,
|
2021-02-23 10:49:37 +00:00
|
|
|
const LayoutDeviceRect& aClipRect, const sRGBColor& aBackgroundColor,
|
|
|
|
const sRGBColor& aBorderColor, CSSCoord aBorderWidth, CSSCoord aRadius,
|
|
|
|
DPIRatio aDpiRatio) {
|
2021-01-26 22:12:03 +00:00
|
|
|
const LayoutDeviceCoord borderWidth(SnapBorderWidth(aBorderWidth, aDpiRatio));
|
2021-02-23 10:49:37 +00:00
|
|
|
const bool needsClip = !(aRect == aClipRect);
|
|
|
|
if (needsClip) {
|
|
|
|
aDrawTarget.PushClipRect(aClipRect.ToUnknownRect());
|
|
|
|
}
|
2020-03-05 00:25:31 +00:00
|
|
|
|
2020-11-29 22:19:10 +00:00
|
|
|
LayoutDeviceRect rect(aRect);
|
2021-01-28 22:11:54 +00:00
|
|
|
// Deflate the rect by half the border width, so that the middle of the
|
|
|
|
// stroke fills exactly the area we want to fill and not more.
|
2020-03-05 00:25:31 +00:00
|
|
|
rect.Deflate(borderWidth * 0.5f);
|
|
|
|
|
2021-03-22 08:12:22 +00:00
|
|
|
LayoutDeviceCoord radius(aRadius * aDpiRatio - borderWidth * 0.5f);
|
2021-01-28 13:14:34 +00:00
|
|
|
// Fix up the radius if it's too large with the rect we're going to paint.
|
|
|
|
{
|
|
|
|
LayoutDeviceCoord min = std::min(rect.width, rect.height);
|
|
|
|
if (radius * 2.0f > min) {
|
|
|
|
radius = min * 0.5f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
Maybe<ColorPattern> backgroundPattern;
|
|
|
|
if (aBackgroundColor.a) {
|
|
|
|
backgroundPattern.emplace(ToDeviceColor(aBackgroundColor));
|
|
|
|
}
|
2021-03-05 01:35:17 +00:00
|
|
|
Maybe<ColorPattern> borderPattern;
|
|
|
|
if (borderWidth && aBorderColor.a) {
|
|
|
|
borderPattern.emplace(ToDeviceColor(aBorderColor));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (borderPattern || backgroundPattern) {
|
|
|
|
if (radius) {
|
|
|
|
RectCornerRadii radii(radius, radius, radius, radius);
|
|
|
|
RefPtr<Path> roundedRect =
|
|
|
|
MakePathForRoundedRect(aDrawTarget, rect.ToUnknownRect(), radii);
|
|
|
|
|
|
|
|
if (backgroundPattern) {
|
|
|
|
aDrawTarget.Fill(roundedRect, *backgroundPattern);
|
|
|
|
}
|
|
|
|
if (borderPattern) {
|
|
|
|
aDrawTarget.Stroke(roundedRect, *borderPattern,
|
2021-03-05 01:15:14 +00:00
|
|
|
StrokeOptions(borderWidth));
|
2021-03-05 01:35:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (backgroundPattern) {
|
|
|
|
aDrawTarget.FillRect(rect.ToUnknownRect(), *backgroundPattern);
|
|
|
|
}
|
|
|
|
if (borderPattern) {
|
|
|
|
aDrawTarget.StrokeRect(rect.ToUnknownRect(), *borderPattern,
|
|
|
|
StrokeOptions(borderWidth));
|
|
|
|
}
|
|
|
|
}
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
2020-03-05 00:25:31 +00:00
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
if (needsClip) {
|
|
|
|
aDrawTarget.PopClip();
|
|
|
|
}
|
2020-03-05 00:25:31 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
void nsNativeBasicTheme::PaintCheckboxControl(DrawTarget& aDrawTarget,
|
2020-11-29 22:19:10 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2020-07-30 17:02:02 +00:00
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2020-11-30 04:48:07 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [backgroundColor, borderColor] = ComputeCheckboxColors(
|
2021-04-27 10:41:00 +00:00
|
|
|
aState, StyleAppearance::Checkbox, aAccent, aUseSystemColors);
|
2021-03-12 12:28:44 +00:00
|
|
|
{
|
2021-03-20 17:56:27 +00:00
|
|
|
const CSSCoord radius = 2.0f;
|
2021-03-12 12:28:44 +00:00
|
|
|
CSSCoord borderWidth = kCheckboxRadioBorderWidth;
|
|
|
|
if (backgroundColor == borderColor) {
|
|
|
|
borderWidth = 0.0f;
|
|
|
|
}
|
|
|
|
PaintRoundedRectWithRadius(aDrawTarget, aRect, backgroundColor, borderColor,
|
|
|
|
borderWidth, radius, aDpiRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aState.HasState(NS_EVENT_STATE_INDETERMINATE)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintIndeterminateMark(aDrawTarget, aRect, aState, aAccent,
|
|
|
|
aUseSystemColors);
|
2021-03-12 12:28:44 +00:00
|
|
|
} else if (aState.HasState(NS_EVENT_STATE_CHECKED)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintCheckMark(aDrawTarget, aRect, aState, aAccent, aUseSystemColors);
|
2021-03-12 12:28:44 +00:00
|
|
|
}
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2020-11-19 02:15:44 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRoundedFocusRect(aDrawTarget, aRect, aAccent, aUseSystemColors,
|
|
|
|
aDpiRatio, 5.0f, 1.0f);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-01 22:55:37 +00:00
|
|
|
constexpr CSSCoord kCheckboxRadioContentBoxSize = 10.0f;
|
|
|
|
constexpr CSSCoord kCheckboxRadioBorderBoxSize =
|
|
|
|
kCheckboxRadioContentBoxSize + kCheckboxRadioBorderWidth * 2.0f;
|
|
|
|
|
|
|
|
// Returns the right scale for points in a aSize x aSize sized box, centered at
|
|
|
|
// 0x0 to fill aRect in the smaller dimension.
|
|
|
|
static float ScaleToFillRect(const LayoutDeviceRect& aRect, const float aSize) {
|
|
|
|
return std::min(aRect.width, aRect.height) / aSize;
|
2020-11-30 04:48:07 +00:00
|
|
|
}
|
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
void nsNativeBasicTheme::PaintCheckMark(DrawTarget& aDrawTarget,
|
2020-11-29 22:19:10 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors) {
|
2021-03-01 22:55:37 +00:00
|
|
|
// Points come from the coordinates on a 14X14 (kCheckboxRadioBorderBoxSize)
|
|
|
|
// unit box centered at 0,0
|
2020-07-30 17:02:02 +00: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 19:26:01 +00:00
|
|
|
const int32_t checkNumPoints = sizeof(checkPolygonX) / sizeof(float);
|
2021-03-01 22:55:37 +00:00
|
|
|
const float scale = ScaleToFillRect(aRect, kCheckboxRadioBorderBoxSize);
|
2020-11-29 22:19:10 +00:00
|
|
|
auto center = aRect.Center().ToUnknownPoint();
|
2020-02-16 16:04:31 +00:00
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
|
2020-07-30 17:02:02 +00:00
|
|
|
Point p = center + Point(checkPolygonX[0] * scale, checkPolygonY[0] * scale);
|
2020-02-10 19:26:01 +00:00
|
|
|
builder->MoveTo(p);
|
2020-07-30 17:02:02 +00:00
|
|
|
for (int32_t i = 1; i < checkNumPoints; i++) {
|
|
|
|
p = center + Point(checkPolygonX[i] * scale, checkPolygonY[i] * scale);
|
2020-02-10 19:26:01 +00:00
|
|
|
builder->LineTo(p);
|
|
|
|
}
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
2020-07-29 22:16:06 +00:00
|
|
|
|
2021-04-27 10:41:00 +00:00
|
|
|
sRGBColor fillColor =
|
|
|
|
ComputeCheckmarkColor(aState, aAccent, aUseSystemColors);
|
2021-02-22 16:18:33 +00:00
|
|
|
aDrawTarget.Fill(path, ColorPattern(ToDeviceColor(fillColor)));
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
void nsNativeBasicTheme::PaintIndeterminateMark(
|
|
|
|
DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect,
|
2021-04-27 10:41:00 +00:00
|
|
|
const EventStates& aState, const AccentColor& aAccent,
|
|
|
|
UseSystemColors aUseSystemColors) {
|
2020-07-30 17:02:02 +00:00
|
|
|
const CSSCoord borderWidth = 2.0f;
|
2021-03-01 22:55:37 +00:00
|
|
|
const float scale = ScaleToFillRect(aRect, kCheckboxRadioBorderBoxSize);
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2020-11-29 22:19:10 +00:00
|
|
|
Rect rect = aRect.ToUnknownRect();
|
2020-07-30 17:02:02 +00: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 19:26:01 +00:00
|
|
|
|
2021-04-27 10:41:00 +00:00
|
|
|
sRGBColor fillColor =
|
|
|
|
ComputeCheckmarkColor(aState, aAccent, aUseSystemColors);
|
2021-02-22 16:18:33 +00:00
|
|
|
aDrawTarget.FillRect(rect, ColorPattern(ToDeviceColor(fillColor)));
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 23:22:19 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void nsNativeBasicTheme::PaintStrokedCircle(PaintBackendData& aPaintData,
|
2021-02-23 12:25:35 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2021-02-23 23:22:19 +00:00
|
|
|
const sRGBColor& aBackgroundColor,
|
|
|
|
const sRGBColor& aBorderColor,
|
|
|
|
const CSSCoord aBorderWidth,
|
2021-02-23 12:25:35 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
2021-02-23 23:22:19 +00:00
|
|
|
auto radius = LayoutDeviceCoord(aRect.Size().width) / aDpiRatio;
|
|
|
|
PaintRoundedRectWithRadius(aPaintData, aRect, aBackgroundColor, aBorderColor,
|
|
|
|
aBorderWidth, radius, aDpiRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsNativeBasicTheme::PaintCircleShadow(WebRenderBackendData& aWrData,
|
|
|
|
const LayoutDeviceRect& aBoxRect,
|
|
|
|
const LayoutDeviceRect& aClipRect,
|
|
|
|
float aShadowAlpha,
|
|
|
|
const CSSPoint& aShadowOffset,
|
|
|
|
CSSCoord aShadowBlurStdDev,
|
|
|
|
DPIRatio aDpiRatio) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsNativeBasicTheme::PaintCircleShadow(DrawTarget& aDrawTarget,
|
|
|
|
const LayoutDeviceRect& aBoxRect,
|
|
|
|
const LayoutDeviceRect& aClipRect,
|
|
|
|
float aShadowAlpha,
|
|
|
|
const CSSPoint& aShadowOffset,
|
|
|
|
CSSCoord aShadowBlurStdDev,
|
|
|
|
DPIRatio aDpiRatio) {
|
2020-11-02 17:09:05 +00:00
|
|
|
Float stdDev = aShadowBlurStdDev * aDpiRatio;
|
2020-11-30 04:48:07 +00:00
|
|
|
Point offset = (aShadowOffset * aDpiRatio).ToUnknownPoint();
|
2020-11-02 17:09:05 +00:00
|
|
|
|
|
|
|
RefPtr<FilterNode> blurFilter =
|
2021-02-22 16:18:33 +00:00
|
|
|
aDrawTarget.CreateFilter(FilterType::GAUSSIAN_BLUR);
|
2020-11-02 17:09:05 +00:00
|
|
|
if (!blurFilter) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
blurFilter->SetAttribute(ATT_GAUSSIAN_BLUR_STD_DEVIATION, stdDev);
|
|
|
|
|
|
|
|
IntSize inflation =
|
|
|
|
gfxAlphaBoxBlur::CalculateBlurRadius(gfxPoint(stdDev, stdDev));
|
2021-02-23 23:22:19 +00:00
|
|
|
Rect inflatedRect = aBoxRect.ToUnknownRect();
|
2020-11-02 17:09:05 +00:00
|
|
|
inflatedRect.Inflate(inflation.width, inflation.height);
|
2020-11-29 22:19:10 +00:00
|
|
|
Rect sourceRectInFilterSpace =
|
2021-02-23 23:22:19 +00:00
|
|
|
inflatedRect - aBoxRect.TopLeft().ToUnknownPoint();
|
2020-11-02 17:09:05 +00:00
|
|
|
Point destinationPointOfSourceRect = inflatedRect.TopLeft() + offset;
|
|
|
|
|
2021-02-23 23:22:19 +00:00
|
|
|
IntSize dtSize = RoundedToInt(aBoxRect.Size().ToUnknownSize());
|
2021-02-22 16:18:33 +00:00
|
|
|
RefPtr<DrawTarget> ellipseDT = aDrawTarget.CreateSimilarDrawTargetForFilter(
|
2020-11-02 17:09:05 +00:00
|
|
|
dtSize, SurfaceFormat::A8, blurFilter, blurFilter,
|
|
|
|
sourceRectInFilterSpace, destinationPointOfSourceRect);
|
|
|
|
if (!ellipseDT) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-23 23:22:19 +00:00
|
|
|
AutoClipRect clipRect(aDrawTarget, aClipRect);
|
|
|
|
|
2020-11-02 17:09:05 +00:00
|
|
|
RefPtr<Path> ellipse = MakePathForEllipse(
|
2021-02-23 23:22:19 +00:00
|
|
|
*ellipseDT, (aBoxRect - aBoxRect.TopLeft()).Center().ToUnknownPoint(),
|
|
|
|
aBoxRect.Size().ToUnknownSize());
|
2020-11-02 17:09:05 +00: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 16:18:33 +00:00
|
|
|
aDrawTarget.DrawFilter(blurFilter, sourceRectInFilterSpace,
|
|
|
|
destinationPointOfSourceRect);
|
2020-11-02 17:09:05 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 23:22:19 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void nsNativeBasicTheme::PaintRadioControl(PaintBackendData& aPaintData,
|
2020-11-29 22:19:10 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2020-07-30 17:02:02 +00:00
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2020-11-30 04:48:07 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
2021-04-27 10:41:00 +00:00
|
|
|
auto [backgroundColor, borderColor] = ComputeCheckboxColors(
|
|
|
|
aState, StyleAppearance::Radio, aAccent, aUseSystemColors);
|
2021-03-12 12:28:44 +00:00
|
|
|
{
|
|
|
|
CSSCoord borderWidth = kCheckboxRadioBorderWidth;
|
|
|
|
if (backgroundColor == borderColor) {
|
|
|
|
borderWidth = 0.0f;
|
|
|
|
}
|
|
|
|
PaintStrokedCircle(aPaintData, aRect, backgroundColor, borderColor,
|
|
|
|
borderWidth, aDpiRatio);
|
|
|
|
}
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2021-03-12 11:25:49 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_CHECKED)) {
|
|
|
|
LayoutDeviceRect rect(aRect);
|
2021-03-12 12:28:44 +00:00
|
|
|
rect.Deflate(SnapBorderWidth(kCheckboxRadioBorderWidth, aDpiRatio));
|
2021-03-12 11:25:49 +00:00
|
|
|
|
2021-04-27 10:41:00 +00:00
|
|
|
auto checkColor = ComputeCheckmarkColor(aState, aAccent, aUseSystemColors);
|
2021-03-12 11:25:49 +00:00
|
|
|
PaintStrokedCircle(aPaintData, rect, backgroundColor, checkColor,
|
2021-03-12 12:28:44 +00:00
|
|
|
kCheckboxRadioBorderWidth, aDpiRatio);
|
2021-03-12 11:25:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-19 02:15:44 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aAccent, aUseSystemColors,
|
|
|
|
aDpiRatio, 5.0f, 1.0f);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void nsNativeBasicTheme::PaintTextField(PaintBackendData& aPaintData,
|
2020-11-29 22:19:10 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2020-07-30 17:02:02 +00:00
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2020-11-30 04:48:07 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [backgroundColor, borderColor] =
|
|
|
|
ComputeTextfieldColors(aState, aUseSystemColors);
|
2020-03-05 00:25:31 +00:00
|
|
|
|
2020-07-30 17:02:02 +00:00
|
|
|
const CSSCoord radius = 2.0f;
|
2020-03-05 00:25:31 +00:00
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
PaintRoundedRectWithRadius(aPaintData, aRect, backgroundColor, borderColor,
|
2020-07-30 17:02:02 +00:00
|
|
|
kTextFieldBorderWidth, radius, aDpiRatio);
|
|
|
|
|
2020-11-19 02:15:44 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aAccent, aUseSystemColors,
|
|
|
|
aDpiRatio, radius + kTextFieldBorderWidth,
|
2021-01-21 22:12:14 +00:00
|
|
|
-kTextFieldBorderWidth);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void nsNativeBasicTheme::PaintListbox(PaintBackendData& aPaintData,
|
2020-11-29 22:19:10 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2020-07-30 17:02:02 +00:00
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2020-11-30 04:48:07 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
2020-07-30 17:02:02 +00:00
|
|
|
const CSSCoord radius = 2.0f;
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [backgroundColor, borderColor] =
|
|
|
|
ComputeTextfieldColors(aState, aUseSystemColors);
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
PaintRoundedRectWithRadius(aPaintData, aRect, backgroundColor, borderColor,
|
2020-07-30 17:02:02 +00:00
|
|
|
kMenulistBorderWidth, radius, aDpiRatio);
|
2020-03-06 17:54:04 +00:00
|
|
|
|
2020-11-19 02:15:44 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aAccent, aUseSystemColors,
|
|
|
|
aDpiRatio, radius + kMenulistBorderWidth,
|
|
|
|
-kMenulistBorderWidth);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void nsNativeBasicTheme::PaintMenulist(PaintBackendData& aDrawTarget,
|
2020-11-29 22:19:10 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2020-07-30 17:02:02 +00:00
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2020-11-30 04:48:07 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
2020-07-30 17:02:02 +00:00
|
|
|
const CSSCoord radius = 4.0f;
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [backgroundColor, borderColor] =
|
|
|
|
ComputeButtonColors(aState, aUseSystemColors);
|
2020-07-30 17:02:02 +00:00
|
|
|
|
|
|
|
PaintRoundedRectWithRadius(aDrawTarget, aRect, backgroundColor, borderColor,
|
|
|
|
kMenulistBorderWidth, radius, aDpiRatio);
|
|
|
|
|
2020-11-19 02:15:44 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRoundedFocusRect(aDrawTarget, aRect, aAccent, aUseSystemColors,
|
|
|
|
aDpiRatio, radius + kMenulistBorderWidth,
|
|
|
|
-kMenulistBorderWidth);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
void nsNativeBasicTheme::PaintArrow(DrawTarget& aDrawTarget,
|
2021-01-20 21:54:58 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
const float aArrowPolygonX[],
|
|
|
|
const float aArrowPolygonY[],
|
2021-03-01 22:55:37 +00:00
|
|
|
const float aArrowPolygonSize,
|
2021-01-20 21:54:58 +00:00
|
|
|
const int32_t aArrowNumPoints,
|
|
|
|
const sRGBColor aFillColor) {
|
2021-03-01 22:55:37 +00:00
|
|
|
const float scale = ScaleToFillRect(aRect, aArrowPolygonSize);
|
2021-01-20 21:54:58 +00:00
|
|
|
|
2020-11-29 22:19:10 +00:00
|
|
|
auto center = aRect.Center().ToUnknownPoint();
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
|
2021-01-20 21:54:58 +00:00
|
|
|
Point p =
|
|
|
|
center + Point(aArrowPolygonX[0] * scale, aArrowPolygonY[0] * scale);
|
2020-02-10 19:26:01 +00:00
|
|
|
builder->MoveTo(p);
|
2021-01-20 21:54:58 +00:00
|
|
|
for (int32_t i = 1; i < aArrowNumPoints; i++) {
|
|
|
|
p = center + Point(aArrowPolygonX[i] * scale, aArrowPolygonY[i] * scale);
|
2020-02-10 19:26:01 +00:00
|
|
|
builder->LineTo(p);
|
|
|
|
}
|
|
|
|
RefPtr<Path> path = builder->Finish();
|
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
aDrawTarget.Fill(path, ColorPattern(ToDeviceColor(aFillColor)));
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
void nsNativeBasicTheme::PaintMenulistArrowButton(
|
|
|
|
nsIFrame* aFrame, DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect,
|
|
|
|
const EventStates& aState, UseSystemColors aUseSystemColors) {
|
2021-03-02 16:14:46 +00:00
|
|
|
const float kPolygonX[] = {-4.0f, -0.5f, 0.5f, 4.0f, 4.0f,
|
2021-03-02 00:48:36 +00:00
|
|
|
3.0f, 0.0f, 0.0f, -3.0f, -4.0f};
|
2021-03-02 16:14:46 +00:00
|
|
|
const float kPolygonY[] = {-1, 3.0f, 3.0f, -1.0f, -2.0f,
|
2021-03-02 00:48:36 +00:00
|
|
|
-2.0f, 1.5f, 1.5f, -2.0f, -2.0f};
|
2021-03-01 22:55:37 +00:00
|
|
|
|
2021-03-02 00:48:36 +00:00
|
|
|
const float kPolygonSize = kMinimumDropdownArrowButtonWidth;
|
2021-03-01 22:55:37 +00:00
|
|
|
|
2021-05-17 12:11:15 +00:00
|
|
|
const auto arrowColor = sRGBColor::FromABGR(
|
|
|
|
nsLayoutUtils::GetColor(aFrame, &nsStyleText::mWebkitTextFillColor));
|
2021-03-01 22:55:37 +00:00
|
|
|
PaintArrow(aDrawTarget, aRect, kPolygonX, kPolygonY, kPolygonSize,
|
|
|
|
ArrayLength(kPolygonX), arrowColor);
|
2020-07-29 23:58:03 +00:00
|
|
|
}
|
2020-07-29 22:16:06 +00:00
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
void nsNativeBasicTheme::PaintSpinnerButton(
|
|
|
|
nsIFrame* aFrame, DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect,
|
|
|
|
const EventStates& aState, StyleAppearance aAppearance,
|
|
|
|
UseSystemColors aUseSystemColors, DPIRatio aDpiRatio) {
|
|
|
|
auto [backgroundColor, borderColor] =
|
|
|
|
ComputeButtonColors(aState, aUseSystemColors);
|
2020-07-29 23:58:03 +00:00
|
|
|
|
2021-02-22 16:18:33 +00:00
|
|
|
aDrawTarget.FillRect(aRect.ToUnknownRect(),
|
|
|
|
ColorPattern(ToDeviceColor(backgroundColor)));
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2021-03-02 16:14:46 +00:00
|
|
|
const float kPolygonX[] = {-3.5f, -0.5f, 0.5f, 3.5f, 3.5f,
|
2021-03-02 00:48:36 +00: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 17:02:02 +00:00
|
|
|
}
|
2021-03-02 00:48:36 +00:00
|
|
|
|
|
|
|
PaintArrow(aDrawTarget, aRect, kPolygonX, polygonY, kPolygonSize,
|
|
|
|
ArrayLength(kPolygonX), borderColor);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 23:22:19 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void nsNativeBasicTheme::PaintRange(nsIFrame* aFrame,
|
|
|
|
PaintBackendData& aPaintData,
|
2020-11-29 22:19:10 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2020-10-26 23:17:57 +00:00
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2020-11-30 04:48:07 +00:00
|
|
|
DPIRatio aDpiRatio, bool aHorizontal) {
|
2020-07-30 17:02:02 +00:00
|
|
|
nsRangeFrame* rangeFrame = do_QueryFrame(aFrame);
|
|
|
|
if (!rangeFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 23:17:57 +00:00
|
|
|
double progress = rangeFrame->GetValueAsFractionOfRange();
|
2020-11-29 22:19:10 +00:00
|
|
|
auto rect = aRect;
|
|
|
|
LayoutDeviceRect thumbRect(0, 0, kMinimumRangeThumbSize * aDpiRatio,
|
|
|
|
kMinimumRangeThumbSize * aDpiRatio);
|
2021-02-23 23:22:19 +00:00
|
|
|
LayoutDeviceRect progressClipRect(aRect);
|
|
|
|
LayoutDeviceRect trackClipRect(aRect);
|
2020-11-30 04:48:07 +00:00
|
|
|
const LayoutDeviceCoord verticalSize = kRangeHeight * aDpiRatio;
|
2020-07-30 17:02:02 +00:00
|
|
|
if (aHorizontal) {
|
|
|
|
rect.height = verticalSize;
|
2020-10-26 23:17:57 +00:00
|
|
|
rect.y = aRect.y + (aRect.height - rect.height) / 2;
|
|
|
|
thumbRect.y = aRect.y + (aRect.height - thumbRect.height) / 2;
|
2020-03-07 09:58:30 +00:00
|
|
|
|
2020-07-30 17:02:02 +00:00
|
|
|
if (IsFrameRTL(aFrame)) {
|
2020-10-26 23:17:57 +00:00
|
|
|
thumbRect.x =
|
|
|
|
aRect.x + (aRect.width - thumbRect.width) * (1.0 - progress);
|
2020-11-02 17:09:05 +00:00
|
|
|
float midPoint = thumbRect.Center().X();
|
2021-02-23 23:22:19 +00:00
|
|
|
trackClipRect.SetBoxX(aRect.X(), midPoint);
|
|
|
|
progressClipRect.SetBoxX(midPoint, aRect.XMost());
|
2020-07-30 17:02:02 +00:00
|
|
|
} else {
|
2020-10-26 23:17:57 +00:00
|
|
|
thumbRect.x = aRect.x + (aRect.width - thumbRect.width) * progress;
|
2020-11-02 17:09:05 +00:00
|
|
|
float midPoint = thumbRect.Center().X();
|
2021-02-23 23:22:19 +00:00
|
|
|
progressClipRect.SetBoxX(aRect.X(), midPoint);
|
|
|
|
trackClipRect.SetBoxX(midPoint, aRect.XMost());
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
2020-03-07 09:58:30 +00:00
|
|
|
} else {
|
2020-10-26 23:17:57 +00:00
|
|
|
rect.width = verticalSize;
|
|
|
|
rect.x = aRect.x + (aRect.width - rect.width) / 2;
|
|
|
|
thumbRect.x = aRect.x + (aRect.width - thumbRect.width) / 2;
|
|
|
|
|
2021-03-07 21:44:37 +00:00
|
|
|
thumbRect.y =
|
|
|
|
aRect.y + (aRect.height - thumbRect.height) * (1.0 - progress);
|
2020-11-02 17:09:05 +00:00
|
|
|
float midPoint = thumbRect.Center().Y();
|
2021-02-23 23:22:19 +00:00
|
|
|
trackClipRect.SetBoxY(aRect.Y(), midPoint);
|
|
|
|
progressClipRect.SetBoxY(midPoint, aRect.YMost());
|
2020-07-29 22:16:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 17:02:02 +00:00
|
|
|
const CSSCoord borderWidth = 1.0f;
|
2021-04-02 14:39:17 +00:00
|
|
|
const CSSCoord radius = 3.0f;
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2020-11-17 20:53:01 +00:00
|
|
|
auto [progressColor, progressBorderColor] =
|
2021-04-27 10:41:00 +00:00
|
|
|
ComputeRangeProgressColors(aState, aAccent, aUseSystemColors);
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [trackColor, trackBorderColor] =
|
|
|
|
ComputeRangeTrackColors(aState, aUseSystemColors);
|
2020-10-26 23:17:50 +00:00
|
|
|
|
2021-02-23 23:22:19 +00:00
|
|
|
PaintRoundedRectWithRadius(aPaintData, rect, progressClipRect, progressColor,
|
|
|
|
progressBorderColor, borderWidth, radius,
|
|
|
|
aDpiRatio);
|
|
|
|
|
|
|
|
PaintRoundedRectWithRadius(aPaintData, rect, trackClipRect, trackColor,
|
|
|
|
trackBorderColor, borderWidth, radius, aDpiRatio);
|
|
|
|
|
|
|
|
if (!aState.HasState(NS_EVENT_STATE_DISABLED)) {
|
|
|
|
// 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-26 23:18:00 +00:00
|
|
|
}
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2020-10-26 23:18:00 +00:00
|
|
|
// Draw the thumb on top.
|
|
|
|
const CSSCoord thumbBorderWidth = 2.0f;
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [thumbColor, thumbBorderColor] =
|
2021-04-27 10:41:00 +00:00
|
|
|
ComputeRangeThumbColors(aState, aAccent, aUseSystemColors);
|
2020-10-26 23:18:00 +00:00
|
|
|
|
2021-02-23 23:22:19 +00:00
|
|
|
PaintStrokedCircle(aPaintData, thumbRect, thumbColor, thumbBorderColor,
|
|
|
|
thumbBorderWidth, aDpiRatio);
|
2020-10-26 23:18:00 +00:00
|
|
|
|
2020-11-19 02:15:44 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aAccent, aUseSystemColors,
|
|
|
|
aDpiRatio, radius, 1.0f);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
2020-07-29 22:16:06 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void nsNativeBasicTheme::PaintProgress(nsIFrame* aFrame,
|
|
|
|
PaintBackendData& aPaintData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2021-03-15 21:01:08 +00:00
|
|
|
DPIRatio aDpiRatio, bool aIsMeter) {
|
2020-07-30 17:02:02 +00:00
|
|
|
const CSSCoord borderWidth = 1.0f;
|
2021-04-02 14:39:17 +00:00
|
|
|
const CSSCoord radius = aIsMeter ? 6.0f : 3.0f;
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2020-11-29 22:19:10 +00:00
|
|
|
LayoutDeviceRect rect(aRect);
|
2021-02-18 06:12:54 +00:00
|
|
|
const LayoutDeviceCoord thickness =
|
2021-01-28 20:58:39 +00:00
|
|
|
(aIsMeter ? kMeterHeight : kProgressbarHeight) * aDpiRatio;
|
2021-02-18 06:12:54 +00: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 17:02:02 +00:00
|
|
|
|
2021-03-15 21:01:08 +00:00
|
|
|
{
|
|
|
|
// Paint the track, unclipped.
|
|
|
|
auto [backgroundColor, borderColor] =
|
2021-03-15 21:06:54 +00:00
|
|
|
ComputeProgressTrackColors(aUseSystemColors);
|
2021-03-15 21:01:08 +00:00
|
|
|
PaintRoundedRectWithRadius(aPaintData, rect, rect, backgroundColor,
|
|
|
|
borderColor, borderWidth, radius, aDpiRatio);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 21:01:08 +00:00
|
|
|
// Now paint the chunk, clipped as needed.
|
|
|
|
LayoutDeviceRect clipRect = rect;
|
|
|
|
if (aState.HasState(NS_EVENT_STATE_INDETERMINATE)) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
return meter->Value() / meter->Max();
|
|
|
|
}
|
|
|
|
auto* progress = dom::HTMLProgressElement::FromNode(aFrame->GetContent());
|
|
|
|
if (!progress) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
return progress->Value() / progress->Max();
|
|
|
|
}();
|
|
|
|
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-15 21:01:08 +00:00
|
|
|
}
|
2021-03-15 21:01:08 +00:00
|
|
|
|
|
|
|
auto [backgroundColor, borderColor] =
|
|
|
|
aIsMeter ? ComputeMeterchunkColors(aState, aUseSystemColors)
|
2021-04-27 10:41:00 +00:00
|
|
|
: ComputeProgressColors(aAccent, aUseSystemColors);
|
2021-03-15 21:01:08 +00:00
|
|
|
PaintRoundedRectWithRadius(aPaintData, rect, clipRect, backgroundColor,
|
|
|
|
borderColor, borderWidth, radius, aDpiRatio);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
void nsNativeBasicTheme::PaintButton(nsIFrame* aFrame,
|
|
|
|
PaintBackendData& aPaintData,
|
2020-11-29 22:19:10 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2020-07-30 17:02:02 +00:00
|
|
|
const EventStates& aState,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2020-11-30 04:48:07 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
2020-07-30 17:02:02 +00:00
|
|
|
const CSSCoord radius = 4.0f;
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [backgroundColor, borderColor] =
|
|
|
|
ComputeButtonColors(aState, aUseSystemColors, aFrame);
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
PaintRoundedRectWithRadius(aPaintData, aRect, backgroundColor, borderColor,
|
2020-07-30 17:02:02 +00:00
|
|
|
kButtonBorderWidth, radius, aDpiRatio);
|
|
|
|
|
2020-11-19 02:15:44 +00:00
|
|
|
if (aState.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRoundedFocusRect(aPaintData, aRect, aAccent, aUseSystemColors,
|
|
|
|
aDpiRatio, radius + kButtonBorderWidth,
|
|
|
|
-kButtonBorderWidth);
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
bool nsNativeBasicTheme::DoPaintDefaultScrollbarThumb(
|
|
|
|
PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
|
|
|
|
bool aHorizontal, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors, DPIRatio aDpiRatio) {
|
|
|
|
sRGBColor thumbColor = ComputeScrollbarThumbColor(
|
|
|
|
aFrame, aStyle, aElementState, aDocumentState, aUseSystemColors);
|
2021-02-23 10:49:37 +00:00
|
|
|
FillRect(aPaintData, aRect, thumbColor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
bool nsNativeBasicTheme::PaintScrollbarThumb(
|
|
|
|
DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, bool aHorizontal,
|
|
|
|
nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
UseSystemColors aUseSystemColors, DPIRatio aDpiRatio) {
|
2021-02-23 10:49:37 +00:00
|
|
|
return DoPaintDefaultScrollbarThumb(aDrawTarget, aRect, aHorizontal, aFrame,
|
|
|
|
aStyle, aElementState, aDocumentState,
|
2021-03-12 14:44:13 +00:00
|
|
|
aUseSystemColors, aDpiRatio);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
bool nsNativeBasicTheme::PaintScrollbarThumb(
|
|
|
|
WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
|
|
|
|
bool aHorizontal, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
UseSystemColors aUseSystemColors, DPIRatio aDpiRatio) {
|
2021-02-23 10:49:37 +00:00
|
|
|
return DoPaintDefaultScrollbarThumb(aWrData, aRect, aHorizontal, aFrame,
|
|
|
|
aStyle, aElementState, aDocumentState,
|
2021-03-12 14:44:13 +00:00
|
|
|
aUseSystemColors, aDpiRatio);
|
2021-02-23 01:10:22 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
bool nsNativeBasicTheme::DoPaintDefaultScrollbar(
|
|
|
|
PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
|
|
|
|
bool aHorizontal, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2021-03-30 03:31:21 +00:00
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
UseSystemColors aUseSystemColors, DPIRatio aDpiRatio) {
|
|
|
|
if (sOverlayScrollbars && !aElementState.HasAtLeastOneOfStates(
|
|
|
|
NS_EVENT_STATE_HOVER | NS_EVENT_STATE_ACTIVE)) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-08 09:48:01 +00:00
|
|
|
auto scrollbarColor = ComputeScrollbarTrackColor(
|
|
|
|
aFrame, aStyle, aDocumentState, aUseSystemColors);
|
2021-02-23 10:49:37 +00:00
|
|
|
FillRect(aPaintData, aRect, scrollbarColor);
|
|
|
|
return true;
|
2021-02-23 02:58:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 03:31:21 +00:00
|
|
|
bool nsNativeBasicTheme::PaintScrollbar(
|
|
|
|
DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, bool aHorizontal,
|
|
|
|
nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
UseSystemColors aUseSystemColors, DPIRatio aDpiRatio) {
|
2021-02-23 10:49:37 +00:00
|
|
|
return DoPaintDefaultScrollbar(aDrawTarget, aRect, aHorizontal, aFrame,
|
2021-03-30 03:31:21 +00:00
|
|
|
aStyle, aElementState, aDocumentState,
|
|
|
|
aUseSystemColors, aDpiRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 03:31:21 +00:00
|
|
|
bool nsNativeBasicTheme::PaintScrollbar(
|
|
|
|
WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
|
|
|
|
bool aHorizontal, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
UseSystemColors aUseSystemColors, DPIRatio aDpiRatio) {
|
2021-02-23 10:49:37 +00:00
|
|
|
return DoPaintDefaultScrollbar(aWrData, aRect, aHorizontal, aFrame, aStyle,
|
2021-03-30 03:31:21 +00:00
|
|
|
aElementState, aDocumentState,
|
|
|
|
aUseSystemColors, aDpiRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename PaintBackendData>
|
|
|
|
bool nsNativeBasicTheme::DoPaintDefaultScrollCorner(
|
|
|
|
PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
|
|
|
|
nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aDocumentState, UseSystemColors aUseSystemColors,
|
|
|
|
DPIRatio aDpiRatio) {
|
2021-04-08 09:48:01 +00:00
|
|
|
auto scrollbarColor = ComputeScrollbarTrackColor(
|
|
|
|
aFrame, aStyle, aDocumentState, aUseSystemColors);
|
2021-02-23 10:49:37 +00:00
|
|
|
FillRect(aPaintData, aRect, scrollbarColor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-12 14:44:13 +00:00
|
|
|
bool nsNativeBasicTheme::PaintScrollCorner(
|
|
|
|
DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect, nsIFrame* aFrame,
|
|
|
|
const ComputedStyle& aStyle, const EventStates& aDocumentState,
|
|
|
|
UseSystemColors aUseSystemColors, DPIRatio aDpiRatio) {
|
2021-02-23 10:49:37 +00:00
|
|
|
return DoPaintDefaultScrollCorner(aDrawTarget, aRect, aFrame, aStyle,
|
2021-03-12 14:44:13 +00:00
|
|
|
aDocumentState, aUseSystemColors,
|
|
|
|
aDpiRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::PaintScrollCorner(WebRenderBackendData& aWrData,
|
|
|
|
const LayoutDeviceRect& aRect,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aDocumentState,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2021-02-23 10:49:37 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
|
|
|
return DoPaintDefaultScrollCorner(aWrData, aRect, aFrame, aStyle,
|
2021-03-12 14:44:13 +00:00
|
|
|
aDocumentState, aUseSystemColors,
|
|
|
|
aDpiRatio);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 21:33:34 +00:00
|
|
|
void nsNativeBasicTheme::PaintScrollbarButton(
|
2021-02-22 16:18:33 +00:00
|
|
|
DrawTarget& aDrawTarget, StyleAppearance aAppearance,
|
2021-01-20 21:33:34 +00:00
|
|
|
const LayoutDeviceRect& aRect, nsIFrame* aFrame,
|
|
|
|
const ComputedStyle& aStyle, const EventStates& aElementState,
|
2021-03-12 14:44:13 +00:00
|
|
|
const EventStates& aDocumentState, UseSystemColors aUseSystemColors,
|
|
|
|
DPIRatio aDpiRatio) {
|
|
|
|
auto [buttonColor, arrowColor] =
|
|
|
|
ComputeScrollbarButtonColors(aFrame, aAppearance, aStyle, aElementState,
|
|
|
|
aDocumentState, aUseSystemColors);
|
2021-02-22 16:18:33 +00:00
|
|
|
aDrawTarget.FillRect(aRect.ToUnknownRect(),
|
|
|
|
ColorPattern(ToDeviceColor(buttonColor)));
|
2020-02-10 19:26:01 +00:00
|
|
|
|
|
|
|
// Start with Up arrow.
|
2021-03-01 22:55:37 +00:00
|
|
|
float arrowPolygonX[] = {-4.0f, 0.0f, 4.0f, 4.0f, 0.0f, -4.0f};
|
|
|
|
float arrowPolygonY[] = {0.0f, -4.0f, 0.0f, 3.0f, -1.0f, 3.0f};
|
|
|
|
|
2021-03-18 19:12:49 +00:00
|
|
|
const float kPolygonSize = 17;
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2021-01-21 16:46:33 +00:00
|
|
|
const int32_t arrowNumPoints = ArrayLength(arrowPolygonX);
|
2020-02-10 19:26:01 +00:00
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
|
|
|
arrowPolygonY[i] *= -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
|
|
|
int32_t temp = arrowPolygonX[i];
|
|
|
|
arrowPolygonX[i] = arrowPolygonY[i];
|
|
|
|
arrowPolygonY[i] = temp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
|
|
|
int32_t temp = arrowPolygonX[i];
|
|
|
|
arrowPolygonX[i] = arrowPolygonY[i] * -1;
|
|
|
|
arrowPolygonY[i] = temp;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2021-03-01 22:55:37 +00:00
|
|
|
PaintArrow(aDrawTarget, aRect, arrowPolygonX, arrowPolygonY, kPolygonSize,
|
|
|
|
arrowNumPoints, arrowColor);
|
2020-03-06 17:54:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeBasicTheme::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
const nsRect& aRect,
|
2021-03-20 23:08:11 +00:00
|
|
|
const nsRect& /* aDirtyRect */,
|
|
|
|
DrawOverflow aDrawOverflow) {
|
2021-02-23 10:49:37 +00:00
|
|
|
if (!DoDrawWidgetBackground(*aContext->GetDrawTarget(), aFrame, aAppearance,
|
2021-03-20 23:08:11 +00:00
|
|
|
aRect, aDrawOverflow)) {
|
2021-02-23 10:49:37 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2021-02-23 04:41:58 +00:00
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
bool nsNativeBasicTheme::CreateWebRenderCommandsForWidget(
|
|
|
|
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 16:11:33 +00:00
|
|
|
return DoDrawWidgetBackground(data, aFrame, aAppearance, aRect,
|
|
|
|
DrawOverflow::Yes);
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static LayoutDeviceRect ToSnappedRect(const nsRect& aRect,
|
|
|
|
nscoord aTwipsPerPixel, DrawTarget& aDt) {
|
|
|
|
return LayoutDeviceRect::FromUnknownRect(
|
|
|
|
NSRectToSnappedRect(aRect, aTwipsPerPixel, aDt));
|
|
|
|
}
|
|
|
|
|
|
|
|
static LayoutDeviceRect ToSnappedRect(
|
|
|
|
const nsRect& aRect, nscoord aTwipsPerPixel,
|
|
|
|
nsNativeBasicTheme::WebRenderBackendData& aDt) {
|
|
|
|
// TODO: Do we need to do any more snapping here?
|
|
|
|
return LayoutDeviceRect::FromAppUnits(aRect, aTwipsPerPixel);
|
|
|
|
}
|
|
|
|
|
2021-06-22 10:43:17 +00:00
|
|
|
auto nsNativeBasicTheme::ShouldUseSystemColors(const nsPresContext& aPc)
|
2021-03-12 14:44:13 +00:00
|
|
|
-> UseSystemColors {
|
2021-06-22 10:43:17 +00:00
|
|
|
// We make sure that we're drawing backgrounds, since otherwise layout will
|
|
|
|
// darken our used text colors etc anyways, and that can cause contrast issues
|
|
|
|
// with dark high-contrast themes.
|
|
|
|
return UseSystemColors(aPc.GetBackgroundColorDraw() &&
|
|
|
|
PreferenceSheet::PrefsFor(*aPc.Document())
|
|
|
|
.NonNativeThemeShouldUseSystemColors());
|
2021-03-12 14:44:13 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
|
|
|
bool nsNativeBasicTheme::DoDrawWidgetBackground(PaintBackendData& aPaintData,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
2021-03-20 23:08:11 +00:00
|
|
|
const nsRect& aRect,
|
|
|
|
DrawOverflow aDrawOverflow) {
|
2021-02-23 10:49:37 +00: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);
|
|
|
|
|
|
|
|
const EventStates docState = pc->Document()->GetDocumentState();
|
2021-06-22 10:43:17 +00:00
|
|
|
const auto useSystemColors = ShouldUseSystemColors(*pc);
|
2021-02-23 10:49:37 +00:00
|
|
|
EventStates eventState = GetContentState(aFrame, aAppearance);
|
2020-03-05 21:13:46 +00:00
|
|
|
if (aAppearance == StyleAppearance::MozMenulistArrowButton) {
|
2020-02-10 19:26:01 +00: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;
|
|
|
|
eventState = GetContentState(parentFrame, aAppearance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-08 12:16:08 +00:00
|
|
|
// Don't paint the outline if we're asked not to draw overflow, or if the
|
|
|
|
// author has specified another kind of outline on focus.
|
|
|
|
if (aDrawOverflow == DrawOverflow::No ||
|
|
|
|
!aFrame->StyleOutline()->mOutlineStyle.IsAuto()) {
|
2021-03-20 23:08:11 +00:00
|
|
|
eventState &= ~NS_EVENT_STATE_FOCUSRING;
|
|
|
|
}
|
|
|
|
|
2021-01-23 19:31:33 +00:00
|
|
|
// Hack to avoid skia fuzziness: Add a dummy clip if the widget doesn't
|
|
|
|
// overflow devPxRect.
|
|
|
|
Maybe<AutoClipRect> maybeClipRect;
|
2021-02-23 10:49:37 +00:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, DrawTarget>) {
|
|
|
|
if (aAppearance != StyleAppearance::FocusOutline &&
|
|
|
|
aAppearance != StyleAppearance::Range &&
|
|
|
|
!eventState.HasState(NS_EVENT_STATE_FOCUSRING)) {
|
|
|
|
maybeClipRect.emplace(aPaintData, devPxRect);
|
|
|
|
}
|
2021-01-23 19:31:33 +00:00
|
|
|
}
|
|
|
|
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor accent(*aFrame->Style());
|
|
|
|
|
2021-01-26 21:34:35 +00:00
|
|
|
DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
|
2020-02-10 19:26:01 +00:00
|
|
|
|
|
|
|
switch (aAppearance) {
|
2020-02-16 16:04:31 +00:00
|
|
|
case StyleAppearance::Radio: {
|
2021-03-12 11:25:49 +00:00
|
|
|
auto rect = CheckBoxRadioRect(devPxRect);
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRadioControl(aPaintData, rect, eventState, accent, useSystemColors,
|
2021-03-12 14:44:13 +00:00
|
|
|
dpiRatio);
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
2020-02-16 16:04:31 +00:00
|
|
|
}
|
|
|
|
case StyleAppearance::Checkbox: {
|
2021-02-23 10:49:37 +00: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 11:25:49 +00:00
|
|
|
auto rect = CheckBoxRadioRect(devPxRect);
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintCheckboxControl(aPaintData, rect, eventState, accent,
|
|
|
|
useSystemColors, dpiRatio);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-02-16 16:04:31 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::NumberInput:
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintTextField(aPaintData, devPxRect, eventState, accent, useSystemColors,
|
2021-03-12 14:44:13 +00:00
|
|
|
dpiRatio);
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Listbox:
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintListbox(aPaintData, devPxRect, eventState, accent, useSystemColors,
|
2021-03-12 14:44:13 +00:00
|
|
|
dpiRatio);
|
2020-07-30 17:02:02 +00:00
|
|
|
break;
|
2020-07-29 23:58:03 +00:00
|
|
|
case StyleAppearance::MenulistButton:
|
2020-07-30 17:02:02 +00:00
|
|
|
case StyleAppearance::Menulist:
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintMenulist(aPaintData, devPxRect, eventState, accent, useSystemColors,
|
2021-03-12 14:44:13 +00:00
|
|
|
dpiRatio);
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
2020-03-05 21:13:46 +00:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2021-02-23 10:49:37 +00: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:44:13 +00:00
|
|
|
PaintMenulistArrowButton(aFrame, aPaintData, devPxRect, eventState,
|
|
|
|
useSystemColors);
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::SpinnerUpbutton:
|
|
|
|
case StyleAppearance::SpinnerDownbutton:
|
2021-02-23 10:49:37 +00:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
|
|
|
|
// TODO: Need to figure out how to best draw this using WR.
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
PaintSpinnerButton(aFrame, aPaintData, devPxRect, eventState,
|
2021-03-12 14:44:13 +00:00
|
|
|
aAppearance, useSystemColors, dpiRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Range:
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintRange(aFrame, aPaintData, devPxRect, eventState, accent,
|
|
|
|
useSystemColors, dpiRatio, IsRangeHorizontal(aFrame));
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::RangeThumb:
|
2020-10-26 23:17:57 +00:00
|
|
|
// Painted as part of StyleAppearance::Range.
|
2020-07-30 17:02:02 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::ProgressBar:
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintProgress(aFrame, aPaintData, devPxRect, eventState, accent,
|
|
|
|
useSystemColors, dpiRatio,
|
2021-03-15 21:01:08 +00:00
|
|
|
/* aIsMeter = */ false);
|
2020-07-30 17:02:02 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Progresschunk:
|
2021-03-15 21:01:08 +00:00
|
|
|
/* Painted as part of the progress bar */
|
2020-07-30 17:02:02 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Meter:
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintProgress(aFrame, aPaintData, devPxRect, eventState, accent,
|
|
|
|
useSystemColors, dpiRatio, /* aIsMeter = */ true);
|
2020-07-30 17:02:02 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Meterchunk:
|
2021-03-15 21:01:08 +00:00
|
|
|
/* Painted as part of the meter bar */
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::ScrollbarthumbHorizontal:
|
2020-10-27 15:27:31 +00:00
|
|
|
case StyleAppearance::ScrollbarthumbVertical: {
|
|
|
|
bool isHorizontal =
|
|
|
|
aAppearance == StyleAppearance::ScrollbarthumbHorizontal;
|
2021-02-23 10:49:37 +00:00
|
|
|
return PaintScrollbarThumb(aPaintData, devPxRect, isHorizontal, aFrame,
|
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame),
|
2021-03-12 14:44:13 +00:00
|
|
|
eventState, docState, useSystemColors,
|
|
|
|
dpiRatio);
|
2020-10-27 15:27:31 +00:00
|
|
|
}
|
2020-11-02 17:09:00 +00:00
|
|
|
case StyleAppearance::ScrollbartrackHorizontal:
|
|
|
|
case StyleAppearance::ScrollbartrackVertical: {
|
|
|
|
bool isHorizontal =
|
|
|
|
aAppearance == StyleAppearance::ScrollbartrackHorizontal;
|
2021-02-23 10:49:37 +00:00
|
|
|
return PaintScrollbarTrack(aPaintData, devPxRect, isHorizontal, aFrame,
|
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame),
|
2021-03-12 14:44:13 +00:00
|
|
|
docState, useSystemColors, dpiRatio);
|
2020-11-02 17:09:00 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::ScrollbarHorizontal:
|
2020-10-27 15:27:31 +00:00
|
|
|
case StyleAppearance::ScrollbarVertical: {
|
|
|
|
bool isHorizontal = aAppearance == StyleAppearance::ScrollbarHorizontal;
|
2021-02-23 10:49:37 +00:00
|
|
|
return PaintScrollbar(aPaintData, devPxRect, isHorizontal, aFrame,
|
2021-03-30 03:31:21 +00:00
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame),
|
|
|
|
eventState, docState, useSystemColors, dpiRatio);
|
2020-10-27 15:27:31 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::Scrollcorner:
|
2021-02-23 10:49:37 +00:00
|
|
|
return PaintScrollCorner(aPaintData, devPxRect, aFrame,
|
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame),
|
2021-03-12 14:44:13 +00:00
|
|
|
docState, useSystemColors, dpiRatio);
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
2021-01-20 21:54:58 +00:00
|
|
|
// For scrollbar-width:thin, we don't display the buttons.
|
|
|
|
if (!IsScrollbarWidthThin(aFrame)) {
|
2021-02-23 10:49:37 +00:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
|
|
|
|
// TODO: Need to figure out how to best draw this using WR.
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
PaintScrollbarButton(aPaintData, aAppearance, devPxRect, aFrame,
|
|
|
|
*nsLayoutUtils::StyleForScrollbar(aFrame),
|
2021-03-12 14:44:13 +00:00
|
|
|
eventState, docState, useSystemColors, dpiRatio);
|
2021-02-23 10:49:37 +00:00
|
|
|
}
|
2021-01-20 21:54:58 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::Button:
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintButton(aFrame, aPaintData, devPxRect, eventState, accent,
|
|
|
|
useSystemColors, dpiRatio);
|
2020-02-10 19:26:01 +00:00
|
|
|
break;
|
2020-11-16 16:53:23 +00:00
|
|
|
case StyleAppearance::FocusOutline:
|
2021-04-27 10:41:00 +00:00
|
|
|
PaintAutoStyleOutline(aFrame, aPaintData, devPxRect, accent,
|
|
|
|
useSystemColors, dpiRatio);
|
2020-11-16 16:53:23 +00:00
|
|
|
break;
|
2020-02-10 19:26:01 +00:00
|
|
|
default:
|
2021-01-10 22:25:07 +00: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-28 22:11:54 +00: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 10:49:37 +00:00
|
|
|
return false;
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
return true;
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
template <typename PaintBackendData>
|
2021-02-08 16:25:16 +00:00
|
|
|
void nsNativeBasicTheme::PaintAutoStyleOutline(nsIFrame* aFrame,
|
2021-02-23 10:49:37 +00:00
|
|
|
PaintBackendData& aPaintData,
|
2021-02-08 16:25:16 +00:00
|
|
|
const LayoutDeviceRect& aRect,
|
2021-04-27 10:41:00 +00:00
|
|
|
const AccentColor& aAccent,
|
2021-03-12 14:44:13 +00:00
|
|
|
UseSystemColors aUseSystemColors,
|
2021-02-08 16:25:16 +00:00
|
|
|
DPIRatio aDpiRatio) {
|
2021-03-12 14:44:13 +00:00
|
|
|
auto [innerColor, middleColor, outerColor] =
|
2021-04-27 10:41:00 +00:00
|
|
|
ComputeFocusRectColors(aAccent, aUseSystemColors);
|
2021-02-08 16:25:16 +00:00
|
|
|
Unused << middleColor;
|
|
|
|
Unused << outerColor;
|
|
|
|
|
2021-02-23 04:41:58 +00:00
|
|
|
LayoutDeviceRect rect(aRect);
|
2021-03-05 01:35:17 +00:00
|
|
|
auto width =
|
|
|
|
LayoutDeviceCoord(SnapBorderWidth(kInnerFocusOutlineWidth, aDpiRatio));
|
2021-02-23 10:49:37 +00:00
|
|
|
rect.Inflate(width);
|
2021-02-08 16:25:16 +00:00
|
|
|
|
2021-03-25 11:28:08 +00:00
|
|
|
const nscoord offset = aFrame->StyleOutline()->mOutlineOffset.ToAppUnits();
|
2021-02-08 16:25:16 +00:00
|
|
|
nscoord cssRadii[8];
|
|
|
|
if (!aFrame->GetBorderRadii(cssRadii)) {
|
2021-03-25 11:28:08 +00:00
|
|
|
const CSSCoord cssOffset = CSSCoord::FromAppUnits(offset);
|
|
|
|
const CSSCoord radius =
|
|
|
|
cssOffset >= 0.0f
|
|
|
|
? kInnerFocusOutlineWidth
|
|
|
|
: std::max(kInnerFocusOutlineWidth + cssOffset, CSSCoord(0.0f));
|
2021-03-06 01:53:38 +00:00
|
|
|
return PaintRoundedRectWithRadius(aPaintData, rect, sRGBColor::White(0.0f),
|
2021-02-23 10:49:37 +00:00
|
|
|
innerColor, kInnerFocusOutlineWidth,
|
2021-03-25 11:28:08 +00:00
|
|
|
radius, aDpiRatio);
|
2021-02-08 16:25:16 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 10:25:32 +00:00
|
|
|
nsPresContext* pc = aFrame->PresContext();
|
|
|
|
const Float devPixelOffset = pc->AppUnitsToFloatDevPixels(offset);
|
|
|
|
|
2021-02-08 16:25:16 +00:00
|
|
|
RectCornerRadii innerRadii;
|
2021-02-16 10:25:32 +00:00
|
|
|
nsCSSRendering::ComputePixelRadii(cssRadii, pc->AppUnitsPerDevPixel(),
|
|
|
|
&innerRadii);
|
2021-02-08 16:25:16 +00:00
|
|
|
|
2021-02-23 10:49:37 +00:00
|
|
|
const auto borderColor = ToDeviceColor(innerColor);
|
|
|
|
// NOTE(emilio): This doesn't use PaintRoundedRectWithRadius because we need
|
|
|
|
// to support arbitrary radii.
|
2021-02-08 16:25:16 +00:00
|
|
|
RectCornerRadii outerRadii;
|
2021-02-23 10:49:37 +00:00
|
|
|
if constexpr (std::is_same_v<PaintBackendData, WebRenderBackendData>) {
|
2021-04-08 14:23:25 +00:00
|
|
|
const Float widths[4] = {width + devPixelOffset, width + devPixelOffset,
|
|
|
|
width + devPixelOffset, width + devPixelOffset};
|
2021-02-23 10:49:37 +00:00
|
|
|
nsCSSBorderRenderer::ComputeOuterRadii(innerRadii, widths, &outerRadii);
|
|
|
|
|
|
|
|
const auto dest = wr::ToLayoutRect(rect);
|
|
|
|
const auto side = wr::ToBorderSide(borderColor, StyleBorderStyle::Solid);
|
|
|
|
const wr::BorderSide sides[4] = {side, side, side, side};
|
|
|
|
const bool kBackfaceIsVisible = true;
|
|
|
|
const auto wrWidths = wr::ToBorderWidths(width, width, width, width);
|
|
|
|
const auto wrRadius = wr::ToBorderRadius(outerRadii);
|
|
|
|
aPaintData.mBuilder.PushBorder(dest, dest, kBackfaceIsVisible, wrWidths,
|
|
|
|
{sides, 4}, wrRadius);
|
|
|
|
} else {
|
|
|
|
const LayoutDeviceCoord halfWidth = width * 0.5f;
|
|
|
|
rect.Deflate(halfWidth);
|
|
|
|
const Float widths[4] = {
|
|
|
|
halfWidth + devPixelOffset, halfWidth + devPixelOffset,
|
|
|
|
halfWidth + devPixelOffset, halfWidth + devPixelOffset};
|
|
|
|
nsCSSBorderRenderer::ComputeOuterRadii(innerRadii, widths, &outerRadii);
|
|
|
|
RefPtr<Path> path =
|
|
|
|
MakePathForRoundedRect(aPaintData, rect.ToUnknownRect(), outerRadii);
|
|
|
|
aPaintData.Stroke(path, ColorPattern(borderColor), StrokeOptions(width));
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
|
2020-12-02 23:11:32 +00:00
|
|
|
LayoutDeviceIntMargin nsNativeBasicTheme::GetWidgetBorder(
|
2020-02-10 19:26:01 +00:00
|
|
|
nsDeviceContext* aContext, nsIFrame* aFrame, StyleAppearance aAppearance) {
|
2020-03-11 01:52:51 +00:00
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::Textarea:
|
2021-01-29 21:18:54 +00:00
|
|
|
case StyleAppearance::NumberInput:
|
2020-03-11 01:52:51 +00:00
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::Menulist:
|
2021-01-29 21:18:54 +00: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
|
|
|
|
// specified by authors, see nsNativeBasicTheme::IsWidgetStyled.
|
|
|
|
//
|
|
|
|
// 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 20:08:35 +00:00
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
case StyleAppearance::Radio: {
|
2021-01-29 21:18:54 +00:00
|
|
|
DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
|
2021-01-26 22:12:03 +00:00
|
|
|
LayoutDeviceIntCoord w =
|
|
|
|
SnapBorderWidth(kCheckboxRadioBorderWidth, dpiRatio);
|
2021-01-20 20:08:35 +00:00
|
|
|
return LayoutDeviceIntMargin(w, w, w, w);
|
|
|
|
}
|
2020-03-11 01:52:51 +00:00
|
|
|
default:
|
2020-12-02 23:11:32 +00:00
|
|
|
return LayoutDeviceIntMargin();
|
2020-03-11 01:52:51 +00:00
|
|
|
}
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::GetWidgetPadding(nsDeviceContext* aContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
2020-12-02 23:11:32 +00:00
|
|
|
LayoutDeviceIntMargin* aResult) {
|
2020-02-10 19:26:01 +00: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-24 22:51:26 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-01-21 21:38:33 +00:00
|
|
|
return false;
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::GetWidgetOverflow(nsDeviceContext* aContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
nsRect* aOverflowRect) {
|
2020-07-30 17:02:02 +00:00
|
|
|
nsIntMargin overflow;
|
|
|
|
switch (aAppearance) {
|
2020-11-16 16:53:23 +00:00
|
|
|
case StyleAppearance::FocusOutline:
|
2021-02-05 16:25:57 +00:00
|
|
|
// 2px * one segment
|
|
|
|
overflow.SizeTo(2, 2, 2, 2);
|
2020-11-16 16:53:23 +00:00
|
|
|
break;
|
2020-07-30 17:02:02 +00:00
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
case StyleAppearance::Range:
|
2021-02-23 23:22:19 +00:00
|
|
|
// 2px for each outline segment, plus 1px separation, plus we paint with a
|
|
|
|
// 1px extra offset, so 6px.
|
2020-07-30 17:02:02 +00:00
|
|
|
overflow.SizeTo(6, 6, 6, 6);
|
|
|
|
break;
|
2020-07-31 15:16:34 +00:00
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::NumberInput:
|
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::MenulistButton:
|
|
|
|
case StyleAppearance::Menulist:
|
|
|
|
case StyleAppearance::Button:
|
2021-01-28 22:11:54 +00:00
|
|
|
// 2px for each segment, plus 1px separation, but we paint 1px inside
|
|
|
|
// the border area so 4px overflow.
|
2020-07-30 17:02:02 +00:00
|
|
|
overflow.SizeTo(4, 4, 4, 4);
|
|
|
|
break;
|
2020-07-31 15:16:34 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 17:09:05 +00: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.
|
2020-07-30 17:02:02 +00:00
|
|
|
aOverflowRect->Inflate(nsMargin(CSSPixel::ToAppUnits(overflow.top),
|
|
|
|
CSSPixel::ToAppUnits(overflow.right),
|
|
|
|
CSSPixel::ToAppUnits(overflow.bottom),
|
|
|
|
CSSPixel::ToAppUnits(overflow.left)));
|
|
|
|
|
|
|
|
return true;
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
2021-01-28 22:11:54 +00:00
|
|
|
auto nsNativeBasicTheme::GetScrollbarSizes(nsPresContext* aPresContext,
|
|
|
|
StyleScrollbarWidth aWidth, Overlay)
|
|
|
|
-> ScrollbarSizes {
|
2021-03-18 19:12:49 +00:00
|
|
|
CSSIntCoord h = sHorizontalScrollbarHeight;
|
|
|
|
CSSIntCoord w = sVerticalScrollbarWidth;
|
|
|
|
if (aWidth == StyleScrollbarWidth::Thin) {
|
|
|
|
h /= 2;
|
|
|
|
w /= 2;
|
|
|
|
}
|
|
|
|
auto dpi = GetDPIRatioForScrollbarPart(aPresContext);
|
|
|
|
return {(CSSCoord(w) * dpi).Rounded(), (CSSCoord(h) * dpi).Rounded()};
|
2021-01-28 22:11:54 +00:00
|
|
|
}
|
|
|
|
|
2021-02-20 00:13:10 +00:00
|
|
|
nscoord nsNativeBasicTheme::GetCheckboxRadioPrefSize() {
|
2021-03-01 22:55:37 +00:00
|
|
|
return CSSPixel::ToAppUnits(kCheckboxRadioContentBoxSize);
|
2021-02-20 00:13:10 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeBasicTheme::GetMinimumWidgetSize(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
2020-12-02 23:11:32 +00:00
|
|
|
LayoutDeviceIntSize* aResult,
|
2020-02-10 19:26:01 +00:00
|
|
|
bool* aIsOverridable) {
|
2021-01-26 21:34:35 +00:00
|
|
|
DPIRatio dpiRatio = GetDPIRatio(aFrame, aAppearance);
|
2020-07-30 17:02:02 +00:00
|
|
|
|
2021-02-20 00:13:10 +00:00
|
|
|
aResult->width = aResult->height = 0;
|
|
|
|
*aIsOverridable = true;
|
2020-07-30 17:02:02 +00:00
|
|
|
|
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::Button:
|
|
|
|
if (IsColorPickerButton(aFrame)) {
|
2020-12-02 23:11:32 +00:00
|
|
|
aResult->height = (kMinimumColorPickerHeight * dpiRatio).Rounded();
|
2020-07-30 17:02:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case StyleAppearance::RangeThumb:
|
2020-12-02 23:11:32 +00:00
|
|
|
aResult->SizeTo((kMinimumRangeThumbSize * dpiRatio).Rounded(),
|
|
|
|
(kMinimumRangeThumbSize * dpiRatio).Rounded());
|
2020-07-30 17:02:02 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2020-12-02 23:11:32 +00:00
|
|
|
aResult->width = (kMinimumDropdownArrowButtonWidth * dpiRatio).Rounded();
|
2020-07-30 17:02:02 +00:00
|
|
|
break;
|
|
|
|
case StyleAppearance::SpinnerUpbutton:
|
|
|
|
case StyleAppearance::SpinnerDownbutton:
|
2020-12-02 23:11:32 +00:00
|
|
|
aResult->width = (kMinimumSpinnerButtonWidth * dpiRatio).Rounded();
|
2021-01-22 16:09:35 +00:00
|
|
|
aResult->height = (kMinimumSpinnerButtonHeight * dpiRatio).Rounded();
|
2020-07-30 17:02:02 +00:00
|
|
|
break;
|
2020-10-15 04:54:41 +00:00
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
2021-01-20 21:54:58 +00:00
|
|
|
// For scrollbar-width:thin, we don't display the buttons.
|
|
|
|
if (IsScrollbarWidthThin(aFrame)) {
|
|
|
|
aResult->SizeTo(0, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[[fallthrough]];
|
2020-10-15 04:54:41 +00:00
|
|
|
case StyleAppearance::ScrollbarthumbVertical:
|
2021-03-01 22:55:32 +00:00
|
|
|
case StyleAppearance::ScrollbarthumbHorizontal: {
|
2021-01-28 22:11:54 +00:00
|
|
|
auto* style = nsLayoutUtils::StyleForScrollbar(aFrame);
|
|
|
|
auto width = style->StyleUIReset()->mScrollbarWidth;
|
|
|
|
auto sizes = GetScrollbarSizes(aPresContext, width, Overlay::No);
|
2021-03-01 22:55:32 +00:00
|
|
|
// TODO: for short scrollbars it could be nice if the thumb could shrink
|
|
|
|
// under this size.
|
2021-03-18 19:12:49 +00:00
|
|
|
const bool isHorizontal =
|
|
|
|
aAppearance == StyleAppearance::ScrollbarthumbHorizontal ||
|
|
|
|
aAppearance == StyleAppearance::ScrollbarbuttonLeft ||
|
|
|
|
aAppearance == StyleAppearance::ScrollbarbuttonRight;
|
|
|
|
const auto size = isHorizontal ? sizes.mHorizontal : sizes.mVertical;
|
|
|
|
aResult->SizeTo(size, size);
|
2020-10-15 04:54:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-07-30 17:02:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-10 19:26:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsITheme::Transparency nsNativeBasicTheme::GetWidgetTransparency(
|
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
|
|
|
return eUnknownTransparency;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeBasicTheme::WidgetStateChanged(nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance,
|
|
|
|
nsAtom* aAttribute, bool* aShouldRepaint,
|
|
|
|
const nsAttrValue* aOldValue) {
|
|
|
|
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 13:57:18 +00: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 19:26:01 +00:00
|
|
|
*aShouldRepaint = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNativeBasicTheme::ThemeChanged() { return NS_OK; }
|
|
|
|
|
2020-10-15 04:54:41 +00:00
|
|
|
bool nsNativeBasicTheme::WidgetAppearanceDependsOnWindowFocus(
|
|
|
|
StyleAppearance aAppearance) {
|
|
|
|
return IsWidgetScrollbarPart(aAppearance);
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsITheme::ThemeGeometryType nsNativeBasicTheme::ThemeGeometryTypeForWidget(
|
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
|
|
|
return eThemeGeometryTypeUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::ThemeSupportsWidget(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
StyleAppearance aAppearance) {
|
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
2020-11-16 16:53:23 +00:00
|
|
|
case StyleAppearance::FocusOutline:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::Textarea:
|
|
|
|
case StyleAppearance::Textfield:
|
|
|
|
case StyleAppearance::Range:
|
2020-03-06 17:54:04 +00:00
|
|
|
case StyleAppearance::RangeThumb:
|
2020-07-30 17:02:02 +00:00
|
|
|
case StyleAppearance::ProgressBar:
|
|
|
|
case StyleAppearance::Progresschunk:
|
|
|
|
case StyleAppearance::Meter:
|
|
|
|
case StyleAppearance::Meterchunk:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
|
|
|
case StyleAppearance::ScrollbarthumbHorizontal:
|
|
|
|
case StyleAppearance::ScrollbarthumbVertical:
|
2020-11-02 17:09:00 +00:00
|
|
|
case StyleAppearance::ScrollbartrackHorizontal:
|
|
|
|
case StyleAppearance::ScrollbartrackVertical:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::ScrollbarHorizontal:
|
|
|
|
case StyleAppearance::ScrollbarVertical:
|
|
|
|
case StyleAppearance::Scrollcorner:
|
|
|
|
case StyleAppearance::Button:
|
|
|
|
case StyleAppearance::Listbox:
|
|
|
|
case StyleAppearance::Menulist:
|
2020-02-19 14:48:43 +00:00
|
|
|
case StyleAppearance::MenulistButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::NumberInput:
|
2020-03-05 21:13:46 +00:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::SpinnerUpbutton:
|
|
|
|
case StyleAppearance::SpinnerDownbutton:
|
|
|
|
return !IsWidgetStyled(aPresContext, aFrame, aAppearance);
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::WidgetIsContainer(StyleAppearance aAppearance) {
|
|
|
|
switch (aAppearance) {
|
2020-03-05 21:13:46 +00:00
|
|
|
case StyleAppearance::MozMenulistArrowButton:
|
2020-02-10 19:26:01 +00:00
|
|
|
case StyleAppearance::Radio:
|
|
|
|
case StyleAppearance::Checkbox:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::ThemeDrawsFocusForWidget(StyleAppearance aAppearance) {
|
2020-07-30 17:02:02 +00:00
|
|
|
return true;
|
2020-02-10 19:26:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool nsNativeBasicTheme::ThemeNeedsComboboxDropmarker() { return true; }
|