dom/events/WheelHandlingHelper.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 sw=2 et tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "WheelHandlingHelper.h"
michael@0 8
michael@0 9 #include "mozilla/EventDispatcher.h"
michael@0 10 #include "mozilla/EventStateManager.h"
michael@0 11 #include "mozilla/MouseEvents.h"
michael@0 12 #include "mozilla/Preferences.h"
michael@0 13 #include "nsCOMPtr.h"
michael@0 14 #include "nsContentUtils.h"
michael@0 15 #include "nsIContent.h"
michael@0 16 #include "nsIDocument.h"
michael@0 17 #include "nsIPresShell.h"
michael@0 18 #include "nsIScrollableFrame.h"
michael@0 19 #include "nsITimer.h"
michael@0 20 #include "nsPresContext.h"
michael@0 21 #include "prtime.h"
michael@0 22 #include "Units.h"
michael@0 23
michael@0 24 namespace mozilla {
michael@0 25
michael@0 26 /******************************************************************/
michael@0 27 /* mozilla::DeltaValues */
michael@0 28 /******************************************************************/
michael@0 29
michael@0 30 DeltaValues::DeltaValues(WidgetWheelEvent* aEvent)
michael@0 31 : deltaX(aEvent->deltaX)
michael@0 32 , deltaY(aEvent->deltaY)
michael@0 33 {
michael@0 34 }
michael@0 35
michael@0 36 /******************************************************************/
michael@0 37 /* mozilla::WheelHandlingUtils */
michael@0 38 /******************************************************************/
michael@0 39
michael@0 40 /* static */ bool
michael@0 41 WheelHandlingUtils::CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax,
michael@0 42 double aDirection)
michael@0 43 {
michael@0 44 return aDirection > 0.0 ? aValue < static_cast<double>(aMax) :
michael@0 45 static_cast<double>(aMin) < aValue;
michael@0 46 }
michael@0 47
michael@0 48 /* static */ bool
michael@0 49 WheelHandlingUtils::CanScrollOn(nsIScrollableFrame* aScrollFrame,
michael@0 50 double aDirectionX, double aDirectionY)
michael@0 51 {
michael@0 52 MOZ_ASSERT(aScrollFrame);
michael@0 53 NS_ASSERTION(aDirectionX || aDirectionY,
michael@0 54 "One of the delta values must be non-zero at least");
michael@0 55
michael@0 56 nsPoint scrollPt = aScrollFrame->GetScrollPosition();
michael@0 57 nsRect scrollRange = aScrollFrame->GetScrollRange();
michael@0 58 uint32_t directions = aScrollFrame->GetPerceivedScrollingDirections();
michael@0 59
michael@0 60 return (aDirectionX && (directions & nsIScrollableFrame::HORIZONTAL) &&
michael@0 61 CanScrollInRange(scrollRange.x, scrollPt.x,
michael@0 62 scrollRange.XMost(), aDirectionX)) ||
michael@0 63 (aDirectionY && (directions & nsIScrollableFrame::VERTICAL) &&
michael@0 64 CanScrollInRange(scrollRange.y, scrollPt.y,
michael@0 65 scrollRange.YMost(), aDirectionY));
michael@0 66 }
michael@0 67
michael@0 68 /******************************************************************/
michael@0 69 /* mozilla::WheelTransaction */
michael@0 70 /******************************************************************/
michael@0 71
michael@0 72 nsWeakFrame WheelTransaction::sTargetFrame(nullptr);
michael@0 73 uint32_t WheelTransaction::sTime = 0;
michael@0 74 uint32_t WheelTransaction::sMouseMoved = 0;
michael@0 75 nsITimer* WheelTransaction::sTimer = nullptr;
michael@0 76 int32_t WheelTransaction::sScrollSeriesCounter = 0;
michael@0 77 bool WheelTransaction::sOwnScrollbars = false;
michael@0 78
michael@0 79 /* static */ bool
michael@0 80 WheelTransaction::OutOfTime(uint32_t aBaseTime, uint32_t aThreshold)
michael@0 81 {
michael@0 82 uint32_t now = PR_IntervalToMilliseconds(PR_IntervalNow());
michael@0 83 return (now - aBaseTime > aThreshold);
michael@0 84 }
michael@0 85
michael@0 86 /* static */ void
michael@0 87 WheelTransaction::OwnScrollbars(bool aOwn)
michael@0 88 {
michael@0 89 sOwnScrollbars = aOwn;
michael@0 90 }
michael@0 91
michael@0 92 /* static */ void
michael@0 93 WheelTransaction::BeginTransaction(nsIFrame* aTargetFrame,
michael@0 94 WidgetWheelEvent* aEvent)
michael@0 95 {
michael@0 96 NS_ASSERTION(!sTargetFrame, "previous transaction is not finished!");
michael@0 97 MOZ_ASSERT(aEvent->message == NS_WHEEL_WHEEL,
michael@0 98 "Transaction must be started with a wheel event");
michael@0 99 ScrollbarsForWheel::OwnWheelTransaction(false);
michael@0 100 sTargetFrame = aTargetFrame;
michael@0 101 sScrollSeriesCounter = 0;
michael@0 102 if (!UpdateTransaction(aEvent)) {
michael@0 103 NS_ERROR("BeginTransaction is called even cannot scroll the frame");
michael@0 104 EndTransaction();
michael@0 105 }
michael@0 106 }
michael@0 107
michael@0 108 /* static */ bool
michael@0 109 WheelTransaction::UpdateTransaction(WidgetWheelEvent* aEvent)
michael@0 110 {
michael@0 111 nsIScrollableFrame* sf = GetTargetFrame()->GetScrollTargetFrame();
michael@0 112 NS_ENSURE_TRUE(sf, false);
michael@0 113
michael@0 114 if (!WheelHandlingUtils::CanScrollOn(sf, aEvent->deltaX, aEvent->deltaY)) {
michael@0 115 OnFailToScrollTarget();
michael@0 116 // We should not modify the transaction state when the view will not be
michael@0 117 // scrolled actually.
michael@0 118 return false;
michael@0 119 }
michael@0 120
michael@0 121 SetTimeout();
michael@0 122
michael@0 123 if (sScrollSeriesCounter != 0 && OutOfTime(sTime, kScrollSeriesTimeout)) {
michael@0 124 sScrollSeriesCounter = 0;
michael@0 125 }
michael@0 126 sScrollSeriesCounter++;
michael@0 127
michael@0 128 // We should use current time instead of WidgetEvent.time.
michael@0 129 // 1. Some events doesn't have the correct creation time.
michael@0 130 // 2. If the computer runs slowly by other processes eating the CPU resource,
michael@0 131 // the event creation time doesn't keep real time.
michael@0 132 sTime = PR_IntervalToMilliseconds(PR_IntervalNow());
michael@0 133 sMouseMoved = 0;
michael@0 134 return true;
michael@0 135 }
michael@0 136
michael@0 137 /* static */ void
michael@0 138 WheelTransaction::MayEndTransaction()
michael@0 139 {
michael@0 140 if (!sOwnScrollbars && ScrollbarsForWheel::IsActive()) {
michael@0 141 ScrollbarsForWheel::OwnWheelTransaction(true);
michael@0 142 } else {
michael@0 143 EndTransaction();
michael@0 144 }
michael@0 145 }
michael@0 146
michael@0 147 /* static */ void
michael@0 148 WheelTransaction::EndTransaction()
michael@0 149 {
michael@0 150 if (sTimer) {
michael@0 151 sTimer->Cancel();
michael@0 152 }
michael@0 153 sTargetFrame = nullptr;
michael@0 154 sScrollSeriesCounter = 0;
michael@0 155 if (sOwnScrollbars) {
michael@0 156 sOwnScrollbars = false;
michael@0 157 ScrollbarsForWheel::OwnWheelTransaction(false);
michael@0 158 ScrollbarsForWheel::Inactivate();
michael@0 159 }
michael@0 160 }
michael@0 161
michael@0 162 /* static */ void
michael@0 163 WheelTransaction::OnEvent(WidgetEvent* aEvent)
michael@0 164 {
michael@0 165 if (!sTargetFrame) {
michael@0 166 return;
michael@0 167 }
michael@0 168
michael@0 169 if (OutOfTime(sTime, GetTimeoutTime())) {
michael@0 170 // Even if the scroll event which is handled after timeout, but onTimeout
michael@0 171 // was not fired by timer, then the scroll event will scroll old frame,
michael@0 172 // therefore, we should call OnTimeout here and ensure to finish the old
michael@0 173 // transaction.
michael@0 174 OnTimeout(nullptr, nullptr);
michael@0 175 return;
michael@0 176 }
michael@0 177
michael@0 178 switch (aEvent->message) {
michael@0 179 case NS_WHEEL_WHEEL:
michael@0 180 if (sMouseMoved != 0 &&
michael@0 181 OutOfTime(sMouseMoved, GetIgnoreMoveDelayTime())) {
michael@0 182 // Terminate the current mousewheel transaction if the mouse moved more
michael@0 183 // than ignoremovedelay milliseconds ago
michael@0 184 EndTransaction();
michael@0 185 }
michael@0 186 return;
michael@0 187 case NS_MOUSE_MOVE:
michael@0 188 case NS_DRAGDROP_OVER: {
michael@0 189 WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
michael@0 190 if (mouseEvent->IsReal()) {
michael@0 191 // If the cursor is moving to be outside the frame,
michael@0 192 // terminate the scrollwheel transaction.
michael@0 193 nsIntPoint pt = GetScreenPoint(mouseEvent);
michael@0 194 nsIntRect r = sTargetFrame->GetScreenRectExternal();
michael@0 195 if (!r.Contains(pt)) {
michael@0 196 EndTransaction();
michael@0 197 return;
michael@0 198 }
michael@0 199
michael@0 200 // If the cursor is moving inside the frame, and it is less than
michael@0 201 // ignoremovedelay milliseconds since the last scroll operation, ignore
michael@0 202 // the mouse move; otherwise, record the current mouse move time to be
michael@0 203 // checked later
michael@0 204 if (!sMouseMoved && OutOfTime(sTime, GetIgnoreMoveDelayTime())) {
michael@0 205 sMouseMoved = PR_IntervalToMilliseconds(PR_IntervalNow());
michael@0 206 }
michael@0 207 }
michael@0 208 return;
michael@0 209 }
michael@0 210 case NS_KEY_PRESS:
michael@0 211 case NS_KEY_UP:
michael@0 212 case NS_KEY_DOWN:
michael@0 213 case NS_MOUSE_BUTTON_UP:
michael@0 214 case NS_MOUSE_BUTTON_DOWN:
michael@0 215 case NS_MOUSE_DOUBLECLICK:
michael@0 216 case NS_MOUSE_CLICK:
michael@0 217 case NS_CONTEXTMENU:
michael@0 218 case NS_DRAGDROP_DROP:
michael@0 219 EndTransaction();
michael@0 220 return;
michael@0 221 }
michael@0 222 }
michael@0 223
michael@0 224 /* static */ void
michael@0 225 WheelTransaction::Shutdown()
michael@0 226 {
michael@0 227 NS_IF_RELEASE(sTimer);
michael@0 228 }
michael@0 229
michael@0 230 /* static */ void
michael@0 231 WheelTransaction::OnFailToScrollTarget()
michael@0 232 {
michael@0 233 NS_PRECONDITION(sTargetFrame, "We don't have mouse scrolling transaction");
michael@0 234
michael@0 235 if (Preferences::GetBool("test.mousescroll", false)) {
michael@0 236 // This event is used for automated tests, see bug 442774.
michael@0 237 nsContentUtils::DispatchTrustedEvent(
michael@0 238 sTargetFrame->GetContent()->OwnerDoc(),
michael@0 239 sTargetFrame->GetContent(),
michael@0 240 NS_LITERAL_STRING("MozMouseScrollFailed"),
michael@0 241 true, true);
michael@0 242 }
michael@0 243 // The target frame might be destroyed in the event handler, at that time,
michael@0 244 // we need to finish the current transaction
michael@0 245 if (!sTargetFrame) {
michael@0 246 EndTransaction();
michael@0 247 }
michael@0 248 }
michael@0 249
michael@0 250 /* static */ void
michael@0 251 WheelTransaction::OnTimeout(nsITimer* aTimer, void* aClosure)
michael@0 252 {
michael@0 253 if (!sTargetFrame) {
michael@0 254 // The transaction target was destroyed already
michael@0 255 EndTransaction();
michael@0 256 return;
michael@0 257 }
michael@0 258 // Store the sTargetFrame, the variable becomes null in EndTransaction.
michael@0 259 nsIFrame* frame = sTargetFrame;
michael@0 260 // We need to finish current transaction before DOM event firing. Because
michael@0 261 // the next DOM event might create strange situation for us.
michael@0 262 MayEndTransaction();
michael@0 263
michael@0 264 if (Preferences::GetBool("test.mousescroll", false)) {
michael@0 265 // This event is used for automated tests, see bug 442774.
michael@0 266 nsContentUtils::DispatchTrustedEvent(
michael@0 267 frame->GetContent()->OwnerDoc(),
michael@0 268 frame->GetContent(),
michael@0 269 NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"),
michael@0 270 true, true);
michael@0 271 }
michael@0 272 }
michael@0 273
michael@0 274 /* static */ void
michael@0 275 WheelTransaction::SetTimeout()
michael@0 276 {
michael@0 277 if (!sTimer) {
michael@0 278 nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
michael@0 279 if (!timer) {
michael@0 280 return;
michael@0 281 }
michael@0 282 timer.swap(sTimer);
michael@0 283 }
michael@0 284 sTimer->Cancel();
michael@0 285 DebugOnly<nsresult> rv =
michael@0 286 sTimer->InitWithFuncCallback(OnTimeout, nullptr, GetTimeoutTime(),
michael@0 287 nsITimer::TYPE_ONE_SHOT);
michael@0 288 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "nsITimer::InitWithFuncCallback failed");
michael@0 289 }
michael@0 290
michael@0 291 /* static */ nsIntPoint
michael@0 292 WheelTransaction::GetScreenPoint(WidgetGUIEvent* aEvent)
michael@0 293 {
michael@0 294 NS_ASSERTION(aEvent, "aEvent is null");
michael@0 295 NS_ASSERTION(aEvent->widget, "aEvent-widget is null");
michael@0 296 return LayoutDeviceIntPoint::ToUntyped(aEvent->refPoint) +
michael@0 297 aEvent->widget->WidgetToScreenOffset();
michael@0 298 }
michael@0 299
michael@0 300 /* static */ uint32_t
michael@0 301 WheelTransaction::GetTimeoutTime()
michael@0 302 {
michael@0 303 return Preferences::GetUint("mousewheel.transaction.timeout", 1500);
michael@0 304 }
michael@0 305
michael@0 306 /* static */ uint32_t
michael@0 307 WheelTransaction::GetIgnoreMoveDelayTime()
michael@0 308 {
michael@0 309 return Preferences::GetUint("mousewheel.transaction.ignoremovedelay", 100);
michael@0 310 }
michael@0 311
michael@0 312 /* static */ DeltaValues
michael@0 313 WheelTransaction::AccelerateWheelDelta(WidgetWheelEvent* aEvent,
michael@0 314 bool aAllowScrollSpeedOverride)
michael@0 315 {
michael@0 316 DeltaValues result(aEvent);
michael@0 317
michael@0 318 // Don't accelerate the delta values if the event isn't line scrolling.
michael@0 319 if (aEvent->deltaMode != nsIDOMWheelEvent::DOM_DELTA_LINE) {
michael@0 320 return result;
michael@0 321 }
michael@0 322
michael@0 323 if (aAllowScrollSpeedOverride) {
michael@0 324 result = OverrideSystemScrollSpeed(aEvent);
michael@0 325 }
michael@0 326
michael@0 327 // Accelerate by the sScrollSeriesCounter
michael@0 328 int32_t start = GetAccelerationStart();
michael@0 329 if (start >= 0 && sScrollSeriesCounter >= start) {
michael@0 330 int32_t factor = GetAccelerationFactor();
michael@0 331 if (factor > 0) {
michael@0 332 result.deltaX = ComputeAcceleratedWheelDelta(result.deltaX, factor);
michael@0 333 result.deltaY = ComputeAcceleratedWheelDelta(result.deltaY, factor);
michael@0 334 }
michael@0 335 }
michael@0 336
michael@0 337 return result;
michael@0 338 }
michael@0 339
michael@0 340 /* static */ double
michael@0 341 WheelTransaction::ComputeAcceleratedWheelDelta(double aDelta,
michael@0 342 int32_t aFactor)
michael@0 343 {
michael@0 344 if (aDelta == 0.0) {
michael@0 345 return 0;
michael@0 346 }
michael@0 347
michael@0 348 return (aDelta * sScrollSeriesCounter * (double)aFactor / 10);
michael@0 349 }
michael@0 350
michael@0 351 /* static */ int32_t
michael@0 352 WheelTransaction::GetAccelerationStart()
michael@0 353 {
michael@0 354 return Preferences::GetInt("mousewheel.acceleration.start", -1);
michael@0 355 }
michael@0 356
michael@0 357 /* static */ int32_t
michael@0 358 WheelTransaction::GetAccelerationFactor()
michael@0 359 {
michael@0 360 return Preferences::GetInt("mousewheel.acceleration.factor", -1);
michael@0 361 }
michael@0 362
michael@0 363 /* static */ DeltaValues
michael@0 364 WheelTransaction::OverrideSystemScrollSpeed(WidgetWheelEvent* aEvent)
michael@0 365 {
michael@0 366 MOZ_ASSERT(sTargetFrame, "We don't have mouse scrolling transaction");
michael@0 367 MOZ_ASSERT(aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE);
michael@0 368
michael@0 369 // If the event doesn't scroll to both X and Y, we don't need to do anything
michael@0 370 // here.
michael@0 371 if (!aEvent->deltaX && !aEvent->deltaY) {
michael@0 372 return DeltaValues(aEvent);
michael@0 373 }
michael@0 374
michael@0 375 // We shouldn't override the scrolling speed on non root scroll frame.
michael@0 376 if (sTargetFrame !=
michael@0 377 sTargetFrame->PresContext()->PresShell()->GetRootScrollFrame()) {
michael@0 378 return DeltaValues(aEvent);
michael@0 379 }
michael@0 380
michael@0 381 // Compute the overridden speed to nsIWidget. The widget can check the
michael@0 382 // conditions (e.g., checking the prefs, and also whether the user customized
michael@0 383 // the system settings of the mouse wheel scrolling or not), and can limit
michael@0 384 // the speed for preventing the unexpected high speed scrolling.
michael@0 385 nsCOMPtr<nsIWidget> widget(sTargetFrame->GetNearestWidget());
michael@0 386 NS_ENSURE_TRUE(widget, DeltaValues(aEvent));
michael@0 387 DeltaValues overriddenDeltaValues(0.0, 0.0);
michael@0 388 nsresult rv =
michael@0 389 widget->OverrideSystemMouseScrollSpeed(aEvent->deltaX, aEvent->deltaY,
michael@0 390 overriddenDeltaValues.deltaX,
michael@0 391 overriddenDeltaValues.deltaY);
michael@0 392 return NS_FAILED(rv) ? DeltaValues(aEvent) : overriddenDeltaValues;
michael@0 393 }
michael@0 394
michael@0 395 /******************************************************************/
michael@0 396 /* mozilla::ScrollbarsForWheel */
michael@0 397 /******************************************************************/
michael@0 398
michael@0 399 const DeltaValues ScrollbarsForWheel::directions[kNumberOfTargets] = {
michael@0 400 DeltaValues(-1, 0), DeltaValues(+1, 0), DeltaValues(0, -1), DeltaValues(0, +1)
michael@0 401 };
michael@0 402
michael@0 403 nsWeakFrame ScrollbarsForWheel::sActiveOwner = nullptr;
michael@0 404 nsWeakFrame ScrollbarsForWheel::sActivatedScrollTargets[kNumberOfTargets] = {
michael@0 405 nullptr, nullptr, nullptr, nullptr
michael@0 406 };
michael@0 407
michael@0 408 bool ScrollbarsForWheel::sHadWheelStart = false;
michael@0 409 bool ScrollbarsForWheel::sOwnWheelTransaction = false;
michael@0 410
michael@0 411 /* static */ void
michael@0 412 ScrollbarsForWheel::PrepareToScrollText(EventStateManager* aESM,
michael@0 413 nsIFrame* aTargetFrame,
michael@0 414 WidgetWheelEvent* aEvent)
michael@0 415 {
michael@0 416 if (aEvent->message == NS_WHEEL_START) {
michael@0 417 WheelTransaction::OwnScrollbars(false);
michael@0 418 if (!IsActive()) {
michael@0 419 TemporarilyActivateAllPossibleScrollTargets(aESM, aTargetFrame, aEvent);
michael@0 420 sHadWheelStart = true;
michael@0 421 }
michael@0 422 } else {
michael@0 423 DeactivateAllTemporarilyActivatedScrollTargets();
michael@0 424 }
michael@0 425 }
michael@0 426
michael@0 427 /* static */ void
michael@0 428 ScrollbarsForWheel::SetActiveScrollTarget(nsIScrollableFrame* aScrollTarget)
michael@0 429 {
michael@0 430 if (!sHadWheelStart) {
michael@0 431 return;
michael@0 432 }
michael@0 433 nsIScrollbarOwner* scrollbarOwner = do_QueryFrame(aScrollTarget);
michael@0 434 if (!scrollbarOwner) {
michael@0 435 return;
michael@0 436 }
michael@0 437 sHadWheelStart = false;
michael@0 438 sActiveOwner = do_QueryFrame(aScrollTarget);
michael@0 439 scrollbarOwner->ScrollbarActivityStarted();
michael@0 440 }
michael@0 441
michael@0 442 /* static */ void
michael@0 443 ScrollbarsForWheel::MayInactivate()
michael@0 444 {
michael@0 445 if (!sOwnWheelTransaction && WheelTransaction::GetTargetFrame()) {
michael@0 446 WheelTransaction::OwnScrollbars(true);
michael@0 447 } else {
michael@0 448 Inactivate();
michael@0 449 }
michael@0 450 }
michael@0 451
michael@0 452 /* static */ void
michael@0 453 ScrollbarsForWheel::Inactivate()
michael@0 454 {
michael@0 455 nsIScrollbarOwner* scrollbarOwner = do_QueryFrame(sActiveOwner);
michael@0 456 if (scrollbarOwner) {
michael@0 457 scrollbarOwner->ScrollbarActivityStopped();
michael@0 458 }
michael@0 459 sActiveOwner = nullptr;
michael@0 460 DeactivateAllTemporarilyActivatedScrollTargets();
michael@0 461 if (sOwnWheelTransaction) {
michael@0 462 sOwnWheelTransaction = false;
michael@0 463 WheelTransaction::OwnScrollbars(false);
michael@0 464 WheelTransaction::EndTransaction();
michael@0 465 }
michael@0 466 }
michael@0 467
michael@0 468 /* static */ bool
michael@0 469 ScrollbarsForWheel::IsActive()
michael@0 470 {
michael@0 471 if (sActiveOwner) {
michael@0 472 return true;
michael@0 473 }
michael@0 474 for (size_t i = 0; i < kNumberOfTargets; ++i) {
michael@0 475 if (sActivatedScrollTargets[i]) {
michael@0 476 return true;
michael@0 477 }
michael@0 478 }
michael@0 479 return false;
michael@0 480 }
michael@0 481
michael@0 482 /* static */ void
michael@0 483 ScrollbarsForWheel::OwnWheelTransaction(bool aOwn)
michael@0 484 {
michael@0 485 sOwnWheelTransaction = aOwn;
michael@0 486 }
michael@0 487
michael@0 488 /* static */ void
michael@0 489 ScrollbarsForWheel::TemporarilyActivateAllPossibleScrollTargets(
michael@0 490 EventStateManager* aESM,
michael@0 491 nsIFrame* aTargetFrame,
michael@0 492 WidgetWheelEvent* aEvent)
michael@0 493 {
michael@0 494 for (size_t i = 0; i < kNumberOfTargets; i++) {
michael@0 495 const DeltaValues *dir = &directions[i];
michael@0 496 nsWeakFrame* scrollTarget = &sActivatedScrollTargets[i];
michael@0 497 MOZ_ASSERT(!*scrollTarget, "scroll target still temporarily activated!");
michael@0 498 nsIScrollableFrame* target =
michael@0 499 aESM->ComputeScrollTarget(aTargetFrame, dir->deltaX, dir->deltaY, aEvent,
michael@0 500 EventStateManager::COMPUTE_DEFAULT_ACTION_TARGET);
michael@0 501 nsIScrollbarOwner* scrollbarOwner = do_QueryFrame(target);
michael@0 502 if (scrollbarOwner) {
michael@0 503 nsIFrame* targetFrame = do_QueryFrame(target);
michael@0 504 *scrollTarget = targetFrame;
michael@0 505 scrollbarOwner->ScrollbarActivityStarted();
michael@0 506 }
michael@0 507 }
michael@0 508 }
michael@0 509
michael@0 510 /* static */ void
michael@0 511 ScrollbarsForWheel::DeactivateAllTemporarilyActivatedScrollTargets()
michael@0 512 {
michael@0 513 for (size_t i = 0; i < kNumberOfTargets; i++) {
michael@0 514 nsWeakFrame* scrollTarget = &sActivatedScrollTargets[i];
michael@0 515 if (*scrollTarget) {
michael@0 516 nsIScrollbarOwner* scrollbarOwner = do_QueryFrame(*scrollTarget);
michael@0 517 if (scrollbarOwner) {
michael@0 518 scrollbarOwner->ScrollbarActivityStopped();
michael@0 519 }
michael@0 520 *scrollTarget = nullptr;
michael@0 521 }
michael@0 522 }
michael@0 523 }
michael@0 524
michael@0 525 } // namespace mozilla

mercurial