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