Home | History | Annotate | Download | only in android
      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 
     54 namespace WebCore {
     55 
     56 IntRect 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 
     66 IntSize ScrollView::platformContentsSize() const
     67 {
     68     return m_contentsSize;
     69 }
     70 
     71 int ScrollView::platformActualWidth() const
     72 {
     73     if (parent())
     74         return width();
     75     return platformWidget()->visibleWidth();
     76 }
     77 
     78 int ScrollView::platformActualHeight() const
     79 {
     80     if (parent())
     81         return height();
     82     return platformWidget()->visibleHeight();
     83 }
     84 
     85 int ScrollView::platformActualScrollX() const
     86 {
     87     if (parent())
     88         return scrollX();
     89     return platformWidget()->visibleX();
     90 }
     91 
     92 int ScrollView::platformActualScrollY() const
     93 {
     94     if (parent())
     95         return scrollY();
     96     return platformWidget()->visibleY();
     97 }
     98 
     99 void ScrollView::platformSetScrollPosition(const WebCore::IntPoint& pt)
    100 {
    101     PlatformBridge::setScrollPosition(this, m_scrollOrigin.x() + pt.x(),
    102             m_scrollOrigin.y() + pt.y());
    103 }
    104 
    105 void ScrollView::platformSetScrollbarModes()
    106 {
    107     if (parent()) // no scrollbar for the subframes
    108         return;
    109     android::WebViewCore::getWebViewCore(this)->setScrollbarModes(m_horizontalScrollbarMode, m_verticalScrollbarMode);
    110 }
    111 
    112 void ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) const
    113 {
    114     // m_horizontalScrollbarMode and m_verticalScrollbarMode are set in ScrollView::setScrollbarModes()
    115     h = m_horizontalScrollbarMode;
    116     v = m_verticalScrollbarMode;
    117 }
    118 
    119 void ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now)
    120 {
    121     IntRect offsetRect = rect;
    122     offsetRect.move(m_scrollOrigin.x(), m_scrollOrigin.y());
    123     android::WebViewCore::getWebViewCore(this)->contentInvalidate(offsetRect);
    124 }
    125 
    126 #ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS
    127 //  Compute the offscreen parts of the drawn rectangle by subtracting
    128 //  vis from rect. This can compute up to four rectangular slices.
    129 void ScrollView::platformOffscreenContentRectangle(const IntRect& vis, const IntRect& rect)
    130 {
    131     android::WebViewCore* core = android::WebViewCore::getWebViewCore(this);
    132     if (!core) // SVG does not instantiate webviewcore
    133         return; // and doesn't need to record drawing offscreen
    134     core->offInvalidate(rect);
    135 }
    136 #endif
    137 
    138 bool ScrollView::platformIsOffscreen() const
    139 {
    140     /* other platforms override platformIsOffscreen when the browser
    141        window is no longer on screen. We override it to prevent gif
    142        animations from queuing up subsequent frames during dragging. */
    143     return android::WebViewCore::getWebViewCore(this)->drawIsPaused();
    144 }
    145 
    146 } // namespace WebCore
    147