• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "WebCoreFrameBridge.h"
34 #include "WebCoreViewBridge.h"
35 #include "WebViewCore.h"
36 
37 /*
38     This class implementation does NOT actually emulate the Qt ScrollView.
39     It does provide an implementation that khtml will use to interact with
40     WebKit's WebFrameView documentView and our NSScrollView subclass.
41 
42     ScrollView's view is a NSScrollView (or subclass of NSScrollView)
43     in most cases. That scrollview is a subview of an
44     WebCoreFrameView. The WebCoreFrameView's documentView will also be
45     the scroll view's documentView.
46 
47     The WebCoreFrameView's size is the frame size.  The WebCoreFrameView's documentView
48     corresponds to the frame content size.  The scrollview itself is autosized to the
49     WebCoreFrameView's size (see Widget::resize).
50 */
51 
52 namespace WebCore {
53 
platformVisibleContentRect(bool includeScrollbars) const54 IntRect ScrollView::platformVisibleContentRect(bool includeScrollbars) const
55 {
56     IntRect rect = platformWidget()->getBounds();
57     // This makes subframes draw correctly, since subframes cannot scroll.
58     if (parent())
59         return IntRect(0, 0, rect.width(), rect.height());
60     return rect;
61 }
62 
platformContentsSize() const63 IntSize ScrollView::platformContentsSize() const
64 {
65     return m_contentsSize;
66 }
67 
platformSetScrollPosition(const WebCore::IntPoint & pt)68 void ScrollView::platformSetScrollPosition(const WebCore::IntPoint& pt)
69 {
70     if (parent()) // don't attempt to scroll subframes; they're fully visible
71         return;
72     android::WebViewCore::getWebViewCore(this)->scrollTo(pt.x(), pt.y());
73 }
74 
platformScrollbarModes(ScrollbarMode & h,ScrollbarMode & v) const75 void ScrollView::platformScrollbarModes(ScrollbarMode& h, ScrollbarMode& v) const
76 {
77     h = v = ScrollbarAlwaysOff;
78 }
79 
platformProhibitsScrolling()80 bool ScrollView::platformProhibitsScrolling()
81 {
82     if (!isFrameView())
83         return false;
84     FrameView* view = static_cast<FrameView*>(this);
85     // We want to ignore requests to scroll that were not initiated by the user.  An
86     // example of this is when text is inserted into a textfield/area, which results in
87     // a scroll.  We ignore this because we now how to do this ourselves in the UI thread.
88     // An example of it being initiated by the user is if the user clicks an anchor
89     // element which simply scrolls the page.
90     return !android::WebFrame::getWebFrame(view->frame())->userInitiatedClick();
91 }
92 
platformRepaintContentRectangle(const IntRect & rect,bool now)93 void ScrollView::platformRepaintContentRectangle(const IntRect &rect, bool now)
94 {
95     android::WebViewCore::getWebViewCore(this)->contentInvalidate(rect);
96 }
97 
98 #ifdef ANDROID_CAPTURE_OFFSCREEN_PAINTS
platformOffscreenContentRectangle(const IntRect & rect)99 void ScrollView::platformOffscreenContentRectangle(const IntRect& rect)
100 {
101     android::WebViewCore::getWebViewCore(this)->offInvalidate(rect);
102 }
103 #endif
104 
105 }
106