OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
6 #define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 6 #define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
11 #include "ui/base/models/simple_menu_model.h" | 11 #include "ui/base/models/simple_menu_model.h" |
12 #include "ui/gfx/font.h" | 12 #include "ui/gfx/font.h" |
13 #include "views/border.h" | 13 #include "views/border.h" |
14 #include "views/controls/textfield/native_textfield_wrapper.h" | 14 #include "views/controls/textfield/native_textfield_wrapper.h" |
15 #include "views/controls/textfield/textfield_views_model.h" | |
16 #include "views/ime/text_input_client.h" | |
15 #include "views/view.h" | 17 #include "views/view.h" |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 class Time; | 20 class Time; |
19 } | 21 } |
20 | 22 |
21 namespace gfx { | 23 namespace gfx { |
22 class Canvas; | 24 class Canvas; |
23 } | 25 } |
24 | 26 |
25 namespace views { | 27 namespace views { |
26 | 28 |
27 class KeyEvent; | 29 class KeyEvent; |
28 class Menu2; | 30 class Menu2; |
29 class TextfieldViewsModel; | |
30 | 31 |
31 // A views/skia only implementation of NativeTextfieldWrapper. | 32 // A views/skia only implementation of NativeTextfieldWrapper. |
32 // No platform specific code is used. | 33 // No platform specific code is used. |
33 // Following features are not yet supported. | 34 // Following features are not yet supported. |
34 // * BIDI | 35 // * BIDI |
35 // * IME/i18n support. | 36 // * IME/i18n support. |
36 // * X selection (only if we want to support). | 37 // * X selection (only if we want to support). |
37 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in | 38 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in |
38 // chromeos, so we may not need them) | 39 // chromeos, so we may not need them) |
39 // * Double click to select word, and triple click to select all. | 40 // * Double click to select word, and triple click to select all. |
40 // * Undo/Redo | 41 // * Undo/Redo |
41 class NativeTextfieldViews : public views::View, | 42 class NativeTextfieldViews : public views::View, |
42 public views::ContextMenuController, | 43 public views::ContextMenuController, |
43 public NativeTextfieldWrapper, | 44 public NativeTextfieldWrapper, |
44 public ui::SimpleMenuModel::Delegate { | 45 public ui::SimpleMenuModel::Delegate, |
46 public TextInputClient, | |
47 public TextfieldViewsModel::Delegate { | |
45 public: | 48 public: |
46 explicit NativeTextfieldViews(Textfield* parent); | 49 explicit NativeTextfieldViews(Textfield* parent); |
47 ~NativeTextfieldViews(); | 50 ~NativeTextfieldViews(); |
48 | 51 |
49 // views::View overrides: | 52 // views::View overrides: |
50 virtual bool OnMousePressed(const views::MouseEvent& e) OVERRIDE; | 53 virtual bool OnMousePressed(const views::MouseEvent& e) OVERRIDE; |
51 virtual bool OnMouseDragged(const views::MouseEvent& e) OVERRIDE; | 54 virtual bool OnMouseDragged(const views::MouseEvent& e) OVERRIDE; |
52 virtual void OnMouseReleased(const views::MouseEvent& e, | 55 virtual void OnMouseReleased(const views::MouseEvent& e, |
53 bool canceled) OVERRIDE; | 56 bool canceled) OVERRIDE; |
54 virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE; | 57 virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE; |
(...skipping 30 matching lines...) Expand all Loading... | |
85 virtual View* GetView() OVERRIDE; | 88 virtual View* GetView() OVERRIDE; |
86 virtual gfx::NativeView GetTestingHandle() const OVERRIDE; | 89 virtual gfx::NativeView GetTestingHandle() const OVERRIDE; |
87 virtual bool IsIMEComposing() const OVERRIDE; | 90 virtual bool IsIMEComposing() const OVERRIDE; |
88 virtual void GetSelectedRange(ui::Range* range) const OVERRIDE; | 91 virtual void GetSelectedRange(ui::Range* range) const OVERRIDE; |
89 virtual void SelectRange(const ui::Range& range) OVERRIDE; | 92 virtual void SelectRange(const ui::Range& range) OVERRIDE; |
90 virtual size_t GetCursorPosition() const OVERRIDE; | 93 virtual size_t GetCursorPosition() const OVERRIDE; |
91 virtual bool HandleKeyPressed(const views::KeyEvent& e) OVERRIDE; | 94 virtual bool HandleKeyPressed(const views::KeyEvent& e) OVERRIDE; |
92 virtual bool HandleKeyReleased(const views::KeyEvent& e) OVERRIDE; | 95 virtual bool HandleKeyReleased(const views::KeyEvent& e) OVERRIDE; |
93 virtual void HandleFocus() OVERRIDE; | 96 virtual void HandleFocus() OVERRIDE; |
94 virtual void HandleBlur() OVERRIDE; | 97 virtual void HandleBlur() OVERRIDE; |
98 virtual TextInputClient* GetTextInputClient() OVERRIDE; | |
95 | 99 |
96 // ui::SimpleMenuModel::Delegate overrides | 100 // ui::SimpleMenuModel::Delegate overrides |
97 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 101 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
98 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 102 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
99 virtual bool GetAcceleratorForCommandId( | 103 virtual bool GetAcceleratorForCommandId( |
100 int command_id, | 104 int command_id, |
101 ui::Accelerator* accelerator) OVERRIDE; | 105 ui::Accelerator* accelerator) OVERRIDE; |
102 virtual void ExecuteCommand(int command_id) OVERRIDE; | 106 virtual void ExecuteCommand(int command_id) OVERRIDE; |
103 | 107 |
104 // class name of internal | 108 // class name of internal |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 has_focus_ = has_focus; | 146 has_focus_ = has_focus; |
143 } | 147 } |
144 | 148 |
145 private: | 149 private: |
146 bool has_focus_; | 150 bool has_focus_; |
147 gfx::Insets insets_; | 151 gfx::Insets insets_; |
148 | 152 |
149 DISALLOW_COPY_AND_ASSIGN(TextfieldBorder); | 153 DISALLOW_COPY_AND_ASSIGN(TextfieldBorder); |
150 }; | 154 }; |
151 | 155 |
156 // Overridden from TextInputClient: | |
157 virtual void SetCompositionText( | |
158 const ui::CompositionText& composition) OVERRIDE; | |
159 virtual void ConfirmCompositionText() OVERRIDE; | |
160 virtual void ClearCompositionText() OVERRIDE; | |
161 virtual void InsertText(const string16& text) OVERRIDE; | |
162 virtual void InsertChar(char16 ch, int flags) OVERRIDE; | |
163 virtual ui::TextInputType GetTextInputType() OVERRIDE; | |
164 virtual gfx::Rect GetCaretBounds() OVERRIDE; | |
165 virtual bool HasCompositionText() OVERRIDE; | |
166 virtual bool GetTextRange(ui::Range* range) OVERRIDE; | |
167 virtual bool GetCompositionTextRange(ui::Range* range) OVERRIDE; | |
168 virtual bool GetSelectionRange(ui::Range* range) OVERRIDE; | |
169 virtual bool SetSelectionRange(const ui::Range& range) OVERRIDE; | |
170 virtual bool DeleteRange(const ui::Range& range) OVERRIDE; | |
171 virtual bool GetTextFromRange( | |
172 const ui::Range& range, | |
173 const base::Callback<void(const string16&)>& callback) OVERRIDE; | |
174 virtual void OnInputMethodChanged() OVERRIDE; | |
175 virtual bool ChangeTextDirectionAndLayoutAlignment( | |
176 base::i18n::TextDirection direction) OVERRIDE; | |
177 | |
178 // Overridden from TextfieldViewsModel::Delegate: | |
179 virtual void OnCompositionTextConfirmedOrCleared() OVERRIDE; | |
180 | |
152 // Returns the Textfield's font. | 181 // Returns the Textfield's font. |
153 const gfx::Font& GetFont() const; | 182 const gfx::Font& GetFont() const; |
154 | 183 |
155 // Returns the Textfield's text color. | 184 // Returns the Textfield's text color. |
156 SkColor GetTextColor() const; | 185 SkColor GetTextColor() const; |
157 | 186 |
158 // A callback function to periodically update the cursor state. | 187 // A callback function to periodically update the cursor state. |
159 void UpdateCursor(); | 188 void UpdateCursor(); |
160 | 189 |
161 // Repaint the cursor. | 190 // Repaint the cursor. |
(...skipping 21 matching lines...) Expand all Loading... | |
183 // that the text in the textfield has changed. | 212 // that the text in the textfield has changed. |
184 void PropagateTextChange(); | 213 void PropagateTextChange(); |
185 | 214 |
186 // Does necessary updates when the text and/or the position of the cursor | 215 // Does necessary updates when the text and/or the position of the cursor |
187 // changed. | 216 // changed. |
188 void UpdateAfterChange(bool text_changed, bool cursor_changed); | 217 void UpdateAfterChange(bool text_changed, bool cursor_changed); |
189 | 218 |
190 // Utility function to create the context menu if one does not already exist. | 219 // Utility function to create the context menu if one does not already exist. |
191 void InitContextMenuIfRequired(); | 220 void InitContextMenuIfRequired(); |
192 | 221 |
222 // Convenience method to call InputMethod::OnTextInputTypeChanged(); | |
223 void OnTextInputTypeChanged(); | |
224 | |
225 // Convenience method to call InputMethod::OnCaretBoundsChanged(); | |
226 void OnCaretBoundsChanged(); | |
227 | |
193 // Convenience method to call TextfieldController::OnBeforeUserAction(); | 228 // Convenience method to call TextfieldController::OnBeforeUserAction(); |
194 void OnBeforeUserAction(); | 229 void OnBeforeUserAction(); |
195 | 230 |
196 // Convenience method to call TextfieldController::OnAfterUserAction(); | 231 // Convenience method to call TextfieldController::OnAfterUserAction(); |
197 void OnAfterUserAction(); | 232 void OnAfterUserAction(); |
198 | 233 |
199 // Checks if a char is ok to be inserted into the textfield. The |ch| is a | 234 // Checks if a char is ok to be inserted into the textfield. The |ch| is a |
200 // modified character, i.e., modifiers took effect when generating this char. | 235 // modified character, i.e., modifiers took effect when generating this char. |
201 static bool ShouldInsertChar(char16 ch, int flags); | 236 static bool ShouldInsertChar(char16 ch, int flags); |
202 | 237 |
203 // The parent textfield, the owner of this object. | 238 // The parent textfield, the owner of this object. |
204 Textfield* textfield_; | 239 Textfield* textfield_; |
205 | 240 |
206 // The text model. | 241 // The text model. |
207 scoped_ptr<TextfieldViewsModel> model_; | 242 scoped_ptr<TextfieldViewsModel> model_; |
208 | 243 |
209 // The reference to the border class. The object is owned by View::border_. | 244 // The reference to the border class. The object is owned by View::border_. |
210 TextfieldBorder* text_border_; | 245 TextfieldBorder* text_border_; |
211 | 246 |
212 // The x offset for the text to be drawn, without insets; | 247 // The x offset for the text to be drawn, without insets; |
213 int text_offset_; | 248 int text_offset_; |
214 | 249 |
215 // Cursor's bounds in the textfield's coordinates. | 250 // Cursor's bounds in the textfield's coordinates. |
216 gfx::Rect cursor_bounds_; | 251 gfx::Rect cursor_bounds_; |
oshima
2011/03/30 21:06:34
If we can assume input_method is always present, m
James Su
2011/03/30 21:30:32
|cursor_bounds_| is also used in painting code, I
| |
217 | 252 |
218 // True if the textfield is in insert mode. | 253 // True if the textfield is in insert mode. |
219 bool insert_; | 254 bool insert_; |
220 | 255 |
221 // The drawing state of cursor. True to draw. | 256 // The drawing state of cursor. True to draw. |
222 bool is_cursor_visible_; | 257 bool is_cursor_visible_; |
223 | 258 |
259 // True if InputMethod::CancelComposition() should not be called. | |
260 bool skip_input_method_cancel_composition_; | |
261 | |
224 // A runnable method factory for callback to update the cursor. | 262 // A runnable method factory for callback to update the cursor. |
225 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; | 263 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; |
226 | 264 |
227 // Time of last LEFT mouse press. Used for tracking double/triple click. | 265 // Time of last LEFT mouse press. Used for tracking double/triple click. |
228 base::Time last_mouse_press_time_; | 266 base::Time last_mouse_press_time_; |
229 | 267 |
230 // Position of last LEFT mouse press. Used for tracking double/triple click. | 268 // Position of last LEFT mouse press. Used for tracking double/triple click. |
231 gfx::Point last_mouse_press_location_; | 269 gfx::Point last_mouse_press_location_; |
232 | 270 |
233 // State variable to track double and triple clicks. | 271 // State variable to track double and triple clicks. |
234 ClickState click_state_; | 272 ClickState click_state_; |
235 | 273 |
236 // Context menu and its content list for the textfield. | 274 // Context menu and its content list for the textfield. |
237 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; | 275 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; |
238 scoped_ptr<Menu2> context_menu_menu_; | 276 scoped_ptr<Menu2> context_menu_menu_; |
239 | 277 |
240 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); | 278 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); |
241 }; | 279 }; |
242 | 280 |
243 } // namespace views | 281 } // namespace views |
244 | 282 |
245 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 283 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
OLD | NEW |