| 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_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 <array> | 10 #include <set> |
| 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" | |
| 25 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
| 26 #include "ui/gfx/sequential_id_generator.h" | 25 #include "ui/gfx/sequential_id_generator.h" |
| 27 #include "ui/gfx/win/window_impl.h" | 26 #include "ui/gfx/win/window_impl.h" |
| 28 #include "ui/views/ime/input_method_delegate.h" | 27 #include "ui/views/ime/input_method_delegate.h" |
| 29 #include "ui/views/views_export.h" | 28 #include "ui/views/views_export.h" |
| 30 | 29 |
| 31 namespace gfx { | 30 namespace gfx { |
| 32 class Canvas; | 31 class Canvas; |
| 33 class ImageSkia; | 32 class ImageSkia; |
| 34 class Insets; | 33 class Insets; |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 void set_use_system_default_icon(bool use_system_default_icon) { | 199 void set_use_system_default_icon(bool use_system_default_icon) { |
| 201 use_system_default_icon_ = use_system_default_icon; | 200 use_system_default_icon_ = use_system_default_icon; |
| 202 } | 201 } |
| 203 | 202 |
| 204 void SetFullscreen(bool fullscreen); | 203 void SetFullscreen(bool fullscreen); |
| 205 | 204 |
| 206 // Updates the window style to reflect whether it can be resized or maximized. | 205 // Updates the window style to reflect whether it can be resized or maximized. |
| 207 void SizeConstraintsChanged(); | 206 void SizeConstraintsChanged(); |
| 208 | 207 |
| 209 private: | 208 private: |
| 210 FRIEND_TEST_ALL_PREFIXES(HWNDMessageHandler, TestCorrectTouchInputList); | 209 typedef std::set<DWORD> TouchIDs; |
| 211 FRIEND_TEST_ALL_PREFIXES(HWNDMessageHandler, TestCombineTouchMoveAndUp); | |
| 212 FRIEND_TEST_ALL_PREFIXES(HWNDMessageHandler, TestMissingTouchRelease); | |
| 213 | |
| 214 // We use InTouchList self-defined type to specify if the touch point from | |
| 215 // last message is in the current message or not. | |
| 216 enum class InTouchList { NotPresent, InPreviousMessage, InCurrentMessage }; | |
| 217 | |
| 218 // We need the touch location to release a touch point which is not in the | |
| 219 // current message. | |
| 220 struct TouchPoint { | |
| 221 gfx::Point location; | |
| 222 InTouchList in_touch_list; | |
| 223 | |
| 224 TouchPoint() : in_touch_list(InTouchList::NotPresent) {} | |
| 225 }; | |
| 226 | |
| 227 using TouchEvents = std::vector<ui::TouchEvent>; | |
| 228 using TouchPointArray = | |
| 229 std::array<TouchPoint, ui::MotionEvent::MAX_TOUCH_POINT_COUNT>; | |
| 230 | 210 |
| 231 // Overridden from internal::InputMethodDelegate: | 211 // Overridden from internal::InputMethodDelegate: |
| 232 void DispatchKeyEventPostIME(const ui::KeyEvent& key) override; | 212 void DispatchKeyEventPostIME(const ui::KeyEvent& key) override; |
| 233 | 213 |
| 234 // Overridden from WindowImpl: | 214 // Overridden from WindowImpl: |
| 235 HICON GetDefaultWindowIcon() const override; | 215 HICON GetDefaultWindowIcon() const override; |
| 236 HICON GetSmallWindowIcon() const override; | 216 HICON GetSmallWindowIcon() const override; |
| 237 LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) override; | 217 LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) override; |
| 238 | 218 |
| 239 // Overridden from WindowEventTarget | 219 // Overridden from WindowEventTarget |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 void OnSize(UINT param, const gfx::Size& size); | 446 void OnSize(UINT param, const gfx::Size& size); |
| 467 void OnSysCommand(UINT notification_code, const gfx::Point& point); | 447 void OnSysCommand(UINT notification_code, const gfx::Point& point); |
| 468 void OnThemeChanged(); | 448 void OnThemeChanged(); |
| 469 LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param); | 449 LRESULT OnTouchEvent(UINT message, WPARAM w_param, LPARAM l_param); |
| 470 void OnWindowPosChanging(WINDOWPOS* window_pos); | 450 void OnWindowPosChanging(WINDOWPOS* window_pos); |
| 471 void OnWindowPosChanged(WINDOWPOS* window_pos); | 451 void OnWindowPosChanged(WINDOWPOS* window_pos); |
| 472 | 452 |
| 473 // Receives Windows Session Change notifications. | 453 // Receives Windows Session Change notifications. |
| 474 void OnSessionChange(WPARAM status_code); | 454 void OnSessionChange(WPARAM status_code); |
| 475 | 455 |
| 456 typedef std::vector<ui::TouchEvent> TouchEvents; |
| 476 // Helper to handle the list of touch events passed in. We need this because | 457 // Helper to handle the list of touch events passed in. We need this because |
| 477 // touch events on windows don't fire if we enter a modal loop in the context | 458 // touch events on windows don't fire if we enter a modal loop in the context |
| 478 // of a touch event. | 459 // of a touch event. |
| 479 void HandleTouchEvents(const TouchEvents& touch_events); | 460 void HandleTouchEvents(const TouchEvents& touch_events); |
| 480 | 461 |
| 481 // Resets the flag which indicates that we are in the context of a touch down | 462 // Resets the flag which indicates that we are in the context of a touch down |
| 482 // event. | 463 // event. |
| 483 void DecrementTouchDownContext(int decrement); | 464 void ResetTouchDownContext(); |
| 484 | 465 |
| 485 // Helper to handle mouse events. | 466 // Helper to handle mouse events. |
| 486 // The |message|, |w_param|, |l_param| parameters identify the Windows mouse | 467 // The |message|, |w_param|, |l_param| parameters identify the Windows mouse |
| 487 // message and its parameters respectively. | 468 // message and its parameters respectively. |
| 488 // The |track_mouse| parameter indicates if we should track the mouse. | 469 // The |track_mouse| parameter indicates if we should track the mouse. |
| 489 LRESULT HandleMouseEventInternal(UINT message, | 470 LRESULT HandleMouseEventInternal(UINT message, |
| 490 WPARAM w_param, | 471 WPARAM w_param, |
| 491 LPARAM l_param, | 472 LPARAM l_param, |
| 492 bool track_mouse); | 473 bool track_mouse); |
| 493 | 474 |
| 494 // Returns true if the mouse message passed in is an OS synthesized mouse | 475 // Returns true if the mouse message passed in is an OS synthesized mouse |
| 495 // message. | 476 // message. |
| 496 // |message| identifies the mouse message. | 477 // |message| identifies the mouse message. |
| 497 // |message_time| is the time when the message occurred. | 478 // |message_time| is the time when the message occurred. |
| 498 // |l_param| indicates the location of the mouse message. | 479 // |l_param| indicates the location of the mouse message. |
| 499 bool IsSynthesizedMouseMessage(unsigned int message, | 480 bool IsSynthesizedMouseMessage(unsigned int message, |
| 500 int message_time, | 481 int message_time, |
| 501 LPARAM l_param); | 482 LPARAM l_param); |
| 502 | 483 |
| 503 // Provides functionality to transition a frame to DWM. | 484 // Provides functionality to transition a frame to DWM. |
| 504 void PerformDwmTransition(); | 485 void PerformDwmTransition(); |
| 505 | 486 |
| 506 void PrepareTouchEventList(TOUCHINPUT input[], | |
| 507 int num_points, | |
| 508 TouchEvents* touch_events); | |
| 509 | |
| 510 // From one WM_TOUCH message, we will generate corresponding touch events. | |
| 511 void GenerateTouchEvent(DWORD input_dwID, | |
| 512 const gfx::Point& point_location, | |
| 513 ui::EventType touch_event_type, | |
| 514 TouchEvents* touch_events); | |
| 515 | |
| 516 // It will release the touch points which are no longer in the current message | |
| 517 // because the messages are sent inconsistently, and also set the touch points | |
| 518 // we have seen in the current message to be InPreviousMessage. | |
| 519 void UpdateTouchPointStates(TouchEvents* touch_events); | |
| 520 | |
| 521 const TouchPointArray& touch_id_list() const { return touch_id_list_; } | |
| 522 | |
| 523 HWNDMessageHandlerDelegate* delegate_; | 487 HWNDMessageHandlerDelegate* delegate_; |
| 524 | 488 |
| 525 scoped_ptr<FullscreenHandler> fullscreen_handler_; | 489 scoped_ptr<FullscreenHandler> fullscreen_handler_; |
| 526 | 490 |
| 527 // Set to true in Close() and false is CloseNow(). | 491 // Set to true in Close() and false is CloseNow(). |
| 528 bool waiting_for_close_now_; | 492 bool waiting_for_close_now_; |
| 529 | 493 |
| 530 bool remove_standard_frame_; | 494 bool remove_standard_frame_; |
| 531 | 495 |
| 532 bool use_system_default_icon_; | 496 bool use_system_default_icon_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 546 | 510 |
| 547 // The flags currently being used with TrackMouseEvent to track mouse | 511 // The flags currently being used with TrackMouseEvent to track mouse |
| 548 // messages. 0 if there is no active tracking. The value of this member is | 512 // messages. 0 if there is no active tracking. The value of this member is |
| 549 // used when tracking is canceled. | 513 // used when tracking is canceled. |
| 550 DWORD active_mouse_tracking_flags_; | 514 DWORD active_mouse_tracking_flags_; |
| 551 | 515 |
| 552 // Set to true when the user presses the right mouse button on the caption | 516 // Set to true when the user presses the right mouse button on the caption |
| 553 // area. We need this so we can correctly show the context menu on mouse-up. | 517 // area. We need this so we can correctly show the context menu on mouse-up. |
| 554 bool is_right_mouse_pressed_on_caption_; | 518 bool is_right_mouse_pressed_on_caption_; |
| 555 | 519 |
| 520 // The set of touch devices currently down. |
| 521 TouchIDs touch_ids_; |
| 522 |
| 556 // ScopedRedrawLock ---------------------------------------------------------- | 523 // ScopedRedrawLock ---------------------------------------------------------- |
| 557 | 524 |
| 558 // Represents the number of ScopedRedrawLocks active against this widget. | 525 // Represents the number of ScopedRedrawLocks active against this widget. |
| 559 // If this is greater than zero, the widget should be locked against updates. | 526 // If this is greater than zero, the widget should be locked against updates. |
| 560 int lock_updates_count_; | 527 int lock_updates_count_; |
| 561 | 528 |
| 562 // Window resizing ----------------------------------------------------------- | 529 // Window resizing ----------------------------------------------------------- |
| 563 | 530 |
| 564 // When true, this flag makes us discard incoming SetWindowPos() requests that | 531 // When true, this flag makes us discard incoming SetWindowPos() requests that |
| 565 // only change our position/size. (We still allow changes to Z-order, | 532 // only change our position/size. (We still allow changes to Z-order, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 // to Aero(glass) we delay setting the DWM related properties in full | 581 // to Aero(glass) we delay setting the DWM related properties in full |
| 615 // screen mode as DWM is not supported in full screen windows. We perform | 582 // screen mode as DWM is not supported in full screen windows. We perform |
| 616 // the DWM related operations when the window comes out of fullscreen mode. | 583 // the DWM related operations when the window comes out of fullscreen mode. |
| 617 // This member variable is set to true if the window is transitioning to | 584 // This member variable is set to true if the window is transitioning to |
| 618 // glass. Defaults to false. | 585 // glass. Defaults to false. |
| 619 bool dwm_transition_desired_; | 586 bool dwm_transition_desired_; |
| 620 | 587 |
| 621 // Manages observation of Windows Session Change messages. | 588 // Manages observation of Windows Session Change messages. |
| 622 scoped_ptr<WindowsSessionChangeObserver> windows_session_change_observer_; | 589 scoped_ptr<WindowsSessionChangeObserver> windows_session_change_observer_; |
| 623 | 590 |
| 624 // HWND Message sometimes sends inconsistent number of touch pointers, so we | |
| 625 // keep the IDs of touch pointers we have seen from last message, and compare | |
| 626 // with the current message in order to release the ones which are not in the | |
| 627 // current list, or send a touchpress when we see a new touch point. The | |
| 628 // index of the array is the touch_ID. | |
| 629 TouchPointArray touch_id_list_; | |
| 630 | |
| 631 // Keep the count of the current active touch points. | |
| 632 int active_touch_point_count_; | |
| 633 | |
| 634 // The WeakPtrFactories below must occur last in the class definition so they | 591 // The WeakPtrFactories below must occur last in the class definition so they |
| 635 // get destroyed last. | 592 // get destroyed last. |
| 636 | 593 |
| 637 // The factory used to lookup appbar autohide edges. | 594 // The factory used to lookup appbar autohide edges. |
| 638 base::WeakPtrFactory<HWNDMessageHandler> autohide_factory_; | 595 base::WeakPtrFactory<HWNDMessageHandler> autohide_factory_; |
| 639 | 596 |
| 640 // The factory used with BEGIN_SAFE_MSG_MAP_EX. | 597 // The factory used with BEGIN_SAFE_MSG_MAP_EX. |
| 641 base::WeakPtrFactory<HWNDMessageHandler> weak_factory_; | 598 base::WeakPtrFactory<HWNDMessageHandler> weak_factory_; |
| 642 | 599 |
| 643 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler); | 600 DISALLOW_COPY_AND_ASSIGN(HWNDMessageHandler); |
| 644 }; | 601 }; |
| 645 | 602 |
| 646 } // namespace views | 603 } // namespace views |
| 647 | 604 |
| 648 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ | 605 #endif // UI_VIEWS_WIN_HWND_MESSAGE_HANDLER_H_ |
| OLD | NEW |