Summary: | [Qt] Add selectedHtml function to QWebView | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Andreas Kling <kling> | ||||
Component: | WebKit Qt | Assignee: | Andreas Kling <kling> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Enhancement | CC: | adawit, eric, faure, kenneth, laszlo.gombos, luiz, tonikitoo, vestbo, wstokes, yael | ||||
Priority: | P2 | Keywords: | Qt | ||||
Version: | 528+ (Nightly build) | ||||||
Hardware: | PC | ||||||
OS: | All | ||||||
Bug Depends on: | |||||||
Bug Blocks: | 31552 | ||||||
Attachments: |
|
Description
Andreas Kling
2010-02-17 03:57:32 PST
why QWebView? What about QGraphicsWebView, or QWebPage? You're right, this should probably lie farther down the food chain in something like QWebPage. What is fundamental is also being able to set the selected html as well, thus I'm looking for something like QString QWebPage::selectedHTML() const; void QWebPage::setSelectedHTML(QString val); where the latter results in a web page with updated content and the updated portion still selected Well, this is very similar to selectedText(), so I would say it should be both in QWebPage and QWebView, just like selectedText() currently. But yes, at least in QWebPage ;-) IMHO let's keep "setSelectedHTML" out of this wish (i.e. make a separate one for it), it sounds quite more involved, than a simple "get me the selection as HTML" when there's already a "get me the selection as plain text". David, you make a good point. FYI, this is how I currently convert a selection portion to upper case. I replace the selected portion. Aka I have to refer to javascript's insertHTML command... QString text = m_webView->selectedText(); text = input.toUpper(); QWebFrame *frame = m_webView->page()->mainFrame(); QString js = QString("document.execCommand(\"%1\", false, \"%2\")").arg("insertHTML").arg(text); frame->evaluateJavaScript(js); Sorry, that should be: QString text = m_webView->selectedText(); text = text.toUpper(); QString js = QString("document.execCommand(\"%1\", false, \"%2\")").arg("insertHTML").arg(text); QWebFrame *frame = m_webView->page()->mainFrame(); frame->evaluateJavaScript(js); Created attachment 68755 [details]
Proposed patch
Added QWebView::selectedHtml() and QWebPage::selectedHtml()
Returned markup originates from the current selection range.
Comment on attachment 68755 [details]
Proposed patch
LGTM
Comment on attachment 68755 [details]
Proposed patch
This needs API review before landing.
Just want to mention this here for the record. Already discussed it with Andreas on IRC, but I am not sure what the proper resolution should/would be: The call to Range::toHTML() used to obtain the selected text will result in the internal style information, which is not part of the actual page, being included in the html fragment that is returned. This might be appropriate if your intention is to paste the selection into a Rich text editing environment, but that cannot be assumed for this API. At least I do not think. There are use cases such as page validation or text to speech where is additionally and rather ugly inclusion is not a necessary welcome. Infact doing this issue was enough of a concern that someone put the following comments atop WebCore::createMarkup (WebCore/editing/markup.cpp), the function the Range::toHTML() function relies on to create the HTML representation: // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForInterchange? // FIXME: At least, annotation and style info should probably not be included in range.markupString() Attachment 68755 [details] was posted by a committer and has review+, assigning to Andreas Kling for commit.
What's left to be done here? Committed r75242: <http://trac.webkit.org/changeset/75242> |