mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibWeb: Implement CanvasRenderingContext2D.reset()
This commit is contained in:
parent
3e0e965f24
commit
2576af5db1
Notes:
sideshowbarker
2024-07-17 22:07:23 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/2576af5db10 Pull-request: https://github.com/SerenityOS/serenity/pull/11444
3 changed files with 33 additions and 0 deletions
|
@ -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>());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -71,6 +71,9 @@ public:
|
|||
|
||||
void save();
|
||||
void restore();
|
||||
void reset();
|
||||
|
||||
void reset_to_default_state();
|
||||
|
||||
HTMLCanvasElement* canvas() { return m_element; }
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ interface CanvasRenderingContext2D {
|
|||
|
||||
undefined save();
|
||||
undefined restore();
|
||||
undefined reset();
|
||||
|
||||
readonly attribute HTMLCanvasElement canvas;
|
||||
|
||||
|
|
Loading…
Reference in a new issue