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

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

Issue 988473002: Correctly release the touch events on Lenovo Horizon device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 <windows.h> 8 #include <windows.h>
9 9
10 #include <set> 10 #include <array>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
18 #include "base/win/scoped_gdi_object.h" 18 #include "base/win/scoped_gdi_object.h"
19 #include "base/win/win_util.h" 19 #include "base/win/win_util.h"
20 #include "ui/accessibility/ax_enums.h" 20 #include "ui/accessibility/ax_enums.h"
21 #include "ui/base/ui_base_types.h" 21 #include "ui/base/ui_base_types.h"
22 #include "ui/base/win/window_event_target.h" 22 #include "ui/base/win/window_event_target.h"
23 #include "ui/events/event.h" 23 #include "ui/events/event.h"
24 #include "ui/events/gesture_detection/motion_event.h"
24 #include "ui/gfx/geometry/rect.h" 25 #include "ui/gfx/geometry/rect.h"
25 #include "ui/gfx/sequential_id_generator.h" 26 #include "ui/gfx/sequential_id_generator.h"
26 #include "ui/gfx/win/window_impl.h" 27 #include "ui/gfx/win/window_impl.h"
27 #include "ui/views/ime/input_method_delegate.h" 28 #include "ui/views/ime/input_method_delegate.h"
28 #include "ui/views/views_export.h" 29 #include "ui/views/views_export.h"
29 30
30 namespace gfx { 31 namespace gfx {
31 class Canvas; 32 class Canvas;
32 class ImageSkia; 33 class ImageSkia;
33 class Insets; 34 class Insets;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 void set_use_system_default_icon(bool use_system_default_icon) { 202 void set_use_system_default_icon(bool use_system_default_icon) {
202 use_system_default_icon_ = use_system_default_icon; 203 use_system_default_icon_ = use_system_default_icon;
203 } 204 }
204 205
205 void SetFullscreen(bool fullscreen); 206 void SetFullscreen(bool fullscreen);
206 207
207 // Updates the window style to reflect whether it can be resized or maximized. 208 // Updates the window style to reflect whether it can be resized or maximized.
208 void SizeConstraintsChanged(); 209 void SizeConstraintsChanged();
209 210
210 private: 211 private:
211 typedef std::set<DWORD> TouchIDs; 212 FRIEND_TEST_ALL_PREFIXES(HWNDMessageHandler, TestCorrectTouchInputList);
213 FRIEND_TEST_ALL_PREFIXES(HWNDMessageHandler, TestMissingTouchRelease);
214 FRIEND_TEST_ALL_PREFIXES(HWNDMessageHandler, TestMissingTouchPress);
215 FRIEND_TEST_ALL_PREFIXES(HWNDMessageHandler, TestMissingTouchPressAndRelease);
216
217 // We use InTouchList self-defined type to specify if the touch point from
218 // last message is in the current message or not.
219 enum class InTouchList { NotPresent, InPreviousMessage, InCurrentMessage };
220
221 // We need the touch location to release a touch point which is not in the
222 // current message.
223 struct TouchPoint {
224 gfx::Point location;
225 InTouchList in_touch_list;
226
227 TouchPoint() : in_touch_list(InTouchList::NotPresent) {}
228 };
229
230 using TouchEvents = std::vector<ui::TouchEvent>;
231 using TouchPointArray =
232 std::array<TouchPoint, ui::MotionEvent::MAX_TOUCH_POINT_COUNT>;
212 233
213 // Overridden from internal::InputMethodDelegate: 234 // Overridden from internal::InputMethodDelegate:
214 void DispatchKeyEventPostIME(const ui::KeyEvent& key) override; 235 void DispatchKeyEventPostIME(const ui::KeyEvent& key) override;
215 236
216 // Overridden from WindowImpl: 237 // Overridden from WindowImpl:
217 HICON GetDefaultWindowIcon() const override; 238 HICON GetDefaultWindowIcon() const override;
218 HICON GetSmallWindowIcon() const override; 239 HICON GetSmallWindowIcon() const override;
219 LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) override; 240 LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) override;
220 241
221 // Overridden from WindowEventTarget 242 // Overridden from WindowEventTarget
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 LRESULT OnSetIcon(UINT size_type, HICON new_icon); 472 LRESULT OnSetIcon(UINT size_type, HICON new_icon);
452 LRESULT OnSetText(const wchar_t* text); 473 LRESULT OnSetText(const wchar_t* text);
453 void OnSettingChange(UINT flags, const wchar_t* section); 474 void OnSettingChange(UINT flags, const wchar_t* section);
454 void OnSize(UINT param, const gfx::Size& size); 475 void OnSize(UINT param, const gfx::Size& size);
455 void OnSysCommand(UINT notification_code, const gfx::Point& point); 476 void OnSysCommand(UINT notification_code, const gfx::Point& point);
456 void OnThemeChanged(); 477 void OnThemeChanged();
457 LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param); 478 LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param);
458 void OnWindowPosChanging(WINDOWPOS* window_pos); 479 void OnWindowPosChanging(WINDOWPOS* window_pos);
459 void OnWindowPosChanged(WINDOWPOS* window_pos); 480 void OnWindowPosChanged(WINDOWPOS* window_pos);
460 481
461 typedef std::vector<ui::TouchEvent> TouchEvents;
462 // Helper to handle the list of touch events passed in. We need this because 482 // Helper to handle the list of touch events passed in. We need this because
463 // touch events on windows don't fire if we enter a modal loop in the context 483 // touch events on windows don't fire if we enter a modal loop in the context
464 // of a touch event. 484 // of a touch event.
465 void HandleTouchEvents(const TouchEvents& touch_events); 485 void HandleTouchEvents(const TouchEvents& touch_events);
466 486
467 // Resets the flag which indicates that we are in the context of a touch down 487 // Resets the flag which indicates that we are in the context of a touch down
468 // event. 488 // event.
469 void ResetTouchDownContext(); 489 void DecrementTouchDownContext(int decrement);
470 490
471 // Helper to handle mouse events. 491 // Helper to handle mouse events.
472 // The |message|, |w_param|, |l_param| parameters identify the Windows mouse 492 // The |message|, |w_param|, |l_param| parameters identify the Windows mouse
473 // message and its parameters respectively. 493 // message and its parameters respectively.
474 // The |track_mouse| parameter indicates if we should track the mouse. 494 // The |track_mouse| parameter indicates if we should track the mouse.
475 LRESULT HandleMouseEventInternal(UINT message, 495 LRESULT HandleMouseEventInternal(UINT message,
476 WPARAM w_param, 496 WPARAM w_param,
477 LPARAM l_param, 497 LPARAM l_param,
478 bool track_mouse); 498 bool track_mouse);
479 499
480 // Returns true if the mouse message passed in is an OS synthesized mouse 500 // Returns true if the mouse message passed in is an OS synthesized mouse
481 // message. 501 // message.
482 // |message| identifies the mouse message. 502 // |message| identifies the mouse message.
483 // |message_time| is the time when the message occurred. 503 // |message_time| is the time when the message occurred.
484 // |l_param| indicates the location of the mouse message. 504 // |l_param| indicates the location of the mouse message.
485 bool IsSynthesizedMouseMessage(unsigned int message, 505 bool IsSynthesizedMouseMessage(unsigned int message,
486 int message_time, 506 int message_time,
487 LPARAM l_param); 507 LPARAM l_param);
488 508
489 // Provides functionality to transition a frame to DWM. 509 // Provides functionality to transition a frame to DWM.
490 void PerformDwmTransition(); 510 void PerformDwmTransition();
491 511
512 void PrepareTouchEventList(TOUCHINPUT input[],
513 int num_points,
514 TouchEvents* touch_events);
515
516 // From one WM_TOUCH message, we will generate corresponding touch events.
517 void GenerateTouchEvent(DWORD input_dwID,
518 const gfx::Point& point_location,
519 ui::EventType touch_event_type,
520 TouchEvents* touch_events);
521
522 // It will release the touch points which are no longer in the current message
523 // because the messages are sent inconsistently, and also set the touch points
524 // we have seen in the current message to be InPreviousMessage.
525 void UpdateTouchPointStates(TouchEvents* touch_events);
526
527 const TouchPointArray& touch_id_list() const { return touch_id_list_; }
528
492 HWNDMessageHandlerDelegate* delegate_; 529 HWNDMessageHandlerDelegate* delegate_;
493 530
494 scoped_ptr<FullscreenHandler> fullscreen_handler_; 531 scoped_ptr<FullscreenHandler> fullscreen_handler_;
495 532
496 // Set to true in Close() and false is CloseNow(). 533 // Set to true in Close() and false is CloseNow().
497 bool waiting_for_close_now_; 534 bool waiting_for_close_now_;
498 535
499 bool remove_standard_frame_; 536 bool remove_standard_frame_;
500 537
501 bool use_system_default_icon_; 538 bool use_system_default_icon_;
(...skipping 13 matching lines...) Expand all
515 552
516 // The flags currently being used with TrackMouseEvent to track mouse 553 // The flags currently being used with TrackMouseEvent to track mouse
517 // messages. 0 if there is no active tracking. The value of this member is 554 // messages. 0 if there is no active tracking. The value of this member is
518 // used when tracking is canceled. 555 // used when tracking is canceled.
519 DWORD active_mouse_tracking_flags_; 556 DWORD active_mouse_tracking_flags_;
520 557
521 // Set to true when the user presses the right mouse button on the caption 558 // Set to true when the user presses the right mouse button on the caption
522 // area. We need this so we can correctly show the context menu on mouse-up. 559 // area. We need this so we can correctly show the context menu on mouse-up.
523 bool is_right_mouse_pressed_on_caption_; 560 bool is_right_mouse_pressed_on_caption_;
524 561
525 // The set of touch devices currently down.
526 TouchIDs touch_ids_;
527
528 // ScopedRedrawLock ---------------------------------------------------------- 562 // ScopedRedrawLock ----------------------------------------------------------
529 563
530 // Represents the number of ScopedRedrawLocks active against this widget. 564 // Represents the number of ScopedRedrawLocks active against this widget.
531 // If this is greater than zero, the widget should be locked against updates. 565 // If this is greater than zero, the widget should be locked against updates.
532 int lock_updates_count_; 566 int lock_updates_count_;
533 567
534 // Window resizing ----------------------------------------------------------- 568 // Window resizing -----------------------------------------------------------
535 569
536 // When true, this flag makes us discard incoming SetWindowPos() requests that 570 // When true, this flag makes us discard incoming SetWindowPos() requests that
537 // only change our position/size. (We still allow changes to Z-order, 571 // only change our position/size. (We still allow changes to Z-order,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 long last_mouse_hwheel_time_; 650 long last_mouse_hwheel_time_;
617 651
618 // On Windows Vista and beyond, if we are transitioning from custom frame 652 // On Windows Vista and beyond, if we are transitioning from custom frame
619 // to Aero(glass) we delay setting the DWM related properties in full 653 // to Aero(glass) we delay setting the DWM related properties in full
620 // screen mode as DWM is not supported in full screen windows. We perform 654 // screen mode as DWM is not supported in full screen windows. We perform
621 // the DWM related operations when the window comes out of fullscreen mode. 655 // the DWM related operations when the window comes out of fullscreen mode.
622 // This member variable is set to true if the window is transitioning to 656 // This member variable is set to true if the window is transitioning to
623 // glass. Defaults to false. 657 // glass. Defaults to false.
624 bool dwm_transition_desired_; 658 bool dwm_transition_desired_;
625 659
660 // The WM_TOUCH message at times sends inconsistent number of touch pointers,
661 // so we keep the IDs of touch pointers we have seen from last message, and
662 // compare with the current message in order to release the ones which are not
663 // in the current list, or send a touchpress when we see a new touch point.
664 // The index of the array is the touch_ID.
665 TouchPointArray touch_id_list_;
666
667 // Keep the count of the current active touch points.
668 int active_touch_point_count_;
669
626 // A factory used to lookup appbar autohide edges. 670 // A factory used to lookup appbar autohide edges.
627 base::WeakPtrFactory<HWNDMessageHandler> autohide_factory_; 671 base::WeakPtrFactory<HWNDMessageHandler> autohide_factory_;
628 672
629 // The factory used with BEGIN_SAFE_MSG_MAP_EX. 673 // The factory used with BEGIN_SAFE_MSG_MAP_EX.
630 base::WeakPtrFactory<HWNDMessageHandler> weak_factory_; 674 base::WeakPtrFactory<HWNDMessageHandler> weak_factory_;
631 675
632 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler); 676 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler);
633 }; 677 };
634 678
635 } // namespace views 679 } // namespace views
636 680
637 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ 681 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698