Bug 1079692 --  [Flame][Woodduck][Free Test][Video] Make video title tru...

...ncation process more efficient
nit: you don't need an if statement here. I think it is cleaner to just return the expression.

Non-nit: this is a huge implicit assumption here that each new line of text will add baseHeight pixels tot he container. That presumably only works if there are no margins in the container. Maybe it is affected by the line-height as well?

As the code stands, I think it would be possible to break this truncation algorithm with changes to the video.css file. That's bad.

I'm not sure what the right way to fix this is. Ideally, you would do this measurement with a private off-screen element that is completely controlled by this function. And instead of passing the real thumbnail details node in you'd pass in the pixel width. That way you could ensure that changes to the thumbnail layout did not affect the success of the line breaking.

Failing that, maybe you could use getComputedStyle() to get the line height of the node so that you can use baseHeight-lineHeight to compute the size of the padding. Then, for each new line, you'd expect the overall height to increase by lineHeight pixels.

Or, maybe you could add code so that when you set the node visibilty to hidden you also set its paddingTop and paddingBottom to 0 (and the borderTop and borderBottom, too?)

Or, if I'm completely off base and this code works just fine as it is, then please add a comment explaining why it works independently of padding and borders.