Backed out 2 changesets (bug 1879680) for causing spidermonkey failures on dumpValue...
[gecko.git] / widget / ScrollbarDrawingGTK.cpp
blob3e0cad9179613cfd053fb2e030a4dde0a4a77b3c
1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "ScrollbarDrawingGTK.h"
8 #include "mozilla/gfx/Helpers.h"
9 #include "mozilla/StaticPrefs_widget.h"
10 #include "nsLayoutUtils.h"
11 #include "nsNativeTheme.h"
13 using namespace mozilla;
14 using namespace mozilla::gfx;
15 using namespace mozilla::widget;
17 LayoutDeviceIntSize ScrollbarDrawingGTK::GetMinimumWidgetSize(
18 nsPresContext* aPresContext, StyleAppearance aAppearance,
19 nsIFrame* aFrame) {
20 MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance));
21 auto scrollbarSize = GetScrollbarSize(aPresContext, aFrame);
22 LayoutDeviceIntSize size{scrollbarSize, scrollbarSize};
23 if (aAppearance == StyleAppearance::ScrollbarHorizontal ||
24 aAppearance == StyleAppearance::ScrollbarVertical ||
25 aAppearance == StyleAppearance::ScrollbarthumbHorizontal ||
26 aAppearance == StyleAppearance::ScrollbarthumbVertical) {
27 CSSCoord thumbSize(
28 StaticPrefs::widget_non_native_theme_gtk_scrollbar_thumb_cross_size());
29 const bool isVertical =
30 aAppearance == StyleAppearance::ScrollbarVertical ||
31 aAppearance == StyleAppearance::ScrollbarthumbVertical;
32 auto dpi = GetDPIRatioForScrollbarPart(aPresContext);
33 if (isVertical) {
34 size.height = thumbSize * dpi;
35 } else {
36 size.width = thumbSize * dpi;
39 return size;
42 Maybe<nsITheme::Transparency> ScrollbarDrawingGTK::GetScrollbarPartTransparency(
43 nsIFrame* aFrame, StyleAppearance aAppearance) {
44 if (!aFrame->PresContext()->UseOverlayScrollbars() &&
45 (aAppearance == StyleAppearance::ScrollbarVertical ||
46 aAppearance == StyleAppearance::ScrollbarHorizontal) &&
47 IsScrollbarTrackOpaque(aFrame)) {
48 return Some(nsITheme::eOpaque);
51 return Nothing();
54 template <typename PaintBackendData>
55 bool ScrollbarDrawingGTK::DoPaintScrollbarThumb(
56 PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
57 ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
58 const ElementState& aElementState, const DocumentState& aDocumentState,
59 const Colors& aColors, const DPIRatio& aDpiRatio) {
60 sRGBColor thumbColor = ComputeScrollbarThumbColor(
61 aFrame, aStyle, aElementState, aDocumentState, aColors);
63 LayoutDeviceRect thumbRect(aRect);
65 const bool horizontal = aScrollbarKind == ScrollbarKind::Horizontal;
66 if (aFrame->PresContext()->UseOverlayScrollbars() &&
67 !ScrollbarDrawing::IsParentScrollbarHoveredOrActive(aFrame)) {
68 if (horizontal) {
69 thumbRect.height *= 0.5;
70 thumbRect.y += thumbRect.height;
71 } else {
72 thumbRect.width *= 0.5;
73 if (aScrollbarKind == ScrollbarKind::VerticalRight) {
74 thumbRect.x += thumbRect.width;
80 float factor = std::max(
81 0.0f,
82 1.0f - StaticPrefs::widget_non_native_theme_gtk_scrollbar_thumb_size());
83 thumbRect.Deflate((horizontal ? thumbRect.height : thumbRect.width) *
84 factor);
87 LayoutDeviceCoord radius =
88 StaticPrefs::widget_non_native_theme_gtk_scrollbar_round_thumb()
89 ? (horizontal ? thumbRect.height : thumbRect.width) / 2.0f
90 : 0.0f;
92 ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, thumbRect, thumbColor,
93 sRGBColor(), 0, radius / aDpiRatio,
94 aDpiRatio);
95 return true;
98 bool ScrollbarDrawingGTK::PaintScrollbarThumb(
99 DrawTarget& aDrawTarget, const LayoutDeviceRect& aRect,
100 ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
101 const ElementState& aElementState, const DocumentState& aDocumentState,
102 const Colors& aColors, const DPIRatio& aDpiRatio) {
103 return DoPaintScrollbarThumb(aDrawTarget, aRect, aScrollbarKind, aFrame,
104 aStyle, aElementState, aDocumentState, aColors,
105 aDpiRatio);
108 bool ScrollbarDrawingGTK::PaintScrollbarThumb(
109 WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
110 ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
111 const ElementState& aElementState, const DocumentState& aDocumentState,
112 const Colors& aColors, const DPIRatio& aDpiRatio) {
113 return DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle,
114 aElementState, aDocumentState, aColors,
115 aDpiRatio);
118 bool ScrollbarDrawingGTK::ShouldDrawScrollbarButtons() {
119 if (StaticPrefs::widget_non_native_theme_enabled()) {
120 return StaticPrefs::widget_non_native_theme_gtk_scrollbar_allow_buttons();
122 return true;
125 void ScrollbarDrawingGTK::RecomputeScrollbarParams() {
126 uint32_t defaultSize = 12;
127 uint32_t overrideSize =
128 StaticPrefs::widget_non_native_theme_scrollbar_size_override();
129 if (overrideSize > 0) {
130 defaultSize = overrideSize;
132 ConfigureScrollbarSize(defaultSize);