ScrollViewAndroid.cpp revision e859a34171f2a36877d95197d118d962078f8aa0
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" 3554b541647c8a934868c6c0f00665611569c9e4b8Leon Scroggins#include "WebCoreFrameBridge.h" 368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "WebCoreViewBridge.h" 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "WebViewCore.h" 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/* 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project This class implementation does NOT actually emulate the Qt ScrollView. 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project It does provide an implementation that khtml will use to interact with 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project WebKit's WebFrameView documentView and our NSScrollView subclass. 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project ScrollView's view is a NSScrollView (or subclass of NSScrollView) 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project in most cases. That scrollview is a subview of an 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project WebCoreFrameView. The WebCoreFrameView's documentView will also be 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project the scroll view's documentView. 488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project The WebCoreFrameView's size is the frame size. The WebCoreFrameView's documentView 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project corresponds to the frame content size. The scrollview itself is autosized to the 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project WebCoreFrameView's size (see Widget::resize). 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project*/ 538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore { 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectIntRect ScrollView::platformVisibleContentRect(bool includeScrollbars) const 578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 58899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba // iframe's visible content rect is relative to its parent, not the viewport. 59899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba // As we auto expand the iframe, the frame rect is the content rect. 60899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba if (parent()) 61899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba return IntRect(0, 0, width(), height()); 62899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba else 63899f518a7f2682c900252ca03d93f83095a43d52Grace Kloba return platformWidget()->getVisibleBounds(); 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source ProjectIntSize ScrollView::platformContentsSize() const 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project return m_contentsSize; 698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformSetScrollPosition(const WebCore::IntPoint& pt) 728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 7344bed85f240ccdf65de028e6fe2832b390676d47George Mount PlatformBridge::setScrollPosition(this, m_scrollOrigin.x() + pt.x(), 7444bed85f240ccdf65de028e6fe2832b390676d47George Mount m_scrollOrigin.y() + pt.y()); 758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 7722804c073ffc06fd1fc520d1afbad71e353e488dGrace Klobavoid ScrollView::platformSetScrollbarModes() 7822804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba{ 7922804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba if (parent()) // no scrollbar for the subframes 8022804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba return; 8122804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba android::WebViewCore::getWebViewCore(this)->setScrollbarModes(m_horizontalScrollbarMode, m_verticalScrollbarMode); 8222804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba} 8322804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) const 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 8622804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba // m_horizontalScrollbarMode and m_verticalScrollbarMode are set in ScrollView::setScrollbarModes() 8722804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba h = m_horizontalScrollbarMode; 8822804c073ffc06fd1fc520d1afbad71e353e488dGrace Kloba v = m_verticalScrollbarMode; 898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectvoid ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now) 928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 9344bed85f240ccdf65de028e6fe2832b390676d47George Mount IntRect offsetRect = rect; 9444bed85f240ccdf65de028e6fe2832b390676d47George Mount offsetRect.move(m_scrollOrigin.x(), m_scrollOrigin.y()); 9544bed85f240ccdf65de028e6fe2832b390676d47George Mount android::WebViewCore::getWebViewCore(this)->contentInvalidate(offsetRect); 968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS 994465d348a977f9f062b28957709a77613311647aAndrei Popescu// Compute the offscreen parts of the drawn rectangle by subtracting 1004465d348a977f9f062b28957709a77613311647aAndrei Popescu// vis from rect. This can compute up to four rectangular slices. 1014465d348a977f9f062b28957709a77613311647aAndrei Popescuvoid ScrollView::platformOffscreenContentRectangle(const IntRect& vis, const IntRect& rect) 1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project{ 103330e608aa0a04d09cbb92a754420c115fb16d993Cary Clark android::WebViewCore* core = android::WebViewCore::getWebViewCore(this); 104330e608aa0a04d09cbb92a754420c115fb16d993Cary Clark if (!core) // SVG does not instantiate webviewcore 105330e608aa0a04d09cbb92a754420c115fb16d993Cary Clark return; // and doesn't need to record drawing offscreen 106e859a34171f2a36877d95197d118d962078f8aa0John Reck core->offInvalidate(rect); 1078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} 1088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 1098e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 110016ea440f1b61a966483fc809a078dd28b784e46Cary Clarkbool ScrollView::platformIsOffscreen() const 111016ea440f1b61a966483fc809a078dd28b784e46Cary Clark{ 112016ea440f1b61a966483fc809a078dd28b784e46Cary Clark /* other platforms override platformIsOffscreen when the browser 113016ea440f1b61a966483fc809a078dd28b784e46Cary Clark window is no longer on screen. We override it to prevent gif 114016ea440f1b61a966483fc809a078dd28b784e46Cary Clark animations from queuing up subsequent frames during dragging. */ 115016ea440f1b61a966483fc809a078dd28b784e46Cary Clark return android::WebViewCore::getWebViewCore(this)->drawIsPaused(); 116016ea440f1b61a966483fc809a078dd28b784e46Cary Clark} 117016ea440f1b61a966483fc809a078dd28b784e46Cary Clark 1180bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5Ben Murdoch} // namespace WebCore 119