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

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

Issue 6155011: Implementing context menu for the new views textfield. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: resolved small merge conflict Created 9 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) 2010 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 "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.
30 // * IME/i18n support. 31 // * IME/i18n support.
31 // * X selection (only if we want to support). 32 // * X selection (only if we want to support).
32 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in 33 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in
33 // chromeos, so we may not need them) 34 // chromeos, so we may not need them)
34 // * Double click to select word, and triple click to select all. 35 // * Double click to select word, and triple click to select all.
35 // * Undo/Redo 36 // * Undo/Redo
36 class NativeTextfieldViews : public views::View, 37 class NativeTextfieldViews : public views::View,
37 public NativeTextfieldWrapper { 38 public views::ContextMenuController,
39 public NativeTextfieldWrapper,
40 public menus::SimpleMenuModel::Delegate {
38 public: 41 public:
39 explicit NativeTextfieldViews(Textfield* parent); 42 explicit NativeTextfieldViews(Textfield* parent);
40 ~NativeTextfieldViews(); 43 ~NativeTextfieldViews();
41 44
42 // views::View overrides: 45 // views::View overrides:
43 virtual bool OnMousePressed(const views::MouseEvent& e); 46 virtual bool OnMousePressed(const views::MouseEvent& e);
44 virtual bool OnMouseDragged(const views::MouseEvent& e); 47 virtual bool OnMouseDragged(const views::MouseEvent& e);
45 virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled); 48 virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled);
46 virtual bool OnKeyPressed(const views::KeyEvent& e); 49 virtual bool OnKeyPressed(const views::KeyEvent& e);
47 virtual bool OnKeyReleased(const views::KeyEvent& e); 50 virtual bool OnKeyReleased(const views::KeyEvent& e);
48 virtual void Paint(gfx::Canvas* canvas); 51 virtual void Paint(gfx::Canvas* canvas);
49 virtual void DidChangeBounds(const gfx::Rect& previous, 52 virtual void DidChangeBounds(const gfx::Rect& previous,
50 const gfx::Rect& current); 53 const gfx::Rect& current);
51 virtual void WillGainFocus(); 54 virtual void WillGainFocus();
52 virtual void DidGainFocus(); 55 virtual void DidGainFocus();
53 virtual void WillLoseFocus(); 56 virtual void WillLoseFocus();
54 57
58 // views::ContextMenuController overrides:
59 virtual void ShowContextMenu(View* source,
60 const gfx::Point& p,
61 bool is_mouse_gesture);
62
55 // NativeTextfieldWrapper overrides: 63 // NativeTextfieldWrapper overrides:
56 virtual string16 GetText() const; 64 virtual string16 GetText() const;
57 virtual void UpdateText(); 65 virtual void UpdateText();
58 virtual void AppendText(const string16& text); 66 virtual void AppendText(const string16& text);
59 virtual string16 GetSelectedText() const; 67 virtual string16 GetSelectedText() const;
60 virtual void SelectAll(); 68 virtual void SelectAll();
61 virtual void ClearSelection(); 69 virtual void ClearSelection();
62 virtual void UpdateBorder(); 70 virtual void UpdateBorder();
63 virtual void UpdateTextColor(); 71 virtual void UpdateTextColor();
64 virtual void UpdateBackgroundColor(); 72 virtual void UpdateBackgroundColor();
65 virtual void UpdateReadOnly(); 73 virtual void UpdateReadOnly();
66 virtual void UpdateFont(); 74 virtual void UpdateFont();
67 virtual void UpdateIsPassword(); 75 virtual void UpdateIsPassword();
68 virtual void UpdateEnabled(); 76 virtual void UpdateEnabled();
69 virtual gfx::Insets CalculateInsets(); 77 virtual gfx::Insets CalculateInsets();
70 virtual void UpdateHorizontalMargins(); 78 virtual void UpdateHorizontalMargins();
71 virtual void UpdateVerticalMargins(); 79 virtual void UpdateVerticalMargins();
72 virtual bool SetFocus(); 80 virtual bool SetFocus();
73 virtual View* GetView(); 81 virtual View* GetView();
74 virtual gfx::NativeView GetTestingHandle() const; 82 virtual gfx::NativeView GetTestingHandle() const;
75 virtual bool IsIMEComposing() const; 83 virtual bool IsIMEComposing() const;
76 virtual bool HandleKeyPressed(const views::KeyEvent& e); 84 virtual bool HandleKeyPressed(const views::KeyEvent& e);
77 virtual bool HandleKeyReleased(const views::KeyEvent& e); 85 virtual bool HandleKeyReleased(const views::KeyEvent& e);
78 virtual void HandleWillGainFocus(); 86 virtual void HandleWillGainFocus();
79 virtual void HandleDidGainFocus(); 87 virtual void HandleDidGainFocus();
80 virtual void HandleWillLoseFocus(); 88 virtual void HandleWillLoseFocus();
81 89
90 // menus::SimpleMenuModel::Delegate overrides
91 virtual bool IsCommandIdChecked(int command_id) const;
92 virtual bool IsCommandIdEnabled(int command_id) const;
93 virtual bool GetAcceleratorForCommandId(int command_id,
94 menus::Accelerator* accelerator);
95 virtual void ExecuteCommand(int command_id);
96
82 // class name of internal 97 // class name of internal
83 static const char kViewClassName[]; 98 static const char kViewClassName[];
84 99
85 // Returns true when 100 // Returns true when
86 // 1) built with GYP_DEFIENS="touchui=1" 101 // 1) built with GYP_DEFIENS="touchui=1"
87 // 2) enabled by SetEnableTextfieldViews(true) 102 // 2) enabled by SetEnableTextfieldViews(true)
88 // 3) enabled by the command line flag "--enable-textfield-view". 103 // 3) enabled by the command line flag "--enable-textfield-view".
89 static bool IsTextfieldViewsEnabled(); 104 static bool IsTextfieldViewsEnabled();
90 // Enable/Disable TextfieldViews implementation for Textfield. 105 // Enable/Disable TextfieldViews implementation for Textfield.
91 static void SetEnableTextfieldViews(bool enabled); 106 static void SetEnableTextfieldViews(bool enabled);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Handle the keyevent. 152 // Handle the keyevent.
138 bool HandleKeyEvent(const KeyEvent& key_event); 153 bool HandleKeyEvent(const KeyEvent& key_event);
139 154
140 // Utility function. Gets the character corresponding to a keyevent. 155 // Utility function. Gets the character corresponding to a keyevent.
141 // Returns 0 if the character is not printable. 156 // Returns 0 if the character is not printable.
142 char16 GetPrintableChar(const KeyEvent& key_event); 157 char16 GetPrintableChar(const KeyEvent& key_event);
143 158
144 // Find a cusor position for given |point| in this views coordinates. 159 // Find a cusor position for given |point| in this views coordinates.
145 size_t FindCursorPosition(const gfx::Point& point) const; 160 size_t FindCursorPosition(const gfx::Point& point) const;
146 161
162 // Utility function to inform the parent textfield (and its controller if any)
163 // that the text in the textfield has changed.
164 void PropagateTextChange();
165
166 // Utility function to create the context menu if one does not already exist.
167 void InitContextMenuIfRequired();
168
147 // The parent textfield, the owner of this object. 169 // The parent textfield, the owner of this object.
148 Textfield* textfield_; 170 Textfield* textfield_;
149 171
150 // The text model. 172 // The text model.
151 scoped_ptr<TextfieldViewsModel> model_; 173 scoped_ptr<TextfieldViewsModel> model_;
152 174
153 // The reference to the border class. The object is owned by View::border_. 175 // The reference to the border class. The object is owned by View::border_.
154 TextfieldBorder* text_border_; 176 TextfieldBorder* text_border_;
155 177
156 // The x offset for the text to be drawn, without insets; 178 // The x offset for the text to be drawn, without insets;
157 int text_offset_; 179 int text_offset_;
158 180
159 // Cursor's bounds in the textfield's coordinates. 181 // Cursor's bounds in the textfield's coordinates.
160 gfx::Rect cursor_bounds_; 182 gfx::Rect cursor_bounds_;
161 183
162 // True if the textfield is in insert mode. 184 // True if the textfield is in insert mode.
163 bool insert_; 185 bool insert_;
164 186
165 // The drawing state of cursor. True to draw. 187 // The drawing state of cursor. True to draw.
166 bool is_cursor_visible_; 188 bool is_cursor_visible_;
167 189
168 // A runnable method factory for callback to update the cursor. 190 // A runnable method factory for callback to update the cursor.
169 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; 191 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_;
170 192
193 // Context menu and its content list for the textfield.
194 scoped_ptr<menus::SimpleMenuModel> context_menu_contents_;
195 scoped_ptr<Menu2> context_menu_menu_;
196
171 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); 197 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews);
172 }; 198 };
173 199
174 } // namespace views 200 } // namespace views
175 201
176 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ 202 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_
OLDNEW
« no previous file with comments | « views/controls/menu/native_menu_x.cc ('k') | views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698