void AccessibilityInspector::inspectWindow(QWindow *window)
{
    qDebug() << "AccessibilityInspector::inspectWindow()" << window;
    if (window->parent() || window->transientParent())
        return;

    optionsWidget = new OptionsWidget();

    accessibilityScene = new MouseInterceptingGraphicsScene();

    accessibilityView = new QGraphicsView();
    accessibilityView->setScene(accessibilityScene);
    accessibilityView->resize(640, 480);
    accessibilityView->scale(1.3, 1.3);

    accessibilityTreeScene = new QGraphicsScene();

    accessibilityTreeView = new QGraphicsView();
    accessibilityTreeView->setScene(accessibilityTreeScene);
    accessibilityTreeView->resize(640, 480);

    sceneManager = new AccessibilitySceneManager();
    QObject::connect(optionsWidget, SIGNAL(optionsChanged()), sceneManager, SLOT(updateAccessibilitySceneItemFlags()));
    QObject::connect(optionsWidget, SIGNAL(refreshClicked()), sceneManager, SLOT(populateAccessibilityScene()));
    QObject::connect(optionsWidget, SIGNAL(refreshClicked()), sceneManager, SLOT(populateAccessibilityTreeScene()));
    QObject::connect(optionsWidget, SIGNAL(scaleChanged(int)), sceneManager, SLOT(changeScale(int)));

    sceneManager->setOptionsWidget(optionsWidget);
    sceneManager->setRootWindow(window);
    sceneManager->setScene(accessibilityScene);
    sceneManager->setView(accessibilityView);
    sceneManager->setTreeScene(accessibilityTreeScene);
    sceneManager->setTreeView(accessibilityTreeView);

    screenReader = new ScreenReader;
    QObject::connect(accessibilityScene, SIGNAL(mousePressed(QPoint)), screenReader, SLOT(touchPoint(QPoint)));
    QObject::connect(accessibilityScene, SIGNAL(mouseDobleClicked()), screenReader, SLOT(activate()));
    QObject::connect(screenReader, SIGNAL(selected(QObject*)), sceneManager, SLOT(setSelected(QObject*)));
    screenReader->setRootObject(window);
    screenReader->setOptionsWidget(optionsWidget);

    previousUpdateHandler = QAccessible::installUpdateHandler(accessibilityUpdateHandler);

    QTimer::singleShot(100, sceneManager, SLOT(populateAccessibilityScene()));
    QTimer::singleShot(100, sceneManager, SLOT(populateAccessibilityTreeScene()));

    QSettings settings;
    accessibilityView->restoreGeometry(settings.value("accessiblityGeometry").toByteArray());
    accessibilityView->setObjectName(QLatin1String("accessibilityInspectorView"));
    accessibilityView->show();


    accessibilityTreeView->restoreGeometry(settings.value("treeGeometry").toByteArray());
    accessibilityTreeView->setObjectName(QLatin1String("accessibilityInspectorTreeView"));
    accessibilityTreeView->show();
    optionsWidget->restoreGeometry(settings.value("optionsGeometry").toByteArray());
    optionsWidget->setObjectName(QLatin1String("accessibilityInspectorOptions"));
    optionsWidget->show();
}
void MultiTouchListener::handleEvent( TUIO::TuioCursor* tcur,
                                      const QEvent::Type eventType )
{
    QGraphicsView* view = _graphicsViewProxy->getGraphicsView();
    if( !view )
        return;

    const QPoint& viewPos = view->mapToGlobal( view->pos());
    const QRectF& sceneRect = view->sceneRect();
    const int viewWidth = view->geometry().width();
    const int viewHeight = view->geometry().height();

    const qreal w = viewWidth / sceneRect.width();
    const qreal h = viewHeight / sceneRect.height();
    const int x = qreal(viewWidth - w) * .5;
    const int y = qreal(viewHeight - h) * .5;
    const QPoint sceneOffset( x, y );

    const QPointF normPos( tcur->getX(), tcur->getY( ));
    const QPoint pos( w * normPos.x(), h * normPos.y( ));
    const QPoint screenPos( viewPos + sceneOffset + pos );

    const QPoint wallPos( g_configuration->getTotalWidth() * tcur->getX(),
                          g_configuration->getTotalHeight() * tcur->getY( ));

    QTouchEvent::TouchPoint touchPoint( tcur->getCursorID( ));
    touchPoint.setPressure( 1.0 );
    touchPoint.setNormalizedPos( normPos );
    touchPoint.setPos( wallPos ); // need for pan gesture recognition
    touchPoint.setScenePos( normPos );
    touchPoint.setScreenPos( screenPos ); // need for hotspot & itemAt

    Qt::TouchPointStates touchPointStates = 0;
    if( tcur->getCursorID() == 0 )
        touchPointStates |= Qt::TouchPointPrimary;

    switch( eventType )
    {
    case QEvent::TouchBegin:
        touchPointStates = Qt::TouchPointPressed;

        touchPoint.setStartNormalizedPos( normPos );
        touchPoint.setStartPos( touchPoint.pos( ));
        touchPoint.setStartScreenPos( screenPos );
        touchPoint.setStartScenePos( touchPoint.scenePos( ));

        touchPoint.setLastNormalizedPos( normPos );
        touchPoint.setLastPos( touchPoint.pos( ));
        touchPoint.setLastScreenPos( screenPos );
        touchPoint.setLastScenePos( touchPoint.scenePos( ));
        break;

    case QEvent::TouchUpdate:
    case QEvent::TouchEnd:
    {
        if( eventType == QEvent::TouchUpdate )
            touchPointStates = tcur->isMoving() ? Qt::TouchPointMoved
                                                : Qt::TouchPointStationary;
        else
            touchPointStates = Qt::TouchPointReleased;

        const QTouchEvent::TouchPoint& prevPoint = _touchPointMap.value( tcur->getCursorID( ));
        touchPoint.setStartNormalizedPos( prevPoint.startNormalizedPos( ));
        touchPoint.setStartPos( prevPoint.startPos( ));
        touchPoint.setStartScreenPos( prevPoint.startScreenPos( ));
        touchPoint.setStartScenePos( prevPoint.startScenePos( ));

        touchPoint.setLastNormalizedPos( prevPoint.normalizedPos( ));
        touchPoint.setLastPos( prevPoint.pos( ));
        touchPoint.setLastScreenPos( prevPoint.screenPos( ));
        touchPoint.setLastScenePos( prevPoint.scenePos( ));
        break;
    }

    default:
        put_flog( LOG_ERROR, "Got wrong touch event type %i", eventType );
        return;
    }

    touchPoint.setState( touchPointStates );
    _touchPointMap.insert( tcur->getCursorID(), touchPoint );

    QEvent* touchEvent = new QTouchEvent( eventType, QTouchEvent::TouchScreen,
                                          Qt::NoModifier, touchPointStates,
                                          _touchPointMap.values( ));
    QApplication::postEvent( view->viewport(), touchEvent );

    if( eventType == QEvent::TouchEnd )
        _touchPointMap.remove( tcur->getCursorID( ));
}
Ejemplo n.º 3
0
bool QTuio::tuioToQt(TUIO::TuioCursor *tcur, QEvent::Type eventType)
{
    const QPointF normPos(tcur->getX(), tcur->getY());
    const QPointF screenPos(screenRect.width() * normPos.x() - OFFSETX, screenRect.height() * normPos.y() - OFFSETY);

    QTouchEvent::TouchPoint touchPoint(tcur->getSessionID());

    touchPoint.setNormalizedPos(normPos);
    touchPoint.setRect(QRectF());

    touchPoint.setPressure(1.0);
    touchPoint.setScreenRect(screenRect);
    touchPoint.setScreenPos(screenPos);

 //   if (theScene) {
 //       touchPoint.setSceneRect(theScene->sceneRect());
 //       if (theView ) {
 //           const QPoint pos((int)screenPos.x() - theView->geometry().x(),
 //                            (int)screenPos.y() - theView->geometry().y());
 //           touchPoint.setPos(pos);
 //           touchPoint.setScenePos(theView->mapToScene(pos));
 //       } else {
 //           foreach (QGraphicsView *view, theScene->views()) {
 //               if (view->isActiveWindow()) {
 //                   const QPoint pos((int)screenPos.x() - view->geometry().x(),
 //                                    (int)screenPos.y() - view->geometry().y());
 //                   touchPoint.setPos(pos);
 //                   touchPoint.setScenePos(view->mapToScene(pos));
 //               }
 //           }
 //       }
 //   } 
	//else {

        const QPoint pos((int)screenPos.x() - theMainWindow->geometry().x(),
                         (int)screenPos.y() - theMainWindow->geometry().y());
        touchPoint.setPos(pos);
        touchPoint.setSceneRect(QRectF());
        touchPoint.setScenePos(pos);
 //   }

    Qt::TouchPointStates touchPointStates;

    switch (eventType) {
    case QEvent::TouchBegin: {
	    touchPointStates = Qt::TouchPointPressed;

            touchPoint.setState(Qt::TouchPointPressed);
            touchPoint.setStartNormalizedPos(normPos);
            touchPoint.setStartPos(touchPoint.pos());
            touchPoint.setStartScreenPos(screenPos);
            touchPoint.setStartScenePos(touchPoint.scenePos());

            touchPoint.setLastNormalizedPos(normPos);
            touchPoint.setLastPos(touchPoint.pos());
            touchPoint.setLastScreenPos(screenPos);
            touchPoint.setLastScenePos(touchPoint.scenePos());

            qTouchPointMap->insert(tcur->getSessionID(), touchPoint);
            break;
        }
    case QEvent::TouchUpdate: {
            if (tcur->getMotionSpeed() > 0)
	    {
                touchPointStates = Qt::TouchPointMoved;

                touchPoint.setState(Qt::TouchPointMoved);
	    }
            else
	    {
                touchPointStates = Qt::TouchPointStationary;

                touchPoint.setState(Qt::TouchPointStationary);
	    }

            touchPoint.setStartNormalizedPos(qTouchPointMap->value(tcur->getSessionID()).startNormalizedPos());
            touchPoint.setStartPos(qTouchPointMap->value(tcur->getSessionID()).startPos());
            touchPoint.setStartScreenPos(qTouchPointMap->value(tcur->getSessionID()).startScreenPos());
            touchPoint.setStartScenePos(qTouchPointMap->value(tcur->getSessionID()).startScenePos());

            touchPoint.setLastNormalizedPos(qTouchPointMap->value(tcur->getSessionID()).normalizedPos());
            touchPoint.setLastPos(qTouchPointMap->value(tcur->getSessionID()).pos());
            touchPoint.setLastScreenPos(qTouchPointMap->value(tcur->getSessionID()).screenPos());
            touchPoint.setLastScenePos(qTouchPointMap->value(tcur->getSessionID()).scenePos());

            qTouchPointMap->insert(tcur->getSessionID(), touchPoint);
            break;
        }
    case QEvent::TouchEnd: {
            touchPointStates = Qt::TouchPointReleased;

            touchPoint.setState(Qt::TouchPointReleased);

            touchPoint.setStartNormalizedPos(qTouchPointMap->value(tcur->getSessionID()).startNormalizedPos());
            touchPoint.setStartPos(qTouchPointMap->value(tcur->getSessionID()).startPos());
            touchPoint.setStartScreenPos(qTouchPointMap->value(tcur->getSessionID()).startScreenPos());
            touchPoint.setStartScenePos(qTouchPointMap->value(tcur->getSessionID()).startScenePos());

            touchPoint.setLastNormalizedPos(qTouchPointMap->value(tcur->getSessionID()).normalizedPos());
            touchPoint.setLastPos(qTouchPointMap->value(tcur->getSessionID()).pos());
            touchPoint.setLastScreenPos(qTouchPointMap->value(tcur->getSessionID()).screenPos());
            touchPoint.setLastScenePos(qTouchPointMap->value(tcur->getSessionID()).scenePos());

            qTouchPointMap->insert(tcur->getSessionID(), touchPoint);
            break;
        }
    default: {}
    }

    QEvent *touchEvent = new QTouchEvent(eventType, QTouchEvent::TouchScreen, Qt::NoModifier, touchPointStates, qTouchPointMap->values());

//**********************************************************
// * Old Code doesn't work with QGraphicsView
// * it doesn't send events to the viewport
// * and which make the pinchzoom example doesn't work
//***********************************************************/
//*    if (theScene)
//        qApp->postEvent(theScene, touchEvent);
//    else if (theView)
//        qApp->postEvent(theView->scene(), touchEvent);
//    else
//        qApp->postEvent(theMainWindow->centralWidget(), touchEvent);*/
//
//************************************************
// * New code fixing the issue with QGraphicsViw
//*************************************************/

	// if (theView && theView->viewport())
 //       qApp->postEvent(theView->viewport(), touchEvent);
 //   else if (theScene)
 //       qApp->postEvent(theScene, touchEvent);
 //   else
	//{
        //qApp->sendEvent(theMainWindow, touchEvent);
		emit touchSignal(static_cast<QTouchEvent*> (touchEvent));
		
//	}

    if (eventType == QEvent::TouchEnd)
        qTouchPointMap->remove(tcur->getSessionID());

    return true;
}
Ejemplo n.º 4
0
Response InspectorInputAgent::dispatchTouchEvent(
    const String& type,
    std::unique_ptr<protocol::Array<protocol::Input::TouchPoint>> touchPoints,
    protocol::Maybe<int> modifiers,
    protocol::Maybe<double> timestamp) {
  PlatformEvent::EventType convertedType;
  if (type == "touchStart")
    convertedType = PlatformEvent::TouchStart;
  else if (type == "touchEnd")
    convertedType = PlatformEvent::TouchEnd;
  else if (type == "touchMove")
    convertedType = PlatformEvent::TouchMove;
  else
    return Response::Error(String("Unrecognized type: " + type));

  unsigned convertedModifiers = GetEventModifiers(modifiers.fromMaybe(0));

  SyntheticInspectorTouchEvent event(convertedType, convertedModifiers,
                                     GetEventTimeStamp(timestamp));

  int autoId = 0;
  for (size_t i = 0; i < touchPoints->length(); ++i) {
    protocol::Input::TouchPoint* point = touchPoints->get(i);
    int radiusX = point->getRadiusX(1);
    int radiusY = point->getRadiusY(1);
    double rotationAngle = point->getRotationAngle(0.0);
    double force = point->getForce(1.0);
    int id;
    if (point->hasId()) {
      if (autoId > 0)
        id = -1;
      else
        id = point->getId(0);
      autoId = -1;
    } else {
      id = autoId++;
    }
    if (id < 0) {
      return Response::Error(
          "All or none of the provided TouchPoints must supply positive "
          "integer ids.");
    }

    PlatformTouchPoint::TouchState convertedState;
    String state = point->getState();
    if (state == "touchPressed")
      convertedState = PlatformTouchPoint::TouchPressed;
    else if (state == "touchReleased")
      convertedState = PlatformTouchPoint::TouchReleased;
    else if (state == "touchMoved")
      convertedState = PlatformTouchPoint::TouchMoved;
    else if (state == "touchStationary")
      convertedState = PlatformTouchPoint::TouchStationary;
    else if (state == "touchCancelled")
      convertedState = PlatformTouchPoint::TouchCancelled;
    else
      return Response::Error(String("Unrecognized state: " + state));

    // Some platforms may have flipped coordinate systems, but the given
    // coordinates assume the origin is in the top-left of the window. Convert.
    IntPoint convertedPoint, globalPoint;
    ConvertInspectorPoint(m_inspectedFrames->root(),
                          IntPoint(point->getX(), point->getY()),
                          &convertedPoint, &globalPoint);

    SyntheticInspectorTouchPoint touchPoint(id++, convertedState, globalPoint,
                                            convertedPoint, radiusX, radiusY,
                                            rotationAngle, force);
    event.append(touchPoint);
  }

  // TODO: We need to add the support for generating coalesced events in
  // the devtools.
  Vector<PlatformTouchEvent> coalescedEvents;

  m_inspectedFrames->root()->eventHandler().handleTouchEvent(event,
                                                             coalescedEvents);
  return Response::OK();
}
Ejemplo n.º 5
0
TEST_F(APZHitTestingTester, TestRepaintFlushOnNewInputBlock) {
  SCOPED_GFX_PREF(TouchActionEnabled, bool, false);

  // The main purpose of this test is to verify that touch-start events (or anything
  // that starts a new input block) don't ever get untransformed. This should always
  // hold because the APZ code should flush repaints when we start a new input block
  // and the transform to gecko space should be empty.

  CreateSimpleScrollingLayer();
  ScopedLayerTreeRegistration registration(manager, 0, root, mcc);
  manager->UpdateHitTestingTree(nullptr, root, false, 0, 0);
  TestAsyncPanZoomController* apzcroot = ApzcOf(root);

  // At this point, the following holds (all coordinates in screen pixels):
  // layers[0] has content from (0,0)-(500,500), clipped by composition bounds (0,0)-(200,200)

  MockFunction<void(std::string checkPointName)> check;

  {
    InSequence s;

    EXPECT_CALL(*mcc, RequestContentRepaint(_)).Times(AtLeast(1));
    EXPECT_CALL(check, Call("post-first-touch-start"));
    EXPECT_CALL(*mcc, RequestContentRepaint(_)).Times(AtLeast(1));
    EXPECT_CALL(check, Call("post-second-fling"));
    EXPECT_CALL(*mcc, RequestContentRepaint(_)).Times(AtLeast(1));
    EXPECT_CALL(check, Call("post-second-touch-start"));
  }

  // This first pan will move the APZC by 50 pixels, and dispatch a paint request.
  ApzcPanNoFling(apzcroot, 100, 50);

  // Verify that a touch start doesn't get untransformed
  ScreenIntPoint touchPoint(50, 50);
  MultiTouchInput mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_START, mcc->Time());
  mti.mTouches.AppendElement(SingleTouchData(0, touchPoint, ScreenSize(0, 0), 0, 0));

  EXPECT_EQ(nsEventStatus_eConsumeDoDefault, manager->ReceiveInputEvent(mti, nullptr, nullptr));
  EXPECT_EQ(touchPoint, mti.mTouches[0].mScreenPoint);
  check.Call("post-first-touch-start");

  // Send a touchend to clear state
  mti.mType = MultiTouchInput::MULTITOUCH_END;
  manager->ReceiveInputEvent(mti, nullptr, nullptr);

  mcc->AdvanceByMillis(1000);

  // Now do two pans. The first of these will dispatch a repaint request, as above.
  // The second will get stuck in the paint throttler because the first one doesn't
  // get marked as "completed", so this will result in a non-empty LD transform.
  // (Note that any outstanding repaint requests from the first half of this test
  // don't impact this half because we advance the time by 1 second, which will trigger
  // the max-wait-exceeded codepath in the paint throttler).
  ApzcPanNoFling(apzcroot, 100, 50);
  check.Call("post-second-fling");
  ApzcPanNoFling(apzcroot, 100, 50);

  // Ensure that a touch start again doesn't get untransformed by flushing
  // a repaint
  mti.mType = MultiTouchInput::MULTITOUCH_START;
  EXPECT_EQ(nsEventStatus_eConsumeDoDefault, manager->ReceiveInputEvent(mti, nullptr, nullptr));
  EXPECT_EQ(touchPoint, mti.mTouches[0].mScreenPoint);
  check.Call("post-second-touch-start");

  mti.mType = MultiTouchInput::MULTITOUCH_END;
  EXPECT_EQ(nsEventStatus_eConsumeDoDefault, manager->ReceiveInputEvent(mti, nullptr, nullptr));
  EXPECT_EQ(touchPoint, mti.mTouches[0].mScreenPoint);
}
void InspectorInputAgent::dispatchTouchEvent(ErrorString* error, const String& type, PassOwnPtr<protocol::Array<protocol::Input::TouchPoint>> touchPoints, const protocol::Maybe<int>& modifiers, const protocol::Maybe<double>& timestamp)
{
    PlatformEvent::Type convertedType;
    if (type == "touchStart") {
        convertedType = PlatformEvent::TouchStart;
    } else if (type == "touchEnd") {
        convertedType = PlatformEvent::TouchEnd;
    } else if (type == "touchMove") {
        convertedType = PlatformEvent::TouchMove;
    } else {
        *error = "Unrecognized type: " + type;
        return;
    }

    unsigned convertedModifiers = GetEventModifiers(modifiers.fromMaybe(0));

    SyntheticInspectorTouchEvent event(convertedType, convertedModifiers, timestamp.fromMaybe(currentTime()));

    int autoId = 0;
    for (size_t i = 0; i < touchPoints->length(); ++i) {
        protocol::Input::TouchPoint* point = touchPoints->get(i);
        int radiusX = point->getRadiusX(1);
        int radiusY = point->getRadiusY(1);
        double rotationAngle = point->getRotationAngle(0.0);
        double force = point->getForce(1.0);
        int id;
        if (point->hasId()) {
            if (autoId > 0)
                id = -1;
            else
                id = point->getId(0);
            autoId = -1;
        } else {
            id = autoId++;
        }
        if (id < 0) {
            *error = "All or none of the provided TouchPoints must supply positive integer ids.";
            return;
        }

        PlatformTouchPoint::State convertedState;
        String state = point->getState();
        if (state == "touchPressed") {
            convertedState = PlatformTouchPoint::TouchPressed;
        } else if (state == "touchReleased") {
            convertedState = PlatformTouchPoint::TouchReleased;
        } else if (state == "touchMoved") {
            convertedState = PlatformTouchPoint::TouchMoved;
        } else if (state == "touchStationary") {
            convertedState = PlatformTouchPoint::TouchStationary;
        } else if (state == "touchCancelled") {
            convertedState = PlatformTouchPoint::TouchCancelled;
        } else {
            *error = "Unrecognized state: " + state;
            return;
        }

        // Some platforms may have flipped coordinate systems, but the given coordinates
        // assume the origin is in the top-left of the window. Convert.
        IntPoint convertedPoint, globalPoint;
        ConvertInspectorPoint(m_inspectedFrames->root(), IntPoint(point->getX(), point->getY()), &convertedPoint, &globalPoint);

        SyntheticInspectorTouchPoint touchPoint(id++, convertedState, globalPoint, convertedPoint, radiusX, radiusY, rotationAngle, force);
        event.append(touchPoint);
    }

    m_inspectedFrames->root()->eventHandler().handleTouchEvent(event);
}