Port bug 1519948: Replace use of boxObject
Categories
(Thunderbird :: General, task)
Tracking
(Not tracked)
People
(Reporter: jorgk-bmo, Assigned: mkmelin)
References
Details
Attachments
(4 files, 6 obsolete files)
91.67 KB,
patch
|
darktrojan
:
review-
darktrojan
:
feedback+
|
Details | Diff | Splinter Review |
27.03 KB,
patch
|
jorgk-bmo
:
review+
|
Details | Diff | Splinter Review |
2.03 KB,
patch
|
alta88
:
review+
jorgk-bmo
:
approval-comm-beta+
|
Details | Diff | Splinter Review |
3.02 KB,
patch
|
pmorris
:
review+
|
Details | Diff | Splinter Review |
As per bug 1519948 comment #5:
element.boxObject.x/y/width/height can mostly be replaced with getBoundingClientRect(). It is almost identicial, although its behaviour in scrolling areas is different. If performing computations with the values, current code might add on scroll offsets and the like, which probably won't be needed with getBoundingClientRect.
element.boxObject.screenX/screenY can be replaced with element.screenX/screenY.
The property related functions would probably work with just properties on the element. I checked at one point and Thunderbird doesn't use them as far as I can tell anyway.
The element relation properties (at the end of BoxObject.webidl), have no exact equivalent but again I'm not sure if Thunderbird needs them. If so, I can suggest alternatives.
Reporter | ||
Comment 1•6 years ago
|
||
Reporter | ||
Comment 2•6 years ago
|
||
OK, here's the straight forward replacement of .x, .y, .width, .height, .screenX, .screenY.
I'll have to check what's left after that.
Reporter | ||
Comment 3•6 years ago
|
||
Comment 4•6 years ago
|
||
I notice there are some copies of some bindings in that link above (comment 1). Note a couple of special cases.
For richlistbox.xml see the changes in bug 1519967. It needs a different fix to fix scroll offsets. I didn't look at the Thunderbird code to see if this is relevant but thought I'd point them out. You may need similar changes in other cases, if the boxobject properties are being used in conjuction with scrollable areas.
For textbox.xml, see https://hg.mozilla.org/mozilla-central/rev/63908a1890a0
Reporter | ||
Comment 5•6 years ago
|
||
OK, this covers all the easy stuff, including richlistbox.xml. textbox.xml was moved to suite/ (SemMonkey), so we don't worry about it.
This is left:
mail:
.\base\content\folderDisplay.js: get parentBox() { return this.domNode.boxObject.parentBox; },
.\base\content\folderDisplay.js: get firstChild() { return this.domNode.boxObject.firstChild; },
.\base\content\folderDisplay.js: get lastChild() { return this.domNode.boxObject.lastChild; },
.\base\content\folderDisplay.js: get nextSibling() { return this.domNode.boxObject.nextSibling; },
.\base\content\folderDisplay.js: get previousSibling() { return this.domNode.boxObject.previousSibling; },
.\base\content\folderDisplay.js: return this.domNode.boxObject.getPropertyAsSupports(propertyName);
.\base\content\folderDisplay.js: this.domNode.boxObject.setPropertyAsSupports(propertyName, value);
.\base\content\folderDisplay.js: return this.domNode.boxObject.getProperty(propertyName);
.\base\content\folderDisplay.js: return this.domNode.boxObject.setProperty(propertyName, value);
.\base\content\folderDisplay.js: return this.domNode.boxObject.removeProperty(propertyName);
.\base\content\msgHdrView.js: let name = attachmentitem.boxObject.firstChild
.\base\content\msgHdrView.js: let label = item.boxObject.firstChild.nextSibling;
calendar:
.\base\content\calendar-multiday-view.xml: let sbo = scrollbox.boxObject;
.\base\content\calendar-multiday-view.xml: let propertyValue = scrollbox.boxObject.firstChild.boxObject[propertyName];
So in mail we have stuff with first/lastChild, nextSibling, etc.
In calendar we have those scroll stuff:
https://searchfox.org/comm-central/rev/b2c998eb41d696d31a87384487514e9b386f201c/calendar/base/content/calendar-multiday-view.xml#1373
So those are the non-trivial things that are left.
Should this patch work now? Then I can start a try.
Reporter | ||
Comment 6•6 years ago
|
||
Comment 7•6 years ago
|
||
.\base\content\folderDisplay.js: get parentBox() { return this.domNode.boxObject.parentBox; },
.\base\content\folderDisplay.js: get firstChild() { return this.domNode.boxObject.firstChild; },
.\base\content\folderDisplay.js: get lastChild() { return this.domNode.boxObject.lastChild; },
.\base\content\folderDisplay.js: get nextSibling() { return this.domNode.boxObject.nextSibling; },
.\base\content\folderDisplay.js: get previousSibling() { return this.domNode.boxObject.previousSibling; },
.\base\content\folderDisplay.js: return this.domNode.boxObject.getPropertyAsSupports(propertyName);
.\base\content\folderDisplay.js: this.domNode.boxObject.setPropertyAsSupports(propertyName, value);
.\base\content\folderDisplay.js: return this.domNode.boxObject.getProperty(propertyName);
.\base\content\folderDisplay.js: return this.domNode.boxObject.setProperty(propertyName, value);
.\base\content\folderDisplay.js: return this.domNode.boxObject.removeProperty(propertyName);
It looks like this is used to implement some fake BoxObject, but I bet it has no callers so they could just be removed.
.\base\content\msgHdrView.js: let name = attachmentitem.boxObject.firstChild
.\base\content\msgHdrView.js: let label = item.boxObject.firstChild.nextSibling;
This seems to have been added by a very recent patch (bug 1345167), so it is probably easier to determine why this was added. I suspect it is only used to get XBL anonymous children, so it should be using getAnonymousXXX type functions instead.
Reporter | ||
Comment 8•6 years ago
•
|
||
I was just about to say that the lot in folderDisplay.js is for the fake box object.
Magnus and Alta88, can you suggest a replacement for:
https://hg.mozilla.org/comm-central/rev/d167921e42eb#l6.720
https://hg.mozilla.org/comm-central/rev/d167921e42eb#l6.923
So that leaves the Calendar stuff
calendar:
.\base\content\calendar-multiday-view.xml: let sbo = scrollbox.boxObject;
.\base\content\calendar-multiday-view.xml: let propertyValue = scrollbox.boxObject.firstChild.boxObject[propertyName];
https://searchfox.org/comm-central/rev/b2c998eb41d696d31a87384487514e9b386f201c/calendar/base/content/calendar-multiday-view.xml#1373
https://searchfox.org/comm-central/rev/b2c998eb41d696d31a87384487514e9b386f201c/calendar/base/content/calendar-multiday-view.xml#3687
For the first call site, we replace let sbo = scrollbox.boxObject; ... ; sbo.scrollBy( ... );
with scrollbox.scrollBy( ... );
?
I'm happy for someone else to provide those tweaks after I've done the mass replacement.
EDIT:
BTW, https://treeherder.mozilla.org/#/jobs?repo=try-comm-central&revision=0fca98077f6a18a6489c25e1a32bd8b29a99debb is green, so the mass replacement was successful as far as we can tell.
Reporter | ||
Updated•6 years ago
|
Reporter | ||
Comment 9•6 years ago
|
||
Rebased. With every de-XBL patch that lands, this will need to be rebased :-(
Reporter | ||
Comment 10•6 years ago
|
||
Reporter | ||
Comment 11•6 years ago
|
||
Another rebase :-(
Reporter | ||
Updated•6 years ago
|
Comment 12•6 years ago
|
||
Comment 13•6 years ago
|
||
Comment 14•6 years ago
|
||
getBoundingClientRect
uses floating-point numbers, which will probably cause a few problems like the test I just fixed. I don't know if clientWidth
and clientHeight
are also for the chop, but it'll do for now.
Comment 15•6 years ago
|
||
Reporter | ||
Comment 16•6 years ago
|
||
(In reply to Geoff Lankow (:darktrojan) from comment #14)
getBoundingClientRect
uses floating-point numbers, which will probably cause a few problems like the test I just fixed.
Thanks, I should have checked my try better :-( - screenY = aDispatcher.ScreenY;
is a good one, but sed didn't notice. I'll go over it and replace the double calls, unless we want to switch to clientLeft/Top/Width/Height
.
To avoid further passes through this code, maybe we can answer these questions first:
- Neil, what about using
clientLeft/Top/Width/Height
, see comment #14 and comment #15. - Neil and Geoff, any suggestion for the calendar stuff in comment #8.
- Alta88 and Magnus, any suggestion for the stuff in msgHdrView.js, see comment #8.
Comment 17•6 years ago
|
||
.\base\content\calendar-multiday-view.xml: let sbo = scrollbox.boxObject;
scrollBy
is also method on sbo.
.\base\content\calendar-multiday-view.xml: let propertyValue = scrollbox.boxObject.firstChild.boxObject[propertyName];
The best I've come up with to get the size of the scrollbar (unless we can get a handle for that scrollbar) is to calculate the size of the scrollbox minus the size of its contents. That seems a bit wrong.
Comment 18•6 years ago
|
||
(In reply to Jorg K (GMT+2) from comment #16)
To avoid further passes through this code, maybe we can answer these questions first:
- Neil, what about using
clientLeft/Top/Width/Height
, see comment #14 and comment #15.
clientWidth/clientHeight return the padding box, whereas boxObject and getBoundingClientRect return the border box. You can use them, but you'll need to adjust any calculations to account for the border.
- Neil and Geoff, any suggestion for the calendar stuff in comment #8.
You should be able to use scrollbox.scrollBy instead.
Reporter | ||
Comment 19•6 years ago
|
||
OK, removed multiple retrievals of bounding rect on same object. Also fixed ScreenX
and the scrollBy
call site. I didn't fix notificationbox.xml to avoid more rebasing in bug 1536935 where that will be removed.
Still left:
https://hg.mozilla.org/comm-central/rev/d167921e42eb#l6.720
https://hg.mozilla.org/comm-central/rev/d167921e42eb#l6.923
.\base\content\calendar-multiday-view.xml: let propertyValue = scrollbox.boxObject.firstChild.boxObject[propertyName];
Comment 20•6 years ago
|
||
(In reply to Jorg K (GMT+2) from comment #8)
I was just about to say that the lot in folderDisplay.js is for the fake box object.
Magnus and Alta88, can you suggest a replacement for:
https://hg.mozilla.org/comm-central/rev/d167921e42eb#l6.720
https://hg.mozilla.org/comm-central/rev/d167921e42eb#l6.923
you can't programmatically access a node created in a binding without boxObject. querySelectorAll doesn't work nor are child nodes exposed (anymore). your options are:
- set an attribute like |externalattachment| on the <richlistitem> and have a custom css selector for the node wanting .text-link styling (also with hover).
- wait for de-xbl of attachment widgets. maybe even future proof it and use html.
- looks like menuitem will continue haunting; as the note says the method in #1 above didn't work well. perhaps something similar can be tried again, otherwise you can remove setting |text-link| and the extra styling there. it was a nice visual bit indicating those menuitems were external links.
Comment 21•6 years ago
|
||
(In reply to alta88 from comment #20)
you can't programmatically access a node created in a binding without boxObject.
That's not correct. You can use document.getAnonymousNodes or document.getAnonymousElementByAttribute
A better way though is to add a method or property to the binding that does what you need it to do, rather than having code external to the binding accessing its internals.
Comment 22•6 years ago
|
||
(In reply to Neil Deakin from comment #21)
(In reply to alta88 from comment #20)
you can't programmatically access a node created in a binding without boxObject.
That's not correct. You can use document.getAnonymousNodes or document.getAnonymousElementByAttribute
how 'forever' are those methods going to be? are they in a spec?
A better way though is to add a method or property to the binding that does what you need it to do, rather than having code external to the binding accessing its internals.
i assume you mean custom element class, and not actually old deprecating 'binding'.
Assignee | ||
Comment 23•6 years ago
|
||
The attachment list is being de-xbl'd and is almost ready (pending a focus/select problem) - bug 1523607
Reporter | ||
Comment 24•6 years ago
•
|
||
I did what I could here, so can someone please take over for the last two remaining bits (see comment #19).
Reporter | ||
Comment 25•6 years ago
|
||
Found some more:
https://searchfox.org/comm-central/search?q=.boxObject&case=false®exp=false&path=
Remaining ones in
calendar/base/content/calendar-multiday-view.xml
mail/base/content/folderDisplay.js (fake stuff)
mail/base/content/msgHdrView.js
Reporter | ||
Comment 26•6 years ago
|
||
Reporter | ||
Comment 27•6 years ago
•
|
||
Reporter | ||
Comment 28•6 years ago
|
||
I hope this is it. Note the bug here:
- { screenX : aDropObject.screenX +
- (aDropObject.getBoundingClientRect().width * aRelDropX),
- screenY : aDropObject.screenY +
- (aDropObject.getBoundingClientRect().width * aRelDropY)
^^^^^
As you saw, I edited the previous comment to note the cases where no saving would occur.
Reporter | ||
Updated•6 years ago
|
Comment 29•6 years ago
|
||
Reporter | ||
Comment 30•6 years ago
|
||
Thanks, I checked linting on try.
Comment 31•6 years ago
|
||
Comment 32•6 years ago
|
||
Comment 33•6 years ago
|
||
Linting doesn't help when the mistake is in an unlinted file and the reviewer is blind.
Reporter | ||
Comment 34•6 years ago
|
||
Thanks for fixing that. Copy/paste error from here: https://hg.mozilla.org/comm-central/rev/a7efaecb39cc#l13.12.
I actually had a green try before those last changes.
Anyway, what's the way forward with the two remaining call sites, not counting the fake stuff?
Still left:
https://hg.mozilla.org/comm-central/rev/d167921e42eb#l6.720
https://hg.mozilla.org/comm-central/rev/d167921e42eb#l6.923
.\base\content\calendar-multiday-view.xml: let propertyValue = scrollbox.boxObject.firstChild.boxObject[propertyName];
Assignee | ||
Comment 35•6 years ago
|
||
The ones still left should be pretty easy to convert at least once bug 1523607 lands (I hear it's figured out and should be finished soon). When it's not anonymous content you can just querySelector the child object you need.
Updated•6 years ago
|
Reporter | ||
Updated•6 years ago
|
Reporter | ||
Comment 36•6 years ago
|
||
Magnus, bug 1523607 didn't fix anything as far as I can see, somehow the count even increased, I guess the ones in calendar-event-dialog-attendees-custom-elements.js were hiding in some pending patches and snuck back in :-(
https://searchfox.org/comm-central/search?q=.boxObject&case=false®exp=false&path=
calendar/base/content/calendar-multiday-base-view.js
1549 const propertyValue = this.scrollbox.boxObject.firstChild.boxObject[widthOrHeight];
calendar/base/content/dialogs/calendar-event-dialog-attendees-custom-elements.js
3158 this.mRowHeight = items[i].boxObject.height;
3169 let listboxHeight = this.boxObject.height;
mail/base/content/folderDisplay.js - some fake tree junk that could just be removed.
2636 get parentBox() { return this.domNode.boxObject.parentBox; },
2637 get firstChild() { return this.domNode.boxObject.firstChild; },
2638 get lastChild() { return this.domNode.boxObject.lastChild; },
2639 get nextSibling() { return this.domNode.boxObject.nextSibling; },
2640 get previousSibling() { return this.domNode.boxObject.previousSibling; },
2642 return this.domNode.boxObject.getPropertyAsSupports(propertyName);
2645 this.domNode.boxObject.setPropertyAsSupports(propertyName, value);
2648 return this.domNode.boxObject.getProperty(propertyName);
2651 return this.domNode.boxObject.setProperty(propertyName, value);
2654 return this.domNode.boxObject.removeProperty(propertyName);
mail/base/content/msgHdrView.js
2352 let name = attachmentitem.boxObject.firstChild
2670 let label = item.boxObject.firstChild.nextSibling;
Assignee | ||
Comment 37•6 years ago
|
||
Assignee | ||
Comment 38•6 years ago
|
||
Comment 39•6 years ago
|
||
Reporter | ||
Comment 40•6 years ago
|
||
Great. Note that the "fake stuff" will go in bug 1518823, see:
https://treeherder.mozilla.org/#/jobs?repo=try-comm-central&revision=e24022251ffeae43ec05cc6a774693e396f0b5f2
Reporter | ||
Comment 41•6 years ago
|
||
Assignee | ||
Comment 42•6 years ago
|
||
I can't imagine there would be any efficiency difference, it's a reference to the same thing. Just more readable.
(Well, children avoids any possible whitespace node problems in the future.)
Reporter | ||
Comment 43•6 years ago
|
||
In general, .children[1] has a complexity of O(N) where N is the number of siblings, .firstChild.nextSibling has a complexity of O(1). That's because DOM nodes don't hold a child array any more, see bug 651120. So the all the children need to be traversed to fill an array which is later discarded :-( - Therefore direct access the first and second child in generally much faster.
How many children are you expecting? BTW, what's a "white-space node problem"?
Comment 44•6 years ago
|
||
To bypass possible text/comment nodes, .firstElementChild and .nextElementSibling could be used. I guess given that bug, these are infinitesimally slightly better ;) if you know for sure the .children array is only constructed lazily.
Assignee | ||
Comment 45•6 years ago
|
||
There's apparently 6 children in this case. firstChild could also include whitespace text nodes (depending on the document type).
I'd still go for readability over micro-optimization here.
Reporter | ||
Comment 46•6 years ago
|
||
Well, for 6 children that we don't need, I'd most certainly go for the "proper" way that M-C promotes of not retrieving all children, also for the simple reason of not establishing a bad pattern that others could copy even if they are 60 children. So can we please revert this unnecessary change or do you insist?
Reporter | ||
Comment 47•6 years ago
•
|
||
https://searchfox.org/comm-central/search?q=.firstChild.nextSibling&case=false®exp=false&path=
584 hits, so you can't really say that it's badly readable.
https://searchfox.org/comm-central/search?q=.children%5B1%5D&case=false®exp=false&path=
130 hits, mostly in 3rd party code, tests and devtools. Also, I have the impression that children
is also used for style retrievals.
https://searchfox.org/comm-central/search?q=.childNodes%5B1%5D&case=false®exp=false&path=
195 hits, mostly in 3rd party code, tests and devtools.
.children and .childNodes are different, the former doesn't return text or comment nodes. Is that desired?
Assignee | ||
Comment 48•6 years ago
|
||
.children is a standard API, and i don't see any de-promotion about it anywhere. (Yes, we want children, not childNodes).
I did a quick check on what kind of numbers we're looking at. Not very conclusive, but what we can say it there is no real difference. The numbers are so tiny any and all changes you make to code could result in such differences. In my test children[1] "won" 3/5 times actually.
children[1]:
0.006427000000257976 ms
0.006904000001668464 ms
0.009058999999979278 ms
0.022188000000824104 ms
0.023704999997789855 ms
firstElementChild.nextElementSibling:
0.004087999999683234 ms
0.0179069999994681 ms
0.010258999998768559 ms
0.01703700000052777 ms
0.00450500000079046 ms
Reporter | ||
Comment 49•6 years ago
•
|
||
No one said that .children is being "de-promoted". All I said is that there is no child node array any more, so retrieving a child is potentially O(N). Surely for small N, you won't see a difference.
If you want to contribute some real insight here, please try with 600 or 6000 children (or post the test for others to try), doing timing on 6 children proves nothing. If for 6000 children .children[1] is still as fast as getting the next sibling, then you won indeed. While you're there, compare getting the 1st and the 6000th child, and also the 5950th, maybe there is optimisation to get the last one. Maybe retrieval is really smart and the linked list of children is only walked to the number you require.
Assignee | ||
Comment 50•6 years ago
|
||
But we only have 6 children, so what's the point? Unless it's very very top level, you won't find that many children.
Comment 51•6 years ago
|
||
Reporter | ||
Updated•6 years ago
|
Reporter | ||
Comment 52•6 years ago
|
||
Comment 53•6 years ago
|
||
Pushed by mozilla@jorgk.com:
https://hg.mozilla.org/comm-central/rev/bb64c0fb051b
Replace use of boxObject in msgHdrView.js. r=alta88
https://hg.mozilla.org/comm-central/rev/12e96412b2c8
Replace remaining use of boxObject in calendar. r=pmorris
Reporter | ||
Comment 54•6 years ago
|
||
We started this in the 68 cycle.
Reporter | ||
Comment 55•6 years ago
|
||
Description
•