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(Node*) OVERRIDE;
virtual bool supportsPlaceholder() const = 0;
String strippedPlaceholder() const;
bool placeholderShouldBeVisible() const;
virtual HTMLElement* placeholderElement() const = 0;
void updatePlaceholderVisibility(bool);
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();
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();
virtual int maxLength() const = 0;
virtual String value() const = 0;
virtual HTMLElement* innerTextElement() const = 0;
void selectionChanged(bool userTriggered);
void notifyFormStateChanged();
bool lastChangeWasUserEdit() const;
void setInnerTextValue(const String&);
String innerTextValue() const;
String directionForFormData() const;
void setTextAsOfLastFormControlChangeEvent(const String& text) { m_textAsOfLastFormControlChangeEvent = text; }
void hidePlaceholder();
void showPlaceholderIfNecessary();
protected:
HTMLTextFormControlElement(const QualifiedName&, Document*, HTMLFormElement*);
virtual bool isPlaceholderEmpty() const;
virtual void updatePlaceholderText() = 0;
virtual void parseAttribute(Attribute*) 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<Node> oldFocusedNode);
virtual void dispatchBlurEvent(PassRefPtr<Node> newFocusedNode);
virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const OVERRIDE;
virtual bool isEmptyValue() const = 0;
virtual bool isEmptySuggestedValue() const { return true; }
virtual void handleFocusEvent() { }
virtual void handleBlurEvent() { }
RenderTextControl* textRendererAfterUpdateLayout();
String m_textAsOfLastFormControlChangeEvent;
bool m_lastChangeWasUserEdit;
int m_cachedSelectionStart;
int m_cachedSelectionEnd;
TextFieldSelectionDirection m_cachedSelectionDirection;
};
inline HTMLTextFormControlElement* toTextFormControl(Node* node)
{
return (node && node->isElementNode() && static_cast<Element*>(node)->isTextFormControl()) ? static_cast<HTMLTextFormControlElement*>(node) : 0;
}
HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
}
#endif