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

Side by Side Diff: ui/views/win/hwnd_message_handler.h

Issue 10867096: Make HWNDMessageHandler subclass WindowImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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) 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_WIN_HWND_MESSAGE_HANDLER_H_ 5 #ifndef UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_
6 #define UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ 6 #define UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_
7 7
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <atlapp.h> 9 #include <atlapp.h>
10 #include <atlmisc.h> 10 #include <atlmisc.h>
11 #include <windows.h> 11 #include <windows.h>
12 12
13 #include <set> 13 #include <set>
14 14
15 #include "base/basictypes.h" 15 #include "base/basictypes.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/message_loop.h"
19 #include "base/string16.h" 20 #include "base/string16.h"
21 #include "base/win/win_util.h"
20 #include "ui/base/accessibility/accessibility_types.h" 22 #include "ui/base/accessibility/accessibility_types.h"
21 #include "ui/base/ui_base_types.h" 23 #include "ui/base/ui_base_types.h"
24 #include "ui/base/win/window_impl.h"
22 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
23 #include "ui/views/ime/input_method_delegate.h" 26 #include "ui/views/ime/input_method_delegate.h"
24 #include "ui/views/views_export.h" 27 #include "ui/views/views_export.h"
25 28
26 namespace gfx { 29 namespace gfx {
27 class Canvas; 30 class Canvas;
28 class ImageSkia; 31 class ImageSkia;
29 class Insets; 32 class Insets;
30 } 33 }
31 34
32 namespace views { 35 namespace views {
33 36
34 class FullscreenHandler; 37 class FullscreenHandler;
35 class HWNDMessageHandlerDelegate; 38 class HWNDMessageHandlerDelegate;
36 class InputMethod; 39 class InputMethod;
37 40
38 VIEWS_EXPORT bool IsAeroGlassEnabled(); 41 VIEWS_EXPORT bool IsAeroGlassEnabled();
39 42
43 // These two messages aren't defined in winuser.h, but they are sent to windows
44 // with captions. They appear to paint the window caption and frame.
45 // Unfortunately if you override the standard non-client rendering as we do
46 // with CustomFrameWindow, sometimes Windows (not deterministically
47 // reproducibly but definitely frequently) will send these messages to the
48 // window and paint the standard caption/title over the top of the custom one.
49 // So we need to handle these messages in CustomFrameWindow to prevent this
50 // from happening.
51 const int WM_NCUAHDRAWCAPTION = 0xAE;
52 const int WM_NCUAHDRAWFRAME = 0xAF;
53
40 // An object that handles messages for a HWND that implements the views 54 // An object that handles messages for a HWND that implements the views
41 // "Custom Frame" look. The purpose of this class is to isolate the windows- 55 // "Custom Frame" look. The purpose of this class is to isolate the windows-
42 // specific message handling from the code that wraps it. It is intended to be 56 // specific message handling from the code that wraps it. It is intended to be
43 // used by both a views::NativeWidget and an aura::RootWindowHost 57 // used by both a views::NativeWidget and an aura::RootWindowHost
44 // implementation. 58 // implementation. Because of this, it explicitly does not use gfx::NativeView
45 // TODO(beng): This object should eventually *become* the WindowImpl. 59 // since the meaning of that typedef can vary. This class only deals with HWNDs.
46 class VIEWS_EXPORT HWNDMessageHandler : public internal::InputMethodDelegate { 60 class VIEWS_EXPORT HWNDMessageHandler : public ui::WindowImpl,
61 public internal::InputMethodDelegate,
62 public MessageLoopForUI::Observer {
47 public: 63 public:
48 explicit HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate); 64 explicit HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate);
49 ~HWNDMessageHandler(); 65 ~HWNDMessageHandler();
50 66
51 void Init(const gfx::Rect& bounds); 67 void Init(HWND parent, const gfx::Rect& bounds);
52 void InitModalType(ui::ModalType modal_type); 68 void InitModalType(ui::ModalType modal_type);
53 69
54 void Close(); 70 void Close();
55 void CloseNow(); 71 void CloseNow();
56 72
57 gfx::Rect GetWindowBoundsInScreen() const; 73 gfx::Rect GetWindowBoundsInScreen() const;
58 gfx::Rect GetClientAreaBoundsInScreen() const; 74 gfx::Rect GetClientAreaBoundsInScreen() const;
59 gfx::Rect GetRestoredBounds() const; 75 gfx::Rect GetRestoredBounds() const;
60 void GetWindowPlacement(gfx::Rect* bounds, 76 void GetWindowPlacement(gfx::Rect* bounds,
61 ui::WindowShowState* show_state) const; 77 ui::WindowShowState* show_state) const;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void set_can_update_layered_window(bool can_update_layered_window) { 144 void set_can_update_layered_window(bool can_update_layered_window) {
129 can_update_layered_window_ = can_update_layered_window; 145 can_update_layered_window_ = can_update_layered_window;
130 } 146 }
131 void SchedulePaintInRect(const gfx::Rect& rect); 147 void SchedulePaintInRect(const gfx::Rect& rect);
132 void SetOpacity(BYTE opacity); 148 void SetOpacity(BYTE opacity);
133 149
134 void SetWindowIcons(const gfx::ImageSkia& window_icon, 150 void SetWindowIcons(const gfx::ImageSkia& window_icon,
135 const gfx::ImageSkia& app_icon); 151 const gfx::ImageSkia& app_icon);
136 152
137 // Message Handlers. 153 // Message Handlers.
154 // This list is in _ALPHABETICAL_ order!
138 void OnActivate(UINT action, BOOL minimized, HWND window); 155 void OnActivate(UINT action, BOOL minimized, HWND window);
139 // TODO(beng): Once this object becomes the WindowImpl, these methods can 156 // TODO(beng): Once this object becomes the WindowImpl, these methods can
140 // be made private. 157 // be made private.
141 void OnActivateApp(BOOL active, DWORD thread_id); 158 void OnActivateApp(BOOL active, DWORD thread_id);
142 // TODO(beng): return BOOL is temporary until this object becomes a 159 // TODO(beng): return BOOL is temporary until this object becomes a
143 // WindowImpl. 160 // WindowImpl.
144 BOOL OnAppCommand(HWND window, short command, WORD device, int keystate); 161 BOOL OnAppCommand(HWND window, short command, WORD device, int keystate);
145 void OnCancelMode(); 162 void OnCancelMode();
146 void OnCaptureChanged(HWND window); 163 void OnCaptureChanged(HWND window);
147 void OnClose(); 164 void OnClose();
148 void OnCommand(UINT notification_code, int command, HWND window); 165 void OnCommand(UINT notification_code, int command, HWND window);
149 LRESULT OnCreate(CREATESTRUCT* create_struct); 166 LRESULT OnCreate(CREATESTRUCT* create_struct);
150 void OnDestroy(); 167 void OnDestroy();
151 void OnDisplayChange(UINT bits_per_pixel, const CSize& screen_size); 168 void OnDisplayChange(UINT bits_per_pixel, const CSize& screen_size);
152 LRESULT OnDwmCompositionChanged(UINT msg, WPARAM w_param, LPARAM l_param); 169 LRESULT OnDwmCompositionChanged(UINT msg, WPARAM w_param, LPARAM l_param);
153 void OnEndSession(BOOL ending, UINT logoff); 170 void OnEndSession(BOOL ending, UINT logoff);
154 void OnEnterSizeMove(); 171 void OnEnterSizeMove();
155 LRESULT OnEraseBkgnd(HDC dc); 172 LRESULT OnEraseBkgnd(HDC dc);
156 void OnExitMenuLoop(BOOL is_track_popup_menu); 173 void OnExitMenuLoop(BOOL is_track_popup_menu);
157 void OnExitSizeMove(); 174 void OnExitSizeMove();
158 void OnHScroll(int scroll_type, short position, HWND scrollbar); 175 void OnHScroll(int scroll_type, short position, HWND scrollbar);
159 void OnGetMinMaxInfo(MINMAXINFO* minmax_info); 176 void OnGetMinMaxInfo(MINMAXINFO* minmax_info);
160 LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param); 177 LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param);
161 LRESULT OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param); 178 LRESULT OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param);
162 void OnInitMenu(HMENU menu); 179 void OnInitMenu(HMENU menu);
163 void OnInitMenuPopup(); 180 void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu);
164 void OnInputLangChange(DWORD character_set, HKL input_language_id); 181 void OnInputLangChange(DWORD character_set, HKL input_language_id);
165 LRESULT OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param); 182 LRESULT OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param);
166 void OnKillFocus(HWND focused_window); 183 void OnKillFocus(HWND focused_window);
167 LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param); 184 LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param);
168 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param); 185 LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param);
169 void OnMove(const CPoint& point); 186 void OnMove(const CPoint& point);
170 void OnMoving(UINT param, const RECT* new_bounds); 187 void OnMoving(UINT param, const RECT* new_bounds);
171 LRESULT OnNCActivate(BOOL active); 188 LRESULT OnNCActivate(BOOL active);
172 LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param); 189 LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param);
173 LRESULT OnNCHitTest(const CPoint& point); 190 LRESULT OnNCHitTest(const CPoint& point);
(...skipping 10 matching lines...) Expand all
184 LRESULT OnSetText(const wchar_t* text); 201 LRESULT OnSetText(const wchar_t* text);
185 void OnSettingChange(UINT flags, const wchar_t* section); 202 void OnSettingChange(UINT flags, const wchar_t* section);
186 void OnSize(UINT param, const CSize& size); 203 void OnSize(UINT param, const CSize& size);
187 void OnSysCommand(UINT notification_code, const CPoint& point); 204 void OnSysCommand(UINT notification_code, const CPoint& point);
188 void OnThemeChanged(); 205 void OnThemeChanged();
189 LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param); 206 LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param);
190 void OnVScroll(int scroll_type, short position, HWND scrollbar); 207 void OnVScroll(int scroll_type, short position, HWND scrollbar);
191 void OnWindowPosChanging(WINDOWPOS* window_pos); 208 void OnWindowPosChanging(WINDOWPOS* window_pos);
192 void OnWindowPosChanged(WINDOWPOS* window_pos); 209 void OnWindowPosChanged(WINDOWPOS* window_pos);
193 210
194 // TODO(beng): Can be removed once this object becomes the WindowImpl.
195 bool remove_standard_frame() const { return remove_standard_frame_; }
196 void set_remove_standard_frame(bool remove_standard_frame) { 211 void set_remove_standard_frame(bool remove_standard_frame) {
197 remove_standard_frame_ = remove_standard_frame; 212 remove_standard_frame_ = remove_standard_frame;
198 } 213 }
199 214
200 // Resets the window region for the current widget bounds if necessary. 215 // Resets the window region for the current widget bounds if necessary.
201 // If |force| is true, the window region is reset to NULL even for native 216 // If |force| is true, the window region is reset to NULL even for native
202 // frame windows. 217 // frame windows.
203 void ResetWindowRegion(bool force); 218 void ResetWindowRegion(bool force);
204 219
205 // TODO(beng): This won't be a style violation once this object becomes the
206 // WindowImpl.
207 HWND hwnd();
208 HWND hwnd() const;
209
210 private: 220 private:
211 typedef std::set<DWORD> TouchIDs; 221 typedef std::set<DWORD> TouchIDs;
212 222
213 // TODO(beng): remove once this is the WindowImpl.
214 friend class NativeWidgetWin;
215
216 // Overridden from internal::InputMethodDelegate: 223 // Overridden from internal::InputMethodDelegate:
217 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE; 224 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
218 225
219 // Overridden from WindowImpl: 226 // Overridden from WindowImpl:
220 virtual HICON GetDefaultWindowIcon() const; 227 virtual HICON GetDefaultWindowIcon() const OVERRIDE;
221 virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); 228 virtual LRESULT OnWndProc(UINT message,
229 WPARAM w_param,
230 LPARAM l_param) OVERRIDE;
231
232 // Overridden from MessageLoop::Observer:
233 virtual base::EventStatus WillProcessEvent(
234 const base::NativeEvent& event) OVERRIDE;
235 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE;
222 236
223 // Can be called after the delegate has had the opportunity to set focus and 237 // Can be called after the delegate has had the opportunity to set focus and
224 // did not do so. 238 // did not do so.
225 void SetInitialFocus(); 239 void SetInitialFocus();
226 240
227 // Called after the WM_ACTIVATE message has been processed by the default 241 // Called after the WM_ACTIVATE message has been processed by the default
228 // windows procedure. 242 // windows procedure.
229 void PostProcessActivateMessage(int activation_state); 243 void PostProcessActivateMessage(int activation_state);
230 244
231 // Enables disabled owner windows that may have been disabled due to this 245 // Enables disabled owner windows that may have been disabled due to this
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Stops ignoring SetWindowPos() requests (see below). 280 // Stops ignoring SetWindowPos() requests (see below).
267 void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; } 281 void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; }
268 282
269 // Synchronously paints the invalid contents of the Widget. 283 // Synchronously paints the invalid contents of the Widget.
270 void RedrawInvalidRect(); 284 void RedrawInvalidRect();
271 285
272 // Synchronously updates the invalid contents of the Widget. Valid for 286 // Synchronously updates the invalid contents of the Widget. Valid for
273 // layered windows only. 287 // layered windows only.
274 void RedrawLayeredWindowContents(); 288 void RedrawLayeredWindowContents();
275 289
276 // TODO(beng): Remove once this class becomes the WindowImpl. 290 // Message Handlers ----------------------------------------------------------
277 void SetMsgHandled(BOOL handled); 291
292 BEGIN_MSG_MAP_EX(HWNDMessageHandler)
293 // Range handlers must go first!
294 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
295 MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE, WM_NCXBUTTONDBLCLK, OnMouseRange)
296
297 // Reflected message handler
298 MESSAGE_HANDLER_EX(base::win::kReflectedMessage, OnReflectedMessage)
299
300 // CustomFrameWindow hacks
301 MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption)
302 MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame)
303
304 // Vista and newer
305 MESSAGE_HANDLER_EX(WM_DWMCOMPOSITIONCHANGED, OnDwmCompositionChanged)
306
307 // Non-atlcrack.h handlers
308 MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject)
309
310 // Mouse events.
311 MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate)
312 MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseRange)
313 MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnMouseRange)
314 MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor);
315
316 // Key events.
317 MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyEvent)
318 MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyEvent)
319 MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyEvent)
320 MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyEvent)
321
322 // IME Events.
323 MESSAGE_HANDLER_EX(WM_IME_SETCONTEXT, OnImeMessages)
324 MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeMessages)
325 MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeMessages)
326 MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeMessages)
327 MESSAGE_HANDLER_EX(WM_IME_REQUEST, OnImeMessages)
328 MESSAGE_HANDLER_EX(WM_CHAR, OnImeMessages)
329 MESSAGE_HANDLER_EX(WM_SYSCHAR, OnImeMessages)
330 MESSAGE_HANDLER_EX(WM_DEADCHAR, OnImeMessages)
331 MESSAGE_HANDLER_EX(WM_SYSDEADCHAR, OnImeMessages)
332
333 // Touch Events.
334 MESSAGE_HANDLER_EX(WM_TOUCH, OnTouchEvent)
335
336 // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU.
337 MSG_WM_ACTIVATE(OnActivate)
338 MSG_WM_ACTIVATEAPP(OnActivateApp)
339 MSG_WM_APPCOMMAND(OnAppCommand)
340 MSG_WM_CANCELMODE(OnCancelMode)
341 MSG_WM_CAPTURECHANGED(OnCaptureChanged)
342 MSG_WM_CLOSE(OnClose)
343 MSG_WM_COMMAND(OnCommand)
344 MSG_WM_CREATE(OnCreate)
345 MSG_WM_DESTROY(OnDestroy)
346 MSG_WM_DISPLAYCHANGE(OnDisplayChange)
347 MSG_WM_ERASEBKGND(OnEraseBkgnd)
348 MSG_WM_ENDSESSION(OnEndSession)
349 MSG_WM_ENTERSIZEMOVE(OnEnterSizeMove)
350 MSG_WM_EXITMENULOOP(OnExitMenuLoop)
351 MSG_WM_EXITSIZEMOVE(OnExitSizeMove)
352 MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo)
353 MSG_WM_HSCROLL(OnHScroll)
354 MSG_WM_INITMENU(OnInitMenu)
355 MSG_WM_INITMENUPOPUP(OnInitMenuPopup)
356 MSG_WM_INPUTLANGCHANGE(OnInputLangChange)
357 MSG_WM_KILLFOCUS(OnKillFocus)
358 MSG_WM_MOVE(OnMove)
359 MSG_WM_MOVING(OnMoving)
360 MSG_WM_NCACTIVATE(OnNCActivate)
361 MSG_WM_NCCALCSIZE(OnNCCalcSize)
362 MSG_WM_NCHITTEST(OnNCHitTest)
363 MSG_WM_NCPAINT(OnNCPaint)
364 MSG_WM_NOTIFY(OnNotify)
365 MSG_WM_PAINT(OnPaint)
366 MSG_WM_POWERBROADCAST(OnPowerBroadcast)
367 MSG_WM_SETFOCUS(OnSetFocus)
368 MSG_WM_SETICON(OnSetIcon)
369 MSG_WM_SETTEXT(OnSetText)
370 MSG_WM_SETTINGCHANGE(OnSettingChange)
371 MSG_WM_SIZE(OnSize)
372 MSG_WM_SYSCOMMAND(OnSysCommand)
373 MSG_WM_THEMECHANGED(OnThemeChanged)
374 MSG_WM_VSCROLL(OnVScroll)
375 MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging)
376 MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged)
377 END_MSG_MAP()
278 378
279 HWNDMessageHandlerDelegate* delegate_; 379 HWNDMessageHandlerDelegate* delegate_;
280 380
281 scoped_ptr<FullscreenHandler> fullscreen_handler_; 381 scoped_ptr<FullscreenHandler> fullscreen_handler_;
282 382
283 // The following factory is used for calls to close the NativeWidgetWin 383 // Performs CloseNow() after a return to the message loop.
284 // instance.
285 base::WeakPtrFactory<HWNDMessageHandler> close_widget_factory_; 384 base::WeakPtrFactory<HWNDMessageHandler> close_widget_factory_;
286 385
287 bool remove_standard_frame_; 386 bool remove_standard_frame_;
288 387
289 // Whether the focus should be restored next time we get enabled. Needed to 388 // Whether the focus should be restored next time we get enabled. Needed to
290 // restore focus correctly when Windows modal dialogs are displayed. 389 // restore focus correctly when Windows modal dialogs are displayed.
291 bool restore_focus_when_enabled_; 390 bool restore_focus_when_enabled_;
292 391
293 // Whether all ancestors have been enabled. This is only used if is_modal_ is 392 // Whether all ancestors have been enabled. This is only used if is_modal_ is
294 // true. 393 // true.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 // True if we are allowed to update the layered window from the DIB backing 474 // True if we are allowed to update the layered window from the DIB backing
376 // store if necessary. 475 // store if necessary.
377 bool can_update_layered_window_; 476 bool can_update_layered_window_;
378 477
379 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler); 478 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler);
380 }; 479 };
381 480
382 } // namespace views 481 } // namespace views
383 482
384 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ 483 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698