diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-09-19 17:46:28 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-19 22:53:35 +0200 |
commit | aaf12929d51d5e352b5d1ed544762f6ef6769249 (patch) | |
tree | c4f8660aa4af933a8feaed3061a1894fa2475e6d /Userland/Libraries/LibWeb/Layout | |
parent | b88641e44bd844d208827c013ee082d41d90e1e4 (diff) | |
download | serenity-aaf12929d51d5e352b5d1ed544762f6ef6769249.zip |
LibWeb: Extract border-radius normalization code from Box
This is going to be needed by InlineNodes too!
`BorderPainting.{h,cpp}` might not be the best place for it, but it
works for now.
Diffstat (limited to 'Userland/Libraries/LibWeb/Layout')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.cpp | 27 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.h | 10 |
2 files changed, 8 insertions, 29 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Box.cpp b/Userland/Libraries/LibWeb/Layout/Box.cpp index a768702792..73e135c572 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.cpp +++ b/Userland/Libraries/LibWeb/Layout/Box.cpp @@ -299,28 +299,13 @@ void Box::paint_box_shadow(PaintContext& context) context.painter().blit(rect.location() + blur_rect_position, *new_bitmap, rect); } -Box::BorderRadiusData Box::normalized_border_radius_data() +Painting::BorderRadiusData Box::normalized_border_radius_data() { - // FIXME: some values should be relative to the height() if specified, but which? For now, all relative values are relative to the width. - auto bottom_left_radius = computed_values().border_bottom_left_radius().resolved_or_zero(*this, width()).to_px(*this); - auto bottom_right_radius = computed_values().border_bottom_right_radius().resolved_or_zero(*this, width()).to_px(*this); - auto top_left_radius = computed_values().border_top_left_radius().resolved_or_zero(*this, width()).to_px(*this); - auto top_right_radius = computed_values().border_top_right_radius().resolved_or_zero(*this, width()).to_px(*this); - - // Scale overlapping curves according to https://www.w3.org/TR/css-backgrounds-3/#corner-overlap - auto bordered_rect = this->bordered_rect(); - auto f = 1.0f; - f = min(f, bordered_rect.width() / (float)(top_left_radius + top_right_radius)); - f = min(f, bordered_rect.height() / (float)(top_right_radius + bottom_right_radius)); - f = min(f, bordered_rect.width() / (float)(bottom_left_radius + bottom_right_radius)); - f = min(f, bordered_rect.height() / (float)(top_left_radius + bottom_left_radius)); - - top_left_radius = (int)(top_left_radius * f); - top_right_radius = (int)(top_right_radius * f); - bottom_right_radius = (int)(bottom_right_radius * f); - bottom_left_radius = (int)(bottom_left_radius * f); - - return { top_left_radius, top_right_radius, bottom_right_radius, bottom_left_radius }; + return Painting::normalized_border_radius_data(*this, bordered_rect(), + computed_values().border_top_left_radius(), + computed_values().border_top_right_radius(), + computed_values().border_bottom_right_radius(), + computed_values().border_bottom_left_radius()); } // https://www.w3.org/TR/css-display-3/#out-of-flow diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index e11f3116d8..2457b45099 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -10,6 +10,7 @@ #include <LibGfx/Rect.h> #include <LibWeb/Layout/LineBox.h> #include <LibWeb/Layout/Node.h> +#include <LibWeb/Painting/BorderPainting.h> #include <LibWeb/Painting/StackingContext.h> namespace Web::Layout { @@ -125,14 +126,7 @@ public: virtual float width_of_logical_containing_block() const; - struct BorderRadiusData { - float top_left { 0 }; - float top_right { 0 }; - float bottom_right { 0 }; - float bottom_left { 0 }; - }; - - BorderRadiusData normalized_border_radius_data(); + Painting::BorderRadiusData normalized_border_radius_data(); protected: Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style) |