/* -*- 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/. */
// 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. enumclass Style {
Overlay,
ThinThumb,
ThickThumb,
};
sRGBColor ScrollbarDrawingWin11::ComputeScrollbarThumbColor(
nsIFrame* aFrame, const ComputedStyle& aStyle, const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors) { if (aColors.HighContrast()) { return ScrollbarDrawingWin::ComputeScrollbarThumbColor(
aFrame, aStyle, aElementState, aDocumentState, aColors);
} const nscolor baseColor = [&] { const nsStyleUI* ui = aStyle.StyleUI(); if (ui->mScrollbarColor.IsColors()) { return ui->mScrollbarColor.AsColors().thumb.CalcColor(aStyle);
} return aColors.IsDark() ? NS_RGBA(149, 149, 149, 255)
: NS_RGBA(133, 133, 133, 255);
}();
ElementState 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 &= ~ElementState::HOVER; if (state.HasState(ElementState::ACTIVE)) {
state &= ~ElementState::ACTIVE;
state |= ElementState::HOVER;
}
} return sRGBColor::FromABGR(
ThemeColors::AdjustUnthemedScrollbarThumbColor(baseColor, state));
}
std::pair<sRGBColor, sRGBColor>
ScrollbarDrawingWin11::ComputeScrollbarButtonColors(
nsIFrame* aFrame, StyleAppearance aAppearance, const ComputedStyle& aStyle, const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors) { if (aColors.HighContrast()) { return ScrollbarDrawingWin::ComputeScrollbarButtonColors(
aFrame, aAppearance, aStyle, aElementState, aDocumentState, aColors);
} // The button always looks transparent (the track behind it is visible), so we // can hardcode it.
sRGBColor arrowColor = ComputeScrollbarThumbColor(
aFrame, aStyle, aElementState, aDocumentState, aColors); return {sRGBColor::White(0.0f), arrowColor};
}
constfloat 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;
}(); constfloat horizontalOffset = [&] { if (style != Style::ThinThumb) { return 0.0f; // Always center it in the rect.
} // 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;
} return aScrollbarKind == ScrollbarKind::VerticalRight ? 0.5f : -0.5f;
}(); constfloat polygonSize = style == Style::Overlay
? float(kDefaultWinOverlayScrollbarSize)
: float(kDefaultWinScrollbarSize); const int32_t arrowNumPoints = std::size(arrowPolygonX);
switch (aAppearance) { case StyleAppearance::ScrollbarbuttonDown: case StyleAppearance::ScrollbarbuttonRight: for (int32_t i = 0; i < arrowNumPoints; i++) {
arrowY[i] += verticalOffset;
arrowY[i] *= -1;
}
[[fallthrough]]; case StyleAppearance::ScrollbarbuttonUp: case StyleAppearance::ScrollbarbuttonLeft: if (horizontalOffset != 0.0f) { for (int32_t i = 0; i < arrowNumPoints; i++) {
arrowX[i] += horizontalOffset;
}
} break; default: returnfalse;
}
// 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. constfloat shiftInPixels = [&] { if (style == Style::Overlay) { if (hovered) { // Keep the center intact. return (defaultTrackSize - thumbSizeInPixels) / 2.0f;
} // We want logical pixels from the thumb to the edge. For LTR and // horizontal scrollbars that means shifting down the scrollbar size minus // the thumb.
constexpr float kSpaceToEdge = 3.0f; if (horizontal || aScrollbarKind == ScrollbarKind::VerticalRight) { return defaultTrackSize - thumbSizeInPixels - kSpaceToEdge;
} // For rtl is simpler. return kSpaceToEdge;
} if (horizontal) { return hovered ? 5.0f : 7.0f;
} constbool ltr = aScrollbarKind == ScrollbarKind::VerticalRight; return ltr ? (hovered ? 6.0f : 8.0f) : (hovered ? 5.0f : 7.0f);
}();
void ScrollbarDrawingWin11::RecomputeScrollbarParams() {
ScrollbarDrawingWin::RecomputeScrollbarParams(); // 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.
ConfigureScrollbarSize(StyleScrollbarWidth::Thin, Overlay::Yes,
kDefaultWinOverlayThinScrollbarSize);
ConfigureScrollbarSize(StyleScrollbarWidth::Auto, Overlay::Yes,
kDefaultWinOverlayScrollbarSize);
}
} // namespace mozilla::widget
¤ Dauer der Verarbeitung: 0.26 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.