Bug 112770 - Autosize should use documentRect height instead of scrollHeight
Summary: Autosize should use documentRect height instead of scrollHeight
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Horton
URL:
Keywords: InRadar
Depends on: 113731
Blocks:
  Show dependency treegraph
 
Reported: 2013-03-19 19:04 PDT by Tim Horton
Modified: 2013-04-18 08:16 PDT (History)
4 users (show)

See Also:


Attachments
testcase (3.32 KB, text/html)
2013-03-19 19:04 PDT, Tim Horton
no flags Details
patch (1.84 KB, patch)
2013-03-19 19:17 PDT, Tim Horton
levin: review+
Details | Formatted Diff | Diff
better patch! (2.20 KB, patch)
2013-04-01 17:19 PDT, Tim Horton
levin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Horton 2013-03-19 19:04:37 PDT
Created attachment 193966 [details]
testcase

We've found a few cases where autosizing will get the wrong size with overflow. I'll attach one of them here. The solution *seems* to be to use RenderView::documentRect's height, which gets the right height, instead of scrollHeight, which gets the wrong (very short) clipped height.

<rdar://problem/13202277>
Comment 1 Tim Horton 2013-03-19 19:17:05 PDT
Created attachment 193967 [details]
patch
Comment 2 Tim Horton 2013-03-19 19:18:42 PDT
Autosizing on Mac doesn't actually resize the view, it waits for the view to be laid-out by autolayout, and this only works for WebKit2 anyway. Making this testable on Mac would be a good chunk of work.

I might consider adding a test that works on other platforms but is skipped on Mac, just so others don't regress this.
Comment 3 David Levin 2013-03-19 19:39:22 PDT
You could consider adding drt support like what was done in http://trac.webkit.org/changeset/104398

I only did it for chromium but it was the only port using the feature at the time.
Comment 4 David Levin 2013-03-20 01:39:39 PDT
I was trying to remember why I used that (and I finally tracked it back to the chromium code that had inspired it:
https://code.google.com/p/chromium/codesearch#chromium/src/content/renderer/render_view_impl.cc&q=scrollHeight%20file:%5C.cc&sq=package:chromium&type=cs&l=3961), so I'll admit to not having a large bias for scrollHeight over documentRect.



In fact after some more code investigation, it looks like the content size is set based on documentRect (https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/WebCore/page/FrameView.cpp&sq=package:chromium&type=cs&rcl=1363736896&l=593) and that is how scrollbars are determined so this seems very consistent with what this function is trying to do.

Thanks!


You may want to consider adding some simple drt support (like what I mentioned below), but I don't think that should block your fix. (Just to help you sleep better at night knowing that folks are much less likely to break you at random, you may want to consider it in the future.)
Comment 5 Tim Horton 2013-03-20 11:37:58 PDT
(In reply to comment #4)
> I was trying to remember why I used that (and I finally tracked it back to the chromium code that had inspired it:
> https://code.google.com/p/chromium/codesearch#chromium/src/content/renderer/render_view_impl.cc&q=scrollHeight%20file:%5C.cc&sq=package:chromium&type=cs&l=3961), so I'll admit to not having a large bias for scrollHeight over documentRect.
> 
> 
> 
> In fact after some more code investigation, it looks like the content size is set based on documentRect 

^^ this is exactly what made me pretty sure that we want this change. Our use of autosizing involves the WKView being sized to the FrameView contentsSize, and that was getting the right number, but we'd only paint a few pixels right at the top :)

(https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/WebCore/page/FrameView.cpp&sq=package:chromium&type=cs&rcl=1363736896&l=593) and that is how scrollbars are determined so this seems very consistent with what this function is trying to do.
> 
> Thanks!
> 
> 
> You may want to consider adding some simple drt support (like what I mentioned below), but I don't think that should block your fix. (Just to help you sleep better at night knowing that folks are much less likely to break you at random, you may want to consider it in the future.)

Agreed, I definitely want to work out how to make testing go.

Thanks for the review!
Comment 6 Tim Horton 2013-03-20 11:59:51 PDT
http://trac.webkit.org/changeset/146373
Comment 7 Tim Horton 2013-04-01 16:27:17 PDT
This broke autosizing entirely, it will now never shrink to be smaller than it was before. David, do you know if it's unreasonable to remove the condition from this call?

    // If this is the first time we run autosize, start from small height and
    // allow it to grow.
    if (!m_didRunAutosize)
         resize(frameRect().width(), m_minAutoSize.height());

If we shrink the FrameView each time, the documentRect is right. If we don't, the documentRect never gets smaller than it has previously been.
Comment 8 Tim Horton 2013-04-01 16:28:57 PDT
(In reply to comment #7)
> This broke autosizing entirely, it will now never shrink to be smaller than it was before. David, do you know if it's unreasonable to remove the condition from this call?
> 
>     // If this is the first time we run autosize, start from small height and
>     // allow it to grow.
>     if (!m_didRunAutosize)
>          resize(frameRect().width(), m_minAutoSize.height());
> 
> If we shrink the FrameView each time, the documentRect is right. If we don't, the documentRect never gets smaller than it has previously been.

But there are presumably performance implications.
Comment 9 Tim Horton 2013-04-01 17:19:26 PDT
Created attachment 196045 [details]
better patch!
Comment 10 Tim Horton 2013-04-01 17:24:57 PDT
http://trac.webkit.org/changeset/147373
Comment 11 Michael Thiessen 2013-04-18 08:16:39 PDT
FYI, this has been reverted in Blink for triggering ASSERTs

(https://codereview.chromium.org/14139021/)