2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-15 19:55:36 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2010-09-23 20:28:15 -07:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2010-08-17 01:07:44 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsEventStateManager.h"
|
|
|
|
#include "nsEventListenerManager.h"
|
|
|
|
#include "nsIMEStateManager.h"
|
2009-02-10 12:56:51 -08:00
|
|
|
#include "nsContentEventHandler.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIComboboxControlFrame.h"
|
2009-08-13 13:54:09 -07:00
|
|
|
#include "nsIScrollableFrame.h"
|
2011-10-29 13:03:55 -07:00
|
|
|
#include "nsIDOMHTMLElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULControlElement.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsISelection.h"
|
|
|
|
#include "nsFrameSelection.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2010-02-20 08:07:03 -08:00
|
|
|
#include "nsPIWindowRoot.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsIContentViewer.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-08-25 22:37:02 -07:00
|
|
|
#ifdef MOZ_XUL
|
2007-08-15 18:09:58 -07:00
|
|
|
#include "nsXULPopupManager.h"
|
2007-08-25 22:37:02 -07:00
|
|
|
#endif
|
2010-01-11 13:45:02 -08:00
|
|
|
#include "nsFrameManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
#include "nsFocusManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
2012-08-11 18:42:35 -07:00
|
|
|
#include "nsIDOMWheelEvent.h"
|
2008-08-27 05:07:27 -07:00
|
|
|
#include "nsIDOMDragEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2011-08-26 00:43:49 -07:00
|
|
|
#include "nsIDOMUIEvent.h"
|
2008-08-27 05:07:27 -07:00
|
|
|
#include "nsDOMDragEvent.h"
|
2008-09-25 07:45:03 -07:00
|
|
|
#include "nsIDOMNSEditableElement.h"
|
2012-04-25 09:35:58 -07:00
|
|
|
#include "nsIDOMMozBrowserFrame.h"
|
|
|
|
#include "nsIMozBrowserFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-16 03:52:01 -07:00
|
|
|
#include "nsCaret.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-30 17:49:07 -07:00
|
|
|
#include "nsSubDocumentFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsIProperties.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
|
2007-10-22 14:42:25 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsITimer.h"
|
2011-04-07 18:05:49 -07:00
|
|
|
#include "nsFontMetrics.h"
|
2008-12-30 06:09:14 -08:00
|
|
|
#include "nsIDOMXULDocument.h"
|
2008-08-27 05:07:27 -07:00
|
|
|
#include "nsIDragService.h"
|
|
|
|
#include "nsIDragSession.h"
|
|
|
|
#include "nsDOMDataTransfer.h"
|
|
|
|
#include "nsContentAreaDragDrop.h"
|
|
|
|
#ifdef MOZ_XUL
|
2008-10-27 21:47:19 -07:00
|
|
|
#include "nsTreeBodyFrame.h"
|
2008-08-27 05:07:27 -07:00
|
|
|
#endif
|
2009-08-07 08:11:17 -07:00
|
|
|
#include "nsIController.h"
|
2010-01-10 17:45:45 -08:00
|
|
|
#include "nsICommandParams.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
#include "mozilla/Services.h"
|
2011-03-28 20:32:11 -07:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2012-12-21 06:06:50 -08:00
|
|
|
#include "mozilla/dom/HTMLLabelElement.h"
|
2008-08-27 05:07:27 -07:00
|
|
|
|
2011-05-24 23:31:59 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-09-08 19:27:12 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2013-03-18 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2011-05-24 23:31:59 -07:00
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
#include "nsIDOMClientRect.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_MACOSX
|
2009-09-18 09:34:37 -07:00
|
|
|
#import <ApplicationServices/ApplicationServices.h>
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2011-05-24 23:31:59 -07:00
|
|
|
using namespace mozilla;
|
2010-09-23 20:28:15 -07:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//#define DEBUG_DOCSHELL_FOCUS
|
|
|
|
|
2007-10-22 14:42:25 -07:00
|
|
|
#define NS_USER_INTERACTION_INTERVAL 5000 // ms
|
|
|
|
|
2012-09-30 13:15:29 -07:00
|
|
|
static const nsIntPoint kInvalidRefPoint = nsIntPoint(-1,-1);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sLeftClickOnly = true;
|
|
|
|
static bool sKeyCausesActivation = true;
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t sESMInstanceCount = 0;
|
|
|
|
static int32_t sChromeAccessModifier = 0, sContentAccessModifier = 0;
|
|
|
|
int32_t nsEventStateManager::sUserInputEventDepth = 0;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsEventStateManager::sNormalLMouseEventInProcess = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsEventStateManager* nsEventStateManager::sActiveESM = nullptr;
|
|
|
|
nsIDocument* nsEventStateManager::sMouseOverDocument = nullptr;
|
|
|
|
nsWeakFrame nsEventStateManager::sLastDragOverFrame = nullptr;
|
2012-09-30 13:15:29 -07:00
|
|
|
nsIntPoint nsEventStateManager::sLastRefPoint = kInvalidRefPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
nsIntPoint nsEventStateManager::sLastScreenPoint = nsIntPoint(0,0);
|
2012-09-30 13:15:29 -07:00
|
|
|
nsIntPoint nsEventStateManager::sSynthCenteringPoint = kInvalidRefPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
nsIntPoint nsEventStateManager::sLastClientPoint = nsIntPoint(0,0);
|
|
|
|
bool nsEventStateManager::sIsPointerLocked = false;
|
|
|
|
// Reference to the pointer locked element.
|
|
|
|
nsWeakPtr nsEventStateManager::sPointerLockedElement;
|
|
|
|
// Reference to the document which requested pointer lock.
|
|
|
|
nsWeakPtr nsEventStateManager::sPointerLockedDoc;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsCOMPtr<nsIContent> nsEventStateManager::sDragOverContent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t gMouseOrKeyboardEventCounter = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
static nsITimer* gUserInteractionTimer = nullptr;
|
|
|
|
static nsITimerCallback* gUserInteractionTimerCallback = nullptr;
|
2007-10-22 14:42:25 -07:00
|
|
|
|
2011-09-06 13:14:59 -07:00
|
|
|
TimeStamp nsEventStateManager::sHandlingInputStart;
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
nsEventStateManager::WheelPrefs*
|
|
|
|
nsEventStateManager::WheelPrefs::sInstance = nullptr;
|
2012-08-11 18:42:36 -07:00
|
|
|
nsEventStateManager::DeltaAccumulator*
|
|
|
|
nsEventStateManager::DeltaAccumulator::sInstance = nullptr;
|
2012-08-11 18:42:34 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static inline int32_t
|
2012-08-11 18:42:35 -07:00
|
|
|
RoundDown(double aDouble)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
return (aDouble > 0) ? static_cast<int32_t>(floor(aDouble)) :
|
|
|
|
static_cast<int32_t>(ceil(aDouble));
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static inline bool
|
2010-03-23 20:36:27 -07:00
|
|
|
IsMouseEventReal(nsEvent* aEvent)
|
|
|
|
{
|
2010-05-12 19:33:16 -07:00
|
|
|
NS_ABORT_IF_FALSE(NS_IS_MOUSE_EVENT_STRUCT(aEvent), "Not a mouse event");
|
2010-03-23 20:36:27 -07:00
|
|
|
// Return true if not synthesized.
|
|
|
|
return static_cast<nsMouseEvent*>(aEvent)->reason == nsMouseEvent::eReal;
|
|
|
|
}
|
|
|
|
|
2008-11-02 07:00:05 -08:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
static void
|
|
|
|
PrintDocTree(nsIDocShellTreeItem* aParentItem, int aLevel)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i=0;i<aLevel;i++) printf(" ");
|
2008-11-02 07:00:05 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childWebshellCount;
|
2008-11-02 07:00:05 -08:00
|
|
|
aParentItem->GetChildCount(&childWebshellCount);
|
|
|
|
nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(aParentItem));
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t type;
|
2008-11-02 07:00:05 -08:00
|
|
|
aParentItem->GetItemType(&type);
|
2012-12-28 17:56:42 -08:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = parentAsDocShell->GetPresShell();
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
2008-11-02 07:00:05 -08:00
|
|
|
parentAsDocShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
parentAsDocShell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
if (cv)
|
|
|
|
cv->GetDOMDocument(getter_AddRefs(domDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
2012-07-30 07:20:58 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> domwin = doc ? doc->GetWindow() : nullptr;
|
|
|
|
nsIURI* uri = doc ? doc->GetDocumentURI() : nullptr;
|
2008-11-02 07:00:05 -08:00
|
|
|
|
|
|
|
printf("DS %p Type %s Cnt %d Doc %p DW %p EM %p%c",
|
|
|
|
static_cast<void*>(parentAsDocShell.get()),
|
|
|
|
type==nsIDocShellTreeItem::typeChrome?"Chrome":"Content",
|
|
|
|
childWebshellCount, static_cast<void*>(doc.get()),
|
|
|
|
static_cast<void*>(domwin.get()),
|
2012-07-30 07:20:58 -07:00
|
|
|
static_cast<void*>(presContext ? presContext->EventStateManager() : nullptr),
|
2008-11-02 07:00:05 -08:00
|
|
|
uri ? ' ' : '\n');
|
|
|
|
if (uri) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString spec;
|
2008-11-02 07:00:05 -08:00
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf("\"%s\"\n", spec.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childWebshellCount > 0) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < childWebshellCount; i++) {
|
2008-11-02 07:00:05 -08:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> child;
|
|
|
|
aParentItem->GetChildAt(i, getter_AddRefs(child));
|
|
|
|
PrintDocTree(child, aLevel + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
PrintDocTreeAll(nsIDocShellTreeItem* aItem)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> item = aItem;
|
|
|
|
for(;;) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parent;
|
|
|
|
item->GetParent(getter_AddRefs(parent));
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
item = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrintDocTree(item, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-18 19:30:09 -07:00
|
|
|
class nsUITimerCallback MOZ_FINAL : public nsITimerCallback
|
2007-10-22 14:42:25 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsUITimerCallback() : mPreviousCount(0) {}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
private:
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mPreviousCount;
|
2007-10-22 14:42:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsUITimerCallback, nsITimerCallback)
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
// If aTimer is nullptr, this method always sends "user-interaction-inactive"
|
2007-10-22 14:42:25 -07:00
|
|
|
// notification.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsUITimerCallback::Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (!obs)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-10-22 14:42:25 -07:00
|
|
|
if ((gMouseOrKeyboardEventCounter == mPreviousCount) || !aTimer) {
|
|
|
|
gMouseOrKeyboardEventCounter = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
obs->NotifyObservers(nullptr, "user-interaction-inactive", nullptr);
|
2010-11-07 11:07:59 -08:00
|
|
|
if (gUserInteractionTimer) {
|
|
|
|
gUserInteractionTimer->Cancel();
|
|
|
|
NS_RELEASE(gUserInteractionTimer);
|
|
|
|
}
|
2007-10-22 14:42:25 -07:00
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
obs->NotifyObservers(nullptr, "user-interaction-active", nullptr);
|
2010-11-07 11:07:59 -08:00
|
|
|
nsEventStateManager::UpdateUserActivityTimer();
|
2007-10-22 14:42:25 -07:00
|
|
|
}
|
|
|
|
mPreviousCount = gMouseOrKeyboardEventCounter;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// mask values for ui.key.chromeAccess and ui.key.contentAccess
|
|
|
|
#define NS_MODIFIER_SHIFT 1
|
|
|
|
#define NS_MODIFIER_CONTROL 2
|
|
|
|
#define NS_MODIFIER_ALT 4
|
|
|
|
#define NS_MODIFIER_META 8
|
2012-07-18 18:28:16 -07:00
|
|
|
#define NS_MODIFIER_OS 16
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsIDocument *
|
|
|
|
GetDocumentFromWindow(nsIDOMWindow *aWindow)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aWindow);
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
if (win) {
|
|
|
|
doc = do_QueryInterface(win->GetExtantDocument());
|
|
|
|
}
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t
|
|
|
|
GetAccessModifierMaskFromPref(int32_t aItemType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t accessKey = Preferences::GetInt("ui.key.generalAccessKey", -1);
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (accessKey) {
|
|
|
|
case -1: break; // use the individual prefs
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_SHIFT: return NS_MODIFIER_SHIFT;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL: return NS_MODIFIER_CONTROL;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT: return NS_MODIFIER_ALT;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META: return NS_MODIFIER_META;
|
2012-07-18 18:28:16 -07:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_WIN: return NS_MODIFIER_OS;
|
2007-03-22 10:30:00 -07:00
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aItemType) {
|
|
|
|
case nsIDocShellTreeItem::typeChrome:
|
2011-05-24 23:32:00 -07:00
|
|
|
return Preferences::GetInt("ui.key.chromeAccess", 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsIDocShellTreeItem::typeContent:
|
2011-05-24 23:32:00 -07:00
|
|
|
return Preferences::GetInt("ui.key.contentAccess", 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
struct DeltaValues
|
|
|
|
{
|
|
|
|
DeltaValues() : deltaX(0.0), deltaY(0.0) {}
|
|
|
|
|
|
|
|
DeltaValues(double aDeltaX, double aDeltaY) :
|
|
|
|
deltaX(aDeltaX), deltaY(aDeltaY)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit DeltaValues(widget::WheelEvent* aEvent) :
|
|
|
|
deltaX(aEvent->deltaX), deltaY(aEvent->deltaY)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
double deltaX;
|
|
|
|
double deltaY;
|
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsMouseWheelTransaction {
|
|
|
|
public:
|
|
|
|
static nsIFrame* GetTargetFrame() { return sTargetFrame; }
|
|
|
|
static void BeginTransaction(nsIFrame* aTargetFrame,
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* aEvent);
|
2009-02-17 07:55:53 -08:00
|
|
|
// Be careful, UpdateTransaction may fire a DOM event, therefore, the target
|
|
|
|
// frame might be destroyed in the event handler.
|
2012-08-11 18:42:35 -07:00
|
|
|
static bool UpdateTransaction(widget::WheelEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
static void EndTransaction();
|
|
|
|
static void OnEvent(nsEvent* aEvent);
|
2009-02-12 02:44:38 -08:00
|
|
|
static void Shutdown();
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t GetTimeoutTime();
|
2012-08-11 18:42:35 -07:00
|
|
|
|
|
|
|
|
|
|
|
static DeltaValues AccelerateWheelDelta(widget::WheelEvent* aEvent,
|
|
|
|
bool aAllowScrollSpeedOverride);
|
2009-09-03 00:07:18 -07:00
|
|
|
|
|
|
|
enum {
|
|
|
|
kScrollSeriesTimeout = 80
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2009-01-14 19:27:09 -08:00
|
|
|
static nsIntPoint GetScreenPoint(nsGUIEvent* aEvent);
|
2009-02-12 02:44:38 -08:00
|
|
|
static void OnFailToScrollTarget();
|
|
|
|
static void OnTimeout(nsITimer *aTimer, void *aClosure);
|
|
|
|
static void SetTimeout();
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t GetIgnoreMoveDelayTime();
|
|
|
|
static int32_t GetAccelerationStart();
|
|
|
|
static int32_t GetAccelerationFactor();
|
2012-08-11 18:42:35 -07:00
|
|
|
static DeltaValues OverrideSystemScrollSpeed(widget::WheelEvent* aEvent);
|
2012-08-22 08:56:38 -07:00
|
|
|
static double ComputeAcceleratedWheelDelta(double aDelta, int32_t aFactor);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsWeakFrame sTargetFrame;
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t sTime; // in milliseconds
|
|
|
|
static uint32_t sMouseMoved; // in milliseconds
|
2009-02-12 02:44:38 -08:00
|
|
|
static nsITimer* sTimer;
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t sScrollSeriesCounter;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsWeakFrame nsMouseWheelTransaction::sTargetFrame(nullptr);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t nsMouseWheelTransaction::sTime = 0;
|
|
|
|
uint32_t nsMouseWheelTransaction::sMouseMoved = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsITimer* nsMouseWheelTransaction::sTimer = nullptr;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nsMouseWheelTransaction::sScrollSeriesCounter = 0;
|
2009-09-03 00:07:18 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-08-22 08:56:38 -07:00
|
|
|
OutOfTime(uint32_t aBaseTime, uint32_t aThreshold)
|
2009-09-03 00:07:18 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t now = PR_IntervalToMilliseconds(PR_IntervalNow());
|
2009-09-03 00:07:18 -07:00
|
|
|
return (now - aBaseTime > aThreshold);
|
|
|
|
}
|
2009-02-12 02:44:38 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-08-11 18:42:35 -07:00
|
|
|
CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax, double aDirection)
|
2010-01-11 13:45:02 -08:00
|
|
|
{
|
2012-08-11 18:42:35 -07:00
|
|
|
return aDirection > 0.0 ? aValue < static_cast<double>(aMax) :
|
|
|
|
static_cast<double>(aMin) < aValue;
|
2010-01-11 13:45:02 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-08-11 18:42:35 -07:00
|
|
|
CanScrollOn(nsIScrollableFrame* aScrollFrame, double aDeltaX, double aDeltaY)
|
2009-02-12 02:44:38 -08:00
|
|
|
{
|
2012-08-11 18:42:35 -07:00
|
|
|
MOZ_ASSERT(aScrollFrame);
|
|
|
|
NS_ASSERTION(aDeltaX || aDeltaY,
|
|
|
|
"One of the delta values must be non-zero at least");
|
|
|
|
|
2010-01-11 13:45:02 -08:00
|
|
|
nsPoint scrollPt = aScrollFrame->GetScrollPosition();
|
|
|
|
nsRect scrollRange = aScrollFrame->GetScrollRange();
|
2012-09-23 21:30:33 -07:00
|
|
|
uint32_t directions = aScrollFrame->GetPerceivedScrollingDirections();
|
2010-01-11 13:45:02 -08:00
|
|
|
|
2012-09-23 21:30:33 -07:00
|
|
|
return (aDeltaX && (directions & nsIScrollableFrame::HORIZONTAL) &&
|
2012-09-12 21:13:19 -07:00
|
|
|
CanScrollInRange(scrollRange.x, scrollPt.x, scrollRange.XMost(), aDeltaX)) ||
|
2012-09-23 21:30:33 -07:00
|
|
|
(aDeltaY && (directions & nsIScrollableFrame::VERTICAL) &&
|
2012-09-12 21:13:19 -07:00
|
|
|
CanScrollInRange(scrollRange.y, scrollPt.y, scrollRange.YMost(), aDeltaY));
|
2009-02-12 02:44:38 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::BeginTransaction(nsIFrame* aTargetFrame,
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!sTargetFrame, "previous transaction is not finished!");
|
|
|
|
sTargetFrame = aTargetFrame;
|
2009-09-03 00:07:18 -07:00
|
|
|
sScrollSeriesCounter = 0;
|
2012-08-11 18:42:35 -07:00
|
|
|
if (!UpdateTransaction(aEvent)) {
|
2009-02-12 02:44:38 -08:00
|
|
|
NS_ERROR("BeginTransaction is called even cannot scroll the frame");
|
|
|
|
EndTransaction();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-11 18:42:35 -07:00
|
|
|
nsMouseWheelTransaction::UpdateTransaction(widget::WheelEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-11 13:45:02 -08:00
|
|
|
nsIScrollableFrame* sf = GetTargetFrame()->GetScrollTargetFrame();
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ENSURE_TRUE(sf, false);
|
2009-02-12 02:44:38 -08:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
if (!CanScrollOn(sf, aEvent->deltaX, aEvent->deltaY)) {
|
2009-02-12 02:44:38 -08:00
|
|
|
OnFailToScrollTarget();
|
|
|
|
// We should not modify the transaction state when the view will not be
|
|
|
|
// scrolled actually.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-02-12 02:44:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
SetTimeout();
|
2009-09-03 00:07:18 -07:00
|
|
|
|
|
|
|
if (sScrollSeriesCounter != 0 && OutOfTime(sTime, kScrollSeriesTimeout))
|
|
|
|
sScrollSeriesCounter = 0;
|
|
|
|
sScrollSeriesCounter++;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// We should use current time instead of nsEvent.time.
|
|
|
|
// 1. Some events doesn't have the correct creation time.
|
|
|
|
// 2. If the computer runs slowly by other processes eating the CPU resource,
|
|
|
|
// the event creation time doesn't keep real time.
|
|
|
|
sTime = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
sMouseMoved = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::EndTransaction()
|
|
|
|
{
|
2009-02-12 02:44:38 -08:00
|
|
|
if (sTimer)
|
|
|
|
sTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
sTargetFrame = nullptr;
|
2009-09-03 00:07:18 -07:00
|
|
|
sScrollSeriesCounter = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::OnEvent(nsEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!sTargetFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (OutOfTime(sTime, GetTimeoutTime())) {
|
2009-02-12 02:44:38 -08:00
|
|
|
// Even if the scroll event which is handled after timeout, but onTimeout
|
|
|
|
// was not fired by timer, then the scroll event will scroll old frame,
|
|
|
|
// therefore, we should call OnTimeout here and ensure to finish the old
|
|
|
|
// transaction.
|
2012-07-30 07:20:58 -07:00
|
|
|
OnTimeout(nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_WHEEL_WHEEL:
|
2007-03-22 10:30:00 -07:00
|
|
|
if (sMouseMoved != 0 &&
|
|
|
|
OutOfTime(sMouseMoved, GetIgnoreMoveDelayTime())) {
|
|
|
|
// Terminate the current mousewheel transaction if the mouse moved more
|
|
|
|
// than ignoremovedelay milliseconds ago
|
|
|
|
EndTransaction();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
case NS_DRAGDROP_OVER:
|
2010-03-23 20:36:27 -07:00
|
|
|
if (IsMouseEventReal(aEvent)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the cursor is moving to be outside the frame,
|
|
|
|
// terminate the scrollwheel transaction.
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntPoint pt = GetScreenPoint((nsGUIEvent*)aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIntRect r = sTargetFrame->GetScreenRectExternal();
|
|
|
|
if (!r.Contains(pt)) {
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the cursor is moving inside the frame, and it is less than
|
|
|
|
// ignoremovedelay milliseconds since the last scroll operation, ignore
|
|
|
|
// the mouse move; otherwise, record the current mouse move time to be
|
|
|
|
// checked later
|
|
|
|
if (OutOfTime(sTime, GetIgnoreMoveDelayTime())) {
|
|
|
|
if (sMouseMoved == 0)
|
|
|
|
sMouseMoved = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case NS_KEY_PRESS:
|
|
|
|
case NS_KEY_UP:
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
case NS_MOUSE_BUTTON_UP:
|
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_DOUBLECLICK:
|
|
|
|
case NS_MOUSE_CLICK:
|
|
|
|
case NS_CONTEXTMENU:
|
|
|
|
case NS_DRAGDROP_DROP:
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 02:44:38 -08:00
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::Shutdown()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(sTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::OnFailToScrollTarget()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(sTargetFrame, "We don't have mouse scrolling transaction");
|
2009-05-05 21:30:39 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("test.mousescroll", false)) {
|
2009-05-05 21:30:39 -07:00
|
|
|
// This event is used for automated tests, see bug 442774.
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
2011-10-18 03:53:36 -07:00
|
|
|
sTargetFrame->GetContent()->OwnerDoc(),
|
2009-05-05 21:30:39 -07:00
|
|
|
sTargetFrame->GetContent(),
|
|
|
|
NS_LITERAL_STRING("MozMouseScrollFailed"),
|
2011-10-17 07:59:28 -07:00
|
|
|
true, true);
|
2009-05-05 21:30:39 -07:00
|
|
|
}
|
2009-02-17 07:55:53 -08:00
|
|
|
// The target frame might be destroyed in the event handler, at that time,
|
|
|
|
// we need to finish the current transaction
|
|
|
|
if (!sTargetFrame)
|
|
|
|
EndTransaction();
|
2009-02-12 02:44:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::OnTimeout(nsITimer* aTimer, void* aClosure)
|
|
|
|
{
|
|
|
|
if (!sTargetFrame) {
|
|
|
|
// The transaction target was destroyed already
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Store the sTargetFrame, the variable becomes null in EndTransaction.
|
|
|
|
nsIFrame* frame = sTargetFrame;
|
|
|
|
// We need to finish current transaction before DOM event firing. Because
|
|
|
|
// the next DOM event might create strange situation for us.
|
|
|
|
EndTransaction();
|
2009-05-05 21:30:39 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("test.mousescroll", false)) {
|
2009-05-05 21:30:39 -07:00
|
|
|
// This event is used for automated tests, see bug 442774.
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
2011-10-18 03:53:36 -07:00
|
|
|
frame->GetContent()->OwnerDoc(),
|
2009-05-05 21:30:39 -07:00
|
|
|
frame->GetContent(),
|
|
|
|
NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"),
|
2011-10-17 07:59:28 -07:00
|
|
|
true, true);
|
2009-05-05 21:30:39 -07:00
|
|
|
}
|
2009-02-12 02:44:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::SetTimeout()
|
|
|
|
{
|
|
|
|
if (!sTimer) {
|
|
|
|
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
|
|
|
if (!timer)
|
|
|
|
return;
|
|
|
|
timer.swap(sTimer);
|
|
|
|
}
|
|
|
|
sTimer->Cancel();
|
2011-04-14 05:04:12 -07:00
|
|
|
#ifdef DEBUG
|
2009-02-12 02:44:38 -08:00
|
|
|
nsresult rv =
|
2011-04-14 05:04:12 -07:00
|
|
|
#endif
|
2012-07-30 07:20:58 -07:00
|
|
|
sTimer->InitWithFuncCallback(OnTimeout, nullptr, GetTimeoutTime(),
|
2011-04-14 05:04:12 -07:00
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2009-02-12 02:44:38 -08:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "nsITimer::InitWithFuncCallback failed");
|
|
|
|
}
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntPoint
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseWheelTransaction::GetScreenPoint(nsGUIEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent, "aEvent is null");
|
|
|
|
NS_ASSERTION(aEvent->widget, "aEvent-widget is null");
|
2009-02-18 16:11:49 -08:00
|
|
|
return aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseWheelTransaction::GetTimeoutTime()
|
|
|
|
{
|
2011-05-24 23:32:00 -07:00
|
|
|
return Preferences::GetUint("mousewheel.transaction.timeout", 1500);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseWheelTransaction::GetIgnoreMoveDelayTime()
|
|
|
|
{
|
2011-05-24 23:32:00 -07:00
|
|
|
return Preferences::GetUint("mousewheel.transaction.ignoremovedelay", 100);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
DeltaValues
|
|
|
|
nsMouseWheelTransaction::AccelerateWheelDelta(widget::WheelEvent* aEvent,
|
|
|
|
bool aAllowScrollSpeedOverride)
|
2009-09-03 00:07:18 -07:00
|
|
|
{
|
2012-08-11 18:42:35 -07:00
|
|
|
DeltaValues result(aEvent);
|
|
|
|
|
|
|
|
// Don't accelerate the delta values if the event isn't line scrolling.
|
|
|
|
if (aEvent->deltaMode != nsIDOMWheelEvent::DOM_DELTA_LINE) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2009-09-24 03:58:04 -07:00
|
|
|
if (aAllowScrollSpeedOverride) {
|
2012-08-11 18:42:35 -07:00
|
|
|
result = OverrideSystemScrollSpeed(aEvent);
|
2009-09-24 03:58:04 -07:00
|
|
|
}
|
2009-09-03 00:07:18 -07:00
|
|
|
|
2009-09-24 03:58:04 -07:00
|
|
|
// Accelerate by the sScrollSeriesCounter
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t start = GetAccelerationStart();
|
2009-09-24 03:58:04 -07:00
|
|
|
if (start >= 0 && sScrollSeriesCounter >= start) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t factor = GetAccelerationFactor();
|
2009-09-24 03:58:04 -07:00
|
|
|
if (factor > 0) {
|
2012-08-11 18:42:35 -07:00
|
|
|
result.deltaX = ComputeAcceleratedWheelDelta(result.deltaX, factor);
|
|
|
|
result.deltaY = ComputeAcceleratedWheelDelta(result.deltaY, factor);
|
2009-09-24 03:58:04 -07:00
|
|
|
}
|
|
|
|
}
|
2009-09-03 00:07:18 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
return result;
|
2009-09-03 00:07:18 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
double
|
|
|
|
nsMouseWheelTransaction::ComputeAcceleratedWheelDelta(double aDelta,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aFactor)
|
2009-09-03 00:07:18 -07:00
|
|
|
{
|
2012-08-11 18:42:35 -07:00
|
|
|
if (aDelta == 0.0) {
|
2009-09-03 00:07:18 -07:00
|
|
|
return 0;
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
2009-09-03 00:07:18 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
return (aDelta * sScrollSeriesCounter * (double)aFactor / 10);
|
2009-09-03 00:07:18 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2009-09-03 00:07:18 -07:00
|
|
|
nsMouseWheelTransaction::GetAccelerationStart()
|
|
|
|
{
|
2011-05-24 23:32:00 -07:00
|
|
|
return Preferences::GetInt("mousewheel.acceleration.start", -1);
|
2009-09-03 00:07:18 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2009-09-03 00:07:18 -07:00
|
|
|
nsMouseWheelTransaction::GetAccelerationFactor()
|
|
|
|
{
|
2011-05-24 23:32:00 -07:00
|
|
|
return Preferences::GetInt("mousewheel.acceleration.factor", -1);
|
2009-09-03 00:07:18 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
DeltaValues
|
|
|
|
nsMouseWheelTransaction::OverrideSystemScrollSpeed(widget::WheelEvent* aEvent)
|
2009-09-24 03:58:04 -07:00
|
|
|
{
|
2012-08-11 18:42:35 -07:00
|
|
|
MOZ_ASSERT(sTargetFrame, "We don't have mouse scrolling transaction");
|
|
|
|
MOZ_ASSERT(aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE);
|
2009-09-24 03:58:04 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
// If the event doesn't scroll to both X and Y, we don't need to do anything
|
2013-03-15 02:03:16 -07:00
|
|
|
// here.
|
|
|
|
if (!aEvent->deltaX && !aEvent->deltaY) {
|
|
|
|
return DeltaValues(aEvent);
|
2009-09-24 03:58:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// We shouldn't override the scrolling speed on non root scroll frame.
|
|
|
|
if (sTargetFrame !=
|
|
|
|
sTargetFrame->PresContext()->PresShell()->GetRootScrollFrame()) {
|
2013-03-15 02:03:16 -07:00
|
|
|
return DeltaValues(aEvent);
|
2009-09-24 03:58:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the overridden speed to nsIWidget. The widget can check the
|
|
|
|
// conditions (e.g., checking the prefs, and also whether the user customized
|
|
|
|
// the system settings of the mouse wheel scrolling or not), and can limit
|
|
|
|
// the speed for preventing the unexpected high speed scrolling.
|
2010-07-02 12:11:04 -07:00
|
|
|
nsCOMPtr<nsIWidget> widget(sTargetFrame->GetNearestWidget());
|
2013-03-15 02:03:16 -07:00
|
|
|
NS_ENSURE_TRUE(widget, DeltaValues(aEvent));
|
|
|
|
DeltaValues overriddenDeltaValues(0.0, 0.0);
|
|
|
|
nsresult rv =
|
|
|
|
widget->OverrideSystemMouseScrollSpeed(aEvent->deltaX, aEvent->deltaY,
|
|
|
|
overriddenDeltaValues.deltaX,
|
|
|
|
overriddenDeltaValues.deltaY);
|
|
|
|
return NS_FAILED(rv) ? DeltaValues(aEvent) : overriddenDeltaValues;
|
2009-09-24 03:58:04 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/******************************************************************/
|
|
|
|
/* nsEventStateManager */
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
nsEventStateManager::nsEventStateManager()
|
|
|
|
: mLockCursor(0),
|
2012-04-11 14:55:21 -07:00
|
|
|
mPreLockPoint(0,0),
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentTarget(nullptr),
|
|
|
|
mLastMouseOverFrame(nullptr),
|
2007-03-22 10:30:00 -07:00
|
|
|
// init d&d gesture state machine variables
|
|
|
|
mGestureDownPoint(0,0),
|
2012-07-30 07:20:58 -07:00
|
|
|
mPresContext(nullptr),
|
2007-03-22 10:30:00 -07:00
|
|
|
mLClickCount(0),
|
|
|
|
mMClickCount(0),
|
|
|
|
mRClickCount(0),
|
2011-10-17 07:59:28 -07:00
|
|
|
m_haveShutdown(false),
|
|
|
|
mClickHoldContextMenu(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-10-22 14:42:25 -07:00
|
|
|
if (sESMInstanceCount == 0) {
|
|
|
|
gUserInteractionTimerCallback = new nsUITimerCallback();
|
2010-11-07 11:07:59 -08:00
|
|
|
if (gUserInteractionTimerCallback)
|
2007-10-22 14:42:25 -07:00
|
|
|
NS_ADDREF(gUserInteractionTimerCallback);
|
2010-11-07 11:07:59 -08:00
|
|
|
UpdateUserActivityTimer();
|
2007-10-22 14:42:25 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
++sESMInstanceCount;
|
|
|
|
}
|
|
|
|
|
2010-11-07 11:07:59 -08:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::UpdateUserActivityTimer(void)
|
|
|
|
{
|
|
|
|
if (!gUserInteractionTimerCallback)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!gUserInteractionTimer)
|
|
|
|
CallCreateInstance("@mozilla.org/timer;1", &gUserInteractionTimer);
|
|
|
|
|
|
|
|
if (gUserInteractionTimer) {
|
|
|
|
gUserInteractionTimer->InitWithCallback(gUserInteractionTimerCallback,
|
|
|
|
NS_USER_INTERACTION_INTERVAL,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-28 16:39:27 -07:00
|
|
|
static const char* kObservedPrefs[] = {
|
|
|
|
"accessibility.accesskeycausesactivation",
|
|
|
|
"nglayout.events.dispatchLeftClickOnly",
|
|
|
|
"ui.key.generalAccessKey",
|
|
|
|
"ui.key.chromeAccess",
|
|
|
|
"ui.key.contentAccess",
|
|
|
|
"ui.click_hold_context_menus",
|
|
|
|
"dom.popup_allowed_events",
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr
|
2011-05-28 16:39:27 -07:00
|
|
|
};
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStateManager::Init()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (!observerService)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-28 16:39:27 -07:00
|
|
|
if (sESMInstanceCount == 1) {
|
2011-06-03 12:38:24 -07:00
|
|
|
sKeyCausesActivation =
|
|
|
|
Preferences::GetBool("accessibility.accesskeycausesactivation",
|
|
|
|
sKeyCausesActivation);
|
2011-05-28 16:39:27 -07:00
|
|
|
sLeftClickOnly =
|
|
|
|
Preferences::GetBool("nglayout.events.dispatchLeftClickOnly",
|
|
|
|
sLeftClickOnly);
|
|
|
|
sChromeAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeChrome);
|
|
|
|
sContentAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeContent);
|
|
|
|
}
|
2011-05-28 16:39:27 -07:00
|
|
|
Preferences::AddWeakObservers(this, kObservedPrefs);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-16 00:36:11 -07:00
|
|
|
mClickHoldContextMenu =
|
2011-09-28 23:19:26 -07:00
|
|
|
Preferences::GetBool("ui.click_hold_context_menus", false);
|
2010-06-16 00:36:11 -07:00
|
|
|
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStateManager::~nsEventStateManager()
|
|
|
|
{
|
2010-09-16 06:10:18 -07:00
|
|
|
if (sActiveESM == this) {
|
2012-07-30 07:20:58 -07:00
|
|
|
sActiveESM = nullptr;
|
2010-09-16 06:10:18 -07:00
|
|
|
}
|
2010-06-16 00:36:11 -07:00
|
|
|
if (mClickHoldContextMenu)
|
|
|
|
KillClickHoldTimer();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-09-17 11:56:53 -07:00
|
|
|
if (mDocument == sMouseOverDocument)
|
2012-07-30 07:20:58 -07:00
|
|
|
sMouseOverDocument = nullptr;
|
2010-09-17 11:56:53 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
--sESMInstanceCount;
|
|
|
|
if(sESMInstanceCount == 0) {
|
2009-02-12 02:44:38 -08:00
|
|
|
nsMouseWheelTransaction::Shutdown();
|
2007-10-22 14:42:25 -07:00
|
|
|
if (gUserInteractionTimerCallback) {
|
2012-07-30 07:20:58 -07:00
|
|
|
gUserInteractionTimerCallback->Notify(nullptr);
|
2007-10-22 14:42:25 -07:00
|
|
|
NS_RELEASE(gUserInteractionTimerCallback);
|
|
|
|
}
|
|
|
|
if (gUserInteractionTimer) {
|
|
|
|
gUserInteractionTimer->Cancel();
|
|
|
|
NS_RELEASE(gUserInteractionTimer);
|
|
|
|
}
|
2012-08-11 18:42:34 -07:00
|
|
|
WheelPrefs::Shutdown();
|
2012-08-11 18:42:36 -07:00
|
|
|
DeltaAccumulator::Shutdown();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-18 03:53:36 -07:00
|
|
|
if (sDragOverContent && sDragOverContent->OwnerDoc() == mDocument) {
|
2012-07-30 07:20:58 -07:00
|
|
|
sDragOverContent = nullptr;
|
2011-09-26 13:55:04 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!m_haveShutdown) {
|
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
// Don't remove from Observer service in Shutdown because Shutdown also
|
|
|
|
// gets called from xpcom shutdown observer. And we don't want to remove
|
|
|
|
// from the service in that case.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
2007-03-22 10:30:00 -07:00
|
|
|
observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::Shutdown()
|
|
|
|
{
|
2011-05-28 16:39:27 -07:00
|
|
|
Preferences::RemoveObservers(this, kObservedPrefs);
|
2011-10-17 07:59:28 -07:00
|
|
|
m_haveShutdown = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *someData)
|
|
|
|
{
|
|
|
|
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
|
|
|
|
Shutdown();
|
|
|
|
else if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
|
|
|
if (!someData)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsDependentString data(someData);
|
|
|
|
if (data.EqualsLiteral("accessibility.accesskeycausesactivation")) {
|
|
|
|
sKeyCausesActivation =
|
2011-05-24 23:31:59 -07:00
|
|
|
Preferences::GetBool("accessibility.accesskeycausesactivation",
|
|
|
|
sKeyCausesActivation);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (data.EqualsLiteral("nglayout.events.dispatchLeftClickOnly")) {
|
|
|
|
sLeftClickOnly =
|
2011-05-24 23:31:59 -07:00
|
|
|
Preferences::GetBool("nglayout.events.dispatchLeftClickOnly",
|
|
|
|
sLeftClickOnly);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (data.EqualsLiteral("ui.key.generalAccessKey")) {
|
|
|
|
sChromeAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeChrome);
|
|
|
|
sContentAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeContent);
|
|
|
|
} else if (data.EqualsLiteral("ui.key.chromeAccess")) {
|
|
|
|
sChromeAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeChrome);
|
|
|
|
} else if (data.EqualsLiteral("ui.key.contentAccess")) {
|
|
|
|
sContentAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeContent);
|
2010-06-16 00:36:11 -07:00
|
|
|
} else if (data.EqualsLiteral("ui.click_hold_context_menus")) {
|
|
|
|
mClickHoldContextMenu =
|
2011-09-28 23:19:26 -07:00
|
|
|
Preferences::GetBool("ui.click_hold_context_menus", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (data.EqualsLiteral("dom.popup_allowed_events")) {
|
|
|
|
nsDOMEvent::PopupAllowedEventsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-10 14:25:24 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsEventStateManager)
|
2011-04-21 10:35:52 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
|
2007-08-10 14:25:24 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 03:11:31 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsEventStateManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsEventStateManager)
|
2007-08-10 14:25:24 -07:00
|
|
|
|
2013-04-02 09:48:59 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_17(nsEventStateManager,
|
|
|
|
mCurrentTargetContent,
|
|
|
|
mLastMouseOverElement,
|
|
|
|
mGestureDownContent,
|
|
|
|
mGestureDownFrameOwner,
|
|
|
|
mLastLeftMouseDownContent,
|
|
|
|
mLastLeftMouseDownContentParent,
|
|
|
|
mLastMiddleMouseDownContent,
|
|
|
|
mLastMiddleMouseDownContentParent,
|
|
|
|
mLastRightMouseDownContent,
|
|
|
|
mLastRightMouseDownContentParent,
|
|
|
|
mActiveContent,
|
|
|
|
mHoverContent,
|
|
|
|
mURLTargetContent,
|
|
|
|
mFirstMouseOverEventElement,
|
|
|
|
mFirstMouseOutEventElement,
|
|
|
|
mDocument,
|
|
|
|
mAccessKeys)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
|
|
|
|
nsEvent *aEvent,
|
|
|
|
nsIFrame* aTargetFrame,
|
2011-11-21 09:53:20 -08:00
|
|
|
nsEventStatus* aStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aStatus);
|
|
|
|
NS_ENSURE_ARG(aPresContext);
|
|
|
|
if (!aEvent) {
|
|
|
|
NS_ERROR("aEvent is null. This should never happen.");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrentTarget = aTargetFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentTargetContent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Focus events don't necessarily need a frame.
|
|
|
|
if (NS_EVENT_NEEDS_FRAME(aEvent)) {
|
|
|
|
NS_ASSERTION(mCurrentTarget, "mCurrentTarget is null. this should not happen. see bug #13007");
|
|
|
|
if (!mCurrentTarget) return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2012-04-11 14:55:21 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (NS_IS_DRAG_EVENT(aEvent) && sIsPointerLocked) {
|
|
|
|
NS_ASSERTION(sIsPointerLocked,
|
|
|
|
"sIsPointerLocked is true. Drag events should be suppressed when the pointer is locked.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// Store last known screenPoint and clientPoint so pointer lock
|
|
|
|
// can use these values as constants.
|
2012-12-15 17:26:03 -08:00
|
|
|
if (aEvent->mFlags.mIsTrusted &&
|
2012-04-16 14:29:14 -07:00
|
|
|
((NS_IS_MOUSE_EVENT_STRUCT(aEvent) &&
|
2012-04-11 14:55:21 -07:00
|
|
|
IsMouseEventReal(aEvent)) ||
|
2012-08-11 18:42:34 -07:00
|
|
|
aEvent->eventStructType == NS_WHEEL_EVENT)) {
|
2012-04-11 14:55:21 -07:00
|
|
|
if (!sIsPointerLocked) {
|
|
|
|
sLastScreenPoint = nsDOMUIEvent::CalculateScreenPoint(aPresContext, aEvent);
|
2012-07-30 07:20:58 -07:00
|
|
|
sLastClientPoint = nsDOMUIEvent::CalculateClientPoint(aPresContext, aEvent, nullptr);
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-10-22 14:42:25 -07:00
|
|
|
// Do not take account NS_MOUSE_ENTER/EXIT so that loading a page
|
|
|
|
// when user is not active doesn't change the state to active.
|
2012-12-15 17:26:03 -08:00
|
|
|
if (aEvent->mFlags.mIsTrusted &&
|
2007-10-22 14:42:25 -07:00
|
|
|
((aEvent->eventStructType == NS_MOUSE_EVENT &&
|
2010-03-23 20:36:27 -07:00
|
|
|
IsMouseEventReal(aEvent) &&
|
2007-10-22 14:42:25 -07:00
|
|
|
aEvent->message != NS_MOUSE_ENTER &&
|
|
|
|
aEvent->message != NS_MOUSE_EXIT) ||
|
2012-08-11 18:42:34 -07:00
|
|
|
aEvent->eventStructType == NS_WHEEL_EVENT ||
|
2007-10-22 14:42:25 -07:00
|
|
|
aEvent->eventStructType == NS_KEY_EVENT)) {
|
|
|
|
if (gMouseOrKeyboardEventCounter == 0) {
|
|
|
|
nsCOMPtr<nsIObserverService> obs =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
mozilla::services::GetObserverService();
|
2007-10-22 14:42:25 -07:00
|
|
|
if (obs) {
|
2012-07-30 07:20:58 -07:00
|
|
|
obs->NotifyObservers(nullptr, "user-interaction-active", nullptr);
|
2010-11-07 11:07:59 -08:00
|
|
|
UpdateUserActivityTimer();
|
2007-10-22 14:42:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++gMouseOrKeyboardEventCounter;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
nsMouseWheelTransaction::OnEvent(aEvent);
|
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
2007-07-08 00:08:04 -07:00
|
|
|
switch (static_cast<nsMouseEvent*>(aEvent)->button) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsMouseEvent::eLeftButton:
|
|
|
|
#ifndef XP_OS2
|
2010-06-16 00:36:11 -07:00
|
|
|
BeginTrackingDragGesture(aPresContext, (nsMouseEvent*)aEvent, aTargetFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
mLClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
2011-10-17 07:59:28 -07:00
|
|
|
sNormalLMouseEventInProcess = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case nsMouseEvent::eMiddleButton:
|
|
|
|
mMClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
|
|
|
case nsMouseEvent::eRightButton:
|
|
|
|
#ifdef XP_OS2
|
2010-06-16 00:36:11 -07:00
|
|
|
BeginTrackingDragGesture(aPresContext, (nsMouseEvent*)aEvent, aTargetFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
mRClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_BUTTON_UP:
|
2007-07-08 00:08:04 -07:00
|
|
|
switch (static_cast<nsMouseEvent*>(aEvent)->button) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case nsMouseEvent::eLeftButton:
|
2010-06-16 00:36:11 -07:00
|
|
|
if (mClickHoldContextMenu) {
|
|
|
|
KillClickHoldTimer();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifndef XP_OS2
|
2010-06-16 00:36:11 -07:00
|
|
|
StopTrackingDragGesture();
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
sNormalLMouseEventInProcess = false;
|
2010-12-19 16:46:00 -08:00
|
|
|
// then fall through...
|
2010-06-16 00:36:11 -07:00
|
|
|
case nsMouseEvent::eRightButton:
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef XP_OS2
|
2010-06-16 00:36:11 -07:00
|
|
|
StopTrackingDragGesture();
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2010-12-19 16:46:00 -08:00
|
|
|
// then fall through...
|
2010-06-16 00:36:11 -07:00
|
|
|
case nsMouseEvent::eMiddleButton:
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_EXIT:
|
2008-03-12 15:44:45 -07:00
|
|
|
// If the event is not a top-level window exit, then it's not
|
|
|
|
// really an exit --- we may have traversed widget boundaries but
|
2007-03-22 10:30:00 -07:00
|
|
|
// we're still in our toplevel window.
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsMouseEvent* mouseEvent = static_cast<nsMouseEvent*>(aEvent);
|
2008-03-12 15:44:45 -07:00
|
|
|
if (mouseEvent->exit != nsMouseEvent::eTopLevel) {
|
2008-04-23 15:51:27 -07:00
|
|
|
// Treat it as a synthetic move so we don't generate spurious
|
|
|
|
// "exit" or "move" events. Any necessary "out" or "over" events
|
|
|
|
// will be generated by GenerateMouseEnterExit
|
|
|
|
mouseEvent->message = NS_MOUSE_MOVE;
|
|
|
|
mouseEvent->reason = nsMouseEvent::eSynthesized;
|
2007-03-22 10:30:00 -07:00
|
|
|
// then fall through...
|
|
|
|
} else {
|
|
|
|
GenerateMouseEnterExit((nsGUIEvent*)aEvent);
|
|
|
|
//This is a window level mouse exit event and should stop here
|
|
|
|
aEvent->message = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
// on the Mac, GenerateDragGesture() may not return until the drag
|
|
|
|
// has completed and so |aTargetFrame| may have been deleted (moving
|
|
|
|
// a bookmark, for example). If this is the case, however, we know
|
|
|
|
// that ClearFrameRefs() has been called and it cleared out
|
|
|
|
// |mCurrentTarget|. As a result, we should pass |mCurrentTarget|
|
|
|
|
// into UpdateCursor().
|
|
|
|
GenerateDragGesture(aPresContext, (nsMouseEvent*)aEvent);
|
|
|
|
UpdateCursor(aPresContext, aEvent, mCurrentTarget, aStatus);
|
|
|
|
GenerateMouseEnterExit((nsGUIEvent*)aEvent);
|
2011-12-23 19:52:26 -08:00
|
|
|
// Flush pending layout changes, so that later mouse move events
|
|
|
|
// will go to the right nodes.
|
|
|
|
FlushPendingEvents(aPresContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_DRAGDROP_GESTURE:
|
2010-06-16 00:36:11 -07:00
|
|
|
if (mClickHoldContextMenu) {
|
|
|
|
// an external drag gesture event came in, not generated internally
|
|
|
|
// by Gecko. Make sure we get rid of the click-hold timer.
|
|
|
|
KillClickHoldTimer();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_DRAGDROP_OVER:
|
2008-08-27 05:07:27 -07:00
|
|
|
// NS_DRAGDROP_DROP is fired before NS_DRAGDROP_DRAGDROP so send
|
|
|
|
// the enter/exit events before NS_DRAGDROP_DROP.
|
2007-03-22 10:30:00 -07:00
|
|
|
GenerateDragDropEnterExit(aPresContext, (nsGUIEvent*)aEvent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_KEY_PRESS:
|
|
|
|
{
|
|
|
|
|
|
|
|
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t modifierMask = 0;
|
2012-04-24 20:00:02 -07:00
|
|
|
if (keyEvent->IsShift())
|
2007-03-22 10:30:00 -07:00
|
|
|
modifierMask |= NS_MODIFIER_SHIFT;
|
2012-04-24 20:00:02 -07:00
|
|
|
if (keyEvent->IsControl())
|
2007-03-22 10:30:00 -07:00
|
|
|
modifierMask |= NS_MODIFIER_CONTROL;
|
2012-04-24 20:00:02 -07:00
|
|
|
if (keyEvent->IsAlt())
|
2007-03-22 10:30:00 -07:00
|
|
|
modifierMask |= NS_MODIFIER_ALT;
|
2012-04-24 20:00:02 -07:00
|
|
|
if (keyEvent->IsMeta())
|
2007-03-22 10:30:00 -07:00
|
|
|
modifierMask |= NS_MODIFIER_META;
|
2012-07-18 18:28:16 -07:00
|
|
|
if (keyEvent->IsOS())
|
|
|
|
modifierMask |= NS_MODIFIER_OS;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Prevent keyboard scrolling while an accesskey modifier is in use.
|
|
|
|
if (modifierMask && (modifierMask == sChromeAccessModifier ||
|
|
|
|
modifierMask == sContentAccessModifier))
|
2012-07-30 07:20:58 -07:00
|
|
|
HandleAccessKey(aPresContext, keyEvent, aStatus, nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
eAccessKeyProcessingNormal, modifierMask);
|
|
|
|
}
|
2010-12-19 16:46:00 -08:00
|
|
|
// then fall through...
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_KEY_DOWN:
|
|
|
|
case NS_KEY_UP:
|
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIContent* content = GetFocusedContent();
|
|
|
|
if (content)
|
|
|
|
mCurrentTargetContent = content;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
2012-08-11 18:42:35 -07:00
|
|
|
case NS_WHEEL_WHEEL:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
NS_ASSERTION(aEvent->mFlags.mIsTrusted,
|
2012-08-11 18:42:35 -07:00
|
|
|
"Untrusted wheel event shouldn't be here");
|
2012-08-11 18:42:35 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIContent* content = GetFocusedContent();
|
|
|
|
if (content)
|
|
|
|
mCurrentTargetContent = content;
|
2008-09-17 04:27:19 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* wheelEvent = static_cast<widget::WheelEvent*>(aEvent);
|
|
|
|
WheelPrefs::GetInstance()->ApplyUserPrefsToDelta(wheelEvent);
|
2012-08-11 18:42:36 -07:00
|
|
|
|
2012-08-16 18:32:15 -07:00
|
|
|
// If we won't dispatch a DOM event for this event, nothing to do anymore.
|
|
|
|
if (!NS_IsAllowedToDispatchDOMEvent(wheelEvent)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:36 -07:00
|
|
|
// Init lineOrPageDelta values for line scroll events for some devices
|
|
|
|
// on some platforms which might dispatch wheel events which don't have
|
|
|
|
// lineOrPageDelta values. And also, if delta values are customized by
|
|
|
|
// prefs, this recomputes them.
|
|
|
|
DeltaAccumulator::GetInstance()->
|
|
|
|
InitLineOrPageDelta(aTargetFrame, this, wheelEvent);
|
2008-09-17 04:27:19 -07:00
|
|
|
}
|
|
|
|
break;
|
2008-02-19 23:40:04 -08:00
|
|
|
case NS_QUERY_SELECTED_TEXT:
|
2011-09-22 02:17:40 -07:00
|
|
|
DoQuerySelectedText(static_cast<nsQueryContentEvent*>(aEvent));
|
2008-02-19 23:40:04 -08:00
|
|
|
break;
|
|
|
|
case NS_QUERY_TEXT_CONTENT:
|
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
if (RemoteQueryContentEvent(aEvent))
|
|
|
|
break;
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
2008-02-19 23:40:04 -08:00
|
|
|
handler.OnQueryTextContent((nsQueryContentEvent*)aEvent);
|
|
|
|
}
|
|
|
|
break;
|
2009-02-10 12:56:51 -08:00
|
|
|
case NS_QUERY_CARET_RECT:
|
2009-02-10 03:15:36 -08:00
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
// XXX remote event
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryCaretRect((nsQueryContentEvent*)aEvent);
|
2009-02-10 03:15:36 -08:00
|
|
|
}
|
|
|
|
break;
|
2009-02-10 12:56:51 -08:00
|
|
|
case NS_QUERY_TEXT_RECT:
|
2009-02-10 03:15:36 -08:00
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
// XXX remote event
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryTextRect((nsQueryContentEvent*)aEvent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_QUERY_EDITOR_RECT:
|
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
// XXX remote event
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryEditorRect((nsQueryContentEvent*)aEvent);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-17 19:04:01 -07:00
|
|
|
case NS_QUERY_CONTENT_STATE:
|
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
// XXX remote event
|
2009-03-17 19:04:01 -07:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryContentState(static_cast<nsQueryContentEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_QUERY_SELECTION_AS_TRANSFERABLE:
|
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
// XXX remote event
|
2009-03-17 19:04:01 -07:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQuerySelectionAsTransferable(static_cast<nsQueryContentEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2009-05-14 17:46:24 -07:00
|
|
|
case NS_QUERY_CHARACTER_AT_POINT:
|
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
// XXX remote event
|
2009-05-14 17:46:24 -07:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryCharacterAtPoint(static_cast<nsQueryContentEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2011-03-01 13:15:23 -08:00
|
|
|
case NS_QUERY_DOM_WIDGET_HITTEST:
|
|
|
|
{
|
|
|
|
// XXX remote event
|
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryDOMWidgetHittest(static_cast<nsQueryContentEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2009-02-10 12:56:51 -08:00
|
|
|
case NS_SELECTION_SET:
|
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
nsSelectionEvent *selectionEvent =
|
|
|
|
static_cast<nsSelectionEvent*>(aEvent);
|
|
|
|
if (IsTargetCrossProcess(selectionEvent)) {
|
|
|
|
// Will not be handled locally, remote the event
|
|
|
|
if (GetCrossProcessTarget()->SendSelectionEvent(*selectionEvent))
|
2011-10-17 07:59:28 -07:00
|
|
|
selectionEvent->mSucceeded = true;
|
2010-09-23 20:28:15 -07:00
|
|
|
break;
|
|
|
|
}
|
2009-02-10 12:56:51 -08:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnSelectionEvent((nsSelectionEvent*)aEvent);
|
2008-02-19 23:40:04 -08:00
|
|
|
}
|
|
|
|
break;
|
2009-08-07 08:11:17 -07:00
|
|
|
case NS_CONTENT_COMMAND_CUT:
|
|
|
|
case NS_CONTENT_COMMAND_COPY:
|
|
|
|
case NS_CONTENT_COMMAND_PASTE:
|
|
|
|
case NS_CONTENT_COMMAND_DELETE:
|
|
|
|
case NS_CONTENT_COMMAND_UNDO:
|
|
|
|
case NS_CONTENT_COMMAND_REDO:
|
2010-01-10 17:45:45 -08:00
|
|
|
case NS_CONTENT_COMMAND_PASTE_TRANSFERABLE:
|
2009-08-07 08:11:17 -07:00
|
|
|
{
|
|
|
|
DoContentCommandEvent(static_cast<nsContentCommandEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2010-03-10 21:25:29 -08:00
|
|
|
case NS_CONTENT_COMMAND_SCROLL:
|
|
|
|
{
|
|
|
|
DoContentCommandScrollEvent(static_cast<nsContentCommandEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2010-08-17 01:07:44 -07:00
|
|
|
case NS_TEXT_TEXT:
|
|
|
|
{
|
|
|
|
nsTextEvent *textEvent = static_cast<nsTextEvent*>(aEvent);
|
|
|
|
if (IsTargetCrossProcess(textEvent)) {
|
|
|
|
// Will not be handled locally, remote the event
|
2010-09-23 20:28:15 -07:00
|
|
|
if (GetCrossProcessTarget()->SendTextEvent(*textEvent)) {
|
2010-08-17 01:07:44 -07:00
|
|
|
// Cancel local dispatching
|
2012-12-15 17:26:03 -08:00
|
|
|
aEvent->mFlags.mPropagationStopped = true;
|
2010-08-17 01:07:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_COMPOSITION_START:
|
2012-12-15 17:26:03 -08:00
|
|
|
if (aEvent->mFlags.mIsTrusted) {
|
2011-09-22 02:17:40 -07:00
|
|
|
// If the event is trusted event, set the selected text to data of
|
|
|
|
// composition event.
|
|
|
|
nsCompositionEvent *compositionEvent =
|
|
|
|
static_cast<nsCompositionEvent*>(aEvent);
|
2011-10-17 07:59:28 -07:00
|
|
|
nsQueryContentEvent selectedText(true, NS_QUERY_SELECTED_TEXT,
|
2011-09-22 02:17:40 -07:00
|
|
|
compositionEvent->widget);
|
|
|
|
DoQuerySelectedText(&selectedText);
|
|
|
|
NS_ASSERTION(selectedText.mSucceeded, "Failed to get selected text");
|
|
|
|
compositionEvent->data = selectedText.mReply.mString;
|
|
|
|
}
|
|
|
|
// through to compositionend handling
|
2011-09-22 02:17:40 -07:00
|
|
|
case NS_COMPOSITION_UPDATE:
|
2010-08-17 01:07:44 -07:00
|
|
|
case NS_COMPOSITION_END:
|
|
|
|
{
|
|
|
|
nsCompositionEvent *compositionEvent =
|
|
|
|
static_cast<nsCompositionEvent*>(aEvent);
|
|
|
|
if (IsTargetCrossProcess(compositionEvent)) {
|
|
|
|
// Will not be handled locally, remote the event
|
2010-09-23 20:28:15 -07:00
|
|
|
if (GetCrossProcessTarget()->SendCompositionEvent(*compositionEvent)) {
|
2010-08-17 01:07:44 -07:00
|
|
|
// Cancel local dispatching
|
2012-12-15 17:26:03 -08:00
|
|
|
aEvent->mFlags.mPropagationStopped = true;
|
2010-08-17 01:07:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
GetAccessModifierMask(nsISupports* aDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(aDocShell));
|
|
|
|
if (!treeItem)
|
|
|
|
return -1; // invalid modifier
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t itemType;
|
2007-03-22 10:30:00 -07:00
|
|
|
treeItem->GetItemType(&itemType);
|
|
|
|
switch (itemType) {
|
|
|
|
|
|
|
|
case nsIDocShellTreeItem::typeChrome:
|
|
|
|
return sChromeAccessModifier;
|
|
|
|
|
|
|
|
case nsIDocShellTreeItem::typeContent:
|
|
|
|
return sContentAccessModifier;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1; // invalid modifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2008-04-14 21:16:24 -07:00
|
|
|
IsAccessKeyTarget(nsIContent* aContent, nsIFrame* aFrame, nsAString& aKey)
|
2007-11-28 12:14:12 -08:00
|
|
|
{
|
2012-12-13 14:08:44 -08:00
|
|
|
// Use GetAttr because we want Unicode case=insensitive matching
|
|
|
|
// XXXbz shouldn't this be case-sensitive, per spec?
|
|
|
|
nsString contentKey;
|
|
|
|
if (!aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, contentKey) ||
|
|
|
|
!contentKey.Equals(aKey, nsCaseInsensitiveStringComparator()))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-11-28 12:14:12 -08:00
|
|
|
|
2008-12-30 06:09:14 -08:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc =
|
2011-10-18 03:53:36 -07:00
|
|
|
do_QueryInterface(aContent->OwnerDoc());
|
2009-08-24 13:02:07 -07:00
|
|
|
if (!xulDoc && !aContent->IsXUL())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-12-30 06:09:14 -08:00
|
|
|
|
|
|
|
// For XUL we do visibility checks.
|
|
|
|
if (!aFrame)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-11-28 12:14:12 -08:00
|
|
|
|
|
|
|
if (aFrame->IsFocusable())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-11-28 12:14:12 -08:00
|
|
|
|
2011-10-26 16:57:55 -07:00
|
|
|
if (!aFrame->IsVisibleConsideringAncestors())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-11-28 12:14:12 -08:00
|
|
|
|
2008-12-30 06:09:14 -08:00
|
|
|
// XUL controls can be activated.
|
2007-11-28 12:14:12 -08:00
|
|
|
nsCOMPtr<nsIDOMXULControlElement> control(do_QueryInterface(aContent));
|
|
|
|
if (control)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-11-28 12:14:12 -08:00
|
|
|
|
2009-08-24 13:02:07 -07:00
|
|
|
if (aContent->IsHTML()) {
|
2008-05-08 13:00:24 -07:00
|
|
|
nsIAtom* tag = aContent->Tag();
|
|
|
|
|
|
|
|
// HTML area, label and legend elements are never focusable, so
|
|
|
|
// we need to check for them explicitly before giving up.
|
|
|
|
if (tag == nsGkAtoms::area ||
|
|
|
|
tag == nsGkAtoms::label ||
|
|
|
|
tag == nsGkAtoms::legend)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-07-10 05:17:15 -07:00
|
|
|
|
2009-08-24 13:02:07 -07:00
|
|
|
} else if (aContent->IsXUL()) {
|
2009-07-10 05:17:15 -07:00
|
|
|
// XUL label elements are never focusable, so we need to check for them
|
|
|
|
// explicitly before giving up.
|
|
|
|
if (aContent->Tag() == nsGkAtoms::label)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-05-08 13:00:24 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-11-28 12:14:12 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsEventStateManager::ExecuteAccessKey(nsTArray<uint32_t>& aAccessCharCodes,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsTrustedEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count, start = -1;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIContent* focusedContent = GetFocusedContent();
|
|
|
|
if (focusedContent) {
|
|
|
|
start = mAccessKeys.IndexOf(focusedContent);
|
|
|
|
if (start == -1 && focusedContent->GetBindingParent())
|
|
|
|
start = mAccessKeys.IndexOf(focusedContent->GetBindingParent());
|
2008-04-14 21:16:24 -07:00
|
|
|
}
|
|
|
|
nsIContent *content;
|
|
|
|
nsIFrame *frame;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t length = mAccessKeys.Count();
|
|
|
|
for (uint32_t i = 0; i < aAccessCharCodes.Length(); ++i) {
|
|
|
|
uint32_t ch = aAccessCharCodes[i];
|
2008-04-14 21:16:24 -07:00
|
|
|
nsAutoString accessKey;
|
|
|
|
AppendUCS4ToUTF16(ch, accessKey);
|
2007-11-28 12:14:12 -08:00
|
|
|
for (count = 1; count <= length; ++count) {
|
|
|
|
content = mAccessKeys[(start + count) % length];
|
2009-12-24 13:20:05 -08:00
|
|
|
frame = content->GetPrimaryFrame();
|
2008-04-14 21:16:24 -07:00
|
|
|
if (IsAccessKeyTarget(content, frame, accessKey)) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shouldActivate = sKeyCausesActivation;
|
2007-11-28 12:14:12 -08:00
|
|
|
while (shouldActivate && ++count <= length) {
|
|
|
|
nsIContent *oc = mAccessKeys[(start + count) % length];
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame *of = oc->GetPrimaryFrame();
|
2008-04-14 21:16:24 -07:00
|
|
|
if (IsAccessKeyTarget(oc, of, accessKey))
|
2011-10-17 07:59:28 -07:00
|
|
|
shouldActivate = false;
|
2007-11-28 12:14:12 -08:00
|
|
|
}
|
|
|
|
if (shouldActivate)
|
2008-04-14 21:16:24 -07:00
|
|
|
content->PerformAccesskey(shouldActivate, aIsTrustedEvent);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
else {
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(content);
|
|
|
|
fm->SetFocus(element, nsIFocusManager::FLAG_BYKEY);
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-11-28 12:14:12 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-04-14 21:16:24 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-07-31 12:43:54 -07:00
|
|
|
nsEventStateManager::GetAccessKeyLabelPrefix(nsAString& aPrefix)
|
|
|
|
{
|
|
|
|
aPrefix.Truncate();
|
|
|
|
nsAutoString separator, modifierText;
|
|
|
|
nsContentUtils::GetModifierSeparatorText(separator);
|
|
|
|
|
2011-08-06 01:24:48 -07:00
|
|
|
nsCOMPtr<nsISupports> container = mPresContext->GetContainer();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t modifier = GetAccessModifierMask(container);
|
2011-07-31 12:43:54 -07:00
|
|
|
|
|
|
|
if (modifier & NS_MODIFIER_CONTROL) {
|
|
|
|
nsContentUtils::GetControlText(modifierText);
|
|
|
|
aPrefix.Append(modifierText + separator);
|
|
|
|
}
|
|
|
|
if (modifier & NS_MODIFIER_META) {
|
|
|
|
nsContentUtils::GetMetaText(modifierText);
|
|
|
|
aPrefix.Append(modifierText + separator);
|
|
|
|
}
|
2012-07-18 18:28:16 -07:00
|
|
|
if (modifier & NS_MODIFIER_OS) {
|
|
|
|
nsContentUtils::GetOSText(modifierText);
|
|
|
|
aPrefix.Append(modifierText + separator);
|
|
|
|
}
|
2011-07-31 12:43:54 -07:00
|
|
|
if (modifier & NS_MODIFIER_ALT) {
|
|
|
|
nsContentUtils::GetAltText(modifierText);
|
|
|
|
aPrefix.Append(modifierText + separator);
|
|
|
|
}
|
|
|
|
if (modifier & NS_MODIFIER_SHIFT) {
|
|
|
|
nsContentUtils::GetShiftText(modifierText);
|
|
|
|
aPrefix.Append(modifierText + separator);
|
|
|
|
}
|
|
|
|
return !aPrefix.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::HandleAccessKey(nsPresContext* aPresContext,
|
|
|
|
nsKeyEvent *aEvent,
|
|
|
|
nsEventStatus* aStatus,
|
|
|
|
nsIDocShellTreeItem* aBubbledFrom,
|
|
|
|
ProcessingAccessKeyState aAccessKeyState,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModifierMask)
|
2008-04-14 21:16:24 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> pcContainer = aPresContext->GetContainer();
|
|
|
|
|
|
|
|
// Alt or other accesskey modifier is down, we may need to do an accesskey
|
|
|
|
if (mAccessKeys.Count() > 0 &&
|
|
|
|
aModifierMask == GetAccessModifierMask(pcContainer)) {
|
|
|
|
// Someone registered an accesskey. Find and activate it.
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAutoTArray<uint32_t, 10> accessCharCodes;
|
2008-04-14 21:16:24 -07:00
|
|
|
nsContentUtils::GetAccessKeyCandidates(aEvent, accessCharCodes);
|
2012-12-15 17:26:03 -08:00
|
|
|
if (ExecuteAccessKey(accessCharCodes, aEvent->mFlags.mIsTrusted)) {
|
2008-04-14 21:16:24 -07:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// after the local accesskey handling
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
// checking all sub docshells
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShell(do_QueryInterface(pcContainer));
|
|
|
|
if (!docShell) {
|
|
|
|
NS_WARNING("no docShellTreeNode for presContext");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t childCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
docShell->GetChildCount(&childCount);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t counter = 0; counter < childCount; counter++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Not processing the child which bubbles up the handling
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> subShellItem;
|
|
|
|
docShell->GetChildAt(counter, getter_AddRefs(subShellItem));
|
2007-05-17 20:49:14 -07:00
|
|
|
if (aAccessKeyState == eAccessKeyProcessingUp &&
|
|
|
|
subShellItem == aBubbledFrom)
|
|
|
|
continue;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDocShell> subDS = do_QueryInterface(subShellItem);
|
|
|
|
if (subDS && IsShellVisible(subDS)) {
|
2012-12-28 17:56:42 -08:00
|
|
|
nsCOMPtr<nsIPresShell> subPS = subDS->GetPresShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Docshells need not have a presshell (eg. display:none
|
|
|
|
// iframes, docshells in transition between documents, etc).
|
|
|
|
if (!subPS) {
|
|
|
|
// Oh, well. Just move on to the next child
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext *subPC = subPS->GetPresContext();
|
|
|
|
|
|
|
|
nsEventStateManager* esm =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsEventStateManager *>(subPC->EventStateManager());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (esm)
|
2012-07-30 07:20:58 -07:00
|
|
|
esm->HandleAccessKey(subPC, aEvent, aStatus, nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
eAccessKeyProcessingDown, aModifierMask);
|
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aStatus)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}// if end . checking all sub docshell ends here.
|
|
|
|
|
2007-05-17 20:49:14 -07:00
|
|
|
// bubble up the process to the parent docshell if necessary
|
2007-03-22 10:30:00 -07:00
|
|
|
if (eAccessKeyProcessingDown != aAccessKeyState && nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(pcContainer));
|
|
|
|
if (!docShell) {
|
2007-05-17 20:49:14 -07:00
|
|
|
NS_WARNING("no docShellTreeItem for presContext");
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentShellItem;
|
|
|
|
docShell->GetParent(getter_AddRefs(parentShellItem));
|
|
|
|
nsCOMPtr<nsIDocShell> parentDS = do_QueryInterface(parentShellItem);
|
|
|
|
if (parentDS) {
|
2012-12-28 17:56:42 -08:00
|
|
|
nsCOMPtr<nsIPresShell> parentPS = parentDS->GetPresShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(parentPS, "Our PresShell exists but the parent's does not?");
|
|
|
|
|
|
|
|
nsPresContext *parentPC = parentPS->GetPresContext();
|
|
|
|
NS_ASSERTION(parentPC, "PresShell without PresContext");
|
|
|
|
|
|
|
|
nsEventStateManager* esm =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsEventStateManager *>(parentPC->EventStateManager());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (esm)
|
2007-05-17 20:49:14 -07:00
|
|
|
esm->HandleAccessKey(parentPC, aEvent, aStatus, docShell,
|
2007-03-22 10:30:00 -07:00
|
|
|
eAccessKeyProcessingUp, aModifierMask);
|
|
|
|
}
|
|
|
|
}// if end. bubble up process
|
|
|
|
}// end of HandleAccessKey
|
|
|
|
|
2012-07-15 19:58:43 -07:00
|
|
|
bool
|
|
|
|
nsEventStateManager::DispatchCrossProcessEvent(nsEvent* aEvent,
|
2012-07-18 12:43:06 -07:00
|
|
|
nsFrameLoader* aFrameLoader,
|
2012-07-15 19:58:43 -07:00
|
|
|
nsEventStatus *aStatus) {
|
2012-07-18 12:43:06 -07:00
|
|
|
PBrowserParent* remoteBrowser = aFrameLoader->GetRemoteBrowser();
|
2011-06-21 17:32:43 -07:00
|
|
|
TabParent* remote = static_cast<TabParent*>(remoteBrowser);
|
|
|
|
if (!remote) {
|
2012-07-15 19:58:43 -07:00
|
|
|
return false;
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
|
|
|
|
2012-07-15 19:58:43 -07:00
|
|
|
switch (aEvent->eventStructType) {
|
|
|
|
case NS_MOUSE_EVENT: {
|
2011-06-21 17:32:43 -07:00
|
|
|
nsMouseEvent* mouseEvent = static_cast<nsMouseEvent*>(aEvent);
|
2012-07-15 19:58:43 -07:00
|
|
|
return remote->SendRealMouseEvent(*mouseEvent);
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
2012-07-15 19:58:43 -07:00
|
|
|
case NS_KEY_EVENT: {
|
2011-06-21 17:32:43 -07:00
|
|
|
nsKeyEvent* keyEvent = static_cast<nsKeyEvent*>(aEvent);
|
2012-07-15 19:58:43 -07:00
|
|
|
return remote->SendRealKeyEvent(*keyEvent);
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
2012-08-11 18:42:34 -07:00
|
|
|
case NS_WHEEL_EVENT: {
|
|
|
|
widget::WheelEvent* wheelEvent = static_cast<widget::WheelEvent*>(aEvent);
|
|
|
|
return remote->SendMouseWheelEvent(*wheelEvent);
|
|
|
|
}
|
2012-07-15 19:58:43 -07:00
|
|
|
case NS_TOUCH_EVENT: {
|
|
|
|
// Let the child process synthesize a mouse event if needed, and
|
|
|
|
// ensure we don't synthesize one in this process.
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
|
|
|
|
return remote->SendRealTouchEvent(*touchEvent);
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
MOZ_NOT_REACHED("Attempt to send non-whitelisted event?");
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-06-21 17:32:43 -07:00
|
|
|
nsEventStateManager::IsRemoteTarget(nsIContent* target) {
|
2012-04-25 09:35:58 -07:00
|
|
|
if (!target) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// <browser/iframe remote=true> from XUL
|
|
|
|
if ((target->Tag() == nsGkAtoms::browser ||
|
|
|
|
target->Tag() == nsGkAtoms::iframe) &&
|
|
|
|
target->IsXUL() &&
|
|
|
|
target->AttrValueIs(kNameSpaceID_None, nsGkAtoms::Remote,
|
|
|
|
nsGkAtoms::_true, eIgnoreCase)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
// <frame/iframe mozbrowser/mozapp>
|
2012-04-25 09:35:58 -07:00
|
|
|
nsCOMPtr<nsIMozBrowserFrame> browserFrame = do_QueryInterface(target);
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
if (browserFrame && browserFrame->GetReallyIsBrowserOrApp()) {
|
|
|
|
return !!TabParent::GetFrom(target);
|
2012-04-25 09:35:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
|
|
|
|
2012-09-11 13:05:52 -07:00
|
|
|
/*static*/ void
|
|
|
|
nsEventStateManager::MapEventCoordinatesForChildProcess(nsFrameLoader* aFrameLoader,
|
|
|
|
nsEvent* aEvent)
|
|
|
|
{
|
|
|
|
// The "toplevel widget" in child processes is always at position
|
|
|
|
// 0,0. Map the event coordinates to match that.
|
|
|
|
nsIFrame* targetFrame = aFrameLoader->GetPrimaryFrameOfOwningContent();
|
|
|
|
if (!targetFrame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsPresContext* presContext = targetFrame->PresContext();
|
|
|
|
|
|
|
|
if (aEvent->eventStructType != NS_TOUCH_EVENT) {
|
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
|
|
|
|
targetFrame);
|
|
|
|
aEvent->refPoint = pt.ToNearestPixels(presContext->AppUnitsPerDevPixel());
|
|
|
|
} else {
|
|
|
|
aEvent->refPoint = nsIntPoint();
|
|
|
|
// Find out how far we're offset from the nearest widget.
|
|
|
|
nsPoint offset =
|
|
|
|
nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, targetFrame);
|
|
|
|
nsIntPoint intOffset =
|
|
|
|
offset.ToNearestPixels(presContext->AppUnitsPerDevPixel());
|
|
|
|
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
|
|
|
|
// Then offset all the touch points by that distance, to put them
|
|
|
|
// in the space where top-left is 0,0.
|
|
|
|
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
|
|
|
nsIDOMTouch* touch = touches[i];
|
|
|
|
if (touch) {
|
|
|
|
touch->mRefPoint += intOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-07-15 19:58:43 -07:00
|
|
|
CrossProcessSafeEvent(const nsEvent& aEvent)
|
|
|
|
{
|
|
|
|
switch (aEvent.eventStructType) {
|
|
|
|
case NS_KEY_EVENT:
|
2012-08-11 18:42:34 -07:00
|
|
|
case NS_WHEEL_EVENT:
|
2012-07-15 19:58:43 -07:00
|
|
|
return true;
|
|
|
|
case NS_MOUSE_EVENT:
|
|
|
|
switch (aEvent.message) {
|
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_BUTTON_UP:
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
return true;
|
2012-07-16 15:19:00 -07:00
|
|
|
default:
|
|
|
|
return false;
|
2012-07-15 19:58:43 -07:00
|
|
|
}
|
|
|
|
case NS_TOUCH_EVENT:
|
|
|
|
switch (aEvent.message) {
|
|
|
|
case NS_TOUCH_START:
|
|
|
|
case NS_TOUCH_MOVE:
|
|
|
|
case NS_TOUCH_END:
|
|
|
|
case NS_TOUCH_CANCEL:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return false;
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
2012-07-15 19:58:43 -07:00
|
|
|
}
|
2012-07-16 15:19:00 -07:00
|
|
|
|
2012-07-15 19:58:43 -07:00
|
|
|
bool
|
|
|
|
nsEventStateManager::HandleCrossProcessEvent(nsEvent *aEvent,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsEventStatus *aStatus) {
|
2011-06-21 17:32:43 -07:00
|
|
|
if (*aStatus == nsEventStatus_eConsumeNoDefault ||
|
2012-12-15 17:26:05 -08:00
|
|
|
aEvent->mFlags.mNoCrossProcessBoundaryForwarding ||
|
2012-07-15 19:58:43 -07:00
|
|
|
!CrossProcessSafeEvent(*aEvent)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
|
|
|
|
2012-07-15 19:58:43 -07:00
|
|
|
// Collect the remote event targets we're going to forward this
|
|
|
|
// event to.
|
|
|
|
//
|
|
|
|
// NB: the elements of |targets| must be unique, for correctness.
|
|
|
|
nsAutoTArray<nsCOMPtr<nsIContent>, 1> targets;
|
|
|
|
if (aEvent->eventStructType != NS_TOUCH_EVENT ||
|
|
|
|
aEvent->message == NS_TOUCH_START) {
|
|
|
|
// If this event only has one target, and it's remote, add it to
|
|
|
|
// the array.
|
|
|
|
nsIContent* target = mCurrentTargetContent;
|
|
|
|
if (!target && aTargetFrame) {
|
|
|
|
target = aTargetFrame->GetContent();
|
|
|
|
}
|
|
|
|
if (IsRemoteTarget(target)) {
|
|
|
|
targets.AppendElement(target);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is a touch event with possibly multiple touch points.
|
|
|
|
// Each touch point may have its own target. So iterate through
|
|
|
|
// all of them and collect the unique set of targets for event
|
|
|
|
// forwarding.
|
|
|
|
//
|
|
|
|
// This loop is similar to the one used in
|
|
|
|
// PresShell::DispatchTouchEvent().
|
|
|
|
nsTouchEvent* touchEvent = static_cast<nsTouchEvent*>(aEvent);
|
|
|
|
const nsTArray<nsCOMPtr<nsIDOMTouch> >& touches = touchEvent->touches;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < touches.Length(); ++i) {
|
2012-07-15 19:58:43 -07:00
|
|
|
nsIDOMTouch* touch = touches[i];
|
|
|
|
// NB: the |mChanged| check is an optimization, subprocesses can
|
|
|
|
// compute this for themselves. If the touch hasn't changed, we
|
|
|
|
// may be able to avoid forwarding the event entirely (which is
|
|
|
|
// not free).
|
|
|
|
if (!touch || !touch->mChanged) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-04-05 17:44:26 -07:00
|
|
|
nsCOMPtr<EventTarget> targetPtr = touch->GetTarget();
|
2012-07-15 19:58:43 -07:00
|
|
|
if (!targetPtr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> target = do_QueryInterface(targetPtr);
|
|
|
|
if (IsRemoteTarget(target) && !targets.Contains(target)) {
|
|
|
|
targets.AppendElement(target);
|
|
|
|
}
|
|
|
|
}
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 12:43:06 -07:00
|
|
|
if (targets.Length() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-15 19:58:43 -07:00
|
|
|
// Look up the frame loader for all the remote targets we found, and
|
|
|
|
// then dispatch the event to the remote content they represent.
|
|
|
|
bool dispatched = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < targets.Length(); ++i) {
|
2012-07-15 19:58:43 -07:00
|
|
|
nsIContent* target = targets[i];
|
|
|
|
nsCOMPtr<nsIFrameLoaderOwner> loaderOwner = do_QueryInterface(target);
|
|
|
|
if (!loaderOwner) {
|
2012-07-18 12:43:06 -07:00
|
|
|
continue;
|
2012-07-15 19:58:43 -07:00
|
|
|
}
|
2011-06-21 17:32:43 -07:00
|
|
|
|
2012-07-15 19:58:43 -07:00
|
|
|
nsRefPtr<nsFrameLoader> frameLoader = loaderOwner->GetFrameLoader();
|
|
|
|
if (!frameLoader) {
|
2012-07-18 12:43:06 -07:00
|
|
|
continue;
|
2012-07-15 19:58:43 -07:00
|
|
|
}
|
2011-06-21 17:32:43 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t eventMode;
|
2012-07-15 19:58:43 -07:00
|
|
|
frameLoader->GetEventMode(&eventMode);
|
|
|
|
if (eventMode == nsIFrameLoader::EVENT_MODE_DONT_FORWARD_TO_CHILD) {
|
2012-07-18 12:43:06 -07:00
|
|
|
continue;
|
2012-07-15 19:58:43 -07:00
|
|
|
}
|
2011-06-21 17:32:43 -07:00
|
|
|
|
2012-09-11 13:05:52 -07:00
|
|
|
MapEventCoordinatesForChildProcess(frameLoader, aEvent);
|
2012-07-15 19:58:43 -07:00
|
|
|
|
|
|
|
dispatched |= DispatchCrossProcessEvent(aEvent, frameLoader, aStatus);
|
|
|
|
}
|
|
|
|
return dispatched;
|
2011-06-21 17:32:43 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// CreateClickHoldTimer
|
|
|
|
//
|
|
|
|
// Fire off a timer for determining if the user wants click-hold. This timer
|
|
|
|
// is a one-shot that will be cancelled when the user moves enough to fire
|
|
|
|
// a drag.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager::CreateClickHoldTimer(nsPresContext* inPresContext,
|
|
|
|
nsIFrame* inDownFrame,
|
|
|
|
nsGUIEvent* inMouseDownEvent)
|
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
if (!inMouseDownEvent->mFlags.mIsTrusted)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
// just to be anal (er, safe)
|
|
|
|
if (mClickHoldTimer) {
|
|
|
|
mClickHoldTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mClickHoldTimer = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// if content clicked on has a popup, don't even start the timer
|
|
|
|
// since we'll end up conflicting and both will show.
|
|
|
|
if (mGestureDownContent) {
|
|
|
|
// check for the |popup| attribute
|
|
|
|
if (nsContentUtils::HasNonEmptyAttr(mGestureDownContent, kNameSpaceID_None,
|
|
|
|
nsGkAtoms::popup))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// check for a <menubutton> like bookmarks
|
|
|
|
if (mGestureDownContent->Tag() == nsGkAtoms::menubutton)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mClickHoldTimer = do_CreateInstance("@mozilla.org/timer;1");
|
2010-06-16 00:36:11 -07:00
|
|
|
if (mClickHoldTimer) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t clickHoldDelay =
|
2011-05-24 23:32:00 -07:00
|
|
|
Preferences::GetInt("ui.click_hold_context_menus.delay", 500);
|
2007-03-22 10:30:00 -07:00
|
|
|
mClickHoldTimer->InitWithFuncCallback(sClickHoldCallback, this,
|
2010-06-16 00:36:11 -07:00
|
|
|
clickHoldDelay,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2010-06-16 00:36:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} // CreateClickHoldTimer
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// KillClickHoldTimer
|
|
|
|
//
|
|
|
|
// Stop the timer that would show the context menu dead in its tracks
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager::KillClickHoldTimer()
|
|
|
|
{
|
|
|
|
if (mClickHoldTimer) {
|
|
|
|
mClickHoldTimer->Cancel();
|
2012-07-30 07:20:58 -07:00
|
|
|
mClickHoldTimer = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// sClickHoldCallback
|
|
|
|
//
|
|
|
|
// This fires after the mouse has been down for a certain length of time.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager::sClickHoldCallback(nsITimer *aTimer, void* aESM)
|
|
|
|
{
|
2013-01-24 13:19:15 -08:00
|
|
|
nsRefPtr<nsEventStateManager> self = static_cast<nsEventStateManager*>(aESM);
|
|
|
|
if (self) {
|
2007-03-22 10:30:00 -07:00
|
|
|
self->FireContextClick();
|
2013-01-24 13:19:15 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// NOTE: |aTimer| and |self->mAutoHideTimer| are invalid after calling ClosePopup();
|
|
|
|
|
|
|
|
} // sAutoHideCallback
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// FireContextClick
|
|
|
|
//
|
|
|
|
// If we're this far, our timer has fired, which means the mouse has been down
|
|
|
|
// for a certain period of time and has not moved enough to generate a dragGesture.
|
|
|
|
// We can be certain the user wants a context-click at this stage, so generate
|
|
|
|
// a dom event and fire it in.
|
|
|
|
//
|
|
|
|
// After the event fires, check if PreventDefault() has been set on the event which
|
|
|
|
// means that someone either ate the event or put up a context menu. This is our cue
|
|
|
|
// to stop tracking the drag gesture. If we always did this, draggable items w/out
|
|
|
|
// a context menu wouldn't be draggable after a certain length of time, which is
|
|
|
|
// _not_ what we want.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager::FireContextClick()
|
|
|
|
{
|
2010-06-16 00:36:11 -07:00
|
|
|
if (!mGestureDownContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2009-09-18 09:34:37 -07:00
|
|
|
// Hack to ensure that we don't show a context menu when the user
|
|
|
|
// let go of the mouse after a long cpu-hogging operation prevented
|
2007-03-22 10:30:00 -07:00
|
|
|
// us from handling any OS events. See bug 117589.
|
2009-09-18 09:34:37 -07:00
|
|
|
if (!CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
// Dispatch to the DOM. We have to fake out the ESM and tell it that the
|
|
|
|
// current target frame is actually where the mouseDown occurred, otherwise it
|
|
|
|
// will use the frame the mouse is currently over which may or may not be
|
|
|
|
// the same. (Note: saari and I have decided that we don't have to reset |mCurrentTarget|
|
|
|
|
// when we're through because no one else is doing anything more with this
|
|
|
|
// event and it will get reset on the very next event to the correct frame).
|
2009-12-24 13:20:05 -08:00
|
|
|
mCurrentTarget = mPresContext->GetPrimaryFrameFor(mGestureDownContent);
|
2013-01-24 13:19:15 -08:00
|
|
|
// make sure the widget sticks around
|
|
|
|
nsCOMPtr<nsIWidget> targetWidget;
|
|
|
|
if (mCurrentTarget && (targetWidget = mCurrentTarget->GetNearestWidget())) {
|
2009-12-24 13:20:05 -08:00
|
|
|
NS_ASSERTION(mPresContext == mCurrentTarget->PresContext(),
|
|
|
|
"a prescontext returned a primary frame that didn't belong to it?");
|
|
|
|
|
|
|
|
// before dispatching, check that we're not on something that
|
|
|
|
// doesn't get a context menu
|
|
|
|
nsIAtom *tag = mGestureDownContent->Tag();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool allowedToDispatch = true;
|
2009-12-24 13:20:05 -08:00
|
|
|
|
|
|
|
if (mGestureDownContent->IsXUL()) {
|
|
|
|
if (tag == nsGkAtoms::scrollbar ||
|
|
|
|
tag == nsGkAtoms::scrollbarbutton ||
|
|
|
|
tag == nsGkAtoms::button)
|
2011-10-17 07:59:28 -07:00
|
|
|
allowedToDispatch = false;
|
2009-12-24 13:20:05 -08:00
|
|
|
else if (tag == nsGkAtoms::toolbarbutton) {
|
|
|
|
// a <toolbarbutton> that has the container attribute set
|
|
|
|
// will already have its own dropdown.
|
|
|
|
if (nsContentUtils::HasNonEmptyAttr(mGestureDownContent,
|
|
|
|
kNameSpaceID_None, nsGkAtoms::container)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
allowedToDispatch = false;
|
2009-12-24 13:20:05 -08:00
|
|
|
} else {
|
|
|
|
// If the toolbar button has an open menu, don't attempt to open
|
2007-03-22 10:30:00 -07:00
|
|
|
// a second menu
|
2009-12-24 13:20:05 -08:00
|
|
|
if (mGestureDownContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::open,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
allowedToDispatch = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-12-24 13:20:05 -08:00
|
|
|
}
|
|
|
|
else if (mGestureDownContent->IsHTML()) {
|
|
|
|
nsCOMPtr<nsIFormControl> formCtrl(do_QueryInterface(mGestureDownContent));
|
|
|
|
|
|
|
|
if (formCtrl) {
|
2013-02-12 08:41:58 -08:00
|
|
|
allowedToDispatch = formCtrl->IsTextControl(false) ||
|
|
|
|
formCtrl->GetType() == NS_FORM_INPUT_FILE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-12-24 13:20:05 -08:00
|
|
|
else if (tag == nsGkAtoms::applet ||
|
|
|
|
tag == nsGkAtoms::embed ||
|
|
|
|
tag == nsGkAtoms::object) {
|
2011-10-17 07:59:28 -07:00
|
|
|
allowedToDispatch = false;
|
2009-12-24 13:20:05 -08:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
if (allowedToDispatch) {
|
|
|
|
// init the event while mCurrentTarget is still good
|
2011-10-17 07:59:28 -07:00
|
|
|
nsMouseEvent event(true, NS_CONTEXTMENU,
|
2009-12-24 13:20:05 -08:00
|
|
|
targetWidget,
|
|
|
|
nsMouseEvent::eReal);
|
|
|
|
event.clickCount = 1;
|
|
|
|
FillInEventFromGestureDown(&event);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
// stop selection tracking, we're in control now
|
|
|
|
if (mCurrentTarget)
|
|
|
|
{
|
2011-05-18 20:10:49 -07:00
|
|
|
nsRefPtr<nsFrameSelection> frameSel =
|
2009-12-24 13:20:05 -08:00
|
|
|
mCurrentTarget->GetFrameSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
if (frameSel && frameSel->GetMouseDownState()) {
|
|
|
|
// note that this can cause selection changed events to fire if we're in
|
|
|
|
// a text field, which will null out mCurrentTarget
|
2011-10-17 07:59:28 -07:00
|
|
|
frameSel->SetMouseDownState(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-12-24 13:20:05 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-26 10:13:53 -08:00
|
|
|
nsIDocument* doc = mGestureDownContent->GetCurrentDoc();
|
|
|
|
nsAutoHandlingUserInputStatePusher userInpStatePusher(true, &event, doc);
|
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
// dispatch to DOM
|
|
|
|
nsEventDispatcher::Dispatch(mGestureDownContent, mPresContext, &event,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, &status);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
// We don't need to dispatch to frame handling because no frames
|
|
|
|
// watch NS_CONTEXTMENU except for nsMenuFrame and that's only for
|
|
|
|
// dismissal. That's just as well since we don't really know
|
|
|
|
// which frame to send it to.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check if the event has been handled. If so, stop tracking a drag
|
2010-06-16 00:36:11 -07:00
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
2007-03-22 10:30:00 -07:00
|
|
|
StopTrackingDragGesture();
|
|
|
|
}
|
|
|
|
|
|
|
|
KillClickHoldTimer();
|
|
|
|
|
|
|
|
} // FireContextClick
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// BeginTrackingDragGesture
|
|
|
|
//
|
|
|
|
// Record that the mouse has gone down and that we should move to TRACKING state
|
|
|
|
// of d&d gesture tracker.
|
|
|
|
//
|
2010-06-16 00:36:11 -07:00
|
|
|
// We also use this to track click-hold context menus. When the mouse goes down,
|
2007-03-22 10:30:00 -07:00
|
|
|
// fire off a short timer. If the timer goes off and we have yet to fire the
|
|
|
|
// drag gesture (ie, the mouse hasn't moved a certain distance), then we can
|
|
|
|
// assume the user wants a click-hold, so fire a context-click event. We only
|
|
|
|
// want to cancel the drag gesture if the context-click event is handled.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext,
|
|
|
|
nsMouseEvent* inDownEvent,
|
|
|
|
nsIFrame* inDownFrame)
|
|
|
|
{
|
2010-06-16 00:36:11 -07:00
|
|
|
if (!inDownEvent->widget)
|
|
|
|
return;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Note that |inDownEvent| could be either a mouse down event or a
|
|
|
|
// synthesized mouse move event.
|
2010-06-16 00:36:11 -07:00
|
|
|
mGestureDownPoint = inDownEvent->refPoint +
|
2009-02-18 16:11:49 -08:00
|
|
|
inDownEvent->widget->WidgetToScreenOffset();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-26 13:55:04 -07:00
|
|
|
inDownFrame->GetContentForEvent(inDownEvent,
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(mGestureDownContent));
|
|
|
|
|
|
|
|
mGestureDownFrameOwner = inDownFrame->GetContent();
|
2012-04-24 20:00:01 -07:00
|
|
|
mGestureModifiers = inDownEvent->modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
mGestureDownButtons = inDownEvent->buttons;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-16 00:36:11 -07:00
|
|
|
if (mClickHoldContextMenu) {
|
|
|
|
// fire off a timer to track click-hold
|
|
|
|
CreateClickHoldTimer(aPresContext, inDownFrame, inDownEvent);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// StopTrackingDragGesture
|
|
|
|
//
|
|
|
|
// Record that the mouse has gone back up so that we should leave the TRACKING
|
|
|
|
// state of d&d gesture tracker and return to the START state.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager::StopTrackingDragGesture()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mGestureDownContent = nullptr;
|
|
|
|
mGestureDownFrameOwner = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::FillInEventFromGestureDown(nsMouseEvent* aEvent)
|
|
|
|
{
|
2010-07-02 12:11:04 -07:00
|
|
|
NS_ASSERTION(aEvent->widget == mCurrentTarget->GetNearestWidget(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Incorrect widget in event");
|
|
|
|
|
|
|
|
// Set the coordinates in the new event to the coordinates of
|
|
|
|
// the old event, adjusted for the fact that the widget might be
|
|
|
|
// different
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint tmpPoint = aEvent->widget->WidgetToScreenOffset();
|
|
|
|
aEvent->refPoint = mGestureDownPoint - tmpPoint;
|
2012-04-24 20:00:01 -07:00
|
|
|
aEvent->modifiers = mGestureModifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
aEvent->buttons = mGestureDownButtons;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// GenerateDragGesture
|
|
|
|
//
|
|
|
|
// If we're in the TRACKING state of the d&d gesture tracker, check the current position
|
|
|
|
// of the mouse in relation to the old one. If we've moved a sufficient amount from
|
|
|
|
// the mouse down, then fire off a drag gesture event.
|
|
|
|
void
|
|
|
|
nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
|
|
|
|
nsMouseEvent *aEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aPresContext, "This shouldn't happen.");
|
2010-06-16 00:36:11 -07:00
|
|
|
if (IsTrackingDragGesture()) {
|
2009-12-24 13:20:05 -08:00
|
|
|
mCurrentTarget = mGestureDownFrameOwner->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!mCurrentTarget) {
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if selection is tracking drag gestures, if so
|
|
|
|
// don't interfere!
|
|
|
|
if (mCurrentTarget)
|
|
|
|
{
|
2011-05-18 20:10:49 -07:00
|
|
|
nsRefPtr<nsFrameSelection> frameSel = mCurrentTarget->GetFrameSelection();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (frameSel && frameSel->GetMouseDownState()) {
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-02 18:07:08 -08:00
|
|
|
// If non-native code is capturing the mouse don't start a drag.
|
|
|
|
if (nsIPresShell::IsMouseCapturePreventingDrag()) {
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t pixelThresholdX = 0;
|
|
|
|
static int32_t pixelThresholdY = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!pixelThresholdX) {
|
2011-09-08 19:27:12 -07:00
|
|
|
pixelThresholdX =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_DragThresholdX, 0);
|
|
|
|
pixelThresholdY =
|
|
|
|
LookAndFeel::GetInt(LookAndFeel::eIntID_DragThresholdY, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!pixelThresholdX)
|
|
|
|
pixelThresholdX = 5;
|
|
|
|
if (!pixelThresholdY)
|
|
|
|
pixelThresholdY = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fire drag gesture if mouse has moved enough
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint pt = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
|
2013-03-05 15:43:30 -08:00
|
|
|
if (DeprecatedAbs(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
|
|
|
|
DeprecatedAbs(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
|
2010-06-16 00:36:11 -07:00
|
|
|
if (mClickHoldContextMenu) {
|
|
|
|
// stop the click-hold before we fire off the drag gesture, in case
|
|
|
|
// it takes a long time
|
|
|
|
KillClickHoldTimer();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-03-11 08:49:48 -07:00
|
|
|
nsRefPtr<nsDOMDataTransfer> dataTransfer =
|
|
|
|
new nsDOMDataTransfer(NS_DRAGDROP_START, false);
|
2008-08-27 05:07:27 -07:00
|
|
|
if (!dataTransfer)
|
|
|
|
return;
|
|
|
|
|
2012-02-17 06:16:59 -08:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
2008-08-27 05:07:27 -07:00
|
|
|
nsCOMPtr<nsIContent> eventContent, targetContent;
|
2011-09-26 13:55:04 -07:00
|
|
|
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(eventContent));
|
2008-08-27 05:07:27 -07:00
|
|
|
if (eventContent)
|
|
|
|
DetermineDragTarget(aPresContext, eventContent, dataTransfer,
|
2012-02-17 06:16:59 -08:00
|
|
|
getter_AddRefs(selection), getter_AddRefs(targetContent));
|
2008-08-27 05:07:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Stop tracking the drag gesture now. This should stop us from
|
|
|
|
// reentering GenerateDragGesture inside DOM event processing.
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
if (!targetContent)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
sLastDragOverFrame = nullptr;
|
2010-07-02 12:11:04 -07:00
|
|
|
nsCOMPtr<nsIWidget> widget = mCurrentTarget->GetNearestWidget();
|
2007-04-11 21:37:39 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// get the widget from the target frame
|
2012-12-15 17:26:03 -08:00
|
|
|
nsDragEvent startEvent(aEvent->mFlags.mIsTrusted,
|
|
|
|
NS_DRAGDROP_START, widget);
|
2008-08-27 05:07:27 -07:00
|
|
|
FillInEventFromGestureDown(&startEvent);
|
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
nsDragEvent gestureEvent(aEvent->mFlags.mIsTrusted,
|
|
|
|
NS_DRAGDROP_GESTURE, widget);
|
2007-04-11 21:37:39 -07:00
|
|
|
FillInEventFromGestureDown(&gestureEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
startEvent.dataTransfer = gestureEvent.dataTransfer = dataTransfer;
|
2010-04-06 05:59:24 -07:00
|
|
|
startEvent.inputSource = gestureEvent.inputSource = aEvent->inputSource;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Dispatch to the DOM. By setting mCurrentTarget we are faking
|
|
|
|
// out the ESM and telling it that the current target frame is
|
|
|
|
// actually where the mouseDown occurred, otherwise it will use
|
|
|
|
// the frame the mouse is currently over which may or may not be
|
|
|
|
// the same. (Note: saari and I have decided that we don't have
|
|
|
|
// to reset |mCurrentTarget| when we're through because no one
|
|
|
|
// else is doing anything more with this event and it will get
|
|
|
|
// reset on the very next event to the correct frame).
|
|
|
|
|
|
|
|
// Hold onto old target content through the event and reset after.
|
|
|
|
nsCOMPtr<nsIContent> targetBeforeEvent = mCurrentTargetContent;
|
|
|
|
|
|
|
|
// Set the current target to the content for the mouse down
|
|
|
|
mCurrentTargetContent = targetContent;
|
|
|
|
|
2008-09-25 07:45:03 -07:00
|
|
|
// Dispatch both the dragstart and draggesture events to the DOM. For
|
|
|
|
// elements in an editor, only fire the draggesture event so that the
|
|
|
|
// editor code can handle it but content doesn't see a dragstart.
|
2007-04-11 21:37:39 -07:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsEventDispatcher::Dispatch(targetContent, aPresContext, &startEvent, nullptr,
|
2012-02-17 06:16:59 -08:00
|
|
|
&status);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
nsDragEvent* event = &startEvent;
|
|
|
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
|
|
|
status = nsEventStatus_eIgnore;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsEventDispatcher::Dispatch(targetContent, aPresContext, &gestureEvent, nullptr,
|
2008-08-27 05:07:27 -07:00
|
|
|
&status);
|
|
|
|
event = &gestureEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now that the dataTransfer has been updated in the dragstart and
|
|
|
|
// draggesture events, make it read only so that the data doesn't
|
|
|
|
// change during the drag.
|
|
|
|
dataTransfer->SetReadOnly();
|
|
|
|
|
2009-11-09 06:55:53 -08:00
|
|
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool dragStarted = DoDefaultDragStart(aPresContext, event, dataTransfer,
|
2012-02-17 06:16:59 -08:00
|
|
|
targetContent, selection);
|
2009-11-09 06:55:53 -08:00
|
|
|
if (dragStarted) {
|
2012-07-30 07:20:58 -07:00
|
|
|
sActiveESM = nullptr;
|
2012-12-15 17:26:03 -08:00
|
|
|
aEvent->mFlags.mPropagationStopped = true;
|
2009-11-09 06:55:53 -08:00
|
|
|
}
|
|
|
|
}
|
2008-08-27 05:07:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Note that frame event handling doesn't care about NS_DRAGDROP_GESTURE,
|
|
|
|
// which is just as well since we don't really know which frame to
|
|
|
|
// send it to
|
|
|
|
|
|
|
|
// Reset mCurretTargetContent to what it was
|
|
|
|
mCurrentTargetContent = targetBeforeEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now flush all pending notifications, for better responsiveness
|
|
|
|
// while dragging.
|
|
|
|
FlushPendingEvents(aPresContext);
|
|
|
|
}
|
|
|
|
} // GenerateDragGesture
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::DetermineDragTarget(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aSelectionTarget,
|
|
|
|
nsDOMDataTransfer* aDataTransfer,
|
2012-02-17 06:16:59 -08:00
|
|
|
nsISelection** aSelection,
|
2008-08-27 05:07:27 -07:00
|
|
|
nsIContent** aTargetNode)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aTargetNode = nullptr;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container = aPresContext->GetContainer();
|
2012-08-04 00:44:01 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(container);
|
2012-05-16 16:55:09 -07:00
|
|
|
if (!window)
|
|
|
|
return;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// GetDragData determines if a selection, link or image in the content
|
|
|
|
// should be dragged, and places the data associated with the drag in the
|
2012-02-17 06:16:59 -08:00
|
|
|
// data transfer.
|
|
|
|
// mGestureDownContent is the node where the mousedown event for the drag
|
|
|
|
// occurred, and aSelectionTarget is the node to use when a selection is used
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canDrag;
|
2008-08-27 05:07:27 -07:00
|
|
|
nsCOMPtr<nsIContent> dragDataNode;
|
2012-04-24 20:00:02 -07:00
|
|
|
bool wasAlt = (mGestureModifiers & widget::MODIFIER_ALT) != 0;
|
2012-02-17 06:16:59 -08:00
|
|
|
nsresult rv = nsContentAreaDragDrop::GetDragData(window, mGestureDownContent,
|
2012-04-24 20:00:02 -07:00
|
|
|
aSelectionTarget, wasAlt,
|
2012-02-17 06:16:59 -08:00
|
|
|
aDataTransfer, &canDrag, aSelection,
|
|
|
|
getter_AddRefs(dragDataNode));
|
|
|
|
if (NS_FAILED(rv) || !canDrag)
|
|
|
|
return;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// if GetDragData returned a node, use that as the node being dragged.
|
|
|
|
// Otherwise, if a selection is being dragged, use the node within the
|
|
|
|
// selection that was dragged. Otherwise, just use the mousedown target.
|
|
|
|
nsIContent* dragContent = mGestureDownContent;
|
|
|
|
if (dragDataNode)
|
|
|
|
dragContent = dragDataNode;
|
2012-02-17 06:16:59 -08:00
|
|
|
else if (*aSelection)
|
2008-08-27 05:07:27 -07:00
|
|
|
dragContent = aSelectionTarget;
|
|
|
|
|
|
|
|
nsIContent* originalDragContent = dragContent;
|
|
|
|
|
|
|
|
// If a selection isn't being dragged, look for an ancestor with the
|
|
|
|
// draggable property set. If one is found, use that as the target of the
|
|
|
|
// drag instead of the node that was clicked on. If a draggable node wasn't
|
|
|
|
// found, just use the clicked node.
|
2012-02-17 06:16:59 -08:00
|
|
|
if (!*aSelection) {
|
2008-08-27 05:07:27 -07:00
|
|
|
while (dragContent) {
|
2011-10-29 13:03:55 -07:00
|
|
|
nsCOMPtr<nsIDOMHTMLElement> htmlElement = do_QueryInterface(dragContent);
|
2008-08-27 05:07:27 -07:00
|
|
|
if (htmlElement) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool draggable = false;
|
2008-08-27 05:07:27 -07:00
|
|
|
htmlElement->GetDraggable(&draggable);
|
|
|
|
if (draggable)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(dragContent);
|
|
|
|
if (xulElement) {
|
|
|
|
// All XUL elements are draggable, so if a XUL element is
|
|
|
|
// encountered, stop looking for draggable nodes and just use the
|
|
|
|
// original clicked node instead.
|
|
|
|
// XXXndeakin
|
|
|
|
// In the future, we will want to improve this so that XUL has a
|
|
|
|
// better way to specify whether something is draggable than just
|
|
|
|
// on/off.
|
|
|
|
dragContent = mGestureDownContent;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// otherwise, it's not an HTML or XUL element, so just keep looking
|
|
|
|
}
|
|
|
|
dragContent = dragContent->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no node in the hierarchy was found to drag, but the GetDragData method
|
2008-09-08 09:09:35 -07:00
|
|
|
// returned a node, use that returned node. Otherwise, nothing is draggable.
|
|
|
|
if (!dragContent && dragDataNode)
|
|
|
|
dragContent = dragDataNode;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
if (dragContent) {
|
|
|
|
// if an ancestor node was used instead, clear the drag data
|
|
|
|
// XXXndeakin rework this a bit. Find a way to just not call GetDragData if we don't need to.
|
|
|
|
if (dragContent != originalDragContent)
|
|
|
|
aDataTransfer->ClearAll();
|
|
|
|
*aTargetNode = dragContent;
|
|
|
|
NS_ADDREF(*aTargetNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-08-27 05:07:27 -07:00
|
|
|
nsEventStateManager::DoDefaultDragStart(nsPresContext* aPresContext,
|
|
|
|
nsDragEvent* aDragEvent,
|
|
|
|
nsDOMDataTransfer* aDataTransfer,
|
|
|
|
nsIContent* aDragTarget,
|
2012-02-17 06:16:59 -08:00
|
|
|
nsISelection* aSelection)
|
2008-08-27 05:07:27 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDragService> dragService =
|
|
|
|
do_GetService("@mozilla.org/widget/dragservice;1");
|
|
|
|
if (!dragService)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// Default handling for the draggesture/dragstart event.
|
|
|
|
//
|
|
|
|
// First, check if a drag session already exists. This means that the drag
|
|
|
|
// service was called directly within a draggesture handler. In this case,
|
|
|
|
// don't do anything more, as it is assumed that the handler is managing
|
2009-11-09 06:55:53 -08:00
|
|
|
// drag and drop manually. Make sure to return true to indicate that a drag
|
|
|
|
// began.
|
2008-08-27 05:07:27 -07:00
|
|
|
nsCOMPtr<nsIDragSession> dragSession;
|
|
|
|
dragService->GetCurrentSession(getter_AddRefs(dragSession));
|
|
|
|
if (dragSession)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// No drag session is currently active, so check if a handler added
|
|
|
|
// any items to be dragged. If not, there isn't anything to drag.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = 0;
|
2008-08-27 05:07:27 -07:00
|
|
|
if (aDataTransfer)
|
|
|
|
aDataTransfer->GetMozItemCount(&count);
|
|
|
|
if (!count)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// Get the target being dragged, which may not be the same as the
|
|
|
|
// target of the mouse event. If one wasn't set in the
|
|
|
|
// aDataTransfer during the event handler, just use the original
|
|
|
|
// target instead.
|
|
|
|
nsCOMPtr<nsIDOMNode> dragTarget;
|
|
|
|
nsCOMPtr<nsIDOMElement> dragTargetElement;
|
|
|
|
aDataTransfer->GetDragTarget(getter_AddRefs(dragTargetElement));
|
|
|
|
dragTarget = do_QueryInterface(dragTargetElement);
|
|
|
|
if (!dragTarget) {
|
|
|
|
dragTarget = do_QueryInterface(aDragTarget);
|
|
|
|
if (!dragTarget)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
2013-03-09 03:34:29 -08:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(dragTarget);
|
2008-08-27 05:07:27 -07:00
|
|
|
|
2008-09-01 12:51:12 -07:00
|
|
|
// check which drag effect should initially be used. If the effect was not
|
|
|
|
// set, just use all actions, otherwise Windows won't allow a drop.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t action;
|
2008-09-01 12:51:12 -07:00
|
|
|
aDataTransfer->GetEffectAllowedInt(&action);
|
|
|
|
if (action == nsIDragService::DRAGDROP_ACTION_UNINITIALIZED)
|
|
|
|
action = nsIDragService::DRAGDROP_ACTION_COPY |
|
|
|
|
nsIDragService::DRAGDROP_ACTION_MOVE |
|
|
|
|
nsIDragService::DRAGDROP_ACTION_LINK;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// get any custom drag image that was set
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t imageX, imageY;
|
2008-08-27 05:07:27 -07:00
|
|
|
nsIDOMElement* dragImage = aDataTransfer->GetDragImage(&imageX, &imageY);
|
|
|
|
|
2013-03-11 08:49:48 -07:00
|
|
|
nsCOMPtr<nsISupportsArray> transArray = aDataTransfer->GetTransferables(dragTarget);
|
2008-08-27 05:07:27 -07:00
|
|
|
if (!transArray)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
// XXXndeakin don't really want to create a new drag DOM event
|
|
|
|
// here, but we need something to pass to the InvokeDragSession
|
|
|
|
// methods.
|
|
|
|
nsCOMPtr<nsIDOMEvent> domEvent;
|
2013-03-09 03:34:29 -08:00
|
|
|
NS_NewDOMDragEvent(getter_AddRefs(domEvent), content,
|
|
|
|
aPresContext, aDragEvent);
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDragEvent> domDragEvent = do_QueryInterface(domEvent);
|
|
|
|
// if creating a drag event failed, starting a drag session will
|
|
|
|
// just fail.
|
2012-02-17 06:16:59 -08:00
|
|
|
|
|
|
|
// Use InvokeDragSessionWithSelection if a selection is being dragged,
|
|
|
|
// such that the image can be generated from the selected text. However,
|
|
|
|
// use InvokeDragSessionWithImage if a custom image was set or something
|
|
|
|
// other than a selection is being dragged.
|
|
|
|
if (!dragImage && aSelection) {
|
|
|
|
dragService->InvokeDragSessionWithSelection(aSelection, transArray,
|
2008-08-27 05:07:27 -07:00
|
|
|
action, domDragEvent,
|
|
|
|
aDataTransfer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if dragging within a XUL tree and no custom drag image was
|
|
|
|
// set, the region argument to InvokeDragSessionWithImage needs
|
|
|
|
// to be set to the area encompassing the selected rows of the
|
|
|
|
// tree to ensure that the drag feedback gets clipped to those
|
|
|
|
// rows. For other content, region should be null.
|
|
|
|
nsCOMPtr<nsIScriptableRegion> region;
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
if (dragTarget && !dragImage) {
|
|
|
|
if (content->NodeInfo()->Equals(nsGkAtoms::treechildren,
|
|
|
|
kNameSpaceID_XUL)) {
|
2009-12-24 13:20:05 -08:00
|
|
|
nsTreeBodyFrame* treeBody = do_QueryFrame(content->GetPrimaryFrame());
|
|
|
|
if (treeBody) {
|
|
|
|
treeBody->GetSelectionRegion(getter_AddRefs(region));
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dragService->InvokeDragSessionWithImage(dragTarget, transArray,
|
|
|
|
region, action, dragImage,
|
|
|
|
imageX, imageY, domDragEvent,
|
|
|
|
aDataTransfer);
|
|
|
|
}
|
2009-11-09 06:55:53 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2007-10-30 12:13:37 -07:00
|
|
|
nsEventStateManager::GetMarkupDocumentViewer(nsIMarkupDocumentViewer** aMv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aMv = nullptr;
|
2007-10-30 12:13:37 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if(!fm) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> focusedWindow;
|
|
|
|
fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(focusedWindow);
|
2007-03-22 10:30:00 -07:00
|
|
|
if(!ourWindow) return NS_ERROR_FAILURE;
|
|
|
|
|
2011-07-15 03:31:34 -07:00
|
|
|
nsIDOMWindow *rootWindow = ourWindow->GetPrivateRoot();
|
2007-03-22 10:30:00 -07:00
|
|
|
if(!rootWindow) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> contentWindow;
|
|
|
|
rootWindow->GetContent(getter_AddRefs(contentWindow));
|
|
|
|
if(!contentWindow) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsIDocument *doc = GetDocumentFromWindow(contentWindow);
|
|
|
|
if(!doc) return NS_ERROR_FAILURE;
|
|
|
|
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell *presShell = doc->GetShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
if(!presShell) return NS_ERROR_FAILURE;
|
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
|
|
|
if(!presContext) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> pcContainer = presContext->GetContainer();
|
|
|
|
if(!pcContainer) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docshell(do_QueryInterface(pcContainer));
|
|
|
|
if(!docshell) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docshell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
if(!cv) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mv(do_QueryInterface(cv));
|
|
|
|
if(!mv) return NS_ERROR_FAILURE;
|
|
|
|
|
2007-10-30 12:13:37 -07:00
|
|
|
*aMv = mv;
|
|
|
|
NS_IF_ADDREF(*aMv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsEventStateManager::ChangeTextSize(int32_t change)
|
2007-10-30 12:13:37 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mv;
|
|
|
|
nsresult rv = GetMarkupDocumentViewer(getter_AddRefs(mv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
float textzoom;
|
2011-05-24 23:32:00 -07:00
|
|
|
float zoomMin = ((float)Preferences::GetInt("zoom.minPercent", 50)) / 100;
|
|
|
|
float zoomMax = ((float)Preferences::GetInt("zoom.maxPercent", 300)) / 100;
|
2007-10-30 12:13:37 -07:00
|
|
|
mv->GetTextZoom(&textzoom);
|
|
|
|
textzoom += ((float)change) / 10;
|
2008-10-22 07:15:14 -07:00
|
|
|
if (textzoom < zoomMin)
|
|
|
|
textzoom = zoomMin;
|
|
|
|
else if (textzoom > zoomMax)
|
|
|
|
textzoom = zoomMax;
|
|
|
|
mv->SetTextZoom(textzoom);
|
2007-10-30 12:13:37 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsEventStateManager::ChangeFullZoom(int32_t change)
|
2007-10-30 12:13:37 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mv;
|
|
|
|
nsresult rv = GetMarkupDocumentViewer(getter_AddRefs(mv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-10-25 16:02:20 -07:00
|
|
|
float fullzoom;
|
2011-05-24 23:32:00 -07:00
|
|
|
float zoomMin = ((float)Preferences::GetInt("zoom.minPercent", 50)) / 100;
|
|
|
|
float zoomMax = ((float)Preferences::GetInt("zoom.maxPercent", 300)) / 100;
|
2007-10-25 16:02:20 -07:00
|
|
|
mv->GetFullZoom(&fullzoom);
|
|
|
|
fullzoom += ((float)change) / 10;
|
|
|
|
if (fullzoom < zoomMin)
|
|
|
|
fullzoom = zoomMin;
|
|
|
|
else if (fullzoom > zoomMax)
|
|
|
|
fullzoom = zoomMax;
|
|
|
|
mv->SetFullZoom(fullzoom);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsEventStateManager::DoScrollHistory(int32_t direction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> pcContainer(mPresContext->GetContainer());
|
|
|
|
if (pcContainer) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(pcContainer));
|
|
|
|
if (webNav) {
|
|
|
|
// positive direction to go back one step, nonpositive to go forward
|
|
|
|
if (direction > 0)
|
|
|
|
webNav->GoBack();
|
|
|
|
else
|
|
|
|
webNav->GoForward();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-13 03:00:45 -08:00
|
|
|
nsEventStateManager::DoScrollZoom(nsIFrame *aTargetFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t adjustment)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Exclude form controls and XUL content.
|
|
|
|
nsIContent *content = aTargetFrame->GetContent();
|
|
|
|
if (content &&
|
|
|
|
!content->IsNodeOfType(nsINode::eHTML_FORM_CONTROL) &&
|
2012-08-13 07:20:13 -07:00
|
|
|
!content->OwnerDoc()->IsXUL())
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-13 03:00:45 -08:00
|
|
|
// positive adjustment to decrease zoom, negative to increase
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t change = (adjustment > 0) ? -1 : 1;
|
2007-10-30 12:13:37 -07:00
|
|
|
|
2011-11-16 20:25:00 -08:00
|
|
|
if (Preferences::GetBool("browser.zoom.full") || content->GetCurrentDoc()->IsSyntheticDocument()) {
|
2008-02-13 03:00:45 -08:00
|
|
|
ChangeFullZoom(change);
|
2011-05-24 23:31:59 -07:00
|
|
|
} else {
|
2008-02-13 03:00:45 -08:00
|
|
|
ChangeTextSize(change);
|
2011-05-24 23:31:59 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIFrame*
|
2010-01-11 13:45:02 -08:00
|
|
|
GetParentFrameToScroll(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-01-11 13:45:02 -08:00
|
|
|
if (!aFrame)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
if (aFrame->StyleDisplay()->mPosition == NS_STYLE_POSITION_FIXED &&
|
2008-11-25 15:22:39 -08:00
|
|
|
nsLayoutUtils::IsReallyFixedPos(aFrame))
|
2010-01-11 13:45:02 -08:00
|
|
|
return aFrame->PresContext()->GetPresShell()->GetRootScrollFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::DispatchLegacyMouseScrollEvents(nsIFrame* aTargetFrame,
|
|
|
|
widget::WheelEvent* aEvent,
|
|
|
|
nsEventStatus* aStatus)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aEvent);
|
|
|
|
MOZ_ASSERT(aStatus);
|
|
|
|
|
|
|
|
if (!aTargetFrame || *aStatus == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore mouse wheel transaction for computing legacy mouse wheel
|
|
|
|
// events' delta value.
|
|
|
|
nsIScrollableFrame* scrollTarget =
|
2012-09-04 01:39:28 -07:00
|
|
|
ComputeScrollTarget(aTargetFrame, aEvent,
|
|
|
|
COMPUTE_LEGACY_MOUSE_SCROLL_EVENT_TARGET);
|
2012-08-11 18:42:35 -07:00
|
|
|
|
|
|
|
nsIFrame* scrollFrame = do_QueryFrame(scrollTarget);
|
|
|
|
nsPresContext* pc =
|
|
|
|
scrollFrame ? scrollFrame->PresContext() : aTargetFrame->PresContext();
|
|
|
|
|
|
|
|
// DOM event's delta vales are computed from CSS pixels.
|
|
|
|
nsSize scrollAmount = GetScrollAmount(pc, aEvent, scrollTarget);
|
|
|
|
nsIntSize scrollAmountInCSSPixels(
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(scrollAmount.width),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(scrollAmount.height));
|
|
|
|
|
2012-08-19 09:46:21 -07:00
|
|
|
// XXX We don't deal with fractional amount in legacy event, though the
|
|
|
|
// default action handler (DoScrollText()) deals with it.
|
|
|
|
// If we implemented such strict computation, we would need additional
|
|
|
|
// accumulated delta values. It would made the code more complicated.
|
|
|
|
// And also it would computes different delta values from older version.
|
|
|
|
// It doesn't make sense to implement such code for legacy events and
|
|
|
|
// rare cases.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t scrollDeltaX, scrollDeltaY, pixelDeltaX, pixelDeltaY;
|
2012-08-11 18:42:35 -07:00
|
|
|
switch (aEvent->deltaMode) {
|
|
|
|
case nsIDOMWheelEvent::DOM_DELTA_PAGE:
|
|
|
|
scrollDeltaX =
|
|
|
|
!aEvent->lineOrPageDeltaX ? 0 :
|
|
|
|
(aEvent->lineOrPageDeltaX > 0 ? nsIDOMUIEvent::SCROLL_PAGE_DOWN :
|
|
|
|
nsIDOMUIEvent::SCROLL_PAGE_UP);
|
|
|
|
scrollDeltaY =
|
|
|
|
!aEvent->lineOrPageDeltaY ? 0 :
|
|
|
|
(aEvent->lineOrPageDeltaY > 0 ? nsIDOMUIEvent::SCROLL_PAGE_DOWN :
|
|
|
|
nsIDOMUIEvent::SCROLL_PAGE_UP);
|
|
|
|
pixelDeltaX = RoundDown(aEvent->deltaX * scrollAmountInCSSPixels.width);
|
|
|
|
pixelDeltaY = RoundDown(aEvent->deltaY * scrollAmountInCSSPixels.height);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMWheelEvent::DOM_DELTA_LINE:
|
|
|
|
scrollDeltaX = aEvent->lineOrPageDeltaX;
|
|
|
|
scrollDeltaY = aEvent->lineOrPageDeltaY;
|
|
|
|
pixelDeltaX = RoundDown(aEvent->deltaX * scrollAmountInCSSPixels.width);
|
|
|
|
pixelDeltaY = RoundDown(aEvent->deltaY * scrollAmountInCSSPixels.height);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsIDOMWheelEvent::DOM_DELTA_PIXEL:
|
|
|
|
scrollDeltaX = aEvent->lineOrPageDeltaX;
|
|
|
|
scrollDeltaY = aEvent->lineOrPageDeltaY;
|
|
|
|
pixelDeltaX = RoundDown(aEvent->deltaX);
|
|
|
|
pixelDeltaY = RoundDown(aEvent->deltaY);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_NOT_REACHED("Invalid deltaMode value comes");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send the legacy events in following order:
|
|
|
|
// 1. Vertical scroll
|
|
|
|
// 2. Vertical pixel scroll (even if #1 isn't consumed)
|
|
|
|
// 3. Horizontal scroll (even if #1 and/or #2 are consumed)
|
|
|
|
// 4. Horizontal pixel scroll (even if #3 isn't consumed)
|
|
|
|
|
|
|
|
nsWeakFrame targetFrame(aTargetFrame);
|
|
|
|
|
|
|
|
nsEventStatus statusX = *aStatus;
|
|
|
|
nsEventStatus statusY = *aStatus;
|
|
|
|
if (scrollDeltaY) {
|
|
|
|
SendLineScrollEvent(aTargetFrame, aEvent, &statusY,
|
|
|
|
scrollDeltaY, DELTA_DIRECTION_Y);
|
|
|
|
if (!targetFrame.IsAlive()) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixelDeltaY) {
|
|
|
|
SendPixelScrollEvent(aTargetFrame, aEvent, &statusY,
|
|
|
|
pixelDeltaY, DELTA_DIRECTION_Y);
|
|
|
|
if (!targetFrame.IsAlive()) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scrollDeltaX) {
|
|
|
|
SendLineScrollEvent(aTargetFrame, aEvent, &statusX,
|
|
|
|
scrollDeltaX, DELTA_DIRECTION_X);
|
|
|
|
if (!targetFrame.IsAlive()) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pixelDeltaX) {
|
|
|
|
SendPixelScrollEvent(aTargetFrame, aEvent, &statusX,
|
|
|
|
pixelDeltaX, DELTA_DIRECTION_X);
|
|
|
|
if (!targetFrame.IsAlive()) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statusY == nsEventStatus_eConsumeNoDefault ||
|
|
|
|
statusX == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (statusY == nsEventStatus_eConsumeDoDefault ||
|
|
|
|
statusX == nsEventStatus_eConsumeDoDefault) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-02 12:34:31 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* aEvent,
|
2009-04-02 12:34:31 -07:00
|
|
|
nsEventStatus* aStatus,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aDelta,
|
2012-08-11 18:42:35 -07:00
|
|
|
DeltaDirection aDeltaDirection)
|
2009-04-02 12:34:31 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent();
|
|
|
|
if (!targetContent)
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
targetContent = GetFocusedContent();
|
2009-04-02 12:34:31 -07:00
|
|
|
if (!targetContent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (targetContent->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
targetContent = targetContent->GetParent();
|
|
|
|
}
|
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
nsMouseScrollEvent event(aEvent->mFlags.mIsTrusted, NS_MOUSE_SCROLL,
|
2012-08-11 18:42:35 -07:00
|
|
|
aEvent->widget);
|
|
|
|
if (*aStatus == nsEventStatus_eConsumeNoDefault) {
|
2012-12-15 17:26:04 -08:00
|
|
|
event.mFlags.mDefaultPrevented = true;
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
2009-04-02 12:34:31 -07:00
|
|
|
event.refPoint = aEvent->refPoint;
|
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.time = aEvent->time;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.modifiers = aEvent->modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.buttons = aEvent->buttons;
|
2012-08-11 18:42:37 -07:00
|
|
|
event.isHorizontal = (aDeltaDirection == DELTA_DIRECTION_X);
|
2012-08-11 18:42:35 -07:00
|
|
|
event.delta = aDelta;
|
|
|
|
event.inputSource = aEvent->inputSource;
|
2009-04-02 12:34:31 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
nsEventDispatcher::Dispatch(targetContent, aTargetFrame->PresContext(),
|
|
|
|
&event, nullptr, aStatus);
|
2009-04-02 12:34:31 -07:00
|
|
|
}
|
|
|
|
|
2008-09-17 04:27:19 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* aEvent,
|
|
|
|
nsEventStatus* aStatus,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aPixelDelta,
|
2012-08-11 18:42:35 -07:00
|
|
|
DeltaDirection aDeltaDirection)
|
2008-09-17 04:27:19 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> targetContent = aTargetFrame->GetContent();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (!targetContent) {
|
|
|
|
targetContent = GetFocusedContent();
|
|
|
|
if (!targetContent)
|
|
|
|
return;
|
|
|
|
}
|
2008-09-17 04:27:19 -07:00
|
|
|
|
|
|
|
while (targetContent->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
targetContent = targetContent->GetParent();
|
|
|
|
}
|
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
nsMouseScrollEvent event(aEvent->mFlags.mIsTrusted, NS_MOUSE_PIXEL_SCROLL,
|
2012-08-11 18:42:35 -07:00
|
|
|
aEvent->widget);
|
|
|
|
if (*aStatus == nsEventStatus_eConsumeNoDefault) {
|
2012-12-15 17:26:04 -08:00
|
|
|
event.mFlags.mDefaultPrevented = true;
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
2008-09-17 04:27:19 -07:00
|
|
|
event.refPoint = aEvent->refPoint;
|
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.time = aEvent->time;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.modifiers = aEvent->modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.buttons = aEvent->buttons;
|
2012-08-11 18:42:37 -07:00
|
|
|
event.isHorizontal = (aDeltaDirection == DELTA_DIRECTION_X);
|
2012-08-11 18:42:35 -07:00
|
|
|
event.delta = aPixelDelta;
|
|
|
|
event.inputSource = aEvent->inputSource;
|
2008-09-17 04:27:19 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
nsEventDispatcher::Dispatch(targetContent, aTargetFrame->PresContext(),
|
|
|
|
&event, nullptr, aStatus);
|
2008-09-17 04:27:19 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
nsIScrollableFrame*
|
|
|
|
nsEventStateManager::ComputeScrollTarget(nsIFrame* aTargetFrame,
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* aEvent,
|
2012-09-04 01:39:28 -07:00
|
|
|
ComputeScrollTargetOptions aOptions)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-04 01:39:28 -07:00
|
|
|
if (aOptions & PREFER_MOUSE_WHEEL_TRANSACTION) {
|
2012-08-11 18:42:34 -07:00
|
|
|
// If the user recently scrolled with the mousewheel, then they probably
|
|
|
|
// want to scroll the same view as before instead of the view under the
|
|
|
|
// cursor. nsMouseWheelTransaction tracks the frame currently being
|
|
|
|
// scrolled with the mousewheel. We consider the transaction ended when the
|
|
|
|
// mouse moves more than "mousewheel.transaction.ignoremovedelay"
|
|
|
|
// milliseconds after the last scroll operation, or any time the mouse moves
|
|
|
|
// out of the frame, or when more than "mousewheel.transaction.timeout"
|
|
|
|
// milliseconds have passed after the last operation, even if the mouse
|
|
|
|
// hasn't moved.
|
|
|
|
nsIFrame* lastScrollFrame = nsMouseWheelTransaction::GetTargetFrame();
|
|
|
|
if (lastScrollFrame) {
|
|
|
|
nsIScrollableFrame* frameToScroll =
|
|
|
|
lastScrollFrame->GetScrollTargetFrame();
|
|
|
|
if (frameToScroll) {
|
|
|
|
return frameToScroll;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
// If the event doesn't cause scroll actually, we cannot find scroll target
|
|
|
|
// because we check if the event can cause scroll actually on each found
|
|
|
|
// scrollable frame.
|
|
|
|
if (!aEvent->deltaX && !aEvent->deltaY) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-09-04 01:39:28 -07:00
|
|
|
bool checkIfScrollableX =
|
|
|
|
aEvent->deltaX && (aOptions & PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_X_AXIS);
|
|
|
|
bool checkIfScrollableY =
|
|
|
|
aEvent->deltaY && (aOptions & PREFER_ACTUAL_SCROLLABLE_TARGET_ALONG_Y_AXIS);
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
nsIScrollableFrame* frameToScroll = nullptr;
|
2012-09-04 01:39:28 -07:00
|
|
|
nsIFrame* scrollFrame =
|
|
|
|
!(aOptions & START_FROM_PARENT) ? aTargetFrame :
|
|
|
|
GetParentFrameToScroll(aTargetFrame);
|
|
|
|
for (; scrollFrame; scrollFrame = GetParentFrameToScroll(scrollFrame)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check whether the frame wants to provide us with a scrollable view.
|
2010-01-11 13:45:02 -08:00
|
|
|
frameToScroll = scrollFrame->GetScrollTargetFrame();
|
|
|
|
if (!frameToScroll) {
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-09-04 01:39:28 -07:00
|
|
|
if (!checkIfScrollableX && !checkIfScrollableY) {
|
2012-08-11 18:42:34 -07:00
|
|
|
return frameToScroll;
|
|
|
|
}
|
|
|
|
|
2010-01-11 13:45:02 -08:00
|
|
|
nsPresContext::ScrollbarStyles ss = frameToScroll->GetScrollbarStyles();
|
2012-08-11 18:42:35 -07:00
|
|
|
bool hiddenForV = (NS_STYLE_OVERFLOW_HIDDEN == ss.mVertical);
|
|
|
|
bool hiddenForH = (NS_STYLE_OVERFLOW_HIDDEN == ss.mHorizontal);
|
|
|
|
if ((hiddenForV && hiddenForH) ||
|
2012-09-04 01:39:28 -07:00
|
|
|
(checkIfScrollableY && !checkIfScrollableX && hiddenForV) ||
|
|
|
|
(checkIfScrollableX && !checkIfScrollableY && hiddenForH)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-19 09:46:21 -07:00
|
|
|
// For default action, we should climb up the tree if cannot scroll it
|
|
|
|
// by the event actually.
|
|
|
|
bool canScroll = CanScrollOn(frameToScroll,
|
|
|
|
aEvent->deltaX, aEvent->deltaY);
|
|
|
|
// Comboboxes need special care.
|
|
|
|
nsIComboboxControlFrame* comboBox = do_QueryFrame(scrollFrame);
|
|
|
|
if (comboBox) {
|
|
|
|
if (comboBox->IsDroppedDown()) {
|
|
|
|
// Don't propagate to parent when drop down menu is active.
|
|
|
|
return canScroll ? frameToScroll : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-19 09:46:21 -07:00
|
|
|
// Always propagate when not dropped down (even if focused).
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-19 09:46:21 -07:00
|
|
|
if (canScroll) {
|
|
|
|
return frameToScroll;
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
2011-05-23 07:56:59 -07:00
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
nsIFrame* newFrame = nsLayoutUtils::GetCrossDocParentFrame(
|
|
|
|
aTargetFrame->PresContext()->FrameManager()->GetRootFrame());
|
2012-09-04 01:39:28 -07:00
|
|
|
aOptions =
|
|
|
|
static_cast<ComputeScrollTargetOptions>(aOptions & ~START_FROM_PARENT);
|
|
|
|
return newFrame ? ComputeScrollTarget(newFrame, aEvent, aOptions) : nullptr;
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
nsSize
|
2012-08-11 18:42:34 -07:00
|
|
|
nsEventStateManager::GetScrollAmount(nsPresContext* aPresContext,
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* aEvent,
|
2012-08-11 18:42:34 -07:00
|
|
|
nsIScrollableFrame* aScrollableFrame)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aPresContext);
|
|
|
|
MOZ_ASSERT(aEvent);
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
bool isPage = (aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_PAGE);
|
2012-08-11 18:42:34 -07:00
|
|
|
if (aScrollableFrame) {
|
2012-08-11 18:42:35 -07:00
|
|
|
return isPage ? aScrollableFrame->GetPageScrollAmount() :
|
|
|
|
aScrollableFrame->GetLineScrollAmount();
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no scrollable frame and page scrolling, use view port size.
|
|
|
|
if (isPage) {
|
2012-08-11 18:42:35 -07:00
|
|
|
return aPresContext->GetVisibleArea().Size();
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no scrollable frame, we should use root frame's information.
|
|
|
|
nsIFrame* rootFrame = aPresContext->PresShell()->GetRootFrame();
|
|
|
|
if (!rootFrame) {
|
2012-08-11 18:42:35 -07:00
|
|
|
return nsSize(0, 0);
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(rootFrame, getter_AddRefs(fm),
|
|
|
|
nsLayoutUtils::FontSizeInflationFor(rootFrame));
|
2012-08-11 18:42:35 -07:00
|
|
|
NS_ENSURE_TRUE(fm, nsSize(0, 0));
|
2012-10-28 22:44:31 -07:00
|
|
|
return nsSize(fm->AveCharWidth(), fm->MaxHeight());
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
2011-05-23 07:56:59 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::DoScrollText(nsIScrollableFrame* aScrollableFrame,
|
|
|
|
widget::WheelEvent* aEvent)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
2012-08-11 18:42:35 -07:00
|
|
|
MOZ_ASSERT(aScrollableFrame);
|
|
|
|
MOZ_ASSERT(aEvent);
|
2011-05-18 16:12:34 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
nsIFrame* scrollFrame = do_QueryFrame(aScrollableFrame);
|
2012-08-11 18:42:34 -07:00
|
|
|
MOZ_ASSERT(scrollFrame);
|
|
|
|
nsWeakFrame scrollFrameWeak(scrollFrame);
|
|
|
|
|
|
|
|
nsIFrame* lastScrollFrame = nsMouseWheelTransaction::GetTargetFrame();
|
|
|
|
if (!lastScrollFrame) {
|
2012-08-11 18:42:35 -07:00
|
|
|
nsMouseWheelTransaction::BeginTransaction(scrollFrame, aEvent);
|
2012-08-11 18:42:34 -07:00
|
|
|
} else if (lastScrollFrame != scrollFrame) {
|
|
|
|
nsMouseWheelTransaction::EndTransaction();
|
2012-08-11 18:42:35 -07:00
|
|
|
nsMouseWheelTransaction::BeginTransaction(scrollFrame, aEvent);
|
2012-08-11 18:42:34 -07:00
|
|
|
} else {
|
2012-08-11 18:42:35 -07:00
|
|
|
nsMouseWheelTransaction::UpdateTransaction(aEvent);
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// When the scroll event will not scroll any views, UpdateTransaction
|
|
|
|
// fired MozMouseScrollFailed event which is for automated testing.
|
|
|
|
// In the event handler, the target frame might be destroyed. Then,
|
|
|
|
// we should not try scrolling anything.
|
|
|
|
if (!scrollFrameWeak.IsAlive()) {
|
|
|
|
nsMouseWheelTransaction::EndTransaction();
|
2012-08-11 18:42:35 -07:00
|
|
|
return;
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
// Default action's actual scroll amount should be computed from device
|
|
|
|
// pixels.
|
|
|
|
nsPresContext* pc = scrollFrame->PresContext();
|
|
|
|
nsSize scrollAmount = GetScrollAmount(pc, aEvent, aScrollableFrame);
|
|
|
|
nsIntSize scrollAmountInDevPixels(
|
|
|
|
pc->AppUnitsToDevPixels(scrollAmount.width),
|
|
|
|
pc->AppUnitsToDevPixels(scrollAmount.height));
|
2012-08-19 09:46:21 -07:00
|
|
|
nsIntPoint actualDevPixelScrollAmount =
|
|
|
|
DeltaAccumulator::GetInstance()->
|
|
|
|
ComputeScrollAmountForDefaultAction(aEvent, scrollAmountInDevPixels);
|
2012-08-11 18:42:34 -07:00
|
|
|
|
2012-08-29 18:05:16 -07:00
|
|
|
// Don't scroll around the axis whose overflow style is hidden.
|
|
|
|
nsPresContext::ScrollbarStyles overflowStyle =
|
|
|
|
aScrollableFrame->GetScrollbarStyles();
|
|
|
|
if (overflowStyle.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
actualDevPixelScrollAmount.x = 0;
|
|
|
|
}
|
|
|
|
if (overflowStyle.mVertical == NS_STYLE_OVERFLOW_HIDDEN) {
|
|
|
|
actualDevPixelScrollAmount.y = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
nsIAtom* origin = nullptr;
|
|
|
|
switch (aEvent->deltaMode) {
|
|
|
|
case nsIDOMWheelEvent::DOM_DELTA_LINE:
|
|
|
|
origin = nsGkAtoms::mouseWheel;
|
|
|
|
break;
|
|
|
|
case nsIDOMWheelEvent::DOM_DELTA_PAGE:
|
|
|
|
origin = nsGkAtoms::pages;
|
|
|
|
break;
|
|
|
|
case nsIDOMWheelEvent::DOM_DELTA_PIXEL:
|
|
|
|
origin = nsGkAtoms::pixels;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_NOT_REACHED("Invalid deltaMode value comes");
|
|
|
|
return;
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
2011-07-14 15:12:20 -07:00
|
|
|
|
2012-10-30 16:22:23 -07:00
|
|
|
// We shouldn't scroll more one page at once except when over one page scroll
|
|
|
|
// is allowed for the event.
|
2012-08-11 18:42:35 -07:00
|
|
|
nsSize pageSize = aScrollableFrame->GetPageScrollAmount();
|
|
|
|
nsIntSize devPixelPageSize(pc->AppUnitsToDevPixels(pageSize.width),
|
|
|
|
pc->AppUnitsToDevPixels(pageSize.height));
|
2012-10-30 16:22:23 -07:00
|
|
|
if (!WheelPrefs::GetInstance()->IsOverOnePageScrollAllowedX(aEvent) &&
|
2013-03-05 15:43:30 -08:00
|
|
|
DeprecatedAbs(actualDevPixelScrollAmount.x) > devPixelPageSize.width) {
|
2012-08-11 18:42:35 -07:00
|
|
|
actualDevPixelScrollAmount.x =
|
|
|
|
(actualDevPixelScrollAmount.x >= 0) ? devPixelPageSize.width :
|
|
|
|
-devPixelPageSize.width;
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
|
2012-10-30 16:22:23 -07:00
|
|
|
if (!WheelPrefs::GetInstance()->IsOverOnePageScrollAllowedY(aEvent) &&
|
2013-03-05 15:43:30 -08:00
|
|
|
DeprecatedAbs(actualDevPixelScrollAmount.y) > devPixelPageSize.height) {
|
2012-08-11 18:42:35 -07:00
|
|
|
actualDevPixelScrollAmount.y =
|
|
|
|
(actualDevPixelScrollAmount.y >= 0) ? devPixelPageSize.height :
|
|
|
|
-devPixelPageSize.height;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-19 09:46:21 -07:00
|
|
|
bool isDeltaModePixel =
|
|
|
|
(aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL);
|
|
|
|
|
2012-08-11 18:42:36 -07:00
|
|
|
nsIScrollableFrame::ScrollMode mode;
|
|
|
|
switch (aEvent->scrollType) {
|
|
|
|
case widget::WheelEvent::SCROLL_DEFAULT:
|
|
|
|
if (isDeltaModePixel) {
|
|
|
|
mode = nsIScrollableFrame::NORMAL;
|
|
|
|
} else {
|
|
|
|
mode = nsIScrollableFrame::SMOOTH;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case widget::WheelEvent::SCROLL_SYNCHRONOUSLY:
|
|
|
|
mode = nsIScrollableFrame::INSTANT;
|
|
|
|
break;
|
|
|
|
case widget::WheelEvent::SCROLL_ASYNCHRONOUSELY:
|
|
|
|
mode = nsIScrollableFrame::NORMAL;
|
|
|
|
break;
|
|
|
|
case widget::WheelEvent::SCROLL_SMOOTHLY:
|
|
|
|
mode = nsIScrollableFrame::SMOOTH;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_NOT_REACHED("Invalid scrollType value comes");
|
|
|
|
return;
|
|
|
|
}
|
2009-05-19 19:05:59 -07:00
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
nsIntPoint overflow;
|
2012-08-11 18:42:35 -07:00
|
|
|
aScrollableFrame->ScrollBy(actualDevPixelScrollAmount,
|
|
|
|
nsIScrollableFrame::DEVICE_PIXELS,
|
|
|
|
mode, &overflow, origin);
|
|
|
|
|
2012-09-04 01:39:28 -07:00
|
|
|
if (!scrollFrameWeak.IsAlive()) {
|
|
|
|
// If the scroll causes changing the layout, we can think that the event
|
|
|
|
// has been completely consumed by the content. Then, users probably don't
|
|
|
|
// want additional action.
|
|
|
|
aEvent->overflowDeltaX = aEvent->overflowDeltaY = 0;
|
|
|
|
} else if (isDeltaModePixel) {
|
2012-08-11 18:42:35 -07:00
|
|
|
aEvent->overflowDeltaX = overflow.x;
|
|
|
|
aEvent->overflowDeltaY = overflow.y;
|
|
|
|
} else {
|
|
|
|
aEvent->overflowDeltaX =
|
|
|
|
static_cast<double>(overflow.x) / scrollAmountInDevPixels.width;
|
|
|
|
aEvent->overflowDeltaY =
|
|
|
|
static_cast<double>(overflow.y) / scrollAmountInDevPixels.height;
|
|
|
|
}
|
2012-08-29 18:05:16 -07:00
|
|
|
|
|
|
|
// If CSS overflow properties caused not to scroll, the overflowDelta* values
|
|
|
|
// should be same as delta* values since they may be used as gesture event by
|
2012-09-04 01:39:28 -07:00
|
|
|
// widget. However, if there is another scrollable element in the ancestor
|
|
|
|
// along the axis, probably users don't want the operation to cause
|
|
|
|
// additional action such as moving history. In such case, overflowDelta
|
|
|
|
// values should stay zero.
|
|
|
|
if (scrollFrameWeak.IsAlive()) {
|
|
|
|
if (aEvent->deltaX &&
|
|
|
|
overflowStyle.mHorizontal == NS_STYLE_OVERFLOW_HIDDEN &&
|
|
|
|
!ComputeScrollTarget(scrollFrame, aEvent,
|
|
|
|
COMPUTE_SCROLLABLE_ANCESTOR_ALONG_X_AXIS)) {
|
|
|
|
aEvent->overflowDeltaX = aEvent->deltaX;
|
|
|
|
}
|
|
|
|
if (aEvent->deltaY &&
|
|
|
|
overflowStyle.mVertical == NS_STYLE_OVERFLOW_HIDDEN &&
|
|
|
|
!ComputeScrollTarget(scrollFrame, aEvent,
|
|
|
|
COMPUTE_SCROLLABLE_ANCESTOR_ALONG_Y_AXIS)) {
|
|
|
|
aEvent->overflowDeltaY = aEvent->deltaY;
|
|
|
|
}
|
2012-08-29 18:05:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aEvent->overflowDeltaX == 0 ||
|
2012-09-04 01:39:28 -07:00
|
|
|
(aEvent->overflowDeltaX > 0) == (aEvent->deltaX > 0),
|
2012-08-29 18:05:16 -07:00
|
|
|
"The sign of overflowDeltaX is different from the scroll direction");
|
|
|
|
NS_ASSERTION(aEvent->overflowDeltaY == 0 ||
|
2012-09-04 01:39:28 -07:00
|
|
|
(aEvent->overflowDeltaY > 0) == (aEvent->deltaY > 0),
|
2012-08-29 18:05:16 -07:00
|
|
|
"The sign of overflowDeltaY is different from the scroll direction");
|
|
|
|
|
2012-08-11 18:42:36 -07:00
|
|
|
WheelPrefs::GetInstance()->CancelApplyingUserPrefsFromOverflowDelta(aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-08-13 13:54:09 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::DecideGestureEvent(nsGestureNotifyEvent* aEvent,
|
|
|
|
nsIFrame* targetFrame)
|
|
|
|
{
|
|
|
|
|
|
|
|
NS_ASSERTION(aEvent->message == NS_GESTURENOTIFY_EVENT_START,
|
|
|
|
"DecideGestureEvent called with a non-gesture event");
|
|
|
|
|
|
|
|
/* Check the ancestor tree to decide if any frame is willing* to receive
|
|
|
|
* a MozPixelScroll event. If that's the case, the current touch gesture
|
|
|
|
* will be used as a pan gesture; otherwise it will be a regular
|
|
|
|
* mousedown/mousemove/click event.
|
|
|
|
*
|
|
|
|
* *willing: determine if it makes sense to pan the element using scroll events:
|
|
|
|
* - For web content: if there are any visible scrollbars on the touch point
|
|
|
|
* - For XUL: if it's an scrollable element that can currently scroll in some
|
|
|
|
* direction.
|
|
|
|
*
|
|
|
|
* Note: we'll have to one-off various cases to ensure a good usable behavior
|
|
|
|
*/
|
|
|
|
nsGestureNotifyEvent::ePanDirection panDirection = nsGestureNotifyEvent::ePanNone;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool displayPanFeedback = false;
|
2009-08-13 13:54:09 -07:00
|
|
|
for (nsIFrame* current = targetFrame; current;
|
|
|
|
current = nsLayoutUtils::GetCrossDocParentFrame(current)) {
|
|
|
|
|
|
|
|
nsIAtom* currentFrameType = current->GetType();
|
|
|
|
|
|
|
|
// Scrollbars should always be draggable
|
|
|
|
if (currentFrameType == nsGkAtoms::scrollbarFrame) {
|
|
|
|
panDirection = nsGestureNotifyEvent::ePanNone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// Special check for trees
|
|
|
|
nsTreeBodyFrame* treeFrame = do_QueryFrame(current);
|
|
|
|
if (treeFrame) {
|
|
|
|
if (treeFrame->GetHorizontalOverflow()) {
|
|
|
|
panDirection = nsGestureNotifyEvent::ePanHorizontal;
|
|
|
|
}
|
|
|
|
if (treeFrame->GetVerticalOverflow()) {
|
|
|
|
panDirection = nsGestureNotifyEvent::ePanVertical;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(current);
|
|
|
|
if (scrollableFrame) {
|
|
|
|
if (current->IsFrameOfType(nsIFrame::eXULBox)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
displayPanFeedback = true;
|
2009-08-13 13:54:09 -07:00
|
|
|
|
2010-01-11 13:45:04 -08:00
|
|
|
nsRect scrollRange = scrollableFrame->GetScrollRange();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canScrollHorizontally = scrollRange.width > 0;
|
2009-08-13 13:54:09 -07:00
|
|
|
|
2010-01-11 13:45:04 -08:00
|
|
|
if (targetFrame->GetType() == nsGkAtoms::menuFrame) {
|
|
|
|
// menu frames report horizontal scroll when they have submenus
|
|
|
|
// and we don't want that
|
2011-10-17 07:59:28 -07:00
|
|
|
canScrollHorizontally = false;
|
|
|
|
displayPanFeedback = false;
|
2010-01-11 13:45:04 -08:00
|
|
|
}
|
2009-08-13 13:54:09 -07:00
|
|
|
|
2010-01-11 13:45:04 -08:00
|
|
|
// Vertical panning has priority over horizontal panning, so
|
|
|
|
// when vertical movement is possible we can just finish the loop.
|
|
|
|
if (scrollRange.height > 0) {
|
|
|
|
panDirection = nsGestureNotifyEvent::ePanVertical;
|
|
|
|
break;
|
2009-08-13 13:54:09 -07:00
|
|
|
}
|
|
|
|
|
2010-01-11 13:45:04 -08:00
|
|
|
if (canScrollHorizontally) {
|
|
|
|
panDirection = nsGestureNotifyEvent::ePanHorizontal;
|
2011-10-17 07:59:28 -07:00
|
|
|
displayPanFeedback = false;
|
2010-01-11 13:45:04 -08:00
|
|
|
}
|
2009-08-13 13:54:09 -07:00
|
|
|
} else { //Not a XUL box
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t scrollbarVisibility = scrollableFrame->GetScrollbarVisibility();
|
2009-08-13 13:54:09 -07:00
|
|
|
|
|
|
|
//Check if we have visible scrollbars
|
2010-01-14 05:00:00 -08:00
|
|
|
if (scrollbarVisibility & nsIScrollableFrame::VERTICAL) {
|
2009-08-13 13:54:09 -07:00
|
|
|
panDirection = nsGestureNotifyEvent::ePanVertical;
|
2011-10-17 07:59:28 -07:00
|
|
|
displayPanFeedback = true;
|
2009-08-13 13:54:09 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-14 05:00:00 -08:00
|
|
|
if (scrollbarVisibility & nsIScrollableFrame::HORIZONTAL) {
|
2009-08-13 13:54:09 -07:00
|
|
|
panDirection = nsGestureNotifyEvent::ePanHorizontal;
|
2011-10-17 07:59:28 -07:00
|
|
|
displayPanFeedback = true;
|
2009-08-13 13:54:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} //scrollableFrame
|
|
|
|
} //ancestor chain
|
|
|
|
|
|
|
|
aEvent->displayPanFeedback = displayPanFeedback;
|
|
|
|
aEvent->panDirection = panDirection;
|
|
|
|
}
|
|
|
|
|
2010-11-24 01:49:02 -08:00
|
|
|
#ifdef XP_MACOSX
|
2010-07-16 05:50:28 -07:00
|
|
|
static bool
|
|
|
|
NodeAllowsClickThrough(nsINode* aNode)
|
|
|
|
{
|
|
|
|
while (aNode) {
|
|
|
|
if (aNode->IsElement() && aNode->AsElement()->IsXUL()) {
|
|
|
|
mozilla::dom::Element* element = aNode->AsElement();
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{&nsGkAtoms::always, &nsGkAtoms::never, nullptr};
|
2010-07-16 05:50:28 -07:00
|
|
|
switch (element->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::clickthrough,
|
|
|
|
strings, eCaseMatters)) {
|
|
|
|
case 0:
|
|
|
|
return true;
|
|
|
|
case 1:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aNode = nsContentUtils::GetCrossDocParentNode(aNode);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-24 01:49:02 -08:00
|
|
|
#endif
|
2010-07-16 05:50:28 -07:00
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
|
|
|
|
nsEvent *aEvent,
|
|
|
|
nsIFrame* aTargetFrame,
|
2011-11-21 09:53:20 -08:00
|
|
|
nsEventStatus* aStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aPresContext);
|
|
|
|
NS_ENSURE_ARG_POINTER(aStatus);
|
2007-03-24 02:45:01 -07:00
|
|
|
|
2011-06-21 17:32:43 -07:00
|
|
|
HandleCrossProcessEvent(aEvent, aTargetFrame, aStatus);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentTarget = aTargetFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentTargetContent = nullptr;
|
2007-03-24 02:45:01 -07:00
|
|
|
|
2007-11-20 14:30:27 -08:00
|
|
|
// Most of the events we handle below require a frame.
|
|
|
|
// Add special cases here.
|
2010-10-09 12:09:22 -07:00
|
|
|
if (!mCurrentTarget && aEvent->message != NS_MOUSE_BUTTON_UP &&
|
|
|
|
aEvent->message != NS_MOUSE_BUTTON_DOWN) {
|
2007-03-24 02:45:01 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//Keep the prescontext alive, we might need it after event dispatch
|
|
|
|
nsRefPtr<nsPresContext> presContext = aPresContext;
|
2007-03-24 02:45:01 -07:00
|
|
|
nsresult ret = NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
if (static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton &&
|
2010-09-08 10:41:37 -07:00
|
|
|
!sNormalLMouseEventInProcess) {
|
2009-09-13 06:13:16 -07:00
|
|
|
// We got a mouseup event while a mousedown event was being processed.
|
|
|
|
// Make sure that the capturing content is cleared.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-10-15 09:41:02 -07:00
|
|
|
nsCOMPtr<nsIContent> activeContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
2010-10-15 09:41:02 -07:00
|
|
|
nsCOMPtr<nsIContent> newFocus;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool suppressBlur = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCurrentTarget) {
|
2011-09-26 13:55:04 -07:00
|
|
|
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(newFocus));
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleUserInterface* ui = mCurrentTarget->StyleUserInterface();
|
2013-02-27 07:53:41 -08:00
|
|
|
activeContent = mCurrentTarget->GetContent();
|
2013-02-28 16:15:59 -08:00
|
|
|
|
|
|
|
// In some cases, we do not want to even blur the current focused
|
|
|
|
// element. Those cases are:
|
|
|
|
// 1. -moz-user-focus CSS property is set to 'ignore';
|
|
|
|
// 2. Element with NS_EVENT_STATE_DISABLED
|
|
|
|
// (aka :disabled pseudo-class for HTML element);
|
|
|
|
// 3. XUL control element has the disabled property set to 'true'.
|
|
|
|
//
|
|
|
|
// We can't use nsIFrame::IsFocusable() because we want to blur when
|
|
|
|
// we click on a visibility: none element.
|
|
|
|
// We can't use nsIContent::IsFocusable() because we want to blur when
|
|
|
|
// we click on a non-focusable element like a <div>.
|
|
|
|
// We have to use |aEvent->target| to not make sure we do not check an
|
|
|
|
// anonymous node of the targeted element.
|
|
|
|
suppressBlur = (ui->mUserFocus == NS_STYLE_USER_FOCUS_IGNORE);
|
|
|
|
|
|
|
|
if (!suppressBlur) {
|
|
|
|
nsCOMPtr<Element> element = do_QueryInterface(aEvent->target);
|
|
|
|
suppressBlur = element &&
|
|
|
|
element->State().HasState(NS_EVENT_STATE_DISABLED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!suppressBlur) {
|
|
|
|
nsCOMPtr<nsIDOMXULControlElement> xulControl =
|
|
|
|
do_QueryInterface(aEvent->target);
|
|
|
|
if (xulControl) {
|
|
|
|
bool disabled;
|
|
|
|
xulControl->GetDisabled(&disabled);
|
|
|
|
suppressBlur = disabled;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-21 06:13:08 -07:00
|
|
|
nsIFrame* currFrame = mCurrentTarget;
|
|
|
|
|
|
|
|
// When a root content which isn't editable but has an editable HTML
|
|
|
|
// <body> element is clicked, we should redirect the focus to the
|
|
|
|
// the <body> element. E.g., when an user click bottom of the editor
|
|
|
|
// where is outside of the <body> element, the <body> should be focused
|
|
|
|
// and the user can edit immediately after that.
|
|
|
|
//
|
|
|
|
// NOTE: The newFocus isn't editable that also means it's not in
|
|
|
|
// designMode. In designMode, all contents are not focusable.
|
|
|
|
if (newFocus && !newFocus->IsEditable()) {
|
|
|
|
nsIDocument *doc = newFocus->GetCurrentDoc();
|
2010-04-30 06:12:05 -07:00
|
|
|
if (doc && newFocus == doc->GetRootElement()) {
|
2010-04-21 06:13:08 -07:00
|
|
|
nsIContent *bodyContent =
|
|
|
|
nsLayoutUtils::GetEditableRootContentByContentEditable(doc);
|
|
|
|
if (bodyContent) {
|
|
|
|
nsIFrame* bodyFrame = bodyContent->GetPrimaryFrame();
|
|
|
|
if (bodyFrame) {
|
|
|
|
currFrame = bodyFrame;
|
|
|
|
newFocus = bodyContent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
// When the mouse is pressed, the default action is to focus the
|
|
|
|
// target. Look for the nearest enclosing focusable frame.
|
2007-03-22 10:30:00 -07:00
|
|
|
while (currFrame) {
|
|
|
|
// If the mousedown happened inside a popup, don't
|
|
|
|
// try to set focus on one of its containing elements
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleDisplay* display = currFrame->StyleDisplay();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (display->mDisplay == NS_STYLE_DISPLAY_POPUP) {
|
2012-07-30 07:20:58 -07:00
|
|
|
newFocus = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t tabIndexUnused;
|
2011-10-17 07:59:28 -07:00
|
|
|
if (currFrame->IsFocusable(&tabIndexUnused, true)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
newFocus = currFrame->GetContent();
|
|
|
|
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(newFocus));
|
|
|
|
if (domElement)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
currFrame = currFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
// if something was found to focus, focus it. Otherwise, if the
|
|
|
|
// element that was clicked doesn't have -moz-user-focus: ignore,
|
|
|
|
// clear the existing focus. For -moz-user-focus: ignore, the focus
|
|
|
|
// is just left as is.
|
|
|
|
// Another effect of mouse clicking, handled in nsSelection, is that
|
|
|
|
// it should update the caret position to where the mouse was
|
|
|
|
// clicked. Because the focus is cleared when clicking on a
|
|
|
|
// non-focusable node, the next press of the tab key will cause
|
|
|
|
// focus to be shifted from the caret position instead of the root.
|
|
|
|
if (newFocus && currFrame) {
|
|
|
|
// use the mouse flag and the noscroll flag so that the content
|
|
|
|
// doesn't unexpectedly scroll when clicking an element that is
|
|
|
|
// only hald visible
|
|
|
|
nsCOMPtr<nsIDOMElement> newFocusElement = do_QueryInterface(newFocus);
|
|
|
|
fm->SetFocus(newFocusElement, nsIFocusManager::FLAG_BYMOUSE |
|
|
|
|
nsIFocusManager::FLAG_NOSCROLL);
|
|
|
|
}
|
|
|
|
else if (!suppressBlur) {
|
|
|
|
// clear the focus within the frame and then set it as the
|
|
|
|
// focused frame
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
if (mDocument) {
|
2010-04-21 07:53:42 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (!activeContent || !activeContent->IsXUL())
|
|
|
|
#endif
|
|
|
|
fm->ClearFocus(mDocument->GetWindow());
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
fm->SetFocusedWindow(mDocument->GetWindow());
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// The rest is left button-specific.
|
2007-07-08 00:08:04 -07:00
|
|
|
if (static_cast<nsMouseEvent*>(aEvent)->button !=
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent::eLeftButton)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (activeContent) {
|
|
|
|
// The nearest enclosing element goes into the
|
|
|
|
// :active state. If we fail the QI to DOMElement,
|
|
|
|
// then we know we're only a node, and that we need
|
|
|
|
// to obtain our parent element and put it into :active
|
|
|
|
// instead.
|
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(activeContent));
|
|
|
|
if (!elt) {
|
|
|
|
nsIContent* par = activeContent->GetParent();
|
|
|
|
if (par)
|
|
|
|
activeContent = par;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if we're here, the event handler returned false, so stop
|
|
|
|
// any of our own processing of a drag. Workaround for bug 43258.
|
|
|
|
StopTrackingDragGesture();
|
2011-01-24 06:50:37 -08:00
|
|
|
|
|
|
|
// When the event was cancelled, there is currently a chrome document
|
|
|
|
// focused and a mousedown just occurred on a content document, ensure
|
|
|
|
// that the window that was clicked is focused.
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (mDocument && fm) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> currentWindow;
|
|
|
|
fm->GetFocusedWindow(getter_AddRefs(currentWindow));
|
2012-10-11 15:43:42 -07:00
|
|
|
if (currentWindow && mDocument->GetWindow() &&
|
|
|
|
currentWindow != mDocument->GetWindow() &&
|
2011-01-24 06:50:37 -08:00
|
|
|
!nsContentUtils::IsChromeDoc(mDocument)) {
|
2012-10-11 15:43:42 -07:00
|
|
|
nsCOMPtr<nsIDOMWindow> currentTop;
|
|
|
|
nsCOMPtr<nsIDOMWindow> newTop;
|
2012-10-13 18:43:24 -07:00
|
|
|
currentWindow->GetTop(getter_AddRefs(currentTop));
|
|
|
|
mDocument->GetWindow()->GetTop(getter_AddRefs(newTop));
|
2011-01-24 06:50:37 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(currentWindow);
|
|
|
|
nsCOMPtr<nsIDocument> currentDoc = do_QueryInterface(win->GetExtantDocument());
|
2012-10-11 15:43:42 -07:00
|
|
|
if (nsContentUtils::IsChromeDoc(currentDoc) ||
|
|
|
|
(currentTop && newTop && currentTop != newTop)) {
|
2011-01-24 06:50:37 -08:00
|
|
|
fm->SetFocusedWindow(mDocument->GetWindow());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-10-28 07:11:15 -07:00
|
|
|
SetActiveManager(this, activeContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_BUTTON_UP:
|
|
|
|
{
|
2010-10-28 07:11:15 -07:00
|
|
|
ClearGlobalActiveContent(this);
|
2010-03-23 20:36:27 -07:00
|
|
|
if (IsMouseEventReal(aEvent)) {
|
|
|
|
if (!mCurrentTarget) {
|
2011-04-21 10:35:52 -07:00
|
|
|
GetEventTarget();
|
2010-03-23 20:36:27 -07:00
|
|
|
}
|
2012-06-07 03:06:39 -07:00
|
|
|
// Make sure to dispatch the click even if there is no frame for
|
|
|
|
// the current target element. This is required for Web compatibility.
|
|
|
|
ret = CheckForAndDispatchClick(presContext, (nsMouseEvent*)aEvent,
|
|
|
|
aStatus);
|
2007-11-20 14:30:27 -08:00
|
|
|
}
|
2009-09-13 06:13:16 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIPresShell *shell = presContext->GetPresShell();
|
|
|
|
if (shell) {
|
2011-05-18 20:10:49 -07:00
|
|
|
nsRefPtr<nsFrameSelection> frameSelection = shell->FrameSelection();
|
2011-10-17 07:59:28 -07:00
|
|
|
frameSelection->SetMouseDownState(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-08-11 18:42:35 -07:00
|
|
|
case NS_WHEEL_WHEEL:
|
2008-09-17 04:27:19 -07:00
|
|
|
{
|
2012-12-15 17:26:03 -08:00
|
|
|
MOZ_ASSERT(aEvent->mFlags.mIsTrusted);
|
2012-08-11 18:42:35 -07:00
|
|
|
|
|
|
|
if (*aStatus == nsEventStatus_eConsumeNoDefault) {
|
|
|
|
break;
|
2008-09-17 04:27:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* wheelEvent = static_cast<widget::WheelEvent*>(aEvent);
|
2012-08-11 18:42:36 -07:00
|
|
|
switch (WheelPrefs::GetInstance()->ComputeActionFor(wheelEvent)) {
|
|
|
|
case WheelPrefs::ACTION_SCROLL: {
|
2013-01-05 04:14:27 -08:00
|
|
|
if (!wheelEvent->deltaX && !wheelEvent->deltaY) {
|
|
|
|
break;
|
|
|
|
}
|
2012-08-11 18:42:36 -07:00
|
|
|
// For scrolling of default action, we should honor the mouse wheel
|
|
|
|
// transaction.
|
|
|
|
nsIScrollableFrame* scrollTarget =
|
2012-09-04 01:39:28 -07:00
|
|
|
ComputeScrollTarget(aTargetFrame, wheelEvent,
|
|
|
|
COMPUTE_DEFAULT_ACTION_TARGET);
|
2012-08-14 17:52:07 -07:00
|
|
|
wheelEvent->overflowDeltaX = wheelEvent->deltaX;
|
|
|
|
wheelEvent->overflowDeltaY = wheelEvent->deltaY;
|
|
|
|
WheelPrefs::GetInstance()->
|
|
|
|
CancelApplyingUserPrefsFromOverflowDelta(wheelEvent);
|
2012-08-11 18:42:36 -07:00
|
|
|
if (scrollTarget) {
|
|
|
|
DoScrollText(scrollTarget, wheelEvent);
|
|
|
|
} else {
|
|
|
|
nsMouseWheelTransaction::EndTransaction();
|
2012-03-26 04:34:10 -07:00
|
|
|
}
|
2008-09-17 04:27:19 -07:00
|
|
|
break;
|
2012-08-11 18:42:36 -07:00
|
|
|
}
|
2013-01-05 04:14:27 -08:00
|
|
|
case WheelPrefs::ACTION_HISTORY: {
|
|
|
|
// If this event doesn't cause NS_MOUSE_SCROLL event or the direction
|
|
|
|
// is oblique, don't perform history back/forward.
|
|
|
|
int32_t intDelta = wheelEvent->GetPreferredIntDelta();
|
|
|
|
if (!intDelta) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DoScrollHistory(intDelta);
|
2008-09-17 04:27:19 -07:00
|
|
|
break;
|
2013-01-05 04:14:27 -08:00
|
|
|
}
|
|
|
|
case WheelPrefs::ACTION_ZOOM: {
|
|
|
|
// If this event doesn't cause NS_MOUSE_SCROLL event or the direction
|
|
|
|
// is oblique, don't perform zoom in/out.
|
|
|
|
int32_t intDelta = wheelEvent->GetPreferredIntDelta();
|
|
|
|
if (!intDelta) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DoScrollZoom(aTargetFrame, intDelta);
|
2008-09-17 04:27:19 -07:00
|
|
|
break;
|
2013-01-05 04:14:27 -08:00
|
|
|
}
|
|
|
|
case WheelPrefs::ACTION_NONE:
|
2012-08-11 20:32:30 -07:00
|
|
|
default:
|
2013-01-05 04:14:27 -08:00
|
|
|
// If we don't handle the wheel event, all of the delta values must
|
|
|
|
// be overflown delta values.
|
|
|
|
wheelEvent->overflowDeltaX = wheelEvent->deltaX;
|
|
|
|
wheelEvent->overflowDeltaY = wheelEvent->deltaY;
|
|
|
|
WheelPrefs::GetInstance()->
|
|
|
|
CancelApplyingUserPrefsFromOverflowDelta(wheelEvent);
|
2012-08-11 20:32:30 -07:00
|
|
|
break;
|
2008-09-17 04:27:19 -07:00
|
|
|
}
|
2012-08-11 18:42:36 -07:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
2008-09-17 04:27:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
2009-08-13 13:54:09 -07:00
|
|
|
case NS_GESTURENOTIFY_EVENT_START:
|
|
|
|
{
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus)
|
|
|
|
DecideGestureEvent(static_cast<nsGestureNotifyEvent*>(aEvent), mCurrentTarget);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
case NS_DRAGDROP_ENTER:
|
|
|
|
case NS_DRAGDROP_OVER:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent->eventStructType == NS_DRAG_EVENT, "Expected a drag event");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
|
|
|
|
if (!dragSession)
|
|
|
|
break;
|
|
|
|
|
2009-10-29 04:11:02 -07:00
|
|
|
// Reset the flag.
|
2011-10-17 07:59:28 -07:00
|
|
|
dragSession->SetOnlyChromeDrop(false);
|
2009-10-29 04:11:02 -07:00
|
|
|
if (mPresContext) {
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChromeDoc = nsContentUtils::IsChromeDoc(mDocument);
|
2009-10-29 04:11:02 -07:00
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
// the initial dataTransfer is the one from the dragstart event that
|
|
|
|
// was set on the dragSession when the drag began.
|
2012-02-07 10:02:32 -08:00
|
|
|
nsCOMPtr<nsIDOMDataTransfer> dataTransfer;
|
2008-08-27 05:07:27 -07:00
|
|
|
nsCOMPtr<nsIDOMDataTransfer> initialDataTransfer;
|
|
|
|
dragSession->GetDataTransfer(getter_AddRefs(initialDataTransfer));
|
|
|
|
|
2009-10-06 19:51:02 -07:00
|
|
|
nsDragEvent *dragEvent = (nsDragEvent*)aEvent;
|
|
|
|
|
|
|
|
// collect any changes to moz cursor settings stored in the event's
|
|
|
|
// data transfer.
|
|
|
|
UpdateDragDataTransfer(dragEvent);
|
|
|
|
|
2008-08-27 05:07:27 -07:00
|
|
|
// cancelling a dragenter or dragover event means that a drop should be
|
|
|
|
// allowed, so update the dropEffect and the canDrop state to indicate
|
|
|
|
// that a drag is allowed. If the event isn't cancelled, a drop won't be
|
|
|
|
// allowed. Essentially, to allow a drop somewhere, specify the effects
|
|
|
|
// using the effectAllowed and dropEffect properties in a dragenter or
|
|
|
|
// dragover event and cancel the event. To not allow a drop somewhere,
|
|
|
|
// don't cancel the event or set the effectAllowed or dropEffect to
|
|
|
|
// "none". This way, if the event is just ignored, no drop will be
|
|
|
|
// allowed.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t dropEffect = nsIDragService::DRAGDROP_ACTION_NONE;
|
2008-08-27 05:07:27 -07:00
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aStatus) {
|
|
|
|
// if the event has a dataTransfer set, use it.
|
|
|
|
if (dragEvent->dataTransfer) {
|
|
|
|
// get the dataTransfer and the dropEffect that was set on it
|
|
|
|
dataTransfer = do_QueryInterface(dragEvent->dataTransfer);
|
|
|
|
dataTransfer->GetDropEffectInt(&dropEffect);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// if dragEvent->dataTransfer is null, it means that no attempt was
|
|
|
|
// made to access the dataTransfer during the event, yet the event
|
|
|
|
// was cancelled. Instead, use the initial data transfer available
|
|
|
|
// from the drag session. The drop effect would not have been
|
|
|
|
// initialized (which is done in nsDOMDragEvent::GetDataTransfer),
|
|
|
|
// so set it from the drag action. We'll still want to filter it
|
|
|
|
// based on the effectAllowed below.
|
2012-02-07 10:02:32 -08:00
|
|
|
dataTransfer = initialDataTransfer;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t action;
|
2008-08-27 05:07:27 -07:00
|
|
|
dragSession->GetDragAction(&action);
|
|
|
|
|
|
|
|
// filter the drop effect based on the action. Use UNINITIALIZED as
|
|
|
|
// any effect is allowed.
|
2009-06-24 10:12:33 -07:00
|
|
|
dropEffect = nsContentUtils::FilterDropEffect(action,
|
2008-08-27 05:07:27 -07:00
|
|
|
nsIDragService::DRAGDROP_ACTION_UNINITIALIZED);
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point, if the dataTransfer is null, it means that the
|
|
|
|
// drag was originally started by directly calling the drag service.
|
|
|
|
// Just assume that all effects are allowed.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t effectAllowed = nsIDragService::DRAGDROP_ACTION_UNINITIALIZED;
|
2008-08-27 05:07:27 -07:00
|
|
|
if (dataTransfer)
|
|
|
|
dataTransfer->GetEffectAllowedInt(&effectAllowed);
|
|
|
|
|
|
|
|
// set the drag action based on the drop effect and effect allowed.
|
|
|
|
// The drop effect field on the drag transfer object specifies the
|
|
|
|
// desired current drop effect. However, it cannot be used if the
|
|
|
|
// effectAllowed state doesn't include that type of action. If the
|
|
|
|
// dropEffect is "none", then the action will be 'none' so a drop will
|
|
|
|
// not be allowed.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t action = nsIDragService::DRAGDROP_ACTION_NONE;
|
2008-08-27 05:07:27 -07:00
|
|
|
if (effectAllowed == nsIDragService::DRAGDROP_ACTION_UNINITIALIZED ||
|
|
|
|
dropEffect & effectAllowed)
|
|
|
|
action = dropEffect;
|
|
|
|
|
|
|
|
if (action == nsIDragService::DRAGDROP_ACTION_NONE)
|
|
|
|
dropEffect = nsIDragService::DRAGDROP_ACTION_NONE;
|
|
|
|
|
|
|
|
// inform the drag session that a drop is allowed on this node.
|
|
|
|
dragSession->SetDragAction(action);
|
|
|
|
dragSession->SetCanDrop(action != nsIDragService::DRAGDROP_ACTION_NONE);
|
2009-10-29 04:11:02 -07:00
|
|
|
|
|
|
|
// For now, do this only for dragover.
|
|
|
|
//XXXsmaug dragenter needs some more work.
|
|
|
|
if (aEvent->message == NS_DRAGDROP_OVER && !isChromeDoc) {
|
|
|
|
// Someone has called preventDefault(), check whether is was content.
|
|
|
|
dragSession->SetOnlyChromeDrop(
|
2012-12-15 17:26:04 -08:00
|
|
|
!aEvent->mFlags.mDefaultPreventedByContent);
|
2009-10-29 04:11:02 -07:00
|
|
|
}
|
|
|
|
} else if (aEvent->message == NS_DRAGDROP_OVER && !isChromeDoc) {
|
2009-11-05 06:39:18 -08:00
|
|
|
// No one called preventDefault(), so handle drop only in chrome.
|
2011-10-17 07:59:28 -07:00
|
|
|
dragSession->SetOnlyChromeDrop(true);
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// now set the drop effect in the initial dataTransfer. This ensures
|
|
|
|
// that we can get the desired drop effect in the drop event.
|
2012-02-07 10:02:32 -08:00
|
|
|
if (initialDataTransfer)
|
|
|
|
initialDataTransfer->SetDropEffectInt(dropEffect);
|
2008-08-27 05:07:27 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_DRAGDROP_DROP:
|
2008-08-27 05:07:27 -07:00
|
|
|
{
|
|
|
|
// now fire the dragdrop event, for compatibility with XUL
|
|
|
|
if (mCurrentTarget && nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
2011-09-26 13:55:04 -07:00
|
|
|
mCurrentTarget->GetContentForEvent(aEvent,
|
2008-08-27 05:07:27 -07:00
|
|
|
getter_AddRefs(targetContent));
|
|
|
|
|
2010-07-02 12:11:04 -07:00
|
|
|
nsCOMPtr<nsIWidget> widget = mCurrentTarget->GetNearestWidget();
|
2012-12-15 17:26:03 -08:00
|
|
|
nsDragEvent event(aEvent->mFlags.mIsTrusted,
|
|
|
|
NS_DRAGDROP_DRAGDROP, widget);
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
nsMouseEvent* mouseEvent = static_cast<nsMouseEvent*>(aEvent);
|
|
|
|
event.refPoint = mouseEvent->refPoint;
|
2010-06-25 14:51:17 -07:00
|
|
|
if (mouseEvent->widget) {
|
|
|
|
event.refPoint += mouseEvent->widget->WidgetToScreenOffset();
|
|
|
|
}
|
|
|
|
event.refPoint -= widget->WidgetToScreenOffset();
|
2012-04-24 20:00:01 -07:00
|
|
|
event.modifiers = mouseEvent->modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.buttons = mouseEvent->buttons;
|
2010-04-06 05:59:24 -07:00
|
|
|
event.inputSource = mouseEvent->inputSource;
|
2008-08-27 05:07:27 -07:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
presShell->HandleEventWithTarget(&event, mCurrentTarget,
|
|
|
|
targetContent, &status);
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
sLastDragOverFrame = nullptr;
|
2010-10-28 07:11:15 -07:00
|
|
|
ClearGlobalActiveContent(this);
|
2008-08-27 05:07:27 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_DRAGDROP_EXIT:
|
2008-08-27 05:07:27 -07:00
|
|
|
// make sure to fire the enter and exit_synth events after the
|
|
|
|
// NS_DRAGDROP_EXIT event, otherwise we'll clean up too early
|
2007-03-22 10:30:00 -07:00
|
|
|
GenerateDragDropEnterExit(presContext, (nsGUIEvent*)aEvent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_KEY_UP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_KEY_PRESS:
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
|
|
|
//This is to prevent keyboard scrolling while alt modifier in use.
|
2012-04-24 20:00:02 -07:00
|
|
|
if (!keyEvent->IsAlt()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(keyEvent->keyCode) {
|
|
|
|
case NS_VK_TAB:
|
|
|
|
case NS_VK_F6:
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm && mDocument) {
|
|
|
|
// Shift focus forward or back depending on shift key
|
2012-04-24 20:00:02 -07:00
|
|
|
bool isDocMove = ((nsInputEvent*)aEvent)->IsControl() ||
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
(keyEvent->keyCode == NS_VK_F6);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t dir =
|
2012-04-24 20:00:02 -07:00
|
|
|
static_cast<nsInputEvent*>(aEvent)->IsShift() ?
|
2012-08-22 08:56:38 -07:00
|
|
|
(isDocMove ? static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_BACKWARDDOC) :
|
|
|
|
static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_BACKWARD)) :
|
|
|
|
(isDocMove ? static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_FORWARDDOC) :
|
|
|
|
static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_FORWARD));
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> result;
|
2012-07-30 07:20:58 -07:00
|
|
|
fm->MoveFocus(mDocument->GetWindow(), nullptr, dir,
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIFocusManager::FLAG_BYKEY,
|
|
|
|
getter_AddRefs(result));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_MOUSE_ENTER:
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
2011-09-26 13:55:04 -07:00
|
|
|
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(targetContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
SetContentState(targetContent, NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
|
|
|
break;
|
2010-07-16 05:50:28 -07:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case NS_MOUSE_ACTIVATE:
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
2011-09-26 13:55:04 -07:00
|
|
|
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(targetContent));
|
2010-07-16 05:50:28 -07:00
|
|
|
if (!NodeAllowsClickThrough(targetContent)) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//Reset target frame to null to avoid mistargeting after reentrant event
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentTarget = nullptr;
|
|
|
|
mCurrentTargetContent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-09-23 20:28:15 -07:00
|
|
|
nsEventStateManager::RemoteQueryContentEvent(nsEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsQueryContentEvent *queryEvent =
|
|
|
|
static_cast<nsQueryContentEvent*>(aEvent);
|
|
|
|
if (!IsTargetCrossProcess(queryEvent)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
// Will not be handled locally, remote the event
|
|
|
|
GetCrossProcessTarget()->HandleQueryContentEvent(*queryEvent);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TabParent*
|
2010-08-17 01:07:44 -07:00
|
|
|
nsEventStateManager::GetCrossProcessTarget()
|
|
|
|
{
|
2010-09-23 20:28:15 -07:00
|
|
|
return TabParent::GetIMETabParent();
|
2010-08-17 01:07:44 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-17 01:07:44 -07:00
|
|
|
nsEventStateManager::IsTargetCrossProcess(nsGUIEvent *aEvent)
|
|
|
|
{
|
2010-09-27 14:46:51 -07:00
|
|
|
// Check to see if there is a focused, editable content in chrome,
|
|
|
|
// in that case, do not forward IME events to content
|
|
|
|
nsIContent *focusedContent = GetFocusedContent();
|
|
|
|
if (focusedContent && focusedContent->IsEditable())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2012-07-30 07:20:58 -07:00
|
|
|
return TabParent::GetIMETabParent() != nullptr;
|
2010-08-17 01:07:44 -07:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStateManager::NotifyDestroyPresContext(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsIMEStateManager::OnDestroyPresContext(aPresContext);
|
2012-05-17 20:11:27 -07:00
|
|
|
if (mHoverContent) {
|
|
|
|
// Bug 70855: Presentation is going away, possibly for a reframe.
|
|
|
|
// Reset the hover state so that if we're recreating the presentation,
|
|
|
|
// we won't have the old hover state still set in the new presentation,
|
|
|
|
// as if the new presentation is resized, a new element may be hovered.
|
2012-07-30 07:20:58 -07:00
|
|
|
SetContentState(nullptr, NS_EVENT_STATE_HOVER);
|
2012-05-17 20:11:27 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStateManager::SetPresContext(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
mPresContext = aPresContext;
|
|
|
|
}
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStateManager::ClearFrameRefs(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (aFrame && aFrame == mCurrentTarget) {
|
|
|
|
mCurrentTargetContent = aFrame->GetContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::UpdateCursor(nsPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent, nsIFrame* aTargetFrame,
|
|
|
|
nsEventStatus* aStatus)
|
|
|
|
{
|
2011-06-21 17:32:43 -07:00
|
|
|
if (aTargetFrame && IsRemoteTarget(aTargetFrame->GetContent())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t cursor = NS_STYLE_CURSOR_DEFAULT;
|
2012-07-30 07:20:58 -07:00
|
|
|
imgIContainer* container = nullptr;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool haveHotspot = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
float hotspotX = 0.0f, hotspotY = 0.0f;
|
|
|
|
|
|
|
|
//If cursor is locked just use the locked one
|
|
|
|
if (mLockCursor) {
|
|
|
|
cursor = mLockCursor;
|
|
|
|
}
|
|
|
|
//If not locked, look for correct cursor
|
|
|
|
else if (aTargetFrame) {
|
|
|
|
nsIFrame::Cursor framecursor;
|
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
|
|
|
|
aTargetFrame);
|
|
|
|
if (NS_FAILED(aTargetFrame->GetCursor(pt, framecursor)))
|
|
|
|
return; // don't update the cursor if we failed to get it from the frame see bug 118877
|
|
|
|
cursor = framecursor.mCursor;
|
|
|
|
container = framecursor.mContainer;
|
|
|
|
haveHotspot = framecursor.mHaveHotspot;
|
|
|
|
hotspotX = framecursor.mHotspotX;
|
|
|
|
hotspotY = framecursor.mHotspotY;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("ui.use_activity_cursor", false)) {
|
2009-09-17 06:04:08 -07:00
|
|
|
// Check whether or not to show the busy cursor
|
|
|
|
nsCOMPtr<nsISupports> pcContainer = aPresContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(pcContainer));
|
|
|
|
if (!docShell) return;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
|
2009-09-17 06:04:08 -07:00
|
|
|
docShell->GetBusyFlags(&busyFlags);
|
|
|
|
|
|
|
|
// Show busy cursor everywhere before page loads
|
|
|
|
// and just replace the arrow cursor after page starts loading
|
|
|
|
if (busyFlags & nsIDocShell::BUSY_FLAGS_BUSY &&
|
|
|
|
(cursor == NS_STYLE_CURSOR_AUTO || cursor == NS_STYLE_CURSOR_DEFAULT))
|
|
|
|
{
|
|
|
|
cursor = NS_STYLE_CURSOR_SPINNING;
|
2012-07-30 07:20:58 -07:00
|
|
|
container = nullptr;
|
2009-09-17 06:04:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aTargetFrame) {
|
|
|
|
SetCursor(cursor, container, haveHotspot, hotspotX, hotspotY,
|
2011-10-17 07:59:28 -07:00
|
|
|
aTargetFrame->GetNearestWidget(), false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mLockCursor || NS_STYLE_CURSOR_AUTO != cursor) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsEventStateManager::SetCursor(int32_t aCursor, imgIContainer* aContainer,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aHaveHotspot,
|
2007-03-22 10:30:00 -07:00
|
|
|
float aHotspotX, float aHotspotY,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIWidget* aWidget, bool aLockCursor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-17 11:56:53 -07:00
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
|
|
|
|
sMouseOverDocument = mDocument.get();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCursor c;
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aWidget, NS_ERROR_FAILURE);
|
|
|
|
if (aLockCursor) {
|
|
|
|
if (NS_STYLE_CURSOR_AUTO != aCursor) {
|
|
|
|
mLockCursor = aCursor;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//If cursor style is set to auto we unlock the cursor again.
|
|
|
|
mLockCursor = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (aCursor) {
|
|
|
|
default:
|
|
|
|
case NS_STYLE_CURSOR_AUTO:
|
|
|
|
case NS_STYLE_CURSOR_DEFAULT:
|
|
|
|
c = eCursor_standard;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_POINTER:
|
|
|
|
c = eCursor_hyperlink;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_CROSSHAIR:
|
|
|
|
c = eCursor_crosshair;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_MOVE:
|
|
|
|
c = eCursor_move;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_TEXT:
|
|
|
|
c = eCursor_select;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_WAIT:
|
|
|
|
c = eCursor_wait;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_HELP:
|
|
|
|
c = eCursor_help;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_N_RESIZE:
|
|
|
|
c = eCursor_n_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_S_RESIZE:
|
|
|
|
c = eCursor_s_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_W_RESIZE:
|
|
|
|
c = eCursor_w_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_E_RESIZE:
|
|
|
|
c = eCursor_e_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NW_RESIZE:
|
|
|
|
c = eCursor_nw_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_SE_RESIZE:
|
|
|
|
c = eCursor_se_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NE_RESIZE:
|
|
|
|
c = eCursor_ne_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_SW_RESIZE:
|
|
|
|
c = eCursor_sw_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_COPY: // CSS3
|
|
|
|
c = eCursor_copy;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_ALIAS:
|
|
|
|
c = eCursor_alias;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_CONTEXT_MENU:
|
|
|
|
c = eCursor_context_menu;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_CELL:
|
|
|
|
c = eCursor_cell;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_GRAB:
|
|
|
|
c = eCursor_grab;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_GRABBING:
|
|
|
|
c = eCursor_grabbing;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_SPINNING:
|
|
|
|
c = eCursor_spinning;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_MOZ_ZOOM_IN:
|
|
|
|
c = eCursor_zoom_in;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_MOZ_ZOOM_OUT:
|
|
|
|
c = eCursor_zoom_out;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NOT_ALLOWED:
|
|
|
|
c = eCursor_not_allowed;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_COL_RESIZE:
|
|
|
|
c = eCursor_col_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_ROW_RESIZE:
|
|
|
|
c = eCursor_row_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NO_DROP:
|
|
|
|
c = eCursor_no_drop;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_VERTICAL_TEXT:
|
|
|
|
c = eCursor_vertical_text;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_ALL_SCROLL:
|
|
|
|
c = eCursor_all_scroll;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NESW_RESIZE:
|
|
|
|
c = eCursor_nesw_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NWSE_RESIZE:
|
|
|
|
c = eCursor_nwse_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NS_RESIZE:
|
|
|
|
c = eCursor_ns_resize;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_EW_RESIZE:
|
|
|
|
c = eCursor_ew_resize;
|
|
|
|
break;
|
2008-01-18 10:39:49 -08:00
|
|
|
case NS_STYLE_CURSOR_NONE:
|
|
|
|
c = eCursor_none;
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// First, try the imgIContainer, if non-null
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
if (aContainer) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t hotspotX, hotspotY;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// css3-ui says to use the CSS-specified hotspot if present,
|
|
|
|
// otherwise use the intrinsic hotspot, otherwise use the top left
|
|
|
|
// corner.
|
|
|
|
if (aHaveHotspot) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t imgWidth, imgHeight;
|
2007-03-22 10:30:00 -07:00
|
|
|
aContainer->GetWidth(&imgWidth);
|
|
|
|
aContainer->GetHeight(&imgHeight);
|
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
// XXX std::max(NS_lround(x), 0)?
|
2007-03-22 10:30:00 -07:00
|
|
|
hotspotX = aHotspotX > 0.0f
|
2012-08-22 08:56:38 -07:00
|
|
|
? uint32_t(aHotspotX + 0.5f) : uint32_t(0);
|
|
|
|
if (hotspotX >= uint32_t(imgWidth))
|
2007-03-22 10:30:00 -07:00
|
|
|
hotspotX = imgWidth - 1;
|
|
|
|
hotspotY = aHotspotY > 0.0f
|
2012-08-22 08:56:38 -07:00
|
|
|
? uint32_t(aHotspotY + 0.5f) : uint32_t(0);
|
|
|
|
if (hotspotY >= uint32_t(imgHeight))
|
2007-03-22 10:30:00 -07:00
|
|
|
hotspotY = imgHeight - 1;
|
|
|
|
} else {
|
|
|
|
hotspotX = 0;
|
|
|
|
hotspotY = 0;
|
|
|
|
nsCOMPtr<nsIProperties> props(do_QueryInterface(aContainer));
|
|
|
|
if (props) {
|
|
|
|
nsCOMPtr<nsISupportsPRUint32> hotspotXWrap, hotspotYWrap;
|
|
|
|
|
|
|
|
props->Get("hotspotX", NS_GET_IID(nsISupportsPRUint32), getter_AddRefs(hotspotXWrap));
|
|
|
|
props->Get("hotspotY", NS_GET_IID(nsISupportsPRUint32), getter_AddRefs(hotspotYWrap));
|
|
|
|
|
|
|
|
if (hotspotXWrap)
|
|
|
|
hotspotXWrap->GetData(&hotspotX);
|
|
|
|
if (hotspotYWrap)
|
|
|
|
hotspotYWrap->GetData(&hotspotY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = aWidget->SetCursor(aContainer, hotspotX, hotspotY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
aWidget->SetCursor(c);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-11 20:20:09 -07:00
|
|
|
class MOZ_STACK_CLASS nsESMEventCB : public nsDispatchingCallback
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsESMEventCB(nsIContent* aTarget) : mTarget(aTarget) {}
|
|
|
|
|
|
|
|
virtual void HandleEvent(nsEventChainPostVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
if (aVisitor.mPresContext) {
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = aVisitor.mPresContext->GetPrimaryFrameFor(mTarget);
|
|
|
|
if (frame) {
|
|
|
|
frame->HandleEvent(aVisitor.mPresContext,
|
|
|
|
(nsGUIEvent*) aVisitor.mEvent,
|
|
|
|
&aVisitor.mEventStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> mTarget;
|
|
|
|
};
|
|
|
|
|
2013-01-23 11:39:34 -08:00
|
|
|
/*static*/ bool
|
|
|
|
nsEventStateManager::IsHandlingUserInput()
|
|
|
|
{
|
|
|
|
if (sUserInputEventDepth <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeDuration timeout = nsContentUtils::HandlingUserInputTimeout();
|
|
|
|
return timeout <= TimeDuration(0) ||
|
|
|
|
(TimeStamp::Now() - sHandlingInputStart) <= timeout;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame*
|
2012-08-22 08:56:38 -07:00
|
|
|
nsEventStateManager::DispatchMouseEvent(nsGUIEvent* aEvent, uint32_t aMessage,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* aTargetContent,
|
|
|
|
nsIContent* aRelatedContent)
|
|
|
|
{
|
2012-04-11 14:55:21 -07:00
|
|
|
// http://dvcs.w3.org/hg/webevents/raw-file/default/mouse-lock.html#methods
|
|
|
|
// "[When the mouse is locked on an element...e]vents that require the concept
|
|
|
|
// of a mouse cursor must not be dispatched (for example: mouseover, mouseout).
|
|
|
|
if (sIsPointerLocked &&
|
|
|
|
(aMessage == NS_MOUSELEAVE ||
|
|
|
|
aMessage == NS_MOUSEENTER ||
|
|
|
|
aMessage == NS_MOUSE_ENTER_SYNTH ||
|
|
|
|
aMessage == NS_MOUSE_EXIT_SYNTH)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentTargetContent = nullptr;
|
2012-04-11 14:55:21 -07:00
|
|
|
nsCOMPtr<Element> pointerLockedElement =
|
|
|
|
do_QueryReferent(nsEventStateManager::sPointerLockedElement);
|
|
|
|
if (!pointerLockedElement) {
|
|
|
|
NS_WARNING("Should have pointer locked element, but didn't.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(pointerLockedElement);
|
|
|
|
return mPresContext->GetPrimaryFrameFor(content);
|
|
|
|
}
|
|
|
|
|
2013-03-15 21:47:02 -07:00
|
|
|
PROFILER_LABEL("Input", "DispatchMouseEvent");
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2012-12-15 17:26:03 -08:00
|
|
|
nsMouseEvent event(aEvent->mFlags.mIsTrusted, aMessage, aEvent->widget,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent::eReal);
|
|
|
|
event.refPoint = aEvent->refPoint;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.modifiers = ((nsMouseEvent*)aEvent)->modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.buttons = ((nsMouseEvent*)aEvent)->buttons;
|
2009-11-10 13:55:38 -08:00
|
|
|
event.pluginEvent = ((nsMouseEvent*)aEvent)->pluginEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
event.relatedTarget = aRelatedContent;
|
2010-04-06 05:59:24 -07:00
|
|
|
event.inputSource = static_cast<nsMouseEvent*>(aEvent)->inputSource;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-27 16:15:08 -07:00
|
|
|
nsWeakFrame previousTarget = mCurrentTarget;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentTargetContent = aTargetContent;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* targetFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aTargetContent) {
|
|
|
|
nsESMEventCB callback(aTargetContent);
|
2012-07-30 07:20:58 -07:00
|
|
|
nsEventDispatcher::Dispatch(aTargetContent, mPresContext, &event, nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
&status, &callback);
|
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
// Although the primary frame was checked in event callback,
|
|
|
|
// it may not be the same object after event dispatching and handling.
|
|
|
|
// So we need to refetch it.
|
|
|
|
if (mPresContext) {
|
|
|
|
targetFrame = mPresContext->GetPrimaryFrameFor(aTargetContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentTargetContent = nullptr;
|
2010-08-27 16:15:08 -07:00
|
|
|
mCurrentTarget = previousTarget;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return targetFrame;
|
|
|
|
}
|
|
|
|
|
2011-09-18 00:45:14 -07:00
|
|
|
class MouseEnterLeaveDispatcher
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MouseEnterLeaveDispatcher(nsEventStateManager* aESM,
|
|
|
|
nsIContent* aTarget, nsIContent* aRelatedTarget,
|
2012-08-22 08:56:38 -07:00
|
|
|
nsGUIEvent* aEvent, uint32_t aType)
|
2011-09-18 00:45:14 -07:00
|
|
|
: mESM(aESM), mEvent(aEvent), mType(aType)
|
|
|
|
{
|
|
|
|
nsPIDOMWindow* win =
|
2012-07-30 07:20:58 -07:00
|
|
|
aTarget ? aTarget->OwnerDoc()->GetInnerWindow() : nullptr;
|
2011-09-18 00:45:14 -07:00
|
|
|
if (win && win->HasMouseEnterLeaveEventListeners()) {
|
|
|
|
mRelatedTarget = aRelatedTarget ?
|
2012-10-10 12:04:42 -07:00
|
|
|
aRelatedTarget->FindFirstNonChromeOnlyAccessContent() : nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsINode* commonParent = nullptr;
|
2011-09-18 00:45:14 -07:00
|
|
|
if (aTarget && aRelatedTarget) {
|
|
|
|
commonParent =
|
|
|
|
nsContentUtils::GetCommonAncestor(aTarget, aRelatedTarget);
|
|
|
|
}
|
|
|
|
nsIContent* current = aTarget;
|
|
|
|
// Note, it is ok if commonParent is null!
|
|
|
|
while (current && current != commonParent) {
|
2012-10-10 12:04:42 -07:00
|
|
|
if (!current->ChromeOnlyAccess()) {
|
2011-09-18 00:45:14 -07:00
|
|
|
mTargets.AppendObject(current);
|
|
|
|
}
|
|
|
|
// mouseenter/leave is fired only on elements.
|
|
|
|
current = current->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~MouseEnterLeaveDispatcher()
|
|
|
|
{
|
2012-06-23 05:41:47 -07:00
|
|
|
if (mType == NS_MOUSEENTER) {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = mTargets.Count() - 1; i >= 0; --i) {
|
2012-06-23 05:41:47 -07:00
|
|
|
mESM->DispatchMouseEvent(mEvent, mType, mTargets[i], mRelatedTarget);
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < mTargets.Count(); ++i) {
|
2012-06-23 05:41:47 -07:00
|
|
|
mESM->DispatchMouseEvent(mEvent, mType, mTargets[i], mRelatedTarget);
|
|
|
|
}
|
2011-09-18 00:45:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStateManager* mESM;
|
|
|
|
nsCOMArray<nsIContent> mTargets;
|
|
|
|
nsCOMPtr<nsIContent> mRelatedTarget;
|
|
|
|
nsGUIEvent* mEvent;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mType;
|
2011-09-18 00:45:14 -07:00
|
|
|
};
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::NotifyMouseOut(nsGUIEvent* aEvent, nsIContent* aMovingInto)
|
|
|
|
{
|
|
|
|
if (!mLastMouseOverElement)
|
|
|
|
return;
|
|
|
|
// Before firing mouseout, check for recursion
|
|
|
|
if (mLastMouseOverElement == mFirstMouseOutEventElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mLastMouseOverFrame) {
|
|
|
|
// if the frame is associated with a subdocument,
|
|
|
|
// tell the subdocument that we're moving out of it
|
2010-08-30 17:49:07 -07:00
|
|
|
nsSubDocumentFrame* subdocFrame = do_QueryFrame(mLastMouseOverFrame.GetFrame());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (subdocFrame) {
|
|
|
|
nsCOMPtr<nsIDocShell> docshell;
|
|
|
|
subdocFrame->GetDocShell(getter_AddRefs(docshell));
|
|
|
|
if (docshell) {
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
docshell->GetPresContext(getter_AddRefs(presContext));
|
2010-03-25 06:17:11 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (presContext) {
|
2011-04-21 10:35:52 -07:00
|
|
|
nsEventStateManager* kidESM = presContext->EventStateManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
// Not moving into any element in this subdocument
|
2012-07-30 07:20:58 -07:00
|
|
|
kidESM->NotifyMouseOut(aEvent, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// That could have caused DOM events which could wreak havoc. Reverify
|
|
|
|
// things and be careful.
|
|
|
|
if (!mLastMouseOverElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Store the first mouseOut event we fire and don't refire mouseOut
|
|
|
|
// to that element while the first mouseOut is still ongoing.
|
|
|
|
mFirstMouseOutEventElement = mLastMouseOverElement;
|
|
|
|
|
|
|
|
// Don't touch hover state if aMovingInto is non-null. Caller will update
|
|
|
|
// hover state itself, and we have optimizations for hover switching between
|
|
|
|
// two nearby elements both deep in the DOM tree that would be defeated by
|
|
|
|
// switching the hover state to null here.
|
|
|
|
if (!aMovingInto) {
|
|
|
|
// Unset :hover
|
2012-07-30 07:20:58 -07:00
|
|
|
SetContentState(nullptr, NS_EVENT_STATE_HOVER);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-09-18 00:45:14 -07:00
|
|
|
|
|
|
|
MouseEnterLeaveDispatcher leaveDispatcher(this, mLastMouseOverElement, aMovingInto,
|
|
|
|
aEvent, NS_MOUSELEAVE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Fire mouseout
|
|
|
|
DispatchMouseEvent(aEvent, NS_MOUSE_EXIT_SYNTH,
|
|
|
|
mLastMouseOverElement, aMovingInto);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastMouseOverFrame = nullptr;
|
|
|
|
mLastMouseOverElement = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Turn recursion protection back off
|
2012-07-30 07:20:58 -07:00
|
|
|
mFirstMouseOutEventElement = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::NotifyMouseOver(nsGUIEvent* aEvent, nsIContent* aContent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "Mouse must be over something");
|
|
|
|
|
|
|
|
if (mLastMouseOverElement == aContent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Before firing mouseover, check for recursion
|
|
|
|
if (aContent == mFirstMouseOverEventElement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check to see if we're a subdocument and if so update the parent
|
|
|
|
// document's ESM state to indicate that the mouse is over the
|
|
|
|
// content associated with our subdocument.
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
nsIDocument *parentDoc = mDocument->GetParentDocument();
|
|
|
|
if (parentDoc) {
|
|
|
|
nsIContent *docContent = parentDoc->FindContentForSubDocument(mDocument);
|
|
|
|
if (docContent) {
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell *parentShell = parentDoc->GetShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parentShell) {
|
2011-04-21 10:35:52 -07:00
|
|
|
nsEventStateManager* parentESM = parentShell->GetPresContext()->EventStateManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
parentESM->NotifyMouseOver(aEvent, docContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Firing the DOM event in the parent document could cause all kinds
|
|
|
|
// of havoc. Reverify and take care.
|
|
|
|
if (mLastMouseOverElement == aContent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Remember mLastMouseOverElement as the related content for the
|
|
|
|
// DispatchMouseEvent() call below, since NotifyMouseOut() resets it, bug 298477.
|
|
|
|
nsCOMPtr<nsIContent> lastMouseOverElement = mLastMouseOverElement;
|
|
|
|
|
2011-09-18 00:45:14 -07:00
|
|
|
MouseEnterLeaveDispatcher enterDispatcher(this, aContent, lastMouseOverElement,
|
|
|
|
aEvent, NS_MOUSEENTER);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NotifyMouseOut(aEvent, aContent);
|
|
|
|
|
|
|
|
// Store the first mouseOver event we fire and don't refire mouseOver
|
|
|
|
// to that element while the first mouseOver is still ongoing.
|
|
|
|
mFirstMouseOverEventElement = aContent;
|
|
|
|
|
|
|
|
SetContentState(aContent, NS_EVENT_STATE_HOVER);
|
|
|
|
|
|
|
|
// Fire mouseover
|
|
|
|
mLastMouseOverFrame = DispatchMouseEvent(aEvent, NS_MOUSE_ENTER_SYNTH,
|
|
|
|
aContent, lastMouseOverElement);
|
|
|
|
mLastMouseOverElement = aContent;
|
|
|
|
|
|
|
|
// Turn recursion protection back off
|
2012-07-30 07:20:58 -07:00
|
|
|
mFirstMouseOverEventElement = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-20 16:38:03 -07:00
|
|
|
// Returns the center point of the window's inner content area.
|
|
|
|
// This is in widget coordinates, i.e. relative to the widget's top
|
2012-09-24 16:43:27 -07:00
|
|
|
// left corner, not in screen coordinates, the same units that
|
|
|
|
// nsDOMUIEvent::refPoint is in.
|
2013-03-06 09:16:55 -08:00
|
|
|
//
|
|
|
|
// XXX Hack alert: XXX
|
|
|
|
// However, we do the computation in integer CSS pixels, NOT device pix,
|
|
|
|
// in order to fudge around the one-pixel error in innerHeight in fullscreen
|
|
|
|
// mode (see bug 799523 comment 35, and bug 729011). Using integer CSS pix
|
|
|
|
// makes us throw away the fractional error that results, rather than having
|
|
|
|
// it manifest as a potential one-device-pix discrepancy.
|
2012-06-20 16:38:03 -07:00
|
|
|
static nsIntPoint
|
|
|
|
GetWindowInnerRectCenter(nsPIDOMWindow* aWindow,
|
|
|
|
nsIWidget* aWidget,
|
|
|
|
nsPresContext* aContext)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aWindow && aWidget && aContext, nsIntPoint(0,0));
|
|
|
|
|
|
|
|
float cssInnerX = 0.0;
|
|
|
|
aWindow->GetMozInnerScreenX(&cssInnerX);
|
2013-03-06 09:16:55 -08:00
|
|
|
int32_t innerX = int32_t(NS_round(cssInnerX));
|
2012-06-20 16:38:03 -07:00
|
|
|
|
|
|
|
float cssInnerY = 0.0;
|
|
|
|
aWindow->GetMozInnerScreenY(&cssInnerY);
|
2013-03-06 09:16:55 -08:00
|
|
|
int32_t innerY = int32_t(NS_round(cssInnerY));
|
2012-06-20 16:38:03 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t innerWidth = 0;
|
2012-06-20 16:38:03 -07:00
|
|
|
aWindow->GetInnerWidth(&innerWidth);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t innerHeight = 0;
|
2012-06-20 16:38:03 -07:00
|
|
|
aWindow->GetInnerHeight(&innerHeight);
|
2013-03-06 09:16:08 -08:00
|
|
|
|
2012-06-20 16:38:03 -07:00
|
|
|
nsIntRect screen;
|
|
|
|
aWidget->GetScreenBounds(screen);
|
|
|
|
|
2013-03-06 09:16:55 -08:00
|
|
|
int32_t cssScreenX = aContext->DevPixelsToIntCSSPixels(screen.x);
|
|
|
|
int32_t cssScreenY = aContext->DevPixelsToIntCSSPixels(screen.y);
|
|
|
|
|
|
|
|
return nsIntPoint(
|
|
|
|
aContext->CSSPixelsToDevPixels(innerX - cssScreenX + innerWidth / 2),
|
|
|
|
aContext->CSSPixelsToDevPixels(innerY - cssScreenY + innerHeight / 2));
|
2012-06-20 16:38:03 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::GenerateMouseEnterExit(nsGUIEvent* aEvent)
|
|
|
|
{
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
if (!mDocument)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Hold onto old target content through the event and reset after.
|
|
|
|
nsCOMPtr<nsIContent> targetBeforeEvent = mCurrentTargetContent;
|
|
|
|
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
{
|
2012-09-24 16:44:03 -07:00
|
|
|
// Mouse movement is reported on the MouseEvent.movement{X,Y} fields.
|
|
|
|
// Movement is calculated in nsDOMUIEvent::GetMovementPoint() as:
|
|
|
|
// previous_mousemove_refPoint - current_mousemove_refPoint.
|
2012-04-11 14:55:21 -07:00
|
|
|
if (sIsPointerLocked && aEvent->widget) {
|
2012-09-24 16:44:03 -07:00
|
|
|
// The pointer is locked. If the pointer is not located at the center of
|
|
|
|
// the window, dispatch a synthetic mousemove to return the pointer there.
|
|
|
|
// Doing this between "real" pointer moves gives the impression that the
|
|
|
|
// (locked) pointer can continue moving and won't stop at the screen
|
|
|
|
// boundary. We cancel the synthetic event so that we don't end up
|
|
|
|
// dispatching the centering move event to content.
|
2012-06-20 16:38:03 -07:00
|
|
|
nsIntPoint center = GetWindowInnerRectCenter(mDocument->GetWindow(),
|
|
|
|
aEvent->widget,
|
|
|
|
mPresContext);
|
|
|
|
aEvent->lastRefPoint = center;
|
|
|
|
if (aEvent->refPoint != center) {
|
2012-09-24 16:44:03 -07:00
|
|
|
// Mouse move doesn't finish at the center of the window. Dispatch a
|
|
|
|
// synthetic native mouse event to move the pointer back to the center
|
|
|
|
// of the window, to faciliate more movement. But first, record that
|
|
|
|
// we've dispatched a synthetic mouse movement, so we can cancel it
|
|
|
|
// in the other branch here.
|
|
|
|
sSynthCenteringPoint = center;
|
2012-09-24 16:43:27 -07:00
|
|
|
aEvent->widget->SynthesizeNativeMouseMove(
|
|
|
|
center + aEvent->widget->WidgetToScreenOffset());
|
2012-09-24 16:44:03 -07:00
|
|
|
} else if (aEvent->refPoint == sSynthCenteringPoint) {
|
|
|
|
// This is the "synthetic native" event we dispatched to re-center the
|
|
|
|
// pointer. Cancel it so we don't expose the centering move to content.
|
2012-12-15 17:26:03 -08:00
|
|
|
aEvent->mFlags.mPropagationStopped = true;
|
2012-09-24 16:44:03 -07:00
|
|
|
// Clear sSynthCenteringPoint so we don't cancel other events
|
|
|
|
// targeted at the center.
|
2012-09-30 13:15:29 -07:00
|
|
|
sSynthCenteringPoint = kInvalidRefPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
2012-09-30 13:15:29 -07:00
|
|
|
} else if (sLastRefPoint == kInvalidRefPoint) {
|
|
|
|
// We don't have a valid previous mousemove refPoint. This is either
|
|
|
|
// the first move we've encountered, or the mouse has just re-entered
|
|
|
|
// the application window. We should report (0,0) movement for this
|
|
|
|
// case, so make the current and previous refPoints the same.
|
|
|
|
aEvent->lastRefPoint = aEvent->refPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
} else {
|
2012-06-20 16:38:03 -07:00
|
|
|
aEvent->lastRefPoint = sLastRefPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the last known refPoint with the current refPoint.
|
2012-06-20 16:38:03 -07:00
|
|
|
sLastRefPoint = aEvent->refPoint;
|
2012-04-11 14:55:21 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get the target content target (mousemove target == mouseover target)
|
2011-04-21 10:35:52 -07:00
|
|
|
nsCOMPtr<nsIContent> targetElement = GetEventTargetContent(aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!targetElement) {
|
|
|
|
// We're always over the document root, even if we're only
|
|
|
|
// over dead space in a page (whose frame is not associated with
|
|
|
|
// any content) or in print preview dead space
|
2010-04-30 06:12:05 -07:00
|
|
|
targetElement = mDocument->GetRootElement();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (targetElement) {
|
|
|
|
NotifyMouseOver(aEvent, targetElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_EXIT:
|
|
|
|
{
|
|
|
|
// This is actually the window mouse exit event. We're not moving
|
|
|
|
// into any new element.
|
2007-12-02 21:46:22 -08:00
|
|
|
|
|
|
|
if (mLastMouseOverFrame &&
|
|
|
|
nsContentUtils::GetTopLevelWidget(aEvent->widget) !=
|
2010-07-02 12:11:04 -07:00
|
|
|
nsContentUtils::GetTopLevelWidget(mLastMouseOverFrame->GetNearestWidget())) {
|
2007-12-02 21:46:22 -08:00
|
|
|
// the MouseOut event widget doesn't have same top widget with
|
|
|
|
// mLastMouseOverFrame, it's a spurious event for mLastMouseOverFrame
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-30 13:15:29 -07:00
|
|
|
// Reset sLastRefPoint, so that we'll know not to report any
|
|
|
|
// movement the next time we re-enter the window.
|
|
|
|
sLastRefPoint = kInvalidRefPoint;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NotifyMouseOut(aEvent, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reset mCurretTargetContent to what it was
|
|
|
|
mCurrentTargetContent = targetBeforeEvent;
|
|
|
|
}
|
|
|
|
|
2012-04-11 14:55:21 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::SetPointerLock(nsIWidget* aWidget,
|
|
|
|
nsIContent* aElement)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
// NOTE: aElement will be nullptr when unlocking.
|
2012-04-11 14:55:21 -07:00
|
|
|
sIsPointerLocked = !!aElement;
|
|
|
|
|
|
|
|
if (!aWidget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset mouse wheel transaction
|
|
|
|
nsMouseWheelTransaction::EndTransaction();
|
|
|
|
|
|
|
|
// Deal with DnD events
|
|
|
|
nsCOMPtr<nsIDragService> dragService =
|
|
|
|
do_GetService("@mozilla.org/widget/dragservice;1");
|
|
|
|
|
|
|
|
if (sIsPointerLocked) {
|
|
|
|
// Store the last known ref point so we can reposition the pointer after unlock.
|
2012-06-20 16:38:03 -07:00
|
|
|
mPreLockPoint = sLastRefPoint;
|
|
|
|
|
|
|
|
// Fire a synthetic mouse move to ensure event state is updated. We first
|
|
|
|
// set the mouse to the center of the window, so that the mouse event
|
|
|
|
// doesn't report any movement.
|
|
|
|
sLastRefPoint = GetWindowInnerRectCenter(aElement->OwnerDoc()->GetWindow(),
|
|
|
|
aWidget,
|
|
|
|
mPresContext);
|
2012-09-24 16:43:27 -07:00
|
|
|
aWidget->SynthesizeNativeMouseMove(
|
|
|
|
sLastRefPoint + aWidget->WidgetToScreenOffset());
|
2012-04-11 14:55:21 -07:00
|
|
|
|
|
|
|
// Retarget all events to this element via capture.
|
|
|
|
nsIPresShell::SetCapturingContent(aElement, CAPTURE_POINTERLOCK);
|
|
|
|
|
|
|
|
// Suppress DnD
|
|
|
|
if (dragService) {
|
|
|
|
dragService->Suppress();
|
|
|
|
}
|
|
|
|
} else {
|
2012-06-20 16:38:03 -07:00
|
|
|
// Unlocking, so return pointer to the original position by firing a
|
|
|
|
// synthetic mouse event. We first reset sLastRefPoint to its
|
|
|
|
// pre-pointerlock position, so that the synthetic mouse event reports
|
|
|
|
// no movement.
|
|
|
|
sLastRefPoint = mPreLockPoint;
|
2012-09-24 16:43:27 -07:00
|
|
|
aWidget->SynthesizeNativeMouseMove(
|
|
|
|
mPreLockPoint + aWidget->WidgetToScreenOffset());
|
2012-04-11 14:55:21 -07:00
|
|
|
|
|
|
|
// Don't retarget events to this element any more.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, CAPTURE_POINTERLOCK);
|
2012-04-11 14:55:21 -07:00
|
|
|
|
|
|
|
// Unsuppress DnD
|
|
|
|
if (dragService) {
|
|
|
|
dragService->Unsuppress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent)
|
|
|
|
{
|
|
|
|
//Hold onto old target content through the event and reset after.
|
|
|
|
nsCOMPtr<nsIContent> targetBeforeEvent = mCurrentTargetContent;
|
|
|
|
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_DRAGDROP_OVER:
|
|
|
|
{
|
2010-12-03 08:19:55 -08:00
|
|
|
// when dragging from one frame to another, events are fired in the
|
|
|
|
// order: dragexit, dragenter, dragleave
|
2011-09-26 13:55:04 -07:00
|
|
|
if (sLastDragOverFrame != mCurrentTarget) {
|
2007-03-22 10:30:00 -07:00
|
|
|
//We'll need the content, too, to check if it changed separately from the frames.
|
|
|
|
nsCOMPtr<nsIContent> lastContent;
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
2011-09-26 13:55:04 -07:00
|
|
|
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(targetContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-26 13:55:04 -07:00
|
|
|
if (sLastDragOverFrame) {
|
2007-04-11 21:37:39 -07:00
|
|
|
//The frame has changed but the content may not have. Check before dispatching to content
|
2011-09-26 13:55:04 -07:00
|
|
|
sLastDragOverFrame->GetContentForEvent(aEvent, getter_AddRefs(lastContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-26 13:55:04 -07:00
|
|
|
FireDragEnterOrExit(sLastDragOverFrame->PresContext(),
|
|
|
|
aEvent, NS_DRAGDROP_EXIT_SYNTH,
|
|
|
|
targetContent, lastContent, sLastDragOverFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:37:39 -07:00
|
|
|
FireDragEnterOrExit(aPresContext, aEvent, NS_DRAGDROP_ENTER,
|
|
|
|
lastContent, targetContent, mCurrentTarget);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-26 13:55:04 -07:00
|
|
|
if (sLastDragOverFrame) {
|
|
|
|
FireDragEnterOrExit(sLastDragOverFrame->PresContext(),
|
|
|
|
aEvent, NS_DRAGDROP_LEAVE_SYNTH,
|
|
|
|
targetContent, lastContent, sLastDragOverFrame);
|
2010-12-03 08:19:55 -08:00
|
|
|
}
|
|
|
|
|
2011-09-26 13:55:04 -07:00
|
|
|
sLastDragOverFrame = mCurrentTarget;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_DRAGDROP_EXIT:
|
|
|
|
{
|
|
|
|
//This is actually the window mouse exit event.
|
2011-09-26 13:55:04 -07:00
|
|
|
if (sLastDragOverFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIContent> lastContent;
|
2011-09-26 13:55:04 -07:00
|
|
|
sLastDragOverFrame->GetContentForEvent(aEvent, getter_AddRefs(lastContent));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-26 13:55:04 -07:00
|
|
|
nsRefPtr<nsPresContext> lastDragOverFramePresContext = sLastDragOverFrame->PresContext();
|
|
|
|
FireDragEnterOrExit(lastDragOverFramePresContext,
|
|
|
|
aEvent, NS_DRAGDROP_EXIT_SYNTH,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, lastContent, sLastDragOverFrame);
|
2011-09-26 13:55:04 -07:00
|
|
|
FireDragEnterOrExit(lastDragOverFramePresContext,
|
|
|
|
aEvent, NS_DRAGDROP_LEAVE_SYNTH,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, lastContent, sLastDragOverFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
sLastDragOverFrame = nullptr;
|
2007-04-11 21:37:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//reset mCurretTargetContent to what it was
|
|
|
|
mCurrentTargetContent = targetBeforeEvent;
|
|
|
|
|
|
|
|
// Now flush all pending notifications, for better responsiveness.
|
|
|
|
FlushPendingEvents(aPresContext);
|
|
|
|
}
|
|
|
|
|
2007-04-11 21:37:39 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::FireDragEnterOrExit(nsPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aMsg,
|
2007-04-11 21:37:39 -07:00
|
|
|
nsIContent* aRelatedTarget,
|
|
|
|
nsIContent* aTargetContent,
|
|
|
|
nsWeakFrame& aTargetFrame)
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2012-12-15 17:26:03 -08:00
|
|
|
nsDragEvent event(aEvent->mFlags.mIsTrusted, aMsg, aEvent->widget);
|
2007-04-11 21:37:39 -07:00
|
|
|
event.refPoint = aEvent->refPoint;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.modifiers = ((nsMouseEvent*)aEvent)->modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.buttons = ((nsMouseEvent*)aEvent)->buttons;
|
2007-04-11 21:37:39 -07:00
|
|
|
event.relatedTarget = aRelatedTarget;
|
2010-04-06 05:59:24 -07:00
|
|
|
event.inputSource = static_cast<nsMouseEvent*>(aEvent)->inputSource;
|
2007-04-11 21:37:39 -07:00
|
|
|
|
|
|
|
mCurrentTargetContent = aTargetContent;
|
|
|
|
|
|
|
|
if (aTargetContent != aRelatedTarget) {
|
|
|
|
//XXX This event should still go somewhere!!
|
|
|
|
if (aTargetContent)
|
|
|
|
nsEventDispatcher::Dispatch(aTargetContent, aPresContext, &event,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, &status);
|
2007-04-11 21:37:39 -07:00
|
|
|
|
2008-09-25 07:44:53 -07:00
|
|
|
// adjust the drag hover if the dragenter event was cancelled or this is a drag exit
|
|
|
|
if (status == nsEventStatus_eConsumeNoDefault || aMsg == NS_DRAGDROP_EXIT)
|
2012-07-30 07:20:58 -07:00
|
|
|
SetContentState((aMsg == NS_DRAGDROP_ENTER) ? aTargetContent : nullptr,
|
2007-04-11 21:37:39 -07:00
|
|
|
NS_EVENT_STATE_DRAGOVER);
|
2009-10-06 19:51:02 -07:00
|
|
|
|
|
|
|
// collect any changes to moz cursor settings stored in the event's
|
|
|
|
// data transfer.
|
|
|
|
if (aMsg == NS_DRAGDROP_LEAVE_SYNTH || aMsg == NS_DRAGDROP_EXIT_SYNTH ||
|
|
|
|
aMsg == NS_DRAGDROP_ENTER)
|
|
|
|
UpdateDragDataTransfer(&event);
|
2007-04-11 21:37:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finally dispatch the event to the frame
|
|
|
|
if (aTargetFrame)
|
|
|
|
aTargetFrame->HandleEvent(aPresContext, &event, &status);
|
|
|
|
}
|
|
|
|
|
2009-10-06 19:51:02 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::UpdateDragDataTransfer(nsDragEvent* dragEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(dragEvent, "drag event is null in UpdateDragDataTransfer!");
|
|
|
|
if (!dragEvent->dataTransfer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDragSession> dragSession = nsContentUtils::GetDragSession();
|
|
|
|
|
|
|
|
if (dragSession) {
|
|
|
|
// the initial dataTransfer is the one from the dragstart event that
|
|
|
|
// was set on the dragSession when the drag began.
|
|
|
|
nsCOMPtr<nsIDOMDataTransfer> initialDataTransfer;
|
|
|
|
dragSession->GetDataTransfer(getter_AddRefs(initialDataTransfer));
|
2012-02-07 10:02:32 -08:00
|
|
|
if (initialDataTransfer) {
|
2009-10-06 19:51:02 -07:00
|
|
|
// retrieve the current moz cursor setting and save it.
|
|
|
|
nsAutoString mozCursor;
|
2012-02-07 10:02:32 -08:00
|
|
|
dragEvent->dataTransfer->GetMozCursor(mozCursor);
|
|
|
|
initialDataTransfer->SetMozCursor(mozCursor);
|
2009-10-06 19:51:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::SetClickCount(nsPresContext* aPresContext,
|
|
|
|
nsMouseEvent *aEvent,
|
|
|
|
nsEventStatus* aStatus)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> mouseContent;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent* mouseContentParent = nullptr;
|
2011-09-26 13:55:04 -07:00
|
|
|
mCurrentTarget->GetContentForEvent(aEvent, getter_AddRefs(mouseContent));
|
2011-05-07 02:42:45 -07:00
|
|
|
if (mouseContent) {
|
|
|
|
if (mouseContent->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
mouseContent = mouseContent->GetParent();
|
|
|
|
}
|
|
|
|
if (mouseContent && mouseContent->IsRootOfNativeAnonymousSubtree()) {
|
|
|
|
mouseContentParent = mouseContent->GetParent();
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (aEvent->button) {
|
|
|
|
case nsMouseEvent::eLeftButton:
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
mLastLeftMouseDownContent = mouseContent;
|
2010-09-01 19:38:54 -07:00
|
|
|
mLastLeftMouseDownContentParent = mouseContentParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
2010-01-25 01:21:33 -08:00
|
|
|
if (mLastLeftMouseDownContent == mouseContent ||
|
2010-09-01 19:38:54 -07:00
|
|
|
mLastLeftMouseDownContentParent == mouseContent ||
|
|
|
|
mLastLeftMouseDownContent == mouseContentParent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aEvent->clickCount = mLClickCount;
|
|
|
|
mLClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastLeftMouseDownContent = nullptr;
|
|
|
|
mLastLeftMouseDownContentParent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsMouseEvent::eMiddleButton:
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
mLastMiddleMouseDownContent = mouseContent;
|
2010-09-01 19:38:54 -07:00
|
|
|
mLastMiddleMouseDownContentParent = mouseContentParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
2010-01-25 01:21:33 -08:00
|
|
|
if (mLastMiddleMouseDownContent == mouseContent ||
|
2010-09-01 19:38:54 -07:00
|
|
|
mLastMiddleMouseDownContentParent == mouseContent ||
|
2010-09-08 06:25:21 -07:00
|
|
|
mLastMiddleMouseDownContent == mouseContentParent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aEvent->clickCount = mMClickCount;
|
|
|
|
mMClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastMiddleMouseDownContent = nullptr;
|
|
|
|
mLastMiddleMouseDownContentParent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsMouseEvent::eRightButton:
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
mLastRightMouseDownContent = mouseContent;
|
2010-09-01 19:38:54 -07:00
|
|
|
mLastRightMouseDownContentParent = mouseContentParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
2010-01-25 01:21:33 -08:00
|
|
|
if (mLastRightMouseDownContent == mouseContent ||
|
2010-09-01 19:38:54 -07:00
|
|
|
mLastRightMouseDownContentParent == mouseContent ||
|
2010-09-08 06:25:21 -07:00
|
|
|
mLastRightMouseDownContent == mouseContentParent) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aEvent->clickCount = mRClickCount;
|
|
|
|
mRClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastRightMouseDownContent = nullptr;
|
|
|
|
mLastRightMouseDownContentParent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext,
|
|
|
|
nsMouseEvent *aEvent,
|
|
|
|
nsEventStatus* aStatus)
|
|
|
|
{
|
|
|
|
nsresult ret = NS_OK;
|
|
|
|
|
|
|
|
//If mouse is still over same element, clickcount will be > 1.
|
|
|
|
//If it has moved it will be zero, so no click.
|
|
|
|
if (0 != aEvent->clickCount) {
|
|
|
|
//Check that the window isn't disabled before firing a click
|
|
|
|
//(see bug 366544).
|
2012-07-22 22:19:08 -07:00
|
|
|
if (aEvent->widget && !aEvent->widget->IsEnabled()) {
|
|
|
|
return ret;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
//fire click
|
2012-12-15 17:26:05 -08:00
|
|
|
bool notDispatchToContents =
|
|
|
|
(aEvent->button == nsMouseEvent::eMiddleButton ||
|
|
|
|
aEvent->button == nsMouseEvent::eRightButton);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-15 17:26:03 -08:00
|
|
|
nsMouseEvent event(aEvent->mFlags.mIsTrusted, NS_MOUSE_CLICK,
|
|
|
|
aEvent->widget, nsMouseEvent::eReal);
|
2007-03-22 10:30:00 -07:00
|
|
|
event.refPoint = aEvent->refPoint;
|
|
|
|
event.clickCount = aEvent->clickCount;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.modifiers = aEvent->modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
event.buttons = aEvent->buttons;
|
2007-03-22 10:30:00 -07:00
|
|
|
event.time = aEvent->time;
|
2012-12-15 17:26:05 -08:00
|
|
|
event.mFlags.mNoContentDispatch = notDispatchToContents;
|
2007-03-22 10:30:00 -07:00
|
|
|
event.button = aEvent->button;
|
2010-04-06 05:59:24 -07:00
|
|
|
event.inputSource = aEvent->inputSource;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
|
|
|
|
if (presShell) {
|
2011-04-21 10:35:52 -07:00
|
|
|
nsCOMPtr<nsIContent> mouseContent = GetEventTargetContent(aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ret = presShell->HandleEventWithTarget(&event, mCurrentTarget,
|
|
|
|
mouseContent, aStatus);
|
|
|
|
if (NS_SUCCEEDED(ret) && aEvent->clickCount == 2) {
|
|
|
|
//fire double click
|
2012-12-15 17:26:03 -08:00
|
|
|
nsMouseEvent event2(aEvent->mFlags.mIsTrusted, NS_MOUSE_DOUBLECLICK,
|
2007-03-22 10:30:00 -07:00
|
|
|
aEvent->widget, nsMouseEvent::eReal);
|
|
|
|
event2.refPoint = aEvent->refPoint;
|
|
|
|
event2.clickCount = aEvent->clickCount;
|
2012-04-24 20:00:01 -07:00
|
|
|
event2.modifiers = aEvent->modifiers;
|
2012-04-24 20:00:01 -07:00
|
|
|
event2.buttons = aEvent->buttons;
|
2012-12-15 17:26:05 -08:00
|
|
|
event2.mFlags.mNoContentDispatch = notDispatchToContents;
|
2007-03-22 10:30:00 -07:00
|
|
|
event2.button = aEvent->button;
|
2010-04-06 05:59:24 -07:00
|
|
|
event2.inputSource = aEvent->inputSource;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
ret = presShell->HandleEventWithTarget(&event2, mCurrentTarget,
|
|
|
|
mouseContent, aStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
nsIFrame*
|
|
|
|
nsEventStateManager::GetEventTarget()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-22 15:31:01 -07:00
|
|
|
nsIPresShell *shell;
|
|
|
|
if (mCurrentTarget ||
|
|
|
|
!mPresContext ||
|
|
|
|
!(shell = mPresContext->GetPresShell())) {
|
2011-04-21 10:35:52 -07:00
|
|
|
return mCurrentTarget;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-22 15:31:01 -07:00
|
|
|
if (mCurrentTargetContent) {
|
2009-12-24 13:20:05 -08:00
|
|
|
mCurrentTarget = mPresContext->GetPrimaryFrameFor(mCurrentTargetContent);
|
2009-07-22 15:31:01 -07:00
|
|
|
if (mCurrentTarget) {
|
2011-04-21 10:35:52 -07:00
|
|
|
return mCurrentTarget;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
|
2010-03-31 05:43:01 -07:00
|
|
|
nsIFrame* frame = shell->GetEventTargetFrame();
|
2011-04-21 10:35:52 -07:00
|
|
|
return (mCurrentTarget = frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
already_AddRefed<nsIContent>
|
|
|
|
nsEventStateManager::GetEventTargetContent(nsEvent* aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (aEvent &&
|
|
|
|
(aEvent->message == NS_FOCUS_CONTENT ||
|
|
|
|
aEvent->message == NS_BLUR_CONTENT)) {
|
2011-04-21 10:35:52 -07:00
|
|
|
nsCOMPtr<nsIContent> content = GetFocusedContent();
|
|
|
|
return content.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (mCurrentTargetContent) {
|
2011-04-21 10:35:52 -07:00
|
|
|
nsCOMPtr<nsIContent> content = mCurrentTargetContent;
|
|
|
|
return content.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent *content = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIPresShell *presShell = mPresContext->GetPresShell();
|
|
|
|
if (presShell) {
|
2011-04-21 10:35:52 -07:00
|
|
|
content = presShell->GetEventTargetContent(aEvent).get();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
// Some events here may set mCurrentTarget but not set the corresponding
|
|
|
|
// event target in the PresShell.
|
2011-04-21 10:35:52 -07:00
|
|
|
if (!content && mCurrentTarget) {
|
2011-09-26 13:55:04 -07:00
|
|
|
mCurrentTarget->GetContentForEvent(aEvent, &content);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
return content;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-24 17:18:40 -07:00
|
|
|
static Element*
|
|
|
|
GetLabelTarget(nsIContent* aPossibleLabel)
|
2010-05-31 10:49:55 -07:00
|
|
|
{
|
2012-12-21 06:06:50 -08:00
|
|
|
mozilla::dom::HTMLLabelElement* label =
|
|
|
|
mozilla::dom::HTMLLabelElement::FromContent(aPossibleLabel);
|
2010-05-31 10:49:55 -07:00
|
|
|
if (!label)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-05-31 10:49:55 -07:00
|
|
|
|
2011-05-24 17:18:40 -07:00
|
|
|
return label->GetLabeledElement();
|
2010-05-31 10:49:55 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsIContent* FindCommonAncestor(nsIContent *aNode1, nsIContent *aNode2)
|
|
|
|
{
|
|
|
|
// Find closest common ancestor
|
|
|
|
if (aNode1 && aNode2) {
|
|
|
|
// Find the nearest common ancestor by counting the distance to the
|
|
|
|
// root and then walking up again, in pairs.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t offset = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent *anc1 = aNode1;
|
|
|
|
for (;;) {
|
|
|
|
++offset;
|
|
|
|
nsIContent* parent = anc1->GetParent();
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
anc1 = parent;
|
|
|
|
}
|
|
|
|
nsIContent *anc2 = aNode2;
|
|
|
|
for (;;) {
|
|
|
|
--offset;
|
|
|
|
nsIContent* parent = anc2->GetParent();
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
anc2 = parent;
|
|
|
|
}
|
|
|
|
if (anc1 == anc2) {
|
|
|
|
anc1 = aNode1;
|
|
|
|
anc2 = aNode2;
|
|
|
|
while (offset > 0) {
|
|
|
|
anc1 = anc1->GetParent();
|
|
|
|
--offset;
|
|
|
|
}
|
|
|
|
while (offset < 0) {
|
|
|
|
anc2 = anc2->GetParent();
|
|
|
|
++offset;
|
|
|
|
}
|
|
|
|
while (anc1 != anc2) {
|
|
|
|
anc1 = anc1->GetParent();
|
|
|
|
anc2 = anc2->GetParent();
|
|
|
|
}
|
|
|
|
return anc1;
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-31 22:11:09 -07:00
|
|
|
static Element*
|
|
|
|
GetParentElement(Element* aElement)
|
|
|
|
{
|
|
|
|
nsIContent* p = aElement->GetParent();
|
2012-07-30 07:20:58 -07:00
|
|
|
return (p && p->IsElement()) ? p->AsElement() : nullptr;
|
2011-10-31 22:11:09 -07:00
|
|
|
}
|
|
|
|
|
2011-09-04 13:39:08 -07:00
|
|
|
/* static */
|
|
|
|
void
|
2011-10-31 22:11:09 -07:00
|
|
|
nsEventStateManager::SetFullScreenState(Element* aElement, bool aIsFullScreen)
|
2011-09-04 13:39:08 -07:00
|
|
|
{
|
|
|
|
DoStateChange(aElement, NS_EVENT_STATE_FULL_SCREEN, aIsFullScreen);
|
2011-10-31 22:11:09 -07:00
|
|
|
Element* ancestor = aElement;
|
|
|
|
while ((ancestor = GetParentElement(ancestor))) {
|
|
|
|
DoStateChange(ancestor, NS_EVENT_STATE_FULL_SCREEN_ANCESTOR, aIsFullScreen);
|
|
|
|
}
|
2011-09-04 13:39:08 -07:00
|
|
|
}
|
|
|
|
|
2011-05-31 18:46:56 -07:00
|
|
|
/* static */
|
|
|
|
inline void
|
|
|
|
nsEventStateManager::DoStateChange(Element* aElement, nsEventStates aState,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAddState)
|
2010-05-31 10:47:11 -07:00
|
|
|
{
|
2011-05-31 18:46:56 -07:00
|
|
|
if (aAddState) {
|
|
|
|
aElement->AddStates(aState);
|
|
|
|
} else {
|
|
|
|
aElement->RemoveStates(aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-31 18:46:56 -07:00
|
|
|
/* static */
|
|
|
|
inline void
|
|
|
|
nsEventStateManager::DoStateChange(nsIContent* aContent, nsEventStates aState,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aStateAdded)
|
2011-05-31 18:46:56 -07:00
|
|
|
{
|
|
|
|
if (aContent->IsElement()) {
|
|
|
|
DoStateChange(aContent->AsElement(), aState, aStateAdded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-31 18:46:56 -07:00
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsEventStateManager::UpdateAncestorState(nsIContent* aStartNode,
|
|
|
|
nsIContent* aStopBefore,
|
|
|
|
nsEventStates aState,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAddState)
|
2011-05-31 18:46:56 -07:00
|
|
|
{
|
|
|
|
for (; aStartNode && aStartNode != aStopBefore;
|
|
|
|
aStartNode = aStartNode->GetParent()) {
|
|
|
|
// We might be starting with a non-element (e.g. a text node) and
|
|
|
|
// if someone is doing something weird might be ending with a
|
|
|
|
// non-element too (e.g. a document fragment)
|
|
|
|
if (!aStartNode->IsElement()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Element* element = aStartNode->AsElement();
|
|
|
|
DoStateChange(element, aState, aAddState);
|
|
|
|
Element* labelTarget = GetLabelTarget(element);
|
2010-05-31 10:49:55 -07:00
|
|
|
if (labelTarget) {
|
2011-05-31 18:46:56 -07:00
|
|
|
DoStateChange(labelTarget, aState, aAddState);
|
2010-05-31 10:49:55 -07:00
|
|
|
}
|
2010-05-31 10:47:11 -07:00
|
|
|
}
|
2011-12-21 13:50:29 -08:00
|
|
|
|
|
|
|
if (aAddState) {
|
|
|
|
// We might be in a situation where a node was in hover both
|
|
|
|
// because it was hovered and because the label for it was
|
|
|
|
// hovered, and while we stopped hovering the node the label is
|
|
|
|
// still hovered. Or we might have had two nested labels for the
|
|
|
|
// same node, and while one is no longer hovered the other still
|
|
|
|
// is. In that situation, the label that's still hovered will be
|
|
|
|
// aStopBefore or some ancestor of it, and the call we just made
|
|
|
|
// to UpdateAncestorState with aAddState = false would have
|
|
|
|
// removed the hover state from the node. But the node should
|
|
|
|
// still be in hover state. To handle this situation we need to
|
|
|
|
// keep walking up the tree and any time we find a label mark its
|
|
|
|
// corresponding node as still in our state.
|
|
|
|
for ( ; aStartNode; aStartNode = aStartNode->GetParent()) {
|
|
|
|
if (!aStartNode->IsElement()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element* labelTarget = GetLabelTarget(aStartNode->AsElement());
|
|
|
|
if (labelTarget && !labelTarget->State().HasState(aState)) {
|
|
|
|
DoStateChange(labelTarget, aState, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-31 10:47:11 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStateManager::SetContentState(nsIContent *aContent, nsEventStates aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-03-28 20:32:11 -07:00
|
|
|
// We manage 4 states here: ACTIVE, HOVER, DRAGOVER, URLTARGET
|
|
|
|
// The input must be exactly one of them.
|
|
|
|
NS_PRECONDITION(aState == NS_EVENT_STATE_ACTIVE ||
|
|
|
|
aState == NS_EVENT_STATE_HOVER ||
|
|
|
|
aState == NS_EVENT_STATE_DRAGOVER ||
|
|
|
|
aState == NS_EVENT_STATE_URLTARGET,
|
|
|
|
"Unexpected state");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> notifyContent1;
|
|
|
|
nsCOMPtr<nsIContent> notifyContent2;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool updateAncestors;
|
2011-03-28 20:32:11 -07:00
|
|
|
|
|
|
|
if (aState == NS_EVENT_STATE_HOVER || aState == NS_EVENT_STATE_ACTIVE) {
|
|
|
|
// Hover and active are hierarchical
|
2011-10-17 07:59:28 -07:00
|
|
|
updateAncestors = true;
|
2011-03-28 20:32:11 -07:00
|
|
|
|
|
|
|
// check to see that this state is allowed by style. Check dragover too?
|
|
|
|
// XXX Is this even what we want?
|
|
|
|
if (mCurrentTarget)
|
|
|
|
{
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleUserInterface* ui = mCurrentTarget->StyleUserInterface();
|
2011-03-28 20:32:11 -07:00
|
|
|
if (ui->mUserInput == NS_STYLE_USER_INPUT_NONE)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-03-28 20:32:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-28 20:32:11 -07:00
|
|
|
if (aState == NS_EVENT_STATE_ACTIVE) {
|
|
|
|
if (aContent != mActiveContent) {
|
|
|
|
notifyContent1 = aContent;
|
|
|
|
notifyContent2 = mActiveContent;
|
|
|
|
mActiveContent = aContent;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2011-03-28 20:32:11 -07:00
|
|
|
NS_ASSERTION(aState == NS_EVENT_STATE_HOVER, "How did that happen?");
|
|
|
|
nsIContent* newHover;
|
|
|
|
|
|
|
|
if (mPresContext->IsDynamic()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
newHover = aContent;
|
|
|
|
} else {
|
2011-03-28 20:32:11 -07:00
|
|
|
NS_ASSERTION(!aContent ||
|
|
|
|
aContent->GetCurrentDoc() == mPresContext->PresShell()->GetDocument(),
|
|
|
|
"Unexpected document");
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame *frame = aContent ? aContent->GetPrimaryFrame() : nullptr;
|
2011-03-28 20:32:11 -07:00
|
|
|
if (frame && nsLayoutUtils::IsViewportScrollbarFrame(frame)) {
|
|
|
|
// The scrollbars of viewport should not ignore the hover state.
|
|
|
|
// Because they are *not* the content of the web page.
|
|
|
|
newHover = aContent;
|
|
|
|
} else {
|
|
|
|
// All contents of the web page should ignore the hover state.
|
2012-07-30 07:20:58 -07:00
|
|
|
newHover = nullptr;
|
2011-03-28 20:32:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-03-28 20:32:11 -07:00
|
|
|
if (newHover != mHoverContent) {
|
|
|
|
notifyContent1 = newHover;
|
|
|
|
notifyContent2 = mHoverContent;
|
|
|
|
mHoverContent = newHover;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2011-03-28 20:32:11 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
updateAncestors = false;
|
2011-03-28 20:32:11 -07:00
|
|
|
if (aState == NS_EVENT_STATE_DRAGOVER) {
|
2011-09-26 13:55:04 -07:00
|
|
|
if (aContent != sDragOverContent) {
|
2011-03-28 20:32:11 -07:00
|
|
|
notifyContent1 = aContent;
|
2011-09-26 13:55:04 -07:00
|
|
|
notifyContent2 = sDragOverContent;
|
|
|
|
sDragOverContent = aContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-03-28 20:32:11 -07:00
|
|
|
} else if (aState == NS_EVENT_STATE_URLTARGET) {
|
|
|
|
if (aContent != mURLTargetContent) {
|
|
|
|
notifyContent1 = aContent;
|
|
|
|
notifyContent2 = mURLTargetContent;
|
|
|
|
mURLTargetContent = aContent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-31 18:46:56 -07:00
|
|
|
// We need to keep track of which of notifyContent1 and notifyContent2 is
|
|
|
|
// getting the state set and which is getting it unset. If both are
|
|
|
|
// non-null, then notifyContent1 is having the state set and notifyContent2
|
|
|
|
// is having it unset. But if one of them is null, we need to keep track of
|
|
|
|
// the right thing for notifyContent1 explicitly.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool content1StateSet = true;
|
2011-03-28 20:32:11 -07:00
|
|
|
if (!notifyContent1) {
|
|
|
|
// This is ok because FindCommonAncestor wouldn't find anything
|
|
|
|
// anyway if notifyContent1 is null.
|
|
|
|
notifyContent1 = notifyContent2;
|
2012-07-30 07:20:58 -07:00
|
|
|
notifyContent2 = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
content1StateSet = false;
|
2011-03-28 20:32:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-28 20:32:11 -07:00
|
|
|
if (notifyContent1 && mPresContext) {
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
if (mDocument) {
|
2011-05-31 14:38:25 -07:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2011-03-28 20:32:11 -07:00
|
|
|
|
2011-05-31 18:46:56 -07:00
|
|
|
if (updateAncestors) {
|
2011-03-28 20:32:11 -07:00
|
|
|
nsCOMPtr<nsIContent> commonAncestor =
|
|
|
|
FindCommonAncestor(notifyContent1, notifyContent2);
|
|
|
|
if (notifyContent2) {
|
2011-05-31 18:46:56 -07:00
|
|
|
// It's very important to first notify the state removal and
|
|
|
|
// then the state addition, because due to labels it's
|
|
|
|
// possible that we're removing state from some element but
|
|
|
|
// then adding it again (say because mHoverContent changed
|
|
|
|
// from a control to its label).
|
2011-10-17 07:59:28 -07:00
|
|
|
UpdateAncestorState(notifyContent2, commonAncestor, aState, false);
|
2011-03-28 20:32:11 -07:00
|
|
|
}
|
2011-05-31 18:46:56 -07:00
|
|
|
UpdateAncestorState(notifyContent1, commonAncestor, aState,
|
|
|
|
content1StateSet);
|
2011-03-28 20:32:11 -07:00
|
|
|
} else {
|
|
|
|
if (notifyContent2) {
|
2011-10-17 07:59:28 -07:00
|
|
|
DoStateChange(notifyContent2, aState, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-05-31 18:46:56 -07:00
|
|
|
DoStateChange(notifyContent1, aState, content1StateSet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
void
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsEventStateManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-04-19 03:20:34 -07:00
|
|
|
/*
|
|
|
|
* Anchor and area elements when focused or hovered might make the UI to show
|
|
|
|
* the current link. We want to make sure that the UI gets informed when they
|
|
|
|
* are actually removed from the DOM.
|
|
|
|
*/
|
|
|
|
if (aContent->IsHTML() &&
|
|
|
|
(aContent->Tag() == nsGkAtoms::a || aContent->Tag() == nsGkAtoms::area) &&
|
|
|
|
(aContent->AsElement()->State().HasAtLeastOneOfStates(NS_EVENT_STATE_FOCUS |
|
|
|
|
NS_EVENT_STATE_HOVER))) {
|
|
|
|
nsGenericHTMLElement* element = static_cast<nsGenericHTMLElement*>(aContent);
|
|
|
|
element->LeaveLink(element->GetPresContext());
|
|
|
|
}
|
|
|
|
|
2012-09-25 22:47:45 -07:00
|
|
|
nsIMEStateManager::OnRemoveContent(mPresContext, aContent);
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
// inform the focus manager that the content is being removed. If this
|
|
|
|
// content is focused, the focus will be removed without firing events.
|
2010-04-27 02:58:58 -07:00
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (fm)
|
|
|
|
fm->ContentRemoved(aDocument, aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (mHoverContent &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mHoverContent, aContent)) {
|
|
|
|
// Since hover is hierarchical, set the current hover to the
|
|
|
|
// content's parent node.
|
2010-05-31 10:49:55 -07:00
|
|
|
SetContentState(aContent->GetParent(), NS_EVENT_STATE_HOVER);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (mActiveContent &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mActiveContent, aContent)) {
|
|
|
|
// Active is hierarchical, so set the current active to the
|
|
|
|
// content's parent node.
|
2010-05-31 10:49:55 -07:00
|
|
|
SetContentState(aContent->GetParent(), NS_EVENT_STATE_ACTIVE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-26 13:55:04 -07:00
|
|
|
if (sDragOverContent &&
|
2011-10-18 03:53:36 -07:00
|
|
|
sDragOverContent->OwnerDoc() == aContent->OwnerDoc() &&
|
2011-09-26 13:55:04 -07:00
|
|
|
nsContentUtils::ContentIsDescendantOf(sDragOverContent, aContent)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
sDragOverContent = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (mLastMouseOverElement &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mLastMouseOverElement, aContent)) {
|
|
|
|
// See bug 292146 for why we want to null this out
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastMouseOverElement = nullptr;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-04-21 10:35:52 -07:00
|
|
|
nsEventStateManager::EventStatusOK(nsGUIEvent* aEvent)
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
{
|
2011-04-21 10:35:52 -07:00
|
|
|
return !(aEvent->message == NS_MOUSE_BUTTON_DOWN &&
|
|
|
|
static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton &&
|
|
|
|
!sNormalLMouseEventInProcess);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
//-------------------------------------------
|
|
|
|
// Access Key Registration
|
|
|
|
//-------------------------------------------
|
2011-04-21 10:35:52 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsEventStateManager::RegisterAccessKey(nsIContent* aContent, uint32_t aKey)
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
{
|
|
|
|
if (aContent && mAccessKeys.IndexOf(aContent) == -1)
|
|
|
|
mAccessKeys.AppendObject(aContent);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-21 10:35:52 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsEventStateManager::UnregisterAccessKey(nsIContent* aContent, uint32_t aKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-11-28 12:14:12 -08:00
|
|
|
if (aContent)
|
|
|
|
mAccessKeys.RemoveObject(aContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2011-04-21 10:35:52 -07:00
|
|
|
nsEventStateManager::GetRegisteredAccessKey(nsIContent* aContent)
|
2007-08-28 23:52:46 -07:00
|
|
|
{
|
2012-09-06 00:14:49 -07:00
|
|
|
MOZ_ASSERT(aContent);
|
2007-08-28 23:52:46 -07:00
|
|
|
|
2007-11-28 12:14:12 -08:00
|
|
|
if (mAccessKeys.IndexOf(aContent) == -1)
|
2011-04-21 10:35:52 -07:00
|
|
|
return 0;
|
2007-08-28 23:52:46 -07:00
|
|
|
|
2007-11-28 12:14:12 -08:00
|
|
|
nsAutoString accessKey;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
|
2011-04-21 10:35:52 -07:00
|
|
|
return accessKey.First();
|
2007-08-28 23:52:46 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::EnsureDocument(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
if (!mDocument)
|
|
|
|
mDocument = aPresContext->Document();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::FlushPendingEvents(nsPresContext* aPresContext)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != aPresContext, "nullptr ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIPresShell *shell = aPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
2009-04-21 16:53:52 -07:00
|
|
|
shell->FlushPendingNotifications(Flush_InterruptibleLayout);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIContent*
|
|
|
|
nsEventStateManager::GetFocusedContent()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm || !mDocument)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
2011-10-17 07:59:28 -07:00
|
|
|
return nsFocusManager::GetFocusedDescendant(mDocument->GetWindow(), false,
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
getter_AddRefs(focusedWindow));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
2011-10-17 07:59:28 -07:00
|
|
|
// Return true if the docshell is visible
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsEventStateManager::IsShellVisible(nsIDocShell* aShell)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aShell, "docshell is null");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> basewin = do_QueryInterface(aShell);
|
|
|
|
if (!basewin)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isVisible = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
basewin->GetVisibility(&isVisible);
|
|
|
|
|
|
|
|
// We should be doing some additional checks here so that
|
|
|
|
// we don't tab into hidden tabs of tabbrowser. -bryner
|
|
|
|
|
|
|
|
return isVisible;
|
|
|
|
}
|
2009-08-07 08:11:17 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::DoContentCommandEvent(nsContentCommandEvent* aEvent)
|
|
|
|
{
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
|
2010-02-20 08:07:03 -08:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
|
2009-08-07 08:11:17 -07:00
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
2010-02-20 08:07:03 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsPIWindowRoot> root = window->GetTopWindowRoot();
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
2009-08-07 08:11:17 -07:00
|
|
|
const char* cmd;
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_CONTENT_COMMAND_CUT:
|
|
|
|
cmd = "cmd_cut";
|
|
|
|
break;
|
|
|
|
case NS_CONTENT_COMMAND_COPY:
|
|
|
|
cmd = "cmd_copy";
|
|
|
|
break;
|
|
|
|
case NS_CONTENT_COMMAND_PASTE:
|
|
|
|
cmd = "cmd_paste";
|
|
|
|
break;
|
|
|
|
case NS_CONTENT_COMMAND_DELETE:
|
|
|
|
cmd = "cmd_delete";
|
|
|
|
break;
|
|
|
|
case NS_CONTENT_COMMAND_UNDO:
|
|
|
|
cmd = "cmd_undo";
|
|
|
|
break;
|
|
|
|
case NS_CONTENT_COMMAND_REDO:
|
|
|
|
cmd = "cmd_redo";
|
|
|
|
break;
|
2010-01-10 17:45:45 -08:00
|
|
|
case NS_CONTENT_COMMAND_PASTE_TRANSFERABLE:
|
|
|
|
cmd = "cmd_pasteTransferable";
|
|
|
|
break;
|
2009-08-07 08:11:17 -07:00
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIController> controller;
|
2010-02-20 08:07:03 -08:00
|
|
|
nsresult rv = root->GetControllerForCommand(cmd, getter_AddRefs(controller));
|
2009-08-07 08:11:17 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!controller) {
|
|
|
|
// When GetControllerForCommand succeeded but there is no controller, the
|
|
|
|
// command isn't supported.
|
2011-10-17 07:59:28 -07:00
|
|
|
aEvent->mIsEnabled = false;
|
2009-08-07 08:11:17 -07:00
|
|
|
} else {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canDoIt;
|
2009-08-07 08:11:17 -07:00
|
|
|
rv = controller->IsCommandEnabled(cmd, &canDoIt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
aEvent->mIsEnabled = canDoIt;
|
|
|
|
if (canDoIt && !aEvent->mOnlyEnabledCheck) {
|
2010-01-10 17:45:45 -08:00
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_CONTENT_COMMAND_PASTE_TRANSFERABLE: {
|
|
|
|
nsCOMPtr<nsICommandController> commandController = do_QueryInterface(controller);
|
|
|
|
NS_ENSURE_STATE(commandController);
|
|
|
|
|
|
|
|
nsCOMPtr<nsICommandParams> params = do_CreateInstance("@mozilla.org/embedcomp/command-params;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = params->SetISupportsValue("transferable", aEvent->mTransferable);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = commandController->DoCommandWithParams(cmd, params);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = controller->DoCommand(cmd);
|
|
|
|
break;
|
|
|
|
}
|
2009-08-07 08:11:17 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
aEvent->mSucceeded = true;
|
2009-08-07 08:11:17 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-03-10 21:25:29 -08:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::DoContentCommandScrollEvent(nsContentCommandEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mPresContext, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
nsIPresShell* ps = mPresContext->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(ps, NS_ERROR_NOT_AVAILABLE);
|
|
|
|
NS_ENSURE_TRUE(aEvent->mScroll.mAmount != 0, NS_ERROR_INVALID_ARG);
|
|
|
|
|
|
|
|
nsIScrollableFrame::ScrollUnit scrollUnit;
|
|
|
|
switch (aEvent->mScroll.mUnit) {
|
|
|
|
case nsContentCommandEvent::eCmdScrollUnit_Line:
|
|
|
|
scrollUnit = nsIScrollableFrame::LINES;
|
|
|
|
break;
|
|
|
|
case nsContentCommandEvent::eCmdScrollUnit_Page:
|
|
|
|
scrollUnit = nsIScrollableFrame::PAGES;
|
|
|
|
break;
|
|
|
|
case nsContentCommandEvent::eCmdScrollUnit_Whole:
|
|
|
|
scrollUnit = nsIScrollableFrame::WHOLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
aEvent->mSucceeded = true;
|
2010-03-10 21:25:29 -08:00
|
|
|
|
|
|
|
nsIScrollableFrame* sf =
|
|
|
|
ps->GetFrameToScrollAsScrollable(nsIPresShell::eEither);
|
2012-08-11 18:42:35 -07:00
|
|
|
aEvent->mIsEnabled = sf ?
|
|
|
|
(aEvent->mScroll.mIsHorizontal ?
|
|
|
|
CanScrollOn(sf, aEvent->mScroll.mAmount, 0) :
|
|
|
|
CanScrollOn(sf, 0, aEvent->mScroll.mAmount)) : false;
|
2010-03-10 21:25:29 -08:00
|
|
|
|
|
|
|
if (!aEvent->mIsEnabled || aEvent->mOnlyEnabledCheck) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint pt(0, 0);
|
|
|
|
if (aEvent->mScroll.mIsHorizontal) {
|
|
|
|
pt.x = aEvent->mScroll.mAmount;
|
|
|
|
} else {
|
|
|
|
pt.y = aEvent->mScroll.mAmount;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The caller may want synchronous scrolling.
|
|
|
|
sf->ScrollBy(pt, scrollUnit, nsIScrollableFrame::INSTANT);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-16 06:10:18 -07:00
|
|
|
|
2011-09-22 02:17:40 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::DoQuerySelectedText(nsQueryContentEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (RemoteQueryContentEvent(aEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQuerySelectedText(aEvent);
|
|
|
|
}
|
|
|
|
|
2010-09-16 06:10:18 -07:00
|
|
|
void
|
2010-10-28 07:11:15 -07:00
|
|
|
nsEventStateManager::SetActiveManager(nsEventStateManager* aNewESM,
|
|
|
|
nsIContent* aContent)
|
2010-09-16 06:10:18 -07:00
|
|
|
{
|
|
|
|
if (sActiveESM && aNewESM != sActiveESM) {
|
2012-07-30 07:20:58 -07:00
|
|
|
sActiveESM->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE);
|
2010-09-16 06:10:18 -07:00
|
|
|
}
|
|
|
|
sActiveESM = aNewESM;
|
2010-10-28 07:11:15 -07:00
|
|
|
if (sActiveESM && aContent) {
|
2010-09-16 06:10:18 -07:00
|
|
|
sActiveESM->SetContentState(aContent, NS_EVENT_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
}
|
2010-10-15 09:41:02 -07:00
|
|
|
|
|
|
|
void
|
2010-10-28 07:11:15 -07:00
|
|
|
nsEventStateManager::ClearGlobalActiveContent(nsEventStateManager* aClearer)
|
2010-10-15 09:41:02 -07:00
|
|
|
{
|
2010-10-28 07:11:15 -07:00
|
|
|
if (aClearer) {
|
2012-07-30 07:20:58 -07:00
|
|
|
aClearer->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE);
|
2011-09-26 13:55:04 -07:00
|
|
|
if (sDragOverContent) {
|
2012-07-30 07:20:58 -07:00
|
|
|
aClearer->SetContentState(nullptr, NS_EVENT_STATE_DRAGOVER);
|
2011-09-26 13:55:04 -07:00
|
|
|
}
|
2010-10-28 07:11:15 -07:00
|
|
|
}
|
|
|
|
if (sActiveESM && aClearer != sActiveESM) {
|
2012-07-30 07:20:58 -07:00
|
|
|
sActiveESM->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE);
|
2010-10-15 09:41:02 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
sActiveESM = nullptr;
|
2010-10-15 09:41:02 -07:00
|
|
|
}
|
2012-08-11 18:42:34 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
/******************************************************************/
|
2012-08-11 18:42:36 -07:00
|
|
|
/* nsEventStateManager::DeltaAccumulator */
|
2012-08-11 18:42:35 -07:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
void
|
2012-08-11 18:42:36 -07:00
|
|
|
nsEventStateManager::DeltaAccumulator::InitLineOrPageDelta(
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsEventStateManager* aESM,
|
|
|
|
widget::WheelEvent* aEvent)
|
2012-08-11 18:42:35 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aESM);
|
|
|
|
MOZ_ASSERT(aEvent);
|
|
|
|
|
2012-08-11 18:42:36 -07:00
|
|
|
// Reset if the previous wheel event is too old.
|
2012-08-11 18:42:35 -07:00
|
|
|
if (!mLastTime.IsNull()) {
|
|
|
|
TimeDuration duration = TimeStamp::Now() - mLastTime;
|
|
|
|
if (duration.ToMilliseconds() > nsMouseWheelTransaction::GetTimeoutTime()) {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
}
|
2012-08-11 18:42:36 -07:00
|
|
|
// If we have accumulated delta, we may need to reset it.
|
2012-08-19 09:46:21 -07:00
|
|
|
if (IsInTransaction()) {
|
2012-08-11 18:42:36 -07:00
|
|
|
// If wheel event type is changed, reset the values.
|
|
|
|
if (mHandlingDeltaMode != aEvent->deltaMode ||
|
|
|
|
mHandlingPixelOnlyDevice != aEvent->isPixelOnlyDevice) {
|
|
|
|
Reset();
|
|
|
|
} else {
|
|
|
|
// If the delta direction is changed, we should reset only the
|
|
|
|
// accumulated values.
|
|
|
|
if (mX && aEvent->deltaX && ((aEvent->deltaX > 0.0) != (mX > 0.0))) {
|
2012-08-19 09:46:21 -07:00
|
|
|
mX = mPendingScrollAmountX = 0.0;
|
2012-08-11 18:42:36 -07:00
|
|
|
}
|
|
|
|
if (mY && aEvent->deltaY && ((aEvent->deltaY > 0.0) != (mY > 0.0))) {
|
2012-08-19 09:46:21 -07:00
|
|
|
mY = mPendingScrollAmountY = 0.0;
|
2012-08-11 18:42:36 -07:00
|
|
|
}
|
|
|
|
}
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:36 -07:00
|
|
|
mHandlingDeltaMode = aEvent->deltaMode;
|
|
|
|
mHandlingPixelOnlyDevice = aEvent->isPixelOnlyDevice;
|
|
|
|
|
2012-08-19 09:46:21 -07:00
|
|
|
// If it's handling neither pixel scroll mode for pixel only device nor
|
|
|
|
// delta values multiplied by prefs, we must not modify lineOrPageDelta
|
|
|
|
// values.
|
|
|
|
if (!(mHandlingDeltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL &&
|
|
|
|
mHandlingPixelOnlyDevice) &&
|
|
|
|
!nsEventStateManager::WheelPrefs::GetInstance()->
|
|
|
|
NeedToComputeLineOrPageDelta(aEvent)) {
|
|
|
|
// Set the delta values to mX and mY. They would be used when above block
|
|
|
|
// resets mX/mY/mPendingScrollAmountX/mPendingScrollAmountY if the direction
|
|
|
|
// is changed.
|
|
|
|
// NOTE: We shouldn't accumulate the delta values, it might could cause
|
|
|
|
// overflow even though it's not a realistic situation.
|
|
|
|
if (aEvent->deltaX) {
|
|
|
|
mX = aEvent->deltaX;
|
|
|
|
}
|
|
|
|
if (aEvent->deltaY) {
|
|
|
|
mY = aEvent->deltaY;
|
|
|
|
}
|
|
|
|
mLastTime = TimeStamp::Now();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:36 -07:00
|
|
|
mX += aEvent->deltaX;
|
|
|
|
mY += aEvent->deltaY;
|
|
|
|
|
|
|
|
if (mHandlingDeltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL) {
|
|
|
|
// Records pixel delta values and init lineOrPageDeltaX and
|
|
|
|
// lineOrPageDeltaY for wheel events which are caused by pixel only
|
|
|
|
// devices. Ignore mouse wheel transaction for computing this. The
|
|
|
|
// lineOrPageDelta values will be used by dispatching legacy
|
|
|
|
// NS_MOUSE_SCROLL_EVENT (DOMMouseScroll) but not be used for scrolling
|
|
|
|
// of default action. The transaction should be used only for the default
|
|
|
|
// action.
|
|
|
|
nsIScrollableFrame* scrollTarget =
|
2012-09-04 01:39:28 -07:00
|
|
|
aESM->ComputeScrollTarget(aTargetFrame, aEvent,
|
|
|
|
COMPUTE_LEGACY_MOUSE_SCROLL_EVENT_TARGET);
|
2012-08-11 18:42:36 -07:00
|
|
|
nsIFrame* frame = do_QueryFrame(scrollTarget);
|
|
|
|
nsPresContext* pc =
|
|
|
|
frame ? frame->PresContext() : aTargetFrame->PresContext();
|
|
|
|
nsSize scrollAmount = aESM->GetScrollAmount(pc, aEvent, scrollTarget);
|
|
|
|
nsIntSize scrollAmountInCSSPixels(
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(scrollAmount.width),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(scrollAmount.height));
|
|
|
|
|
|
|
|
aEvent->lineOrPageDeltaX = RoundDown(mX) / scrollAmountInCSSPixels.width;
|
|
|
|
aEvent->lineOrPageDeltaY = RoundDown(mY) / scrollAmountInCSSPixels.height;
|
|
|
|
|
|
|
|
mX -= aEvent->lineOrPageDeltaX * scrollAmountInCSSPixels.width;
|
|
|
|
mY -= aEvent->lineOrPageDeltaY * scrollAmountInCSSPixels.height;
|
|
|
|
} else {
|
|
|
|
aEvent->lineOrPageDeltaX = RoundDown(mX);
|
|
|
|
aEvent->lineOrPageDeltaY = RoundDown(mY);
|
|
|
|
mX -= aEvent->lineOrPageDeltaX;
|
|
|
|
mY -= aEvent->lineOrPageDeltaY;
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:36 -07:00
|
|
|
mLastTime = TimeStamp::Now();
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-11 18:42:36 -07:00
|
|
|
nsEventStateManager::DeltaAccumulator::Reset()
|
2012-08-11 18:42:35 -07:00
|
|
|
{
|
2012-08-11 18:42:36 -07:00
|
|
|
mX = mY = 0.0;
|
2012-08-19 09:46:21 -07:00
|
|
|
mPendingScrollAmountX = mPendingScrollAmountY = 0.0;
|
2012-09-27 23:57:33 -07:00
|
|
|
mHandlingDeltaMode = UINT32_MAX;
|
2012-08-11 18:42:36 -07:00
|
|
|
mHandlingPixelOnlyDevice = false;
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
|
|
|
|
2012-08-19 09:46:21 -07:00
|
|
|
nsIntPoint
|
|
|
|
nsEventStateManager::DeltaAccumulator::ComputeScrollAmountForDefaultAction(
|
|
|
|
widget::WheelEvent* aEvent,
|
|
|
|
const nsIntSize& aScrollAmountInDevPixels)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aEvent);
|
|
|
|
|
|
|
|
// If the wheel event is line scroll and the delta value is computed from
|
|
|
|
// system settings, allow to override the system speed.
|
|
|
|
bool allowScrollSpeedOverride =
|
|
|
|
(!aEvent->customizedByUserPrefs &&
|
|
|
|
aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_LINE);
|
|
|
|
DeltaValues acceleratedDelta =
|
|
|
|
nsMouseWheelTransaction::AccelerateWheelDelta(aEvent,
|
|
|
|
allowScrollSpeedOverride);
|
|
|
|
|
|
|
|
nsIntPoint result(0, 0);
|
|
|
|
if (aEvent->deltaMode == nsIDOMWheelEvent::DOM_DELTA_PIXEL) {
|
|
|
|
mPendingScrollAmountX += acceleratedDelta.deltaX;
|
|
|
|
mPendingScrollAmountY += acceleratedDelta.deltaY;
|
|
|
|
} else {
|
|
|
|
mPendingScrollAmountX +=
|
|
|
|
aScrollAmountInDevPixels.width * acceleratedDelta.deltaX;
|
|
|
|
mPendingScrollAmountY +=
|
|
|
|
aScrollAmountInDevPixels.height * acceleratedDelta.deltaY;
|
|
|
|
}
|
|
|
|
result.x = RoundDown(mPendingScrollAmountX);
|
|
|
|
result.y = RoundDown(mPendingScrollAmountY);
|
|
|
|
mPendingScrollAmountX -= result.x;
|
|
|
|
mPendingScrollAmountY -= result.y;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
/******************************************************************/
|
|
|
|
/* nsEventStateManager::WheelPrefs */
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
// static
|
|
|
|
nsEventStateManager::WheelPrefs*
|
|
|
|
nsEventStateManager::WheelPrefs::GetInstance()
|
|
|
|
{
|
|
|
|
if (!sInstance) {
|
|
|
|
sInstance = new WheelPrefs();
|
|
|
|
}
|
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsEventStateManager::WheelPrefs::Shutdown()
|
|
|
|
{
|
|
|
|
delete sInstance;
|
|
|
|
sInstance = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
int
|
|
|
|
nsEventStateManager::WheelPrefs::OnPrefChanged(const char* aPrefName,
|
|
|
|
void* aClosure)
|
|
|
|
{
|
|
|
|
// forget all prefs, it's not problem for performance.
|
|
|
|
sInstance->Reset();
|
2012-08-11 18:42:36 -07:00
|
|
|
DeltaAccumulator::GetInstance()->Reset();
|
2012-08-11 18:42:34 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStateManager::WheelPrefs::WheelPrefs()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
Preferences::RegisterCallback(OnPrefChanged, "mousewheel.", nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStateManager::WheelPrefs::~WheelPrefs()
|
|
|
|
{
|
|
|
|
Preferences::UnregisterCallback(OnPrefChanged, "mousewheel.", nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::WheelPrefs::Reset()
|
|
|
|
{
|
|
|
|
memset(mInit, 0, sizeof(mInit));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStateManager::WheelPrefs::Index
|
2012-08-11 18:42:36 -07:00
|
|
|
nsEventStateManager::WheelPrefs::GetIndexFor(widget::WheelEvent* aEvent)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
2012-08-11 18:42:35 -07:00
|
|
|
if (!aEvent) {
|
|
|
|
return INDEX_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:34 -07:00
|
|
|
widget::Modifiers modifiers =
|
|
|
|
(aEvent->modifiers & (widget::MODIFIER_ALT |
|
|
|
|
widget::MODIFIER_CONTROL |
|
|
|
|
widget::MODIFIER_META |
|
|
|
|
widget::MODIFIER_SHIFT |
|
|
|
|
widget::MODIFIER_OS));
|
|
|
|
|
|
|
|
switch (modifiers) {
|
|
|
|
case widget::MODIFIER_ALT:
|
|
|
|
return INDEX_ALT;
|
|
|
|
case widget::MODIFIER_CONTROL:
|
|
|
|
return INDEX_CONTROL;
|
|
|
|
case widget::MODIFIER_META:
|
|
|
|
return INDEX_META;
|
|
|
|
case widget::MODIFIER_SHIFT:
|
|
|
|
return INDEX_SHIFT;
|
|
|
|
case widget::MODIFIER_OS:
|
|
|
|
return INDEX_OS;
|
|
|
|
default:
|
|
|
|
// If two or more modifier keys are pressed, we should use default
|
|
|
|
// settings.
|
|
|
|
return INDEX_DEFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::WheelPrefs::GetBasePrefName(
|
|
|
|
nsEventStateManager::WheelPrefs::Index aIndex,
|
|
|
|
nsACString& aBasePrefName)
|
|
|
|
{
|
|
|
|
aBasePrefName.AssignLiteral("mousewheel.");
|
|
|
|
switch (aIndex) {
|
|
|
|
case INDEX_ALT:
|
2012-08-11 18:42:35 -07:00
|
|
|
aBasePrefName.AppendLiteral("with_alt.");
|
2012-08-11 18:42:34 -07:00
|
|
|
break;
|
|
|
|
case INDEX_CONTROL:
|
2012-08-11 18:42:35 -07:00
|
|
|
aBasePrefName.AppendLiteral("with_control.");
|
2012-08-11 18:42:34 -07:00
|
|
|
break;
|
|
|
|
case INDEX_META:
|
2012-08-11 18:42:35 -07:00
|
|
|
aBasePrefName.AppendLiteral("with_meta.");
|
2012-08-11 18:42:34 -07:00
|
|
|
break;
|
|
|
|
case INDEX_SHIFT:
|
2012-08-11 18:42:35 -07:00
|
|
|
aBasePrefName.AppendLiteral("with_shift.");
|
2012-08-11 18:42:34 -07:00
|
|
|
break;
|
|
|
|
case INDEX_OS:
|
2012-08-11 18:42:35 -07:00
|
|
|
aBasePrefName.AppendLiteral("with_win.");
|
2012-08-11 18:42:34 -07:00
|
|
|
break;
|
|
|
|
case INDEX_DEFAULT:
|
|
|
|
default:
|
2012-08-11 18:42:35 -07:00
|
|
|
aBasePrefName.AppendLiteral("default.");
|
2012-08-11 18:42:34 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::WheelPrefs::Init(
|
|
|
|
nsEventStateManager::WheelPrefs::Index aIndex)
|
|
|
|
{
|
|
|
|
if (mInit[aIndex]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mInit[aIndex] = true;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString basePrefName;
|
2012-08-11 18:42:34 -07:00
|
|
|
GetBasePrefName(aIndex, basePrefName);
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString prefNameX(basePrefName);
|
2012-08-11 18:42:34 -07:00
|
|
|
prefNameX.AppendLiteral("delta_multiplier_x");
|
|
|
|
mMultiplierX[aIndex] =
|
|
|
|
static_cast<double>(Preferences::GetInt(prefNameX.get(), 100)) / 100;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString prefNameY(basePrefName);
|
2012-08-11 18:42:34 -07:00
|
|
|
prefNameY.AppendLiteral("delta_multiplier_y");
|
|
|
|
mMultiplierY[aIndex] =
|
|
|
|
static_cast<double>(Preferences::GetInt(prefNameY.get(), 100)) / 100;
|
2012-08-11 18:42:35 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString prefNameZ(basePrefName);
|
2012-08-11 18:42:36 -07:00
|
|
|
prefNameZ.AppendLiteral("delta_multiplier_z");
|
|
|
|
mMultiplierZ[aIndex] =
|
|
|
|
static_cast<double>(Preferences::GetInt(prefNameZ.get(), 100)) / 100;
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString prefNameAction(basePrefName);
|
2012-08-11 18:42:35 -07:00
|
|
|
prefNameAction.AppendLiteral("action");
|
2012-12-07 20:08:19 -08:00
|
|
|
int32_t action = Preferences::GetInt(prefNameAction.get(), ACTION_SCROLL);
|
2012-12-09 10:28:49 -08:00
|
|
|
if (action < int32_t(ACTION_NONE) || action > int32_t(ACTION_LAST)) {
|
2012-08-11 18:42:35 -07:00
|
|
|
NS_WARNING("Unsupported action pref value, replaced with 'Scroll'.");
|
2012-12-07 20:08:19 -08:00
|
|
|
action = ACTION_SCROLL;
|
|
|
|
}
|
|
|
|
mActions[aIndex] = static_cast<Action>(action);
|
|
|
|
|
|
|
|
// Compute action values overridden by .override_x pref.
|
|
|
|
// At present, override is possible only for the x-direction
|
|
|
|
// because this pref is introduced mainly for tilt wheels.
|
|
|
|
prefNameAction.AppendLiteral(".override_x");
|
|
|
|
int32_t actionOverrideX = Preferences::GetInt(prefNameAction.get(), -1);
|
2012-12-09 10:28:49 -08:00
|
|
|
if (actionOverrideX < -1 || actionOverrideX > int32_t(ACTION_LAST)) {
|
2012-12-07 20:08:19 -08:00
|
|
|
NS_WARNING("Unsupported action override pref value, didn't override.");
|
|
|
|
actionOverrideX = -1;
|
|
|
|
}
|
|
|
|
mOverriddenActionsX[aIndex] = (actionOverrideX == -1)
|
|
|
|
? static_cast<Action>(action)
|
|
|
|
: static_cast<Action>(actionOverrideX);
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::WheelPrefs::ApplyUserPrefsToDelta(
|
2012-08-11 18:42:35 -07:00
|
|
|
widget::WheelEvent* aEvent)
|
2012-08-11 18:42:34 -07:00
|
|
|
{
|
|
|
|
Index index = GetIndexFor(aEvent);
|
|
|
|
Init(index);
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
aEvent->deltaX *= mMultiplierX[index];
|
|
|
|
aEvent->deltaY *= mMultiplierY[index];
|
2012-08-11 18:42:36 -07:00
|
|
|
aEvent->deltaZ *= mMultiplierZ[index];
|
2012-08-11 18:42:35 -07:00
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
// If the multiplier is 1.0 or -1.0, i.e., it doesn't change the absolute
|
|
|
|
// value, we should use lineOrPageDelta values which were set by widget.
|
|
|
|
// Otherwise, we need to compute them from accumulated delta values.
|
2012-08-11 18:42:36 -07:00
|
|
|
if (!NeedToComputeLineOrPageDelta(aEvent)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
aEvent->lineOrPageDeltaX *= static_cast<int32_t>(mMultiplierX[index]);
|
|
|
|
aEvent->lineOrPageDeltaY *= static_cast<int32_t>(mMultiplierY[index]);
|
2012-08-11 18:42:35 -07:00
|
|
|
} else {
|
|
|
|
aEvent->lineOrPageDeltaX = 0;
|
|
|
|
aEvent->lineOrPageDeltaY = 0;
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
aEvent->customizedByUserPrefs =
|
2012-08-11 18:42:36 -07:00
|
|
|
((mMultiplierX[index] != 1.0) || (mMultiplierY[index] != 1.0) ||
|
|
|
|
(mMultiplierZ[index] != 1.0));
|
2012-08-11 18:42:34 -07:00
|
|
|
}
|
2012-08-11 18:42:35 -07:00
|
|
|
|
2012-08-11 18:42:36 -07:00
|
|
|
void
|
|
|
|
nsEventStateManager::WheelPrefs::CancelApplyingUserPrefsFromOverflowDelta(
|
|
|
|
widget::WheelEvent* aEvent)
|
|
|
|
{
|
|
|
|
Index index = GetIndexFor(aEvent);
|
|
|
|
Init(index);
|
|
|
|
|
2012-08-29 18:05:16 -07:00
|
|
|
// XXX If the multiplier pref value is negative, the scroll direction was
|
|
|
|
// changed and caused to scroll different direction. In such case,
|
|
|
|
// this method reverts the sign of overflowDelta. Does it make widget
|
|
|
|
// happy? Although, widget can know the pref applied delta values by
|
|
|
|
// referrencing the deltaX and deltaY of the event.
|
|
|
|
|
2012-08-16 18:32:15 -07:00
|
|
|
if (mMultiplierX[index]) {
|
|
|
|
aEvent->overflowDeltaX /= mMultiplierX[index];
|
|
|
|
}
|
|
|
|
if (mMultiplierY[index]) {
|
|
|
|
aEvent->overflowDeltaY /= mMultiplierY[index];
|
|
|
|
}
|
2012-08-11 18:42:36 -07:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:42:35 -07:00
|
|
|
nsEventStateManager::WheelPrefs::Action
|
2012-08-11 18:42:36 -07:00
|
|
|
nsEventStateManager::WheelPrefs::ComputeActionFor(widget::WheelEvent* aEvent)
|
2012-08-11 18:42:35 -07:00
|
|
|
{
|
|
|
|
Index index = GetIndexFor(aEvent);
|
|
|
|
Init(index);
|
2012-08-11 18:42:36 -07:00
|
|
|
|
2012-12-07 20:08:19 -08:00
|
|
|
bool deltaXPreferred =
|
2013-03-05 15:43:44 -08:00
|
|
|
(Abs(aEvent->deltaX) > Abs(aEvent->deltaY) &&
|
|
|
|
Abs(aEvent->deltaX) > Abs(aEvent->deltaZ));
|
2012-12-07 20:08:19 -08:00
|
|
|
Action* actions = deltaXPreferred ? mOverriddenActionsX : mActions;
|
|
|
|
if (actions[index] == ACTION_NONE || actions[index] == ACTION_SCROLL) {
|
|
|
|
return actions[index];
|
2012-08-11 18:42:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Momentum events shouldn't run special actions.
|
|
|
|
if (aEvent->isMomentum) {
|
|
|
|
// Use the default action. Note that user might kill the wheel scrolling.
|
|
|
|
Init(INDEX_DEFAULT);
|
2012-12-07 20:08:19 -08:00
|
|
|
return (actions[INDEX_DEFAULT] == ACTION_SCROLL) ? ACTION_SCROLL :
|
|
|
|
ACTION_NONE;
|
2012-08-11 18:42:36 -07:00
|
|
|
}
|
|
|
|
|
2013-01-05 04:14:27 -08:00
|
|
|
return actions[index];
|
2012-08-11 18:42:35 -07:00
|
|
|
}
|
2012-08-11 18:42:36 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsEventStateManager::WheelPrefs::NeedToComputeLineOrPageDelta(
|
|
|
|
widget::WheelEvent* aEvent)
|
|
|
|
{
|
|
|
|
Index index = GetIndexFor(aEvent);
|
|
|
|
Init(index);
|
|
|
|
|
|
|
|
return (mMultiplierX[index] != 1.0 && mMultiplierX[index] != -1.0) ||
|
|
|
|
(mMultiplierY[index] != 1.0 && mMultiplierY[index] != -1.0);
|
|
|
|
}
|
2012-10-30 16:22:23 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedX(
|
|
|
|
widget::WheelEvent* aEvent)
|
|
|
|
{
|
|
|
|
Index index = GetIndexFor(aEvent);
|
|
|
|
Init(index);
|
2013-03-05 15:43:44 -08:00
|
|
|
return Abs(mMultiplierX[index]) >=
|
2012-10-30 16:22:23 -07:00
|
|
|
MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsEventStateManager::WheelPrefs::IsOverOnePageScrollAllowedY(
|
|
|
|
widget::WheelEvent* aEvent)
|
|
|
|
{
|
|
|
|
Index index = GetIndexFor(aEvent);
|
|
|
|
Init(index);
|
2013-03-05 15:43:44 -08:00
|
|
|
return Abs(mMultiplierY[index]) >=
|
2012-10-30 16:22:23 -07:00
|
|
|
MIN_MULTIPLIER_VALUE_ALLOWING_OVER_ONE_PAGE_SCROLL;
|
|
|
|
}
|