Closed Bug 672003 Opened 13 years ago Closed 12 years ago

[highlighter] Toggleable classes in the selected node's "infobar"

Categories

(DevTools :: General, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: rcampbell, Assigned: paul)

References

Details

(Whiteboard: [minotaur][best: 2d, likely: 3d, worst: 4d][has-patch])

Attachments

(1 file, 4 obsolete files)

The classlist in the selected node's "infobar" (toolbar) should be toggleable. That is, when clicking one it removes it from the node's classlist. Clicking it again re-adds it. It will provide a quick way to see the effects of a given class on a node in the highlighter
Whiteboard: [minotaur]
Assignee: nobody → paul
this bug needs a patch, badly!
Priority: -- → P1
Whiteboard: [minotaur] → [minotaur][has-patch]
I'm assuming, in that case, that [has-patch] was in error.
Whiteboard: [minotaur][has-patch] → [minotaur][best: 2d, likely: 3d, worst: 4d]
Oh, it was a hoarded patch.
Whiteboard: [minotaur][best: 2d, likely: 3d, worst: 4d] → [minotaur][best: 2d, likely: 3d, worst: 4d][has-patch]
Attached patch patch v0.1 WIP (obsolete) — Splinter Review
Attached patch patch v0.2 WIP (obsolete) — Splinter Review
rebased.
Attachment #550401 - Attachment is obsolete: true
Attached patch patch v0.3 (no test) (obsolete) — Splinter Review
The highlighter is not updated any more when class change. The mutation events should trigger an update (bug 566085).
Attachment #551086 - Attachment is obsolete: true
Depends on: 566085
Attached patch patch v1 (obsolete) — Splinter Review
Attachment #557988 - Attachment is obsolete: true
Attachment #560599 - Flags: review?(rcampbell)
Priority: P1 → P3
Comment on attachment 560599 [details] [diff] [review]
patch v1

in inspector.js

nit!
+   */
+   buildInfobarClassButton:
+     function Highlighter_buildInfobarClassButton(aClass, aDisabled)

function indentation should be under the b in buildInfo...

and,
+  getAlteredClassList:  function Highlighter_getAlteredClassList(aNode)

extra space after the :

I can't see what method the if (alteredClasses) block is in because I don't have context. Is that for loop being executed everytime the highlighter is repositioned? It could be costly.

+    aNode.classList.add(aClass);
+  },
+
+
+
+
   /////////////////////////////////////////////////////////////////////////
   //// Event Handling

extra gap between the end of this method and the event handling section.

I think this is pretty decent. Still need to see it in action to get a feel for the behavior.
Rebased (from inspector.js to the jsm) + rob's comments.



(In reply to Rob Campbell [:rc] (robcee) from comment #8)
> Comment on attachment 560599 [details] [diff] [review] [diff] [details] [review]
> patch v1
>
> I can't see what method the if (alteredClasses) block is in because I don't
> have context. Is that for loop being executed everytime the highlighter is
> repositioned? It could be costly.

It is in this loop (updateInfobar()), and it is updated when a new node is selected (not when the highlighter is repositioned). Yes, it is costly, but not more than the original updateInfobar. What do you consider costly here?
Attachment #560599 - Attachment is obsolete: true
Attachment #562742 - Flags: review?(rcampbell)
Attachment #560599 - Flags: review?(rcampbell)
Comment on attachment 562742 [details] [diff] [review]
patch v1.1 - rebased

in inspector.jsm:

this:
+    let alteredClasses = this.getAlteredClassList(this.node);
+
+    if (alteredClasses) {
       let fragment = this.chromeDoc.createDocumentFragment();
-      for (let i = 0; i < this.node.classList.length; i++) {
-        let classLabel = this.chromeDoc.createElement("label");
-        classLabel.className = "highlighter-nodeinfobar-class plain";
-        classLabel.textContent = this.node.classList[i];
-        fragment.appendChild(classLabel);
+      for (let oneClass in alteredClasses) {
+        let disabled = alteredClasses[oneClass];
+        let button = this.buildInfobarClassButton(oneClass, disabled);
+        fragment.appendChild(button);
       }
       classes.appendChild(fragment);
+    } else {
+      if (this.node.className) {
+        let fragment = this.chromeDoc.createDocumentFragment();
+        for (let i = 0; i < this.node.classList.length; i++) {
+          let oneClass = this.node.classList[i];
+          let button = this.buildInfobarClassButton(oneClass, false);
+          fragment.appendChild(button);
+        }
+        classes.appendChild(fragment);
+      }

I think can be replaced with something like:

let alteredClasses = this.getAlteredClassList(this.node);
let fragment = this.chromeDoc.createDocumentFragment();

for (let i = 0; i < this.node.classList.length; i++) {
  let oneClass = this.node.classList[i];
  let disabled = alteredClasses && alteredClasses[oneClass];
  let button = this.buildInfobarClassButton(oneClass, disabled);
  fragment.appendChild(button);
}

classes.appendChild(fragment);

... though this didn't work as included here in testing for some reason.

+  buildInfobarClassButton:
+    function Highlighter_buildInfobarClassButton(aClass, aDisabled)
+  {

indent function directly under the property, e.g., 

buildInfobarClassButton:
function Highlighter...

NIT in getAlteredClassList:

+    for (let i = 0; i < this.alteredNodes.length; i++)
+    {

try to be consistent in your bracket cuddling. :)

this patch tests fine in both opt and debug, so that's good. I did make a couple of observations though:

1) The HTML panel isn't updated if shown when a class is removed. This could probably be done in a followup.

2) Same probably applies to Style Inspector.

3) Switching tabs and returning presents an incorrect view of the content page. Classes that were disabled are just gone and unable to be restored unless you reload.

I'm a little worried about modifying content like this. One of the goals of this tool was to not make any changes to content if at all possible, though modifying attributes is already possible. It just feels like toggling a class through this type of button shouldn't be quite so destructive.

Any ideas? Welcome feedback and opinions from others here.
Attachment #562742 - Flags: review?(rcampbell) → review-
(In reply to Rob Campbell [:rc] (robcee) from comment #10) 
> I'm a little worried about modifying content like this. One of the goals of
> this tool was to not make any changes to content if at all possible, though
> modifying attributes is already possible. It just feels like toggling a
> class through this type of button shouldn't be quite so destructive.
> 
> Any ideas? Welcome feedback and opinions from others here.

I understood the goal to be more like "Don't modify content as an implementation detail of the tool", not "don't allow modification of content through this tool".

Toggling the classes seems useful for quickly understanding their effects on rendering.  We could maybe do that non-destructively through some sort of shenanigans (somehow rendering with one set of classes but maintaining the dom unmodified) but that sounds more difficult to explain/understand than just modifying the dom.

We could consider ways to make the interaction more explicit (maybe just clicking is too easy for a destructive change).

If we're more concerned about the minor data loss than mutations, we could maintain a weakmap of nodes -> classes-that-have-been-toggled-off-with-this-ui, so that we don't lose the toggled-off classes after changing selected nodes.
(In reply to Rob Campbell [:rc] (robcee) from comment #10)

> 1) The HTML panel isn't updated if shown when a class is removed. This could
> probably be done in a followup.
> 
> 2) Same probably applies to Style Inspector.

Yeah, a convincing case could be made that we should wait to land (or enable) this until all the tools are properly responding to content changes.
(In reply to Dave Camp (:dcamp) from comment #11)
> (In reply to Rob Campbell [:rc] (robcee) from comment #10) 
> > I'm a little worried about modifying content like this. One of the goals of
> > this tool was to not make any changes to content if at all possible, though
> > modifying attributes is already possible. It just feels like toggling a
> > class through this type of button shouldn't be quite so destructive.
> > 
> > Any ideas? Welcome feedback and opinions from others here.
> 
> I understood the goal to be more like "Don't modify content as an
> implementation detail of the tool", not "don't allow modification of content
> through this tool".
> 
> Toggling the classes seems useful for quickly understanding their effects on
> rendering.  We could maybe do that non-destructively through some sort of
> shenanigans (somehow rendering with one set of classes but maintaining the
> dom unmodified) but that sounds more difficult to explain/understand than
> just modifying the dom.
> 
> We could consider ways to make the interaction more explicit (maybe just
> clicking is too easy for a destructive change).
> 
> If we're more concerned about the minor data loss than mutations, we could
> maintain a weakmap of nodes ->
> classes-that-have-been-toggled-off-with-this-ui, so that we don't lose the
> toggled-off classes after changing selected nodes.

I think the dataloss is the bigger deal here. Mutation is acceptable, otherwise, how else are we going to be able to try out changes unless we load a separate copy of a web page for manipulating with the tools. I think it should be a goal that users can get back to the original state no matter what happens.

(In reply to Dave Camp (:dcamp) from comment #12)
> (In reply to Rob Campbell [:rc] (robcee) from comment #10)
> 
> > 1) The HTML panel isn't updated if shown when a class is removed. This could
> > probably be done in a followup.
> > 
> > 2) Same probably applies to Style Inspector.
> 
> Yeah, a convincing case could be made that we should wait to land (or
> enable) this until all the tools are properly responding to content changes.

Probably not a bad idea. Though we could also land this while working on the problem. That might be preferable to having to continually rebase this until we get there.

I think we could get most of what we need with a toolsUpdate(node) method in IUI that can be called whenever a mutation occurs.
WONTFIX?
If someone thinks we still need this feature, feel free to reopen.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WONTFIX
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: