mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 12:05:07 +00:00
LibWeb: Add basic implementation of progress bar element
This commit is contained in:
parent
d8388f30c8
commit
21e353980f
6 changed files with 133 additions and 3 deletions
|
@ -1,10 +1,12 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
* Copyright (c) 2020-2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/HTMLProgressElement.h>
|
||||
#include <LibWeb/Layout/Progress.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -17,4 +19,57 @@ HTMLProgressElement::~HTMLProgressElement()
|
|||
{
|
||||
}
|
||||
|
||||
RefPtr<Layout::Node> HTMLProgressElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
|
||||
{
|
||||
return adopt_ref(*new Layout::Progress(document(), *this, move(style)));
|
||||
}
|
||||
|
||||
double HTMLProgressElement::value() const
|
||||
{
|
||||
auto parsed_value = strtod(attribute(HTML::AttributeNames::value).characters(), nullptr);
|
||||
if (!isfinite(parsed_value) || parsed_value < 0)
|
||||
return 0;
|
||||
|
||||
return min(parsed_value, max());
|
||||
}
|
||||
|
||||
void HTMLProgressElement::set_value(double value)
|
||||
{
|
||||
if (value < 0)
|
||||
return;
|
||||
|
||||
set_attribute(HTML::AttributeNames::value, String::number(value));
|
||||
|
||||
if (layout_node())
|
||||
layout_node()->set_needs_display();
|
||||
}
|
||||
|
||||
double HTMLProgressElement::max() const
|
||||
{
|
||||
auto parsed_value = strtod(attribute(HTML::AttributeNames::max).characters(), nullptr);
|
||||
if (!isfinite(parsed_value) || parsed_value <= 0)
|
||||
return 1;
|
||||
|
||||
return parsed_value;
|
||||
}
|
||||
|
||||
void HTMLProgressElement::set_max(double value)
|
||||
{
|
||||
if (value <= 0)
|
||||
return;
|
||||
|
||||
set_attribute(HTML::AttributeNames::max, String::number(value));
|
||||
|
||||
if (layout_node())
|
||||
layout_node()->set_needs_display();
|
||||
}
|
||||
|
||||
double HTMLProgressElement::position() const
|
||||
{
|
||||
if (!is_determinate())
|
||||
return -1;
|
||||
|
||||
return value() / max();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue