This source file includes following definitions.
- m_searchEventTimer
- create
- countUsage
- createRenderer
- formControlType
- shouldRespectSpeechAttribute
- isSearchField
- needsContainer
- createShadowSubtree
- handleKeydownEvent
- startSearchEventTimer
- stopSearchEventTimer
- searchEventTimerFired
- searchEventsShouldBeDispatched
- didSetValueByUserEdit
- updateView
- updateCancelButtonVisibility
- supportsInputModeAttribute
#include "config.h"
#include "core/html/forms/SearchInputType.h"
#include "HTMLNames.h"
#include "InputTypeNames.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/events/KeyboardEvent.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/shadow/ShadowElementNames.h"
#include "core/html/shadow/TextControlInnerElements.h"
#include "core/rendering/RenderSearchField.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
using namespace HTMLNames;
inline SearchInputType::SearchInputType(HTMLInputElement& element)
: BaseTextInputType(element)
, m_searchEventTimer(this, &SearchInputType::searchEventTimerFired)
{
}
PassRefPtr<InputType> SearchInputType::create(HTMLInputElement& element)
{
return adoptRef(new SearchInputType(element));
}
void SearchInputType::countUsage()
{
countUsageIfVisible(UseCounter::InputTypeSearch);
}
RenderObject* SearchInputType::createRenderer(RenderStyle*) const
{
return new RenderSearchField(&element());
}
const AtomicString& SearchInputType::formControlType() const
{
return InputTypeNames::search;
}
bool SearchInputType::shouldRespectSpeechAttribute()
{
return true;
}
bool SearchInputType::isSearchField() const
{
return true;
}
bool SearchInputType::needsContainer() const
{
return true;
}
void SearchInputType::createShadowSubtree()
{
TextFieldInputType::createShadowSubtree();
Element* container = containerElement();
Element* viewPort = element().userAgentShadowRoot()->getElementById(ShadowElementNames::editingViewPort());
ASSERT(container);
ASSERT(viewPort);
container->insertBefore(SearchFieldDecorationElement::create(element().document()), viewPort);
container->insertBefore(SearchFieldCancelButtonElement::create(element().document()), viewPort->nextSibling());
}
void SearchInputType::handleKeydownEvent(KeyboardEvent* event)
{
if (element().isDisabledOrReadOnly()) {
TextFieldInputType::handleKeydownEvent(event);
return;
}
const String& key = event->keyIdentifier();
if (key == "U+001B") {
RefPtr<HTMLInputElement> input(element());
input->setValueForUser("");
input->onSearch();
event->setDefaultHandled();
return;
}
TextFieldInputType::handleKeydownEvent(event);
}
void SearchInputType::startSearchEventTimer()
{
ASSERT(element().renderer());
unsigned length = element().innerTextValue().length();
if (!length) {
stopSearchEventTimer();
element().onSearch();
return;
}
m_searchEventTimer.startOneShot(max(0.2, 0.6 - 0.1 * length), FROM_HERE);
}
void SearchInputType::stopSearchEventTimer()
{
m_searchEventTimer.stop();
}
void SearchInputType::searchEventTimerFired(Timer<SearchInputType>*)
{
element().onSearch();
}
bool SearchInputType::searchEventsShouldBeDispatched() const
{
return element().hasAttribute(incrementalAttr);
}
void SearchInputType::didSetValueByUserEdit(ValueChangeState state)
{
updateCancelButtonVisibility();
if (searchEventsShouldBeDispatched())
startSearchEventTimer();
TextFieldInputType::didSetValueByUserEdit(state);
}
void SearchInputType::updateView()
{
BaseTextInputType::updateView();
updateCancelButtonVisibility();
}
void SearchInputType::updateCancelButtonVisibility()
{
Element* button = element().userAgentShadowRoot()->getElementById(ShadowElementNames::clearButton());
if (!button)
return;
if (element().value().isEmpty()) {
button->setInlineStyleProperty(CSSPropertyOpacity, 0.0, CSSPrimitiveValue::CSS_NUMBER);
button->setInlineStyleProperty(CSSPropertyPointerEvents, CSSValueNone);
} else {
button->removeInlineStyleProperty(CSSPropertyOpacity);
button->removeInlineStyleProperty(CSSPropertyPointerEvents);
}
}
bool SearchInputType::supportsInputModeAttribute() const
{
return true;
}
}