Bug 51094

Summary: [Qt] No way to set focus to GraphicsWebView with Qt Quick (QML) outside of a mouse click.
Product: WebKit Reporter: Gary <getownse>
Component: WebKit QtAssignee: Girish Ramakrishnan <girish>
Status: RESOLVED FIXED    
Severity: Major CC: girish, hausmann, menard
Priority: P2 Keywords: Qt
Version: 528+ (Nightly build)   
Hardware: PC   
OS: Linux   
URL: http://developer.qt.nokia.com/forums/viewthread/2394/
Attachments:
Description Flags
QML Project Code to show Error
none
Make QDeclarativeWebView the focus proxy of QGraphicsWebView
none
Make QGraphicsWebView a FocusScope
none
77882: Make QGraphicsWebView a FocusScope (2) hausmann: review+

Description Gary 2010-12-14 21:19:22 PST
In QML:

WebView {
    id: webView
    width: 1280
    height: 600
    url: "http://www.google.com"
    focus: true
}

WebView will get the focus, but not the underlining GraphicsWebView.  In order for key events to be posted to the GraphicsWebView (and allow for HTML key events to be executed) a user must first click on the WebView to give the GraphicsWebView focus, and then key events will work.  My targetted system does not have a mouse, and makes it impossible for a keyboard to post key input to a website that requires key events WITHOUT having a focus html element such as a input box.

My work around was to make the GraphicsWebView the Focus Proxy by changing the following init method in qdeclarativewebview.cpp:

void QDeclarativeWebView::init()
{
    d = new QDeclarativeWebViewPrivate(this);

    QWebSettings::enablePersistentStorage();

    setAcceptedMouseButtons(Qt::LeftButton);
    setFlag(QGraphicsItem::ItemHasNoContents, true);
    setClip(true);

    d->view = new GraphicsWebView(this);
    d->view->setResizesToContents(true);
    QWebPage* wp = new QDeclarativeWebPage(this);
    setPage(wp);

    setFocusProxy(d->view);  /********************** <---- THIS LINE IS THE WORK AROUND **********************/

    connect(d->view, SIGNAL(geometryChanged()), this, SLOT(updateDeclarativeWebViewSize()));
    connect(d->view, SIGNAL(doubleClick(int, int)), this, SIGNAL(doubleClick(int, int)));
    connect(d->view, SIGNAL(scaleChanged()), this, SIGNAL(contentsScaleChanged()));
}


I attached an example.

You can navigate between the HTML menu and the QML menu using the left and right keys.
You can navigate the QML menu by pressing up and down.
You can NOT navigate the HTML menu by pressing up and down, UNTIL you first click on the HTML menu.  Then you CAN navigate the HTML menu by pressing up and down.
Comment 1 Gary 2010-12-14 21:24:22 PST
Created attachment 76628 [details]
QML Project Code to show Error

QML Project:

WebKit.qml -- The QML code. Creates 2 menus. One with QML and one with HTML.
index.html -- The HTML menu.  Uses JavaScript to navigate a menu.
jquery-1.4.4.min.js -- JQuery javascript library.  Assist in JavaScript development.
main.css -- Stylesheets for HTML menu.

Launch WebKit.qml with QtCreator or qmlviewer WebKit.qml.

You can navigate between the HTML menu and the QML menu using the left and right keys.
You can navigate the QML menu by pressing up and down.
You can NOT navigate the HTML menu by pressing up and down, UNTIL you first click on the HTML menu.  Then you CAN navigate the HTML menu by pressing up and down.
Comment 2 Girish Ramakrishnan 2011-01-04 04:36:57 PST
Created attachment 77877 [details]
Make QDeclarativeWebView the focus proxy of QGraphicsWebView

Make QDeclarativeWebView the focus proxy of QGraphicsWebView.
Comment 3 Girish Ramakrishnan 2011-01-04 06:07:14 PST
Created attachment 77882 [details]
Make QGraphicsWebView a FocusScope

Making it a FocusProxy is not the correct fix because it would result in qml 'focus' property returning false even when the view has focus.
Comment 4 Girish Ramakrishnan 2011-01-04 06:10:31 PST
Created attachment 77883 [details]
77882: Make QGraphicsWebView a FocusScope (2)

Wrong description and ChangeLog
Comment 5 Simon Hausmann 2011-01-05 01:27:07 PST
Comment on attachment 77883 [details]
77882: Make QGraphicsWebView a FocusScope (2)

r=me. ACKed also by Aaron. Would be nice to have a more elaborate changelog entry when landing *hint* *hint* :)
Comment 6 Girish Ramakrishnan 2011-01-05 16:43:44 PST
Landed as r75119