DragTracker.cpp (1961B)
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 #include "mozilla/Logging.h" 11 12 static mozilla::LazyLogModule sApzDrgLog("apz.drag"); 13 #define DRAG_LOG(...) MOZ_LOG(sApzDrgLog, LogLevel::Debug, (__VA_ARGS__)) 14 15 namespace mozilla { 16 namespace layers { 17 18 DragTracker::DragTracker() : mInDrag(false) {} 19 20 /*static*/ 21 bool DragTracker::StartsDrag(const MouseInput& aInput) { 22 return aInput.IsLeftButton() && aInput.mType == MouseInput::MOUSE_DOWN; 23 } 24 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; 35 } 36 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(); 45 } 46 } 47 48 bool DragTracker::InDrag() const { return mInDrag; } 49 50 bool DragTracker::IsOnScrollbar(bool aOnScrollbar) { 51 if (!mOnScrollbar) { 52 DRAG_LOG("Setting hitscrollbar %d\n", aOnScrollbar); 53 mOnScrollbar = Some(aOnScrollbar); 54 } 55 return mOnScrollbar.value(); 56 } 57 58 } // namespace layers 59 } // namespace mozilla