Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / layers / viewport.h
blob5d96cd3b28361db09fbb7ab0da9cb93cdb153888
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_LAYERS_VIEWPORT_H_
6 #define CC_LAYERS_VIEWPORT_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "cc/layers/layer_impl.h"
10 #include "ui/gfx/geometry/vector2d_f.h"
12 namespace cc {
14 class LayerTreeHostImpl;
16 // Encapsulates gesture handling logic on the viewport layers. The "viewport"
17 // is made up of two scrolling layers, the inner viewport (visual) and the
18 // outer viewport (layout) scroll layers. These layers have different scroll
19 // bubbling behavior from the rest of the layer tree which is encoded in this
20 // class.
21 class CC_EXPORT Viewport {
22 public:
23 // If the pinch zoom anchor on the first PinchUpdate is within this length
24 // of the screen edge, "snap" the zoom to that edge. Experimentally
25 // determined.
26 static const int kPinchZoomSnapMarginDips = 100;
28 // TODO(tdresser): eventually |consumed_delta| should equal
29 // |content_scrolled_delta|. See crbug.com/510045 for details.
30 struct ScrollResult {
31 gfx::Vector2dF consumed_delta;
32 gfx::Vector2dF content_scrolled_delta;
35 static scoped_ptr<Viewport> Create(LayerTreeHostImpl* host_impl);
37 // Differs from scrolling in that only the visual viewport is moved, without
38 // affecting the top controls or outer viewport.
39 void Pan(const gfx::Vector2dF& delta);
41 // Scrolls the viewport, applying the unique bubbling between the inner and
42 // outer viewport. Scrolls can be consumed by top controls.
43 ScrollResult ScrollBy(const gfx::Vector2dF& delta,
44 const gfx::Point& viewport_point,
45 bool is_wheel_scroll,
46 bool affect_top_controls);
48 void PinchUpdate(float magnify_delta, const gfx::Point& anchor);
49 void PinchEnd();
51 private:
52 explicit Viewport(LayerTreeHostImpl* host_impl);
54 bool ShouldTopControlsConsumeScroll(const gfx::Vector2dF& scroll_delta) const;
55 gfx::Vector2dF AdjustOverscroll(const gfx::Vector2dF& delta) const;
57 // Sends the delta to the top controls, returns the amount applied.
58 gfx::Vector2dF ScrollTopControls(const gfx::Vector2dF& delta);
60 gfx::ScrollOffset MaxTotalScrollOffset() const;
61 gfx::ScrollOffset TotalScrollOffset() const;
63 LayerImpl* InnerScrollLayer() const;
64 LayerImpl* OuterScrollLayer() const;
66 void SnapPinchAnchorIfWithinMargin(const gfx::Point& anchor);
68 LayerTreeHostImpl* host_impl_;
70 bool pinch_zoom_active_;
72 // The pinch zoom anchor point is adjusted by this amount during a pinch. This
73 // is used to "snap" a pinch-zoom to the edge of the screen.
74 gfx::Vector2d pinch_anchor_adjustment_;
76 DISALLOW_COPY_AND_ASSIGN(Viewport);
79 } // namespace cc
81 #endif // CC_LAYERS_VIEWPORT_H_