Files
ladybird/Libraries/LibWeb/HTML/Canvas/CanvasShadowStyles.h
R-Goc 15cb3e872e LibWeb: Use static cast to cast from base class
It is not guaranteed that inherited classes have the same address as the
base of the derived class. In that case a reinterpret cast leads to
undefined behavior. This occured on msvc ABI. See:
https://godbolt.org/z/jGeEW3c48

Co-authored-by: ayeteadoe <ayeteadoe@gmail.com>
2026-01-01 12:23:15 +01:00

43 lines
1.2 KiB
C++

/*
* Copyright (c) 2024, İbrahim UYSAL <uysalibov@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/String.h>
#include <LibWeb/HTML/Canvas/CanvasState.h>
#include <LibWeb/HTML/CanvasGradient.h>
#include <LibWeb/HTML/CanvasPattern.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/canvas.html#canvasshadowstyles
template<typename IncludingClass>
class CanvasShadowStyles {
public:
~CanvasShadowStyles() = default;
virtual float shadow_offset_x() const = 0;
virtual void set_shadow_offset_x(float offsetX) = 0;
virtual float shadow_offset_y() const = 0;
virtual void set_shadow_offset_y(float offsetY) = 0;
virtual float shadow_blur() const = 0;
virtual void set_shadow_blur(float offsetY) = 0;
virtual String shadow_color() const = 0;
virtual void set_shadow_color(String color) = 0;
protected:
CanvasShadowStyles() = default;
private:
CanvasState::DrawingState& my_drawing_state() { return static_cast<IncludingClass&>(*this).drawing_state(); }
CanvasState::DrawingState const& my_drawing_state() const { return static_cast<IncludingClass const&>(*this).drawing_state(); }
};
}