ButtonBox.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Font/Font.h>
  7. #include <LibWeb/DOM/Document.h>
  8. #include <LibWeb/Layout/ButtonBox.h>
  9. #include <LibWeb/Painting/ButtonPaintable.h>
  10. namespace Web::Layout {
  11. JS_DEFINE_ALLOCATOR(ButtonBox);
  12. ButtonBox::ButtonBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr<CSS::StyleProperties> style)
  13. : FormAssociatedLabelableNode(document, element, move(style))
  14. {
  15. }
  16. ButtonBox::~ButtonBox() = default;
  17. void ButtonBox::prepare_for_replaced_layout()
  18. {
  19. // For <input type="submit" /> and <input type="button" />, the contents of
  20. // the button does not appear as the contents of the element but as the
  21. // value attribute. This is not the case with <button />, which contains
  22. // its contents normally.
  23. if (is<HTML::HTMLInputElement>(dom_node())) {
  24. set_natural_width(CSSPixels::nearest_value_for(first_available_font().width(static_cast<HTML::HTMLInputElement&>(dom_node()).value())));
  25. set_natural_height(first_available_font().pixel_size_rounded_up());
  26. }
  27. }
  28. JS::GCPtr<Painting::Paintable> ButtonBox::create_paintable() const
  29. {
  30. return Painting::ButtonPaintable::create(*this);
  31. }
  32. }