Bug 103428

Summary: [WK2] TiledBackingStore: Frame view re-layouts with wrong Fixed Visible Content Rect.
Product: WebKit Reporter: Mikhail Pozdnyakov <mikhail.pozdnyakov>
Component: WebKit2Assignee: Mikhail Pozdnyakov <mikhail.pozdnyakov>
Status: RESOLVED FIXED    
Severity: Normal CC: hugo.lima, jesus, jussi.kukkonen, kenneth, noam, rafael.lobo, tmpsantos, webkit.review.bot, zeno
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 95959, 103105    
Attachments:
Description Flags
patch
kenneth: review-, kenneth: commit-queue-
patch v2
kenneth: review+
patch v3 none

Description Mikhail Pozdnyakov 2012-11-27 09:24:52 PST
WebPage re-layouts its view with wrong Fixed Visible Content Rect. This happens because Fixed Visible Content Rect is set with a delay by LayerTreeCoordinator when layout is already done. As a result have failing css3/device-adapt/opera/constrain-006(7).xhtml tests and maybe others.
Comment 1 Thiago Marcos P. Santos 2012-11-27 09:50:54 PST
*** Bug 102922 has been marked as a duplicate of this bug. ***
Comment 2 Mikhail Pozdnyakov 2012-11-28 08:26:04 PST
Created attachment 176489 [details]
patch
Comment 3 Kenneth Rohde Christiansen 2012-11-28 08:44:20 PST
Comment on attachment 176489 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=176489&action=review

> Source/WebKit2/UIProcess/DrawingAreaProxy.h:91
> +    virtual void setFixedLayoutSize(const WebCore::IntSize& /*layoutSize*/, const WebCore::FloatRect& /*visibleContentsRect*/, float /*scale*/) { }

space after /* and before */

> Source/WebKit2/UIProcess/PageViewportController.cpp:223
> -    drawingArea->setVisibleContentsRect(visibleContentsRect, m_effectiveScale, trajectoryVector);
> +    if (trajectoryVector == FloatPoint::zero()) {
> +        IntSize fixedLayoutSize = IntSize(static_cast<int>(m_rawAttributes.layoutSize.width()), static_cast<int>(m_rawAttributes.layoutSize.height()));
> +        drawingArea->setFixedLayoutSize(fixedLayoutSize, visibleContentsRect, m_effectiveScale);
> +    } else
> +        drawingArea->setVisibleContentsRect(visibleContentsRect, m_effectiveScale, trajectoryVector);
>  

It is zero in other cases than when setting new fixed layout size. For instance when panning ends.

Why not replace syncVisibleContents() inside didChangeViewportAttributes instead?

IntSize fixedLayoutSize = IntSize(static_cast<int>(m_rawAttributes.layoutSize.width()), static_cast<int>(m_rawAttributes.layoutSize.height()));
drawingArea->setFixedLayoutSize(fixedLayoutSize, visibleContentsRect, m_effectiveScale);

Also why not

IntSize fixedLayoutSize = roundedIntRect(m_rawAttributes.layoutSize);

Or

drawingArea->setFixedLayoutSize(roundedIntRect(m_rawAttributes.layoutSize), visibleContentsRect, m_effectiveScale);


Notice that in the code above m_contentsSize cannot be trusted, it is from the old content (old layout sizes)

I guess you should use:

FloatRect visibleContentsRect(FloatPoint(), viewportSizeInContentsCoordinates());
drawingArea->setFixedLayoutSize(roundedIntRect(m_rawAttributes.layoutSize), visibleContentsRect, m_effectiveScale);
Comment 4 Noam Rosenthal 2012-11-28 08:47:07 PST
Comment on attachment 176489 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=176489&action=review

> Source/WebKit2/UIProcess/PageViewportController.cpp:218
> +    if (trajectoryVector == FloatPoint::zero()) {

Can you explain this in a comment?

> Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp:729
> +void LayerTreeCoordinator::setFixedLayoutSize(const IntSize& layoutSize, const IntRect& rect, float scale)
> +{
> +    setVisibleContentsRect(rect, scale, FloatPoint());
> +    m_webPage->setFixedLayoutSize(layoutSize);
> +}

This is a bit messy. Why not have this message in WebPage, and have WebPage call layerTreeCoordinator->setVisibleContentsRect?
I prefer it if LayerTreeCoordinator dealt with viewport/graphics only and not with layout magic.
Comment 5 Noam Rosenthal 2012-11-28 08:49:20 PST
(In reply to comment #4)
> (From update of attachment 176489 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=176489&action=review
> 
> > Source/WebKit2/UIProcess/PageViewportController.cpp:218
> > +    if (trajectoryVector == FloatPoint::zero()) {
> 
> Can you explain this in a comment?
> 
> > Source/WebKit2/WebProcess/WebPage/CoordinatedGraphics/LayerTreeCoordinator.cpp:729
> > +void LayerTreeCoordinator::setFixedLayoutSize(const IntSize& layoutSize, const IntRect& rect, float scale)
> > +{
> > +    setVisibleContentsRect(rect, scale, FloatPoint());
> > +    m_webPage->setFixedLayoutSize(layoutSize);
> > +}
> 
> This is a bit messy. Why not have this message in WebPage, and have WebPage call layerTreeCoordinator->setVisibleContentsRect?
> I prefer it if LayerTreeCoordinator dealt with viewport/graphics only and not with layout magic.

but seems like Kenneth's comments and mine might collide... his are better :)
Comment 6 Mikhail Pozdnyakov 2012-11-28 11:25:11 PST
(In reply to comment #3)
> (From update of attachment 176489 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=176489&action=review
> 
> Why not replace syncVisibleContents() inside didChangeViewportAttributes instead?
> 
Ah indeed! this is much much better, thanks!
Comment 7 Kenneth Rohde Christiansen 2012-11-29 02:20:14 PST
Comment on attachment 176489 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=176489&action=review

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:-1029
> -    // This also takes care of the relayout.
> -    setFixedLayoutSize(IntSize(static_cast<int>(attr.layoutSize.width()), static_cast<int>(attr.layoutSize.height())));

So this is wrong; we need to do the layout immediate when we get the viewport info, because otherwise it is going to layout using old info.

Say it parses the document and finds the viewport meta tag, then calls then and then continues to layout.

Instead we should make sure here that we update the visibleContentsRect as well.

You know the scale from the viewport info (will require a few changes) and you know the viewport size m_viewportSize. You also have the current position from the previous visibleContentsRect, but it should be set to (0, 0) if page->layoutMilestones() == 0; (no layout was done yet)
Comment 8 Mikhail Pozdnyakov 2012-11-30 03:37:59 PST
Created attachment 176936 [details]
patch v2

New approach is applied, set contents fixed rect before the layout and still layout immediately after viewport attrs are changed.
Comment 9 Kenneth Rohde Christiansen 2012-11-30 04:15:21 PST
Comment on attachment 176936 [details]
patch v2

View in context: https://bugs.webkit.org/attachment.cgi?id=176936&action=review

> Source/WebKit2/UIProcess/PageViewportController.cpp:237
>      if (updateMinimumScaleToFit(true))
>          m_client->didChangeViewportAttributes();
> -
> -    syncVisibleContents();
>  }

Maybe a comment here some how? that this is not needed

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:1032
> +    // Keep the current position, update size only.
> +    FrameView* view = m_page->mainFrame()->view();
> +    IntPoint contentFixedOrigin = view->fixedVisibleContentRect().location();

It should be mentioned here that this is indeed (0, 0) for new loads and not the position for the previous page

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:1041
> -    setFixedLayoutSize(IntSize(static_cast<int>(attr.layoutSize.width()), static_cast<int>(attr.layoutSize.height())));
> +    setFixedLayoutSize(roundedIntSize(attr.layoutSize));

much nicer
Comment 10 Kenneth Rohde Christiansen 2012-11-30 04:24:17 PST
Comment on attachment 176936 [details]
patch v2

View in context: https://bugs.webkit.org/attachment.cgi?id=176936&action=review

> Source/WebKit2/WebProcess/WebPage/WebPage.cpp:1036
> +    IntSize contentFixedSize = m_viewportSize;
> +    contentFixedSize.scale(1 / m_page->deviceScaleFactor());

This should further more be at the current scale!
1 / (deviceScaleFactor() * attr.initialScale)
Comment 11 Mikhail Pozdnyakov 2012-11-30 05:05:32 PST
Created attachment 176945 [details]
patch v3
Comment 12 WebKit Review Bot 2012-11-30 05:57:45 PST
Comment on attachment 176945 [details]
patch v3

Clearing flags on attachment: 176945

Committed r136231: <http://trac.webkit.org/changeset/136231>
Comment 13 WebKit Review Bot 2012-11-30 05:57:49 PST
All reviewed patches have been landed.  Closing bug.
Comment 14 Thiago Marcos P. Santos 2012-12-02 05:29:43 PST
This patch made css3/device-adapt/viewport-width-not-affecting-next-page.html flaky.