OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
oshima
2011/01/12 18:46:25
2011 (other files too)
varunjain
2011/01/12 19:59:05
These files were created in 2010... I think this i
tfarina
2011/01/12 20:01:22
No, you have to update the copyright here, when yo
oshima
2011/01/12 21:01:47
tfarina is correct. chrome updates the copyright w
varunjain
2011/01/12 21:28:11
Done.
| |
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 "app/menus/simple_menu_model.h" | |
9 #include "base/string16.h" | 10 #include "base/string16.h" |
10 #include "base/task.h" | 11 #include "base/task.h" |
11 #include "gfx/font.h" | 12 #include "gfx/font.h" |
12 #include "views/border.h" | 13 #include "views/border.h" |
13 #include "views/controls/textfield/native_textfield_wrapper.h" | 14 #include "views/controls/textfield/native_textfield_wrapper.h" |
14 #include "views/view.h" | 15 #include "views/view.h" |
15 | 16 |
16 namespace gfx { | 17 namespace gfx { |
17 class Canvas; | 18 class Canvas; |
18 } // namespace | 19 } // namespace |
19 | 20 |
20 namespace views { | 21 namespace views { |
21 | 22 |
22 class KeyEvent; | 23 class KeyEvent; |
24 class Menu2; | |
23 class TextfieldViewsModel; | 25 class TextfieldViewsModel; |
24 | 26 |
25 // A views/skia only implementation of NativeTextfieldWrapper. | 27 // A views/skia only implementation of NativeTextfieldWrapper. |
26 // No platform specific code is used. | 28 // No platform specific code is used. |
27 // Following features are not yet supported. | 29 // Following features are not yet supported. |
28 // * BIDI | 30 // * BIDI |
29 // * Context Menu. | 31 // * Context Menu. |
oshima
2011/01/12 18:46:25
remove this
varunjain
2011/01/12 19:59:05
Done.
| |
30 // * IME/i18n support. | 32 // * IME/i18n support. |
31 // * X selection (only if we want to support). | 33 // * X selection (only if we want to support). |
32 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in | 34 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in |
33 // chromeos, so we may not need them) | 35 // chromeos, so we may not need them) |
34 // * Double click to select word, and triple click to select all. | 36 // * Double click to select word, and triple click to select all. |
35 // * Undo/Redo | 37 // * Undo/Redo |
36 class NativeTextfieldViews : public views::View, | 38 class NativeTextfieldViews : public views::View, |
37 public NativeTextfieldWrapper { | 39 public views::ContextMenuController, |
40 public NativeTextfieldWrapper, | |
41 public menus::SimpleMenuModel::Delegate { | |
38 public: | 42 public: |
39 explicit NativeTextfieldViews(Textfield* parent); | 43 explicit NativeTextfieldViews(Textfield* parent); |
40 ~NativeTextfieldViews(); | 44 ~NativeTextfieldViews(); |
41 | 45 |
42 // views::View overrides: | 46 // views::View overrides: |
43 virtual bool OnMousePressed(const views::MouseEvent& e); | 47 virtual bool OnMousePressed(const views::MouseEvent& e); |
44 virtual bool OnMouseDragged(const views::MouseEvent& e); | 48 virtual bool OnMouseDragged(const views::MouseEvent& e); |
45 virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled); | 49 virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled); |
46 virtual bool OnKeyPressed(const views::KeyEvent& e); | 50 virtual bool OnKeyPressed(const views::KeyEvent& e); |
47 virtual bool OnKeyReleased(const views::KeyEvent& e); | 51 virtual bool OnKeyReleased(const views::KeyEvent& e); |
48 virtual void Paint(gfx::Canvas* canvas); | 52 virtual void Paint(gfx::Canvas* canvas); |
49 virtual void DidChangeBounds(const gfx::Rect& previous, | 53 virtual void DidChangeBounds(const gfx::Rect& previous, |
50 const gfx::Rect& current); | 54 const gfx::Rect& current); |
51 virtual void WillGainFocus(); | 55 virtual void WillGainFocus(); |
52 virtual void DidGainFocus(); | 56 virtual void DidGainFocus(); |
53 virtual void WillLoseFocus(); | 57 virtual void WillLoseFocus(); |
54 | 58 |
59 // views::ContextMenuController overrides: | |
60 virtual void ShowContextMenu(View* source, | |
61 const gfx::Point& p, | |
62 bool is_mouse_gesture); | |
63 | |
55 // NativeTextfieldWrapper overrides: | 64 // NativeTextfieldWrapper overrides: |
56 virtual string16 GetText() const; | 65 virtual string16 GetText() const; |
57 virtual void UpdateText(); | 66 virtual void UpdateText(); |
58 virtual void AppendText(const string16& text); | 67 virtual void AppendText(const string16& text); |
59 virtual string16 GetSelectedText() const; | 68 virtual string16 GetSelectedText() const; |
60 virtual void SelectAll(); | 69 virtual void SelectAll(); |
61 virtual void ClearSelection(); | 70 virtual void ClearSelection(); |
62 virtual void UpdateBorder(); | 71 virtual void UpdateBorder(); |
63 virtual void UpdateTextColor(); | 72 virtual void UpdateTextColor(); |
64 virtual void UpdateBackgroundColor(); | 73 virtual void UpdateBackgroundColor(); |
65 virtual void UpdateReadOnly(); | 74 virtual void UpdateReadOnly(); |
66 virtual void UpdateFont(); | 75 virtual void UpdateFont(); |
67 virtual void UpdateIsPassword(); | 76 virtual void UpdateIsPassword(); |
68 virtual void UpdateEnabled(); | 77 virtual void UpdateEnabled(); |
69 virtual gfx::Insets CalculateInsets(); | 78 virtual gfx::Insets CalculateInsets(); |
70 virtual void UpdateHorizontalMargins(); | 79 virtual void UpdateHorizontalMargins(); |
71 virtual void UpdateVerticalMargins(); | 80 virtual void UpdateVerticalMargins(); |
72 virtual bool SetFocus(); | 81 virtual bool SetFocus(); |
73 virtual View* GetView(); | 82 virtual View* GetView(); |
74 virtual gfx::NativeView GetTestingHandle() const; | 83 virtual gfx::NativeView GetTestingHandle() const; |
75 virtual bool IsIMEComposing() const; | 84 virtual bool IsIMEComposing() const; |
76 virtual bool HandleKeyPressed(const views::KeyEvent& e); | 85 virtual bool HandleKeyPressed(const views::KeyEvent& e); |
77 virtual bool HandleKeyReleased(const views::KeyEvent& e); | 86 virtual bool HandleKeyReleased(const views::KeyEvent& e); |
78 virtual void HandleWillGainFocus(); | 87 virtual void HandleWillGainFocus(); |
79 virtual void HandleDidGainFocus(); | 88 virtual void HandleDidGainFocus(); |
80 virtual void HandleWillLoseFocus(); | 89 virtual void HandleWillLoseFocus(); |
81 | 90 |
91 // menus::SimpleMenuModel::Delegate overrides | |
92 virtual bool IsCommandIdChecked(int command_id) const; | |
93 virtual bool IsCommandIdEnabled(int command_id) const; | |
94 virtual bool GetAcceleratorForCommandId(int command_id, | |
95 menus::Accelerator* accelerator); | |
96 virtual void ExecuteCommand(int command_id); | |
97 | |
82 // class name of internal | 98 // class name of internal |
83 static const char kViewClassName[]; | 99 static const char kViewClassName[]; |
84 | 100 |
85 // Returns true when | 101 // Returns true when |
86 // 1) built with GYP_DEFIENS="touchui=1" | 102 // 1) built with GYP_DEFIENS="touchui=1" |
87 // 2) enabled by SetEnableTextfieldViews(true) | 103 // 2) enabled by SetEnableTextfieldViews(true) |
88 // 3) enabled by the command line flag "--enable-textfield-view". | 104 // 3) enabled by the command line flag "--enable-textfield-view". |
89 static bool IsTextfieldViewsEnabled(); | 105 static bool IsTextfieldViewsEnabled(); |
90 // Enable/Disable TextfieldViews implementation for Textfield. | 106 // Enable/Disable TextfieldViews implementation for Textfield. |
91 static void SetEnableTextfieldViews(bool enabled); | 107 static void SetEnableTextfieldViews(bool enabled); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 // Handle the keyevent. | 153 // Handle the keyevent. |
138 bool HandleKeyEvent(const KeyEvent& key_event); | 154 bool HandleKeyEvent(const KeyEvent& key_event); |
139 | 155 |
140 // Utility function. Gets the character corresponding to a keyevent. | 156 // Utility function. Gets the character corresponding to a keyevent. |
141 // Returns 0 if the character is not printable. | 157 // Returns 0 if the character is not printable. |
142 char16 GetPrintableChar(const KeyEvent& key_event); | 158 char16 GetPrintableChar(const KeyEvent& key_event); |
143 | 159 |
144 // Find a cusor position for given |point| in this views coordinates. | 160 // Find a cusor position for given |point| in this views coordinates. |
145 size_t FindCursorPosition(const gfx::Point& point) const; | 161 size_t FindCursorPosition(const gfx::Point& point) const; |
146 | 162 |
163 // Utility function to inform the parent textfield (and its controller if any) | |
164 // that the text in the textfield has changed. | |
165 void PropagateTextChange(); | |
166 | |
167 // Utility function to create the context menu. | |
168 void CreateContextMenu(); | |
oshima
2011/01/12 18:46:25
CreateXXX is typically used to return instance, so
varunjain
2011/01/12 19:59:05
Changed to Init
| |
169 | |
147 // The parent textfield, the owner of this object. | 170 // The parent textfield, the owner of this object. |
148 Textfield* textfield_; | 171 Textfield* textfield_; |
149 | 172 |
150 // The text model. | 173 // The text model. |
151 scoped_ptr<TextfieldViewsModel> model_; | 174 scoped_ptr<TextfieldViewsModel> model_; |
152 | 175 |
153 // The reference to the border class. The object is owned by View::border_. | 176 // The reference to the border class. The object is owned by View::border_. |
154 TextfieldBorder* text_border_; | 177 TextfieldBorder* text_border_; |
155 | 178 |
156 // The x offset for the text to be drawn, without insets; | 179 // The x offset for the text to be drawn, without insets; |
157 int text_offset_; | 180 int text_offset_; |
158 | 181 |
159 // Cursor's bounds in the textfield's coordinates. | 182 // Cursor's bounds in the textfield's coordinates. |
160 gfx::Rect cursor_bounds_; | 183 gfx::Rect cursor_bounds_; |
161 | 184 |
162 // True if the textfield is in insert mode. | 185 // True if the textfield is in insert mode. |
163 bool insert_; | 186 bool insert_; |
164 | 187 |
165 // The drawing state of cursor. True to draw. | 188 // The drawing state of cursor. True to draw. |
166 bool is_cursor_visible_; | 189 bool is_cursor_visible_; |
167 | 190 |
168 // A runnable method factory for callback to update the cursor. | 191 // A runnable method factory for callback to update the cursor. |
169 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; | 192 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; |
170 | 193 |
194 // Context menu and its content list for the textfield. | |
195 scoped_ptr<menus::SimpleMenuModel> context_menu_contents_; | |
196 scoped_ptr<Menu2> context_menu_menu_; | |
197 | |
171 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); | 198 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); |
172 }; | 199 }; |
173 | 200 |
174 } // namespace views | 201 } // namespace views |
175 | 202 |
176 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 203 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
OLD | NEW |