TextControlInnerElements.cpp [plain text]
#include "config.h"
#include "TextControlInnerElements.h"
#include "Document.h"
#include "EventNames.h"
#include "Frame.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "LocalizedStrings.h"
#include "MouseEvent.h"
#include "PlatformMouseEvent.h"
#include "RenderSearchField.h"
#include "RenderTextControl.h"
#include "RenderView.h"
#include "ScriptController.h"
#include "TextEvent.h"
#include "TextEventInputType.h"
#include <wtf/Ref.h>
namespace WebCore {
using namespace HTMLNames;
TextControlInnerContainer::TextControlInnerContainer(Document& document)
: HTMLDivElement(divTag, document)
{
}
Ref<TextControlInnerContainer> TextControlInnerContainer::create(Document& document)
{
return adoptRef(*new TextControlInnerContainer(document));
}
RenderPtr<RenderElement> TextControlInnerContainer::createElementRenderer(Ref<RenderStyle>&& style, const RenderTreePosition&)
{
return createRenderer<RenderTextControlInnerContainer>(*this, WTF::move(style));
}
TextControlInnerElement::TextControlInnerElement(Document& document)
: HTMLDivElement(divTag, document)
{
setHasCustomStyleResolveCallbacks();
}
Ref<TextControlInnerElement> TextControlInnerElement::create(Document& document)
{
return adoptRef(*new TextControlInnerElement(document));
}
RefPtr<RenderStyle> TextControlInnerElement::customStyleForRenderer(RenderStyle&)
{
RenderTextControlSingleLine& parentRenderer = downcast<RenderTextControlSingleLine>(*shadowHost()->renderer());
return parentRenderer.createInnerBlockStyle(&parentRenderer.style());
}
inline TextControlInnerTextElement::TextControlInnerTextElement(Document& document)
: HTMLDivElement(divTag, document)
{
setHasCustomStyleResolveCallbacks();
}
Ref<TextControlInnerTextElement> TextControlInnerTextElement::create(Document& document)
{
return adoptRef(*new TextControlInnerTextElement(document));
}
void TextControlInnerTextElement::defaultEventHandler(Event* event)
{
if (event->isBeforeTextInsertedEvent() || event->type() == eventNames().webkitEditableContentChangedEvent) {
Element* shadowAncestor = shadowHost();
if (shadowAncestor)
shadowAncestor->defaultEventHandler(event);
}
if (!event->defaultHandled())
HTMLDivElement::defaultEventHandler(event);
}
RenderPtr<RenderElement> TextControlInnerTextElement::createElementRenderer(Ref<RenderStyle>&& style, const RenderTreePosition&)
{
return createRenderer<RenderTextControlInnerBlock>(*this, WTF::move(style));
}
RenderTextControlInnerBlock* TextControlInnerTextElement::renderer() const
{
return downcast<RenderTextControlInnerBlock>(HTMLDivElement::renderer());
}
RefPtr<RenderStyle> TextControlInnerTextElement::customStyleForRenderer(RenderStyle&)
{
RenderTextControl& parentRenderer = downcast<RenderTextControl>(*shadowHost()->renderer());
return parentRenderer.createInnerTextStyle(&parentRenderer.style());
}
inline SearchFieldResultsButtonElement::SearchFieldResultsButtonElement(Document& document)
: HTMLDivElement(divTag, document)
{
}
Ref<SearchFieldResultsButtonElement> SearchFieldResultsButtonElement::create(Document& document)
{
return adoptRef(*new SearchFieldResultsButtonElement(document));
}
void SearchFieldResultsButtonElement::defaultEventHandler(Event* event)
{
HTMLInputElement* input = downcast<HTMLInputElement>(shadowHost());
if (input && event->type() == eventNames().mousedownEvent && is<MouseEvent>(*event) && downcast<MouseEvent>(*event).button() == LeftButton) {
input->focus();
input->select();
#if !PLATFORM(IOS)
RenderSearchField& renderer = downcast<RenderSearchField>(*input->renderer());
if (renderer.popupIsVisible())
renderer.hidePopup();
else if (input->maxResults() > 0)
renderer.showPopup();
#endif
event->setDefaultHandled();
}
if (!event->defaultHandled())
HTMLDivElement::defaultEventHandler(event);
}
#if !PLATFORM(IOS)
bool SearchFieldResultsButtonElement::willRespondToMouseClickEvents()
{
return true;
}
#endif
inline SearchFieldCancelButtonElement::SearchFieldCancelButtonElement(Document& document)
: HTMLDivElement(divTag, document)
{
setPseudo(AtomicString("-webkit-search-cancel-button", AtomicString::ConstructFromLiteral));
#if !PLATFORM(IOS)
setAttribute(aria_labelAttr, AXSearchFieldCancelButtonText());
#endif
setAttribute(roleAttr, AtomicString("button", AtomicString::ConstructFromLiteral));
}
Ref<SearchFieldCancelButtonElement> SearchFieldCancelButtonElement::create(Document& document)
{
return adoptRef(*new SearchFieldCancelButtonElement(document));
}
void SearchFieldCancelButtonElement::defaultEventHandler(Event* event)
{
RefPtr<HTMLInputElement> input(downcast<HTMLInputElement>(shadowHost()));
if (!input || input->isDisabledOrReadOnly()) {
if (!event->defaultHandled())
HTMLDivElement::defaultEventHandler(event);
return;
}
if (event->type() == eventNames().mousedownEvent && is<MouseEvent>(*event) && downcast<MouseEvent>(*event).button() == LeftButton) {
input->focus();
input->select();
event->setDefaultHandled();
}
if (event->type() == eventNames().clickEvent) {
input->setValueForUser(emptyString());
input->onSearch();
event->setDefaultHandled();
}
if (!event->defaultHandled())
HTMLDivElement::defaultEventHandler(event);
}
#if !PLATFORM(IOS)
bool SearchFieldCancelButtonElement::willRespondToMouseClickEvents()
{
const HTMLInputElement* input = downcast<HTMLInputElement>(shadowHost());
if (input && !input->isDisabledOrReadOnly())
return true;
return HTMLDivElement::willRespondToMouseClickEvents();
}
#endif
}