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& event) OVERRIDE; | 53 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; |
51 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; | 54 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; |
52 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; | 55 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; |
53 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; | 56 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; |
54 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 57 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
(...skipping 28 matching lines...) Expand all Loading... |
83 virtual View* GetView() OVERRIDE; | 86 virtual View* GetView() OVERRIDE; |
84 virtual gfx::NativeView GetTestingHandle() const OVERRIDE; | 87 virtual gfx::NativeView GetTestingHandle() const OVERRIDE; |
85 virtual bool IsIMEComposing() const OVERRIDE; | 88 virtual bool IsIMEComposing() const OVERRIDE; |
86 virtual void GetSelectedRange(ui::Range* range) const OVERRIDE; | 89 virtual void GetSelectedRange(ui::Range* range) const OVERRIDE; |
87 virtual void SelectRange(const ui::Range& range) OVERRIDE; | 90 virtual void SelectRange(const ui::Range& range) OVERRIDE; |
88 virtual size_t GetCursorPosition() const OVERRIDE; | 91 virtual size_t GetCursorPosition() const OVERRIDE; |
89 virtual bool HandleKeyPressed(const views::KeyEvent& e) OVERRIDE; | 92 virtual bool HandleKeyPressed(const views::KeyEvent& e) OVERRIDE; |
90 virtual bool HandleKeyReleased(const views::KeyEvent& e) OVERRIDE; | 93 virtual bool HandleKeyReleased(const views::KeyEvent& e) OVERRIDE; |
91 virtual void HandleFocus() OVERRIDE; | 94 virtual void HandleFocus() OVERRIDE; |
92 virtual void HandleBlur() OVERRIDE; | 95 virtual void HandleBlur() OVERRIDE; |
| 96 virtual TextInputClient* GetTextInputClient() OVERRIDE; |
93 | 97 |
94 // ui::SimpleMenuModel::Delegate overrides | 98 // ui::SimpleMenuModel::Delegate overrides |
95 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 99 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
96 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 100 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
97 virtual bool GetAcceleratorForCommandId( | 101 virtual bool GetAcceleratorForCommandId( |
98 int command_id, | 102 int command_id, |
99 ui::Accelerator* accelerator) OVERRIDE; | 103 ui::Accelerator* accelerator) OVERRIDE; |
100 virtual void ExecuteCommand(int command_id) OVERRIDE; | 104 virtual void ExecuteCommand(int command_id) OVERRIDE; |
101 | 105 |
102 // class name of internal | 106 // class name of internal |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 has_focus_ = has_focus; | 144 has_focus_ = has_focus; |
141 } | 145 } |
142 | 146 |
143 private: | 147 private: |
144 bool has_focus_; | 148 bool has_focus_; |
145 gfx::Insets insets_; | 149 gfx::Insets insets_; |
146 | 150 |
147 DISALLOW_COPY_AND_ASSIGN(TextfieldBorder); | 151 DISALLOW_COPY_AND_ASSIGN(TextfieldBorder); |
148 }; | 152 }; |
149 | 153 |
| 154 // Overridden from TextInputClient: |
| 155 virtual void SetCompositionText( |
| 156 const ui::CompositionText& composition) OVERRIDE; |
| 157 virtual void ConfirmCompositionText() OVERRIDE; |
| 158 virtual void ClearCompositionText() OVERRIDE; |
| 159 virtual void InsertText(const string16& text) OVERRIDE; |
| 160 virtual void InsertChar(char16 ch, int flags) OVERRIDE; |
| 161 virtual ui::TextInputType GetTextInputType() OVERRIDE; |
| 162 virtual gfx::Rect GetCaretBounds() OVERRIDE; |
| 163 virtual bool HasCompositionText() OVERRIDE; |
| 164 virtual bool GetTextRange(ui::Range* range) OVERRIDE; |
| 165 virtual bool GetCompositionTextRange(ui::Range* range) OVERRIDE; |
| 166 virtual bool GetSelectionRange(ui::Range* range) OVERRIDE; |
| 167 virtual bool SetSelectionRange(const ui::Range& range) OVERRIDE; |
| 168 virtual bool DeleteRange(const ui::Range& range) OVERRIDE; |
| 169 virtual bool GetTextFromRange( |
| 170 const ui::Range& range, |
| 171 const base::Callback<void(const string16&)>& callback) OVERRIDE; |
| 172 virtual void OnInputMethodChanged() OVERRIDE; |
| 173 virtual bool ChangeTextDirectionAndLayoutAlignment( |
| 174 base::i18n::TextDirection direction) OVERRIDE; |
| 175 virtual View* GetOwnerViewOfTextInputClient() OVERRIDE; |
| 176 |
| 177 // Overridden from TextfieldViewsModel::Delegate: |
| 178 virtual void OnCompositionTextConfirmedOrCleared() OVERRIDE; |
| 179 |
150 // Returns the Textfield's font. | 180 // Returns the Textfield's font. |
151 const gfx::Font& GetFont() const; | 181 const gfx::Font& GetFont() const; |
152 | 182 |
153 // Returns the Textfield's text color. | 183 // Returns the Textfield's text color. |
154 SkColor GetTextColor() const; | 184 SkColor GetTextColor() const; |
155 | 185 |
156 // A callback function to periodically update the cursor state. | 186 // A callback function to periodically update the cursor state. |
157 void UpdateCursor(); | 187 void UpdateCursor(); |
158 | 188 |
159 // Repaint the cursor. | 189 // Repaint the cursor. |
(...skipping 21 matching lines...) Expand all Loading... |
181 // that the text in the textfield has changed. | 211 // that the text in the textfield has changed. |
182 void PropagateTextChange(); | 212 void PropagateTextChange(); |
183 | 213 |
184 // Does necessary updates when the text and/or the position of the cursor | 214 // Does necessary updates when the text and/or the position of the cursor |
185 // changed. | 215 // changed. |
186 void UpdateAfterChange(bool text_changed, bool cursor_changed); | 216 void UpdateAfterChange(bool text_changed, bool cursor_changed); |
187 | 217 |
188 // Utility function to create the context menu if one does not already exist. | 218 // Utility function to create the context menu if one does not already exist. |
189 void InitContextMenuIfRequired(); | 219 void InitContextMenuIfRequired(); |
190 | 220 |
| 221 // Convenience method to call InputMethod::OnTextInputTypeChanged(); |
| 222 void OnTextInputTypeChanged(); |
| 223 |
| 224 // Convenience method to call InputMethod::OnCaretBoundsChanged(); |
| 225 void OnCaretBoundsChanged(); |
| 226 |
191 // Convenience method to call TextfieldController::OnBeforeUserAction(); | 227 // Convenience method to call TextfieldController::OnBeforeUserAction(); |
192 void OnBeforeUserAction(); | 228 void OnBeforeUserAction(); |
193 | 229 |
194 // Convenience method to call TextfieldController::OnAfterUserAction(); | 230 // Convenience method to call TextfieldController::OnAfterUserAction(); |
195 void OnAfterUserAction(); | 231 void OnAfterUserAction(); |
196 | 232 |
197 // Checks if a char is ok to be inserted into the textfield. The |ch| is a | 233 // Checks if a char is ok to be inserted into the textfield. The |ch| is a |
198 // modified character, i.e., modifiers took effect when generating this char. | 234 // modified character, i.e., modifiers took effect when generating this char. |
199 static bool ShouldInsertChar(char16 ch, int flags); | 235 static bool ShouldInsertChar(char16 ch, int flags); |
200 | 236 |
(...skipping 11 matching lines...) Expand all Loading... |
212 | 248 |
213 // Cursor's bounds in the textfield's coordinates. | 249 // Cursor's bounds in the textfield's coordinates. |
214 gfx::Rect cursor_bounds_; | 250 gfx::Rect cursor_bounds_; |
215 | 251 |
216 // True if the textfield is in insert mode. | 252 // True if the textfield is in insert mode. |
217 bool insert_; | 253 bool insert_; |
218 | 254 |
219 // The drawing state of cursor. True to draw. | 255 // The drawing state of cursor. True to draw. |
220 bool is_cursor_visible_; | 256 bool is_cursor_visible_; |
221 | 257 |
| 258 // True if InputMethod::CancelComposition() should not be called. |
| 259 bool skip_input_method_cancel_composition_; |
| 260 |
222 // A runnable method factory for callback to update the cursor. | 261 // A runnable method factory for callback to update the cursor. |
223 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; | 262 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; |
224 | 263 |
225 // Time of last LEFT mouse press. Used for tracking double/triple click. | 264 // Time of last LEFT mouse press. Used for tracking double/triple click. |
226 base::Time last_mouse_press_time_; | 265 base::Time last_mouse_press_time_; |
227 | 266 |
228 // Position of last LEFT mouse press. Used for tracking double/triple click. | 267 // Position of last LEFT mouse press. Used for tracking double/triple click. |
229 gfx::Point last_mouse_press_location_; | 268 gfx::Point last_mouse_press_location_; |
230 | 269 |
231 // State variable to track double and triple clicks. | 270 // State variable to track double and triple clicks. |
232 ClickState click_state_; | 271 ClickState click_state_; |
233 | 272 |
234 // Context menu and its content list for the textfield. | 273 // Context menu and its content list for the textfield. |
235 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; | 274 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; |
236 scoped_ptr<Menu2> context_menu_menu_; | 275 scoped_ptr<Menu2> context_menu_menu_; |
237 | 276 |
238 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); | 277 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); |
239 }; | 278 }; |
240 | 279 |
241 } // namespace views | 280 } // namespace views |
242 | 281 |
243 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 282 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
OLD | NEW |