fune/widget/ScrollbarDrawingAndroid.cpp
Matthias Camenzind c9300fab1e Bug 1786048 - Part 3: Merge nsIEmbeddingSiteWindow into nsIBaseWindow. r=emilio
Implementations of nsIEmbeddingSiteWindow and nsIBaseWindow largely
overlap, and where they don't, the nsIEmbeddingSiteWindow implementation
of the otherwise shared interface is primarily stubbed out with the
exception of Get/SetDimensions().

This patch moves a reimplementation of Get/SetDimensions() from
nsIEmbeddingSiteWindow to nsIBaseWindow. The other methods of
nsIEmbeddingSiteWindow remain covered by nsIBaseWindow.
Get/SetDimensions() can be implemented as part of nsIWebBrowserChrome
where nsIBaseWindow is not necessary. This removes the need for
nsIEmbeddingSiteWindow.

Blur() has also been moved to nsIWebBrowserChrome, as only
nsContentTreeOwner has an actual implementation which we in theory also
want to call from BrowserChild/Parent, but the spec suggests to
"selectively or uniformly ignore calls".

GetVisibility() had an implementation in BrowserChild that pretended to
always be visible. Instead of providing an interface for that,
nsDocShell now handles the not implemented case for tree owners.

nsIEmbeddingSiteWindow::GetSiteWindow() used to call through to
nsIBaseWindow::GetParentNativeWindow().

The Get/SetDimensions() implementation has been replaced with a strongly
typed setter, which is now also used directly from nsGlobalWindowOuter
to avoid problems that come with autodetecting unchanged dimensions,
when the current dimensions are outdated (e.g. immediately reverting a
change can be ignored).

Differential Revision: https://phabricator.services.mozilla.com/D160260
2022-12-15 23:13:00 +00:00

93 lines
3.8 KiB
C++

/* -*- 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/. */
#include "ScrollbarDrawingAndroid.h"
#include "nsIFrame.h"
#include "nsNativeTheme.h"
#include "mozilla/StaticPrefs_widget.h"
using namespace mozilla;
using namespace mozilla::widget;
LayoutDeviceIntSize ScrollbarDrawingAndroid::GetMinimumWidgetSize(
nsPresContext* aPresContext, StyleAppearance aAppearance,
nsIFrame* aFrame) {
MOZ_ASSERT(nsNativeTheme::IsWidgetScrollbarPart(aAppearance));
auto sizes =
GetScrollbarSizes(aPresContext, StyleScrollbarWidth::Auto, Overlay::Yes);
MOZ_ASSERT(sizes.mHorizontal == sizes.mVertical);
return LayoutDeviceIntSize{sizes.mHorizontal, sizes.mVertical};
}
auto ScrollbarDrawingAndroid::GetScrollbarSizes(nsPresContext* aPresContext,
StyleScrollbarWidth aWidth,
Overlay aOverlay)
-> ScrollbarSizes {
// We force auto-width scrollbars because scrollbars on android are already
// thin enough.
return ScrollbarDrawing::GetScrollbarSizes(
aPresContext, StyleScrollbarWidth::Auto, aOverlay);
}
template <typename PaintBackendData>
void ScrollbarDrawingAndroid::DoPaintScrollbarThumb(
PaintBackendData& aPaintData, const LayoutDeviceRect& aRect,
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
const ElementState& aElementState, const DocumentState& aDocumentState,
const Colors& aColors, const DPIRatio& aDpiRatio) {
// TODO(emilio): Maybe do like macOS and draw a stroke?
const auto color = ComputeScrollbarThumbColor(aFrame, aStyle, aElementState,
aDocumentState, aColors);
const bool horizontal = aScrollbarKind == ScrollbarKind::Horizontal;
// Draw the thumb rect centered in the scrollbar.
LayoutDeviceRect thumbRect(aRect);
if (horizontal) {
thumbRect.height *= 0.5f;
thumbRect.y += thumbRect.height * 0.5f;
} else {
thumbRect.width *= 0.5f;
thumbRect.x += thumbRect.width * 0.5f;
}
const LayoutDeviceCoord radius =
(horizontal ? thumbRect.height : thumbRect.width) / 2.0f;
ThemeDrawing::PaintRoundedRectWithRadius(aPaintData, thumbRect, color,
sRGBColor::White(0.0f), 0.0f,
radius / aDpiRatio, aDpiRatio);
}
bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
DrawTarget& aDt, const LayoutDeviceRect& aRect,
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
const ElementState& aElementState, const DocumentState& aDocumentState,
const Colors& aColors, const DPIRatio& aDpiRatio) {
DoPaintScrollbarThumb(aDt, aRect, aScrollbarKind, aFrame, aStyle,
aElementState, aDocumentState, aColors, aDpiRatio);
return true;
}
bool ScrollbarDrawingAndroid::PaintScrollbarThumb(
WebRenderBackendData& aWrData, const LayoutDeviceRect& aRect,
ScrollbarKind aScrollbarKind, nsIFrame* aFrame, const ComputedStyle& aStyle,
const ElementState& aElementState, const DocumentState& aDocumentState,
const Colors& aColors, const DPIRatio& aDpiRatio) {
DoPaintScrollbarThumb(aWrData, aRect, aScrollbarKind, aFrame, aStyle,
aElementState, aDocumentState, aColors, aDpiRatio);
return true;
}
void ScrollbarDrawingAndroid::RecomputeScrollbarParams() {
uint32_t defaultSize = 6;
uint32_t overrideSize =
StaticPrefs::widget_non_native_theme_scrollbar_size_override();
if (overrideSize > 0) {
defaultSize = overrideSize;
}
mHorizontalScrollbarHeight = mVerticalScrollbarWidth = defaultSize;
}