#ifndef HTMLTextFormControlElement_h
#define HTMLTextFormControlElement_h
#include "core/html/HTMLFormControlElementWithState.h"
namespace WebCore {
class ExceptionState;
class Position;
class RenderTextControl;
class VisiblePosition;
enum TextFieldSelectionDirection { SelectionHasNoDirection, SelectionHasForwardDirection, SelectionHasBackwardDirection };
enum TextFieldEventBehavior { DispatchNoEvent, DispatchChangeEvent, DispatchInputAndChangeEvent };
class HTMLTextFormControlElement : public HTMLFormControlElementWithState {
public:
enum NeedsToCheckDirtyFlag {CheckDirtyFlag, IgnoreDirtyFlag};
virtual ~HTMLTextFormControlElement();
void forwardEvent(Event*);
virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
virtual bool supportsPlaceholder() const = 0;
String strippedPlaceholder() const;
bool placeholderShouldBeVisible() const;
HTMLElement* placeholderElement() const;
void updatePlaceholderVisibility(bool);
VisiblePosition visiblePositionForIndex(int) const;
int indexForVisiblePosition(const VisiblePosition&) const;
int selectionStart() const;
int selectionEnd() const;
const AtomicString& selectionDirection() const;
void setSelectionStart(int);
void setSelectionEnd(int);
void setSelectionDirection(const String&);
void select();
virtual void setRangeText(const String& replacement, ExceptionState&);
virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionState&);
void setSelectionRange(int start, int end, const String& direction);
void setSelectionRange(int start, int end, TextFieldSelectionDirection = SelectionHasNoDirection);
PassRefPtrWillBeRawPtr<Range> selection() const;
virtual void dispatchFormControlChangeEvent() OVERRIDE FINAL;
virtual String value() const = 0;
HTMLElement* innerTextElement() const;
void selectionChanged(bool userTriggered);
bool lastChangeWasUserEdit() const;
void setInnerTextValue(const String&);
String innerTextValue() const;
String directionForFormData() const;
void setTextAsOfLastFormControlChangeEvent(const String& text) { m_textAsOfLastFormControlChangeEvent = text; }
protected:
HTMLTextFormControlElement(const QualifiedName&, Document&, HTMLFormElement*);
bool isPlaceholderEmpty() const;
virtual void updatePlaceholderText() = 0;
virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
void cacheSelection(int start, int end, TextFieldSelectionDirection direction)
{
m_cachedSelectionStart = start;
m_cachedSelectionEnd = end;
m_cachedSelectionDirection = direction;
}
void restoreCachedSelection();
bool hasCachedSelection() const { return m_cachedSelectionStart >= 0; }
virtual void defaultEventHandler(Event*) OVERRIDE;
virtual void subtreeHasChanged() = 0;
void setLastChangeWasNotUserEdit() { m_lastChangeWasUserEdit = false; }
String valueWithHardLineBreaks() const;
private:
int computeSelectionStart() const;
int computeSelectionEnd() const;
TextFieldSelectionDirection computeSelectionDirection() const;
virtual void dispatchFocusEvent(Element* oldFocusedElement, FocusType) OVERRIDE FINAL;
virtual void dispatchBlurEvent(Element* newFocusedElement) OVERRIDE FINAL;
virtual bool isEmptyValue() const = 0;
virtual bool isEmptySuggestedValue() const { return true; }
virtual void handleFocusEvent(Element* , FocusType) { }
virtual void handleBlurEvent() { }
String m_textAsOfLastFormControlChangeEvent;
bool m_lastChangeWasUserEdit;
int m_cachedSelectionStart;
int m_cachedSelectionEnd;
TextFieldSelectionDirection m_cachedSelectionDirection;
};
inline bool isHTMLTextFormControlElement(const Element& element)
{
return element.isTextFormControl();
}
DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTextFormControlElement);
HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
}
#endif