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     if (parent()) // don't attempt to scroll subframes; they're fully visible
    102         return;
    103     PlatformBridge::setScrollPosition(this, m_scrollOrigin.x() + pt.x(),
    104             m_scrollOrigin.y() + pt.y());
    105 }
    106 
    107 void ScrollView::platformSetScrollbarModes()
    108 {
    109     if (parent()) // no scrollbar for the subframes
    110         return;
    111     android::WebViewCore::getWebViewCore(this)->setScrollbarModes(m_horizontalScrollbarMode, m_verticalScrollbarMode);
    112 }
    113 
    114 void ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) const
    115 {
    116     // m_horizontalScrollbarMode and m_verticalScrollbarMode are set in ScrollView::setScrollbarModes()
    117     h = m_horizontalScrollbarMode;
    118     v = m_verticalScrollbarMode;
    119 }
    120 
    121 void ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now)
    122 {
    123     IntRect offsetRect = rect;
    124     offsetRect.move(m_scrollOrigin.x(), m_scrollOrigin.y());
    125     android::WebViewCore::getWebViewCore(this)->contentInvalidate(offsetRect);
    126 }
    127 
    128 #ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS
    129 //  Compute the offscreen parts of the drawn rectangle by subtracting
    130 //  vis from rect. This can compute up to four rectangular slices.
    131 void ScrollView::platformOffscreenContentRectangle(const IntRect& vis, const IntRect& rect)
    132 {
    133     android::WebViewCore* core = android::WebViewCore::getWebViewCore(this);
    134     if (!core) // SVG does not instantiate webviewcore
    135         return; // and doesn't need to record drawing offscreen
    136     SkRegion rectRgn = SkRegion(rect);
    137     rectRgn.op(vis, SkRegion::kDifference_Op);
    138     SkRegion::Iterator iter(rectRgn);
    139     for (; !iter.done(); iter.next()) {
    140         const SkIRect& diff = iter.rect();
    141         core->offInvalidate(diff);
    142     }
    143 }
    144 #endif
    145 
    146 bool ScrollView::platformIsOffscreen() const
    147 {
    148     /* other platforms override platformIsOffscreen when the browser
    149        window is no longer on screen. We override it to prevent gif
    150        animations from queuing up subsequent frames during dragging. */
    151     return android::WebViewCore::getWebViewCore(this)->drawIsPaused();
    152 }
    153 
    154 } // namespace WebCore
    155