Source code

Revision control

Other Tools

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
#include "DragTracker.h"
8
9
#include "InputData.h"
10
11
static mozilla::LazyLogModule sApzDrgLog("apz.drag");
12
#define DRAG_LOG(...) MOZ_LOG(sApzDrgLog, LogLevel::Debug, (__VA_ARGS__))
13
14
namespace mozilla {
15
namespace layers {
16
17
DragTracker::DragTracker() : mInDrag(false) {}
18
19
/*static*/
20
bool DragTracker::StartsDrag(const MouseInput& aInput) {
21
return aInput.IsLeftButton() && aInput.mType == MouseInput::MOUSE_DOWN;
22
}
23
24
/*static*/
25
bool DragTracker::EndsDrag(const MouseInput& aInput) {
26
// On Windows, we don't receive a MOUSE_UP at the end of a drag if an
27
// actual drag session took place. As a backup, we detect the end of the
28
// drag using the MOUSE_DRAG_END event, which normally is routed directly
29
// to content, but we're specially routing to APZ for this purpose. Bug
30
// 1265105 tracks a solution to this at the Windows widget layer; once
31
// that is implemented, this workaround can be removed.
32
return (aInput.IsLeftButton() && aInput.mType == MouseInput::MOUSE_UP) ||
33
aInput.mType == MouseInput::MOUSE_DRAG_END;
34
}
35
36
void DragTracker::Update(const MouseInput& aInput) {
37
if (StartsDrag(aInput)) {
38
DRAG_LOG("Starting drag\n");
39
mInDrag = true;
40
} else if (EndsDrag(aInput)) {
41
DRAG_LOG("Ending drag\n");
42
mInDrag = false;
43
mOnScrollbar = Nothing();
44
}
45
}
46
47
bool DragTracker::InDrag() const { return mInDrag; }
48
49
bool DragTracker::IsOnScrollbar(bool aOnScrollbar) {
50
if (!mOnScrollbar) {
51
DRAG_LOG("Setting hitscrollbar %d\n", aOnScrollbar);
52
mOnScrollbar = Some(aOnScrollbar);
53
}
54
return mOnScrollbar.value();
55
}
56
57
} // namespace layers
58
} // namespace mozilla