Bug 34902 - [Qt] Add methods to QtWebKit API for setting and consulting the CSS2 media type
Summary: [Qt] Add methods to QtWebKit API for setting and consulting the CSS2 media type
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Qt (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Enhancement
Assignee: Kenneth Rohde Christiansen
URL:
Keywords: Qt, QtTriaged
Depends on:
Blocks:
 
Reported: 2010-02-12 12:00 PST by Kenneth Rohde Christiansen
Modified: 2014-02-03 03:16 PST (History)
10 users (show)

See Also:


Attachments
Patch (3.94 KB, patch)
2010-02-12 12:00 PST, Kenneth Rohde Christiansen
hausmann: review-
hausmann: commit-queue-
Details | Formatted Diff | Diff
Second try, up for comments (6.19 KB, patch)
2010-05-06 15:01 PDT, Kenneth Rohde Christiansen
no flags Details | Formatted Diff | Diff
Patch (9.09 KB, patch)
2010-05-07 14:18 PDT, Kenneth Rohde Christiansen
hausmann: commit-queue-
Details | Formatted Diff | Diff
Patch (Add as a setting) (9.52 KB, patch)
2010-05-14 14:35 PDT, Kenneth Rohde Christiansen
hausmann: review-
hausmann: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kenneth Rohde Christiansen 2010-02-12 12:00:29 PST
Added methods to QWebFrame for setting and consulting the CSS2 media type
Comment 1 Kenneth Rohde Christiansen 2010-02-12 12:00:57 PST
Created attachment 48656 [details]
Patch
Comment 2 Laszlo Gombos 2010-02-12 12:50:56 PST
I think QPrinter references are suppose to be behind QT_NO_PRINTER guards - see qwebframe.* and qwebview.*.
Comment 3 Kenneth Rohde Christiansen 2010-02-18 05:12:27 PST
Maybe we should use an enum instead?
Comment 4 Simon Hausmann 2010-02-18 10:56:30 PST
Comment on attachment 48656 [details]
Patch


> @@ -1439,6 +1466,9 @@ void QWebFrame::print(QPrinter *printer) const
>      }
>  
>      printContext.end();
> +
> +    QWebFrame* that = const_cast<QWebFrame*>(this);
> +    that->setMediaType(currentMediaType);
>  }
>  #endif // QT_NO_PRINTER

Wouldn't it be nicer if the media type was preserved in Frame::setPrinting?
Comment 5 Kenneth Rohde Christiansen 2010-02-18 10:58:33 PST
> Wouldn't it be nicer if the media type was preserved in Frame::setPrinting?

It would, and I should fix that.
Comment 6 Simon Hausmann 2010-02-18 11:10:20 PST
Comment on attachment 48656 [details]
Patch

Other than that I like the API. I think it should be a Q_PROPERTY.

It would be nice perhaps if the media type could be propagated down to child frames. Theoretically the frame is the correct place, but given that child frames can appear and disappear at will it only makes sense to set this property on the persistent main frame, at which point to avoid disambigouties a property on the page might be clearer.

I'm going to say r- because of the missing Q_PROPERTY and more importantly because I feel it's not clear that this is the right place. Would love to hear input from others on this. Mailing list? :)
Comment 7 Kenneth Rohde Christiansen 2010-02-18 11:15:38 PST
I'm still not sure if we should use an enum instead of a string, to not allow people to add non-standard media types.

Media types is only one part of media as we have media features as well, and their support depend on the parser recognizing the right keywords, so it would be impossible extending the media features via a public api (it would also be hard as we would need callback methods, knowing about the type, css etc), and that is probably not something that we would like to do anyway.

My the current patch, the user of the api can add whatever media type he/she likes and I think we should disencourage that.

What is your take on that Simon?
Comment 8 Yael 2010-02-19 06:11:04 PST
(In reply to comment #6)
> It would be nice perhaps if the media type could be propagated down to child
> frames. Theoretically the frame is the correct place, but given that child
> frames can appear and disappear at will it only makes sense to set this
> property on the persistent main frame, at which point to avoid disambigouties a
> property on the page might be clearer.
> 
> I'm going to say r- because of the missing Q_PROPERTY and more importantly
> because I feel it's not clear that this is the right place. Would love to hear
> input from others on this. Mailing list? :)

I totally agree with Simon. When I saw this patch, my first thought was that this should be a QWebPage property, because we are not planning on supporting different media types per frame.
Comment 9 Kenneth Rohde Christiansen 2010-05-06 15:01:02 PDT
Created attachment 55304 [details]
Second try, up for comments
Comment 10 Antonio Gomes 2010-05-06 19:43:06 PDT
(In reply to comment #9)
> Created an attachment (id=55304) [details]
> Second try, up for comments

goog patch.

+static void setMediaTypeRecursively(WebCore::Frame* frame, WebCore::String media)

const WebCore::String&

nitpick:

-    m_frame->createView(m_webFrame->page()->viewportSize(),
+    m_frame->createView(page->viewportSize(),

it is indeed right, but does it need to happen in this patch? :)


+    \since 4.7
+*/

you are proposing it for 4.7, so it should block the qtwebkit-2.0 release.
Comment 11 Simon Hausmann 2010-05-07 06:54:24 PDT
Comment on attachment 55304 [details]
Second try, up for comments

WebKit/qt/Api/qwebpage.cpp:1821
 +      d->mainFrame->d->setMediaType(d->mediaType);
This should probably call mainFrame() instead of accessing d->mainFrame directly, to avoid crashing when d->mainFrame is a null pointer.

WebKit/qt/Api/qwebpage.cpp:1807
 +  QString QWebPage::mediaType() const
Since this is a Q_PROPERTY the document must use the \property syntax, instead of individual documentation for the setter and getter.

WebKit/qt/Api/qwebpage_p.h:173
 +      QString mediaType;
Do we really need to store a copy of the media type in WebKit? I haven't looked deeply, just wondering if we can't just keep the string in WebCore?
Comment 12 Simon Hausmann 2010-05-07 06:57:15 PDT
(In reply to comment #10)
> +    \since 4.7
> +*/
> 
> you are proposing it for 4.7, so it should block the qtwebkit-2.0 release.

That's a good point. Do we really need this feature in the release?

We have 43 bugs blocking the release and 23 triaged priority one bugs.....
Comment 13 Kenneth Rohde Christiansen 2010-05-07 06:58:39 PDT
(In reply to comment #11)
> (From update of attachment 55304 [details])
> WebKit/qt/Api/qwebpage.cpp:1821
>  +      d->mainFrame->d->setMediaType(d->mediaType);
> This should probably call mainFrame() instead of accessing d->mainFrame
> directly, to avoid crashing when d->mainFrame is a null pointer.

OK, fine.

> 
> WebKit/qt/Api/qwebpage.cpp:1807
>  +  QString QWebPage::mediaType() const
> Since this is a Q_PROPERTY the document must use the \property syntax, instead
> of individual documentation for the setter and getter.

OK, so not individual documentation then.

> 
> WebKit/qt/Api/qwebpage_p.h:173
>  +      QString mediaType;
> Do we really need to store a copy of the media type in WebKit? I haven't looked
> deeply, just wondering if we can't just keep the string in WebCore?

We do, as you can set it before a frame is loaded and because you can move a
frame from one page to another.
Comment 14 Kenneth Rohde Christiansen 2010-05-07 07:00:46 PDT
(In reply to comment #12)
> (In reply to comment #10)
> > +    \since 4.7
> > +*/
> > 
> > you are proposing it for 4.7, so it should block the qtwebkit-2.0 release.
> 
> That's a good point. Do we really need this feature in the release?
> 
> We have 43 bugs blocking the release and 23 triaged priority one bugs.....

I didn't add it as a blocker, but that could be done it it enters trunk.

Btw, 43 includes the tracker bugs, and I am actually trying to triage the bugs right now :-)
Comment 15 Kenneth Rohde Christiansen 2010-05-07 14:18:15 PDT
Created attachment 55417 [details]
Patch
Comment 16 Antonio Gomes 2010-05-09 20:26:51 PDT
Comment on attachment 55417 [details]
Patch

>+static void setMediaTypeRecursively(WebCore::Frame* frame, const WebCore::String& media)
>+{
>+    WebCore::FrameView* view = frame->view();
>+    if (view->mediaType() != media) {
>+        view->setMediaType(media);
>+        frame->document()->updateStyleSelector();
>+        frame->view()->layout();
>+    }
>+
>+    for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->nextSibling())
>+        setMediaTypeRecursively(child, media);
>+}
>+
>+void QWebFramePrivate::setMediaType(const QString& media)
>+{
>+    setMediaTypeRecursively(frame, media);
>+}

If it is specified in the specs that an outer frame should propagate its media type value to its inner frames, the recursive step (read method setMediaTypeRecursively) should go to Frame.cpp. That way you would be ensuring that other ports that implement setMediaType-like method in their API would also follow the same recurvive assignment behaviour. In other words, adding setMediaTypeRecursively in WebKit side can create diverging behaviors between webkit ports if one does the recursive assignment and other(s) do(es) not.

+    \note A frame inherits the media type of its owner, thus either another frame in the case it is a sub
+    frame, or else the page itself. When a frame is moved from one page to another, the media type is
+    automatically updated.
+
 
it would be so great to autotest that as well :) , but it can come in a follow up test I think.
Comment 17 Kenneth Rohde Christiansen 2010-05-10 05:54:01 PDT
Antonio, this is a C++ side API decision. The spec doesn't define how the user agent/browser should create it's API for setting the media type, that is up to us.
Comment 18 Simon Hausmann 2010-05-14 08:31:12 PDT
Comment on attachment 55417 [details]
Patch

r=me

However before landing I think this property should be moved to QWebSettings
Comment 19 Kenneth Rohde Christiansen 2010-05-14 14:35:49 PDT
Created attachment 56110 [details]
Patch (Add as a setting)
Comment 20 Adam Barth 2010-05-15 18:55:14 PDT
Comment on attachment 55417 [details]
Patch

clearing r+ from obsolete patch.
Comment 21 Kenneth Rohde Christiansen 2010-06-05 07:37:05 PDT
Ping review?
Comment 22 Simon Hausmann 2010-06-07 07:25:07 PDT
Comment on attachment 56110 [details]
Patch (Add as a setting)

WebCore/page/Settings.h:311
 +          Page* page() { return m_page; }
This should probably be const.

WebKit/qt/Api/qwebframe.cpp:225
 +  void QWebFramePrivate::applyMediaType(WebCore::Frame* frame, const WebCore::String& mediaType, bool recursive)
I don't see where false is passed from any caller of this method, so I think you can remove the argument and call the function applyMediaTypeRecursively (Webkittish ;)

WebKit/qt/Api/qwebsettings.cpp:584
 +  void QWebSettings::setStyleSheetMediaType(const QString& mediaType)
The implementation of this function should fall back to the media type of the global QWebSettings object.

The usual pattern is to do the changes in apply(), which will also be be called if you change settings in the global QWebSettings object.

WebKit/qt/Api/qwebsettings.cpp:591
 +  QString QWebSettings::styleSheetMediaType() const
I think the implementation of this function should returnd->styleSheetMediaType straight, instead of automatically falling back.

See the same pattern for example with QWebSettings::userStyleSheetUrl and setUserStyleSheetUrl.
Comment 23 Andreas Kling 2011-04-08 10:57:53 PDT
Chilling the prio on this a bit, since it hasn't been touched in almost a year.
Comment 24 Jocelyn Turcotte 2014-02-03 03:16:10 PST
=== Bulk closing of Qt bugs ===

If you believe that this bug report is still relevant for a non-Qt port of webkit.org, please re-open it and remove [Qt] from the summary.

If you believe that this is still an important QtWebKit bug, please fill a new report at https://bugreports.qt-project.org and add a link to this issue. See http://qt-project.org/wiki/ReportingBugsInQt for additional guidelines.