OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEW_H_ | |
6 #define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include "base/string16.h" | |
10 #include "base/task.h" | |
11 #include "gfx/font.h" | |
12 #include "views/border.h" | |
13 #include "views/controls/textfield/native_textfield_wrapper.h" | |
14 #include "views/view.h" | |
15 | |
16 namespace gfx { | |
17 class Canvas; | |
18 } // namespace | |
19 | |
20 namespace views { | |
21 | |
22 class KeyEvent; | |
23 class TextfieldViewModel; | |
24 | |
25 // A non-native, skia based implementation of NativeTextfieldWrapper. | |
26 // Following features are not yet supported. | |
27 // * BIDI | |
28 // * Clipboard (Cut & Paste). | |
29 // * Context Menu. | |
30 // * IME support. | |
31 // * X selection (only if we want to support). | |
32 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in | |
33 // chromeos, so we may not need them) | |
34 class NativeTextfieldView : public views::View, | |
sky
2010/12/15 20:31:27
This name is confusing given the class description
oshima
2010/12/16 01:15:19
I've been going back and forth, and this name soun
| |
35 public NativeTextfieldWrapper { | |
36 public: | |
37 explicit NativeTextfieldView(Textfield* parent); | |
38 ~NativeTextfieldView(); | |
39 | |
40 // views::View overrides: | |
41 virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e); | |
42 virtual bool OnMousePressed(const views::MouseEvent& e); | |
43 virtual bool OnMouseDragged(const views::MouseEvent& e); | |
44 virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled); | |
45 virtual bool OnKeyPressed(const views::KeyEvent& e); | |
46 virtual bool OnKeyReleased(const views::KeyEvent& e); | |
47 virtual void Paint(gfx::Canvas* canvas); | |
48 virtual void WillGainFocus(); | |
49 virtual void DidGainFocus(); | |
50 virtual void WillLoseFocus(); | |
51 virtual void DidChangeBounds(const gfx::Rect& previous, | |
52 const gfx::Rect& current); | |
53 | |
54 // NativeTextfieldWrapper overrides: | |
55 virtual string16 GetText() const; | |
56 virtual void UpdateText(); | |
57 virtual void AppendText(const string16& text); | |
58 virtual string16 GetSelectedText() const; | |
59 virtual void SelectAll(); | |
60 virtual void ClearSelection(); | |
61 virtual void UpdateBorder(); | |
62 virtual void UpdateTextColor(); | |
63 virtual void UpdateBackgroundColor(); | |
64 virtual void UpdateReadOnly(); | |
65 virtual void UpdateFont(); | |
66 virtual void UpdateIsPassword(); | |
67 virtual void UpdateEnabled(); | |
68 virtual bool IsPassword(); | |
69 virtual gfx::Insets CalculateInsets(); | |
70 virtual void UpdateHorizontalMargins(); | |
71 virtual void UpdateVerticalMargins(); | |
72 virtual void SetFocus(); | |
73 virtual View* GetView(); | |
74 virtual gfx::NativeView GetTestingHandle() const; | |
75 virtual bool IsIMEComposing() const; | |
76 | |
77 // class name of internal | |
78 static const char kViewClassName[]; | |
79 | |
80 static bool IsTextfieldViewEnabled(); | |
81 static void SetEnableTextfieldView(bool enabled); | |
82 | |
83 private: | |
84 friend class NativeTextfieldViewTest; | |
85 | |
86 // A Border class to draw focus border for the text field. | |
87 class TextfieldBorder : public Border { | |
sky
2010/12/15 20:31:27
nit: put this in the .cc?
| |
88 public: | |
89 TextfieldBorder(); | |
90 | |
91 // Border implementation. | |
92 virtual void Paint(const View& view, gfx::Canvas* canvas) const; | |
93 virtual void GetInsets(gfx::Insets* insets) const; | |
94 | |
95 // Sets the insets of the border. | |
96 void SetInsets(int top, int left, int bottom, int right); | |
97 | |
98 // Sets the focus state. | |
99 void set_has_focus(bool has_focus) { | |
100 has_focus_ = has_focus; | |
101 } | |
102 | |
103 private: | |
104 bool has_focus_; | |
105 gfx::Insets insets_; | |
106 | |
107 DISALLOW_COPY_AND_ASSIGN(TextfieldBorder); | |
108 }; | |
109 | |
110 // Returns the Textfield's font. | |
111 gfx::Font GetFont() const; | |
sky
2010/12/15 20:31:27
const gfx::Font&
oshima
2010/12/16 01:15:19
Done. It was cut&paste from Textfield. Updated Tex
| |
112 | |
113 // Returns the Textfield's text color. | |
114 SkColor GetTextColor() const; | |
115 | |
116 // A callback function to periodically update the cursor state. | |
117 void UpdateCursor(); | |
118 | |
119 // Repaint the cursor. | |
120 void RepaintCursor(); | |
121 | |
122 // Update the cursor_bounds and text_offset. | |
123 void UpdateCursorBoundsAndTextOffset(); | |
124 | |
125 void PaintTextAndCursor(gfx::Canvas* canvas); | |
126 | |
127 // Handle the keyevent. | |
128 bool HandleKeyEvent(const KeyEvent& key_event); | |
129 | |
130 // Utility function. Gets the character corresponding to a keyevent/ | |
131 // key_code. Returns 0 if the character is not printable. | |
132 char16 GetPrintableChar(const KeyEvent& key_event); | |
133 char16 GetPrintableChar(app::KeyboardCode key_code, bool shift); | |
134 | |
135 // Find a cusor position for given |point| in this views coordinates. | |
136 size_t FindCursorPosition(const gfx::Point& point) const; | |
137 | |
138 // The parent textfield, the owner of this object. | |
139 Textfield* textfield_; | |
140 | |
141 // The text model. | |
142 scoped_ptr<TextfieldViewModel> model_; | |
143 | |
144 // The reference to the border class. The object is owned by View::border_. | |
145 TextfieldBorder* text_border_; | |
146 | |
147 // The x offset for the text to be drawn, without insets; | |
148 int text_offset_; | |
149 | |
150 // Cursor's bounds in the textfield's coordinates. | |
151 gfx::Rect cursor_bounds_; | |
152 | |
153 // True if the textfield is in insert mode. | |
154 bool insert_; | |
155 | |
156 // The drawing state of cursor. True to draw. | |
sky
2010/12/15 20:31:27
How about naming this is_cursor_visible_?
oshima
2010/12/16 01:15:19
Done.
| |
157 bool cursor_; | |
158 | |
159 // A runnable method factory for callback to update the cursor. | |
160 ScopedRunnableMethodFactory<NativeTextfieldView> cursor_timer_; | |
161 | |
162 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldView); | |
163 }; | |
164 | |
165 } // namespace views | |
166 | |
167 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEW_H_ | |
OLD | NEW |