• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ScrollableLayerAndroid_h
18 #define ScrollableLayerAndroid_h
19 
20 #if USE(ACCELERATED_COMPOSITING)
21 
22 #include "LayerAndroid.h"
23 
24 namespace WebCore {
25 
26 class ScrollableLayerAndroid : public LayerAndroid {
27 
28 public:
ScrollableLayerAndroid(RenderLayer * owner)29     ScrollableLayerAndroid(RenderLayer* owner)
30         : LayerAndroid(owner) {}
ScrollableLayerAndroid(const ScrollableLayerAndroid & layer)31     ScrollableLayerAndroid(const ScrollableLayerAndroid& layer)
32         : LayerAndroid(layer)
33         , m_scrollLimits(layer.m_scrollLimits) {}
ScrollableLayerAndroid(const LayerAndroid & layer)34     ScrollableLayerAndroid(const LayerAndroid& layer)
35         : LayerAndroid(layer)
36     {
37         m_scrollLimits.setEmpty();
38     }
~ScrollableLayerAndroid()39     virtual ~ScrollableLayerAndroid() {};
40 
contentIsScrollable()41     virtual bool contentIsScrollable() const { return true; }
42 
copy()43     virtual LayerAndroid* copy() const { return new ScrollableLayerAndroid(*this); }
subclassType()44     virtual SubclassType subclassType() const { return LayerAndroid::ScrollableLayer; }
45 
46     // Scrolls to the given position in the layer.
47     // Returns whether or not any scrolling was required.
48     virtual bool scrollTo(int x, int y);
49 
50     // Fills the rect with the current scroll offset and the maximum scroll offset.
51     // fLeft   = scrollX
52     // fTop    = scrollY
53     // fRight  = maxScrollX
54     // fBottom = maxScrollY
55     virtual void getScrollRect(SkIRect*) const;
56 
57     void setScrollLimits(float minX, float minY, float maxX, float maxY);
58 
59     // Given a rect in the layer, scrolls to bring the rect into view. Uses a
60     // lazy approach, whereby we scroll as little as possible to bring the
61     // entire rect into view. If the size of the rect exceeds that of the
62     // visible area of the layer, we favor the top and left of the rect.
63     // Returns whether or not any scrolling was required.
64     bool scrollRectIntoView(const SkIRect&);
65 
66     friend void android::serializeLayer(LayerAndroid* layer, SkWStream* stream);
67     friend LayerAndroid* android::deserializeLayer(int version, SkStream* stream);
68 
69 protected:
70 
71     void getScrollBounds(IntRect*) const;
72 
73     // The position of the visible area of the layer, relative to the parent
74     // layer. This is fixed during scrolling. We acheive scrolling by modifying
75     // the position of the layer.
76     SkRect m_scrollLimits;
77 };
78 
79 }
80 
81 #endif // USE(ACCELERATED_COMPOSITING)
82 
83 #endif // LayerAndroid_h
84