This source file includes following definitions.
- create
- createRenderer
- didAddUserAgentShadowRoot
- detailsElement
- isMainSummary
- isClickableControl
- supportsFocus
- defaultEventHandler
- willRespondToMouseClickEvents
#include "config.h"
#include "core/html/HTMLSummaryElement.h"
#include "HTMLNames.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/events/KeyboardEvent.h"
#include "core/dom/NodeRenderingTraversal.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/html/HTMLContentElement.h"
#include "core/html/HTMLDetailsElement.h"
#include "core/html/shadow/DetailsMarkerControl.h"
#include "core/rendering/RenderBlockFlow.h"
namespace WebCore {
using namespace HTMLNames;
PassRefPtr<HTMLSummaryElement> HTMLSummaryElement::create(Document& document)
{
RefPtr<HTMLSummaryElement> summary = adoptRef(new HTMLSummaryElement(document));
summary->ensureUserAgentShadowRoot();
return summary.release();
}
HTMLSummaryElement::HTMLSummaryElement(Document& document)
: HTMLElement(summaryTag, document)
{
}
RenderObject* HTMLSummaryElement::createRenderer(RenderStyle*)
{
return new RenderBlockFlow(this);
}
void HTMLSummaryElement::didAddUserAgentShadowRoot(ShadowRoot& root)
{
root.appendChild(DetailsMarkerControl::create(document()));
root.appendChild(HTMLContentElement::create(document()));
}
HTMLDetailsElement* HTMLSummaryElement::detailsElement() const
{
Node* parent = NodeRenderingTraversal::parent(this);
if (isHTMLDetailsElement(parent))
return toHTMLDetailsElement(parent);
return 0;
}
bool HTMLSummaryElement::isMainSummary() const
{
if (HTMLDetailsElement* details = detailsElement())
return details->findMainSummary() == this;
return false;
}
static bool isClickableControl(Node* node)
{
if (!node->isElementNode())
return false;
Element* element = toElement(node);
if (element->isFormControlElement())
return true;
Element* host = element->shadowHost();
return host && host->isFormControlElement();
}
bool HTMLSummaryElement::supportsFocus() const
{
return isMainSummary();
}
void HTMLSummaryElement::defaultEventHandler(Event* event)
{
if (isMainSummary() && renderer()) {
if (event->type() == EventTypeNames::DOMActivate && !isClickableControl(event->target()->toNode())) {
if (HTMLDetailsElement* details = detailsElement())
details->toggleOpen();
event->setDefaultHandled();
return;
}
if (event->isKeyboardEvent()) {
if (event->type() == EventTypeNames::keydown && toKeyboardEvent(event)->keyIdentifier() == "U+0020") {
setActive(true);
return;
}
if (event->type() == EventTypeNames::keypress) {
switch (toKeyboardEvent(event)->charCode()) {
case '\r':
dispatchSimulatedClick(event);
event->setDefaultHandled();
return;
case ' ':
event->setDefaultHandled();
return;
}
}
if (event->type() == EventTypeNames::keyup && toKeyboardEvent(event)->keyIdentifier() == "U+0020") {
if (active())
dispatchSimulatedClick(event);
event->setDefaultHandled();
return;
}
}
}
HTMLElement::defaultEventHandler(event);
}
bool HTMLSummaryElement::willRespondToMouseClickEvents()
{
if (isMainSummary() && renderer())
return true;
return HTMLElement::willRespondToMouseClickEvents();
}
}