From b106fd640bed5674ee7ebbd57e9bdba0ef04a351 Mon Sep 17 00:00:00 2001 From: MacDue Date: Thu, 2 Feb 2023 20:41:03 +0000 Subject: [PATCH] LibWeb: Fix typo and use auto where possible --- .../HTML/Canvas/CanvasFillStrokeStyles.h | 14 +++++------ .../LibWeb/HTML/Canvas/CanvasState.cpp | 8 +++--- .../LibWeb/HTML/Canvas/CanvasState.h | 25 +++++++++++++------ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h index 5ff5703610b..25c3cec2617 100644 --- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h @@ -22,37 +22,37 @@ public: ~CanvasFillStrokeStyles() = default; using FillOrStrokeStyleVariant = Variant>; - static CanvasState::FillOrStrokeStyle to_canvas_state_fill_or_stoke_style(auto const& style) + static CanvasState::FillOrStrokeStyle to_canvas_state_fill_or_stroke_style(auto const& style) { return style.visit( [&](DeprecatedString const& string) -> CanvasState::FillOrStrokeStyle { return Gfx::Color::from_string(string).value_or(Color::Black); }, - [&](JS::Handle gradient) -> CanvasState::FillOrStrokeStyle { - return gradient; + [&](auto fill_or_stroke_style) -> CanvasState::FillOrStrokeStyle { + return fill_or_stroke_style; }); } void set_fill_style(FillOrStrokeStyleVariant style) { // FIXME: 2. If the given value is a CanvasPattern object that is marked as not origin-clean, then set this's origin-clean flag to false. - my_drawing_state().fill_style = to_canvas_state_fill_or_stoke_style(style); + my_drawing_state().fill_style = to_canvas_state_fill_or_stroke_style(style); } FillOrStrokeStyleVariant fill_style() const { - return my_drawing_state().fill_style.to_js_fill_or_stoke_style(); + return my_drawing_state().fill_style.to_js_fill_or_stroke_style(); } void set_stroke_style(FillOrStrokeStyleVariant style) { // FIXME: 2. If the given value is a CanvasPattern object that is marked as not origin-clean, then set this's origin-clean flag to false. - my_drawing_state().stroke_style = to_canvas_state_fill_or_stoke_style(style); + my_drawing_state().stroke_style = to_canvas_state_fill_or_stroke_style(style); } FillOrStrokeStyleVariant stroke_style() const { - return my_drawing_state().stroke_style.to_js_fill_or_stoke_style(); + return my_drawing_state().stroke_style.to_js_fill_or_stroke_style(); } WebIDL::ExceptionOr> create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1) diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.cpp b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.cpp index 876cc17d600..d20f69542b6 100644 --- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.cpp +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.cpp @@ -42,14 +42,14 @@ bool CanvasState::is_context_lost() NonnullRefPtr CanvasState::FillOrStrokeStyle::to_gfx_paint_style() { - return m_fill_or_stoke_style.visit( + return m_fill_or_stroke_style.visit( [&](Gfx::Color color) -> NonnullRefPtr { if (!m_color_paint_style) m_color_paint_style = Gfx::SolidColorPaintStyle::create(color); return m_color_paint_style.release_nonnull(); }, - [&](JS::Handle gradient) { - return gradient->to_gfx_paint_style(); + [&](auto handle) { + return handle->to_gfx_paint_style(); }); } @@ -60,7 +60,7 @@ Gfx::Color CanvasState::FillOrStrokeStyle::to_color_but_fixme_should_accept_any_ Optional CanvasState::FillOrStrokeStyle::as_color() const { - if (auto* color = m_fill_or_stoke_style.get_pointer()) + if (auto* color = m_fill_or_stroke_style.get_pointer()) return *color; return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.h index 3532d1bca47..d125b45b21c 100644 --- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.h +++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasState.h @@ -30,12 +30,17 @@ public: struct FillOrStrokeStyle { FillOrStrokeStyle(Gfx::Color color) - : m_fill_or_stoke_style(color) + : m_fill_or_stroke_style(color) { } FillOrStrokeStyle(JS::Handle gradient) - : m_fill_or_stoke_style(gradient) + : m_fill_or_stroke_style(gradient) + { + } + + FillOrStrokeStyle(JS::Handle pattern) + : m_fill_or_stroke_style(pattern) { } @@ -44,15 +49,21 @@ public: Optional as_color() const; Gfx::Color to_color_but_fixme_should_accept_any_paint_style() const; - Variant> to_js_fill_or_stoke_style() const + using JsFillOrStrokeStyle = Variant>; + + JsFillOrStrokeStyle to_js_fill_or_stroke_style() const { - if (auto* handle = m_fill_or_stoke_style.get_pointer>()) - return *handle; - return m_fill_or_stoke_style.get().to_deprecated_string(); + return m_fill_or_stroke_style.visit( + [&](Gfx::Color color) -> JsFillOrStrokeStyle { + return color.to_deprecated_string(); + }, + [&](auto handle) -> JsFillOrStrokeStyle { + return handle; + }); } private: - FillOrStrokeVariant m_fill_or_stoke_style; + FillOrStrokeVariant m_fill_or_stroke_style; RefPtr m_color_paint_style { nullptr }; };