1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:08:13 +00:00

LibWeb: Add "Label" to be the layout node for HTMLLabelElement

The HTML <label> element is special in that it may be associated with
some other <input> element. When the label element is clicked, the input
element should be activated.

To achieve this, a LableableNode base class is introduced to provide an
interface for "labelable" elements to handle mouse events on their
associated labels. This not only allows clicking the label to activate
the input, but dragging the mouse from the label to the input (and vice-
versa) while the mouse is clicked will also active the label.

As of this commit, this infrastructure is not hooked up to any elements.
This commit is contained in:
Timothy Flynn 2021-04-03 21:32:16 -04:00 committed by Andreas Kling
parent 4f9e9c0715
commit d8106dda73
7 changed files with 271 additions and 0 deletions

View file

@ -24,7 +24,9 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLLabelElement.h>
#include <LibWeb/Layout/Label.h>
namespace Web::HTML {
@ -37,4 +39,15 @@ HTMLLabelElement::~HTMLLabelElement()
{
}
RefPtr<Layout::Node> HTMLLabelElement::create_layout_node()
{
auto style = document().style_resolver().resolve_style(*this);
if (style->display() == CSS::Display::None)
return nullptr;
auto layout_node = adopt(*new Layout::Label(document(), this, move(style)));
layout_node->set_inline(true);
return layout_node;
}
}