Bug 148067 - Web Inspector: TreeOutline should just dispatch events via WebInspector.Object
Summary: Web Inspector: TreeOutline should just dispatch events via WebInspector.Object
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Matt Baker
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2015-08-16 10:07 PDT by Matt Baker
Modified: 2015-12-01 17:38 PST (History)
8 users (show)

See Also:


Attachments
[Patch] Proposed Fix (47.02 KB, patch)
2015-11-29 00:53 PST, Matt Baker
no flags Details | Formatted Diff | Diff
[Patch] Proposed Fix (51.17 KB, patch)
2015-12-01 16:10 PST, Matt Baker
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Baker 2015-08-16 10:07:56 PDT
* SUMMARY
TreeOutline should just dispatch events via WebInspector.Object.
Comment 1 Radar WebKit Bug Importer 2015-08-16 10:08:14 PDT
<rdar://problem/22301243>
Comment 2 Matt Baker 2015-11-29 00:53:42 PST
Created attachment 266222 [details]
[Patch] Proposed Fix
Comment 3 BJ Burg 2015-11-30 14:58:47 PST
Comment on attachment 266222 [details]
[Patch] Proposed Fix

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

r=me, would like Tim to comment on event names though.

Please rename these events and related code:

s/SelectedElementChanged/SelectionChanged/
s/ElementHiddenChanged/ElementVisibilityChanged/

> Source/WebInspectorUI/UserInterface/Views/TreeOutline.js:142
> +        if (this.treeOutline)

Do we ever need this check? We assume it exists in some calls to dispatchEventToListeners(), but not others. This one seems to be a more paranoid check than was there before, while others are neutral.

> Source/WebInspectorUI/UserInterface/Views/TreeOutline.js:1018
> +            if (this.onselect)

What is this for? I thought we removed onselect

> Source/WebInspectorUI/UserInterface/Views/TreeOutlineDataGridSynchronizer.js:-52
> -        // FIXME: This is a hack. TreeOutline should just dispatch events via WebInspector.Object.

Good riddance!

> Source/WebInspectorUI/UserInterface/Views/TreeOutlineDataGridSynchronizer.js:208
> +    _treeElementSelected(event)

This should match the new event name.
Comment 4 Matt Baker 2015-11-30 20:13:28 PST
(In reply to comment #3)
> Comment on attachment 266222 [details]
> [Patch] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=266222&action=review
> 
> r=me, would like Tim to comment on event names though.
> 
> Please rename these events and related code:
> 
> s/SelectedElementChanged/SelectionChanged/
> s/ElementHiddenChanged/ElementVisibilityChanged/
> 
> > Source/WebInspectorUI/UserInterface/Views/TreeOutline.js:142
> > +        if (this.treeOutline)
> 
> Do we ever need this check? We assume it exists in some calls to
> dispatchEventToListeners(), but not others. This one seems to be a more
> paranoid check than was there before, while others are neutral.

I'll take a look and see if it is ever null.

> > Source/WebInspectorUI/UserInterface/Views/TreeOutline.js:1018
> > +            if (this.onselect)
> 
> What is this for? I thought we removed onselect

This is calling TreeElement.onselect. DOMTreeElement still overrides this, oncollapse, and other methods.

> > Source/WebInspectorUI/UserInterface/Views/TreeOutlineDataGridSynchronizer.js:-52
> > -        // FIXME: This is a hack. TreeOutline should just dispatch events via WebInspector.Object.
> 
> Good riddance!
> 
> > Source/WebInspectorUI/UserInterface/Views/TreeOutlineDataGridSynchronizer.js:208
> > +    _treeElementSelected(event)
> 
> This should match the new event name.
Comment 5 Timothy Hatcher 2015-12-01 13:30:50 PST
I suggested some better event names on IRC.
Comment 6 Matt Baker 2015-12-01 13:49:34 PST
(In reply to comment #5)
> I suggested some better event names on IRC.

Are we happy with the following?

ElementAdded
ElementDidChange
ElementRemoved
ElementDisclosureDidChange
ElementVisibilityDidChange
SelectionDidChange
Comment 7 Matt Baker 2015-12-01 14:51:23 PST
Comment on attachment 266222 [details]
[Patch] Proposed Fix

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

>>> Source/WebInspectorUI/UserInterface/Views/TreeOutline.js:142
>>> +        if (this.treeOutline)
>> 
>> Do we ever need this check? We assume it exists in some calls to dispatchEventToListeners(), but not others. This one seems to be a more paranoid check than was there before, while others are neutral.
> 
> I'll take a look and see if it is ever null.

These checks are needed. Many operations in TreeOutline that dispatch events are also bound to TreeElement, which may be in a detached state. I missed a few checks in the TreeOutline.prototype.remove* family of methods which I'll add.

I think we should reconsider TreeOutline's design at some point. BindingTreeOutline methods to another class to achieve reuse makes the code harder to follow. Instead, TreeOutline should have a public getter for an invisible root that always exists:

let tree = new WebInspector.TreeOutline;
tree.root.appendChild(childElement);

If having to get the root is too verbose, TreeOutline could encapsulate the invisible root and forward operations to it:

TreeOutline.prototype.appendChild = function(child) {
    this.root.appendChild(child);
}
Comment 8 Matt Baker 2015-12-01 16:10:59 PST
Created attachment 266406 [details]
[Patch] Proposed Fix

Left r? since a bunch of names have changed
Comment 9 Timothy Hatcher 2015-12-01 16:53:10 PST
Comment on attachment 266406 [details]
[Patch] Proposed Fix

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

> Source/WebInspectorUI/UserInterface/Views/TreeOutline.js:864
> +        // Set this before onpopulate. Since onpopulate can add elements and dispatch an ElementAdded event,

We should rename onpopulate, to sound more like a subclass able method than an event.
Comment 10 WebKit Commit Bot 2015-12-01 17:37:57 PST
Comment on attachment 266406 [details]
[Patch] Proposed Fix

Clearing flags on attachment: 266406

Committed r192936: <http://trac.webkit.org/changeset/192936>
Comment 11 WebKit Commit Bot 2015-12-01 17:38:00 PST
All reviewed patches have been landed.  Closing bug.