/* -*- 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/. */
// 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.
sRGBColor ScrollbarDrawing::ComputeScrollbarThumbColor(
nsIFrame* aFrame, const ComputedStyle& aStyle, const ElementState& aElementState, const DocumentState& aDocumentState, const Colors& aColors) { const nsStyleUI* ui = aStyle.StyleUI(); if (ui->mScrollbarColor.IsColors()) { return sRGBColor::FromABGR(ThemeColors::AdjustUnthemedScrollbarThumbColor(
ui->mScrollbarColor.AsColors().thumb.CalcColor(aStyle), aElementState));
}
auto systemColor = [&] { if (aDocumentState.HasState(DocumentState::WINDOW_INACTIVE)) { return StyleSystemColor::ThemedScrollbarThumbInactive;
} if (aElementState.HasState(ElementState::ACTIVE)) { if (aColors.HighContrast()) { return StyleSystemColor::Selecteditem;
} return StyleSystemColor::ThemedScrollbarThumbActive;
} if (aElementState.HasState(ElementState::HOVER)) { if (aColors.HighContrast()) { return StyleSystemColor::Selecteditem;
} return StyleSystemColor::ThemedScrollbarThumbHover;
} if (aColors.HighContrast()) { return StyleSystemColor::Windowtext;
} return StyleSystemColor::ThemedScrollbarThumb;
}();
nscolor ScrollbarDrawing::GetScrollbarButtonColor(nscolor aTrackColor,
ElementState aStates) { // See numbers in GetScrollbarArrowColor. // This function is written based on ratios between values listed there.
Maybe<nscolor> ScrollbarDrawing::GetScrollbarArrowColor(nscolor aButtonColor) { // 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.
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();
}
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. constfloat GRAY96_LUMINANCE = 0.117f; return Some(RelativeLuminanceUtils::Adjust(aButtonColor, GRAY96_LUMINANCE));
} // 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. // // 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... if (luminance >= 0.18) { return Some(NS_RGBA(0, 0, 0, NS_GET_A(aButtonColor)));
} return Some(NS_RGBA(255, 255, 255, NS_GET_A(aButtonColor)));
}
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.