Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / frame / PinchViewport.h
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef PinchViewport_h
32 #define PinchViewport_h
33
34 #include "platform/geometry/FloatPoint.h"
35 #include "platform/geometry/FloatRect.h"
36 #include "platform/geometry/IntSize.h"
37 #include "platform/graphics/GraphicsLayerClient.h"
38 #include "platform/scroll/ScrollableArea.h"
39 #include "public/platform/WebScrollbar.h"
40 #include "public/platform/WebSize.h"
41 #include "wtf/OwnPtr.h"
42 #include "wtf/PassOwnPtr.h"
43
44 namespace blink {
45 class WebLayerTreeView;
46 class WebScrollbarLayer;
47 }
48
49 namespace WebCore {
50
51 class FrameHost;
52 class GraphicsContext;
53 class GraphicsLayer;
54 class GraphicsLayerFactory;
55 class IntRect;
56 class IntSize;
57 class LocalFrame;
58
59 // Represents the pinch-to-zoom viewport the user is currently seeing the page through. This
60 // class corresponds to the InnerViewport on the compositor. It is a ScrollableArea; it's
61 // offset is set through the GraphicsLayer <-> CC sync mechanisms. Its contents is the page's
62 // main FrameView, which corresponds to the outer viewport. The inner viewport is always contained
63 // in the outer viewport and can pan within it.
64 class PinchViewport FINAL : public GraphicsLayerClient, public ScrollableArea {
65 public:
66     explicit PinchViewport(FrameHost&);
67     virtual ~PinchViewport();
68
69     void attachToLayerTree(GraphicsLayer*, GraphicsLayerFactory*);
70     GraphicsLayer* rootGraphicsLayer()
71     {
72         return m_innerViewportContainerLayer.get();
73     }
74
75     // Sets the location of the inner viewport relative to the outer viewport. The
76     // coordinates are in partial CSS pixels.
77     void setLocation(const FloatPoint&);
78     void move(const FloatPoint&);
79
80     // Sets the size of the inner viewport when unscaled in CSS pixels.
81     // This will be clamped to the size of the outer viewport (the main frame).
82     void setSize(const IntSize&);
83     IntSize size() const { return m_size; }
84
85     // Resets the viewport to initial state.
86     void reset();
87
88     // Let the viewport know that the main frame changed size (either through screen
89     // rotation on Android or window resize elsewhere).
90     void mainFrameDidChangeSize();
91
92     void setScale(float);
93     float scale() const { return m_scale; }
94
95     void registerLayersWithTreeView(blink::WebLayerTreeView*) const;
96     void clearLayersForTreeView(blink::WebLayerTreeView*) const;
97
98     // The portion of the unzoomed frame visible in the inner "pinch" viewport, in partial CSS pixels.
99     FloatRect visibleRect() const;
100 private:
101     // ScrollableArea implementation
102     virtual bool isActive() const OVERRIDE { return false; }
103     virtual int scrollSize(ScrollbarOrientation) const OVERRIDE;
104     virtual bool isScrollCornerVisible() const OVERRIDE { return false; }
105     virtual IntRect scrollCornerRect() const OVERRIDE { return IntRect(); }
106     virtual IntPoint scrollPosition() const OVERRIDE { return flooredIntPoint(m_offset); }
107     virtual IntPoint minimumScrollPosition() const OVERRIDE;
108     virtual IntPoint maximumScrollPosition() const OVERRIDE;
109     virtual int visibleHeight() const OVERRIDE { return visibleRect().height(); };
110     virtual int visibleWidth() const OVERRIDE { return visibleRect().width(); };
111     virtual IntSize contentsSize() const OVERRIDE;
112     virtual bool scrollbarsCanBeActive() const OVERRIDE { return false; }
113     virtual IntRect scrollableAreaBoundingBox() const OVERRIDE;
114     virtual bool userInputScrollable(ScrollbarOrientation) const OVERRIDE { return true; }
115     virtual bool shouldPlaceVerticalScrollbarOnLeft() const OVERRIDE { return false; }
116     virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) OVERRIDE;
117     virtual void invalidateScrollCornerRect(const IntRect&) OVERRIDE { }
118     virtual void setScrollOffset(const IntPoint&) OVERRIDE;
119     virtual GraphicsLayer* layerForContainer() const OVERRIDE;
120     virtual GraphicsLayer* layerForScrolling() const OVERRIDE;
121     virtual GraphicsLayer* layerForHorizontalScrollbar() const OVERRIDE;
122     virtual GraphicsLayer* layerForVerticalScrollbar() const OVERRIDE;
123
124     // GraphicsLayerClient implementation.
125     virtual void notifyAnimationStarted(const GraphicsLayer*, double monotonicTime) OVERRIDE;
126     virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& inClip) OVERRIDE;
127     virtual String debugName(const GraphicsLayer*) OVERRIDE;
128
129     void setupScrollbar(blink::WebScrollbar::Orientation);
130     FloatPoint clampOffsetToBoundaries(const FloatPoint&);
131
132     LocalFrame* mainFrame() const;
133
134     FrameHost& m_frameHost;
135     OwnPtr<GraphicsLayer> m_innerViewportContainerLayer;
136     OwnPtr<GraphicsLayer> m_pageScaleLayer;
137     OwnPtr<GraphicsLayer> m_innerViewportScrollLayer;
138     OwnPtr<GraphicsLayer> m_overlayScrollbarHorizontal;
139     OwnPtr<GraphicsLayer> m_overlayScrollbarVertical;
140     OwnPtr<blink::WebScrollbarLayer> m_webOverlayScrollbarHorizontal;
141     OwnPtr<blink::WebScrollbarLayer> m_webOverlayScrollbarVertical;
142
143     // Offset of the pinch viewport from the main frame's origin, in CSS pixels.
144     FloatPoint m_offset;
145     float m_scale;
146     IntSize m_size;
147 };
148
149 } // namespace WebCore
150
151 #endif // PinchViewport_h