LibreOffice Module android (master) 1
SubdocumentScrollHelper.java
Go to the documentation of this file.
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/. */
5
6package org.mozilla.gecko.gfx;
7
8import android.graphics.PointF;
9import android.os.Handler;
10
11class SubdocumentScrollHelper {
12 private static final String LOGTAG = "GeckoSubdocumentScrollHelper";
13
14 private final Handler mUiHandler;
15
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;
19
20 /* When this is true, we're sending scroll events to JS to scroll the active subdocument. */
21 private boolean mOverridePanning;
22
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;
27
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;
31
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;
35
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();
40 }
41
42 void destroy() {
43 }
44
45 boolean scrollBy(PointF displacement) {
46 if (! mOverridePanning) {
47 return false;
48 }
49
50 if (! mOverrideScrollAck) {
51 mOverrideScrollPending = true;
52 mPendingDisplacement.x += displacement.x;
53 mPendingDisplacement.y += displacement.y;
54 return true;
55 }
56
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;
63
64 return true;
65 }
66
67 void cancel() {
68 mOverridePanning = false;
69 }
70
71 boolean scrolling() {
72 return mOverridePanning;
73 }
74
75 boolean lastScrollSucceeded() {
76 return mScrollSucceeded;
77 }
78}
#define LOGTAG