There remain some direct call sites of nsPresContext::UseOverlayScrollbars. 0) two call sites in nsCSSFrameConstructor::GetAnonymousContent [0] These call sites for used for scrollbar style caching stuff, thoguh I am not 100% sure whether these two call sites needs to be replaced, in the next patch only width/height are applicable to ::-webkit-scrollbar pseudo elements and those properties are flagged as has_effect_on_gecko_scrollbars=false, so it's okay-ish? anyway the first one can not be replaced since it gets called before styling the <scrollbar> itself 1) in Element::GetClientAreaRect [1] it's for an optimization to avoid layout flush on the root scroll container, we will not apply ::-webkit-scrollbar to the root one, so it doesn't matter 2) in Gecko_GetScrollbarInlineSize [2] it's used only for internal CSS env scrollbar-inline-size, so it doesn't matter unless we use ::-webkit-scrollbar internally 3) in nsTreeBodyFrame::Init [3] it's XUL we won't use ::-webkit-scrollbar in chrome contents 4) in Gecko_MediaFeatures_UseOverlayScrollbars [4] it's used for `-moz-overlay-scrollbars` media query, we leave the styles in the media query, to disable overlay we will set `active` to the scrollbar element. [0] https://searchfox.org/firefox-main/rev/33fd6bd39c625067a29f153adce6a4646e45750f/layout/base/nsCSSFrameConstructor.cpp#3964,4035 [1] https://searchfox.org/firefox-main/rev/e480af4adea0d838f97b105d7efdd32fa18b73c1/dom/base/Element.cpp#1057 [2] https://searchfox.org/firefox-main/rev/e480af4adea0d838f97b105d7efdd32fa18b73c1/layout/style/GeckoBindings.cpp#317 [3] https://searchfox.org/firefox-main/rev/e480af4adea0d838f97b105d7efdd32fa18b73c1/layout/xul/tree/nsTreeBodyFrame.cpp#293 [4] https://searchfox.org/firefox-main/rev/e480af4adea0d838f97b105d7efdd32fa18b73c1/layout/style/nsMediaFeatures.cpp#112 Differential Revision: https://phabricator.services.mozilla.com/D281571
128 lines
4.7 KiB
C++
128 lines
4.7 KiB
C++
/* 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 "ScrollbarDrawingGTK.h"
|
|
|
|
#include "mozilla/gfx/Helpers.h"
|
|
#include "mozilla/StaticPrefs_widget.h"
|
|
#include "nsLayoutUtils.h"
|
|
#include "nsNativeTheme.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::gfx;
|
|
using namespace mozilla::widget;
|
|
|
|
LayoutDeviceIntSize ScrollbarDrawingGTK::GetMinimumWidgetSize(
|
|
nsPresContext* aPresContext, StyleAppearance aAppearance,
|
|
nsIFrame* aFrame) {
|
|
MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance));
|
|
auto scrollbarSize = GetScrollbarSize(aPresContext, aFrame);
|
|
LayoutDeviceIntSize size{scrollbarSize, scrollbarSize};
|
|
if (aAppearance == StyleAppearance::ScrollbarHorizontal ||
|
|
aAppearance == StyleAppearance::ScrollbarVertical ||
|
|
aAppearance == StyleAppearance::ScrollbarthumbHorizontal ||
|
|
aAppearance == StyleAppearance::ScrollbarthumbVertical) {
|
|
CSSCoord thumbSize(
|
|
StaticPrefs::widget_non_native_theme_gtk_scrollbar_thumb_cross_size());
|
|
const bool isVertical =
|
|
aAppearance == StyleAppearance::ScrollbarVertical ||
|
|
aAppearance == StyleAppearance::ScrollbarthumbVertical;
|
|
auto dpi = GetDPIRatioForScrollbarPart(aPresContext);
|
|
if (isVertical) {
|
|
size.height = thumbSize * dpi;
|
|
} else {
|
|
size.width = thumbSize * dpi;
|
|
}
|
|
}
|
|
return size;
|
|
}
|
|
|
|
Maybe<nsITheme::Transparency> ScrollbarDrawingGTK::GetScrollbarPartTransparency(
|
|
nsIFrame* aFrame, StyleAppearance aAppearance) {
|
|
if (!nsLayoutUtils::UseOverlayScrollbars(aFrame) &&
|
|
(aAppearance == StyleAppearance::ScrollbarVertical ||
|
|
aAppearance == StyleAppearance::ScrollbarHorizontal) &&
|
|
IsScrollbarTrackOpaque(aFrame)) {
|
|
return Some(nsITheme::eOpaque);
|
|
}
|
|
|
|
return Nothing();
|
|
}
|
|
|
|
template <typename PaintBackendData>
|
|
bool ScrollbarDrawingGTK::DoPaintScrollbarThumb(
|
|
PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
const ElementState& aElementState, const Colors& aColors,
|
|
const DPIRatio& aDpiRatio) {
|
|
sRGBColor thumbColor =
|
|
ComputeScrollbarThumbColor(aFrame, aStyle, aElementState, aColors);
|
|
|
|
LayoutDeviceRect thumbRect(aRect);
|
|
|
|
const bool horizontal = aScrollbarKind == ScrollbarKind::Horizontal;
|
|
if (nsLayoutUtils::UseOverlayScrollbars(aFrame) &&
|
|
!ScrollbarDrawing::IsParentScrollbarHoveredOrActive(aFrame)) {
|
|
if (horizontal) {
|
|
thumbRect.height *= 0.5;
|
|
thumbRect.y += thumbRect.height;
|
|
} else {
|
|
thumbRect.width *= 0.5;
|
|
if (aScrollbarKind == ScrollbarKind::VerticalRight) {
|
|
thumbRect.x += thumbRect.width;
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
float factor = std::max(
|
|
0.0f,
|
|
1.0f - StaticPrefs::widget_non_native_theme_gtk_scrollbar_thumb_size());
|
|
thumbRect.Deflate((horizontal ? thumbRect.height : thumbRect.width) *
|
|
factor);
|
|
}
|
|
|
|
LayoutDeviceCoord radius =
|
|
StaticPrefs::widget_non_native_theme_gtk_scrollbar_round_thumb()
|
|
? (horizontal ? thumbRect.height : thumbRect.width) / 2.0f
|
|
: 0.0f;
|
|
|
|
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, thumbRect, thumbColor,
|
|
sRGBColor(), 0, radius / aDpiRatio,
|
|
aDpiRatio);
|
|
return true;
|
|
}
|
|
|
|
bool ScrollbarDrawingGTK::PaintScrollbarThumb(
|
|
DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect,
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
const ElementState& aElementState, const Colors& aColors,
|
|
const DPIRatio& aDpiRatio) {
|
|
return DoPaintScrollbarThumb(aDrawTarget, aRect, aScrollbarKind, aFrame,
|
|
aStyle, aElementState, aColors, aDpiRatio);
|
|
}
|
|
|
|
bool ScrollbarDrawingGTK::PaintScrollbarThumb(
|
|
WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
|
|
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
|
|
const ElementState& aElementState, const Colors& aColors,
|
|
const DPIRatio& aDpiRatio) {
|
|
return DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle,
|
|
aElementState, aColors, aDpiRatio);
|
|
}
|
|
|
|
bool ScrollbarDrawingGTK::ShouldDrawScrollbarButtons() {
|
|
return StaticPrefs::widget_non_native_theme_gtk_scrollbar_allow_buttons();
|
|
}
|
|
|
|
void ScrollbarDrawingGTK::RecomputeScrollbarParams() {
|
|
uint32_t defaultSize = 12;
|
|
uint32_t overrideSize =
|
|
StaticPrefs::widget_non_native_theme_scrollbar_size_override();
|
|
if (overrideSize > 0) {
|
|
defaultSize = overrideSize;
|
|
}
|
|
ConfigureScrollbarSize(defaultSize);
|
|
}
|