OLD | NEW |
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 Loading... |
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 OnTsfStartComposition() OVERRIDE; |
| 118 virtual void OnTsfEndComposition() OVERRIDE; |
| 119 |
113 // Update accessibility information. | 120 // Update accessibility information. |
114 void InitializeAccessibilityInfo(); | 121 void InitializeAccessibilityInfo(); |
115 void UpdateAccessibleState(uint32 state_flag, bool set_value); | 122 void UpdateAccessibleState(uint32 state_flag, bool set_value); |
116 void UpdateAccessibleValue(const string16& value); | 123 void UpdateAccessibleValue(const string16& value); |
117 | 124 |
118 // CWindowImpl | 125 // CWindowImpl |
119 BEGIN_MSG_MAP(Edit) | 126 BEGIN_MSG_MAP(Edit) |
120 MSG_WM_CHAR(OnChar) | 127 MSG_WM_CHAR(OnChar) |
121 MSG_WM_CONTEXTMENU(OnContextMenu) | 128 MSG_WM_CONTEXTMENU(OnContextMenu) |
122 MSG_WM_COPY(OnCopy) | 129 MSG_WM_COPY(OnCopy) |
(...skipping 12 matching lines...) Expand all Loading... |
135 MSG_WM_LBUTTONUP(OnLButtonUp) | 142 MSG_WM_LBUTTONUP(OnLButtonUp) |
136 MSG_WM_MBUTTONDOWN(OnNonLButtonDown) | 143 MSG_WM_MBUTTONDOWN(OnNonLButtonDown) |
137 MSG_WM_MOUSEMOVE(OnMouseMove) | 144 MSG_WM_MOUSEMOVE(OnMouseMove) |
138 MSG_WM_MOUSELEAVE(OnMouseLeave) | 145 MSG_WM_MOUSELEAVE(OnMouseLeave) |
139 MESSAGE_HANDLER_EX(WM_MOUSEWHEEL, OnMouseWheel) | 146 MESSAGE_HANDLER_EX(WM_MOUSEWHEEL, OnMouseWheel) |
140 MSG_WM_NCCALCSIZE(OnNCCalcSize) | 147 MSG_WM_NCCALCSIZE(OnNCCalcSize) |
141 MSG_WM_NCPAINT(OnNCPaint) | 148 MSG_WM_NCPAINT(OnNCPaint) |
142 MSG_WM_RBUTTONDOWN(OnNonLButtonDown) | 149 MSG_WM_RBUTTONDOWN(OnNonLButtonDown) |
143 MSG_WM_PASTE(OnPaste) | 150 MSG_WM_PASTE(OnPaste) |
144 MSG_WM_SETFOCUS(OnSetFocus) | 151 MSG_WM_SETFOCUS(OnSetFocus) |
| 152 MSG_WM_KILLFOCUS(OnKillFocus) |
145 MSG_WM_SYSCHAR(OnSysChar) // WM_SYSxxx == WM_xxx with ALT down | 153 MSG_WM_SYSCHAR(OnSysChar) // WM_SYSxxx == WM_xxx with ALT down |
146 MSG_WM_SYSKEYDOWN(OnKeyDown) | 154 MSG_WM_SYSKEYDOWN(OnKeyDown) |
147 END_MSG_MAP() | 155 END_MSG_MAP() |
148 | 156 |
149 private: | 157 private: |
150 // This object freezes repainting of the edit until the object is destroyed. | 158 // 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 | 159 // 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 | 160 // don't freeze, the user will see a rapid series of calls to these as |
153 // flickers. | 161 // flickers. |
154 // | 162 // |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 void OnLButtonDown(UINT keys, const CPoint& point); | 207 void OnLButtonDown(UINT keys, const CPoint& point); |
200 void OnLButtonUp(UINT keys, const CPoint& point); | 208 void OnLButtonUp(UINT keys, const CPoint& point); |
201 void OnMouseLeave(); | 209 void OnMouseLeave(); |
202 LRESULT OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param); | 210 LRESULT OnMouseWheel(UINT message, WPARAM w_param, LPARAM l_param); |
203 void OnMouseMove(UINT keys, const CPoint& point); | 211 void OnMouseMove(UINT keys, const CPoint& point); |
204 int OnNCCalcSize(BOOL w_param, LPARAM l_param); | 212 int OnNCCalcSize(BOOL w_param, LPARAM l_param); |
205 void OnNCPaint(HRGN region); | 213 void OnNCPaint(HRGN region); |
206 void OnNonLButtonDown(UINT keys, const CPoint& point); | 214 void OnNonLButtonDown(UINT keys, const CPoint& point); |
207 void OnPaste(); | 215 void OnPaste(); |
208 void OnSetFocus(HWND hwnd); | 216 void OnSetFocus(HWND hwnd); |
| 217 void OnKillFocus(HWND hwnd); |
209 void OnSysChar(TCHAR ch, UINT repeat_count, UINT flags); | 218 void OnSysChar(TCHAR ch, UINT repeat_count, UINT flags); |
210 | 219 |
211 // Helper function for OnChar() and OnKeyDown() that handles keystrokes that | 220 // Helper function for OnChar() and OnKeyDown() that handles keystrokes that |
212 // could change the text in the edit. | 221 // could change the text in the edit. |
213 // Note: This function assumes GetCurrentMessage() returns a MSG with | 222 // Note: This function assumes GetCurrentMessage() returns a MSG with |
214 // msg > WM_KEYFIRST and < WM_KEYLAST. | 223 // msg > WM_KEYFIRST and < WM_KEYLAST. |
215 void HandleKeystroke(); | 224 void HandleKeystroke(); |
216 | 225 |
217 // Every piece of code that can change the edit should call these functions | 226 // Every piece of code that can change the edit should call these functions |
218 // before and after the change. These functions determine if anything | 227 // before and after the change. These functions determine if anything |
(...skipping 19 matching lines...) Expand all Loading... |
238 // doesn't click on the text itself. | 247 // doesn't click on the text itself. |
239 // | 248 // |
240 // |is_triple_click| should be true iff this is the third click of a triple | 249 // |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. | 250 // click. Sadly, we need to clip slightly differently in this case. |
242 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const; | 251 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const; |
243 | 252 |
244 // Sets whether the mouse is in the edit. As necessary this redraws the | 253 // Sets whether the mouse is in the edit. As necessary this redraws the |
245 // edit. | 254 // edit. |
246 void SetContainsMouse(bool contains_mouse); | 255 void SetContainsMouse(bool contains_mouse); |
247 | 256 |
| 257 // Handles composition related works on both IMM32 and TSF implementation. |
| 258 void OnImeStartCompositionInternal(); |
| 259 void OnImeEndCompositionInternal(); |
| 260 |
248 // Getter for the text_object_model_, used by the ScopedFreeze class. Note | 261 // 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 | 262 // that the pointer returned here is only valid as long as the Edit is still |
250 // alive. | 263 // alive. |
251 ITextDocument* GetTextObjectModel() const; | 264 ITextDocument* GetTextObjectModel() const; |
252 | 265 |
253 // Generates the contents of the context menu. | 266 // Generates the contents of the context menu. |
254 void BuildContextMenu(); | 267 void BuildContextMenu(); |
255 | 268 |
256 static HMODULE loaded_libarary_module_; | 269 static HMODULE loaded_libarary_module_; |
257 | 270 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 int ime_composition_length_; | 308 int ime_composition_length_; |
296 | 309 |
297 // TODO(beng): remove this when we are a subclass of NativeControlWin. | 310 // TODO(beng): remove this when we are a subclass of NativeControlWin. |
298 NativeViewHost* container_view_; | 311 NativeViewHost* container_view_; |
299 | 312 |
300 COLORREF bg_color_; | 313 COLORREF bg_color_; |
301 | 314 |
302 // The accessibility state of this object. | 315 // The accessibility state of this object. |
303 int accessibility_state_; | 316 int accessibility_state_; |
304 | 317 |
| 318 scoped_ptr<ui::TsfEventRouter> tsf_event_router_; |
| 319 |
305 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldWin); | 320 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldWin); |
306 }; | 321 }; |
307 | 322 |
308 } // namespace views | 323 } // namespace views |
309 | 324 |
310 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ | 325 #endif // UI_VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WIN_H_ |
OLD | NEW |