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: 29 ScrollableLayerAndroid(RenderLayer* owner) 30 : LayerAndroid(owner) {} 31 ScrollableLayerAndroid(const ScrollableLayerAndroid& layer) 32 : LayerAndroid(layer) 33 , m_scrollLimits(layer.m_scrollLimits) {} 34 ScrollableLayerAndroid(const LayerAndroid& layer) 35 : LayerAndroid(layer) 36 { 37 m_scrollLimits.setEmpty(); 38 } 39 virtual ~ScrollableLayerAndroid() {}; 40 41 virtual bool contentIsScrollable() const { return true; } 42 43 virtual LayerAndroid* copy() const { return new ScrollableLayerAndroid(*this); } 44 45 virtual bool updateWithLayer(LayerAndroid*) { return true; } 46 47 // Scrolls to the given position in the layer. 48 // Returns whether or not any scrolling was required. 49 bool scrollTo(int x, int y); 50 51 // Fills the rect with the current scroll offset and the maximum scroll offset. 52 // fLeft = scrollX 53 // fTop = scrollY 54 // fRight = maxScrollX 55 // fBottom = maxScrollY 56 void getScrollRect(SkIRect*) const; 57 58 void setScrollLimits(float x, float y, float width, float height) 59 { 60 m_scrollLimits.set(x, y, x + width, y + height); 61 } 62 63 // Given a rect in the layer, scrolls to bring the rect into view. Uses a 64 // lazy approach, whereby we scroll as little as possible to bring the 65 // entire rect into view. If the size of the rect exceeds that of the 66 // visible area of the layer, we favor the top and left of the rect. 67 // Returns whether or not any scrolling was required. 68 bool scrollRectIntoView(const SkIRect&); 69 70 friend void android::serializeLayer(LayerAndroid* layer, SkWStream* stream); 71 friend LayerAndroid* android::deserializeLayer(SkStream* stream); 72 73 private: 74 // The position of the visible area of the layer, relative to the parent 75 // layer. This is fixed during scrolling. We acheive scrolling by modifying 76 // the position of the layer. 77 SkRect m_scrollLimits; 78 }; 79 80 } 81 82 #endif // USE(ACCELERATED_COMPOSITING) 83 84 #endif // LayerAndroid_h 85