Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: third_party/WebKit/Source/core/html/TextControlElement.h

Issue 2735633006: INPUT/TEXTAREA elements: Dispatch 'select' event only if text selection is changed. (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. 7 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 29 matching lines...) Expand all
40 SelectionHasNoDirection, 40 SelectionHasNoDirection,
41 SelectionHasForwardDirection, 41 SelectionHasForwardDirection,
42 SelectionHasBackwardDirection 42 SelectionHasBackwardDirection
43 }; 43 };
44 enum TextFieldEventBehavior { 44 enum TextFieldEventBehavior {
45 DispatchNoEvent, 45 DispatchNoEvent,
46 DispatchChangeEvent, 46 DispatchChangeEvent,
47 DispatchInputAndChangeEvent 47 DispatchInputAndChangeEvent
48 }; 48 };
49 49
50 enum class TextControlSetValueSelection {
51 kSetSelectionToEnd,
yoichio 2017/03/07 09:00:56 Why do you use another coding style to above enums
tkent 2017/03/07 09:27:34 kFooBar is the standard naming convention. FooBar
52 kDoNotSet,
53 };
54
50 class CORE_EXPORT TextControlElement : public HTMLFormControlElementWithState { 55 class CORE_EXPORT TextControlElement : public HTMLFormControlElementWithState {
51 public: 56 public:
52 // Common flag for HTMLInputElement::tooLong(), 57 // Common flag for HTMLInputElement::tooLong(),
53 // HTMLTextAreaElement::tooLong(), 58 // HTMLTextAreaElement::tooLong(),
54 // HTMLInputElement::tooShort() and HTMLTextAreaElement::tooShort(). 59 // HTMLInputElement::tooShort() and HTMLTextAreaElement::tooShort().
55 enum NeedsToCheckDirtyFlag { CheckDirtyFlag, IgnoreDirtyFlag }; 60 enum NeedsToCheckDirtyFlag { CheckDirtyFlag, IgnoreDirtyFlag };
56 61
57 ~TextControlElement() override; 62 ~TextControlElement() override;
58 63
59 void forwardEvent(Event*); 64 void forwardEvent(Event*);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 void setTextAsOfLastFormControlChangeEvent(const String& text) { 122 void setTextAsOfLastFormControlChangeEvent(const String& text) {
118 m_textAsOfLastFormControlChangeEvent = text; 123 m_textAsOfLastFormControlChangeEvent = text;
119 } 124 }
120 // A user has changed the value since the last 'change' event. 125 // A user has changed the value since the last 'change' event.
121 bool wasChangedSinceLastFormControlChangeEvent() const { 126 bool wasChangedSinceLastFormControlChangeEvent() const {
122 return m_wasChangedSinceLastFormControlChangeEvent; 127 return m_wasChangedSinceLastFormControlChangeEvent;
123 } 128 }
124 void setChangedSinceLastFormControlChangeEvent(bool); 129 void setChangedSinceLastFormControlChangeEvent(bool);
125 130
126 virtual String value() const = 0; 131 virtual String value() const = 0;
127 virtual void setValue(const String&, 132 virtual void setValue(
128 TextFieldEventBehavior = DispatchNoEvent) = 0; 133 const String&,
134 TextFieldEventBehavior = DispatchNoEvent,
135 TextControlSetValueSelection =
136 TextControlSetValueSelection::kSetSelectionToEnd) = 0;
129 137
130 HTMLElement* innerEditorElement() const; 138 HTMLElement* innerEditorElement() const;
131 139
132 void selectionChanged(bool userTriggered); 140 void selectionChanged(bool userTriggered);
133 bool lastChangeWasUserEdit() const; 141 bool lastChangeWasUserEdit() const;
134 virtual void setInnerEditorValue(const String&); 142 virtual void setInnerEditorValue(const String&);
135 String innerEditorValue() const; 143 String innerEditorValue() const;
136 Node* createPlaceholderBreakElement() const; 144 Node* createPlaceholderBreakElement() const;
137 145
138 String directionForFormData() const; 146 String directionForFormData() const;
(...skipping 14 matching lines...) Expand all
153 void addPlaceholderBreakElementIfNecessary(); 161 void addPlaceholderBreakElementIfNecessary();
154 String valueWithHardLineBreaks() const; 162 String valueWithHardLineBreaks() const;
155 163
156 virtual bool shouldDispatchFormControlChangeEvent(String&, String&); 164 virtual bool shouldDispatchFormControlChangeEvent(String&, String&);
157 void copyNonAttributePropertiesFromElement(const Element&) override; 165 void copyNonAttributePropertiesFromElement(const Element&) override;
158 166
159 private: 167 private:
160 unsigned computeSelectionStart() const; 168 unsigned computeSelectionStart() const;
161 unsigned computeSelectionEnd() const; 169 unsigned computeSelectionEnd() const;
162 TextFieldSelectionDirection computeSelectionDirection() const; 170 TextFieldSelectionDirection computeSelectionDirection() const;
163 void cacheSelection(unsigned start, 171 // Returns true if cached values and arguments are not same.
172 bool cacheSelection(unsigned start,
164 unsigned end, 173 unsigned end,
165 TextFieldSelectionDirection direction) { 174 TextFieldSelectionDirection);
166 DCHECK_LE(start, end);
167 m_cachedSelectionStart = start;
168 m_cachedSelectionEnd = end;
169 m_cachedSelectionDirection = direction;
170 }
171 static unsigned indexForPosition(HTMLElement* innerEditor, const Position&); 175 static unsigned indexForPosition(HTMLElement* innerEditor, const Position&);
172 176
173 void dispatchFocusEvent(Element* oldFocusedElement, 177 void dispatchFocusEvent(Element* oldFocusedElement,
174 WebFocusType, 178 WebFocusType,
175 InputDeviceCapabilities* sourceCapabilities) final; 179 InputDeviceCapabilities* sourceCapabilities) final;
176 void dispatchBlurEvent(Element* newFocusedElement, 180 void dispatchBlurEvent(Element* newFocusedElement,
177 WebFocusType, 181 WebFocusType,
178 InputDeviceCapabilities* sourceCapabilities) final; 182 InputDeviceCapabilities* sourceCapabilities) final;
179 void scheduleSelectEvent(); 183 void scheduleSelectEvent();
180 184
(...skipping 28 matching lines...) Expand all
209 } 213 }
210 214
211 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(TextControlElement); 215 DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(TextControlElement);
212 216
213 TextControlElement* enclosingTextControl(const Position&); 217 TextControlElement* enclosingTextControl(const Position&);
214 TextControlElement* enclosingTextControl(const Node*); 218 TextControlElement* enclosingTextControl(const Node*);
215 219
216 } // namespace blink 220 } // namespace blink
217 221
218 #endif 222 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698