Bug 21413

Summary: DOMWindow.cpp DOMWindow::moveTo offsets moves by 22 (menu bar height)
Product: WebKit Reporter: Eric Simenel <esimenel>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: UNCONFIRMED ---    
Severity: Normal CC: esimenel, marcus, yevseytsev
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Macintosh   
OS: OS X 10.5   

Description Eric Simenel 2008-10-06 15:09:08 PDT
Easy to reproduce:
Using the following HTML code:
<html>
<script>
    function M(dx, dy) {

        window.moveTo(window.screenX+dx, window.screenY+dy);
    }
    
</script>
<body>
<input type="button" value="move me" onclick="M(0, -50)">
</body>
</html>

Safari/Webkit windows move up 28 pixels, Firefox windows move up 50 pixels.

Tentative fix:

Instead of:
    FloatRect fr = page->chrome()->windowRect();
    FloatRect sr = screenAvailableRect(page->mainFrame()->view());
    fr.setLocation(sr.location());
    FloatRect update = fr;
    update.move(x, y);     

We should have:
    FloatRect fr = page->chrome()->windowRect();
    FloatRect sr = screenAvailableRect(page->mainFrame()->view());
    x -= fr.x();
    y -= fr.y();
    FloatRect update = fr;
    update.move(x, y);     

That change seems to fix the problem.
Comment 1 yevseytsev 2019-02-15 11:24:53 PST
Tried to reproduce a bug in Safari and Firefox using the code provided, but windows are not moving at all. As well Firefox is no longer uses WebKit, so I am not sure it is a bug nowadays.
Comment 2 yevseytsev 2019-02-15 13:40:23 PST
 Please ignore the second part of my previous comment, Firefox uses WebKit only on iOS
Comment 3 yevseytsev 2019-02-22 10:48:24 PST
in webkit/Source/WebCore/page/DOMWindow.cpp file there is a code that prevents window geometry to be changed

void DOMWindow::moveTo(float x, float y) const
{
    if (!allowedToChangeWindowGeometry())
        return;


    Page* page = m_frame->page();
    FloatRect fr = page->chrome().windowRect();
    FloatRect sr = screenAvailableRect(page->mainFrame().view());
    fr.setLocation(sr.location());
    FloatRect update = fr;
    update.move(x, y);
    page->chrome().setWindowRect(adjustWindowRect(*page, update));
}