ScrollViewAndroid.cpp revision e859a34171f2a36877d95197d118d962078f8aa0
1/*
2 * Copyright 2007, The Android Open Source Project
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *  * Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 *  * Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#define LOG_TAG "WebCore"
26
27#include "config.h"
28#include "ScrollView.h"
29
30#include "FloatRect.h"
31#include "FrameView.h"
32#include "IntRect.h"
33#include "PlatformBridge.h"
34#include "SkRegion.h"
35#include "WebCoreFrameBridge.h"
36#include "WebCoreViewBridge.h"
37#include "WebViewCore.h"
38
39/*
40    This class implementation does NOT actually emulate the Qt ScrollView.
41    It does provide an implementation that khtml will use to interact with
42    WebKit's WebFrameView documentView and our NSScrollView subclass.
43
44    ScrollView's view is a NSScrollView (or subclass of NSScrollView)
45    in most cases. That scrollview is a subview of an
46    WebCoreFrameView. The WebCoreFrameView's documentView will also be
47    the scroll view's documentView.
48
49    The WebCoreFrameView's size is the frame size.  The WebCoreFrameView's documentView
50    corresponds to the frame content size.  The scrollview itself is autosized to the
51    WebCoreFrameView's size (see Widget::resize).
52*/
53
54namespace WebCore {
55
56IntRect ScrollView::platformVisibleContentRect(bool includeScrollbars) const
57{
58    // iframe's visible content rect is relative to its parent, not the viewport.
59    // As we auto expand the iframe, the frame rect is the content rect.
60    if (parent())
61        return IntRect(0, 0, width(), height());
62    else
63        return platformWidget()->getVisibleBounds();
64}
65
66IntSize ScrollView::platformContentsSize() const
67{
68    return m_contentsSize;
69}
70
71void ScrollView::platformSetScrollPosition(const WebCore::IntPoint& pt)
72{
73    PlatformBridge::setScrollPosition(this, m_scrollOrigin.x() + pt.x(),
74            m_scrollOrigin.y() + pt.y());
75}
76
77void ScrollView::platformSetScrollbarModes()
78{
79    if (parent()) // no scrollbar for the subframes
80        return;
81    android::WebViewCore::getWebViewCore(this)->setScrollbarModes(m_horizontalScrollbarMode, m_verticalScrollbarMode);
82}
83
84void ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) const
85{
86    // m_horizontalScrollbarMode and m_verticalScrollbarMode are set in ScrollView::setScrollbarModes()
87    h = m_horizontalScrollbarMode;
88    v = m_verticalScrollbarMode;
89}
90
91void ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now)
92{
93    IntRect offsetRect = rect;
94    offsetRect.move(m_scrollOrigin.x(), m_scrollOrigin.y());
95    android::WebViewCore::getWebViewCore(this)->contentInvalidate(offsetRect);
96}
97
98#ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS
99//  Compute the offscreen parts of the drawn rectangle by subtracting
100//  vis from rect. This can compute up to four rectangular slices.
101void ScrollView::platformOffscreenContentRectangle(const IntRect& vis, const IntRect& rect)
102{
103    android::WebViewCore* core = android::WebViewCore::getWebViewCore(this);
104    if (!core) // SVG does not instantiate webviewcore
105        return; // and doesn't need to record drawing offscreen
106    core->offInvalidate(rect);
107}
108#endif
109
110bool ScrollView::platformIsOffscreen() const
111{
112    /* other platforms override platformIsOffscreen when the browser
113       window is no longer on screen. We override it to prevent gif
114       animations from queuing up subsequent frames during dragging. */
115    return android::WebViewCore::getWebViewCore(this)->drawIsPaused();
116}
117
118} // namespace WebCore
119