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

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

Issue 11305002: Support TSF related event handling on NativeTextField (Closed) Base URL: http://git.chromium.org/chromium/src.git@findbar_fix
Patch Set: Reorder functions Created 8 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ 5 #ifndef UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_
6 #define UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ 6 #define UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_
7 7
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <atlapp.h> 9 #include <atlapp.h>
10 #include <atlcrack.h> 10 #include <atlcrack.h>
11 #include <atlctrls.h> 11 #include <atlctrls.h>
12 #include <atlmisc.h> 12 #include <atlmisc.h>
13 #include <oleacc.h> 13 #include <oleacc.h>
14 #include <peninputpanel.h> 14 #include <peninputpanel.h>
15 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl 15 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl
16 #include <vsstyle.h> 16 #include <vsstyle.h>
17 17
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/string16.h" 19 #include "base/string16.h"
20 #include "base/win/scoped_comptr.h" 20 #include "base/win/scoped_comptr.h"
21 #include "ui/base/models/simple_menu_model.h" 21 #include "ui/base/models/simple_menu_model.h"
22 #include "ui/base/ime/win/tsf_event_router.h"
22 #include "ui/gfx/insets.h" 23 #include "ui/gfx/insets.h"
23 #include "ui/base/win/extra_sdk_defines.h" 24 #include "ui/base/win/extra_sdk_defines.h"
24 #include "ui/views/controls/textfield/native_textfield_wrapper.h" 25 #include "ui/views/controls/textfield/native_textfield_wrapper.h"
25 26
26 namespace gfx { 27 namespace gfx {
27 class SelectionModel; 28 class SelectionModel;
28 } 29 }
29 30
30 namespace views { 31 namespace views {
31 32
32 class MenuRunner; 33 class MenuRunner;
33 class NativeViewHost; 34 class NativeViewHost;
34 class Textfield; 35 class Textfield;
35 36
36 static const int kDefaultEditStyle = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | 37 static const int kDefaultEditStyle = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN |
37 WS_CLIPSIBLINGS; 38 WS_CLIPSIBLINGS;
38 39
39 // TODO(beng): make a subclass of NativeControlWin instead. 40 // TODO(beng): make a subclass of NativeControlWin instead.
40 class NativeTextfieldWin 41 class NativeTextfieldWin
41 : public CWindowImpl<NativeTextfieldWin, CRichEditCtrl, 42 : public CWindowImpl<NativeTextfieldWin, CRichEditCtrl,
42 CWinTraits<kDefaultEditStyle> >, 43 CWinTraits<kDefaultEditStyle> >,
43 public CRichEditCommands<NativeTextfieldWin>, 44 public CRichEditCommands<NativeTextfieldWin>,
44 public NativeTextfieldWrapper, 45 public NativeTextfieldWrapper,
45 public ui::SimpleMenuModel::Delegate { 46 public ui::SimpleMenuModel::Delegate,
47 public ui::TsfEventRouterObserver {
46 public: 48 public:
47 DECLARE_WND_SUPERCLASS(L"ViewsTextfieldEdit", MSFTEDIT_CLASS); 49 DECLARE_WND_SUPERCLASS(L"ViewsTextfieldEdit", MSFTEDIT_CLASS);
48 50
49 explicit NativeTextfieldWin(Textfield* parent); 51 explicit NativeTextfieldWin(Textfield* parent);
50 ~NativeTextfieldWin(); 52 ~NativeTextfieldWin();
51 53
52 // Returns true if the current point is close enough to the origin point in 54 // Returns true if the current point is close enough to the origin point in
53 // space and time that it would be considered a double click. 55 // space and time that it would be considered a double click.
54 VIEWS_EXPORT static bool IsDoubleClick(const POINT& origin, 56 VIEWS_EXPORT static bool IsDoubleClick(const POINT& origin,
55 const POINT& current, 57 const POINT& current,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 virtual int GetFontHeight() OVERRIDE; 105 virtual int GetFontHeight() OVERRIDE;
104 106
105 // Overridden from ui::SimpleMenuModel::Delegate: 107 // Overridden from ui::SimpleMenuModel::Delegate:
106 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 108 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
107 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 109 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
108 virtual bool GetAcceleratorForCommandId( 110 virtual bool GetAcceleratorForCommandId(
109 int command_id, 111 int command_id,
110 ui::Accelerator* accelerator) OVERRIDE; 112 ui::Accelerator* accelerator) OVERRIDE;
111 virtual void ExecuteCommand(int command_id) OVERRIDE; 113 virtual void ExecuteCommand(int command_id) OVERRIDE;
112 114
115 // Overridden from ui::TsfEventRouterObserver:
116 virtual void OnTextUpdated(const ui::Range& composition_range) OVERRIDE;
117 virtual void OnCandidateWindowCountChanged(size_t window_count) OVERRIDE;
118 virtual void OnTsfStartComposition() OVERRIDE;
119 virtual void OnTsfEndComposition() OVERRIDE;
120
113 // Update accessibility information. 121 // Update accessibility information.
114 void InitializeAccessibilityInfo(); 122 void InitializeAccessibilityInfo();
115 void UpdateAccessibleState(uint32 state_flag, bool set_value); 123 void UpdateAccessibleState(uint32 state_flag, bool set_value);
116 void UpdateAccessibleValue(const string16& value); 124 void UpdateAccessibleValue(const string16& value);
117 125
118 // CWindowImpl 126 // CWindowImpl
119 BEGIN_MSG_MAP(Edit) 127 BEGIN_MSG_MAP(Edit)
120 MSG_WM_CHAR(OnChar) 128 MSG_WM_CHAR(OnChar)
121 MSG_WM_CONTEXTMENU(OnContextMenu) 129 MSG_WM_CONTEXTMENU(OnContextMenu)
122 MSG_WM_COPY(OnCopy) 130 MSG_WM_COPY(OnCopy)
(...skipping 12 matching lines...) Expand all
135 MSG_WM_LBUTTONUP(OnLButtonUp) 143 MSG_WM_LBUTTONUP(OnLButtonUp)
136 MSG_WM_MBUTTONDOWN(OnNonLButtonDown) 144 MSG_WM_MBUTTONDOWN(OnNonLButtonDown)
137 MSG_WM_MOUSEMOVE(OnMouseMove) 145 MSG_WM_MOUSEMOVE(OnMouseMove)
138 MSG_WM_MOUSELEAVE(OnMouseLeave) 146 MSG_WM_MOUSELEAVE(OnMouseLeave)
139 MESSAGE_HANDLER_EX(WM_MOUSEWHEEL, OnMouseWheel) 147 MESSAGE_HANDLER_EX(WM_MOUSEWHEEL, OnMouseWheel)
140 MSG_WM_NCCALCSIZE(OnNCCalcSize) 148 MSG_WM_NCCALCSIZE(OnNCCalcSize)
141 MSG_WM_NCPAINT(OnNCPaint) 149 MSG_WM_NCPAINT(OnNCPaint)
142 MSG_WM_RBUTTONDOWN(OnNonLButtonDown) 150 MSG_WM_RBUTTONDOWN(OnNonLButtonDown)
143 MSG_WM_PASTE(OnPaste) 151 MSG_WM_PASTE(OnPaste)
144 MSG_WM_SETFOCUS(OnSetFocus) 152 MSG_WM_SETFOCUS(OnSetFocus)
153 MSG_WM_KILLFOCUS(OnKillFocus)
145 MSG_WM_SYSCHAR(OnSysChar) // WM_SYSxxx == WM_xxx with ALT down 154 MSG_WM_SYSCHAR(OnSysChar) // WM_SYSxxx == WM_xxx with ALT down
146 MSG_WM_SYSKEYDOWN(OnKeyDown) 155 MSG_WM_SYSKEYDOWN(OnKeyDown)
147 END_MSG_MAP() 156 END_MSG_MAP()
148 157
149 private: 158 private:
150 // This object freezes repainting of the edit until the object is destroyed. 159 // This object freezes repainting of the edit until the object is destroyed.
151 // Some methods of the CRichEditCtrl draw synchronously to the screen. If we 160 // Some methods of the CRichEditCtrl draw synchronously to the screen. If we
152 // don't freeze, the user will see a rapid series of calls to these as 161 // don't freeze, the user will see a rapid series of calls to these as
153 // flickers. 162 // flickers.
154 // 163 //
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 void OnLButtonDown(UINT keys, const CPoint& point); 208 void OnLButtonDown(UINT keys, const CPoint& point);
200 void OnLButtonUp(UINT keys, const CPoint& point); 209 void OnLButtonUp(UINT keys, const CPoint& point);
201 void OnMouseLeave(); 210 void OnMouseLeave();
202 LRESULT OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param); 211 LRESULT OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param);
203 void OnMouseMove(UINT keys, const CPoint& point); 212 void OnMouseMove(UINT keys, const CPoint& point);
204 int OnNCCalcSize(BOOL w_param, LPARAM l_param); 213 int OnNCCalcSize(BOOL w_param, LPARAM l_param);
205 void OnNCPaint(HRGN region); 214 void OnNCPaint(HRGN region);
206 void OnNonLButtonDown(UINT keys, const CPoint& point); 215 void OnNonLButtonDown(UINT keys, const CPoint& point);
207 void OnPaste(); 216 void OnPaste();
208 void OnSetFocus(HWND hwnd); 217 void OnSetFocus(HWND hwnd);
218 void OnKillFocus(HWND hwnd);
209 void OnSysChar(TCHAR ch, UINT repeat_count, UINT flags); 219 void OnSysChar(TCHAR ch, UINT repeat_count, UINT flags);
210 220
211 // Helper function for OnChar() and OnKeyDown() that handles keystrokes that 221 // Helper function for OnChar() and OnKeyDown() that handles keystrokes that
212 // could change the text in the edit. 222 // could change the text in the edit.
213 // Note: This function assumes GetCurrentMessage() returns a MSG with 223 // Note: This function assumes GetCurrentMessage() returns a MSG with
214 // msg > WM_KEYFIRST and < WM_KEYLAST. 224 // msg > WM_KEYFIRST and < WM_KEYLAST.
215 void HandleKeystroke(); 225 void HandleKeystroke();
216 226
217 // Every piece of code that can change the edit should call these functions 227 // Every piece of code that can change the edit should call these functions
218 // before and after the change. These functions determine if anything 228 // before and after the change. These functions determine if anything
(...skipping 19 matching lines...) Expand all
238 // doesn't click on the text itself. 248 // doesn't click on the text itself.
239 // 249 //
240 // |is_triple_click| should be true iff this is the third click of a triple 250 // |is_triple_click| should be true iff this is the third click of a triple
241 // click. Sadly, we need to clip slightly differently in this case. 251 // click. Sadly, we need to clip slightly differently in this case.
242 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const; 252 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const;
243 253
244 // Sets whether the mouse is in the edit. As necessary this redraws the 254 // Sets whether the mouse is in the edit. As necessary this redraws the
245 // edit. 255 // edit.
246 void SetContainsMouse(bool contains_mouse); 256 void SetContainsMouse(bool contains_mouse);
247 257
258 // Handles composition related works on both IMM32 and TSF implementation.
259 void OnImeStartCompositionInternal();
260 void OnImeEndCompositionInternal();
261
248 // Getter for the text_object_model_, used by the ScopedFreeze class. Note 262 // Getter for the text_object_model_, used by the ScopedFreeze class. Note
249 // that the pointer returned here is only valid as long as the Edit is still 263 // that the pointer returned here is only valid as long as the Edit is still
250 // alive. 264 // alive.
251 ITextDocument* GetTextObjectModel() const; 265 ITextDocument* GetTextObjectModel() const;
252 266
253 // Generates the contents of the context menu. 267 // Generates the contents of the context menu.
254 void BuildContextMenu(); 268 void BuildContextMenu();
255 269
256 static HMODULE loaded_libarary_module_; 270 static HMODULE loaded_libarary_module_;
257 271
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 int ime_composition_length_; 309 int ime_composition_length_;
296 310
297 // TODO(beng): remove this when we are a subclass of NativeControlWin. 311 // TODO(beng): remove this when we are a subclass of NativeControlWin.
298 NativeViewHost* container_view_; 312 NativeViewHost* container_view_;
299 313
300 COLORREF bg_color_; 314 COLORREF bg_color_;
301 315
302 // The accessibility state of this object. 316 // The accessibility state of this object.
303 int accessibility_state_; 317 int accessibility_state_;
304 318
319 scoped_ptr<ui::TsfEventRouter> tsf_event_router_;
320
305 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldWin); 321 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldWin);
306 }; 322 };
307 323
308 } // namespace views 324 } // namespace views
309 325
310 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ 326 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698