18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright 2007, The Android Open Source Project
38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Redistribution and use in source and binary forms, with or without
58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modification, are permitted provided that the following conditions
68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * are met:
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *  * Redistributions of source code must retain the above copyright
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *  * Redistributions in binary form must reproduce the above copyright
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    notice, this list of conditions and the following disclaimer in the
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    documentation and/or other materials provided with the distribution.
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#define LOG_TAG "WebCore"
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "config.h"
288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "ScrollView.h"
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "FloatRect.h"
318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "FrameView.h"
328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "IntRect.h"
33163705a9d305337a58133a58c0d0e9686b4af589Leon Scroggins III#include "PlatformBridge.h"
34025ac4e283bb4b48f580d48541224e3996dc6f84Cary Clark#include "SkRegion.h"
3554b541647c8a934868c6c0f00665611569c9e4b8Leon Scroggins#include "WebCoreFrameBridge.h"
368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "WebCoreViewBridge.h"
378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "WebViewCore.h"
388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    This class implementation does NOT actually emulate the Qt ScrollView.
418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    It does provide an implementation that khtml will use to interact with
428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    WebKit's WebFrameView documentView and our NSScrollView subclass.
438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    ScrollView's view is a NSScrollView (or subclass of NSScrollView)
458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    in most cases. That scrollview is a subview of an
468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    WebCoreFrameView. The WebCoreFrameView's documentView will also be
478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    the scroll view's documentView.
488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    The WebCoreFrameView's size is the frame size.  The WebCoreFrameView's documentView
508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    corresponds to the frame content size.  The scrollview itself is autosized to the
518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    WebCoreFrameView's size (see Widget::resize).
528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project*/
538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectIntRect ScrollView::platformVisibleContentRect(bool includeScrollbars) const
578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
58899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba    // iframe's visible content rect is relative to its parent, not the viewport.
59899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba    // As we auto expand the iframe, the frame rect is the content rect.
60899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba    if (parent())
61899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba        return IntRect(0, 0, width(), height());
62899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba    else
63899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba        return platformWidget()->getVisibleBounds();
648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectIntSize ScrollView::platformContentsSize() const
678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    return m_contentsSize;
698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
71541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiwareint ScrollView::platformActualWidth() const
72541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware{
73541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware    if (parent())
74541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware        return width();
75541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware    return platformWidget()->visibleWidth();
76541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware}
77541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware
78541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiwareint ScrollView::platformActualHeight() const
79541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware{
80541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware    if (parent())
81541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware        return height();
82541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware    return platformWidget()->visibleHeight();
83541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware}
84541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware
85541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiwareint ScrollView::platformActualScrollX() const
86541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware{
87541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware    if (parent())
88541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware        return scrollX();
89541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware    return platformWidget()->visibleX();
90541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware}
91541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware
92541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiwareint ScrollView::platformActualScrollY() const
93541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware{
94541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware    if (parent())
95541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware        return scrollY();
96541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware    return platformWidget()->visibleY();
97541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware}
98541af8dff4d592277d0f835deafaf728dad8bc57Mangesh Ghiware
998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformSetScrollPosition(const WebCore::IntPoint& pt)
1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
10144bed85f240ccdf65de028e6fe2832b390676d47George Mount    PlatformBridge::setScrollPosition(this, m_scrollOrigin.x() + pt.x(),
10244bed85f240ccdf65de028e6fe2832b390676d47George Mount            m_scrollOrigin.y() + pt.y());
1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
10522804c073ffc06fd1fc520d1afbad71e353e488dGrace Klobavoid ScrollView::platformSetScrollbarModes()
10622804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba{
10722804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba    if (parent()) // no scrollbar for the subframes
10822804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba        return;
10922804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba    android::WebViewCore::getWebViewCore(this)->setScrollbarModes(m_horizontalScrollbarMode, m_verticalScrollbarMode);
11022804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba}
11122804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba
1128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) const
1138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
11422804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba    // m_horizontalScrollbarMode and m_verticalScrollbarMode are set in ScrollView::setScrollbarModes()
11522804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba    h = m_horizontalScrollbarMode;
11622804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba    v = m_verticalScrollbarMode;
1178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now)
1208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
12144bed85f240ccdf65de028e6fe2832b390676d47George Mount    IntRect offsetRect = rect;
12244bed85f240ccdf65de028e6fe2832b390676d47George Mount    offsetRect.move(m_scrollOrigin.x(), m_scrollOrigin.y());
12344bed85f240ccdf65de028e6fe2832b390676d47George Mount    android::WebViewCore::getWebViewCore(this)->contentInvalidate(offsetRect);
1248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS
1274465d348a977f9f062b28957709a77613311647aAndrei Popescu//  Compute the offscreen parts of the drawn rectangle by subtracting
1284465d348a977f9f062b28957709a77613311647aAndrei Popescu//  vis from rect. This can compute up to four rectangular slices.
1294465d348a977f9f062b28957709a77613311647aAndrei Popescuvoid ScrollView::platformOffscreenContentRectangle(const IntRect& vis, const IntRect& rect)
1308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{
131330e608aa0a04d09cbb92a754420c115fb16d993Cary Clark    android::WebViewCore* core = android::WebViewCore::getWebViewCore(this);
132330e608aa0a04d09cbb92a754420c115fb16d993Cary Clark    if (!core) // SVG does not instantiate webviewcore
133330e608aa0a04d09cbb92a754420c115fb16d993Cary Clark        return; // and doesn't need to record drawing offscreen
134e859a34171f2a36877d95197d118d962078f8aa0John Reck    core->offInvalidate(rect);
1358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}
1368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
1378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
138016ea440f1b61a966483fc809a078dd28b784e46Cary Clarkbool ScrollView::platformIsOffscreen() const
139016ea440f1b61a966483fc809a078dd28b784e46Cary Clark{
140016ea440f1b61a966483fc809a078dd28b784e46Cary Clark    /* other platforms override platformIsOffscreen when the browser
141016ea440f1b61a966483fc809a078dd28b784e46Cary Clark       window is no longer on screen. We override it to prevent gif
142016ea440f1b61a966483fc809a078dd28b784e46Cary Clark       animations from queuing up subsequent frames during dragging. */
143016ea440f1b61a966483fc809a078dd28b784e46Cary Clark    return android::WebViewCore::getWebViewCore(this)->drawIsPaused();
144016ea440f1b61a966483fc809a078dd28b784e46Cary Clark}
145016ea440f1b61a966483fc809a078dd28b784e46Cary Clark
1460bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch} // namespace WebCore
147