I am going to attach a patch including test cases.
Created attachment 7375 [details]
Comment on attachment 7375 [details]
Looks good to me, but also I think lots of layout code is crying out for use of overflowRect as opposed to the separate overflowLeft, Top, Width, Height functions.
Verified in r13675 nightly.