LibWeb: Implement CanvasRenderingContext2D.reset()

This commit is contained in:
Linus Groh 2021-12-27 14:33:36 +01:00 committed by Andreas Kling
parent 3e0e965f24
commit 2576af5db1
Notes: sideshowbarker 2024-07-17 22:07:23 +09:00
3 changed files with 33 additions and 0 deletions

View file

@ -329,4 +329,33 @@ void CanvasRenderingContext2D::restore()
m_drawing_state = m_drawing_state_stack.take_last();
}
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-reset
void CanvasRenderingContext2D::reset()
{
// The reset() method steps are to reset the rendering context to its default state.
reset_to_default_state();
}
// https://html.spec.whatwg.org/multipage/canvas.html#reset-the-rendering-context-to-its-default-state
void CanvasRenderingContext2D::reset_to_default_state()
{
auto painter = this->painter();
// 1. Clear canvas's bitmap to transparent black.
if (painter)
painter->clear_rect(painter->target()->rect(), Color::Transparent);
// 2. Empty the list of subpaths in context's current default path.
m_path.clear();
// 3. Clear the context's drawing state stack.
m_drawing_state_stack.clear();
// 4. Reset everything that drawing state consists of to their initial values.
m_drawing_state = {};
if (painter)
did_draw(painter->target()->rect().to_type<float>());
}
}

View file

@ -71,6 +71,9 @@ public:
void save();
void restore();
void reset();
void reset_to_default_state();
HTMLCanvasElement* canvas() { return m_element; }

View file

@ -33,6 +33,7 @@ interface CanvasRenderingContext2D {
undefined save();
undefined restore();
undefined reset();
readonly attribute HTMLCanvasElement canvas;