ButtonBox.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/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. ButtonBox::ButtonBox(DOM::Document& document, HTML::HTMLInputElement& element, NonnullRefPtr<CSS::StyleProperties> style)
  12. : FormAssociatedLabelableNode(document, element, move(style))
  13. {
  14. }
  15. ButtonBox::~ButtonBox() = default;
  16. void ButtonBox::prepare_for_replaced_layout()
  17. {
  18. // For <input type="submit" /> and <input type="button" />, the contents of
  19. // the button does not appear as the contents of the element but as the
  20. // value attribute. This is not the case with <button />, which contains
  21. // its contents normally.
  22. if (is<HTML::HTMLInputElement>(dom_node())) {
  23. set_intrinsic_width(font().width(static_cast<HTML::HTMLInputElement&>(dom_node()).value()));
  24. set_intrinsic_height(font().glyph_height());
  25. }
  26. }
  27. RefPtr<Painting::Paintable> ButtonBox::create_paintable() const
  28. {
  29. return Painting::ButtonPaintable::create(*this);
  30. }
  31. }