Quelle ScrollbarDrawingCocoa.cpp
Sprache: unbekannt
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- */ /* vim: set sw=2 ts=8 et tw=80 : */ /* 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/. */
auto minSize = [&]() -> CSSIntSize { switch (aAppearance) { case StyleAppearance::ScrollbarthumbHorizontal: return {26, 0}; case StyleAppearance::ScrollbarthumbVertical: return {0, 26}; case StyleAppearance::ScrollbarVertical: case StyleAppearance::ScrollbarHorizontal: {
ComputedStyle* style = nsLayoutUtils::StyleForScrollbar(aFrame); auto scrollbarWidth = style->StyleUIReset()->ScrollbarWidth(); auto size = GetCSSScrollbarSize(
scrollbarWidth, Overlay(aPresContext->UseOverlayScrollbars())); return {size, size};
} case StyleAppearance::ScrollbarbuttonUp: case StyleAppearance::ScrollbarbuttonDown: return {15, 16}; case StyleAppearance::ScrollbarbuttonLeft: case StyleAppearance::ScrollbarbuttonRight: return {16, 15}; default: return {};
}
}();
auto dpi = GetDPIRatioForScrollbarPart(aPresContext); return LayoutDeviceIntSize::Round(CSSSize(minSize) * dpi);
}
static ThumbRect GetThumbRect(const LayoutDeviceRect& aRect, const ScrollbarParams& aParams, float aScale) { // Compute the thumb thickness. This varies based on aParams.isSmall, // aParams.isOverlay and aParams.isRolledOver. // non-overlay: 6 / 8, overlay non-hovered: 5 / 7, overlay hovered: 7 / 11 // Note that this is drawn inside the rect of a size as specified by // ConfigureScrollbarSize(). float thickness = aParams.isSmall ? 6.0f : 8.0f; if (aParams.isOverlay) {
thickness -= 1.0f; if (aParams.isRolledOver) {
thickness = aParams.isSmall ? 7.0f : 11.0f;
}
}
// Overlay scrollbars have an additional stroke around the fill. if (aParams.isOverlay) { // For the default alpha of 128 we want to end up with 48 in the outline.
constexpr float kAlphaScaling = 48.0f / 128.0f; const uint8_t strokeAlpha =
uint8_t(std::clamp(NS_GET_A(faceColor) * kAlphaScaling, 0.0f, 48.0f)); if (strokeAlpha) {
strokeOutset = (aParams.isDark ? 0.3f : 0.5f) * aScale;
strokeWidth = (aParams.isDark ? 0.6f : 0.8f) * aScale;
// The scrollbar track is drawn as multiple non-overlapping segments, which // make up lines of different widths and with slightly different shading.
ScrollbarTrackDecorationColors colors =
ComputeScrollbarTrackDecorationColors(trackColor); struct {
nscolor color; float thickness;
} segments[] = {
{colors.mInnerColor, 1.0f * aScale},
{colors.mShadowColor, 1.0f * aScale},
{trackColor, thickness - 3.0f * aScale},
{colors.mOuterColor, 1.0f * aScale},
};
// Iterate over the segments "from inside to outside" and fill each segment. // For horizontal scrollbars, iterate top to bottom. // For vertical scrollbars, iterate left to right or right to left based on // aParams.isRtl. auto current = aRects.begin(); float accumulatedThickness = 0.0f; for (constauto& segment : segments) {
LayoutDeviceRect segmentRect = aRect; float startThickness = accumulatedThickness; float endThickness = startThickness + segment.thickness; if (aParams.isHorizontal) {
segmentRect.SetBoxY(aRect.Y() + startThickness, aRect.Y() + endThickness);
} else { if (aParams.isRtl) {
segmentRect.SetBoxX(aRect.XMost() - endThickness,
aRect.XMost() - startThickness);
} else {
segmentRect.SetBoxX(aRect.X() + startThickness,
aRect.X() + endThickness);
}
}
accumulatedThickness = endThickness;
*current++ = {segmentRect, segment.color};
}
returntrue;
}
staticbool GetScrollCornerRects(const LayoutDeviceRect& aRect, const ScrollbarParams& aParams, float aScale,
ScrollCornerRects& aRects) { if (aParams.isOverlay && !aParams.isRolledOver) { // Non-hovered overlay scrollbars don't have a corner. Draw nothing. returnfalse;
}
// Draw the following scroll corner. // // Output: Rectangles: // +---+---+----------+---+ +---+---+----------+---+ // | I | S | T ... T | O | | I | S | T ... T | O | // +---+ | | | +---+---+ | | // | S S | T ... T | | | S S | T ... T | . | // +-------+ | . | +-------+----------+ . | // | T ... T | . | | T ... T | . | // | . . | . | | . . | | // | T ... T | | | T ... T | O | // +------------------+ | +------------------+---+ // | O ... O | | O ... O | // +----------------------+ +----------------------+