Bug 51094 - [Qt] No way to set focus to GraphicsWebView with Qt Quick (QML) outside of a mouse click.
Summary: [Qt] No way to set focus to GraphicsWebView with Qt Quick (QML) outside of a ...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Qt (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Major
Assignee: Girish Ramakrishnan
URL: http://developer.qt.nokia.com/forums/...
Keywords: Qt
Depends on:
Blocks:
 
Reported: 2010-12-14 21:19 PST by Gary
Modified: 2011-01-05 16:43 PST (History)
3 users (show)

See Also:


Attachments
QML Project Code to show Error (28.31 KB, application/x-compressed-tar)
2010-12-14 21:24 PST, Gary
no flags Details
Make QDeclarativeWebView the focus proxy of QGraphicsWebView (1.57 KB, patch)
2011-01-04 04:36 PST, Girish Ramakrishnan
no flags Details | Formatted Diff | Diff
Make QGraphicsWebView a FocusScope (1.74 KB, patch)
2011-01-04 06:07 PST, Girish Ramakrishnan
no flags Details | Formatted Diff | Diff
77882: Make QGraphicsWebView a FocusScope (2) (1.69 KB, patch)
2011-01-04 06:10 PST, Girish Ramakrishnan
hausmann: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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