1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/html/HTMLMenuItemElement.h"
8 #include "core/HTMLNames.h"
9 #include "core/dom/ElementTraversal.h"
10 #include "core/events/Event.h"
14 using namespace HTMLNames
;
16 inline HTMLMenuItemElement::HTMLMenuItemElement(Document
& document
)
17 : HTMLElement(HTMLNames::menuitemTag
, document
)
21 void HTMLMenuItemElement::defaultEventHandler(Event
* event
)
23 if (event
->type() == EventTypeNames::click
) {
24 if (equalIgnoringCase(fastGetAttribute(typeAttr
), "checkbox")) {
25 if (fastHasAttribute(checkedAttr
))
26 removeAttribute(checkedAttr
);
28 setAttribute(checkedAttr
, "checked");
29 } else if (equalIgnoringCase(fastGetAttribute(typeAttr
), "radio")) {
30 if (Element
* parent
= parentElement()) {
31 const AtomicString
& group
= fastGetAttribute(radiogroupAttr
);
32 for (HTMLMenuItemElement
& menuItem
: Traversal
<HTMLMenuItemElement
>::childrenOf(*parent
)) {
33 if (!menuItem
.fastHasAttribute(checkedAttr
))
35 const AtomicString
& groupAttr
= menuItem
.fastGetAttribute(radiogroupAttr
);
36 if (equalIgnoringNullity(groupAttr
.impl(), group
.impl()))
37 menuItem
.removeAttribute(checkedAttr
);
40 setAttribute(checkedAttr
, "checked");
42 event
->setDefaultHandled();
46 DEFINE_NODE_FACTORY(HTMLMenuItemElement
)