Update git submodules
[LibreOffice.git] / android / source / src / java / org / mozilla / gecko / gfx / SubdocumentScrollHelper.java
blob5a752e3c71a8d726e20590a9977cfb503ab8a125
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org.mozilla.gecko.gfx;
8 import android.graphics.PointF;
9 import android.os.Handler;
11 class SubdocumentScrollHelper {
12 private static final String LOGTAG = "GeckoSubdocumentScrollHelper";
14 private final Handler mUiHandler;
16 /* This is the amount of displacement we have accepted but not yet sent to JS; this is
17 * only valid when mOverrideScrollPending is true. */
18 private final PointF mPendingDisplacement;
20 /* When this is true, we're sending scroll events to JS to scroll the active subdocument. */
21 private boolean mOverridePanning;
23 /* When this is true, we have received an ack for the last scroll event we sent to JS, and
24 * are ready to send the next scroll event. Note we only ever have one scroll event inflight
25 * at a time. */
26 private boolean mOverrideScrollAck;
28 /* When this is true, we have a pending scroll that we need to send to JS; we were unable
29 * to send it when it was initially requested because mOverrideScrollAck was not true. */
30 private boolean mOverrideScrollPending;
32 /* When this is true, the last scroll event we sent actually did some amount of scrolling on
33 * the subdocument; we use this to decide when we have reached the end of the subdocument. */
34 private boolean mScrollSucceeded;
36 SubdocumentScrollHelper() {
37 // mUiHandler will be bound to the UI thread since that's where this constructor runs
38 mUiHandler = new Handler();
39 mPendingDisplacement = new PointF();
42 void destroy() {
45 boolean scrollBy(PointF displacement) {
46 if (! mOverridePanning) {
47 return false;
50 if (! mOverrideScrollAck) {
51 mOverrideScrollPending = true;
52 mPendingDisplacement.x += displacement.x;
53 mPendingDisplacement.y += displacement.y;
54 return true;
57 mOverrideScrollAck = false;
58 mOverrideScrollPending = false;
59 // clear the |mPendingDisplacement| after serializing |displacement| to
60 // JSON because they might be the same object
61 mPendingDisplacement.x = 0;
62 mPendingDisplacement.y = 0;
64 return true;
67 void cancel() {
68 mOverridePanning = false;
71 boolean scrolling() {
72 return mOverridePanning;
75 boolean lastScrollSucceeded() {
76 return mScrollSucceeded;