Closed
Bug 360898
Opened 19 years ago
Closed 19 years ago
Option to hide processing instructions
Categories
(Other Applications :: DOM Inspector, enhancement)
Other Applications
DOM Inspector
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: neil, Assigned: sdwilsh)
References
Details
Attachments
(1 file, 6 obsolete files)
12.62 KB,
patch
|
db48x
:
review+
|
Details | Diff | Splinter Review |
Processing instructions (and there can be quite a few for documents with many overlays) now appear in XUL documents, but I think they're just clutter ;-)
Assignee | ||
Comment 1•19 years ago
|
||
Do we want to add a new preference - something like "inspector.dom.showProcessingInstructions"?
Status: NEW → ASSIGNED
Reporter | ||
Comment 2•19 years ago
|
||
Sounds good to me.
P.S. Did you mean to assign it to yourself? ;-)
Assignee | ||
Updated•19 years ago
|
Assignee: dom-inspector → comrade693+bmo
Status: ASSIGNED → NEW
Assignee | ||
Comment 3•19 years ago
|
||
I can't actually test this since my computer doesn't want to build for whatever reason, but I figured I'd throw this out there. I think it will accomplish the task at hand, but I'm not sure :(
Comment 4•19 years ago
|
||
Comment on attachment 245785 [details] [diff] [review]
v1.0
>Index: layout/inspector/public/inIDOMView.idl
> interface inIDOMView : nsISupports
Rev the IID.
Reporter | ||
Comment 5•19 years ago
|
||
Hey, I wonder whether we can do this by tweaking the whatToShow attribute?
Assignee | ||
Comment 6•19 years ago
|
||
(In reply to comment #5)
> Hey, I wonder whether we can do this by tweaking the whatToShow attribute?
I suppose we could do that if we did something like:
NS_IMETHODIMP
inDOMView::SetShowProcessingInstructions(PRBool aShowProcessingInstructions)
{
if (mShowProcessingInstructions == aShowProcessingInstructions)
return NS_OK;
mShowProcessingInstructions = aShowProcessingInstructions;
if (mShowProcessingInstructions) {
mWhatToShow = mWhatToShow | nsIDOMNodeFilter::SHOW_PROCESSING_INSTRUCTION;
} else {
mWhatToShow = mWhatToShow ^ nsIDOMNodeFilter::SHOW_PROCESSING_INSTRUCTION;
}
return NS_OK;
}
Someone check me on that logic though.
Status: NEW → ASSIGNED
Reporter | ||
Comment 7•19 years ago
|
||
Or you could move the bit-twiddling logic into the JS front end.
Assignee | ||
Comment 8•19 years ago
|
||
This works quite nicely (I forgot I could build on my mac).
Neil - I didn't move the bit twiddling to the JS because I felt that if anyone else ever wanted to use this in something else, I'd rather it work for them instead of the fiddling with it in their JS. Doing it this way keeps the toggleProcessingInstructions/setProcessingInstructions inline with other existing toggleSomething/setSomething functions in dom.js.
This removes outdated locales from the Makefile and adds the proper entities to the dom.dtd file. Let me know if I should use a different access key.
Attachment #245785 -
Attachment is obsolete: true
Attachment #245808 -
Flags: superreview?(neil)
Attachment #245808 -
Flags: review?(timeless)
Reporter | ||
Comment 9•19 years ago
|
||
Comment on attachment 245808 [details] [diff] [review]
v1.1
>+ this.setProcessingInstructions(PrefUtils.getPref("inspector.dom.showProcessingInstructions"));
Execpt it's a two-arg function :-P
>+ mShowProcessingInstructions(PR_TRUE),
> mWhatToShow(nsIDOMNodeFilter::SHOW_ALL)
I don't like this because the two could get out of sync.
Assignee | ||
Comment 10•19 years ago
|
||
(In reply to comment #9)
> (From update of attachment 245808 [details] [diff] [review] [edit])
> >+ this.setProcessingInstructions(PrefUtils.getPref("inspector.dom.showProcessingInstructions"));
> Execpt it's a two-arg function :-P
whoops...
> >+ mShowProcessingInstructions(PR_TRUE),
> > mWhatToShow(nsIDOMNodeFilter::SHOW_ALL)
> I don't like this because the two could get out of sync.
Good point. I'll have a revised patch this evening. Looks like I'll be playing with whatToShow in the JS.
Assignee | ||
Updated•19 years ago
|
Attachment #245808 -
Flags: superreview?(neil)
Attachment #245808 -
Flags: review?(timeless)
Assignee | ||
Comment 11•19 years ago
|
||
Alright, this doesn't change the component anymore and does all of it's magic in the JS file. I cleaned up some formatting of code (added javadoc headers and changed anonymous functions to named functions) when I was nearby it.
I also forgot to include the changes to the default preferences file for the DOM Inspector.
Attachment #245808 -
Attachment is obsolete: true
Attachment #245871 -
Flags: superreview?(neil)
Attachment #245871 -
Flags: review?(timeless)
Reporter | ||
Comment 12•19 years ago
|
||
Comment on attachment 245871 [details] [diff] [review]
v1.2
>- this.mDOMView.whatToShow &= ~(NodeFilter.SHOW_ATTRIBUTE); // hide attribute nodes
>+ // hide attribute nodes
>+ this.mDOMView.whatToShow &= ~(NodeFilter.SHOW_ATTRIBUTE);
>+ if (PrefUtils.getPref("inspector.dom.showProcessingInstructions")) {
>+ this.mDOMView.whatToShow |= NodeFilter.SHOW_PROCESSING_INSTRUCTION;
>+ } else {
>+ this.mDOMView.whatToShow &= ~(NodeFilter.SHOW_PROCESSING_INSTRUCTION);
>+ }
Nit: all options are on by default, so you only need to turn it off if the pref is unset. I don't know why the existing code uses ~(NodeFilter.SHOW_ATTRIBUTE); I would just use ~NodeFilter.SHOW_ATTRIBUTE;
>+ var value = !PrefUtils.getPref("inspector.dom.showProcessingInstructions");
Actually to be consistent with the other settings you should use
!(this.mDOMView.whatToShow & NodeFilter.SHOW_PROCESSING_INSTRUCTION)
>+ var curVal = PrefUtils.getPref("inspector.dom.showProcessingInstructions");
>+ // If the value isn't changing, don't run
>+ if (curVal == aValue) return;
This might not be optimal, see the bug I'm about to file.
Attachment #245871 -
Flags: superreview?(neil) → superreview+
Assignee | ||
Comment 13•19 years ago
|
||
(In reply to comment #12)
> Nit: all options are on by default, so you only need to turn it off if the pref
> is unset. I don't know why the existing code uses ~(NodeFilter.SHOW_ATTRIBUTE);
> I would just use ~NodeFilter.SHOW_ATTRIBUTE;
Fixed.
> Actually to be consistent with the other settings you should use
> !(this.mDOMView.whatToShow & NodeFilter.SHOW_PROCESSING_INSTRUCTION)
Fixed.
> This might not be optimal, see the bug I'm about to file.
I believe I handle it correctly though (https://bugzilla.mozilla.org/attachment.cgi?id=245871&action=diff#mozilla/extensions/inspector/resources/content/viewers/dom/dom.js_sec5), but I do agree that the existing code for other things didn't work right.
The main reason why that line is there is because rebuild is expensive, and if we don't have to rebuild, I don't want to. This is only an issue when loading because I set whatToShow in the DOMView constructor, and then I call setProcessingInstructions in the initialize function to set-up the menu items. I essentially copied this idea from setWhitespaceNodes, but they used a lot more comments to explain it. I can do that if need be.
Attachment #245871 -
Flags: review?(timeless) → review+
Assignee | ||
Comment 14•19 years ago
|
||
So, I lied about being sure that it would work right with the observer. So, I had to make a code change that isn't big, but I figure it should be reviewed.
The observer works nicely (I tested it while playing in about:config).
Attachment #245871 -
Attachment is obsolete: true
Attachment #245924 -
Flags: superreview?(neil)
Attachment #245924 -
Flags: review?(timeless)
Reporter | ||
Comment 15•19 years ago
|
||
Comment on attachment 245924 [details] [diff] [review]
v1.3
>+ aRebuild)
I don't understand why you reintroduced this parameter.
>+ var curVal = PrefUtils.getPref("inspector.dom.showProcessingInstructions");
Unused?
Assignee | ||
Comment 16•19 years ago
|
||
(In reply to comment #15)
> I don't understand why you reintroduced this parameter.
We don't rebuild on initialize because it will already have the correct value from the DOMView constructor. We do however need to call the function to set the check status of the command attribute. Every other call will rebuild, however.
> Unused?
Yes, that shouldn't be there. Will be removed in final patch.
Reporter | ||
Comment 17•19 years ago
|
||
Comment on attachment 245924 [details] [diff] [review]
v1.3
>+ if (!PrefUtils.getPref("inspector.dom.showProcessingInstructions")) {
>+ this.mDOMView.whatToShow &= ~NodeFilter.SHOW_PROCESSING_INSTRUCTION;
>+ }
Except you have custom initialization code...
Assignee | ||
Comment 18•19 years ago
|
||
(In reply to comment #17)
> Except you have custom initialization code...
I see I need a better explanation. In the constructor for DOMViewer I do have code that initializes the state of whatToShow. This happens before the initial build of the tree, which as far as I can tell happens in the second to last line of the constructor (http://lxr.mozilla.org/seamonkey/source/extensions/inspector/resources/content/viewers/dom/dom.js#86). However, this doesn't do anything with the menu items and their checked status. This is why initialize calls setProcessingInstructions with the rebuild parameter set to false. The tree has already been built correctly, but the menuitem's checked state hasn't been updated yet.
The problem with v1.2's code was that I was attempting to prevent rebuild if the value passed to the function was the same as the preference. However, this wouldn't work correctly if the preference was changed elsewhere and the observer called the function.
I suppose I could drop rebuild and just always rebuild the tree, but then we are doing a rebuild when we don't need to (and arguably shouldn't) when initialize calls this.setProcessingInstructions.
Reporter | ||
Comment 19•19 years ago
|
||
(In reply to comment #18)
>However, this doesn't do anything with the menu items and their checked
>status. This is why initialize calls setProcessingInstructions with the
>rebuild parameter set to false. The tree has already been built correctly, but
>the menuitem's checked state hasn't been updated yet.
So if you have to call setProcessingInstructions can you remove that custom initialization?
Assignee | ||
Comment 20•19 years ago
|
||
(In reply to comment #19)
> So if you have to call setProcessingInstructions can you remove that custom
> initialization?
I could, but then we would build the tree in the constructor (DOMViewer), and then rebuild the tree in setProcessingInstructions. I feel that building the tree twice would be a bad thing, but if that is the direction you want me to take, I can do that.
Reporter | ||
Comment 21•19 years ago
|
||
Sorry, I meant leave the rebuild flag in, but don't initialise the tree twice [first with the custom code and second with setProcessingInstructions(false)].
Reporter | ||
Comment 22•19 years ago
|
||
Comment on attachment 245924 [details] [diff] [review]
v1.3
As I read it,
>+ if (!PrefUtils.getPref("inspector.dom.showProcessingInstructions")) {
>+ this.mDOMView.whatToShow &= ~NodeFilter.SHOW_PROCESSING_INSTRUCTION;
>+ }
is made superfluous by
>+ this.setProcessingInstructions(PrefUtils.getPref("inspector.dom.showProcessingInstructions"), false);
which you need anyway to update the menuitem.
Attachment #245924 -
Flags: superreview?(neil) → superreview-
Assignee | ||
Comment 23•19 years ago
|
||
(In reply to comment #22)
> As I read it,
> >+ if (!PrefUtils.getPref("inspector.dom.showProcessingInstructions")) {
> >+ this.mDOMView.whatToShow &= ~NodeFilter.SHOW_PROCESSING_INSTRUCTION;
> >+ }
> is made superfluous by
> >+ this.setProcessingInstructions(PrefUtils.getPref("inspector.dom.showProcessingInstructions"), false);
> which you need anyway to update the menuitem.
This is true. However, this builds the tree, correct?
> this.mDOMTree.treeBoxObject.view = this.mDOMView;
Unless we want to rebuild we need the code in question. Would you be happier if I did something like this?
>+ setProcessingInstructions: function setProcessingInstructions(aValue,
>+ aRebuild)
>+ {
>+ this.mPanel.panelset.setCommandAttribute("cmd:toggleProcessingInstructions",
>+ "checked", aValue);
>+ if (!aRebuild) return;
>+ var curVal = PrefUtils.getPref("inspector.dom.showProcessingInstructions");
>+
>+ if (aValue) {
>+ this.mDOMView.whatToShow |= NodeFilter.SHOW_PROCESSING_INSTRUCTION;
>+ } else {
>+ this.mDOMView.whatToShow &= ~NodeFilter.SHOW_PROCESSING_INSTRUCTION;
>+ }
>+ if ( curValue != aValue) {
>+ PrefUtils.setPref("inspector.dom.showProcessingInstructions", aValue);
>+ }
>+
>+ this.rebuild();
>+ },
Explanation:
If we don't want to rebuild, we return before setting this.mDOMViewer.whatToShow againe. We will only return when initialize is called since it is the only time rebuild is false. Otherwise, we rebuild because this.mDOMViewer.whatToShow should be changing.
The whole point of this is to prevent a rebuild on the initial loading of the viewer.
Reporter | ||
Comment 24•19 years ago
|
||
Actually the initial rebuild happens somewhere inside notifyViewerReady so I therefore put it to you that we're not actually ready when we notify ;-)
Attachment #245924 -
Flags: review?(timeless)
Assignee | ||
Comment 25•19 years ago
|
||
(In reply to comment #24)
> Actually the initial rebuild happens somewhere inside notifyViewerReady so I
> therefore put it to you that we're not actually ready when we notify ;-)
Well, if the tree is built in notifyViewerReady, aren't we ready then? Or are you saying that aPane.notifyViewerReady(this); should be the last thing called in initialize?
Reporter | ||
Comment 26•19 years ago
|
||
(In reply to comment #25)
>Or are you saying that aPane.notifyViewerReady(this); should be the last thing
>called in initialize?
Sounds good to me.
Assignee | ||
Comment 27•19 years ago
|
||
I believe this addresses all the issues brought up.
Attachment #245924 -
Attachment is obsolete: true
Attachment #246242 -
Flags: superreview?(neil)
Attachment #246242 -
Flags: review?(timeless)
Reporter | ||
Comment 28•19 years ago
|
||
Comment on attachment 246242 [details] [diff] [review]
v1.4
>- this.mDOMView.whatToShow &= ~(NodeFilter.SHOW_ATTRIBUTE); // hide attribute nodes
>+ // hide attribute nodes
>+ this.mDOMView.whatToShow &= ~NodeFilter.SHOW_ATTRIBUTE;
>+ if (!PrefUtils.getPref("inspector.dom.showProcessingInstructions")) {
>+ this.mDOMView.whatToShow &= ~NodeFilter.SHOW_PROCESSING_INSTRUCTION;
>+ }
So, my idea is that by changing the code below to match the other cases i.e. if (aRebuild) this.rebuild(); then you don't need the change above.
>+ if (!aRebuild) return;
>+
>+ if (aValue) {
>+ this.mDOMView.whatToShow |= NodeFilter.SHOW_PROCESSING_INSTRUCTION;
>+ } else {
>+ this.mDOMView.whatToShow &= ~NodeFilter.SHOW_PROCESSING_INSTRUCTION;
>+ }
>+
>+ var curVal = PrefUtils.getPref("inspector.dom.showProcessingInstructions");
>+ if (curVal != aValue) {
>+ PrefUtils.setPref("inspector.dom.showProcessingInstructions", aValue);
>+ }
>+
>+ this.rebuild();
Also I don't think you need the curVal check, and watch for trailing spaces.
Assignee | ||
Updated•19 years ago
|
Attachment #246242 -
Flags: superreview?(neil)
Attachment #246242 -
Flags: review?(timeless)
Assignee | ||
Comment 29•19 years ago
|
||
Ok, so as far as I'm seeing, this works.
I still have the currValue check, and that's because when we change the pref, the observer will be called, which calls this function, which would change the pref, which would call the observer....yey for recursion.
I think I addressed all of your comments as well.
Attachment #246242 -
Attachment is obsolete: true
Attachment #248012 -
Flags: superreview?(neil)
Attachment #248012 -
Flags: review?(db48x)
Reporter | ||
Comment 30•19 years ago
|
||
Comment on attachment 248012 [details] [diff] [review]
v1.5
sr=me with these fixed:
>- this.mDOMView.whatToShow &= ~(NodeFilter.SHOW_ATTRIBUTE); // hide attribute nodes
>+ // hide attribute nodes
>+ this.mDOMView.whatToShow &= ~NodeFilter.SHOW_ATTRIBUTE;
Don't bother with this change any more.
>+ var curVal = PrefUtils.getPref("inspector.dom.showProcessingInstructions");
>+ if (curVal != aValue) {
>+ PrefUtils.setPref("inspector.dom.showProcessingInstructions", aValue);
>+ }
Strangely enough all the other prefs manage without it ;-) - for details see pref_ValueChanged in prefapi.cpp - but as I mentioned in bug 361146 you could alternatively make ToggleProcessingInstructions set the pref directly.
>+ <!ENTITY cmdToggleProcessingInstructions.label "Show Processing Instructions">
>+ <!ENTITY cmdToggleProcessingInstructions.accesskey "p">
Nit: should be uppercase P to match (access key code prefers a case-sensitive match first, then falls back to a case-insensitive match).
Attachment #248012 -
Flags: superreview?(neil) → superreview+
Assignee | ||
Comment 31•19 years ago
|
||
Attachment #248012 -
Attachment is obsolete: true
Attachment #248037 -
Flags: review?(db48x)
Attachment #248037 -
Flags: approval-l10n?
Attachment #248012 -
Flags: review?(db48x)
Comment 32•19 years ago
|
||
Comment on attachment 248037 [details] [diff] [review]
v1.6
>+ <menuitem id="item:toggleProcessingInstructions"
>+ <menuitem id="item:toggleProcessingInstructions"
These two have the same id. You could actually get rid of the id altogether, since nothing ever needs to refer to this element by it's id.
My only other comment is that you ought to avoid the setShowPI() -> onPrefChanged() -> setShowPI() recursion. It's not fatal because it stops after one iteration, because the second setShowPI() will set the pref to the value the pref already has so onPrefChanged() won't be called again, but it is wasteful. Make setShowPI() set the pref, and make onPrefChanged() call rebuild(). You're probably just following the pattern set by the rest of the code, but that doesn't make it right.
r=db48x with those changes.
Attachment #248037 -
Flags: review?(db48x) → review+
Reporter | ||
Comment 33•19 years ago
|
||
(In reply to comment #32)
>(From update of attachment 248037 [details] [diff] [review])
>>+ <menuitem id="item:toggleProcessingInstructions"
>>+ <menuitem id="item:toggleProcessingInstructions"
>These two have the same id.
I think these menuitems get overlaid into in different documents.
>My only other comment is that you ought to avoid the setShowPI() ->
>onPrefChanged() -> setShowPI() recursion.
I meant to file a bug on that (for the other prefs) - see comment 30.
Comment 34•19 years ago
|
||
(In reply to comment #33)
> (In reply to comment #32)
> >(From update of attachment 248037 [details] [diff] [review] [edit])
> >>+ <menuitem id="item:toggleProcessingInstructions"
> >>+ <menuitem id="item:toggleProcessingInstructions"
> >These two have the same id.
> I think these menuitems get overlaid into in different documents.
They're still in the same XML document (the overlay file) and therefore shouldn't have the same id. And anyway, nothing ever uses the id, so it's pointless. That said, it's just a nit and I really don't care much.
>
> >My only other comment is that you ought to avoid the setShowPI() ->
> >onPrefChanged() -> setShowPI() recursion.
> I meant to file a bug on that (for the other prefs) - see comment 30.
cc me on that bug, if you would.
Assignee | ||
Comment 35•19 years ago
|
||
(In reply to comment #32)
> (From update of attachment 248037 [details] [diff] [review] [edit])
> >+ <menuitem id="item:toggleProcessingInstructions"
> >+ <menuitem id="item:toggleProcessingInstructions"
>
> These two have the same id. You could actually get rid of the id altogether,
> since nothing ever needs to refer to this element by it's id.
>
> My only other comment is that you ought to avoid the setShowPI() ->
> onPrefChanged() -> setShowPI() recursion. It's not fatal because it stops after
> one iteration, because the second setShowPI() will set the pref to the value
> the pref already has so onPrefChanged() won't be called again, but it is
> wasteful. Make setShowPI() set the pref, and make onPrefChanged() call
> rebuild(). You're probably just following the pattern set by the rest of the
> code, but that doesn't make it right.
>
> r=db48x with those changes.
Would you be OK with both of those issues being fixed in separate bugs since the whole file really needs to be changed for both?
Comment 36•19 years ago
|
||
(In reply to comment #35)
> (In reply to comment #32)
> > r=db48x with those changes.
>
> Would you be OK with both of those issues being fixed in separate bugs since
> the whole file really needs to be changed for both?
>
Yes
Assignee | ||
Comment 37•19 years ago
|
||
(In reply to comment #32)
> My only other comment is that you ought to avoid the setShowPI() ->
> onPrefChanged() -> setShowPI() recursion. It's not fatal because it stops after
> one iteration, because the second setShowPI() will set the pref to the value
> the pref already has so onPrefChanged() won't be called again, but it is
> wasteful. Make setShowPI() set the pref, and make onPrefChanged() call
> rebuild(). You're probably just following the pattern set by the rest of the
> code, but that doesn't make it right.
Before I file the bug, I want to check - that fix doesn't actually stop the wasteful call to set the pref, and you just want to drop the rebuild parameter and put that in onPrefChanged, correct?
Reporter | ||
Comment 38•19 years ago
|
||
(In reply to comment #37)
>Before I file the bug, I want to check - that fix doesn't actually stop the
>wasteful call to set the pref
Old code:
menuitem -> command -> toggler -> setter -> pref -> observer -> setter -> pref
New code:
menuitem -> command -> toggler -> pref -> observer -> setter
I haven't thought about the rebuilding.
Assignee | ||
Updated•19 years ago
|
Attachment #248037 -
Flags: approval-l10n?
Comment 40•19 years ago
|
||
mozilla/extensions/inspector/resources/Makefile.in 1.31
mozilla/extensions/inspector/resources/content/prefs/inspector.js 1.14
mozilla/extensions/inspector/resources/content/viewers/dom/commandOverlay.xul 1.9
mozilla/extensions/inspector/resources/content/viewers/dom/dom.js 1.46
mozilla/extensions/inspector/resources/content/viewers/dom/popupOverlay.xul 1.9
mozilla/extensions/inspector/resources/locale/en-US/viewers/dom.dtd 1.10
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Whiteboard: [checkin needed]
Updated•18 years ago
|
QA Contact: timeless → dom-inspector
You need to log in
before you can comment on or make changes to this bug.
Description
•