gfx/layers/apz/util/ActiveElementManager.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "ActiveElementManager.h"
michael@0 7 #include "mozilla/EventStates.h"
michael@0 8 #include "mozilla/Preferences.h"
michael@0 9 #include "mozilla/Services.h"
michael@0 10 #include "inIDOMUtils.h"
michael@0 11 #include "nsIDOMDocument.h"
michael@0 12 #include "nsIDOMElement.h"
michael@0 13 #include "nsIDOMEventTarget.h"
michael@0 14 #include "base/message_loop.h"
michael@0 15 #include "base/task.h"
michael@0 16
michael@0 17 namespace mozilla {
michael@0 18 namespace layers {
michael@0 19
michael@0 20 static int32_t sActivationDelayMs = 100;
michael@0 21 static bool sActivationDelayMsSet = false;
michael@0 22
michael@0 23 ActiveElementManager::ActiveElementManager()
michael@0 24 : mDomUtils(services::GetInDOMUtils()),
michael@0 25 mCanBePan(false),
michael@0 26 mCanBePanSet(false),
michael@0 27 mSetActiveTask(nullptr)
michael@0 28 {
michael@0 29 if (!sActivationDelayMsSet) {
michael@0 30 Preferences::AddIntVarCache(&sActivationDelayMs,
michael@0 31 "ui.touch_activation.delay_ms",
michael@0 32 sActivationDelayMs);
michael@0 33 sActivationDelayMsSet = true;
michael@0 34 }
michael@0 35 }
michael@0 36
michael@0 37 ActiveElementManager::~ActiveElementManager() {}
michael@0 38
michael@0 39 void
michael@0 40 ActiveElementManager::SetTargetElement(nsIDOMEventTarget* aTarget)
michael@0 41 {
michael@0 42 if (mTarget) {
michael@0 43 // Multiple fingers on screen (since HandleTouchEnd clears mTarget).
michael@0 44 CancelTask();
michael@0 45 ResetActive();
michael@0 46 mTarget = nullptr;
michael@0 47 return;
michael@0 48 }
michael@0 49
michael@0 50 mTarget = do_QueryInterface(aTarget);
michael@0 51 TriggerElementActivation();
michael@0 52 }
michael@0 53
michael@0 54 void
michael@0 55 ActiveElementManager::HandleTouchStart(bool aCanBePan)
michael@0 56 {
michael@0 57 mCanBePan = aCanBePan;
michael@0 58 mCanBePanSet = true;
michael@0 59 TriggerElementActivation();
michael@0 60 }
michael@0 61
michael@0 62 void
michael@0 63 ActiveElementManager::TriggerElementActivation()
michael@0 64 {
michael@0 65 // Both HandleTouchStart() and SetTargetElement() call this. They can be
michael@0 66 // called in either order. One will set mCanBePanSet, and the other, mTarget.
michael@0 67 // We want to actually trigger the activation once both are set.
michael@0 68 if (!(mTarget && mCanBePanSet)) {
michael@0 69 return;
michael@0 70 }
michael@0 71
michael@0 72 // If the touch cannot be a pan, make mTarget :active right away.
michael@0 73 // Otherwise, wait a bit to see if the user will pan or not.
michael@0 74 if (!mCanBePan) {
michael@0 75 SetActive(mTarget);
michael@0 76 } else {
michael@0 77 mSetActiveTask = NewRunnableMethod(
michael@0 78 this, &ActiveElementManager::SetActiveTask, mTarget);
michael@0 79 MessageLoop::current()->PostDelayedTask(
michael@0 80 FROM_HERE, mSetActiveTask, sActivationDelayMs);
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 void
michael@0 85 ActiveElementManager::HandlePanStart()
michael@0 86 {
michael@0 87 // The user started to pan, so we don't want mTarget to be :active.
michael@0 88 // Make it not :active, and clear any pending task to make it :active.
michael@0 89 CancelTask();
michael@0 90 ResetActive();
michael@0 91 }
michael@0 92
michael@0 93 void
michael@0 94 ActiveElementManager::HandleTouchEnd(bool aWasClick)
michael@0 95 {
michael@0 96 // If the touch was a click, make mTarget :active right away.
michael@0 97 // nsEventStateManager will reset the active element when processing
michael@0 98 // the mouse-down event generated by the click.
michael@0 99 CancelTask();
michael@0 100 if (aWasClick) {
michael@0 101 SetActive(mTarget);
michael@0 102 }
michael@0 103
michael@0 104 // Clear mTarget for next touch.
michael@0 105 mTarget = nullptr;
michael@0 106 }
michael@0 107
michael@0 108 void
michael@0 109 ActiveElementManager::SetActive(nsIDOMElement* aTarget)
michael@0 110 {
michael@0 111 if (mDomUtils) {
michael@0 112 mDomUtils->SetContentState(aTarget, NS_EVENT_STATE_ACTIVE.GetInternalValue());;
michael@0 113 }
michael@0 114 }
michael@0 115
michael@0 116 void
michael@0 117 ActiveElementManager::ResetActive()
michael@0 118 {
michael@0 119 // Clear the :active flag from mTarget by setting it on the document root.
michael@0 120 if (mTarget) {
michael@0 121 nsCOMPtr<nsIDOMDocument> doc;
michael@0 122 mTarget->GetOwnerDocument(getter_AddRefs(doc));
michael@0 123 if (doc) {
michael@0 124 nsCOMPtr<nsIDOMElement> root;
michael@0 125 doc->GetDocumentElement(getter_AddRefs(root));
michael@0 126 if (root) {
michael@0 127 SetActive(root);
michael@0 128 }
michael@0 129 }
michael@0 130 }
michael@0 131 }
michael@0 132
michael@0 133 void
michael@0 134 ActiveElementManager::SetActiveTask(nsIDOMElement* aTarget)
michael@0 135 {
michael@0 136 // This gets called from mSetActiveTask's Run() method. The message loop
michael@0 137 // deletes the task right after running it, so we need to null out
michael@0 138 // mSetActiveTask to make sure we're not left with a dangling pointer.
michael@0 139 mSetActiveTask = nullptr;
michael@0 140 SetActive(aTarget);
michael@0 141 }
michael@0 142
michael@0 143 void
michael@0 144 ActiveElementManager::CancelTask()
michael@0 145 {
michael@0 146 if (mSetActiveTask) {
michael@0 147 mSetActiveTask->Cancel();
michael@0 148 mSetActiveTask = nullptr;
michael@0 149 }
michael@0 150 }
michael@0 151
michael@0 152 }
michael@0 153 }

mercurial