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