DoubleTapToZoom.h (3464B)
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 #include "mozilla/gfx/Matrix.h" 12 13 template <class T> 14 class RefPtr; 15 16 namespace mozilla { 17 namespace dom { 18 class Document; 19 } 20 21 namespace layers { 22 23 enum class CantZoomOutBehavior : int8_t { Nothing = 0, ZoomIn }; 24 25 struct ZoomTarget { 26 // The preferred target rect that we'd like to zoom in on, if possible. An 27 // empty rect means the browser should zoom out. 28 CSSRect targetRect; 29 30 // If we are asked to zoom out but cannot (due to zoom constraints, etc), then 31 // zoom in some small amount to provide feedback to the user. 32 CantZoomOutBehavior cantZoomOutBehavior = CantZoomOutBehavior::Nothing; 33 34 // If zooming all the way in on |targetRect| is not possible (for example, due 35 // to a max zoom constraint), |elementBoundingRect| may be used to inform a 36 // more optimal target scroll position (for example, we may try to maximize 37 // the area of |elementBoundingRect| that's showing, while keeping 38 // |targetRect| in view and keeping the zoom as close to the desired zoom as 39 // possible). 40 Maybe<CSSRect> elementBoundingRect; 41 42 // The document relative (ie if the content inside the root scroll frame 43 // existed without that scroll frame) pointer position at the time of the 44 // double tap or location of the double tap if we can compute it. Only used if 45 // the rest of this ZoomTarget is asking to zoom out but we are already at the 46 // minimum zoom. In which case we zoom in a small amount on this point. 47 Maybe<CSSPoint> documentRelativePointerPosition; 48 }; 49 50 struct DoubleTapToZoomMetrics { 51 // The visual viewport rect of the top-level content document. 52 CSSRect mVisualViewport; 53 // The scrollable rect of the root scroll container of the top-level content 54 // document. 55 CSSRect mRootScrollableRect; 56 // If double-tap-to-zoom happens inside an OOP iframe, this transform matrix 57 // is the matrix converting the coordinates relative to layout viewport origin 58 // of the OOP iframe to the document origin of the top level content document. 59 // If not, this is the identity matrix. 60 CSSToCSSMatrix4x4 mTransformMatrix; 61 62 bool operator==(const DoubleTapToZoomMetrics& aOther) const { 63 return mVisualViewport == aOther.mVisualViewport && 64 mRootScrollableRect == aOther.mRootScrollableRect && 65 mTransformMatrix == aOther.mTransformMatrix; 66 } 67 friend std::ostream& operator<<(std::ostream& aStream, 68 const DoubleTapToZoomMetrics& aUpdate); 69 }; 70 71 /** 72 * For a double tap at |aPoint|, return a ZoomTarget struct with contains a rect 73 * to which the browser should zoom in response (see ZoomTarget definition for 74 * more details). An empty rect means the browser should zoom out. |aDocument| 75 * should be the in-process root content document for the content that was 76 * tapped. 77 */ 78 ZoomTarget CalculateRectToZoomTo( 79 const RefPtr<mozilla::dom::Document>& aInProcessRootContentDocument, 80 const CSSPoint& aPoint, const DoubleTapToZoomMetrics& aMetrics); 81 82 } // namespace layers 83 } // namespace mozilla 84 85 #endif /* mozilla_layers_DoubleTapToZoom_h */