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

Issue 1143283002: Revert of Correctly release the touch events on Lenovo Horizon device (Closed)

Created:
5 years, 7 months ago by lanwei
Modified:
5 years, 7 months ago
Reviewers:
girard, sadrul, ananta, tdresser
CC:
chromium-reviews, tfarina
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Revert of Correctly release the touch events on Lenovo Horizon device (patchset #17 id:1140001 of https://codereview.chromium.org/988473002/) Reason for revert: It causes crash and some regression for touches on Windows 8. We will recommit it once we fully fix and test it. Original issue's description: > Correctly release the touch events on Lenovo Horizon device. > > The Lenovo Horizon device displays the wrong number of the touch pointers when all fingers released from the screen. Because HWND Message sometimes sends inconsistent number of touch pointers, we keep the IDs of touch pointers we have seen from last time, and release the ones which are not in the current message. > > BUG=316085 > > Committed: https://crrev.com/a2a44ba54fe134526dc81014991f951c1fb09db1 > Cr-Commit-Position: refs/heads/master@{#329770} TBR=tdresser@chromium.org,sadrul@chromium.org,ananta@chromium.org,girard@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=316085

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+55 lines, -340 lines) Patch
M ui/views/views.gyp View 1 chunk +0 lines, -1 line 0 comments Download
M ui/views/win/hwnd_message_handler.h View 8 chunks +7 lines, -50 lines 0 comments Download
M ui/views/win/hwnd_message_handler.cc View 6 chunks +48 lines, -113 lines 0 comments Download
D ui/views/win/hwnd_message_handler_unittest.cc View 1 chunk +0 lines, -176 lines 0 comments Download

Messages

Total messages: 7 (4 generated)
lanwei
Created Revert of Correctly release the touch events on Lenovo Horizon device
5 years, 7 months ago (2015-05-20 17:17:23 UTC) #1
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1143283002/1
5 years, 7 months ago (2015-05-20 17:18:17 UTC) #2
commit-bot: I haz the power
5 years, 7 months ago (2015-05-20 17:19:18 UTC) #4
Failed to apply patch for ui/views/win/hwnd_message_handler.cc:
While running git apply --index -3 -p1;
  error: patch failed: ui/views/win/hwnd_message_handler.cc:2337
  Falling back to three-way merge...
  Applied patch to 'ui/views/win/hwnd_message_handler.cc' with conflicts.
  U ui/views/win/hwnd_message_handler.cc

Patch:       ui/views/win/hwnd_message_handler.cc
Index: ui/views/win/hwnd_message_handler.cc
diff --git a/ui/views/win/hwnd_message_handler.cc
b/ui/views/win/hwnd_message_handler.cc
index
cb34bbe7999d9a4412b27e04a1656cc2265a5d2d..b48a4db5ddb2d27be422bc3af4cf0ca18a0701a8
100644
--- a/ui/views/win/hwnd_message_handler.cc
+++ b/ui/views/win/hwnd_message_handler.cc
@@ -10,7 +10,6 @@
 
 #include "base/bind.h"
 #include "base/bind_helpers.h"
-#include "base/logging.h"
 #include "base/profiler/scoped_tracker.h"
 #include "base/trace_event/trace_event.h"
 #include "base/tracked_objects.h"
@@ -329,7 +328,6 @@
       last_mouse_hwheel_time_(0),
       msg_handled_(FALSE),
       dwm_transition_desired_(false),
-      active_touch_point_count_(0),
       autohide_factory_(this),
       weak_factory_(this) {
 }
@@ -2299,6 +2297,8 @@
   if (ui::GetTouchInputInfoWrapper(reinterpret_cast<HTOUCHINPUT>(l_param),
                                    num_points, input.get(),
                                    sizeof(TOUCHINPUT))) {
+    int flags = ui::GetModifiersFromKeyState();
+    TouchEvents touch_events;
     for (int i = 0; i < num_points; ++i) {
       POINT point;
       point.x = TOUCH_COORD_TO_PIXEL(input[i].x);
@@ -2314,18 +2314,50 @@
         if (hittest != HTCLIENT)
           return 0;
       }
+
+      ScreenToClient(hwnd(), &point);
+
+      last_touch_message_time_ = ::GetMessageTime();
+
+      ui::EventType touch_event_type = ui::ET_UNKNOWN;
+
+      if (input[i].dwFlags & TOUCHEVENTF_DOWN) {
+        touch_ids_.insert(input[i].dwID);
+        touch_event_type = ui::ET_TOUCH_PRESSED;
+        touch_down_contexts_++;
+        base::MessageLoop::current()->PostDelayedTask(
+            FROM_HERE,
+            base::Bind(&HWNDMessageHandler::ResetTouchDownContext,
+                       weak_factory_.GetWeakPtr()),
+            base::TimeDelta::FromMilliseconds(kTouchDownContextResetTimeout));
+      } else if (input[i].dwFlags & TOUCHEVENTF_UP) {
+        touch_ids_.erase(input[i].dwID);
+        touch_event_type = ui::ET_TOUCH_RELEASED;
+      } else if (input[i].dwFlags & TOUCHEVENTF_MOVE) {
+        touch_event_type = ui::ET_TOUCH_MOVED;
+      }
+      if (touch_event_type != ui::ET_UNKNOWN) {
+        // input[i].dwTime doesn't necessarily relate to the system time at
all,
+        // so use base::TimeTicks::Now()
+        const base::TimeTicks now = base::TimeTicks::Now();
+        ui::TouchEvent event(touch_event_type,
+                             gfx::Point(point.x, point.y),
+                             id_generator_.GetGeneratedID(input[i].dwID),
+                             now - base::TimeTicks());
+        event.set_flags(flags);
+        event.latency()->AddLatencyNumberWithTimestamp(
+            ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
+            0,
+            0,
+            base::TimeTicks::FromInternalValue(
+                event.time_stamp().ToInternalValue()),
+            1);
+
+        touch_events.push_back(event);
+        if (touch_event_type == ui::ET_TOUCH_RELEASED)
+          id_generator_.ReleaseNumber(input[i].dwID);
+      }
     }
-    TouchEvents touch_events;
-    int old_touch_down_contexts = touch_down_contexts_;
-    PrepareTouchEventList(input.get(), num_points, &touch_events);
-    int new_touch_presses = touch_down_contexts_ - old_touch_down_contexts;
-    if (new_touch_presses > 0) {
-      base::MessageLoop::current()->PostDelayedTask(
-          FROM_HERE, base::Bind(&HWNDMessageHandler::DecrementTouchDownContext,
-                                weak_factory_.GetWeakPtr(), new_touch_presses),
-          base::TimeDelta::FromMilliseconds(kTouchDownContextResetTimeout));
-    }
-
     // Handle the touch events asynchronously. We need this because touch
     // events on windows don't fire if we enter a modal loop in the context of
     // a touch event.
@@ -2337,103 +2369,6 @@
   CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(l_param));
   SetMsgHandled(FALSE);
   return 0;
-}
-
-void HWNDMessageHandler::PrepareTouchEventList(TOUCHINPUT input[],
-                                               int num_points,
-                                               TouchEvents* touch_events) {
-  for (int i = 0; i < num_points; ++i) {
-    POINT point;
-    point.x = TOUCH_COORD_TO_PIXEL(input[i].x);
-    point.y = TOUCH_COORD_TO_PIXEL(input[i].y);
-    gfx::Point point_location(point.x, point.y);
-
-    ScreenToClient(hwnd(), &point);
-
-    // TOUCHEVENTF_DOWN cannot be combined with TOUCHEVENTF_MOVE or
-    // TOUCHEVENTF_UP, but TOUCHEVENTF_MOVE and TOUCHEVENTF_UP can be combined
-    // in one input.
-    if (input[i].dwFlags & TOUCHEVENTF_DOWN) {
-      touch_down_contexts_++;
-      active_touch_point_count_++;
-      GenerateTouchEvent(input[i].dwID, point_location, ui::ET_TOUCH_PRESSED,
-                         touch_events);
-    } else {
-      if (input[i].dwFlags & TOUCHEVENTF_MOVE) {
-        GenerateTouchEvent(input[i].dwID, point_location, ui::ET_TOUCH_MOVED,
-                           touch_events);
-      }
-      if (input[i].dwFlags & TOUCHEVENTF_UP) {
-        active_touch_point_count_--;
-        GenerateTouchEvent(input[i].dwID, point_location,
ui::ET_TOUCH_RELEASED,
-                           touch_events);
-      }
-    }
-  }
-  last_touch_message_time_ = ::GetMessageTime();
-
-  UpdateTouchPointStates(touch_events);
-}
-
-void HWNDMessageHandler::GenerateTouchEvent(DWORD input_dwID,
-                                            const gfx::Point& point_location,
-                                            ui::EventType touch_event_type,
-                                            TouchEvents* touch_events) {
-  int touch_id = static_cast<int>(id_generator_.GetGeneratedID(input_dwID));
-  if (touch_id < 0 || touch_id >= static_cast<int>(touch_id_list_.size())) {
-    return;
-  }
-
-  TouchPoint& touch_point = touch_id_list_[touch_id];
-  int flags = ui::GetModifiersFromKeyState();
-
-  // The dwTime of every input in the WM_TOUCH message doesn't necessarily
-  // relate to the system time at all, so use base::TimeTicks::Now() for
-  // touchevent time.
-  base::TimeDelta now = ui::EventTimeForNow();
-
-  // We set a check to assert that we do not have missing touch presses in
-  // every message.
-  bool has_missing_touch_press = touch_event_type != ui::ET_TOUCH_PRESSED &&
-      touch_point.in_touch_list == InTouchList::NotPresent;
-  CHECK(!has_missing_touch_press) << "There are missing touch presses";
-
-  ui::TouchEvent event(touch_event_type, point_location, touch_id, now);
-  event.set_flags(flags);
-  event.latency()->AddLatencyNumberWithTimestamp(
-      ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, 0, base::TimeTicks::Now(),
-      1);
-  touch_events->push_back(event);
-
-  // Mark the active touch pointers in the touch_id_list_ to be
-  // InCurrentMessage, so we can track the ones which are missed in the
-  // current message and release them.
-  if (touch_event_type == ui::ET_TOUCH_RELEASED) {
-    id_generator_.ReleaseNumber(input_dwID);
-    touch_point.in_touch_list = InTouchList::NotPresent;
-  } else {
-    touch_point.in_touch_list = InTouchList::InCurrentMessage;
-    touch_point.location = point_location;
-  }
-}
-
-void HWNDMessageHandler::UpdateTouchPointStates(TouchEvents* touch_events) {
-  for (size_t i = 0; i != touch_id_list_.size(); ++i) {
-    // Loop through the touch pointers list, if we see any which is only in
-    // the previous message, we will send a touch release event for this ID.
-    TouchPoint& touch_point = touch_id_list_[i];
-    if (touch_point.in_touch_list == InTouchList::InPreviousMessage) {
-      base::TimeDelta now = base::TimeTicks::Now() - base::TimeTicks();
-      ui::TouchEvent event(ui::ET_TOUCH_RELEASED, touch_point.location,
-                           static_cast<int>(i), now);
-      touch_events->push_back(event);
-      touch_point.in_touch_list = InTouchList::NotPresent;
-      id_generator_.ReleaseGeneratedID(i);
-      active_touch_point_count_--;
-    } else if (touch_point.in_touch_list == InTouchList::InCurrentMessage) {
-      touch_point.in_touch_list = InTouchList::InPreviousMessage;
-    }
-  }
 }
 
 void HWNDMessageHandler::OnWindowPosChanging(WINDOWPOS* window_pos) {
@@ -2570,15 +2505,15 @@
     delegate_->HandleTouchEvent(touch_events[i]);
 }
 
-void HWNDMessageHandler::DecrementTouchDownContext(int decrement) {
-  touch_down_contexts_ -= decrement;
+void HWNDMessageHandler::ResetTouchDownContext() {
+  touch_down_contexts_--;
 }
 
 LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
                                                      WPARAM w_param,
                                                      LPARAM l_param,
                                                      bool track_mouse) {
-  if (active_touch_point_count_)
+  if (!touch_ids_.empty())
     return 0;
 
   // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.

Powered by Google App Engine
This is Rietveld 408576698