private void dispatchUiEvents(boolean calledFromHandler) {
    for (; ; ) {
      MotionEvent event;
      final int eventType;
      final int flags;
      synchronized (mLock) {
        DispatchEvent d = mUiDispatchEventQueue.dequeue();
        if (d == null) {
          if (mUiDispatchScheduled) {
            mUiDispatchScheduled = false;
            if (!calledFromHandler) {
              mUiHandler.removeMessages(UiHandler.MSG_DISPATCH_UI_EVENTS);
            }
          }
          return;
        }

        event = d.mEvent;
        if (event != null && (d.mFlags & FLAG_WEBKIT_TRANSFORMED_EVENT) != 0) {
          event.scale(1.0f / d.mWebKitScale);
          event.offsetLocation(-d.mWebKitXOffset, -d.mWebKitYOffset);
          d.mFlags &= ~FLAG_WEBKIT_TRANSFORMED_EVENT;
        }

        eventType = d.mEventType;
        if (eventType == EVENT_TYPE_TOUCH) {
          event = mUiTouchStream.update(event);
          if (DEBUG && event == null && d.mEvent != null) {
            Log.d(TAG, "dispatchUiEvents: dropped event " + d.mEvent);
          }
        }

        flags = d.mFlags;

        if (event == d.mEvent) {
          d.mEvent = null; // retain ownership of event, don't recycle it yet
        }
        recycleDispatchEventLocked(d);

        if (eventType == EVENT_TYPE_CLICK) {
          scheduleHideTapHighlightLocked();
        }
      }

      // Handle the event.
      if (event != null) {
        dispatchUiEvent(event, eventType, flags);
        event.recycle();
      }
    }
  }
 private void updateWebKitTimeoutLocked() {
   DispatchEvent d = mWebKitDispatchEventQueue.mHead;
   if (d != null && mWebKitTimeoutScheduled && mWebKitTimeoutTime == d.mTimeoutTime) {
     return;
   }
   if (mWebKitTimeoutScheduled) {
     mUiHandler.removeMessages(UiHandler.MSG_WEBKIT_TIMEOUT);
     mWebKitTimeoutScheduled = false;
   }
   if (d != null) {
     mUiHandler.sendEmptyMessageAtTime(UiHandler.MSG_WEBKIT_TIMEOUT, d.mTimeoutTime);
     mWebKitTimeoutScheduled = true;
     mWebKitTimeoutTime = d.mTimeoutTime;
   }
 }
 private void unscheduleClickLocked() {
   if (mPostClickScheduled) {
     mPostClickScheduled = false;
     mUiHandler.removeMessages(UiHandler.MSG_CLICK);
   }
 }
 private void unscheduleHideTapHighlightLocked() {
   if (mPostHideTapHighlightScheduled) {
     mPostHideTapHighlightScheduled = false;
     mUiHandler.removeMessages(UiHandler.MSG_HIDE_TAP_HIGHLIGHT);
   }
 }
 private void unscheduleShowTapHighlightLocked() {
   if (mPostShowTapHighlightScheduled) {
     mPostShowTapHighlightScheduled = false;
     mUiHandler.removeMessages(UiHandler.MSG_SHOW_TAP_HIGHLIGHT);
   }
 }
 private void unscheduleLongPressLocked() {
   if (mPostLongPressScheduled) {
     mPostLongPressScheduled = false;
     mUiHandler.removeMessages(UiHandler.MSG_LONG_PRESS);
   }
 }