Bug 35125 - [Qt] Web Inspector does not highlight elements
Summary: [Qt] Web Inspector does not highlight elements
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Qt (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Enhancement
Assignee: Nobody
URL:
Keywords: Qt, QtTriaged
: 47224 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-02-18 11:43 PST by pano_90
Modified: 2011-04-14 13:53 PDT (History)
16 users (show)

See Also:


Attachments
Patch 01 (3.14 KB, patch)
2010-11-18 16:03 PST, Ragner Magalhaes
hausmann: review-
Details | Formatted Diff | Diff
Patch result (91.66 KB, image/png)
2010-11-18 16:08 PST, Ragner Magalhaes
no flags Details
Patch 02 (5.51 KB, patch)
2011-01-26 07:54 PST, Ragner Magalhaes
no flags Details | Formatted Diff | Diff
Patch 03 (5.24 KB, patch)
2011-01-26 09:55 PST, Ragner Magalhaes
no flags Details | Formatted Diff | Diff
Patch 04 (6.38 KB, patch)
2011-02-23 11:27 PST, Ragner Magalhaes
tonikitoo: review+
commit-queue: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pano_90 2010-02-18 11:43:26 PST
The Web Inspector in web browsers using QtWebKit, does not *highlight
elements on a page* when the mouse is hovered over the element's node in the
DOM inspector. Apperently the Web Inpector can do this, because it did in e.g. Safari
(http://www.codeofficer.com/gallery/image_full/75/). So this appears to be
specific to QtWebKit.

original bug report:
https://bugs.kde.org/show_bug.cgi?id=227547
Comment 1 Benjamin Poulain 2010-02-26 14:46:56 PST
This is not a bug per se, but that would be a nice feature to have.

I would not enable that be default but instead provide an API to know which QWebElement is hovered by the mouse (signal webElementHovered/webElementSelected(const QWebElement&)?). With this, any browser could implement fancy effects for the hovered element.
Comment 2 Tor Arne Vestbø 2010-03-10 06:32:59 PST
Please follow the QtWebKit bug reporting guidelines when reporting bugs.

See http://trac.webkit.org/wiki/QtWebKitBugs

Specifically:

  - The 'QtWebKit' component should only be used for bugs/features in the
    public QtWebKit API layer, not to signify that the bug is specific to
    the Qt port of WebKit

      http://trac.webkit.org/wiki/QtWebKitBugs#Component

  - Add the keyword 'Qt' to signal that it's a Qt-related bug

      http://trac.webkit.org/wiki/QtWebKitBugs#Keywords
Comment 3 Ragner Magalhaes 2010-11-18 16:03:46 PST
Created attachment 74311 [details]
Patch 01

Web inspector does highlight elements on the page when the mouse is hovered over the element's node in the DOM inspector.

FIXME: we should be able to only invalidate the rects of he new and old elements.
Comment 4 Ragner Magalhaes 2010-11-18 16:08:17 PST
Created attachment 74312 [details]
Patch result
Comment 5 Benjamin Poulain 2010-11-19 01:44:03 PST
I remember Jocelyn suggested having an API to control the highlight. Something like a signal inspectorHighlight(const QWebElement&). I can't remember the use case, you should ask his opinion on this.
Comment 6 Jocelyn Turcotte 2010-11-22 00:47:54 PST
(In reply to comment #5)

The goal was to allow some WYSIWYG editor component to highlight elements by itself, but this is a kind of narrow use case and highlighting from the inspector is far more useful.
Comment 7 Ragner Magalhaes 2010-11-24 12:09:27 PST
Does anyone could help me to fix this bug!?
I would like to get some review ... :P
Comment 8 Antonio Gomes 2010-11-24 12:52:37 PST
Comment on attachment 74311 [details]
Patch 01

View in context: https://bugs.webkit.org/attachment.cgi?id=74311&action=review

> WebKit/qt/WebCoreSupport/InspectorClientQt.cpp:214
> +        // FIXME: we should be able to only invalidate the rects of
> +        // the new and old nodes.

Why can not you just do it?
Comment 9 Ragner Magalhaes 2010-11-25 05:47:26 PST
(In reply to comment #8)
> (From update of attachment 74311 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=74311&action=review
> 
> > WebKit/qt/WebCoreSupport/InspectorClientQt.cpp:214
> > +        // FIXME: we should be able to only invalidate the rects of
> > +        // the new and old nodes.
> 
> Why can not you just do it?
Thank you Tonikito for your reply! :D

I just would like to know how could I do it?

How could I take that elements?

I just need some start point ;) 
thanks ..
Comment 10 Antonio Gomes 2010-11-25 10:39:11 PST
Comment on attachment 74311 [details]
Patch 01

View in context: https://bugs.webkit.org/attachment.cgi?id=74311&action=review

> WebKit/qt/WebCoreSupport/InspectorClientQt.cpp:217
> +        QRect rect = m_inspectedWebPage->mainFrame()->geometry();
> +        if (!rect.isEmpty())
> +            frame->view()->invalidateRect(rect);

what if you pass node in ::hidelight down to ::hideHighlight

and QRect rect = node->getRect()?
Comment 11 Ragner Magalhaes 2010-12-03 07:56:01 PST
(In reply to comment #10)

> 
> what if you pass node in ::hidelight down to ::hideHighlight
> 
> and QRect rect = node->getRect()?

I did this :D
But it is not working well :( because the inspector controller draws a label out of the rect on top or on bottom. how you can see on https://bug-35125-attachments.webkit.org/attachment.cgi?id=74312.

Sometimes this label can be greater than node's width and I did not find a simple way to get/calculate it!

To calculate the rect of the label I need to duplicate a lot of code from inspector controller. I don't think it is a good idea!

How this patch is just for inspector debug,
I don't think we should worry about performance.

We could just invalidate the visible area from main frame and we could have a inspector debug with highlight working :D how is implemented on chromium and gtk port!
Comment 12 Antonio Gomes 2010-12-03 08:00:35 PST
Ok, I understand.

two other questions:

1) how are other ports doing this?
2) what if you inflate the rect got from node::getRect a bit?

(In reply to comment #11)
> (In reply to comment #10)
> 
> > 
> > what if you pass node in ::hidelight down to ::hideHighlight
> > 
> > and QRect rect = node->getRect()?
> 
> I did this :D
> But it is not working well :( because the inspector controller draws a label out of the rect on top or on bottom. how you can see on https://bug-35125-attachments.webkit.org/attachment.cgi?id=74312.
> 
> Sometimes this label can be greater than node's width and I did not find a simple way to get/calculate it!
> 
> To calculate the rect of the label I need to duplicate a lot of code from inspector controller. I don't think it is a good idea!
> 
> How this patch is just for inspector debug,
> I don't think we should worry about performance.
> 
> We could just invalidate the visible area from main frame and we could have a inspector debug with highlight working :D how is implemented on chromium and gtk port!
Comment 13 Ragner Magalhaes 2010-12-03 09:49:57 PST
(In reply to comment #12)
> Ok, I understand.
> 
> two other questions:
> 
> 1) how are other ports doing this?

They are invalidating all the mainframe's view. 

So I think we could do like them and invalidate just the visible area
of the frame's view!

> 2) what if you inflate the rect got from node::getRect a bit?

I tried this,
but how I don't know the label's width I don't know how many pixels I need to expand the rect! 

Look for the FIXME on my code bellow:

void InspectorClientQt::hideHighlight()
{
    if (!m_highlightedNode)
        return;

    RenderObject* renderer = m_highlightedNode->renderer();
    Frame* frame = m_highlightedNode->document()->frame();
    if (!renderer || !frame || !renderer->isBox())
        return;

    RenderBox *renderBox = m_highlightedNode->renderBox();
    QRect contentBox = m_highlightedNode->getRect();

    // Adjust padding
    contentBox.adjust(-renderBox->paddingLeft(), -renderBox->paddingTop(),
            renderBox->paddingRight(), renderBox->paddingBottom());
    // Adjust border
    contentBox.adjust(-renderBox->borderLeft(), -renderBox->borderTop(),
            renderBox->borderRight(), renderBox->borderBottom());
    // Adjust margin
    contentBox.adjust(-renderBox->marginLeft(), -renderBox->marginTop(),
            renderBox->marginRight(), renderBox->marginBottom());

 
   // FIXME: It is not possible to get the size of the label yet!
   // Adjust for label and box lines
   // contentBox.adjust(-2, ?, ?, ?);

    if (!contentBox.isEmpty())
        frame->view()->invalidateRect(contentBox);

}

Thanks,
Tonikitoo
Comment 14 Eugene Ostroukhov 2010-12-21 11:25:27 PST
I would like to suggest make a public API so this highlight might be triggered not only by Inspector.

I.e. something like QElementHighlight* QWebElement::highlight(<color or some other way to customize highlighting>) and QWebElement::removeHighlight(QElementHighlight*)

In this case web inspector would be just another client of the API. Other users might be some IDEs that may want to highlight several elements (i.e. imagine an CSS editor that highlights elements that match the rule).
Comment 15 Eugene Ostroukhov 2010-12-21 11:27:13 PST
*** Bug 47224 has been marked as a duplicate of this bug. ***
Comment 16 Antonio Gomes 2010-12-21 12:54:00 PST
> In this case web inspector would be just another client of the API. Other users might be some IDEs that may want to highlight several elements (i.e. imagine an CSS editor that highlights elements that match the rule).

It is possible already with QWebElement. see http://doc.trolltech.com/4.5/webkit-fancybrowser.html
Comment 17 Eugene Ostroukhov 2010-12-21 13:26:29 PST
The usecases I see come mostly from the tools space (same goes for Web Inspector requirements) so changing the DOM state (including styles) does not seem to be the right approach.

All that I am asking for is not to keep the drawing code in the Web Inspector-specific areas but to make it more general.
Comment 18 Simon Hausmann 2011-01-19 07:38:37 PST
Comment on attachment 74311 [details]
Patch 01

View in context: https://bugs.webkit.org/attachment.cgi?id=74311&action=review

r- because of the rect issue Antonio pointed out and because of the save() / restore() that should be optimized to not be executed in the common case when there is no highlighted node. Otherwise the patch is going in the right direction I'd say :)

> WebKit/qt/Api/qwebframe.cpp:415
> +#if ENABLE(INSPECTOR)
> +    context->save();
> +    frame->page()->inspectorController()->drawNodeHighlight(*context);
> +    context->restore();
> +#endif

It appears that this code is in QWebFramePrivate::renderRelativeCoords. In the _common_ case we would now end up calling save() and restore() on the graphics context each time we render content, where _most_ of the time drawNodeHighlight() returns immediately. save() and restore() are expensive operations we should avoid if necessary.

I suggest to either add a function tin InspectorController that allows us to perform a check here to see if we need to call drawNodeHighlight() and only then do save() / restore() or alternatively change the implementation of drawNodeHighligh() to do the save() / restore() pair.
Comment 19 Yael 2011-01-19 08:39:36 PST
(In reply to comment #18)
> (From update of attachment 74311 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=74311&action=review
> 
> r- because of the rect issue Antonio pointed out and because of the save() / restore() that should be optimized to not be executed in the common case when there is no highlighted node. Otherwise the patch is going in the right direction I'd say :)
> 
I don't think there is a solution for the rect issue. Please don't let that block this patch.
A I mentioned on IRC, other ports invalidate everything as well.
Comment 20 Ragner Magalhaes 2011-01-19 09:26:10 PST
Hi Simon,
thank you for your review.

(In reply to comment #18)
> (From update of attachment 74311 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=74311&action=review
> 
> r- because of the rect issue Antonio pointed out and because of the save() / restore() that should be optimized to not be executed in the common case when there is no highlighted node. Otherwise the patch is going in the right direction I'd say :)

The inspector controller draws a label out of the highlighted rect on top or on bottom(https://bug-35125-attachments.webkit.org/attachment.cgi?id=74312)
 I don't know how to fix the rect issue because is not possible
to get the label's size/position, the controller just build it in the draw method.

What could I do about the label issue?

> 
> > WebKit/qt/Api/qwebframe.cpp:415
> > +#if ENABLE(INSPECTOR)
> > +    context->save();
> > +    frame->page()->inspectorController()->drawNodeHighlight(*context);
> > +    context->restore();
> > +#endif
> 
> It appears that this code is in QWebFramePrivate::renderRelativeCoords. In the _common_ case we would now end up calling save() and restore() on the graphics context each time we render content, where _most_ of the time drawNodeHighlight() returns immediately. save() and restore() are expensive operations we should avoid if necessary.
> 
> I suggest to either add a function tin InspectorController that allows us to perform a check here to see if we need to call drawNodeHighlight() and only then do save() / restore() or alternatively change the implementation of drawNodeHighligh() to do the save() / restore() pair.

Ok,
I will think about and propose a new patch :D

Thank you
Comment 21 Ragner Magalhaes 2011-01-26 07:54:52 PST
Created attachment 80193 [details]
Patch 02
Comment 22 Antonio Gomes 2011-01-26 08:36:17 PST
Comment on attachment 80193 [details]
Patch 02

View in context: https://bugs.webkit.org/attachment.cgi?id=80193&action=review

Looks good, just needs a better changelog.

> Source/WebCore/ChangeLog:8
> +        In the most of the time drawNodeHighlight() returns immediately because doesn't exist

1) "In the most" sounds bad.
2) "because no highlighted node exists" might read better?
3) "just when a highlighted node exists" ?
Comment 23 Ragner Magalhaes 2011-01-26 09:55:50 PST
Created attachment 80205 [details]
Patch 03
Comment 24 Alexis Menard (darktears) 2011-02-16 11:28:43 PST
Comment on attachment 80205 [details]
Patch 03

The patch looks ok to me and I think the feature is quite useful. I just found cumbersome that void InspectorClientQt::highlight(Node*) actually call hideHighlight() (I know they share the implementation :)).
Comment 25 Antonio Gomes 2011-02-16 11:42:58 PST
Comment on attachment 80205 [details]
Patch 03

r=me
Comment 26 Yael 2011-02-16 12:55:17 PST
(In reply to comment #25)
> (From update of attachment 80205 [details])
> r=me

yey! thanks:)
Comment 27 Ragner Magalhaes 2011-02-23 11:27:59 PST
Created attachment 83511 [details]
Patch 04

Sorry tonikitoo,
In the previous patch I forgot to add highlightedNode() method for InspectorController class
so it was not compiling ... :(

Now it is ok ...

Could you review it for me again?

Sorry my mistake guys.
Comment 28 WebKit Commit Bot 2011-02-24 11:37:17 PST
Comment on attachment 83511 [details]
Patch 04

Rejecting attachment 83511 [details] from commit-queue.

Failed to run "['./Tools/Scripts/webkit-patch', '--status-host=queues.webkit.org', '--bot-id=eseidel-cq-sf', 'ap..." exit_code: 2

Last 500 characters of output:

patching file Source/WebCore/inspector/InspectorController.cpp
Hunk #1 succeeded at 211 with fuzz 1 (offset 3 lines).
patching file Source/WebCore/inspector/InspectorController.h
patching file Source/WebKit/qt/Api/qwebframe.cpp
patching file Source/WebKit/qt/ChangeLog
Hunk #1 succeeded at 1 with fuzz 3.
patching file Source/WebKit/qt/WebCoreSupport/InspectorClientQt.cpp

Failed to run "[u'/Projects/CommitQueue/Tools/Scripts/svn-apply', u'--reviewer', u'Antonio Gomes', u'--force']" exit_code: 1

Full output: http://queues.webkit.org/results/7985563
Comment 29 Eric Seidel (no email) 2011-04-06 10:45:17 PDT
Comment on attachment 80205 [details]
Patch 03

Cleared Antonio Gomes's review+ from obsolete attachment 80205 [details] so that this bug does not appear in http://webkit.org/pending-commit.
Comment 30 Antonio Gomes 2011-04-14 13:46:26 PDT
Ragner's patch is good to go. Just needs to be rebased.
Comment 31 Alexis Menard (darktears) 2011-04-14 13:53:41 PDT
Committed r83892: <http://trac.webkit.org/changeset/83892>