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 "SkRegion.h" 34 #include "WebCoreFrameBridge.h" 35 #include "WebCoreViewBridge.h" 36 #include "WebViewCore.h" 37 38 /* 39 This class implementation does NOT actually emulate the Qt ScrollView. 40 It does provide an implementation that khtml will use to interact with 41 WebKit's WebFrameView documentView and our NSScrollView subclass. 42 43 ScrollView's view is a NSScrollView (or subclass of NSScrollView) 44 in most cases. That scrollview is a subview of an 45 WebCoreFrameView. The WebCoreFrameView's documentView will also be 46 the scroll view's documentView. 47 48 The WebCoreFrameView's size is the frame size. The WebCoreFrameView's documentView 49 corresponds to the frame content size. The scrollview itself is autosized to the 50 WebCoreFrameView's size (see Widget::resize). 51 */ 52 53 namespace WebCore { 54 55 IntRect ScrollView::platformVisibleContentRect(bool includeScrollbars) const 56 { 57 IntRect rect = platformWidget()->getBounds(); 58 // This makes subframes draw correctly, since subframes cannot scroll. 59 if (parent()) 60 return IntRect(0, 0, rect.width(), rect.height()); 61 return rect; 62 } 63 64 IntSize ScrollView::platformContentsSize() const 65 { 66 return m_contentsSize; 67 } 68 69 void ScrollView::platformSetScrollPosition(const WebCore::IntPoint& pt) 70 { 71 if (parent()) // don't attempt to scroll subframes; they're fully visible 72 return; 73 android::WebViewCore::getWebViewCore(this)->scrollTo(pt.x(), pt.y()); 74 } 75 76 void ScrollView::platformSetScrollbarModes() 77 { 78 if (parent()) // no scrollbar for the subframes 79 return; 80 android::WebViewCore::getWebViewCore(this)->setScrollbarModes(m_horizontalScrollbarMode, m_verticalScrollbarMode); 81 } 82 83 void ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) const 84 { 85 // m_horizontalScrollbarMode and m_verticalScrollbarMode are set in ScrollView::setScrollbarModes() 86 h = m_horizontalScrollbarMode; 87 v = m_verticalScrollbarMode; 88 } 89 90 bool ScrollView::platformProhibitsScrolling() 91 { 92 if (!isFrameView()) 93 return false; 94 FrameView* view = static_cast<FrameView*>(this); 95 // We want to ignore requests to scroll that were not initiated by the user. An 96 // example of this is when text is inserted into a textfield/area, which results in 97 // a scroll. We ignore this because we now how to do this ourselves in the UI thread. 98 // An example of it being initiated by the user is if the user clicks an anchor 99 // element which simply scrolls the page. 100 return !android::WebFrame::getWebFrame(view->frame())->userInitiatedClick(); 101 } 102 103 void ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now) 104 { 105 android::WebViewCore::getWebViewCore(this)->contentInvalidate(rect); 106 } 107 108 #ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS 109 // Compute the offscreen parts of the drawn rectangle by subtracting 110 // vis from rect. This can compute up to four rectangular slices. 111 void ScrollView::platformOffscreenContentRectangle(const IntRect& vis, const IntRect& rect) 112 { 113 SkRegion rectRgn = SkRegion(rect); 114 rectRgn.op(vis, SkRegion::kDifference_Op); 115 SkRegion::Iterator iter(rectRgn); 116 for (; !iter.done(); iter.next()) { 117 const SkIRect& diff = iter.rect(); 118 android::WebViewCore::getWebViewCore(this)->offInvalidate(diff); 119 } 120 } 121 #endif 122 123 } // namespace WebCore 124