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

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

Issue 113940: Make Textfield more portable.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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
« no previous file with comments | « views/controls/message_box_view.cc ('k') | views/controls/textfield/native_textfield_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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_WIN_H_
6 #define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_
7
8 #include <atlbase.h>
9 #include <atlapp.h>
10 #include <atlcrack.h>
11 #include <atlctrls.h>
12 #include <atlmisc.h>
13 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl
14 #include <vsstyle.h>
15
16 #include "views/controls/textfield/native_textfield_wrapper.h"
17
18 namespace views {
19
20 class HWNDView;
21 class Textfield;
22
23 static const int kDefaultEditStyle = WS_CHILD | WS_VISIBLE;
24
25 // TODO(beng): make a subclass of NativeControlWin instead.
26 class NativeTextfieldWin
27 : public CWindowImpl<NativeTextfieldWin, CRichEditCtrl,
28 CWinTraits<kDefaultEditStyle> >,
29 public CRichEditCommands<NativeTextfieldWin>,
30 public NativeTextfieldWrapper,
31 public Menu::Delegate {
32 public:
33 DECLARE_WND_CLASS(L"ViewsTextfieldEdit");
34
35 explicit NativeTextfieldWin(Textfield* parent);
36 ~NativeTextfieldWin();
37
38 // Overridden from NativeTextfieldWrapper:
39 virtual std::wstring GetText() const;
40 virtual void UpdateText();
41 virtual void AppendText(const std::wstring& text);
42 virtual std::wstring GetSelectedText() const;
43 virtual void SelectAll();
44 virtual void ClearSelection();
45 virtual void UpdateBorder();
46 virtual void UpdateBackgroundColor();
47 virtual void UpdateReadOnly();
48 virtual void UpdateFont();
49 virtual void UpdateEnabled();
50 virtual void SetHorizontalMargins(int left, int right);
51 virtual void SetFocus();
52 virtual View* GetView();
53 virtual gfx::NativeView GetTestingHandle() const;
54
55 // CWindowImpl
56 BEGIN_MSG_MAP(Edit)
57 MSG_WM_CHAR(OnChar)
58 MSG_WM_CONTEXTMENU(OnContextMenu)
59 MSG_WM_COPY(OnCopy)
60 MSG_WM_CUT(OnCut)
61 MESSAGE_HANDLER_EX(WM_IME_CHAR, OnImeChar)
62 MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeStartComposition)
63 MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeComposition)
64 MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeEndComposition)
65 MSG_WM_KEYDOWN(OnKeyDown)
66 MSG_WM_LBUTTONDBLCLK(OnLButtonDblClk)
67 MSG_WM_LBUTTONDOWN(OnLButtonDown)
68 MSG_WM_LBUTTONUP(OnLButtonUp)
69 MSG_WM_MBUTTONDOWN(OnNonLButtonDown)
70 MSG_WM_MOUSEMOVE(OnMouseMove)
71 MSG_WM_MOUSELEAVE(OnMouseLeave)
72 MESSAGE_HANDLER_EX(WM_MOUSEWHEEL, OnMouseWheel)
73 MSG_WM_NCCALCSIZE(OnNCCalcSize)
74 MSG_WM_NCPAINT(OnNCPaint)
75 MSG_WM_RBUTTONDOWN(OnNonLButtonDown)
76 MSG_WM_PASTE(OnPaste)
77 MSG_WM_SYSCHAR(OnSysChar) // WM_SYSxxx == WM_xxx with ALT down
78 MSG_WM_SYSKEYDOWN(OnKeyDown)
79 END_MSG_MAP()
80
81 // Menu::Delegate
82 virtual bool IsCommandEnabled(int id) const;
83 virtual void ExecuteCommand(int id);
84
85 private:
86 // This object freezes repainting of the edit until the object is destroyed.
87 // Some methods of the CRichEditCtrl draw synchronously to the screen. If we
88 // don't freeze, the user will see a rapid series of calls to these as
89 // flickers.
90 //
91 // Freezing the control while it is already frozen is permitted; the control
92 // will unfreeze once both freezes are released (the freezes stack).
93 class ScopedFreeze {
94 public:
95 ScopedFreeze(NativeTextfieldWin* edit, ITextDocument* text_object_model);
96 ~ScopedFreeze();
97
98 private:
99 NativeTextfieldWin* const edit_;
100 ITextDocument* const text_object_model_;
101
102 DISALLOW_COPY_AND_ASSIGN(ScopedFreeze);
103 };
104
105 // message handlers
106 void OnChar(TCHAR key, UINT repeat_count, UINT flags);
107 void OnContextMenu(HWND window, const CPoint& point);
108 void OnCopy();
109 void OnCut();
110 LRESULT OnImeChar(UINT message, WPARAM wparam, LPARAM lparam);
111 LRESULT OnImeStartComposition(UINT message, WPARAM wparam, LPARAM lparam);
112 LRESULT OnImeComposition(UINT message, WPARAM wparam, LPARAM lparam);
113 LRESULT OnImeEndComposition(UINT message, WPARAM wparam, LPARAM lparam);
114 void OnKeyDown(TCHAR key, UINT repeat_count, UINT flags);
115 void OnLButtonDblClk(UINT keys, const CPoint& point);
116 void OnLButtonDown(UINT keys, const CPoint& point);
117 void OnLButtonUp(UINT keys, const CPoint& point);
118 void OnMouseLeave();
119 LRESULT OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param);
120 void OnMouseMove(UINT keys, const CPoint& point);
121 int OnNCCalcSize(BOOL w_param, LPARAM l_param);
122 void OnNCPaint(HRGN region);
123 void OnNonLButtonDown(UINT keys, const CPoint& point);
124 void OnPaste();
125 void OnSysChar(TCHAR ch, UINT repeat_count, UINT flags);
126
127 // Helper function for OnChar() and OnKeyDown() that handles keystrokes that
128 // could change the text in the edit.
129 void HandleKeystroke(UINT message, TCHAR key, UINT repeat_count, UINT flags);
130
131 // Every piece of code that can change the edit should call these functions
132 // before and after the change. These functions determine if anything
133 // meaningful changed, and do any necessary updating and notification.
134 void OnBeforePossibleChange();
135 void OnAfterPossibleChange();
136
137 // Given an X coordinate in client coordinates, returns that coordinate
138 // clipped to be within the horizontal bounds of the visible text.
139 //
140 // This is used in our mouse handlers to work around quirky behaviors of the
141 // underlying CRichEditCtrl like not supporting triple-click when the user
142 // doesn't click on the text itself.
143 //
144 // |is_triple_click| should be true iff this is the third click of a triple
145 // click. Sadly, we need to clip slightly differently in this case.
146 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const;
147
148 // Sets whether the mouse is in the edit. As necessary this redraws the
149 // edit.
150 void SetContainsMouse(bool contains_mouse);
151
152 // Getter for the text_object_model_, used by the ScopedFreeze class. Note
153 // that the pointer returned here is only valid as long as the Edit is still
154 // alive.
155 ITextDocument* GetTextObjectModel() const;
156
157 // The Textfield this object is bound to.
158 Textfield* textfield_;
159
160 // We need to know if the user triple-clicks, so track double click points
161 // and times so we can see if subsequent clicks are actually triple clicks.
162 bool tracking_double_click_;
163 CPoint double_click_point_;
164 DWORD double_click_time_;
165
166 // Used to discard unnecessary WM_MOUSEMOVE events after the first such
167 // unnecessary event. See detailed comments in OnMouseMove().
168 bool can_discard_mousemove_;
169
170 // The text of this control before a possible change.
171 std::wstring text_before_change_;
172
173 // If true, the mouse is over the edit.
174 bool contains_mouse_;
175
176 static bool did_load_library_;
177
178 // The context menu for the edit.
179 scoped_ptr<Menu> context_menu_;
180
181 // Border insets.
182 gfx::Insets content_insets_;
183
184 // This interface is useful for accessing the CRichEditCtrl at a low level.
185 mutable CComQIPtr<ITextDocument> text_object_model_;
186
187 // The position and the length of the ongoing composition string.
188 // These values are used for removing a composition string from a search
189 // text to emulate Firefox.
190 bool ime_discard_composition_;
191 int ime_composition_start_;
192 int ime_composition_length_;
193
194 // TODO(beng): remove this when we are a subclass of NativeControlWin.
195 HWNDView* container_view_;
196
197 COLORREF bg_color_;
198
199 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldWin);
200 };
201
202 };
203
204 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_
OLDNEW
« no previous file with comments | « views/controls/message_box_view.cc ('k') | views/controls/textfield/native_textfield_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698