HTMLTextFieldInnerElement.cpp [plain text]
#include "config.h"
#include "HTMLTextFieldInnerElement.h"
#include "BeforeTextInsertedEvent.h"
#include "Document.h"
#include "EventHandler.h"
#include "EventNames.h"
#include "Frame.h"
#include "HTMLInputElement.h"
#include "HTMLTextAreaElement.h"
#include "MouseEvent.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() == webkitEditableContentChangedEvent)
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 && evt->isMouseEvent() && static_cast<MouseEvent*>(evt)->button() == LeftButton) {
input->focus();
input->select();
evt->setDefaultHandled();
}
if (!evt->defaultHandled())
HTMLDivElement::defaultEventHandler(evt);
}
HTMLSearchFieldCancelButtonElement::HTMLSearchFieldCancelButtonElement(Document* doc)
: HTMLTextFieldInnerElement(doc)
, m_capturing(false)
{
}
void HTMLSearchFieldCancelButtonElement::defaultEventHandler(Event* evt)
{
HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
if (evt->type() == mousedownEvent && evt->isMouseEvent() && static_cast<MouseEvent*>(evt)->button() == LeftButton) {
input->focus();
input->select();
evt->setDefaultHandled();
if (Frame* frame = document()->frame())
frame->eventHandler()->setCapturingMouseEventsNode(this);
m_capturing = true;
} else if (evt->type() == mouseupEvent && evt->isMouseEvent() && static_cast<MouseEvent*>(evt)->button() == LeftButton) {
if (m_capturing && renderer() && renderer()->style()->visibility() == VISIBLE) {
if (hovered()) {
input->setValue("");
input->onSearch();
evt->setDefaultHandled();
}
if (Frame* frame = document()->frame())
frame->eventHandler()->setCapturingMouseEventsNode(0);
m_capturing = false;
}
}
if (!evt->defaultHandled())
HTMLDivElement::defaultEventHandler(evt);
}
}