Skip to content

Truly independent web browser

LibWeb+LibCompositing+Compositor: Follow rounded viewport corners

Andreas Kling4c8651ee683f
diff --git a/Libraries/LibCompositing/Rust/src/display_list/commands.rs b/Libraries/LibCompositing/Rust/src/display_list/commands.rs
index 928f3fac1e2..a606204503f 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/commands.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/commands.rs
@@ -1685,10 +1685,14 @@ pub struct CompositorScrollbar {
pub track_rect: IntRect,
pub expanded_gutter_rect: IntRect,
pub expanded_thumb_rect: IntRect,
+ // The thumb is clipped to this rounded rect, which follows the rounded corners the UI may give the viewport.
+ // A radius of zero means no clip.
+ pub corner_clip_rect: IntRect,
pub scroll_size: f64,
pub expanded_scroll_size: f64,
pub min_scroll_offset: f32,
pub max_scroll_offset: f32,
+ pub corner_clip_radius: i32,
pub thumb_color: Color,
pub track_color: Color,
pub vertical: bool,
@@ -1703,10 +1707,12 @@ ffi_bytes_fields!(CompositorScrollbar {
track_rect,
expanded_gutter_rect,
expanded_thumb_rect,
+ corner_clip_rect,
scroll_size,
expanded_scroll_size,
min_scroll_offset,
max_scroll_offset,
+ corner_clip_radius,
thumb_color,
track_color,
vertical,
diff --git a/Libraries/LibCompositing/Rust/src/display_list/damage.rs b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
index bfff96c8671..e623dfb841a 100644
--- a/Libraries/LibCompositing/Rust/src/display_list/damage.rs
+++ b/Libraries/LibCompositing/Rust/src/display_list/damage.rs
@@ -2422,10 +2422,12 @@ mod tests {
track_rect: IntRect::new(96, 0, 4, 100),
expanded_gutter_rect: IntRect::new(92, 0, 8, 100),
expanded_thumb_rect: IntRect::new(94, 0, 6, 20),
+ corner_clip_rect: IntRect::default(),
scroll_size: 0.8,
expanded_scroll_size: 0.8,
min_scroll_offset: 0.0,
max_scroll_offset: 100.0,
+ corner_clip_radius: 0,
thumb_color: RED,
track_color: Color::TRANSPARENT,
vertical: true,
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
index faa90630ee7..18908847a8b 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.cpp
@@ -154,6 +154,8 @@ AsyncScrollingState async_scrolling_state_from_display_list(Compositing::Display
.track_rect = command.track_rect,
.expanded_gutter_rect = command.expanded_gutter_rect,
.expanded_thumb_rect = command.expanded_thumb_rect,
+ .corner_clip_rect = command.corner_clip_rect,
+ .corner_clip_radius = command.corner_clip_radius,
.scroll_size = command.scroll_size,
.expanded_scroll_size = command.expanded_scroll_size,
.min_scroll_offset = command.min_scroll_offset,
diff --git a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
index cd3e6f60c9f..ed08f852517 100644
--- a/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
+++ b/Libraries/LibCompositing/Scrolling/AsyncScrollingState.h
@@ -131,6 +131,9 @@ struct AsyncScrollbar {
Gfx::IntRect track_rect;
Gfx::IntRect expanded_gutter_rect;
Gfx::IntRect expanded_thumb_rect;
+ // The compositor clips the thumb to this rounded rect when the radius is not zero.
+ Gfx::IntRect corner_clip_rect;
+ i32 corner_clip_radius { 0 };
double scroll_size { 0 };
double expanded_scroll_size { 0 };
float min_scroll_offset { 0 };
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 2e7123d8cc6..8824ba22bca 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -11239,7 +11239,7 @@ Optional<Painting::HitTestQuery> Document::prepare_hit_test_query(Layout::BegunR
paint_state().visual_context_tree_without_update(read, *this),
scroll_state_snapshot(),
page().client().device_pixels_per_css_pixel(),
- page().chrome_metrics(),
+ page().chrome_metrics(*this),
};
}
diff --git a/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp b/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp
index 7bb4f486b45..92043646216 100644
--- a/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp
@@ -281,7 +281,7 @@ bool seal_clock_plan(DOM::Document& document, bool may_plan, u64 update_serial)
.device_pixels_per_css_pixel = document.page().client().device_pixels_per_css_pixel(),
.scroll_offsets = scroll_offsets.data(),
.scroll_offset_count = scroll_offsets.size(),
- .chrome_metrics = document.page().chrome_metrics(),
+ .chrome_metrics = document.page().chrome_metrics(document),
.page_cursor = ffi_page_cursor(document.page().cursor()),
.effect_timing_nodes = effect_timing_nodes.data(),
.effect_timing_identities = effect_timing_identities.data(),
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index c38ea5f11f9..98727ac9764 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -6519,6 +6519,13 @@ void LocalNavigable::set_force_dark_thresholds(i32 foreground, i32 background)
child_navigable->set_force_dark_thresholds(foreground, background);
}
+// The viewport's scrollbars are recorded with a clip that follows its corners.
+void LocalNavigable::viewport_corner_radius_did_change()
+{
+ if (auto document = active_document())
+ document->set_needs_repaint(Badge<HTML::LocalNavigable> {}, InvalidateDisplayList::PaintCommands);
+}
+
void LocalNavigable::set_should_show_caret_hit_test_debug_overlay(bool value)
{
m_should_show_caret_hit_test_debug_overlay = value;
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index cd842358185..928edeb28c8 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -357,6 +357,7 @@ public:
bool force_dark_enabled() const { return m_force_dark_enabled; }
PaintConfig stamp_paint_config(PaintConfig) const;
void set_should_show_caret_hit_test_debug_overlay(bool);
+ void viewport_corner_radius_did_change();
bool should_show_caret_hit_test_debug_overlay() const { return m_should_show_caret_hit_test_debug_overlay; }
bool is_svg_page() const { return m_is_svg_page; }
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index 6975b6a008a..404f66b4e68 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -422,9 +422,12 @@ DevicePixelRect Page::rounded_device_rect(CSSPixelRect rect) const
};
}
-ChromeMetrics Page::chrome_metrics() const
+ChromeMetrics Page::chrome_metrics(DOM::Document const& document) const
{
- return ChromeMetrics { m_client->zoom_level() };
+ // Only the top-level viewport is the one the UI shows with rounded corners.
+ auto navigable = document.navigable();
+ auto is_top_level = navigable && navigable->is_top_level_traversable();
+ return ChromeMetrics { m_client->zoom_level(), is_top_level ? m_client->viewport_corner_radius() : 0 };
}
EventResult Page::handle_mouseup(HTML::LocalNavigable& root, DevicePixelPoint position, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Optional<RemoteInputEventTarget>* remote_target)
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index b22d81e2514..bd8d4a7ac72 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -187,7 +187,7 @@ public:
CSSPixelSize device_to_css_size(DevicePixelSize) const;
DevicePixelRect enclosing_device_rect(CSSPixelRect) const;
DevicePixelRect rounded_device_rect(CSSPixelRect) const;
- ChromeMetrics chrome_metrics() const;
+ ChromeMetrics chrome_metrics(DOM::Document const&) const;
EventResult handle_mouseup(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, Optional<RemoteInputEventTarget>* remote_target);
EventResult handle_mousedown(HTML::LocalNavigable& root, DevicePixelPoint, DevicePixelPoint screen_position, unsigned button, unsigned buttons, unsigned modifiers, int click_count, Optional<Web::ScrollbarDraggedByCompositor> const&, Optional<RemoteInputEventTarget>* remote_target);
@@ -683,6 +683,7 @@ public:
// a menu bar or a dock. A client that doesn't know it reports the whole screen.
virtual DevicePixelRect available_screen_rect() const { return screen_rect(); }
virtual double zoom_level() const = 0;
+ virtual double viewport_corner_radius() const { return 0; }
virtual double device_pixel_ratio() const = 0;
virtual double device_pixels_per_css_pixel() const = 0;
virtual double maximum_frames_per_second() const { return 60.0; }
diff --git a/Libraries/LibWeb/Painting/ChromeMetrics.h b/Libraries/LibWeb/Painting/ChromeMetrics.h
index 41bd87686d7..d287acb63ee 100644
--- a/Libraries/LibWeb/Painting/ChromeMetrics.h
+++ b/Libraries/LibWeb/Painting/ChromeMetrics.h
@@ -21,7 +21,7 @@ struct ChromeMetrics {
static constexpr CSSPixels ZOOM_INVARIANT_RESIZE_GRIPPER_PADDING { 2 };
ChromeMetrics() = default;
- explicit ChromeMetrics(double zoom_factor)
+ explicit ChromeMetrics(double zoom_factor, double viewport_corner_radius = 0)
{
VERIFY(zoom_factor > 0);
// So we can still use device_pixels_per_css_pixel transforms at paint time.
@@ -33,6 +33,7 @@ struct ChromeMetrics {
scroll_gutter_thickness = ZOOM_INVARIANT_SCROLL_GUTTER_THICKNESS * inverse_zoom;
resize_gripper_size = ZOOM_INVARIANT_RESIZE_GRIPPER_SIZE * inverse_zoom;
resize_gripper_padding = ZOOM_INVARIANT_RESIZE_GRIPPER_PADDING * inverse_zoom;
+ this->viewport_corner_radius = CSSPixels { viewport_corner_radius } * inverse_zoom;
}
CSSPixels scroll_thumb_min_length;
CSSPixels scroll_thumb_padding_thin;
@@ -41,6 +42,8 @@ struct ChromeMetrics {
CSSPixels scroll_gutter_thickness;
CSSPixels resize_gripper_size;
CSSPixels resize_gripper_padding;
+ // The UI may round the corners of the top-level viewport with circular arcs. Its scrollbars follow them.
+ CSSPixels viewport_corner_radius;
};
}
diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
index 1404eae9101..7aaf8935e36 100644
--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp
@@ -140,7 +140,7 @@ VERIFY_SHARED_FFI_TYPE(Gfx::ScalingMode);
VERIFY_SHARED_FFI_TYPE(Gfx::InterpolationColorSpace);
VERIFY_SHARED_FFI_TYPE(Compositing::ClipMode);
VERIFY_SHARED_FFI_TYPE(ChromeMetrics);
-static_assert(sizeof(ChromeMetrics) == 7 * sizeof(CSSPixels));
+static_assert(sizeof(ChromeMetrics) == 8 * sizeof(CSSPixels));
static_assert(offsetof(ChromeMetrics, scroll_thumb_min_length) == 0);
static_assert(offsetof(ChromeMetrics, scroll_thumb_padding_thin) == sizeof(CSSPixels));
static_assert(offsetof(ChromeMetrics, scroll_thumb_thickness_thin) == 2 * sizeof(CSSPixels));
@@ -148,6 +148,7 @@ static_assert(offsetof(ChromeMetrics, scroll_thumb_thickness) == 3 * sizeof(CSSP
static_assert(offsetof(ChromeMetrics, scroll_gutter_thickness) == 4 * sizeof(CSSPixels));
static_assert(offsetof(ChromeMetrics, resize_gripper_size) == 5 * sizeof(CSSPixels));
static_assert(offsetof(ChromeMetrics, resize_gripper_padding) == 6 * sizeof(CSSPixels));
+static_assert(offsetof(ChromeMetrics, viewport_corner_radius) == 7 * sizeof(CSSPixels));
VERIFY_SHARED_FFI_TYPE(Optional<CSSPixels>);
VERIFY_SHARED_FFI_TYPE(Optional<CSSPixelRect>);
VERIFY_SHARED_FFI_TYPE(Optional<Gfx::IntRect>);
@@ -597,7 +598,7 @@ Optional<DisplayListRecording> start_rust_display_list_recording(Layout::BegunRe
inputs.document_id = document.unique_id().value();
inputs.has_blocking_wheel_event_region_covering_viewport = wheel_event_region_state.has_blocking_wheel_event_region_covering_viewport;
inputs.wheel_event_listener_state_generation = document.page().wheel_event_listener_state_generation();
- inputs.chrome_metrics = document.page().chrome_metrics();
+ inputs.chrome_metrics = document.page().chrome_metrics(document);
inputs.paint_viewport_scrollbars = should_paint_viewport_scrollbars();
if (auto navigable = document.navigable()) {
if (auto handler = navigable->event_handler().middle_button_scroll_handler(); handler.has_value()) {
diff --git a/Libraries/LibWeb/Painting/Scrollbar.cpp b/Libraries/LibWeb/Painting/Scrollbar.cpp
index 1926bf69d5a..3087c648317 100644
--- a/Libraries/LibWeb/Painting/Scrollbar.cpp
+++ b/Libraries/LibWeb/Painting/Scrollbar.cpp
@@ -114,7 +114,7 @@ bool Scrollbar::scroll_to_mouse_position(CSSPixelPoint position)
auto* node = layout_node();
if (!node)
return false;
- ChromeMetrics metrics = node->document().page().chrome_metrics();
+ ChromeMetrics metrics = node->document().page().chrome_metrics(node->document());
auto const& scroll_state = node->document().scroll_state_snapshot();
auto scrollbar_data = compute_scrollbar_data(*node, m_direction, metrics, &scroll_state,
diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rs
index 40cbe764566..6dee69a4bb5 100644
--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs
+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs
@@ -75,6 +75,7 @@ pub struct FfiChromeMetrics {
pub scroll_gutter_thickness: CssPixels,
pub resize_gripper_size: CssPixels,
pub resize_gripper_padding: CssPixels,
+ pub viewport_corner_radius: CssPixels,
}
#[derive(Clone, Copy, Debug, Default)]
diff --git a/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs b/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs
index 8bf1c097a63..fd9017de03d 100644
--- a/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs
+++ b/Libraries/LibWeb/Rust/src/painting/record/async_scroll_metadata.rs
@@ -7,7 +7,7 @@
use crate::painting::paint_read::{GeometryRead, PaintRead};
use crate::painting::record::trace::Observer;
-use crate::css::css_pixels::{CssPixelPoint, CssPixelRect, CssPixelSize};
+use crate::css::css_pixels::{CssPixelPoint, CssPixelRect, CssPixelSize, CssPixels};
use crate::layout::node_data::{DomPaintFact, NodeKind, NodeSlotId};
use crate::painting::chrome_geometry::{
ChromeGeometry, maximum_scroll_offset, minimum_scroll_offset, scrollbar_colors_for_paint,
@@ -359,6 +359,7 @@ impl<O: Observer> PaintRecorder<'_, O> {
let min_scroll_offset = css_point_to_device_point(minimum_scroll_offset(self.source, paintable), scale);
let max_scroll_offset = css_point_to_device_point(maximum_scroll_offset(self.source, paintable), scale);
let vertical = direction == ScrollDirection::Vertical;
+ let (corner_clip_rect, corner_clip_radius) = self.viewport_scrollbar_corner_clip(paintable);
Some(CompositorScrollbar {
document_id: self.inputs.uncaptured.document_id,
scroll_node_index: self.data(paintable).own_scroll_node_index,
@@ -367,6 +368,7 @@ impl<O: Observer> PaintRecorder<'_, O> {
track_rect: self.converter.rounded_device_rect(scrollbar.track_rect),
expanded_gutter_rect: self.converter.rounded_device_rect(expanded.gutter_rect),
expanded_thumb_rect: self.converter.rounded_device_rect(expanded.thumb_rect),
+ corner_clip_rect,
scroll_size: scrollbar.thumb_travel_to_scroll_ratio.to_double(),
expanded_scroll_size: expanded.thumb_travel_to_scroll_ratio.to_double(),
min_scroll_offset: if vertical {
@@ -379,6 +381,7 @@ impl<O: Observer> PaintRecorder<'_, O> {
} else {
max_scroll_offset.x
},
+ corner_clip_radius,
thumb_color,
track_color,
vertical,
@@ -387,6 +390,28 @@ impl<O: Observer> PaintRecorder<'_, O> {
})
}
+ // The UI may round the viewport's corners. The thumbs of its scrollbars are then clipped to a rounded rect inset by
+ // the gap they keep to the viewport's edges, so that a thumb's end follows a corner with that same gap.
+ fn viewport_scrollbar_corner_clip(&self, paintable: NodeSlotId) -> (IntRect, i32) {
+ let metrics = &self.inputs.uncaptured.chrome_metrics;
+ if metrics.viewport_corner_radius <= CssPixels::from_raw(0)
+ || self.source.node_kind_if_live(paintable) != Some(NodeKind::Viewport)
+ {
+ return (IntRect::default(), 0);
+ }
+ let scale = self.inputs.device_pixels_per_css_pixel;
+ let gap = (metrics.scroll_thumb_padding_thin.to_double() * scale).round() as i32;
+ let radius = (metrics.viewport_corner_radius.to_double() * scale).round() as i32 - gap;
+ let size = self.inputs.uncaptured.device_viewport_size;
+ if radius <= 0 || size.width <= 2 * gap || size.height <= 2 * gap {
+ return (IntRect::default(), 0);
+ }
+ (
+ IntRect::new(gap, gap, size.width - 2 * gap, size.height - 2 * gap),
+ radius,
+ )
+ }
+
fn record_viewport_scrollbar_state(&mut self, paintable: NodeSlotId) {
let records_viewport_scrollbars = self.source.node_kind_if_live(paintable) == Some(NodeKind::Viewport)
&& self.inputs.uncaptured.paint_viewport_scrollbars
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cpp
index 719e698915a..b3fb7f55692 100644
--- a/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Libraries/LibWebView/ViewImplementation.cpp
@@ -687,6 +687,16 @@ void ViewImplementation::set_display_metadata(Optional<u64> display_id, double m
});
}
+void ViewImplementation::set_viewport_corner_radius(double radius)
+{
+ if (m_viewport_corner_radius == radius)
+ return;
+ m_viewport_corner_radius = radius;
+ traversable().for_each_hosting_page([&](WebContentPage& page) {
+ page.async_set_viewport_corner_radius(m_viewport_corner_radius);
+ });
+}
+
void ViewImplementation::update_compositor_display_metadata(WebContentPage& page)
{
Application::the().update_compositor_display_metadata(page.compositor_context_id(), m_display_id, m_maximum_frames_per_second);
@@ -3033,6 +3043,7 @@ void ViewImplementation::prepare_page_for_navigable(WebContentPage& page)
if (m_window_size.has_value())
page.async_set_window_size(m_window_size->to_type<Web::DevicePixels>());
page.async_set_maximum_frames_per_second(m_maximum_frames_per_second);
+ page.async_set_viewport_corner_radius(m_viewport_corner_radius);
page.async_set_has_focus(traversable().has_system_focus());
if (auto focused_navigable_id = traversable().focused_navigable_id(); focused_navigable_id.has_value())
page.async_set_focused_navigable(*focused_navigable_id);
diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h
index 7d8b3262290..d589ce5792d 100644
--- a/Libraries/LibWebView/ViewImplementation.h
+++ b/Libraries/LibWebView/ViewImplementation.h
@@ -208,6 +208,8 @@ public:
double maximum_frames_per_second() const { return m_maximum_frames_per_second; }
// Sends the display metadata to every page hosting documents of the tab.
void set_display_metadata(Optional<u64> display_id, double maximum_frames_per_second);
+ double viewport_corner_radius() const { return m_viewport_corner_radius; }
+ void set_viewport_corner_radius(double);
struct ScreenRects {
Vector<Web::DevicePixelRect> rects;
@@ -798,6 +800,7 @@ protected:
double m_device_pixel_ratio { 1.0 };
Optional<u64> m_display_id;
double m_maximum_frames_per_second { 60.0 };
+ double m_viewport_corner_radius { 0 };
bool m_scales_frames_to_fit { false };
RefPtr<Menu> m_page_context_menu;
diff --git a/Services/Compositor/DisplayListPlayerSkia.cpp b/Services/Compositor/DisplayListPlayerSkia.cpp
index a05fb9b5fcd..b5935f6ace4 100644
--- a/Services/Compositor/DisplayListPlayerSkia.cpp
+++ b/Services/Compositor/DisplayListPlayerSkia.cpp
@@ -206,7 +206,7 @@ static Gfx::IntRect thumb_rect_kept_inside_track(PaintScrollBar const& command)
return thumb_rect;
}
-static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, PaintScrollBar const& command)
+static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, PaintScrollBar const& command, Optional<SkRRect> const& corner_clip = {})
{
auto gutter_rect = to_skia_rect(command.gutter_rect);
@@ -224,9 +224,26 @@ static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, PaintScr
if (thumb_rect.isEmpty())
return;
+ // A thumb reaching into a rounded corner takes the shape of its part inside the corner clip, so that its outline
+ // follows the corner too.
+ Optional<SkPath> clipped_thumb;
+ if (corner_clip.has_value() && !corner_clip->contains(thumb_rect)) {
+ auto result = Op(SkPath::RRect(thumb_rrect), SkPath::RRect(*corner_clip), SkPathOp::kIntersect_SkPathOp);
+ if (!result.has_value() || result->isEmpty())
+ return;
+ clipped_thumb = *std::move(result);
+ }
+ auto draw_thumb = [&](SkPaint const& paint) {
+ if (clipped_thumb.has_value())
+ canvas.drawPath(*clipped_thumb, paint);
+ else
+ canvas.drawRRect(thumb_rrect, paint);
+ };
+
SkPaint thumb_fill_paint;
thumb_fill_paint.setColor(to_skia_color(command.thumb_color));
- canvas.drawRRect(thumb_rrect, thumb_fill_paint);
+ thumb_fill_paint.setAntiAlias(clipped_thumb.has_value());
+ draw_thumb(thumb_fill_paint);
auto stroke_color = command.thumb_color.lightened();
SkPaint stroke_paint;
@@ -234,12 +251,17 @@ static void paint_scrollbar_into_surface(Gfx::PaintingSurface& surface, PaintScr
stroke_paint.setStrokeWidth(1);
stroke_paint.setAntiAlias(true);
stroke_paint.setColor(to_skia_color(stroke_color));
- canvas.drawRRect(thumb_rrect, stroke_paint);
+ draw_thumb(stroke_paint);
}
-void DisplayListPlayerSkia::paint_scrollbar(Gfx::PaintingSurface& surface, PaintScrollBar const& command)
+void DisplayListPlayerSkia::paint_scrollbar(Gfx::PaintingSurface& surface, PaintScrollBar const& command, Gfx::IntRect const& corner_clip_rect, int corner_clip_radius)
{
- paint_scrollbar_into_surface(surface, command);
+ Optional<SkRRect> corner_clip;
+ if (corner_clip_radius > 0) {
+ auto radius = static_cast<SkScalar>(corner_clip_radius);
+ corner_clip = SkRRect::MakeRectXY(to_skia_rect(corner_clip_rect), radius, radius);
+ }
+ paint_scrollbar_into_surface(surface, command, corner_clip);
}
static SkMatrix vertical_glyph_run_rotation(Gfx::IntRect const& rect)
diff --git a/Services/Compositor/DisplayListPlayerSkia.h b/Services/Compositor/DisplayListPlayerSkia.h
index 8edd6c02873..b8b87d8efb5 100644
--- a/Services/Compositor/DisplayListPlayerSkia.h
+++ b/Services/Compositor/DisplayListPlayerSkia.h
@@ -51,7 +51,8 @@ public:
void flush(Gfx::PaintingSurface&) override;
void flush_async(Gfx::PaintingSurface&, Function<void()>&&);
- void paint_scrollbar(Gfx::PaintingSurface&, Compositing::PaintScrollBar const&);
+ // A corner clip radius that is not zero shapes the thumb to the corner clip rect with that radius.
+ void paint_scrollbar(Gfx::PaintingSurface&, Compositing::PaintScrollBar const&, Gfx::IntRect const& corner_clip_rect = {}, int corner_clip_radius = 0);
private:
#define DECLARE_PLAY_COMMAND(command_type) \
diff --git a/Services/Compositor/ScrollbarController.cpp b/Services/Compositor/ScrollbarController.cpp
index 7a2cbe4d6c7..4eda4d41703 100644
--- a/Services/Compositor/ScrollbarController.cpp
+++ b/Services/Compositor/ScrollbarController.cpp
@@ -319,7 +319,7 @@ bool ScrollbarController::paint(Gfx::PaintingSurface& surface, DisplayListPlayer
.track_color = scrollbar.track_color,
.vertical = scrollbar.vertical,
};
- display_list_player.paint_scrollbar(surface, paint_scrollbar);
+ display_list_player.paint_scrollbar(surface, paint_scrollbar, scrollbar.corner_clip_rect, scrollbar.corner_clip_radius);
painted_a_scrollbar = true;
}
return painted_a_scrollbar;
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index 0012c898388..e1521dec4ea 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -3239,6 +3239,12 @@ void ConnectionFromClient::set_maximum_frames_per_second(Web::PageId page_id, do
page->set_maximum_frames_per_second(maximum_frames_per_second);
}
+void ConnectionFromClient::set_viewport_corner_radius(Web::PageId page_id, double radius)
+{
+ if (auto page = this->page(page_id); page.has_value())
+ page->set_viewport_corner_radius(radius);
+}
+
void ConnectionFromClient::set_window_position(Web::PageId page_id, Web::DevicePixelPoint position)
{
if (auto page = this->page(page_id); page.has_value())
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index 7cc19930dde..30ff90b2dc6 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -248,6 +248,7 @@ private:
virtual void set_is_scripting_enabled(Web::PageId page_id, bool) override;
virtual void set_zoom_level(Web::PageId page_id, double zoom_level) override;
virtual void set_maximum_frames_per_second(Web::PageId page_id, double) override;
+ virtual void set_viewport_corner_radius(Web::PageId page_id, double) override;
virtual void set_window_position(Web::PageId page_id, Web::DevicePixelPoint) override;
virtual void set_window_size(Web::PageId page_id, Web::DevicePixelSize) override;
virtual void did_complete_window_rect_request(Web::PageId page_id, u64 completion_id) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 22b124c6b97..32f7962093e 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -851,6 +851,20 @@ void PageClient::inject_rendering_opportunity(double frame_time)
grant_rendering_opportunity(frame_time, Web::HTML::EventLoop::RenderingOpportunitySource::Manual);
}
+void PageClient::set_viewport_corner_radius(double radius)
+{
+ static constexpr double maximum_viewport_corner_radius = 64;
+ if (!isfinite(radius) || radius < 0)
+ return;
+ radius = min(radius, maximum_viewport_corner_radius);
+ if (m_viewport_corner_radius == radius)
+ return;
+ m_viewport_corner_radius = radius;
+
+ if (page().has_local_traversable())
+ page().local_traversable()->viewport_corner_radius_did_change();
+}
+
void PageClient::set_maximum_frames_per_second(double maximum_frames_per_second)
{
if (!isfinite(maximum_frames_per_second) || maximum_frames_per_second <= 0)
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 4be25783854..d2aaffa0093 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -84,6 +84,8 @@ public:
}
void set_zoom_level(double zoom_level);
void set_maximum_frames_per_second(double maximum_frames_per_second);
+ void set_viewport_corner_radius(double radius);
+ virtual double viewport_corner_radius() const override { return m_viewport_corner_radius; }
virtual double maximum_frames_per_second() const override { return m_maximum_frames_per_second; }
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
void set_preferred_contrast(Web::CSS::PreferredContrast);
@@ -404,6 +406,7 @@ private:
Optional<double> m_pending_browser_zoom;
double m_zoom_level { 1.0 };
double m_maximum_frames_per_second { 60.0 };
+ double m_viewport_corner_radius { 0 };
Web::PageId m_id { 0 };
u64 m_next_delete_all_cookies_request_id { 1 };
u64 m_next_text_fragment_generation_id { 1 };
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index 851e8b2d2ef..8ab8f329c7d 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -260,6 +260,7 @@ endpoint WebContentServer routed by Web::PageId page_id
set_is_scripting_enabled(Web::PageId page_id, bool is_scripting_enabled) =|
set_zoom_level(Web::PageId page_id, double zoom_level) =|
set_maximum_frames_per_second(Web::PageId page_id, double maximum_frames_per_second) =|
+ set_viewport_corner_radius(Web::PageId page_id, double radius) =|
set_window_position(Web::PageId page_id, Web::DevicePixelPoint position) =|
set_window_size(Web::PageId page_id, Web::DevicePixelSize size) =|
diff --git a/Tests/Compositor/TestScrollbarController.cpp b/Tests/Compositor/TestScrollbarController.cpp
index 65cb89daf12..f1ddb246e8e 100644
--- a/Tests/Compositor/TestScrollbarController.cpp
+++ b/Tests/Compositor/TestScrollbarController.cpp
@@ -53,6 +53,8 @@ static Compositor::ScrollbarController::Drag begin_scrollbar_drag(Gfx::Orientati
.track_rect = vertical ? Gfx::IntRect { 96, 0, 4, 100 } : Gfx::IntRect { 0, 96, 100, 4 },
.expanded_gutter_rect = vertical ? Gfx::IntRect { 92, 0, 8, 100 } : Gfx::IntRect { 0, 92, 100, 8 },
.expanded_thumb_rect = expanded_thumb_rect.value_or(vertical ? Gfx::IntRect { 94, 20, 6, 20 } : Gfx::IntRect { 20, 94, 20, 6 }),
+ .corner_clip_rect = {},
+ .corner_clip_radius = 0,
.scroll_size = 0.8,
.expanded_scroll_size = 0.8,
.min_scroll_offset = 0,