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

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

Issue 6675005: Integrate the new input method API for Views into Chromium. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix trybot failures. Created 9 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 | Annotate | Revision Log
OLDNEW
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
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
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
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. 234 // Checks if a char is ok to be inserted into the textfield.
200 static bool ShouldInsertChar(char16 ch, int flags); 235 static bool ShouldInsertChar(char16 ch, int flags);
201 236
202 // The parent textfield, the owner of this object. 237 // The parent textfield, the owner of this object.
(...skipping 10 matching lines...) Expand all
213 248
214 // Cursor's bounds in the textfield's coordinates. 249 // Cursor's bounds in the textfield's coordinates.
215 gfx::Rect cursor_bounds_; 250 gfx::Rect cursor_bounds_;
216 251
217 // True if the textfield is in insert mode. 252 // True if the textfield is in insert mode.
218 bool insert_; 253 bool insert_;
219 254
220 // The drawing state of cursor. True to draw. 255 // The drawing state of cursor. True to draw.
221 bool is_cursor_visible_; 256 bool is_cursor_visible_;
222 257
258 // True if InputMethod::CancelComposition() should not be called.
259 bool skip_input_method_cancel_composition_;
260
223 // A runnable method factory for callback to update the cursor. 261 // A runnable method factory for callback to update the cursor.
224 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; 262 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_;
225 263
226 // 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.
227 base::Time last_mouse_press_time_; 265 base::Time last_mouse_press_time_;
228 266
229 // 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.
230 gfx::Point last_mouse_press_location_; 268 gfx::Point last_mouse_press_location_;
231 269
232 // State variable to track double and triple clicks. 270 // State variable to track double and triple clicks.
233 ClickState click_state_; 271 ClickState click_state_;
234 272
235 // Context menu and its content list for the textfield. 273 // Context menu and its content list for the textfield.
236 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; 274 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_;
237 scoped_ptr<Menu2> context_menu_menu_; 275 scoped_ptr<Menu2> context_menu_menu_;
238 276
239 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); 277 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews);
240 }; 278 };
241 279
242 } // namespace views 280 } // namespace views
243 281
244 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ 282 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698