2021-12-15 21:06:58 +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 "ScrollbarDrawingWin11.h"
|
|
|
|
|
|
|
|
#include "mozilla/gfx/Helpers.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
|
|
|
#include "mozilla/StaticPrefs_widget.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2022-01-12 16:33:31 +00:00
|
|
|
#include "Theme.h"
|
2021-12-15 21:06:58 +00:00
|
|
|
#include "nsNativeTheme.h"
|
|
|
|
|
2021-12-27 18:53:32 +00:00
|
|
|
using mozilla::gfx::sRGBColor;
|
|
|
|
|
2021-12-15 21:06:58 +00:00
|
|
|
namespace mozilla::widget {
|
|
|
|
|
2022-03-04 13:44:51 +00:00
|
|
|
// There are effectively three kinds of scrollbars in Windows 11:
|
|
|
|
//
|
|
|
|
// * Overlay scrollbars (the ones where the scrollbar disappears automatically
|
|
|
|
// and doesn't take space)
|
|
|
|
// * Non-overlay scrollbar with thin (overlay-like) thumb.
|
|
|
|
// * Non-overlay scrollbar with thick thumb.
|
|
|
|
//
|
|
|
|
// See bug 1755193 for some discussion on non-overlay scrollbar styles.
|
|
|
|
enum class Style {
|
|
|
|
Overlay,
|
|
|
|
ThinThumb,
|
|
|
|
ThickThumb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Style ScrollbarStyle(nsPresContext* aPresContext) {
|
|
|
|
if (aPresContext->UseOverlayScrollbars()) {
|
|
|
|
return Style::Overlay;
|
|
|
|
}
|
|
|
|
if (StaticPrefs::
|
|
|
|
widget_non_native_theme_win11_scrollbar_force_overlay_style()) {
|
|
|
|
return Style::ThinThumb;
|
|
|
|
}
|
|
|
|
return Style::ThickThumb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr CSSIntCoord kDefaultWinOverlayScrollbarSize = CSSIntCoord(12);
|
|
|
|
static constexpr CSSIntCoord kDefaultWinOverlayThinScrollbarSize =
|
|
|
|
CSSIntCoord(10);
|
|
|
|
|
|
|
|
auto ScrollbarDrawingWin11::GetScrollbarSizes(nsPresContext* aPresContext,
|
|
|
|
StyleScrollbarWidth aWidth,
|
|
|
|
Overlay aOverlay)
|
|
|
|
-> ScrollbarSizes {
|
|
|
|
if (aOverlay == Overlay::Yes) {
|
|
|
|
// TODO(emilio): Maybe make this configurable? Though this doesn't respect
|
|
|
|
// classic Windows registry settings, and cocoa overlay scrollbars also
|
|
|
|
// don't respect the override it seems, so this should be fine.
|
|
|
|
CSSCoord cssSize(aWidth == StyleScrollbarWidth::Thin
|
|
|
|
? kDefaultWinOverlayThinScrollbarSize
|
|
|
|
: kDefaultWinOverlayScrollbarSize);
|
|
|
|
auto size = (cssSize * GetDPIRatioForScrollbarPart(aPresContext)).Rounded();
|
|
|
|
return {size, size};
|
|
|
|
}
|
|
|
|
return ScrollbarDrawingWin::GetScrollbarSizes(aPresContext, aWidth, aOverlay);
|
|
|
|
}
|
|
|
|
|
2021-12-15 21:06:58 +00:00
|
|
|
LayoutDeviceIntSize ScrollbarDrawingWin11::GetMinimumWidgetSize(
|
|
|
|
nsPresContext* aPresContext, StyleAppearance aAppearance,
|
|
|
|
nsIFrame* aFrame) {
|
|
|
|
MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance));
|
2022-03-04 13:44:51 +00:00
|
|
|
if (ScrollbarStyle(aPresContext) != Style::ThinThumb) {
|
2021-12-27 18:53:31 +00:00
|
|
|
return ScrollbarDrawingWin::GetMinimumWidgetSize(aPresContext, aAppearance,
|
|
|
|
aFrame);
|
|
|
|
}
|
2021-12-27 18:53:32 +00:00
|
|
|
constexpr float kArrowRatio = 14.0f / kDefaultWinScrollbarSize;
|
2021-12-15 21:06:58 +00:00
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
2021-12-27 18:53:32 +00:00
|
|
|
case StyleAppearance::ScrollbarbuttonDown: {
|
2021-12-27 18:53:33 +00:00
|
|
|
if (IsScrollbarWidthThin(aFrame)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
const LayoutDeviceIntCoord size =
|
2022-03-04 13:44:51 +00:00
|
|
|
ScrollbarDrawing::GetScrollbarSizes(aPresContext, aFrame).mVertical;
|
2021-12-27 18:53:32 +00:00
|
|
|
return LayoutDeviceIntSize{
|
2021-12-27 18:53:33 +00:00
|
|
|
size, (kArrowRatio * LayoutDeviceCoord(size)).Rounded()};
|
2021-12-27 18:53:32 +00:00
|
|
|
}
|
2021-12-15 21:06:58 +00:00
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
2021-12-27 18:53:32 +00:00
|
|
|
case StyleAppearance::ScrollbarbuttonRight: {
|
2021-12-27 18:53:33 +00:00
|
|
|
if (IsScrollbarWidthThin(aFrame)) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
const LayoutDeviceIntCoord size =
|
2022-03-04 13:44:51 +00:00
|
|
|
ScrollbarDrawing::GetScrollbarSizes(aPresContext, aFrame).mHorizontal;
|
2021-12-27 18:53:32 +00:00
|
|
|
return LayoutDeviceIntSize{
|
2021-12-27 18:53:33 +00:00
|
|
|
(kArrowRatio * LayoutDeviceCoord(size)).Rounded(), size};
|
2021-12-27 18:53:32 +00:00
|
|
|
}
|
2021-12-15 21:06:58 +00:00
|
|
|
default:
|
|
|
|
return ScrollbarDrawingWin::GetMinimumWidgetSize(aPresContext,
|
|
|
|
aAppearance, aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sRGBColor ScrollbarDrawingWin11::ComputeScrollbarTrackColor(
|
|
|
|
nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aDocumentState, const Colors& aColors) {
|
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return ScrollbarDrawingWin::ComputeScrollbarTrackColor(
|
|
|
|
aFrame, aStyle, aDocumentState, aColors);
|
|
|
|
}
|
|
|
|
const nsStyleUI* ui = aStyle.StyleUI();
|
|
|
|
if (ui->mScrollbarColor.IsColors()) {
|
|
|
|
return sRGBColor::FromABGR(
|
|
|
|
ui->mScrollbarColor.AsColors().track.CalcColor(aStyle));
|
|
|
|
}
|
2022-02-09 11:27:16 +00:00
|
|
|
return aColors.IsDark() ? sRGBColor::FromU8(23, 23, 23, 255)
|
|
|
|
: sRGBColor::FromU8(240, 240, 240, 255);
|
2021-12-15 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sRGBColor ScrollbarDrawingWin11::ComputeScrollbarThumbColor(
|
|
|
|
nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
const Colors& aColors) {
|
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return ScrollbarDrawingWin::ComputeScrollbarThumbColor(
|
|
|
|
aFrame, aStyle, aElementState, aDocumentState, aColors);
|
|
|
|
}
|
2021-12-27 18:53:33 +00:00
|
|
|
const nscolor baseColor = [&] {
|
|
|
|
const nsStyleUI* ui = aStyle.StyleUI();
|
|
|
|
if (ui->mScrollbarColor.IsColors()) {
|
|
|
|
return ui->mScrollbarColor.AsColors().thumb.CalcColor(aStyle);
|
|
|
|
}
|
2022-02-09 11:27:16 +00:00
|
|
|
return aColors.IsDark() ? NS_RGBA(149, 149, 149, 255)
|
|
|
|
: NS_RGBA(133, 133, 133, 255);
|
2021-12-27 18:53:33 +00:00
|
|
|
}();
|
|
|
|
EventStates state = aElementState;
|
|
|
|
if (!IsScrollbarWidthThin(aStyle)) {
|
|
|
|
// non-thin scrollbars get hover feedback by changing thumb shape, so we
|
|
|
|
// only provide active feedback (and we use the hover state for that as it's
|
|
|
|
// more subtle).
|
|
|
|
state &= ~NS_EVENT_STATE_HOVER;
|
|
|
|
if (state.HasState(NS_EVENT_STATE_ACTIVE)) {
|
|
|
|
state &= ~NS_EVENT_STATE_ACTIVE;
|
|
|
|
state |= NS_EVENT_STATE_HOVER;
|
|
|
|
}
|
2021-12-15 21:06:58 +00:00
|
|
|
}
|
2021-12-27 18:53:33 +00:00
|
|
|
return sRGBColor::FromABGR(
|
|
|
|
ThemeColors::AdjustUnthemedScrollbarThumbColor(baseColor, state));
|
2021-12-15 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<sRGBColor, sRGBColor>
|
|
|
|
ScrollbarDrawingWin11::ComputeScrollbarButtonColors(
|
|
|
|
nsIFrame* aFrame, StyleAppearance aAppearance, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
const Colors& aColors) {
|
|
|
|
if (aColors.HighContrast()) {
|
|
|
|
return ScrollbarDrawingWin::ComputeScrollbarButtonColors(
|
|
|
|
aFrame, aAppearance, aStyle, aElementState, aDocumentState, aColors);
|
|
|
|
}
|
2022-03-04 13:44:51 +00:00
|
|
|
// The button always looks transparent (the track behind it is visible), so we
|
|
|
|
// can hardcode it.
|
2021-12-15 21:06:58 +00:00
|
|
|
sRGBColor arrowColor = ComputeScrollbarThumbColor(
|
|
|
|
aFrame, aStyle, aElementState, aDocumentState, aColors);
|
2022-03-04 13:44:51 +00:00
|
|
|
return {sRGBColor::White(0.0f), arrowColor};
|
2021-12-15 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollbarDrawingWin11::PaintScrollbarButton(
|
|
|
|
DrawTarget& aDrawTarget, StyleAppearance aAppearance,
|
2022-05-09 17:09:24 +00:00
|
|
|
const LayoutDeviceRect& aRect, ScrollbarKind aScrollbarKind,
|
|
|
|
nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
const Colors& aColors, const DPIRatio& aDpiRatio) {
|
2021-12-15 21:06:58 +00:00
|
|
|
if (!ScrollbarDrawing::IsParentScrollbarHoveredOrActive(aFrame)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-04 13:44:51 +00:00
|
|
|
const auto style = ScrollbarStyle(aFrame->PresContext());
|
2021-12-15 21:06:58 +00:00
|
|
|
auto [buttonColor, arrowColor] = ComputeScrollbarButtonColors(
|
|
|
|
aFrame, aAppearance, aStyle, aElementState, aDocumentState, aColors);
|
2022-03-04 13:44:51 +00:00
|
|
|
if (style != Style::Overlay) {
|
|
|
|
aDrawTarget.FillRect(aRect.ToUnknownRect(),
|
|
|
|
gfx::ColorPattern(ToDeviceColor(buttonColor)));
|
|
|
|
}
|
2021-12-15 21:06:58 +00:00
|
|
|
|
|
|
|
// Start with Up arrow.
|
2021-12-27 18:53:31 +00:00
|
|
|
float arrowPolygonX[] = {-4.5f, 4.5f, 4.5f, 0.5f, -0.5f, -4.5f, -4.5f};
|
|
|
|
float arrowPolygonXActive[] = {-4.0f, 4.0f, 4.0f, -0.25f,
|
|
|
|
-0.25f, -4.0f, -4.0f};
|
|
|
|
float arrowPolygonXHover[] = {-5.0f, 5.0f, 5.0f, 0.75f, -0.75f, -5.0f, -5.0f};
|
2021-12-15 21:06:58 +00:00
|
|
|
float arrowPolygonY[] = {2.5f, 2.5f, 1.0f, -4.0f, -4.0f, 1.0f, 2.5f};
|
|
|
|
float arrowPolygonYActive[] = {2.0f, 2.0f, 0.5f, -3.5f, -3.5f, 0.5f, 2.0f};
|
|
|
|
float arrowPolygonYHover[] = {3.0f, 3.0f, 1.5f, -4.5f, -4.5f, 1.5f, 3.0f};
|
|
|
|
float* arrowX = arrowPolygonX;
|
|
|
|
float* arrowY = arrowPolygonY;
|
2022-05-09 17:09:24 +00:00
|
|
|
const bool horizontal = aScrollbarKind == ScrollbarKind::Horizontal;
|
2021-12-27 18:53:31 +00:00
|
|
|
|
2022-03-04 13:44:51 +00:00
|
|
|
const float verticalOffset = [&] {
|
|
|
|
if (style != Style::Overlay) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
// To compensate for the scrollbar track radius we shift stuff vertically a
|
|
|
|
// bit. This 1px is arbitrary, but enough for the triangle not to overflow.
|
|
|
|
return 1.0f;
|
|
|
|
}();
|
|
|
|
const float horizontalOffset = [&] {
|
|
|
|
if (style != Style::ThinThumb) {
|
2021-12-27 18:53:31 +00:00
|
|
|
return 0.0f; // Always center it in the rect.
|
|
|
|
}
|
2021-12-27 18:53:31 +00:00
|
|
|
// Compensate for the displacement we do of the thumb position by displacing
|
|
|
|
// the arrow as well, see comment in DoPaintScrollbarThumb.
|
|
|
|
if (horizontal) {
|
|
|
|
return -0.5f;
|
|
|
|
}
|
2022-05-09 17:09:24 +00:00
|
|
|
return aScrollbarKind == ScrollbarKind::VerticalRight ? 0.5f : -0.5f;
|
2021-12-27 18:53:31 +00:00
|
|
|
}();
|
2022-03-04 13:44:51 +00:00
|
|
|
const float polygonSize = style == Style::Overlay
|
|
|
|
? float(kDefaultWinOverlayScrollbarSize)
|
|
|
|
: float(kDefaultWinScrollbarSize);
|
2021-12-15 21:06:58 +00:00
|
|
|
const int32_t arrowNumPoints = ArrayLength(arrowPolygonX);
|
|
|
|
|
|
|
|
if (aElementState.HasState(NS_EVENT_STATE_ACTIVE)) {
|
|
|
|
arrowX = arrowPolygonXActive;
|
|
|
|
arrowY = arrowPolygonYActive;
|
|
|
|
} else if (aElementState.HasState(NS_EVENT_STATE_HOVER)) {
|
|
|
|
arrowX = arrowPolygonXHover;
|
|
|
|
arrowY = arrowPolygonYHover;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aAppearance) {
|
|
|
|
case StyleAppearance::ScrollbarbuttonDown:
|
2021-12-27 18:53:31 +00:00
|
|
|
case StyleAppearance::ScrollbarbuttonRight:
|
2021-12-15 21:06:58 +00:00
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
2022-03-04 13:44:51 +00:00
|
|
|
arrowY[i] += verticalOffset;
|
2021-12-15 21:06:58 +00:00
|
|
|
arrowY[i] *= -1;
|
|
|
|
}
|
|
|
|
[[fallthrough]];
|
|
|
|
case StyleAppearance::ScrollbarbuttonUp:
|
|
|
|
case StyleAppearance::ScrollbarbuttonLeft:
|
2022-03-04 13:44:51 +00:00
|
|
|
if (horizontalOffset != 0.0f) {
|
2021-12-27 18:53:31 +00:00
|
|
|
for (int32_t i = 0; i < arrowNumPoints; i++) {
|
2022-03-04 13:44:51 +00:00
|
|
|
arrowX[i] += horizontalOffset;
|
2021-12-27 18:53:31 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-15 21:06:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-27 18:53:31 +00:00
|
|
|
if (horizontal) {
|
|
|
|
std::swap(arrowX, arrowY);
|
|
|
|
}
|
|
|
|
|
2021-12-27 18:53:31 +00:00
|
|
|
LayoutDeviceRect arrowRect(aRect);
|
2022-03-04 13:44:51 +00:00
|
|
|
if (style != Style::ThinThumb) {
|
|
|
|
auto margin = CSSCoord(style == Style::Overlay ? 1 : 2) * aDpiRatio;
|
2021-12-27 18:53:31 +00:00
|
|
|
arrowRect.Deflate(margin, margin);
|
|
|
|
}
|
|
|
|
|
2022-03-04 13:44:51 +00:00
|
|
|
ThemeDrawing::PaintArrow(aDrawTarget, arrowRect, arrowX, arrowY, polygonSize,
|
2021-12-15 21:06:58 +00:00
|
|
|
arrowNumPoints, arrowColor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename PaintBackendData>
|
|
|
|
bool ScrollbarDrawingWin11::DoPaintScrollbarThumb(
|
|
|
|
PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
|
2022-05-09 17:09:24 +00:00
|
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2021-12-15 21:06:58 +00:00
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
const Colors& aColors, const DPIRatio& aDpiRatio) {
|
|
|
|
sRGBColor thumbColor = ComputeScrollbarThumbColor(
|
|
|
|
aFrame, aStyle, aElementState, aDocumentState, aColors);
|
|
|
|
|
|
|
|
LayoutDeviceRect thumbRect(aRect);
|
|
|
|
|
2022-03-04 13:44:51 +00:00
|
|
|
const auto style = ScrollbarStyle(aFrame->PresContext());
|
2021-12-27 18:53:31 +00:00
|
|
|
const bool hovered =
|
2021-12-27 18:53:33 +00:00
|
|
|
ScrollbarDrawing::IsParentScrollbarHoveredOrActive(aFrame) ||
|
2022-03-04 13:44:51 +00:00
|
|
|
(style != Style::Overlay && IsScrollbarWidthThin(aStyle));
|
2022-05-09 17:09:24 +00:00
|
|
|
const bool horizontal = aScrollbarKind == ScrollbarKind::Horizontal;
|
2022-03-04 13:44:51 +00:00
|
|
|
if (style == Style::ThickThumb) {
|
2021-12-27 18:53:32 +00:00
|
|
|
constexpr float kHoveredThumbRatio =
|
|
|
|
(1.0f - (11.0f / kDefaultWinScrollbarSize)) / 2.0f;
|
|
|
|
constexpr float kUnhoveredThumbRatio =
|
|
|
|
(1.0f - (9.0f / kDefaultWinScrollbarSize)) / 2.0f;
|
|
|
|
const float ratio = hovered ? kHoveredThumbRatio : kUnhoveredThumbRatio;
|
2022-05-09 17:09:24 +00:00
|
|
|
if (horizontal) {
|
2021-12-27 18:53:32 +00:00
|
|
|
thumbRect.Deflate(0, thumbRect.height * ratio);
|
2021-12-27 18:53:31 +00:00
|
|
|
} else {
|
2021-12-27 18:53:32 +00:00
|
|
|
thumbRect.Deflate(thumbRect.width * ratio, 0);
|
2021-12-27 18:53:31 +00:00
|
|
|
}
|
2021-12-27 18:53:32 +00:00
|
|
|
|
2021-12-27 18:53:31 +00:00
|
|
|
auto radius = CSSCoord(hovered ? 2 : 0);
|
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, thumbRect, thumbColor,
|
|
|
|
sRGBColor(), 0, radius, aDpiRatio);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-04 13:44:51 +00:00
|
|
|
const float defaultTrackSize = style == Style::Overlay
|
|
|
|
? float(kDefaultWinOverlayScrollbarSize)
|
|
|
|
: float(kDefaultWinScrollbarSize);
|
2022-05-09 17:09:24 +00:00
|
|
|
const float trackSize = horizontal ? thumbRect.height : thumbRect.width;
|
2022-03-04 13:44:51 +00:00
|
|
|
const float thumbSizeInPixels = hovered ? 6.0f : 2.0f;
|
|
|
|
|
|
|
|
// The thumb might be a bit off-center, depending on our scrollbar styles.
|
|
|
|
//
|
|
|
|
// Hovered shifts, if any, need to be accounted for in PaintScrollbarButton.
|
|
|
|
// For example, for the hovered horizontal thin scrollbar shift:
|
|
|
|
//
|
|
|
|
// Scrollbar is 17px high by default. We make the thumb 6px tall and move
|
|
|
|
// it 5px towards the bottom, so the center (8.5 initially) is displaced
|
|
|
|
// by:
|
|
|
|
// (5px + 6px / 2) - 8.5px = -0.5px
|
|
|
|
//
|
|
|
|
// Same calculations apply to other shifts.
|
|
|
|
const float shiftInPixels = [&] {
|
|
|
|
if (style == Style::Overlay) {
|
|
|
|
if (hovered) {
|
|
|
|
// Keep the center intact.
|
|
|
|
return (defaultTrackSize - thumbSizeInPixels) / 2.0f;
|
|
|
|
}
|
2022-05-09 17:09:24 +00:00
|
|
|
// We want logical pixels from the thumb to the edge. For LTR and
|
2022-03-04 13:44:51 +00:00
|
|
|
// horizontal scrollbars that means shifting down the scrollbar size minus
|
|
|
|
// the thumb.
|
|
|
|
constexpr float kSpaceToEdge = 3.0f;
|
2022-05-09 17:09:24 +00:00
|
|
|
if (horizontal || aScrollbarKind == ScrollbarKind::VerticalRight) {
|
2022-03-04 13:44:51 +00:00
|
|
|
return defaultTrackSize - thumbSizeInPixels - kSpaceToEdge;
|
2021-12-15 21:06:58 +00:00
|
|
|
}
|
2022-03-04 13:44:51 +00:00
|
|
|
// For rtl is simpler.
|
|
|
|
return kSpaceToEdge;
|
2021-12-15 21:06:58 +00:00
|
|
|
}
|
2022-05-09 17:09:24 +00:00
|
|
|
if (horizontal) {
|
2022-03-04 13:44:51 +00:00
|
|
|
return hovered ? 5.0f : 7.0f;
|
|
|
|
}
|
2022-05-09 17:09:24 +00:00
|
|
|
const bool ltr = aScrollbarKind == ScrollbarKind::VerticalRight;
|
2022-03-04 13:44:51 +00:00
|
|
|
return ltr ? (hovered ? 6.0f : 8.0f) : (hovered ? 5.0f : 7.0f);
|
|
|
|
}();
|
|
|
|
|
2022-05-09 17:09:24 +00:00
|
|
|
if (horizontal) {
|
2022-03-04 13:44:51 +00:00
|
|
|
thumbRect.y += shiftInPixels * trackSize / defaultTrackSize;
|
|
|
|
thumbRect.height *= thumbSizeInPixels / defaultTrackSize;
|
|
|
|
} else {
|
|
|
|
thumbRect.x += shiftInPixels * trackSize / defaultTrackSize;
|
|
|
|
thumbRect.width *= thumbSizeInPixels / defaultTrackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style == Style::Overlay || hovered) {
|
2021-12-15 21:06:58 +00:00
|
|
|
LayoutDeviceCoord radius =
|
2022-05-09 17:09:24 +00:00
|
|
|
(horizontal ? thumbRect.height : thumbRect.width) / 2.0f;
|
2021-12-15 21:06:58 +00:00
|
|
|
|
|
|
|
MOZ_ASSERT(aRect.Contains(thumbRect));
|
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, thumbRect, thumbColor,
|
|
|
|
sRGBColor(), 0, radius / aDpiRatio,
|
|
|
|
aDpiRatio);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThemeDrawing::FillRect(aPaintData, thumbRect, thumbColor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollbarDrawingWin11::PaintScrollbarThumb(
|
2022-05-09 17:09:24 +00:00
|
|
|
DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect,
|
|
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2021-12-15 21:06:58 +00:00
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
const Colors& aColors, const DPIRatio& aDpiRatio) {
|
2022-05-09 17:09:24 +00:00
|
|
|
return DoPaintScrollbarThumb(aDrawTarget, aRect, aScrollbarKind, aFrame,
|
|
|
|
aStyle, aElementState, aDocumentState, aColors,
|
2021-12-15 21:06:58 +00:00
|
|
|
aDpiRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ScrollbarDrawingWin11::PaintScrollbarThumb(
|
|
|
|
WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
|
2022-05-09 17:09:24 +00:00
|
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
2021-12-15 21:06:58 +00:00
|
|
|
const EventStates& aElementState, const EventStates& aDocumentState,
|
|
|
|
const Colors& aColors, const DPIRatio& aDpiRatio) {
|
2022-05-09 17:09:24 +00:00
|
|
|
return DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle,
|
2021-12-15 21:06:58 +00:00
|
|
|
aElementState, aDocumentState, aColors,
|
|
|
|
aDpiRatio);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla::widget
|