1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_layers_DoubleTapToZoom_h
8 #define mozilla_layers_DoubleTapToZoom_h
9 
10 #include "Units.h"
11 
12 template <class T>
13 class RefPtr;
14 
15 namespace mozilla {
16 namespace dom {
17 class Document;
18 }
19 
20 namespace layers {
21 
22 enum class CantZoomOutBehavior : int8_t { Nothing = 0, ZoomIn };
23 
24 struct ZoomTarget {
25   // The preferred target rect that we'd like to zoom in on, if possible. An
26   // empty rect means the browser should zoom out.
27   CSSRect targetRect;
28 
29   // If we are asked to zoom out but cannot (due to zoom constraints, etc), then
30   // zoom in some small amount to provide feedback to the user.
31   CantZoomOutBehavior cantZoomOutBehavior = CantZoomOutBehavior::Nothing;
32 
33   // If zooming all the way in on |targetRect| is not possible (for example, due
34   // to a max zoom constraint), |elementBoundingRect| may be used to inform a
35   // more optimal target scroll position (for example, we may try to maximize
36   // the area of |elementBoundingRect| that's showing, while keeping
37   // |targetRect| in view and keeping the zoom as close to the desired zoom as
38   // possible).
39   Maybe<CSSRect> elementBoundingRect;
40 
41   // The document relative (ie if the content inside the root scroll frame
42   // existed without that scroll frame) pointer position at the time of the
43   // double tap or location of the double tap if we can compute it. Only used if
44   // the rest of this ZoomTarget is asking to zoom out but we are already at the
45   // minimum zoom. In which case we zoom in a small amount on this point.
46   Maybe<CSSPoint> documentRelativePointerPosition;
47 };
48 
49 /**
50  * For a double tap at |aPoint|, return a ZoomTarget struct with contains a rect
51  * to which the browser should zoom in response (see ZoomTarget definition for
52  * more details). An empty rect means the browser should zoom out. |aDocument|
53  * should be the root content document for the content that was tapped.
54  */
55 ZoomTarget CalculateRectToZoomTo(
56     const RefPtr<mozilla::dom::Document>& aRootContentDocument,
57     const CSSPoint& aPoint);
58 
59 }  // namespace layers
60 }  // namespace mozilla
61 
62 #endif /* mozilla_layers_DoubleTapToZoom_h */
63