ScrollViewAndroid.cpp revision 016ea440f1b61a966483fc809a078dd28b784e46
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" 358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "WebCoreViewBridge.h" 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "WebViewCore.h" 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project This class implementation does NOT actually emulate the Qt ScrollView. 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project It does provide an implementation that khtml will use to interact with 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project WebKit's WebFrameView documentView and our NSScrollView subclass. 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project ScrollView's view is a NSScrollView (or subclass of NSScrollView) 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project in most cases. That scrollview is a subview of an 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project WebCoreFrameView. The WebCoreFrameView's documentView will also be 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project the scroll view's documentView. 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project The WebCoreFrameView's size is the frame size. The WebCoreFrameView's documentView 498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project corresponds to the frame content size. The scrollview itself is autosized to the 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project WebCoreFrameView's size (see Widget::resize). 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project*/ 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore { 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectIntRect ScrollView::platformVisibleContentRect(bool includeScrollbars) const 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 57899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba // iframe's visible content rect is relative to its parent, not the viewport. 58899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba // As we auto expand the iframe, the frame rect is the content rect. 59899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba if (parent()) 60899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba return IntRect(0, 0, width(), height()); 61899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba else 62899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba return platformWidget()->getVisibleBounds(); 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectIntSize ScrollView::platformContentsSize() const 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return m_contentsSize; 688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 70a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Klobaint ScrollView::platformActualWidth() const 71a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba{ 72a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba if (parent()) 73a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba return width(); 74a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba return platformWidget()->visibleWidth(); 75a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba} 76a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba 77a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Klobaint ScrollView::platformActualHeight() const 78a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba{ 79a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba if (parent()) 80a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba return height(); 81a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba return platformWidget()->visibleHeight(); 82a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba} 83a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba 84a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Klobaint ScrollView::platformActualScrollX() const 85a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba{ 86a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba if (parent()) 87a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba return scrollX(); 88a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba return platformWidget()->visibleX(); 89a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba} 90a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba 91a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Klobaint ScrollView::platformActualScrollY() const 92a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba{ 93a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba if (parent()) 94a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba return scrollY(); 95a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba return platformWidget()->visibleY(); 96a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba} 97a551d0e188b3b4a05e05cc70ff0838c3165c10f6Grace Kloba 988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformSetScrollPosition(const WebCore::IntPoint& pt) 998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1000bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch if (parent()) // don't attempt to scroll subframes; they're fully visible 1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return; 102f116b073399a3c3f644d6e6aeb2521ef9d2c9e9bLeon Scroggins III if (isFrameView() && !PlatformBridge::canScroll(static_cast<FrameView*>(this))) 103f116b073399a3c3f644d6e6aeb2521ef9d2c9e9bLeon Scroggins III return; 1040bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch android::WebViewCore::getWebViewCore(this)->scrollTo(pt.x(), pt.y()); 1058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 10722804c073ffc06fd1fc520d1afbad71e353e488dGrace Klobavoid ScrollView::platformSetScrollbarModes() 10822804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba{ 10922804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba if (parent()) // no scrollbar for the subframes 11022804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba return; 11122804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba android::WebViewCore::getWebViewCore(this)->setScrollbarModes(m_horizontalScrollbarMode, m_verticalScrollbarMode); 11222804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba} 11322804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba 1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) const 1158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 11622804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba // m_horizontalScrollbarMode and m_verticalScrollbarMode are set in ScrollView::setScrollbarModes() 11722804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba h = m_horizontalScrollbarMode; 11822804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba v = m_verticalScrollbarMode; 1198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now) 1228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 1238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project android::WebViewCore::getWebViewCore(this)->contentInvalidate(rect); 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 134025ac4e283bb4b48f580d48541224e3996dc6f84Cary Clark SkRegion rectRgn = SkRegion(rect); 135025ac4e283bb4b48f580d48541224e3996dc6f84Cary Clark rectRgn.op(vis, SkRegion::kDifference_Op); 136025ac4e283bb4b48f580d48541224e3996dc6f84Cary Clark SkRegion::Iterator iter(rectRgn); 137025ac4e283bb4b48f580d48541224e3996dc6f84Cary Clark for (; !iter.done(); iter.next()) { 138025ac4e283bb4b48f580d48541224e3996dc6f84Cary Clark const SkIRect& diff = iter.rect(); 139330e608aa0a04d09cbb92a754420c115fb16d993Cary Clark core->offInvalidate(diff); 140025ac4e283bb4b48f580d48541224e3996dc6f84Cary Clark } 1418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 1438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 144016ea440f1b61a966483fc809a078dd28b784e46Cary Clarkbool ScrollView::platformIsOffscreen() const 145016ea440f1b61a966483fc809a078dd28b784e46Cary Clark{ 146016ea440f1b61a966483fc809a078dd28b784e46Cary Clark /* other platforms override platformIsOffscreen when the browser 147016ea440f1b61a966483fc809a078dd28b784e46Cary Clark window is no longer on screen. We override it to prevent gif 148016ea440f1b61a966483fc809a078dd28b784e46Cary Clark animations from queuing up subsequent frames during dragging. */ 149016ea440f1b61a966483fc809a078dd28b784e46Cary Clark return android::WebViewCore::getWebViewCore(this)->drawIsPaused(); 150016ea440f1b61a966483fc809a078dd28b784e46Cary Clark} 151016ea440f1b61a966483fc809a078dd28b784e46Cary Clark 1520bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch} // namespace WebCore 153