• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_
6 #define UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_
7 
8 #include <windows.h>
9 
10 #include <set>
11 #include <vector>
12 
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/strings/string16.h"
18 #include "base/win/scoped_gdi_object.h"
19 #include "base/win/win_util.h"
20 #include "ui/accessibility/ax_enums.h"
21 #include "ui/base/ui_base_types.h"
22 #include "ui/base/win/window_event_target.h"
23 #include "ui/events/event.h"
24 #include "ui/gfx/rect.h"
25 #include "ui/gfx/sequential_id_generator.h"
26 #include "ui/gfx/win/window_impl.h"
27 #include "ui/views/ime/input_method_delegate.h"
28 #include "ui/views/views_export.h"
29 
30 namespace gfx {
31 class Canvas;
32 class ImageSkia;
33 class Insets;
34 }
35 
36 namespace ui  {
37 class ViewProp;
38 }
39 
40 namespace views {
41 
42 class FullscreenHandler;
43 class HWNDMessageHandlerDelegate;
44 class InputMethod;
45 
46 // These two messages aren't defined in winuser.h, but they are sent to windows
47 // with captions. They appear to paint the window caption and frame.
48 // Unfortunately if you override the standard non-client rendering as we do
49 // with CustomFrameWindow, sometimes Windows (not deterministically
50 // reproducibly but definitely frequently) will send these messages to the
51 // window and paint the standard caption/title over the top of the custom one.
52 // So we need to handle these messages in CustomFrameWindow to prevent this
53 // from happening.
54 const int WM_NCUAHDRAWCAPTION = 0xAE;
55 const int WM_NCUAHDRAWFRAME = 0xAF;
56 
57 // IsMsgHandled() and BEGIN_SAFE_MSG_MAP_EX are a modified version of
58 // BEGIN_MSG_MAP_EX. The main difference is it adds a WeakPtrFactory member
59 // (|weak_factory_|) that is used in _ProcessWindowMessage() and changing
60 // IsMsgHandled() from a member function to a define that checks if the weak
61 // factory is still valid in addition to the member. Together these allow for
62 // |this| to be deleted during dispatch.
63 #define IsMsgHandled() !ref.get() || msg_handled_
64 
65 #define BEGIN_SAFE_MSG_MAP_EX(the_class) \
66  private: \
67   base::WeakPtrFactory<the_class> weak_factory_; \
68   BOOL msg_handled_; \
69 \
70  public: \
71   /* "handled" management for cracked handlers */ \
72   void SetMsgHandled(BOOL handled) { \
73     msg_handled_ = handled; \
74   } \
75   BOOL ProcessWindowMessage(HWND hwnd, \
76                             UINT msg, \
77                             WPARAM w_param, \
78                             LPARAM l_param, \
79                             LRESULT& l_result, \
80                             DWORD msg_map_id = 0) { \
81     base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); \
82     BOOL old_msg_handled = msg_handled_; \
83     BOOL ret = _ProcessWindowMessage(hwnd, msg, w_param, l_param, l_result, \
84                                      msg_map_id); \
85     if (ref.get()) \
86       msg_handled_ = old_msg_handled; \
87     return ret; \
88   } \
89   BOOL _ProcessWindowMessage(HWND hWnd, \
90                              UINT uMsg, \
91                              WPARAM wParam, \
92                              LPARAM lParam, \
93                              LRESULT& lResult, \
94                              DWORD dwMsgMapID) { \
95     base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); \
96     BOOL bHandled = TRUE; \
97     hWnd; \
98     uMsg; \
99     wParam; \
100     lParam; \
101     lResult; \
102     bHandled; \
103     switch(dwMsgMapID) { \
104       case 0:
105 
106 // An object that handles messages for a HWND that implements the views
107 // "Custom Frame" look. The purpose of this class is to isolate the windows-
108 // specific message handling from the code that wraps it. It is intended to be
109 // used by both a views::NativeWidget and an aura::WindowTreeHost
110 // implementation.
111 // TODO(beng): This object should eventually *become* the WindowImpl.
112 class VIEWS_EXPORT HWNDMessageHandler :
113     public gfx::WindowImpl,
114     public internal::InputMethodDelegate,
115     public ui::WindowEventTarget {
116  public:
117   explicit HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate);
118   ~HWNDMessageHandler();
119 
120   void Init(HWND parent, const gfx::Rect& bounds);
121   void InitModalType(ui::ModalType modal_type);
122 
123   void Close();
124   void CloseNow();
125 
126   gfx::Rect GetWindowBoundsInScreen() const;
127   gfx::Rect GetClientAreaBoundsInScreen() const;
128   gfx::Rect GetRestoredBounds() const;
129   // This accounts for the case where the widget size is the client size.
130   gfx::Rect GetClientAreaBounds() const;
131 
132   void GetWindowPlacement(gfx::Rect* bounds,
133                           ui::WindowShowState* show_state) const;
134 
135   // Sets the bounds of the HWND to |bounds_in_pixels|. If the HWND size is not
136   // changed, |force_size_changed| determines if we should pretend it is.
137   void SetBounds(const gfx::Rect& bounds_in_pixels, bool force_size_changed);
138 
139   void SetSize(const gfx::Size& size);
140   void CenterWindow(const gfx::Size& size);
141 
142   void SetRegion(HRGN rgn);
143 
144   void StackAbove(HWND other_hwnd);
145   void StackAtTop();
146 
147   void Show();
148   void ShowWindowWithState(ui::WindowShowState show_state);
149   void ShowMaximizedWithBounds(const gfx::Rect& bounds);
150   void Hide();
151 
152   void Maximize();
153   void Minimize();
154   void Restore();
155 
156   void Activate();
157   void Deactivate();
158 
159   void SetAlwaysOnTop(bool on_top);
160 
161   bool IsVisible() const;
162   bool IsActive() const;
163   bool IsMinimized() const;
164   bool IsMaximized() const;
165   bool IsAlwaysOnTop() const;
166 
167   bool RunMoveLoop(const gfx::Vector2d& drag_offset, bool hide_on_escape);
168   void EndMoveLoop();
169 
170   // Tells the HWND its client area has changed.
171   void SendFrameChanged();
172 
173   void FlashFrame(bool flash);
174 
175   void ClearNativeFocus();
176 
177   void SetCapture();
178   void ReleaseCapture();
179   bool HasCapture() const;
180 
fullscreen_handler()181   FullscreenHandler* fullscreen_handler() { return fullscreen_handler_.get(); }
182 
183   void SetVisibilityChangedAnimationsEnabled(bool enabled);
184 
185   // Returns true if the title changed.
186   bool SetTitle(const base::string16& title);
187 
188   void SetCursor(HCURSOR cursor);
189 
190   void FrameTypeChanged();
191 
192   void SchedulePaintInRect(const gfx::Rect& rect);
193   void SetOpacity(BYTE opacity);
194 
195   void SetWindowIcons(const gfx::ImageSkia& window_icon,
196                       const gfx::ImageSkia& app_icon);
197 
set_remove_standard_frame(bool remove_standard_frame)198   void set_remove_standard_frame(bool remove_standard_frame) {
199     remove_standard_frame_ = remove_standard_frame;
200   }
201 
set_use_system_default_icon(bool use_system_default_icon)202   void set_use_system_default_icon(bool use_system_default_icon) {
203     use_system_default_icon_ = use_system_default_icon;
204   }
205 
206  private:
207   typedef std::set<DWORD> TouchIDs;
208 
209   // Overridden from internal::InputMethodDelegate:
210   virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
211 
212   // Overridden from WindowImpl:
213   virtual HICON GetDefaultWindowIcon() const OVERRIDE;
214   virtual LRESULT OnWndProc(UINT message,
215                             WPARAM w_param,
216                             LPARAM l_param) OVERRIDE;
217 
218   // Overridden from WindowEventTarget
219   virtual LRESULT HandleMouseMessage(unsigned int message,
220                                      WPARAM w_param,
221                                      LPARAM l_param) OVERRIDE;
222   virtual LRESULT HandleKeyboardMessage(unsigned int message,
223                                         WPARAM w_param,
224                                         LPARAM l_param) OVERRIDE;
225   virtual LRESULT HandleTouchMessage(unsigned int message,
226                                      WPARAM w_param,
227                                      LPARAM l_param) OVERRIDE;
228 
229   virtual LRESULT HandleScrollMessage(unsigned int message,
230                                       WPARAM w_param,
231                                       LPARAM l_param) OVERRIDE;
232 
233   virtual LRESULT HandleNcHitTestMessage(unsigned int message,
234                                          WPARAM w_param,
235                                          LPARAM l_param) OVERRIDE;
236 
237   // Returns the auto-hide edges of the appbar. See
238   // ViewsDelegate::GetAppbarAutohideEdges() for details. If the edges change,
239   // OnAppbarAutohideEdgesChanged() is called.
240   int GetAppbarAutohideEdges(HMONITOR monitor);
241 
242   // Callback if the autohide edges have changed. See
243   // ViewsDelegate::GetAppbarAutohideEdges() for details.
244   void OnAppbarAutohideEdgesChanged();
245 
246   // Can be called after the delegate has had the opportunity to set focus and
247   // did not do so.
248   void SetInitialFocus();
249 
250   // Called after the WM_ACTIVATE message has been processed by the default
251   // windows procedure.
252   void PostProcessActivateMessage(int activation_state, bool minimized);
253 
254   // Enables disabled owner windows that may have been disabled due to this
255   // window's modality.
256   void RestoreEnabledIfNecessary();
257 
258   // Executes the specified SC_command.
259   void ExecuteSystemMenuCommand(int command);
260 
261   // Start tracking all mouse events so that this window gets sent mouse leave
262   // messages too.
263   void TrackMouseEvents(DWORD mouse_tracking_flags);
264 
265   // Responds to the client area changing size, either at window creation time
266   // or subsequently.
267   void ClientAreaSizeChanged();
268 
269   // Returns the insets of the client area relative to the non-client area of
270   // the window.
271   bool GetClientAreaInsets(gfx::Insets* insets) const;
272 
273   // Resets the window region for the current widget bounds if necessary.
274   // If |force| is true, the window region is reset to NULL even for native
275   // frame windows.
276   void ResetWindowRegion(bool force, bool redraw);
277 
278   // Enables or disables rendering of the non-client (glass) area by DWM,
279   // under Vista and above, depending on whether the caller has requested a
280   // custom frame.
281   void UpdateDwmNcRenderingPolicy();
282 
283   // Calls DefWindowProc, safely wrapping the call in a ScopedRedrawLock to
284   // prevent frame flicker. DefWindowProc handling can otherwise render the
285   // classic-look window title bar directly.
286   LRESULT DefWindowProcWithRedrawLock(UINT message,
287                                       WPARAM w_param,
288                                       LPARAM l_param);
289 
290   // Lock or unlock the window from being able to redraw itself in response to
291   // updates to its invalid region.
292   class ScopedRedrawLock;
293   void LockUpdates(bool force);
294   void UnlockUpdates(bool force);
295 
296   // Stops ignoring SetWindowPos() requests (see below).
StopIgnoringPosChanges()297   void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; }
298 
299   // Synchronously updates the invalid contents of the Widget. Valid for
300   // layered windows only.
301   void RedrawLayeredWindowContents();
302 
303   // Attempts to force the window to be redrawn, ensuring that it gets
304   // onscreen.
305   void ForceRedrawWindow(int attempts);
306 
307   // Message Handlers ----------------------------------------------------------
308 
309   BEGIN_SAFE_MSG_MAP_EX(HWNDMessageHandler)
310     // Range handlers must go first!
311     CR_MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
312     CR_MESSAGE_RANGE_HANDLER_EX(WM_NCMOUSEMOVE,
313                                 WM_NCXBUTTONDBLCLK,
314                                 OnMouseRange)
315 
316     // CustomFrameWindow hacks
317     CR_MESSAGE_HANDLER_EX(WM_NCUAHDRAWCAPTION, OnNCUAHDrawCaption)
318     CR_MESSAGE_HANDLER_EX(WM_NCUAHDRAWFRAME, OnNCUAHDrawFrame)
319 
320     // Vista and newer
321     CR_MESSAGE_HANDLER_EX(WM_DWMCOMPOSITIONCHANGED, OnDwmCompositionChanged)
322 
323     // Non-atlcrack.h handlers
324     CR_MESSAGE_HANDLER_EX(WM_GETOBJECT, OnGetObject)
325 
326     // Mouse events.
327     CR_MESSAGE_HANDLER_EX(WM_MOUSEACTIVATE, OnMouseActivate)
328     CR_MESSAGE_HANDLER_EX(WM_MOUSELEAVE, OnMouseRange)
329     CR_MESSAGE_HANDLER_EX(WM_NCMOUSELEAVE, OnMouseRange)
330     CR_MESSAGE_HANDLER_EX(WM_SETCURSOR, OnSetCursor);
331 
332     // Key events.
333     CR_MESSAGE_HANDLER_EX(WM_KEYDOWN, OnKeyEvent)
334     CR_MESSAGE_HANDLER_EX(WM_KEYUP, OnKeyEvent)
335     CR_MESSAGE_HANDLER_EX(WM_SYSKEYDOWN, OnKeyEvent)
336     CR_MESSAGE_HANDLER_EX(WM_SYSKEYUP, OnKeyEvent)
337 
338     // IME Events.
339     CR_MESSAGE_HANDLER_EX(WM_IME_SETCONTEXT, OnImeMessages)
340     CR_MESSAGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, OnImeMessages)
341     CR_MESSAGE_HANDLER_EX(WM_IME_COMPOSITION, OnImeMessages)
342     CR_MESSAGE_HANDLER_EX(WM_IME_ENDCOMPOSITION, OnImeMessages)
343     CR_MESSAGE_HANDLER_EX(WM_IME_REQUEST, OnImeMessages)
344     CR_MESSAGE_HANDLER_EX(WM_IME_NOTIFY, OnImeMessages)
345     CR_MESSAGE_HANDLER_EX(WM_CHAR, OnImeMessages)
346     CR_MESSAGE_HANDLER_EX(WM_SYSCHAR, OnImeMessages)
347 
348     // Scroll events
349     CR_MESSAGE_HANDLER_EX(WM_VSCROLL, OnScrollMessage)
350     CR_MESSAGE_HANDLER_EX(WM_HSCROLL, OnScrollMessage)
351 
352     // Touch Events.
353     CR_MESSAGE_HANDLER_EX(WM_TOUCH, OnTouchEvent)
354 
355     // Uses the general handler macro since the specific handler macro
356     // MSG_WM_NCACTIVATE would convert WPARAM type to BOOL type. The high
357     // word of WPARAM could be set when the window is minimized or restored.
358     CR_MESSAGE_HANDLER_EX(WM_NCACTIVATE, OnNCActivate)
359 
360     // This list is in _ALPHABETICAL_ order! OR I WILL HURT YOU.
361     CR_MSG_WM_ACTIVATEAPP(OnActivateApp)
362     CR_MSG_WM_APPCOMMAND(OnAppCommand)
363     CR_MSG_WM_CANCELMODE(OnCancelMode)
364     CR_MSG_WM_CAPTURECHANGED(OnCaptureChanged)
365     CR_MSG_WM_CLOSE(OnClose)
366     CR_MSG_WM_COMMAND(OnCommand)
367     CR_MSG_WM_CREATE(OnCreate)
368     CR_MSG_WM_DESTROY(OnDestroy)
369     CR_MSG_WM_DISPLAYCHANGE(OnDisplayChange)
370     CR_MSG_WM_ENTERMENULOOP(OnEnterMenuLoop)
371     CR_MSG_WM_EXITMENULOOP(OnExitMenuLoop)
372     CR_MSG_WM_ENTERSIZEMOVE(OnEnterSizeMove)
373     CR_MSG_WM_ERASEBKGND(OnEraseBkgnd)
374     CR_MSG_WM_EXITSIZEMOVE(OnExitSizeMove)
375     CR_MSG_WM_GETMINMAXINFO(OnGetMinMaxInfo)
376     CR_MSG_WM_INITMENU(OnInitMenu)
377     CR_MSG_WM_INPUTLANGCHANGE(OnInputLangChange)
378     CR_MSG_WM_KILLFOCUS(OnKillFocus)
379     CR_MSG_WM_MOVE(OnMove)
380     CR_MSG_WM_MOVING(OnMoving)
381     CR_MSG_WM_NCCALCSIZE(OnNCCalcSize)
382     CR_MSG_WM_NCHITTEST(OnNCHitTest)
383     CR_MSG_WM_NCPAINT(OnNCPaint)
384     CR_MSG_WM_NOTIFY(OnNotify)
385     CR_MSG_WM_PAINT(OnPaint)
386     CR_MSG_WM_SETFOCUS(OnSetFocus)
387     CR_MSG_WM_SETICON(OnSetIcon)
388     CR_MSG_WM_SETTEXT(OnSetText)
389     CR_MSG_WM_SETTINGCHANGE(OnSettingChange)
390     CR_MSG_WM_SIZE(OnSize)
391     CR_MSG_WM_SYSCOMMAND(OnSysCommand)
392     CR_MSG_WM_THEMECHANGED(OnThemeChanged)
393     CR_MSG_WM_WINDOWPOSCHANGED(OnWindowPosChanged)
394     CR_MSG_WM_WINDOWPOSCHANGING(OnWindowPosChanging)
395     CR_MSG_WM_WTSSESSION_CHANGE(OnSessionChange)
396   CR_END_MSG_MAP()
397 
398   // Message Handlers.
399   // This list is in _ALPHABETICAL_ order!
400   // TODO(beng): Once this object becomes the WindowImpl, these methods can
401   //             be made private.
402   void OnActivateApp(BOOL active, DWORD thread_id);
403   // TODO(beng): return BOOL is temporary until this object becomes a
404   //             WindowImpl.
405   BOOL OnAppCommand(HWND window, short command, WORD device, int keystate);
406   void OnCancelMode();
407   void OnCaptureChanged(HWND window);
408   void OnClose();
409   void OnCommand(UINT notification_code, int command, HWND window);
410   LRESULT OnCreate(CREATESTRUCT* create_struct);
411   void OnDestroy();
412   void OnDisplayChange(UINT bits_per_pixel, const gfx::Size& screen_size);
413   LRESULT OnDwmCompositionChanged(UINT msg, WPARAM w_param, LPARAM l_param);
414   void OnEnterMenuLoop(BOOL from_track_popup_menu);
415   void OnEnterSizeMove();
416   LRESULT OnEraseBkgnd(HDC dc);
417   void OnExitMenuLoop(BOOL is_shortcut_menu);
418   void OnExitSizeMove();
419   void OnGetMinMaxInfo(MINMAXINFO* minmax_info);
420   LRESULT OnGetObject(UINT message, WPARAM w_param, LPARAM l_param);
421   LRESULT OnImeMessages(UINT message, WPARAM w_param, LPARAM l_param);
422   void OnInitMenu(HMENU menu);
423   void OnInputLangChange(DWORD character_set, HKL input_language_id);
424   LRESULT OnKeyEvent(UINT message, WPARAM w_param, LPARAM l_param);
425   void OnKillFocus(HWND focused_window);
426   LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param);
427   LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param);
428   void OnMove(const gfx::Point& point);
429   void OnMoving(UINT param, const RECT* new_bounds);
430   LRESULT OnNCActivate(UINT message, WPARAM w_param, LPARAM l_param);
431   LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param);
432   LRESULT OnNCHitTest(const gfx::Point& point);
433   void OnNCPaint(HRGN rgn);
434   LRESULT OnNCUAHDrawCaption(UINT message, WPARAM w_param, LPARAM l_param);
435   LRESULT OnNCUAHDrawFrame(UINT message, WPARAM w_param, LPARAM l_param);
436   LRESULT OnNotify(int w_param, NMHDR* l_param);
437   void OnPaint(HDC dc);
438   LRESULT OnReflectedMessage(UINT message, WPARAM w_param, LPARAM l_param);
439   LRESULT OnScrollMessage(UINT message, WPARAM w_param, LPARAM l_param);
440   void OnSessionChange(WPARAM status_code, PWTSSESSION_NOTIFICATION session_id);
441   LRESULT OnSetCursor(UINT message, WPARAM w_param, LPARAM l_param);
442   void OnSetFocus(HWND last_focused_window);
443   LRESULT OnSetIcon(UINT size_type, HICON new_icon);
444   LRESULT OnSetText(const wchar_t* text);
445   void OnSettingChange(UINT flags, const wchar_t* section);
446   void OnSize(UINT param, const gfx::Size& size);
447   void OnSysCommand(UINT notification_code, const gfx::Point& point);
448   void OnThemeChanged();
449   LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param);
450   void OnWindowPosChanging(WINDOWPOS* window_pos);
451   void OnWindowPosChanged(WINDOWPOS* window_pos);
452 
453   typedef std::vector<ui::TouchEvent> TouchEvents;
454   // Helper to handle the list of touch events passed in. We need this because
455   // touch events on windows don't fire if we enter a modal loop in the context
456   // of a touch event.
457   void HandleTouchEvents(const TouchEvents& touch_events);
458 
459   // Resets the flag which indicates that we are in the context of a touch down
460   // event.
461   void ResetTouchDownContext();
462 
463   // Helper to handle mouse events.
464   // The |message|, |w_param|, |l_param| parameters identify the Windows mouse
465   // message and its parameters respectively.
466   // The |track_mouse| parameter indicates if we should track the mouse.
467   LRESULT HandleMouseEventInternal(UINT message,
468                                    WPARAM w_param,
469                                    LPARAM l_param,
470                                    bool track_mouse);
471 
472   // Returns true if the mouse message passed in is an OS synthesized mouse
473   // message.
474   // |message| identifies the mouse message.
475   // |message_time| is the time when the message occurred.
476   // |l_param| indicates the location of the mouse message.
477   bool IsSynthesizedMouseMessage(unsigned int message,
478                                  int message_time,
479                                  LPARAM l_param);
480 
481   HWNDMessageHandlerDelegate* delegate_;
482 
483   scoped_ptr<FullscreenHandler> fullscreen_handler_;
484 
485   // Set to true in Close() and false is CloseNow().
486   bool waiting_for_close_now_;
487 
488   bool remove_standard_frame_;
489 
490   bool use_system_default_icon_;
491 
492   // Whether all ancestors have been enabled. This is only used if is_modal_ is
493   // true.
494   bool restored_enabled_;
495 
496   // The current cursor.
497   HCURSOR current_cursor_;
498 
499   // The last cursor that was active before the current one was selected. Saved
500   // so that we can restore it.
501   HCURSOR previous_cursor_;
502 
503   // Event handling ------------------------------------------------------------
504 
505   // The flags currently being used with TrackMouseEvent to track mouse
506   // messages. 0 if there is no active tracking. The value of this member is
507   // used when tracking is canceled.
508   DWORD active_mouse_tracking_flags_;
509 
510   // Set to true when the user presses the right mouse button on the caption
511   // area. We need this so we can correctly show the context menu on mouse-up.
512   bool is_right_mouse_pressed_on_caption_;
513 
514   // The set of touch devices currently down.
515   TouchIDs touch_ids_;
516 
517   // ScopedRedrawLock ----------------------------------------------------------
518 
519   // Represents the number of ScopedRedrawLocks active against this widget.
520   // If this is greater than zero, the widget should be locked against updates.
521   int lock_updates_count_;
522 
523   // Window resizing -----------------------------------------------------------
524 
525   // When true, this flag makes us discard incoming SetWindowPos() requests that
526   // only change our position/size.  (We still allow changes to Z-order,
527   // activation, etc.)
528   bool ignore_window_pos_changes_;
529 
530   // The last-seen monitor containing us, and its rect and work area.  These are
531   // used to catch updates to the rect and work area and react accordingly.
532   HMONITOR last_monitor_;
533   gfx::Rect last_monitor_rect_, last_work_area_;
534 
535   // Layered windows -----------------------------------------------------------
536 
537   // Should we keep an off-screen buffer? This is false by default, set to true
538   // when WS_EX_LAYERED is specified before the native window is created.
539   //
540   // NOTE: this is intended to be used with a layered window (a window with an
541   // extended window style of WS_EX_LAYERED). If you are using a layered window
542   // and NOT changing the layered alpha or anything else, then leave this value
543   // alone. OTOH if you are invoking SetLayeredWindowAttributes then you'll
544   // most likely want to set this to false, or after changing the alpha toggle
545   // the extended style bit to false than back to true. See MSDN for more
546   // details.
547   bool use_layered_buffer_;
548 
549   // The default alpha to be applied to the layered window.
550   BYTE layered_alpha_;
551 
552   // A canvas that contains the window contents in the case of a layered
553   // window.
554   scoped_ptr<gfx::Canvas> layered_window_contents_;
555 
556   // We must track the invalid rect ourselves, for two reasons:
557   // For layered windows, Windows will not do this properly with
558   // InvalidateRect()/GetUpdateRect(). (In fact, it'll return misleading
559   // information from GetUpdateRect()).
560   // We also need to keep track of the invalid rectangle for the RootView should
561   // we need to paint the non-client area. The data supplied to WM_NCPAINT seems
562   // to be insufficient.
563   gfx::Rect invalid_rect_;
564 
565   // Set to true when waiting for RedrawLayeredWindowContents().
566   bool waiting_for_redraw_layered_window_contents_;
567 
568   // True the first time nccalc is called on a sizable widget
569   bool is_first_nccalc_;
570 
571   // Copy of custom window region specified via SetRegion(), if any.
572   base::win::ScopedRegion custom_window_region_;
573 
574   // If > 0 indicates a menu is running (we're showing a native menu).
575   int menu_depth_;
576 
577   // A factory used to lookup appbar autohide edges.
578   base::WeakPtrFactory<HWNDMessageHandler> autohide_factory_;
579 
580   // Generates touch-ids for touch-events.
581   ui::SequentialIDGenerator id_generator_;
582 
583   // Indicates if the window needs the WS_VSCROLL and WS_HSCROLL styles.
584   bool needs_scroll_styles_;
585 
586   // Set to true if we are in the context of a sizing operation.
587   bool in_size_loop_;
588 
589   // Stores a pointer to the WindowEventTarget interface implemented by this
590   // class. Allows callers to retrieve the interface pointer.
591   scoped_ptr<ui::ViewProp> prop_window_target_;
592 
593   // Number of active touch down contexts. This is incremented on touch down
594   // events and decremented later using a delayed task.
595   // We need this to ignore WM_MOUSEACTIVATE messages generated in response to
596   // touch input. This is fine because activation still works correctly via
597   // native SetFocus calls invoked in the views code.
598   int touch_down_contexts_;
599 
600   // Time the last touch message was received. Used to flag mouse messages
601   // synthesized by Windows for touch which are not flagged by the OS as
602   // synthesized mouse messages. For more information please refer to
603   // the IsMouseEventFromTouch function.
604   static long last_touch_message_time_;
605 
606   // Time the last WM_MOUSEHWHEEL message is received. Please refer to the
607   // HandleMouseEventInternal function as to why this is needed.
608   long last_mouse_hwheel_time_;
609 
610   DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler);
611 };
612 
613 }  // namespace views
614 
615 #endif  // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_
616