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

Side by Side Diff: ui/views/controls/textfield/textfield.h

Issue 120503005: Merge NativeTextfieldViews into views::Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename GetText to text. Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 6 #define UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "base/time/time.h" 15 #include "base/timer/timer.h"
16 #include "build/build_config.h"
17 #include "third_party/skia/include/core/SkColor.h" 16 #include "third_party/skia/include/core/SkColor.h"
17 #include "ui/base/ime/text_input_client.h"
18 #include "ui/base/ime/text_input_type.h" 18 #include "ui/base/ime/text_input_type.h"
19 #include "ui/base/models/simple_menu_model.h"
20 #include "ui/base/touch/touch_editing_controller.h"
19 #include "ui/events/keycodes/keyboard_codes.h" 21 #include "ui/events/keycodes/keyboard_codes.h"
20 #include "ui/gfx/font_list.h" 22 #include "ui/gfx/font_list.h"
21 #include "ui/gfx/native_widget_types.h" 23 #include "ui/gfx/range/range.h"
22 #include "ui/gfx/selection_model.h" 24 #include "ui/gfx/selection_model.h"
23 #include "ui/gfx/text_constants.h" 25 #include "ui/gfx/text_constants.h"
26 #include "ui/views/context_menu_controller.h"
27 #include "ui/views/controls/textfield/textfield_views_model.h"
28 #include "ui/views/drag_controller.h"
24 #include "ui/views/view.h" 29 #include "ui/views/view.h"
25 30
26 #if !defined(OS_LINUX)
27 #include "base/logging.h"
28 #endif
29
30 namespace gfx {
31 class Range;
32 class ImageSkia;
33 }
34
35 namespace ui {
36 class TextInputClient;
37 } // namespace ui
38
39 namespace views { 31 namespace views {
40 32
41 class ImageView; 33 class FocusableBorder;
42 class NativeTextfieldViews; 34 class MenuModelAdapter;
35 class MenuRunner;
43 class Painter; 36 class Painter;
44 class TextfieldController; 37 class TextfieldController;
45 38
46 // This class implements a View that wraps a native text (edit) field. 39 // A views/skia textfield implementation. No platform-specific code is used.
47 class VIEWS_EXPORT Textfield : public View { 40 class VIEWS_EXPORT Textfield : public View,
41 public TextfieldViewsModel::Delegate,
42 public ContextMenuController,
43 public DragController,
44 public ui::TouchEditable,
45 public ui::TextInputClient {
48 public: 46 public:
49 // The textfield's class name. 47 // The textfield's class name.
50 static const char kViewClassName[]; 48 static const char kViewClassName[];
51 49
52 enum StyleFlags { 50 enum StyleFlags {
53 STYLE_DEFAULT = 0, 51 STYLE_DEFAULT = 0,
54 STYLE_OBSCURED = 1 << 0, 52 STYLE_OBSCURED = 1 << 0,
55 STYLE_LOWERCASE = 1 << 1 53 STYLE_LOWERCASE = 1 << 1
56 }; 54 };
57 55
(...skipping 10 matching lines...) Expand all
68 66
69 // Gets/Sets whether or not the Textfield is read-only. 67 // Gets/Sets whether or not the Textfield is read-only.
70 bool read_only() const { return read_only_; } 68 bool read_only() const { return read_only_; }
71 void SetReadOnly(bool read_only); 69 void SetReadOnly(bool read_only);
72 70
73 // Gets/sets the STYLE_OBSCURED bit, controlling whether characters in this 71 // Gets/sets the STYLE_OBSCURED bit, controlling whether characters in this
74 // Textfield are displayed as asterisks/bullets. 72 // Textfield are displayed as asterisks/bullets.
75 bool IsObscured() const; 73 bool IsObscured() const;
76 void SetObscured(bool obscured); 74 void SetObscured(bool obscured);
77 75
78 // Gets/sets the duration to reveal the last typed char when the obscured bit 76 // Sets the input type of this textfield.
79 // is set. A duration of zero effectively disables the feature. Other values
80 // cause the last typed char to be shown for the defined duration. Note this
81 // only works with NativeTextfieldViews.
82 const base::TimeDelta& obscured_reveal_duration() const {
83 return obscured_reveal_duration_;
84 }
85 void set_obscured_reveal_duration(const base::TimeDelta& duration) {
86 obscured_reveal_duration_ = duration;
87 }
88
89 // Gets/Sets the input type of this textfield.
90 ui::TextInputType GetTextInputType() const;
91 void SetTextInputType(ui::TextInputType type); 77 void SetTextInputType(ui::TextInputType type);
92 78
93 // Gets/Sets the text currently displayed in the Textfield. 79 // Gets the text currently displayed in the Textfield.
94 const base::string16& text() const { return text_; } 80 const base::string16& text() const { return model_->text(); }
95 81
96 // Sets the text currently displayed in the Textfield. This doesn't 82 // Sets the text currently displayed in the Textfield. This doesn't
97 // change the cursor position if the current cursor is within the 83 // change the cursor position if the current cursor is within the
98 // new text's range, or moves the cursor to the end if the cursor is 84 // new text's range, or moves the cursor to the end if the cursor is
99 // out of the new text's range. 85 // out of the new text's range.
100 void SetText(const base::string16& text); 86 void SetText(const base::string16& new_text);
101 87
102 // Appends the given string to the previously-existing text in the field. 88 // Appends the given string to the previously-existing text in the field.
103 void AppendText(const base::string16& text); 89 void AppendText(const base::string16& new_text);
104 90
105 // Inserts |text| at the current cursor position, replacing any selected text. 91 // Inserts |new_text| at the cursor position, replacing any selected text.
106 void InsertOrReplaceText(const base::string16& text); 92 void InsertOrReplaceText(const base::string16& new_text);
107 93
108 // Returns the text direction. 94 // Returns the text direction.
109 base::i18n::TextDirection GetTextDirection() const; 95 base::i18n::TextDirection GetTextDirection() const;
110 96
111 // Returns the text that is currently selected. 97 // Returns the text that is currently selected.
112 base::string16 GetSelectedText() const; 98 base::string16 GetSelectedText() const;
113 99
114 // Select the entire text range. If |reversed| is true, the range will end at 100 // Select the entire text range. If |reversed| is true, the range will end at
115 // the logical beginning of the text; this generally shows the leading portion 101 // the logical beginning of the text; this generally shows the leading portion
116 // of text that overflows its display area. 102 // of text that overflows its display area.
117 void SelectAll(bool reversed); 103 void SelectAll(bool reversed);
118 104
119 // Clears the selection within the edit field and sets the caret to the end. 105 // Clears the selection within the edit field and sets the caret to the end.
120 void ClearSelection() const; 106 void ClearSelection();
121 107
122 // Checks if there is any selected text. 108 // Checks if there is any selected text.
123 bool HasSelection() const; 109 bool HasSelection() const;
124 110
125 // Accessor for |style_|. 111 // Accessor for |style_|.
126 StyleFlags style() const { return style_; } 112 StyleFlags style() const { return style_; }
127 113
128 // Gets/Sets the text color to be used when painting the Textfield. 114 // Gets/Sets the text color to be used when painting the Textfield.
129 // Call |UseDefaultTextColor| to restore the default system color. 115 // Call |UseDefaultTextColor| to restore the default system color.
130 SkColor GetTextColor() const; 116 SkColor GetTextColor() const;
131 void SetTextColor(SkColor color); 117 void SetTextColor(SkColor color);
132 void UseDefaultTextColor(); 118 void UseDefaultTextColor();
133 119
134 // Gets/Sets the background color to be used when painting the Textfield. 120 // Gets/Sets the background color to be used when painting the Textfield.
135 // Call |UseDefaultBackgroundColor| to restore the default system color. 121 // Call |UseDefaultBackgroundColor| to restore the default system color.
136 SkColor GetBackgroundColor() const; 122 SkColor GetBackgroundColor() const;
137 void SetBackgroundColor(SkColor color); 123 void SetBackgroundColor(SkColor color);
138 void UseDefaultBackgroundColor(); 124 void UseDefaultBackgroundColor();
139 125
140 // Gets/Sets whether or not the cursor is enabled. 126 // Gets/Sets whether or not the cursor is enabled.
141 bool GetCursorEnabled() const; 127 bool GetCursorEnabled() const;
142 void SetCursorEnabled(bool enabled); 128 void SetCursorEnabled(bool enabled);
143 129
144 // Gets/Sets the fonts used when rendering the text within the Textfield. 130 // Gets/Sets the fonts used when rendering the text within the Textfield.
145 const gfx::FontList& font_list() const { return font_list_; } 131 const gfx::FontList& GetFontList() const;
146 void SetFontList(const gfx::FontList& font_list); 132 void SetFontList(const gfx::FontList& font_list);
147 const gfx::Font& GetPrimaryFont() const;
148 void SetFont(const gfx::Font& font);
149 133
150 // Sets the left and right margin (in pixels) within the text box. On Windows 134 // Sets the left and right margins (in pixels) within the Textfield view.
151 // this is accomplished by packing the left and right margin into a single
152 // 32 bit number, so the left and right margins are effectively 16 bits.
153 void SetHorizontalMargins(int left, int right); 135 void SetHorizontalMargins(int left, int right);
154 136
155 // Sets the top and bottom margins (in pixels) within the textfield. 137 // Removes the border from the edit box, giving it a 2D look.
156 // NOTE: in most cases height could be changed instead. 138 void RemoveBorder();
157 void SetVerticalMargins(int top, int bottom);
158 139
159 // Sets the default width of the text control. See default_width_in_chars_. 140 // Sets the default width of the text control. See default_width_in_chars_.
160 void set_default_width_in_chars(int default_width) { 141 void set_default_width_in_chars(int default_width) {
161 default_width_in_chars_ = default_width; 142 default_width_in_chars_ = default_width;
162 } 143 }
163 144
164 // Removes the border from the edit box, giving it a 2D look.
165 bool draw_border() const { return draw_border_; }
166 void RemoveBorder();
167
168 // Sets the text to display when empty. 145 // Sets the text to display when empty.
169 void set_placeholder_text(const base::string16& text) { 146 void set_placeholder_text(const base::string16& text) {
170 placeholder_text_ = text; 147 placeholder_text_ = text;
171 } 148 }
172 virtual base::string16 GetPlaceholderText() const; 149 virtual base::string16 GetPlaceholderText() const;
173 150
174 SkColor placeholder_text_color() const { return placeholder_text_color_; } 151 SkColor placeholder_text_color() const { return placeholder_text_color_; }
175 void set_placeholder_text_color(SkColor color) { 152 void set_placeholder_text_color(SkColor color) {
176 placeholder_text_color_ = color; 153 placeholder_text_color_ = color;
177 } 154 }
178 155
179 // Getter for the horizontal margins that were set. Returns false if 156 // Get the horizontal margins that were set. Returns false if none were set.
180 // horizontal margins weren't set.
181 bool GetHorizontalMargins(int* left, int* right); 157 bool GetHorizontalMargins(int* left, int* right);
182 158
183 // Getter for the vertical margins that were set. Returns false if vertical
184 // margins weren't set.
185 bool GetVerticalMargins(int* top, int* bottom);
186
187 // Updates all properties on the textfield. This is invoked internally.
188 // Users of Textfield never need to invoke this directly.
189 void UpdateAllProperties();
190
191 // Invoked by the edit control when the value changes. This method set
192 // the text_ member variable to the value contained in edit control.
193 // This is important because the edit control can be replaced if it has
194 // been deleted during a window close.
195 void SyncText();
196
197 // Returns whether or not an IME is composing text. 159 // Returns whether or not an IME is composing text.
198 bool IsIMEComposing() const; 160 bool IsIMEComposing() const;
199 161
200 // Gets the selected logical text range. 162 // Gets the selected logical text range.
201 const gfx::Range& GetSelectedRange() const; 163 const gfx::Range& GetSelectedRange() const;
202 164
203 // Selects the specified logical text range. 165 // Selects the specified logical text range.
204 void SelectRange(const gfx::Range& range); 166 void SelectRange(const gfx::Range& range);
205 167
206 // Gets the text selection model. 168 // Gets the text selection model.
(...skipping 20 matching lines...) Expand all
227 void ClearEditHistory(); 189 void ClearEditHistory();
228 190
229 // Set the accessible name of the text field. 191 // Set the accessible name of the text field.
230 void SetAccessibleName(const base::string16& name); 192 void SetAccessibleName(const base::string16& name);
231 193
232 // Performs the action associated with the specified command id. 194 // Performs the action associated with the specified command id.
233 void ExecuteCommand(int command_id); 195 void ExecuteCommand(int command_id);
234 196
235 void SetFocusPainter(scoped_ptr<Painter> focus_painter); 197 void SetFocusPainter(scoped_ptr<Painter> focus_painter);
236 198
237 // Provided only for testing:
238 NativeTextfieldViews* GetTextfieldViewForTesting() const {
239 return textfield_view_;
240 }
241
242 // Returns whether there is a drag operation originating from the textfield. 199 // Returns whether there is a drag operation originating from the textfield.
243 bool HasTextBeingDragged(); 200 bool HasTextBeingDragged();
244 201
245 // Overridden from View: 202 // View overrides:
246 virtual void Layout() OVERRIDE; 203 // TODO(msw): Match declaration and definition order to View.
247 virtual int GetBaseline() const OVERRIDE; 204 virtual int GetBaseline() const OVERRIDE;
248 virtual gfx::Size GetPreferredSize() OVERRIDE; 205 virtual gfx::Size GetPreferredSize() OVERRIDE;
249 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; 206 virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
250 virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE; 207 virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE;
251 virtual void OnEnabledChanged() OVERRIDE; 208 virtual void OnEnabledChanged() OVERRIDE;
252 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 209 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
253 virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE; 210 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
254 virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE; 211 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
255 virtual bool OnMouseDragged(const ui::MouseEvent& e) OVERRIDE; 212 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
213 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
256 virtual void OnFocus() OVERRIDE; 214 virtual void OnFocus() OVERRIDE;
257 virtual void OnBlur() OVERRIDE; 215 virtual void OnBlur() OVERRIDE;
258 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 216 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
259 virtual ui::TextInputClient* GetTextInputClient() OVERRIDE; 217 virtual ui::TextInputClient* GetTextInputClient() OVERRIDE;
260 virtual gfx::Point GetKeyboardContextMenuLocation() OVERRIDE; 218 virtual gfx::Point GetKeyboardContextMenuLocation() OVERRIDE;
219 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE;
220 virtual const char* GetClassName() const OVERRIDE;
221 virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE;
222 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
223 virtual bool GetDropFormats(
224 int* formats,
225 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
226 virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE;
227 virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
228 virtual void OnDragExited() OVERRIDE;
229 virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
230 virtual void OnDragDone() OVERRIDE;
231 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
232
233 // TextfieldViewsModel::Delegate overrides:
234 virtual void OnCompositionTextConfirmedOrCleared() OVERRIDE;
235
236 // ContextMenuController overrides:
237 virtual void ShowContextMenuForView(View* source,
238 const gfx::Point& point,
239 ui::MenuSourceType source_type) OVERRIDE;
240
241 // DragController overrides:
242 virtual void WriteDragDataForView(View* sender,
243 const gfx::Point& press_pt,
244 ui::OSExchangeData* data) OVERRIDE;
245 virtual int GetDragOperationsForView(View* sender,
246 const gfx::Point& p) OVERRIDE;
247 virtual bool CanStartDragForView(View* sender,
248 const gfx::Point& press_pt,
249 const gfx::Point& p) OVERRIDE;
250
251 // ui::TouchEditable overrides:
252 virtual void SelectRect(const gfx::Point& start,
253 const gfx::Point& end) OVERRIDE;
254 virtual void MoveCaretTo(const gfx::Point& point) OVERRIDE;
255 virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) OVERRIDE;
256 virtual gfx::Rect GetBounds() OVERRIDE;
257 virtual gfx::NativeView GetNativeView() const OVERRIDE;
258 virtual void ConvertPointToScreen(gfx::Point* point) OVERRIDE;
259 virtual void ConvertPointFromScreen(gfx::Point* point) OVERRIDE;
260 virtual bool DrawsHandles() OVERRIDE;
261 virtual void OpenContextMenu(const gfx::Point& anchor) OVERRIDE;
262
263 // ui::SimpleMenuModel::Delegate overrides:
264 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
265 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
266 virtual bool GetAcceleratorForCommandId(
267 int command_id,
268 ui::Accelerator* accelerator) OVERRIDE;
269 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
270 virtual base::string16 GetLabelForCommandId(int command_id) const OVERRIDE;
271 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
272
273 // ui::TextInputClient overrides:
274 virtual void SetCompositionText(
275 const ui::CompositionText& composition) OVERRIDE;
276 virtual void ConfirmCompositionText() OVERRIDE;
277 virtual void ClearCompositionText() OVERRIDE;
278 virtual void InsertText(const base::string16& text) OVERRIDE;
279 virtual void InsertChar(base::char16 ch, int flags) OVERRIDE;
280 virtual gfx::NativeWindow GetAttachedWindow() const OVERRIDE;
281 virtual ui::TextInputType GetTextInputType() const OVERRIDE;
282 virtual ui::TextInputMode GetTextInputMode() const OVERRIDE;
283 virtual bool CanComposeInline() const OVERRIDE;
284 virtual gfx::Rect GetCaretBounds() const OVERRIDE;
285 virtual bool GetCompositionCharacterBounds(uint32 index,
286 gfx::Rect* rect) const OVERRIDE;
287 virtual bool HasCompositionText() const OVERRIDE;
288 virtual bool GetTextRange(gfx::Range* range) const OVERRIDE;
289 virtual bool GetCompositionTextRange(gfx::Range* range) const OVERRIDE;
290 virtual bool GetSelectionRange(gfx::Range* range) const OVERRIDE;
291 virtual bool SetSelectionRange(const gfx::Range& range) OVERRIDE;
292 virtual bool DeleteRange(const gfx::Range& range) OVERRIDE;
293 virtual bool GetTextFromRange(const gfx::Range& range,
294 base::string16* text) const OVERRIDE;
295 virtual void OnInputMethodChanged() OVERRIDE;
296 virtual bool ChangeTextDirectionAndLayoutAlignment(
297 base::i18n::TextDirection direction) OVERRIDE;
298 virtual void ExtendSelectionAndDelete(size_t before, size_t after) OVERRIDE;
299 virtual void EnsureCaretInRect(const gfx::Rect& rect) OVERRIDE;
300 virtual void OnCandidateWindowShown() OVERRIDE;
301 virtual void OnCandidateWindowUpdated() OVERRIDE;
302 virtual void OnCandidateWindowHidden() OVERRIDE;
261 303
262 protected: 304 protected:
263 virtual void ViewHierarchyChanged( 305 // Returns the TextfieldViewsModel's text/cursor/selection rendering model.
264 const ViewHierarchyChangedDetails& details) OVERRIDE; 306 gfx::RenderText* GetRenderText() const;
265 virtual const char* GetClassName() const OVERRIDE;
266
267 // The object that actually implements the native textfield view.
268 // TODO(msw): Merge views::NativeTextfieldViews and views::Textfield classes.
269 NativeTextfieldViews* textfield_view_;
270 307
271 private: 308 private:
272 // Returns the insets to the rectangle where text is actually painted. 309 friend class TextfieldTest;
273 gfx::Insets GetTextInsets() const; 310 friend class TouchSelectionControllerImplTest;
311
312 // Converts the raw text according to the current style, e.g. STYLE_LOWERCASE.
313 base::string16 GetTextForDisplay(const base::string16& raw);
274 314
275 // Handles a request to change the value of this text field from software 315 // Handles a request to change the value of this text field from software
276 // using an accessibility API (typically automation software, screen readers 316 // using an accessibility API (typically automation software, screen readers
277 // don't normally use this). Sets the value and clears the selection. 317 // don't normally use this). Sets the value and clears the selection.
278 void AccessibilitySetValue(const base::string16& new_value); 318 void AccessibilitySetValue(const base::string16& new_value);
279 319
320 // Updates the horizontal margins.
321 void UpdateHorizontalMargins();
322
323 // Updates the painted background color.
324 void UpdateBackgroundColor();
325
326 // Updates any colors that have not been explicitly set from the theme.
327 void UpdateColorsFromTheme(const ui::NativeTheme* theme);
328
329 // Does necessary updates when the text and/or cursor position changes.
330 void UpdateAfterChange(bool text_changed, bool cursor_changed);
331
332 // A callback function to periodically update the cursor state.
333 void UpdateCursor();
334
335 // Repaint the cursor.
336 void RepaintCursor();
337
338 void PaintTextAndCursor(gfx::Canvas* canvas);
339
340 // Helper function to call MoveCursorTo on the TextfieldViewsModel.
341 bool MoveCursorTo(const gfx::Point& point, bool select);
342
343 // Convenience method to call InputMethod::OnCaretBoundsChanged();
344 void OnCaretBoundsChanged();
345
346 // Convenience method to call TextfieldController::OnBeforeUserAction();
347 void OnBeforeUserAction();
348
349 // Convenience method to call TextfieldController::OnAfterUserAction();
350 void OnAfterUserAction();
351
352 // Calls |model_->Cut()| and notifies TextfieldController on success.
353 bool Cut();
354
355 // Calls |model_->Copy()| and notifies TextfieldController on success.
356 bool Copy();
357
358 // Calls |model_->Paste()| and calls TextfieldController::ContentsChanged()
359 // explicitly if paste succeeded.
360 bool Paste();
361
362 // Utility function to prepare the context menu.
363 void UpdateContextMenu();
364
365 // Tracks the mouse clicks for single/double/triple clicks.
366 void TrackMouseClicks(const ui::MouseEvent& event);
367
368 // Returns true if the current text input type allows access by the IME.
369 bool ImeEditingAllowed() const;
370
371 // Reveals the obscured char at |index| for the given |duration|. If |index|
372 // is -1, existing revealed index will be cleared.
373 void RevealObscuredChar(int index, const base::TimeDelta& duration);
374
375 void CreateTouchSelectionControllerAndNotifyIt();
376
377 // The text model.
378 scoped_ptr<TextfieldViewsModel> model_;
379
280 // This is the current listener for events from this Textfield. 380 // This is the current listener for events from this Textfield.
281 TextfieldController* controller_; 381 TextfieldController* controller_;
282 382
283 // The mask of style options for this Textfield. 383 // The mask of style options for this Textfield.
284 StyleFlags style_; 384 StyleFlags style_;
285 385
286 // The fonts used to render the text in the Textfield.
287 gfx::FontList font_list_;
288
289 // The text displayed in the Textfield.
290 base::string16 text_;
291
292 // True if this Textfield cannot accept input and is read-only. 386 // True if this Textfield cannot accept input and is read-only.
293 bool read_only_; 387 bool read_only_;
294 388
295 // The default number of average characters for the width of this text field. 389 // The default number of average characters for the width of this text field.
296 // This will be reported as the "desired size". Defaults to 0. 390 // This will be reported as the "desired size". Defaults to 0.
297 int default_width_in_chars_; 391 int default_width_in_chars_;
298 392
299 // Whether the border is drawn. 393 // The focusable border is always non-NULL but is only drawn if |draw_border_|
394 // is true. If it is not drawn, then by default it's also zero-sized unless
395 // the Textfield has explicitly-set margins.
396 FocusableBorder* text_border_;
300 bool draw_border_; 397 bool draw_border_;
301 398
399 scoped_ptr<Painter> focus_painter_;
400
302 // Text color. Only used if |use_default_text_color_| is false. 401 // Text color. Only used if |use_default_text_color_| is false.
303 SkColor text_color_; 402 SkColor text_color_;
304 403
305 // Should we use the system text color instead of |text_color_|? 404 // Should we use the system text color instead of |text_color_|?
306 bool use_default_text_color_; 405 bool use_default_text_color_;
307 406
308 // Background color. Only used if |use_default_background_color_| is false. 407 // Background color. Only used if |use_default_background_color_| is false.
309 SkColor background_color_; 408 SkColor background_color_;
310 409
311 // Should we use the system background color instead of |background_color_|? 410 // Should we use the system background color instead of |background_color_|?
312 bool use_default_background_color_; 411 bool use_default_background_color_;
313 412
314 // Holds inner textfield margins. 413 // Holds inner textfield margins.
315 gfx::Insets margins_; 414 gfx::Insets margins_;
316 415
317 // Holds whether margins were set. 416 // Holds whether margins were set.
318 bool horizontal_margins_were_set_; 417 bool horizontal_margins_were_set_;
319 bool vertical_margins_were_set_;
320 418
321 // Text to display when empty. 419 // Text to display when empty.
322 base::string16 placeholder_text_; 420 base::string16 placeholder_text_;
323 421
324 // Placeholder text color. 422 // Placeholder text color.
325 SkColor placeholder_text_color_; 423 SkColor placeholder_text_color_;
326 424
327 // The accessible name of the text field. 425 // The accessible name of the text field.
328 base::string16 accessible_name_; 426 base::string16 accessible_name_;
329 427
330 // The input type of this text field. 428 // The input type of this text field.
331 ui::TextInputType text_input_type_; 429 ui::TextInputType text_input_type_;
332 430
333 // The duration to reveal the last typed char for obscured textfields. 431 // The duration to reveal the last typed char for obscured textfields.
334 base::TimeDelta obscured_reveal_duration_; 432 base::TimeDelta obscured_reveal_duration_;
335 433
434 // True if InputMethod::CancelComposition() should not be called.
435 bool skip_input_method_cancel_composition_;
436
437 // The text editing cursor visibility.
438 bool is_cursor_visible_;
439
440 // The drop cursor is a visual cue for where dragged text will be dropped.
441 bool is_drop_cursor_visible_;
442 gfx::SelectionModel drop_cursor_position_;
443
444 // Is the user potentially dragging and dropping from this view?
445 bool initiating_drag_;
446
447 // State variables used to track double and triple clicks.
448 size_t aggregated_clicks_;
449 base::TimeDelta last_click_time_;
450 gfx::Point last_click_location_;
451 gfx::Range double_click_word_;
452
453 scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;
454
455 // A timer to control the duration of showing the last typed char in
456 // obscured text. When the timer is running, the last typed char is shown
457 // and when the time expires, the last typed char is obscured.
458 base::OneShotTimer<Textfield> obscured_reveal_timer_;
459
460 // Context menu related members.
461 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_;
462 scoped_ptr<views::MenuModelAdapter> context_menu_delegate_;
sky 2014/01/09 21:43:11 Is this really needed? You should be able to use t
msw 2014/01/10 20:34:55 Done.
463 scoped_ptr<views::MenuRunner> context_menu_runner_;
464
336 // Used to bind callback functions to this object. 465 // Used to bind callback functions to this object.
337 base::WeakPtrFactory<Textfield> weak_ptr_factory_; 466 base::WeakPtrFactory<Textfield> weak_ptr_factory_;
338 467 // Used to bind a cursor painting callback function to this object.
339 scoped_ptr<Painter> focus_painter_; 468 base::WeakPtrFactory<Textfield> cursor_weak_ptr_factory_;
340 469
341 DISALLOW_COPY_AND_ASSIGN(Textfield); 470 DISALLOW_COPY_AND_ASSIGN(Textfield);
342 }; 471 };
343 472
344 } // namespace views 473 } // namespace views
345 474
346 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ 475 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698