HTMLTextFieldInnerElement.cpp [plain text]
#include "config.h"
#include "HTMLTextFieldInnerElement.h"
#include "BeforeTextInsertedEvent.h"
#include "EventNames.h"
#include "HTMLInputElement.h"
#include "HTMLTextAreaElement.h"
#include "RenderTextControl.h"
namespace WebCore {
using namespace EventNames;
HTMLTextFieldInnerElement::HTMLTextFieldInnerElement(Document* doc, Node* shadowParent)
: HTMLDivElement(doc), m_shadowParent(shadowParent)
{
}
HTMLTextFieldInnerTextElement::HTMLTextFieldInnerTextElement(Document* doc, Node* shadowParent)
: HTMLTextFieldInnerElement(doc, shadowParent)
{
}
void HTMLTextFieldInnerTextElement::defaultEventHandler(Event* evt)
{
Node* shadowAncestor = shadowAncestorNode();
if (shadowAncestor && shadowAncestor->renderer()) {
ASSERT(shadowAncestor->renderer()->isTextField() || shadowAncestor->renderer()->isTextArea());
if (evt->isBeforeTextInsertedEvent())
if (shadowAncestor->renderer()->isTextField())
static_cast<HTMLInputElement*>(shadowAncestor)->defaultEventHandler(evt);
else
static_cast<HTMLTextAreaElement*>(shadowAncestor)->defaultEventHandler(evt);
if (evt->type() == khtmlEditableContentChangedEvent)
static_cast<RenderTextControl*>(shadowAncestor->renderer())->subtreeHasChanged();
}
if (!evt->defaultHandled())
HTMLDivElement::defaultEventHandler(evt);
}
HTMLSearchFieldResultsButtonElement::HTMLSearchFieldResultsButtonElement(Document* doc)
: HTMLTextFieldInnerElement(doc)
{
}
void HTMLSearchFieldResultsButtonElement::defaultEventHandler(Event* evt)
{
HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
if (evt->type() == mousedownEvent) {
input->focus();
input->select();
evt->setDefaultHandled();
}
if (!evt->defaultHandled())
HTMLDivElement::defaultEventHandler(evt);
}
HTMLSearchFieldCancelButtonElement::HTMLSearchFieldCancelButtonElement(Document* doc)
: HTMLTextFieldInnerElement(doc)
{
}
void HTMLSearchFieldCancelButtonElement::defaultEventHandler(Event* evt)
{
HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
if (evt->type() == mousedownEvent) {
input->focus();
input->select();
evt->setDefaultHandled();
} else if (evt->type() == mouseupEvent) {
if (renderer() && renderer()->style()->visibility() == VISIBLE) {
input->setValue("");
evt->setDefaultHandled();
}
}
if (!evt->defaultHandled())
HTMLDivElement::defaultEventHandler(evt);
}
}