HTMLTextFormControlElement.h [plain text]
#ifndef HTMLTextFormControlElement_h
#define HTMLTextFormControlElement_h
#include "HTMLFormControlElementWithState.h"
namespace WebCore {
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;
virtual HTMLElement* placeholderElement() const = 0;
void updatePlaceholderVisibility(bool);
static void fixPlaceholderRenderer(HTMLElement* placeholder, HTMLElement* siblingElement);
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, ExceptionCode&);
virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionCode&);
void setSelectionRange(int start, int end, const String& direction);
void setSelectionRange(int start, int end, TextFieldSelectionDirection = SelectionHasNoDirection);
PassRefPtr<Range> selection() const;
String selectedText() const;
virtual void dispatchFormControlChangeEvent() OVERRIDE FINAL;
virtual int maxLength() const = 0;
virtual String value() const = 0;
virtual HTMLElement* innerTextElement() const = 0;
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; }
#if PLATFORM(IOS)
void hidePlaceholder();
void showPlaceholderIfNecessary();
#endif
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*);
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(PassRefPtr<Element> oldFocusedElement, FocusDirection) OVERRIDE FINAL;
virtual void dispatchBlurEvent(PassRefPtr<Element> newFocusedElement) OVERRIDE FINAL;
virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const OVERRIDE;
virtual bool isEmptyValue() const = 0;
virtual bool isEmptySuggestedValue() const { return true; }
virtual void handleFocusEvent(Node* , FocusDirection) { }
virtual void handleBlurEvent() { }
RenderTextControl* textRendererAfterUpdateLayout();
String m_textAsOfLastFormControlChangeEvent;
bool m_lastChangeWasUserEdit;
int m_cachedSelectionStart;
int m_cachedSelectionEnd;
TextFieldSelectionDirection m_cachedSelectionDirection;
};
inline bool isHTMLTextFormControlElement(const Node* node)
{
return node->isElementNode() && toElement(node)->isTextFormControl();
}
inline HTMLTextFormControlElement* toHTMLTextFormControlElement(Node* node)
{
ASSERT_WITH_SECURITY_IMPLICATION(!node || isHTMLTextFormControlElement(node));
return static_cast<HTMLTextFormControlElement*>(node);
}
HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
}
#endif