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