[webkit-qt] Embedding a QWebView into a QScrollArea

Jan Kundrát jkt at flaska.net
Thu Feb 21 12:01:30 PST 2013


Hi folks,
my application is an e-mail client which embeds one or more QWebView instances along with some common, shared headers into a single QScrollArea. The idea behind this is to make it possible to:

- use native widgets for headers etc,
- be able to mix HTML from various message parts,
- scroll all of this together.

After quite some struggling, we've achieved this and everything works great (including proper sizing which was rather PITA to configure properly, and including dynamic changes to the rendered tree in response to CSS pseudoclasses like :checked, yay).

Now, the missing bit is automatically moving the page to the place of the search result in response to QWebPage::findText. Because the QWeb... instances have no scrollbars and are embedded inside a QScrollArea, the QWebFrame::scrollPosition is always (0,0), and that's clearly a useless value here.

I've dug into the webkit sources to see what the suitable callback shall look like, and found a sweet comment (src/3rdparty/webkit/Source/WebCore/rendering/RenderLayer.cpp, line 1477):

  // This is the outermost view of a web page, so after scrolling this view we
  // scroll its container by calling Page::scrollRectIntoView.
  // This only has an effect on the Mac platform in applications
  // that put web views into scrolling containers, such as Mac OS X Mail.
  // The canAutoscroll function in EventHandler also knows about this.
  if (Frame* frame = frameView->frame()) {
      if (Page* page = frame->page())
          page->chrome()->scrollRectIntoView(rect);
  }

...and indeed, the ChromeClientQt defines that method as an empty stub.

I realize that this might not be a terribly important feature for most people (who would possibly put a QWebView into a custom QScrollArea, after all), but Apple needs that, I need that, and with the current QWebView, it isn't possible. Are there any chances of implementing a signal in the QWebView which is emitted when the contents is "scrolled" through this?

With kind regards,
Jan

-- 
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/


More information about the webkit-qt mailing list