2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-10-24 07:38:55 +00:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2001-09-25 01:32:19 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-23 21:53:02 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-06-23 21:53:02 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-06-23 21:53:02 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
2002-12-06 03:41:43 +00:00
|
|
|
* Makoto Kato <m_kato@ga2.so-net.ne.jp>
|
|
|
|
* Dean Tessman <dean_tessman@hotmail.com>
|
2005-06-21 22:55:39 +00:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2005-11-14 23:55:24 +00:00
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
2005-11-18 03:44:50 +00:00
|
|
|
* Ginn Chen <ginn.chen@sun.com>
|
2006-07-13 10:18:12 +00:00
|
|
|
* Simon Bünzli <zeniko@gmail.com>
|
2008-05-08 20:00:24 +00:00
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2009-02-10 20:56:51 +00:00
|
|
|
* Ningjie Chen <chenn@email.uc.edu>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2000-03-16 03:34:52 +00:00
|
|
|
|
2010-09-24 03:28:15 +00:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2010-08-17 08:07:44 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-06-23 21:53:02 +00:00
|
|
|
#include "nsEventStateManager.h"
|
2002-07-24 06:13:18 +00:00
|
|
|
#include "nsEventListenerManager.h"
|
2006-04-11 16:37:58 +00:00
|
|
|
#include "nsIMEStateManager.h"
|
2009-02-10 20:56:51 +00:00
|
|
|
#include "nsContentEventHandler.h"
|
1998-08-07 04:45:03 +00:00
|
|
|
#include "nsIContent.h"
|
2003-09-27 04:18:26 +00:00
|
|
|
#include "nsINodeInfo.h"
|
1998-08-07 04:45:03 +00:00
|
|
|
#include "nsIDocument.h"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIWidget.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsDOMEvent.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2003-05-11 21:14:07 +00:00
|
|
|
#include "nsIEditorDocShell.h"
|
Fixes bug 66597, bug 103284, bug 114440, bug 120023, bug 128741, bug 19259. Cleans up browse with caret, makes it work with XML content docs, creates keyboard toggle for it (Accel+shift+K), synchronizes focus and document selection so that users can tab navigate relative to their last find or click in text, or vice versa, makes tabbing move relative to named anchor that has been jumped to. r=bryner, sr=alecf, a=asa
2002-03-10 06:21:48 +00:00
|
|
|
#include "nsIFormControl.h"
|
2006-02-27 04:13:51 +00:00
|
|
|
#include "nsIComboboxControlFrame.h"
|
2009-08-13 20:54:09 +00:00
|
|
|
#include "nsIScrollableFrame.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
#include "nsIDOMNSHTMLElement.h"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2010-07-28 23:43:52 +00:00
|
|
|
#include "nsIDOMHTMLLabelElement.h"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIDOMHTMLSelectElement.h"
|
|
|
|
#include "nsIDOMHTMLTextAreaElement.h"
|
1999-03-02 19:19:24 +00:00
|
|
|
#include "nsIDOMHTMLAreaElement.h"
|
|
|
|
#include "nsIDOMHTMLButtonElement.h"
|
|
|
|
#include "nsIDOMHTMLObjectElement.h"
|
massive landing of joki changes.
Relevant nsbeta3+ bugs 43309, 44503, 2634, 2504,5981, 24698, 25758, 33577,
36062, 36217, 41191, 41491, 42356, 42829, 43016
r=saari (joki code). also been tested by heikki and bryner
2000-08-08 21:31:05 +00:00
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
|
|
|
#include "nsIDOMHTMLMapElement.h"
|
2001-05-22 23:52:17 +00:00
|
|
|
#include "nsIDOMHTMLBodyElement.h"
|
2003-03-26 02:55:19 +00:00
|
|
|
#include "nsIDOMXULControlElement.h"
|
2005-08-26 18:45:23 +00:00
|
|
|
#include "nsIDOMXULTextboxElement.h"
|
2002-11-29 23:44:07 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2000-02-11 01:56:01 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
2007-02-12 19:17:33 +00:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
2006-04-26 01:57:22 +00:00
|
|
|
#include "nsFrameSelection.h"
|
1999-12-08 04:54:29 +00:00
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2000-09-01 01:54:35 +00:00
|
|
|
#include "nsIDOMWindowInternal.h"
|
1999-12-18 04:02:28 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2010-02-20 16:07:03 +00:00
|
|
|
#include "nsPIWindowRoot.h"
|
2001-11-06 09:02:55 +00:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2000-04-04 23:55:31 +00:00
|
|
|
#include "nsIEnumerator.h"
|
2000-04-16 06:14:38 +00:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2001-10-22 22:43:52 +00:00
|
|
|
#include "nsIDocShellTreeNode.h"
|
2000-04-16 06:14:38 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsIContentViewer.h"
|
2007-08-26 05:37:02 +00:00
|
|
|
#ifdef MOZ_XUL
|
2007-08-16 01:09:58 +00:00
|
|
|
#include "nsXULPopupManager.h"
|
2007-08-26 05:37:02 +00:00
|
|
|
#endif
|
2010-01-11 21:45:02 +00:00
|
|
|
#include "nsFrameManager.h"
|
1999-08-19 19:48:45 +00:00
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2001-11-20 08:40:54 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2000-01-06 06:22:00 +00: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 18:00:39 +00:00
|
|
|
#include "nsFocusManager.h"
|
2000-11-04 08:21:20 +00:00
|
|
|
|
2002-02-21 13:39:39 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
2003-03-26 07:41:30 +00:00
|
|
|
#include "nsIDOMDocument.h"
|
2002-05-08 20:43:49 +00:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2000-03-15 04:03:44 +00:00
|
|
|
#include "nsIObserverService.h"
|
2000-05-15 02:10:11 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
2008-09-17 11:27:19 +00:00
|
|
|
#include "nsIDOMMouseScrollEvent.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
#include "nsIDOMDragEvent.h"
|
2001-11-14 10:06:21 +00:00
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIDOMNSUIEvent.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
#include "nsDOMDragEvent.h"
|
2008-09-25 14:45:03 +00:00
|
|
|
#include "nsIDOMNSEditableElement.h"
|
2001-02-15 05:07:46 +00:00
|
|
|
|
|
|
|
#include "nsIDOMRange.h"
|
2008-07-16 10:52:01 +00:00
|
|
|
#include "nsCaret.h"
|
2001-02-15 05:07:46 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2000-01-13 11:43:54 +00:00
|
|
|
|
2010-08-31 00:49:07 +00:00
|
|
|
#include "nsSubDocumentFrame.h"
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsIFrameTraversal.h"
|
|
|
|
#include "nsLayoutCID.h"
|
2004-08-06 15:55:17 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2001-10-22 22:43:52 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2001-12-17 07:14:49 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2002-08-09 08:45:30 +00:00
|
|
|
#include "nsContentUtils.h"
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2004-12-30 21:56:11 +00:00
|
|
|
#include "imgIContainer.h"
|
2005-07-01 04:29:42 +00:00
|
|
|
#include "nsIProperties.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
2006-03-07 17:08:51 +00:00
|
|
|
#include "nsEventDispatcher.h"
|
2004-12-30 21:56:11 +00:00
|
|
|
|
2007-10-22 21:42:25 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsITimer.h"
|
2011-04-08 01:05:49 +00:00
|
|
|
#include "nsFontMetrics.h"
|
2008-12-30 14:09:14 +00:00
|
|
|
#include "nsIDOMXULDocument.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
#include "nsIDragService.h"
|
|
|
|
#include "nsIDragSession.h"
|
|
|
|
#include "nsDOMDataTransfer.h"
|
|
|
|
#include "nsContentAreaDragDrop.h"
|
|
|
|
#ifdef MOZ_XUL
|
2008-10-28 04:47:19 +00:00
|
|
|
#include "nsTreeBodyFrame.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
#endif
|
2009-08-07 15:11:17 +00:00
|
|
|
#include "nsIController.h"
|
2010-01-11 01:45:45 +00: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 16:59:13 +00:00
|
|
|
#include "mozilla/Services.h"
|
2011-03-29 03:32:11 +00:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2011-05-25 00:18:40 +00:00
|
|
|
#include "nsHTMLLabelElement.h"
|
2008-08-27 12:07:27 +00:00
|
|
|
|
2011-05-25 06:31:59 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2005-08-13 00:20:46 +00:00
|
|
|
#ifdef XP_MACOSX
|
2009-09-18 16:34:37 +00:00
|
|
|
#import <ApplicationServices/ApplicationServices.h>
|
2002-03-26 00:59:03 +00:00
|
|
|
#endif
|
|
|
|
|
2011-05-25 06:31:59 +00:00
|
|
|
using namespace mozilla;
|
2010-09-24 03:28:15 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2001-05-22 23:52:17 +00:00
|
|
|
//#define DEBUG_DOCSHELL_FOCUS
|
2001-03-30 04:45:40 +00:00
|
|
|
|
2007-10-22 21:42:25 +00:00
|
|
|
#define NS_USER_INTERACTION_INTERVAL 5000 // ms
|
|
|
|
|
2001-02-19 12:55:42 +00:00
|
|
|
static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID);
|
|
|
|
|
2001-02-15 05:07:46 +00:00
|
|
|
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
2000-03-15 04:03:44 +00:00
|
|
|
|
2004-04-13 06:41:35 +00:00
|
|
|
static PRBool sLeftClickOnly = PR_TRUE;
|
|
|
|
static PRBool sKeyCausesActivation = PR_TRUE;
|
|
|
|
static PRUint32 sESMInstanceCount = 0;
|
2006-07-13 10:18:12 +00:00
|
|
|
static PRInt32 sChromeAccessModifier = 0, sContentAccessModifier = 0;
|
2004-09-04 19:28:46 +00:00
|
|
|
PRInt32 nsEventStateManager::sUserInputEventDepth = 0;
|
2010-09-08 17:41:37 +00:00
|
|
|
PRBool nsEventStateManager::sNormalLMouseEventInProcess = PR_FALSE;
|
2010-09-16 13:10:18 +00:00
|
|
|
nsEventStateManager* nsEventStateManager::sActiveESM = nsnull;
|
2010-09-17 18:56:53 +00:00
|
|
|
nsIDocument* nsEventStateManager::sMouseOverDocument = nsnull;
|
1999-12-01 09:09:46 +00:00
|
|
|
|
2007-10-22 21:42:25 +00:00
|
|
|
static PRUint32 gMouseOrKeyboardEventCounter = 0;
|
|
|
|
static nsITimer* gUserInteractionTimer = nsnull;
|
|
|
|
static nsITimerCallback* gUserInteractionTimerCallback = nsnull;
|
|
|
|
|
2009-04-02 19:34:31 +00:00
|
|
|
// Pixel scroll accumulation for synthetic line scrolls
|
|
|
|
static nscoord gPixelScrollDeltaX = 0;
|
|
|
|
static nscoord gPixelScrollDeltaY = 0;
|
|
|
|
static PRUint32 gPixelScrollDeltaTimeout = 0;
|
|
|
|
|
|
|
|
static nscoord
|
2010-01-11 21:45:04 +00:00
|
|
|
GetScrollableLineHeight(nsIFrame* aTargetFrame);
|
2009-04-02 19:34:31 +00:00
|
|
|
|
2010-03-24 03:36:27 +00:00
|
|
|
static inline PRBool
|
|
|
|
IsMouseEventReal(nsEvent* aEvent)
|
|
|
|
{
|
2010-05-13 02:33:16 +00:00
|
|
|
NS_ABORT_IF_FALSE(NS_IS_MOUSE_EVENT_STRUCT(aEvent), "Not a mouse event");
|
2010-03-24 03:36:27 +00:00
|
|
|
// Return true if not synthesized.
|
|
|
|
return static_cast<nsMouseEvent*>(aEvent)->reason == nsMouseEvent::eReal;
|
|
|
|
}
|
|
|
|
|
2008-11-02 15:00:05 +00:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
static void
|
|
|
|
PrintDocTree(nsIDocShellTreeItem* aParentItem, int aLevel)
|
|
|
|
{
|
|
|
|
for (PRInt32 i=0;i<aLevel;i++) printf(" ");
|
|
|
|
|
|
|
|
PRInt32 childWebshellCount;
|
|
|
|
aParentItem->GetChildCount(&childWebshellCount);
|
|
|
|
nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(aParentItem));
|
|
|
|
PRInt32 type;
|
|
|
|
aParentItem->GetItemType(&type);
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
parentAsDocShell->GetPresShell(getter_AddRefs(presShell));
|
2010-03-25 13:17:11 +00:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
2008-11-02 15:00:05 +00: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);
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domwin = doc ? doc->GetWindow() : nsnull;
|
|
|
|
nsIURI* uri = doc ? doc->GetDocumentURI() : nsnull;
|
|
|
|
|
|
|
|
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()),
|
|
|
|
static_cast<void*>(presContext ? presContext->EventStateManager() : nsnull),
|
|
|
|
uri ? ' ' : '\n');
|
|
|
|
if (uri) {
|
|
|
|
nsCAutoString spec;
|
|
|
|
uri->GetSpec(spec);
|
|
|
|
printf("\"%s\"\n", spec.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childWebshellCount > 0) {
|
|
|
|
for (PRInt32 i = 0; i < childWebshellCount; i++) {
|
|
|
|
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
|
|
|
|
|
2007-10-22 21:42:25 +00:00
|
|
|
class nsUITimerCallback : public nsITimerCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsUITimerCallback() : mPreviousCount(0) {}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSITIMERCALLBACK
|
|
|
|
private:
|
|
|
|
PRUint32 mPreviousCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsUITimerCallback, nsITimerCallback)
|
|
|
|
|
|
|
|
// If aTimer is nsnull, this method always sends "user-interaction-inactive"
|
|
|
|
// 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 16:59:13 +00:00
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (!obs)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-10-22 21:42:25 +00:00
|
|
|
if ((gMouseOrKeyboardEventCounter == mPreviousCount) || !aTimer) {
|
|
|
|
gMouseOrKeyboardEventCounter = 0;
|
|
|
|
obs->NotifyObservers(nsnull, "user-interaction-inactive", nsnull);
|
2010-11-07 19:07:59 +00:00
|
|
|
if (gUserInteractionTimer) {
|
|
|
|
gUserInteractionTimer->Cancel();
|
|
|
|
NS_RELEASE(gUserInteractionTimer);
|
|
|
|
}
|
2007-10-22 21:42:25 +00:00
|
|
|
} else {
|
|
|
|
obs->NotifyObservers(nsnull, "user-interaction-active", nsnull);
|
2010-11-07 19:07:59 +00:00
|
|
|
nsEventStateManager::UpdateUserActivityTimer();
|
2007-10-22 21:42:25 +00:00
|
|
|
}
|
|
|
|
mPreviousCount = gMouseOrKeyboardEventCounter;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
enum {
|
|
|
|
MOUSE_SCROLL_N_LINES,
|
|
|
|
MOUSE_SCROLL_PAGE,
|
2000-04-25 06:25:43 +00:00
|
|
|
MOUSE_SCROLL_HISTORY,
|
2008-02-13 11:00:45 +00:00
|
|
|
MOUSE_SCROLL_ZOOM,
|
|
|
|
MOUSE_SCROLL_PIXELS
|
2000-01-06 06:22:00 +00:00
|
|
|
};
|
|
|
|
|
2006-07-13 10:18:12 +00: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
|
|
|
|
|
2005-07-30 20:57:07 +00:00
|
|
|
static nsIDocument *
|
2005-08-12 04:11:00 +00:00
|
|
|
GetDocumentFromWindow(nsIDOMWindow *aWindow)
|
2005-07-30 20:57:07 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aWindow);
|
2005-08-12 04:11:00 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2005-07-30 20:57:07 +00:00
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
if (win) {
|
|
|
|
doc = do_QueryInterface(win->GetExtantDocument());
|
2005-07-30 20:57:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2006-07-13 10:18:12 +00:00
|
|
|
static PRInt32
|
|
|
|
GetAccessModifierMaskFromPref(PRInt32 aItemType)
|
|
|
|
{
|
2011-05-25 06:32:00 +00:00
|
|
|
PRInt32 accessKey = Preferences::GetInt("ui.key.generalAccessKey", -1);
|
2006-07-13 10:18:12 +00: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;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aItemType) {
|
|
|
|
case nsIDocShellTreeItem::typeChrome:
|
2011-05-25 06:32:00 +00:00
|
|
|
return Preferences::GetInt("ui.key.chromeAccess", 0);
|
2006-07-13 10:18:12 +00:00
|
|
|
case nsIDocShellTreeItem::typeContent:
|
2011-05-25 06:32:00 +00:00
|
|
|
return Preferences::GetInt("ui.key.contentAccess", 0);
|
2006-07-13 10:18:12 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-20 14:57:52 +00:00
|
|
|
static void
|
|
|
|
GetBasePrefKeyForMouseWheel(nsMouseScrollEvent* aEvent, nsACString& aPref)
|
|
|
|
{
|
|
|
|
NS_NAMED_LITERAL_CSTRING(prefbase, "mousewheel");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(horizscroll, ".horizscroll");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(withshift, ".withshiftkey");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(withalt, ".withaltkey");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(withcontrol, ".withcontrolkey");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(withmetakey, ".withmetakey");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(withno, ".withnokey");
|
|
|
|
|
|
|
|
aPref = prefbase;
|
|
|
|
if (aEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) {
|
|
|
|
aPref.Append(horizscroll);
|
|
|
|
}
|
|
|
|
if (aEvent->isShift) {
|
|
|
|
aPref.Append(withshift);
|
|
|
|
} else if (aEvent->isControl) {
|
|
|
|
aPref.Append(withcontrol);
|
|
|
|
} else if (aEvent->isAlt) {
|
|
|
|
aPref.Append(withalt);
|
|
|
|
} else if (aEvent->isMeta) {
|
|
|
|
aPref.Append(withmetakey);
|
|
|
|
} else {
|
|
|
|
aPref.Append(withno);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-12 04:15:42 +00:00
|
|
|
class nsMouseWheelTransaction {
|
|
|
|
public:
|
|
|
|
static nsIFrame* GetTargetFrame() { return sTargetFrame; }
|
|
|
|
static void BeginTransaction(nsIFrame* aTargetFrame,
|
2009-02-12 10:44:38 +00:00
|
|
|
PRInt32 aNumLines,
|
|
|
|
PRBool aScrollHorizontal);
|
2009-02-17 15:55:53 +00:00
|
|
|
// Be careful, UpdateTransaction may fire a DOM event, therefore, the target
|
|
|
|
// frame might be destroyed in the event handler.
|
2009-02-12 10:44:38 +00:00
|
|
|
static PRBool UpdateTransaction(PRInt32 aNumLines,
|
|
|
|
PRBool aScrollHorizontal);
|
2006-07-12 04:15:42 +00:00
|
|
|
static void EndTransaction();
|
|
|
|
static void OnEvent(nsEvent* aEvent);
|
2009-02-12 10:44:38 +00:00
|
|
|
static void Shutdown();
|
2009-04-02 19:34:31 +00:00
|
|
|
static PRUint32 GetTimeoutTime();
|
2009-09-24 10:58:04 +00:00
|
|
|
static PRInt32 AccelerateWheelDelta(PRInt32 aScrollLines,
|
|
|
|
PRBool aIsHorizontal, PRBool aAllowScrollSpeedOverride,
|
2011-05-23 14:56:59 +00:00
|
|
|
nsIScrollableFrame::ScrollUnit *aScrollQuantity,
|
|
|
|
PRBool aLimitToMaxOnePageScroll = PR_TRUE);
|
2011-05-18 23:12:34 +00:00
|
|
|
static PRBool IsAccelerationEnabled();
|
2009-09-03 07:07:18 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
kScrollSeriesTimeout = 80
|
|
|
|
};
|
2006-07-12 04:15:42 +00:00
|
|
|
protected:
|
2009-01-15 03:27:09 +00:00
|
|
|
static nsIntPoint GetScreenPoint(nsGUIEvent* aEvent);
|
2009-02-12 10:44:38 +00:00
|
|
|
static void OnFailToScrollTarget();
|
|
|
|
static void OnTimeout(nsITimer *aTimer, void *aClosure);
|
|
|
|
static void SetTimeout();
|
2006-08-07 06:33:46 +00:00
|
|
|
static PRUint32 GetIgnoreMoveDelayTime();
|
2009-09-03 07:07:18 +00:00
|
|
|
static PRInt32 GetAccelerationStart();
|
|
|
|
static PRInt32 GetAccelerationFactor();
|
2009-09-24 10:58:04 +00:00
|
|
|
static PRInt32 OverrideSystemScrollSpeed(PRInt32 aScrollLines,
|
|
|
|
PRBool aIsHorizontal);
|
|
|
|
static PRInt32 ComputeAcceleratedWheelDelta(PRInt32 aDelta, PRInt32 aFactor);
|
|
|
|
static PRInt32 LimitToOnePageScroll(PRInt32 aScrollLines,
|
|
|
|
PRBool aIsHorizontal,
|
2010-01-11 21:45:02 +00:00
|
|
|
nsIScrollableFrame::ScrollUnit *aScrollQuantity);
|
2006-07-12 04:15:42 +00:00
|
|
|
|
2006-08-07 06:33:46 +00:00
|
|
|
static nsWeakFrame sTargetFrame;
|
|
|
|
static PRUint32 sTime; // in milliseconds
|
|
|
|
static PRUint32 sMouseMoved; // in milliseconds
|
2009-02-12 10:44:38 +00:00
|
|
|
static nsITimer* sTimer;
|
2009-09-03 07:07:18 +00:00
|
|
|
static PRInt32 sScrollSeriesCounter;
|
2006-07-12 04:15:42 +00:00
|
|
|
};
|
|
|
|
|
2006-07-14 07:55:51 +00:00
|
|
|
nsWeakFrame nsMouseWheelTransaction::sTargetFrame(nsnull);
|
|
|
|
PRUint32 nsMouseWheelTransaction::sTime = 0;
|
2006-08-07 06:33:46 +00:00
|
|
|
PRUint32 nsMouseWheelTransaction::sMouseMoved = 0;
|
2009-02-12 10:44:38 +00:00
|
|
|
nsITimer* nsMouseWheelTransaction::sTimer = nsnull;
|
2009-09-03 07:07:18 +00:00
|
|
|
PRInt32 nsMouseWheelTransaction::sScrollSeriesCounter = 0;
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
OutOfTime(PRUint32 aBaseTime, PRUint32 aThreshold)
|
|
|
|
{
|
|
|
|
PRUint32 now = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
return (now - aBaseTime > aThreshold);
|
|
|
|
}
|
2009-02-12 10:44:38 +00:00
|
|
|
|
|
|
|
static PRBool
|
2010-01-11 21:45:02 +00:00
|
|
|
CanScrollInRange(nscoord aMin, nscoord aValue, nscoord aMax, PRInt32 aDirection)
|
|
|
|
{
|
|
|
|
return aDirection > 0 ? aValue < aMax : aMin < aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
CanScrollOn(nsIScrollableFrame* aScrollFrame, PRInt32 aNumLines,
|
2009-02-12 10:44:38 +00:00
|
|
|
PRBool aScrollHorizontal)
|
|
|
|
{
|
2010-01-11 21:45:02 +00:00
|
|
|
NS_PRECONDITION(aScrollFrame, "aScrollFrame is null");
|
2009-02-12 10:44:38 +00:00
|
|
|
NS_PRECONDITION(aNumLines, "aNumLines must be non-zero");
|
2010-01-11 21:45:02 +00:00
|
|
|
nsPoint scrollPt = aScrollFrame->GetScrollPosition();
|
|
|
|
nsRect scrollRange = aScrollFrame->GetScrollRange();
|
|
|
|
|
|
|
|
return aScrollHorizontal
|
|
|
|
? CanScrollInRange(scrollRange.x, scrollPt.x, scrollRange.XMost(), aNumLines)
|
|
|
|
: CanScrollInRange(scrollRange.y, scrollPt.y, scrollRange.YMost(), aNumLines);
|
2009-02-12 10:44:38 +00:00
|
|
|
}
|
2006-07-12 04:15:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::BeginTransaction(nsIFrame* aTargetFrame,
|
2009-02-12 10:44:38 +00:00
|
|
|
PRInt32 aNumLines,
|
|
|
|
PRBool aScrollHorizontal)
|
2006-07-12 04:15:42 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!sTargetFrame, "previous transaction is not finished!");
|
|
|
|
sTargetFrame = aTargetFrame;
|
2009-09-03 07:07:18 +00:00
|
|
|
sScrollSeriesCounter = 0;
|
2009-02-12 10:44:38 +00:00
|
|
|
if (!UpdateTransaction(aNumLines, aScrollHorizontal)) {
|
|
|
|
NS_ERROR("BeginTransaction is called even cannot scroll the frame");
|
|
|
|
EndTransaction();
|
|
|
|
}
|
2006-07-12 04:15:42 +00:00
|
|
|
}
|
|
|
|
|
2009-02-12 10:44:38 +00:00
|
|
|
PRBool
|
|
|
|
nsMouseWheelTransaction::UpdateTransaction(PRInt32 aNumLines,
|
|
|
|
PRBool aScrollHorizontal)
|
2006-07-12 04:15:42 +00:00
|
|
|
{
|
2010-01-11 21:45:02 +00:00
|
|
|
nsIScrollableFrame* sf = GetTargetFrame()->GetScrollTargetFrame();
|
|
|
|
NS_ENSURE_TRUE(sf, PR_FALSE);
|
2009-02-12 10:44:38 +00:00
|
|
|
|
2010-01-11 21:45:02 +00:00
|
|
|
if (!CanScrollOn(sf, aNumLines, aScrollHorizontal)) {
|
2009-02-12 10:44:38 +00:00
|
|
|
OnFailToScrollTarget();
|
|
|
|
// We should not modify the transaction state when the view will not be
|
|
|
|
// scrolled actually.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetTimeout();
|
2009-09-03 07:07:18 +00:00
|
|
|
|
|
|
|
if (sScrollSeriesCounter != 0 && OutOfTime(sTime, kScrollSeriesTimeout))
|
|
|
|
sScrollSeriesCounter = 0;
|
|
|
|
sScrollSeriesCounter++;
|
|
|
|
|
2006-07-12 04:15:42 +00: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());
|
2006-08-07 06:33:46 +00:00
|
|
|
sMouseMoved = 0;
|
2009-02-12 10:44:38 +00:00
|
|
|
return PR_TRUE;
|
2006-07-12 04:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::EndTransaction()
|
|
|
|
{
|
2009-02-12 10:44:38 +00:00
|
|
|
if (sTimer)
|
|
|
|
sTimer->Cancel();
|
2006-07-12 04:15:42 +00:00
|
|
|
sTargetFrame = nsnull;
|
2009-09-03 07:07:18 +00:00
|
|
|
sScrollSeriesCounter = 0;
|
2006-07-12 04:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::OnEvent(nsEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!sTargetFrame)
|
|
|
|
return;
|
|
|
|
|
2006-08-07 06:33:46 +00:00
|
|
|
if (OutOfTime(sTime, GetTimeoutTime())) {
|
2009-02-12 10:44:38 +00: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.
|
|
|
|
OnTimeout(nsnull, nsnull);
|
2006-07-12 04:15:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-23 14:56:59 +00:00
|
|
|
PRInt32 message = aEvent->message;
|
|
|
|
// If the event is query scroll target info event, that causes modifying
|
|
|
|
// wheel transaction because DoScrollText() needs to use them. Therefore,
|
|
|
|
// we should handle the event as its mouse scroll event here.
|
|
|
|
if (message == NS_QUERY_SCROLL_TARGET_INFO) {
|
|
|
|
nsQueryContentEvent* queryEvent = static_cast<nsQueryContentEvent*>(aEvent);
|
|
|
|
message = queryEvent->mInput.mMouseScrollEvent->message;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (message) {
|
2006-07-12 04:15:42 +00:00
|
|
|
case NS_MOUSE_SCROLL:
|
2011-05-23 14:56:59 +00:00
|
|
|
case NS_MOUSE_PIXEL_SCROLL:
|
2006-08-07 06:33:46 +00:00
|
|
|
if (sMouseMoved != 0 &&
|
|
|
|
OutOfTime(sMouseMoved, GetIgnoreMoveDelayTime())) {
|
|
|
|
// Terminate the current mousewheel transaction if the mouse moved more
|
|
|
|
// than ignoremovedelay milliseconds ago
|
|
|
|
EndTransaction();
|
|
|
|
}
|
2006-07-12 04:15:42 +00:00
|
|
|
return;
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
case NS_DRAGDROP_OVER:
|
2010-03-24 03:36:27 +00:00
|
|
|
if (IsMouseEventReal(aEvent)) {
|
2006-08-07 06:33:46 +00:00
|
|
|
// If the cursor is moving to be outside the frame,
|
|
|
|
// terminate the scrollwheel transaction.
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint pt = GetScreenPoint((nsGUIEvent*)aEvent);
|
2006-07-12 04:15:42 +00:00
|
|
|
nsIntRect r = sTargetFrame->GetScreenRectExternal();
|
2006-08-07 06:33:46 +00:00
|
|
|
if (!r.Contains(pt)) {
|
2006-07-12 04:15:42 +00:00
|
|
|
EndTransaction();
|
2006-08-07 06:33:46 +00:00
|
|
|
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());
|
|
|
|
}
|
2006-07-12 04:15:42 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case NS_KEY_PRESS:
|
|
|
|
case NS_KEY_UP:
|
|
|
|
case NS_KEY_DOWN:
|
2006-11-16 21:35:39 +00:00
|
|
|
case NS_MOUSE_BUTTON_UP:
|
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_DOUBLECLICK:
|
|
|
|
case NS_MOUSE_CLICK:
|
2006-07-12 04:15:42 +00:00
|
|
|
case NS_CONTEXTMENU:
|
|
|
|
case NS_DRAGDROP_DROP:
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-12 10:44:38 +00:00
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::Shutdown()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(sTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::OnFailToScrollTarget()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(sTargetFrame, "We don't have mouse scrolling transaction");
|
2009-05-06 04:30:39 +00:00
|
|
|
|
2011-05-25 06:31:59 +00:00
|
|
|
if (Preferences::GetBool("test.mousescroll", PR_FALSE)) {
|
2009-05-06 04:30:39 +00:00
|
|
|
// This event is used for automated tests, see bug 442774.
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
sTargetFrame->GetContent()->GetOwnerDoc(),
|
|
|
|
sTargetFrame->GetContent(),
|
|
|
|
NS_LITERAL_STRING("MozMouseScrollFailed"),
|
|
|
|
PR_TRUE, PR_TRUE);
|
|
|
|
}
|
2009-02-17 15:55:53 +00: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 10:44:38 +00: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-06 04:30:39 +00:00
|
|
|
|
2011-05-25 06:31:59 +00:00
|
|
|
if (Preferences::GetBool("test.mousescroll", PR_FALSE)) {
|
2009-05-06 04:30:39 +00:00
|
|
|
// This event is used for automated tests, see bug 442774.
|
|
|
|
nsContentUtils::DispatchTrustedEvent(
|
|
|
|
frame->GetContent()->GetOwnerDoc(),
|
|
|
|
frame->GetContent(),
|
|
|
|
NS_LITERAL_STRING("MozMouseScrollTransactionTimeout"),
|
|
|
|
PR_TRUE, PR_TRUE);
|
|
|
|
}
|
2009-02-12 10:44:38 +00: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 12:04:12 +00:00
|
|
|
#ifdef DEBUG
|
2009-02-12 10:44:38 +00:00
|
|
|
nsresult rv =
|
2011-04-14 12:04:12 +00:00
|
|
|
#endif
|
|
|
|
sTimer->InitWithFuncCallback(OnTimeout, nsnull, GetTimeoutTime(),
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2009-02-12 10:44:38 +00:00
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "nsITimer::InitWithFuncCallback failed");
|
|
|
|
}
|
|
|
|
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntPoint
|
2006-07-12 04:15:42 +00:00
|
|
|
nsMouseWheelTransaction::GetScreenPoint(nsGUIEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent, "aEvent is null");
|
|
|
|
NS_ASSERTION(aEvent->widget, "aEvent-widget is null");
|
2009-02-19 00:11:49 +00:00
|
|
|
return aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
|
2006-07-12 04:15:42 +00:00
|
|
|
}
|
|
|
|
|
2006-08-07 06:33:46 +00:00
|
|
|
PRUint32
|
|
|
|
nsMouseWheelTransaction::GetTimeoutTime()
|
|
|
|
{
|
2011-05-25 06:32:00 +00:00
|
|
|
return Preferences::GetUint("mousewheel.transaction.timeout", 1500);
|
2006-08-07 06:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsMouseWheelTransaction::GetIgnoreMoveDelayTime()
|
|
|
|
{
|
2011-05-25 06:32:00 +00:00
|
|
|
return Preferences::GetUint("mousewheel.transaction.ignoremovedelay", 100);
|
2006-08-07 06:33:46 +00:00
|
|
|
}
|
|
|
|
|
2011-05-18 23:12:34 +00:00
|
|
|
PRBool
|
|
|
|
nsMouseWheelTransaction::IsAccelerationEnabled()
|
|
|
|
{
|
|
|
|
return GetAccelerationStart() >= 0 && GetAccelerationFactor() > 0;
|
|
|
|
}
|
|
|
|
|
2009-09-24 10:58:04 +00:00
|
|
|
PRInt32
|
|
|
|
nsMouseWheelTransaction::AccelerateWheelDelta(PRInt32 aScrollLines,
|
|
|
|
PRBool aIsHorizontal,
|
|
|
|
PRBool aAllowScrollSpeedOverride,
|
2011-05-23 14:56:59 +00:00
|
|
|
nsIScrollableFrame::ScrollUnit *aScrollQuantity,
|
|
|
|
PRBool aLimitToMaxOnePageScroll)
|
2009-09-03 07:07:18 +00:00
|
|
|
{
|
2009-09-24 10:58:04 +00:00
|
|
|
if (aAllowScrollSpeedOverride) {
|
|
|
|
aScrollLines = OverrideSystemScrollSpeed(aScrollLines, aIsHorizontal);
|
|
|
|
}
|
2009-09-03 07:07:18 +00:00
|
|
|
|
2009-09-24 10:58:04 +00:00
|
|
|
// Accelerate by the sScrollSeriesCounter
|
|
|
|
PRInt32 start = GetAccelerationStart();
|
|
|
|
if (start >= 0 && sScrollSeriesCounter >= start) {
|
|
|
|
PRInt32 factor = GetAccelerationFactor();
|
|
|
|
if (factor > 0) {
|
|
|
|
aScrollLines = ComputeAcceleratedWheelDelta(aScrollLines, factor);
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 07:07:18 +00:00
|
|
|
|
2009-09-24 10:58:04 +00:00
|
|
|
// If the computed delta is larger than the page, we should limit
|
|
|
|
// the delta value to the one page size.
|
2011-05-23 14:56:59 +00:00
|
|
|
return !aLimitToMaxOnePageScroll ? aScrollLines :
|
|
|
|
LimitToOnePageScroll(aScrollLines, aIsHorizontal, aScrollQuantity);
|
2009-09-03 07:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
2009-09-24 10:58:04 +00:00
|
|
|
nsMouseWheelTransaction::ComputeAcceleratedWheelDelta(PRInt32 aDelta,
|
|
|
|
PRInt32 aFactor)
|
2009-09-03 07:07:18 +00:00
|
|
|
{
|
|
|
|
if (aDelta == 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-09-24 10:58:04 +00:00
|
|
|
return PRInt32(NS_round(aDelta * sScrollSeriesCounter *
|
|
|
|
(double)aFactor / 10));
|
2009-09-03 07:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsMouseWheelTransaction::GetAccelerationStart()
|
|
|
|
{
|
2011-05-25 06:32:00 +00:00
|
|
|
return Preferences::GetInt("mousewheel.acceleration.start", -1);
|
2009-09-03 07:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsMouseWheelTransaction::GetAccelerationFactor()
|
|
|
|
{
|
2011-05-25 06:32:00 +00:00
|
|
|
return Preferences::GetInt("mousewheel.acceleration.factor", -1);
|
2009-09-03 07:07:18 +00:00
|
|
|
}
|
|
|
|
|
2009-09-24 10:58:04 +00:00
|
|
|
PRInt32
|
|
|
|
nsMouseWheelTransaction::OverrideSystemScrollSpeed(PRInt32 aScrollLines,
|
|
|
|
PRBool aIsHorizontal)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(sTargetFrame, "We don't have mouse scrolling transaction");
|
|
|
|
|
|
|
|
if (aScrollLines == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We shouldn't override the scrolling speed on non root scroll frame.
|
|
|
|
if (sTargetFrame !=
|
|
|
|
sTargetFrame->PresContext()->PresShell()->GetRootScrollFrame()) {
|
|
|
|
return aScrollLines;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 19:11:04 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget(sTargetFrame->GetNearestWidget());
|
2009-09-24 10:58:04 +00:00
|
|
|
NS_ENSURE_TRUE(widget, aScrollLines);
|
|
|
|
PRInt32 overriddenDelta;
|
|
|
|
nsresult rv = widget->OverrideSystemMouseScrollSpeed(aScrollLines,
|
|
|
|
aIsHorizontal,
|
|
|
|
overriddenDelta);
|
|
|
|
NS_ENSURE_SUCCESS(rv, aScrollLines);
|
|
|
|
return overriddenDelta;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsMouseWheelTransaction::LimitToOnePageScroll(PRInt32 aScrollLines,
|
|
|
|
PRBool aIsHorizontal,
|
2010-01-11 21:45:02 +00:00
|
|
|
nsIScrollableFrame::ScrollUnit *aScrollQuantity)
|
2009-09-24 10:58:04 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aScrollQuantity, aScrollLines);
|
2010-01-11 21:45:02 +00:00
|
|
|
NS_PRECONDITION(*aScrollQuantity == nsIScrollableFrame::LINES,
|
2009-09-24 10:58:04 +00:00
|
|
|
"aScrollQuantity isn't by line");
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(sTargetFrame, aScrollLines);
|
2010-01-11 21:45:02 +00:00
|
|
|
nsIScrollableFrame* sf = sTargetFrame->GetScrollTargetFrame();
|
|
|
|
NS_ENSURE_TRUE(sf, aScrollLines);
|
2009-09-24 10:58:04 +00:00
|
|
|
|
|
|
|
// Limit scrolling to be at most one page, but if possible, try to
|
|
|
|
// just adjust the number of scrolled lines.
|
2010-01-11 21:45:02 +00:00
|
|
|
nsSize lineAmount = sf->GetLineScrollAmount();
|
|
|
|
nscoord lineScroll = aIsHorizontal ? lineAmount.width : lineAmount.height;
|
2009-09-24 10:58:04 +00:00
|
|
|
|
2010-01-11 21:45:02 +00:00
|
|
|
if (lineScroll == 0)
|
2009-09-24 10:58:04 +00:00
|
|
|
return aScrollLines;
|
|
|
|
|
2010-01-11 21:45:02 +00:00
|
|
|
nsSize pageAmount = sf->GetPageScrollAmount();
|
|
|
|
nscoord pageScroll = aIsHorizontal ? pageAmount.width : pageAmount.height;
|
2009-09-24 10:58:04 +00:00
|
|
|
|
2011-06-02 12:56:50 +00:00
|
|
|
if (NS_ABS(aScrollLines) * lineScroll < pageScroll)
|
2009-09-24 10:58:04 +00:00
|
|
|
return aScrollLines;
|
|
|
|
|
2010-01-11 21:45:02 +00:00
|
|
|
nscoord maxLines = (pageScroll / lineScroll);
|
2009-09-24 10:58:04 +00:00
|
|
|
if (maxLines >= 1)
|
|
|
|
return ((aScrollLines < 0) ? -1 : 1) * maxLines;
|
|
|
|
|
2010-01-11 21:45:02 +00:00
|
|
|
*aScrollQuantity = nsIScrollableFrame::PAGES;
|
2009-09-24 10:58:04 +00:00
|
|
|
return (aScrollLines < 0) ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
2004-02-03 02:22:01 +00:00
|
|
|
/******************************************************************/
|
|
|
|
/* nsEventStateManager */
|
|
|
|
/******************************************************************/
|
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
nsEventStateManager::nsEventStateManager()
|
2004-04-29 23:34:19 +00:00
|
|
|
: mLockCursor(0),
|
|
|
|
mCurrentTarget(nsnull),
|
|
|
|
mLastMouseOverFrame(nsnull),
|
|
|
|
mLastDragOverFrame(nsnull),
|
|
|
|
// init d&d gesture state machine variables
|
|
|
|
mGestureDownPoint(0,0),
|
|
|
|
mPresContext(nsnull),
|
|
|
|
mLClickCount(0),
|
|
|
|
mMClickCount(0),
|
|
|
|
mRClickCount(0),
|
2002-12-24 20:21:40 +00:00
|
|
|
m_haveShutdown(PR_FALSE),
|
2008-09-17 11:27:19 +00:00
|
|
|
mLastLineScrollConsumedX(PR_FALSE),
|
2010-06-16 07:36:11 +00:00
|
|
|
mLastLineScrollConsumedY(PR_FALSE),
|
|
|
|
mClickHoldContextMenu(PR_FALSE)
|
2004-04-29 23:34:19 +00:00
|
|
|
{
|
2007-10-22 21:42:25 +00:00
|
|
|
if (sESMInstanceCount == 0) {
|
|
|
|
gUserInteractionTimerCallback = new nsUITimerCallback();
|
2010-11-07 19:07:59 +00:00
|
|
|
if (gUserInteractionTimerCallback)
|
2007-10-22 21:42:25 +00:00
|
|
|
NS_ADDREF(gUserInteractionTimerCallback);
|
2010-11-07 19:07:59 +00:00
|
|
|
UpdateUserActivityTimer();
|
2007-10-22 21:42:25 +00:00
|
|
|
}
|
2004-04-13 06:41:35 +00:00
|
|
|
++sESMInstanceCount;
|
2000-03-15 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2010-11-07 19:07:59 +00: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 23:39:27 +00:00
|
|
|
static const char* kObservedPrefs[] = {
|
|
|
|
"accessibility.accesskeycausesactivation",
|
|
|
|
"nglayout.events.dispatchLeftClickOnly",
|
|
|
|
"ui.key.generalAccessKey",
|
|
|
|
"ui.key.chromeAccess",
|
|
|
|
"ui.key.contentAccess",
|
|
|
|
"ui.click_hold_context_menus",
|
|
|
|
#if 0
|
|
|
|
"mousewheel.withaltkey.action",
|
|
|
|
"mousewheel.withaltkey.numlines",
|
|
|
|
"mousewheel.withaltkey.sysnumlines",
|
|
|
|
"mousewheel.withcontrolkey.action",
|
|
|
|
"mousewheel.withcontrolkey.numlines",
|
|
|
|
"mousewheel.withcontrolkey.sysnumlines",
|
|
|
|
"mousewheel.withnokey.action",
|
|
|
|
"mousewheel.withnokey.numlines",
|
|
|
|
"mousewheel.withnokey.sysnumlines",
|
|
|
|
"mousewheel.withshiftkey.action",
|
|
|
|
"mousewheel.withshiftkey.numlines",
|
|
|
|
"mousewheel.withshiftkey.sysnumlines",
|
|
|
|
#endif
|
|
|
|
"dom.popup_allowed_events",
|
|
|
|
nsnull
|
|
|
|
};
|
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
nsresult
|
2000-03-15 04:03:44 +00:00
|
|
|
nsEventStateManager::Init()
|
|
|
|
{
|
2004-07-23 07:27:57 +00:00
|
|
|
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 16:59:13 +00:00
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (!observerService)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-03-15 04:03:44 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
|
2000-09-15 06:17:54 +00:00
|
|
|
|
2011-05-28 23:39:27 +00:00
|
|
|
if (sESMInstanceCount == 1) {
|
|
|
|
sLeftClickOnly =
|
|
|
|
Preferences::GetBool("nglayout.events.dispatchLeftClickOnly",
|
|
|
|
sLeftClickOnly);
|
|
|
|
sChromeAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeChrome);
|
|
|
|
sContentAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeContent);
|
|
|
|
}
|
2011-05-28 23:39:27 +00:00
|
|
|
Preferences::AddWeakObservers(this, kObservedPrefs);
|
2000-09-15 06:17:54 +00:00
|
|
|
|
2010-06-16 07:36:11 +00:00
|
|
|
mClickHoldContextMenu =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("ui.click_hold_context_menus", PR_FALSE);
|
2010-06-16 07:36:11 +00:00
|
|
|
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
return NS_OK;
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 14:54:59 +00:00
|
|
|
nsEventStateManager::~nsEventStateManager()
|
|
|
|
{
|
2010-09-16 13:10:18 +00:00
|
|
|
if (sActiveESM == this) {
|
|
|
|
sActiveESM = nsnull;
|
|
|
|
}
|
2010-06-16 07:36:11 +00:00
|
|
|
if (mClickHoldContextMenu)
|
|
|
|
KillClickHoldTimer();
|
2001-04-26 19:12:31 +00:00
|
|
|
|
2010-09-17 18:56:53 +00:00
|
|
|
if (mDocument == sMouseOverDocument)
|
|
|
|
sMouseOverDocument = nsnull;
|
|
|
|
|
2004-04-13 06:41:35 +00:00
|
|
|
--sESMInstanceCount;
|
|
|
|
if(sESMInstanceCount == 0) {
|
2009-02-12 10:44:38 +00:00
|
|
|
nsMouseWheelTransaction::Shutdown();
|
2007-10-22 21:42:25 +00:00
|
|
|
if (gUserInteractionTimerCallback) {
|
|
|
|
gUserInteractionTimerCallback->Notify(nsnull);
|
|
|
|
NS_RELEASE(gUserInteractionTimerCallback);
|
|
|
|
}
|
|
|
|
if (gUserInteractionTimer) {
|
|
|
|
gUserInteractionTimer->Cancel();
|
|
|
|
NS_RELEASE(gUserInteractionTimer);
|
|
|
|
}
|
1999-12-01 09:09:46 +00:00
|
|
|
}
|
2000-03-15 04:03:44 +00: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.
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
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 16:59:13 +00:00
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
2004-04-13 06:41:35 +00:00
|
|
|
observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
|
|
|
}
|
2000-03-15 04:03:44 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
2000-03-15 04:03:44 +00:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::Shutdown()
|
|
|
|
{
|
2011-05-28 23:39:27 +00:00
|
|
|
Preferences::RemoveObservers(this, kObservedPrefs);
|
2000-03-15 04:03:44 +00:00
|
|
|
m_haveShutdown = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-07-23 07:27:57 +00:00
|
|
|
nsEventStateManager::Observe(nsISupports *aSubject,
|
2001-10-19 20:52:59 +00:00
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *someData)
|
|
|
|
{
|
|
|
|
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
|
2000-03-15 04:03:44 +00:00
|
|
|
Shutdown();
|
2003-04-12 03:03:27 +00:00
|
|
|
else if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
2004-04-13 06:41:35 +00:00
|
|
|
if (!someData)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsDependentString data(someData);
|
2004-05-22 22:15:22 +00:00
|
|
|
if (data.EqualsLiteral("accessibility.accesskeycausesactivation")) {
|
2004-04-29 23:34:19 +00:00
|
|
|
sKeyCausesActivation =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("accessibility.accesskeycausesactivation",
|
|
|
|
sKeyCausesActivation);
|
2004-05-22 22:15:22 +00:00
|
|
|
} else if (data.EqualsLiteral("nglayout.events.dispatchLeftClickOnly")) {
|
2004-04-29 23:34:19 +00:00
|
|
|
sLeftClickOnly =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("nglayout.events.dispatchLeftClickOnly",
|
|
|
|
sLeftClickOnly);
|
2004-05-22 22:15:22 +00:00
|
|
|
} else if (data.EqualsLiteral("ui.key.generalAccessKey")) {
|
2006-07-13 10:18:12 +00:00
|
|
|
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 07:36:11 +00:00
|
|
|
} else if (data.EqualsLiteral("ui.click_hold_context_menus")) {
|
|
|
|
mClickHoldContextMenu =
|
2011-05-25 06:31:59 +00:00
|
|
|
Preferences::GetBool("ui.click_hold_context_menus", PR_FALSE);
|
2004-04-13 06:41:35 +00:00
|
|
|
#if 0
|
2004-05-22 22:15:22 +00:00
|
|
|
} else if (data.EqualsLiteral("mousewheel.withaltkey.action")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withaltkey.numlines")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withaltkey.sysnumlines")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withcontrolkey.action")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withcontrolkey.numlines")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withcontrolkey.sysnumlines")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withshiftkey.action")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withshiftkey.numlines")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withshiftkey.sysnumlines")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withnokey.action")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withnokey.numlines")) {
|
|
|
|
} else if (data.EqualsLiteral("mousewheel.withnokey.sysnumlines")) {
|
2004-04-13 06:41:35 +00:00
|
|
|
#endif
|
2004-09-04 19:28:46 +00:00
|
|
|
} else if (data.EqualsLiteral("dom.popup_allowed_events")) {
|
|
|
|
nsDOMEvent::PopupAllowedEventsChanged();
|
2003-04-12 03:03:27 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2000-03-15 04:03:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsEventStateManager)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsEventStateManager)
|
2011-04-21 17:35:52 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 11:11:31 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsEventStateManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsEventStateManager)
|
2007-08-10 21:25:24 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEventStateManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentTargetContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastMouseOverElement);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGestureDownContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGestureDownFrameOwner);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastLeftMouseDownContent);
|
2010-01-25 09:21:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastLeftMouseDownContentParent);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastMiddleMouseDownContent);
|
2010-01-25 09:21:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastMiddleMouseDownContentParent);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastRightMouseDownContent);
|
2010-01-25 09:21:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastRightMouseDownContentParent);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mActiveContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mHoverContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDragOverContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mURLTargetContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstMouseOverEventElement);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFirstMouseOutEventElement);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument);
|
2007-11-28 20:14:12 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mAccessKeys);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsEventStateManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCurrentTargetContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastMouseOverElement);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGestureDownContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGestureDownFrameOwner);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastLeftMouseDownContent);
|
2010-01-25 09:21:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastLeftMouseDownContentParent);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastMiddleMouseDownContent);
|
2010-01-25 09:21:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastMiddleMouseDownContentParent);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastRightMouseDownContent);
|
2010-01-25 09:21:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLastRightMouseDownContentParent);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mActiveContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mHoverContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDragOverContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mURLTargetContent);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstMouseOverEventElement);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFirstMouseOutEventElement);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument);
|
2007-11-28 20:14:12 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mAccessKeys);
|
2007-08-10 21:25:24 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2000-03-15 04:03:44 +00:00
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext,
|
2002-02-21 13:39:39 +00:00
|
|
|
nsEvent *aEvent,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsEventStatus* aStatus,
|
|
|
|
nsIView* aView)
|
1998-06-23 21:53:02 +00:00
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aStatus);
|
|
|
|
NS_ENSURE_ARG(aPresContext);
|
2006-05-11 13:26:08 +00:00
|
|
|
if (!aEvent) {
|
|
|
|
NS_ERROR("aEvent is null. This should never happen.");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-09-30 11:40:42 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
mCurrentTarget = aTargetFrame;
|
2002-12-17 02:10:57 +00:00
|
|
|
mCurrentTargetContent = nsnull;
|
1998-11-19 00:43:36 +00:00
|
|
|
|
2003-05-12 07:11:16 +00: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;
|
|
|
|
}
|
1999-09-02 07:22:47 +00:00
|
|
|
|
2007-10-22 21:42:25 +00: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.
|
|
|
|
if (NS_IS_TRUSTED_EVENT(aEvent) &&
|
|
|
|
((aEvent->eventStructType == NS_MOUSE_EVENT &&
|
2010-03-24 03:36:27 +00:00
|
|
|
IsMouseEventReal(aEvent) &&
|
2007-10-22 21:42:25 +00:00
|
|
|
aEvent->message != NS_MOUSE_ENTER &&
|
|
|
|
aEvent->message != NS_MOUSE_EXIT) ||
|
|
|
|
aEvent->eventStructType == NS_MOUSE_SCROLL_EVENT ||
|
|
|
|
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 16:59:13 +00:00
|
|
|
mozilla::services::GetObserverService();
|
2007-10-22 21:42:25 +00:00
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(nsnull, "user-interaction-active", nsnull);
|
2010-11-07 19:07:59 +00:00
|
|
|
UpdateUserActivityTimer();
|
2007-10-22 21:42:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
++gMouseOrKeyboardEventCounter;
|
|
|
|
}
|
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
*aStatus = nsEventStatus_eIgnore;
|
2001-01-20 04:59:39 +00:00
|
|
|
|
2006-07-12 04:15:42 +00:00
|
|
|
nsMouseWheelTransaction::OnEvent(aEvent);
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
switch (aEvent->message) {
|
2006-11-16 21:35:39 +00:00
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
2007-07-08 07:08:04 +00:00
|
|
|
switch (static_cast<nsMouseEvent*>(aEvent)->button) {
|
2006-11-16 21:35:39 +00:00
|
|
|
case nsMouseEvent::eLeftButton:
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifndef XP_OS2
|
2010-06-16 07:36:11 +00:00
|
|
|
BeginTrackingDragGesture(aPresContext, (nsMouseEvent*)aEvent, aTargetFrame);
|
2002-05-10 03:07:06 +00:00
|
|
|
#endif
|
2006-11-16 21:35:39 +00:00
|
|
|
mLClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
2010-09-08 17:41:37 +00:00
|
|
|
sNormalLMouseEventInProcess = PR_TRUE;
|
2006-11-16 21:35:39 +00:00
|
|
|
break;
|
|
|
|
case nsMouseEvent::eMiddleButton:
|
|
|
|
mMClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
|
|
|
case nsMouseEvent::eRightButton:
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifdef XP_OS2
|
2010-06-16 07:36:11 +00:00
|
|
|
BeginTrackingDragGesture(aPresContext, (nsMouseEvent*)aEvent, aTargetFrame);
|
2002-05-10 03:07:06 +00:00
|
|
|
#endif
|
2006-11-16 21:35:39 +00:00
|
|
|
mRClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
|
|
|
}
|
1999-08-19 19:48:45 +00:00
|
|
|
break;
|
2006-11-16 21:35:39 +00:00
|
|
|
case NS_MOUSE_BUTTON_UP:
|
2007-07-08 07:08:04 +00:00
|
|
|
switch (static_cast<nsMouseEvent*>(aEvent)->button) {
|
2006-11-16 21:35:39 +00:00
|
|
|
case nsMouseEvent::eLeftButton:
|
2010-06-16 07:36:11 +00:00
|
|
|
if (mClickHoldContextMenu) {
|
|
|
|
KillClickHoldTimer();
|
|
|
|
}
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifndef XP_OS2
|
2010-06-16 07:36:11 +00:00
|
|
|
StopTrackingDragGesture();
|
2002-05-10 03:07:06 +00:00
|
|
|
#endif
|
2010-09-08 17:41:37 +00:00
|
|
|
sNormalLMouseEventInProcess = PR_FALSE;
|
2010-12-20 00:46:00 +00:00
|
|
|
// then fall through...
|
2010-06-16 07:36:11 +00:00
|
|
|
case nsMouseEvent::eRightButton:
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifdef XP_OS2
|
2010-06-16 07:36:11 +00:00
|
|
|
StopTrackingDragGesture();
|
2002-05-10 03:07:06 +00:00
|
|
|
#endif
|
2010-12-20 00:46:00 +00:00
|
|
|
// then fall through...
|
2010-06-16 07:36:11 +00:00
|
|
|
case nsMouseEvent::eMiddleButton:
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
2006-11-16 21:35:39 +00:00
|
|
|
}
|
1999-08-19 19:48:45 +00:00
|
|
|
break;
|
2005-02-23 21:46:43 +00:00
|
|
|
case NS_MOUSE_EXIT:
|
2008-03-12 22:44:45 +00: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
|
2005-07-17 21:50:56 +00:00
|
|
|
// we're still in our toplevel window.
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsMouseEvent* mouseEvent = static_cast<nsMouseEvent*>(aEvent);
|
2008-03-12 22:44:45 +00:00
|
|
|
if (mouseEvent->exit != nsMouseEvent::eTopLevel) {
|
2008-04-23 22:51:27 +00: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;
|
2005-07-17 21:50:56 +00:00
|
|
|
// then fall through...
|
|
|
|
} else {
|
|
|
|
GenerateMouseEnterExit((nsGUIEvent*)aEvent);
|
|
|
|
//This is a window level mouse exit event and should stop here
|
|
|
|
aEvent->message = 0;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-23 21:46:43 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_MOUSE_MOVE:
|
2004-06-22 04:32:52 +00:00
|
|
|
// 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|
|
2000-02-24 03:41:14 +00:00
|
|
|
// into UpdateCursor().
|
2005-04-19 23:03:23 +00:00
|
|
|
GenerateDragGesture(aPresContext, (nsMouseEvent*)aEvent);
|
2000-02-24 03:41:14 +00:00
|
|
|
UpdateCursor(aPresContext, aEvent, mCurrentTarget, aStatus);
|
2005-03-28 23:39:13 +00:00
|
|
|
GenerateMouseEnterExit((nsGUIEvent*)aEvent);
|
1998-11-18 05:25:26 +00:00
|
|
|
break;
|
2001-12-06 15:29:01 +00:00
|
|
|
case NS_DRAGDROP_GESTURE:
|
2010-06-16 07:36:11 +00: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();
|
|
|
|
}
|
2001-12-06 15:29:01 +00:00
|
|
|
break;
|
1999-06-22 14:20:14 +00:00
|
|
|
case NS_DRAGDROP_OVER:
|
2008-08-27 12:07:27 +00:00
|
|
|
// NS_DRAGDROP_DROP is fired before NS_DRAGDROP_DRAGDROP so send
|
|
|
|
// the enter/exit events before NS_DRAGDROP_DROP.
|
2000-04-24 04:41:27 +00:00
|
|
|
GenerateDragDropEnterExit(aPresContext, (nsGUIEvent*)aEvent);
|
1999-06-22 14:20:14 +00:00
|
|
|
break;
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-07-27 14:38:07 +00:00
|
|
|
case NS_KEY_PRESS:
|
2000-05-16 10:22:20 +00:00
|
|
|
{
|
2000-06-02 14:20:50 +00:00
|
|
|
|
2000-05-16 10:22:20 +00:00
|
|
|
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
2002-05-08 20:43:49 +00:00
|
|
|
|
2006-07-13 10:18:12 +00:00
|
|
|
PRInt32 modifierMask = 0;
|
|
|
|
if (keyEvent->isShift)
|
|
|
|
modifierMask |= NS_MODIFIER_SHIFT;
|
|
|
|
if (keyEvent->isControl)
|
|
|
|
modifierMask |= NS_MODIFIER_CONTROL;
|
|
|
|
if (keyEvent->isAlt)
|
|
|
|
modifierMask |= NS_MODIFIER_ALT;
|
|
|
|
if (keyEvent->isMeta)
|
|
|
|
modifierMask |= NS_MODIFIER_META;
|
|
|
|
|
|
|
|
// Prevent keyboard scrolling while an accesskey modifier is in use.
|
|
|
|
if (modifierMask && (modifierMask == sChromeAccessModifier ||
|
|
|
|
modifierMask == sContentAccessModifier))
|
2007-05-18 03:49:14 +00:00
|
|
|
HandleAccessKey(aPresContext, keyEvent, aStatus, nsnull,
|
2006-07-13 10:18:12 +00:00
|
|
|
eAccessKeyProcessingNormal, modifierMask);
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
2010-12-20 00:46:00 +00:00
|
|
|
// then fall through...
|
2002-09-03 05:48:06 +00:00
|
|
|
case NS_KEY_DOWN:
|
|
|
|
case NS_KEY_UP:
|
2007-02-20 14:57:52 +00: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 18:00:39 +00:00
|
|
|
nsIContent* content = GetFocusedContent();
|
|
|
|
if (content)
|
|
|
|
mCurrentTargetContent = content;
|
2007-02-20 14:57:52 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-09-03 05:48:06 +00:00
|
|
|
case NS_MOUSE_SCROLL:
|
|
|
|
{
|
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 18:00:39 +00:00
|
|
|
nsIContent* content = GetFocusedContent();
|
|
|
|
if (content)
|
|
|
|
mCurrentTargetContent = content;
|
2007-02-20 14:57:52 +00:00
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
nsMouseScrollEvent* msEvent = static_cast<nsMouseScrollEvent*>(aEvent);
|
2007-02-20 14:57:52 +00:00
|
|
|
|
2011-05-22 05:39:16 +00:00
|
|
|
PRBool useSysNumLines = UseSystemScrollSettingFor(msEvent);
|
|
|
|
PRInt32 action = GetWheelActionFor(msEvent);
|
2007-02-20 14:57:52 +00:00
|
|
|
|
|
|
|
if (!useSysNumLines) {
|
|
|
|
// If the scroll event's delta isn't to our liking, we can
|
|
|
|
// override it with the "numlines" parameter. There are two
|
|
|
|
// things we can do:
|
|
|
|
//
|
|
|
|
// (1) Pick a different number. Instead of scrolling 3
|
|
|
|
// lines ("delta" in Gtk2), we would scroll 1 line.
|
|
|
|
// (2) Swap directions. Instead of scrolling down, scroll up.
|
|
|
|
//
|
|
|
|
// For the first item, the magnitude of the parameter is
|
|
|
|
// used instead of the magnitude of the delta. For the
|
|
|
|
// second item, if the parameter is negative we swap
|
|
|
|
// directions.
|
|
|
|
|
2011-05-22 05:39:16 +00:00
|
|
|
PRInt32 numLines = GetScrollLinesFor(msEvent);
|
2007-02-20 14:57:52 +00:00
|
|
|
|
|
|
|
PRBool swapDirs = (numLines < 0);
|
|
|
|
PRInt32 userSize = swapDirs ? -numLines : numLines;
|
|
|
|
|
|
|
|
PRBool deltaUp = (msEvent->delta < 0);
|
|
|
|
if (swapDirs) {
|
|
|
|
deltaUp = !deltaUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
msEvent->delta = deltaUp ? -userSize : userSize;
|
|
|
|
}
|
|
|
|
if ((useSysNumLines &&
|
|
|
|
(msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)) ||
|
|
|
|
action == MOUSE_SCROLL_PAGE) {
|
|
|
|
msEvent->delta = (msEvent->delta > 0)
|
2008-11-02 15:00:05 +00:00
|
|
|
? PRInt32(nsIDOMNSUIEvent::SCROLL_PAGE_DOWN)
|
|
|
|
: PRInt32(nsIDOMNSUIEvent::SCROLL_PAGE_UP);
|
2007-02-20 14:57:52 +00:00
|
|
|
}
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-09-17 11:27:19 +00:00
|
|
|
case NS_MOUSE_PIXEL_SCROLL:
|
|
|
|
{
|
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 18:00:39 +00:00
|
|
|
nsIContent* content = GetFocusedContent();
|
|
|
|
if (content)
|
|
|
|
mCurrentTargetContent = content;
|
2008-09-17 11:27:19 +00:00
|
|
|
|
|
|
|
nsMouseScrollEvent *msEvent = static_cast<nsMouseScrollEvent*>(aEvent);
|
2009-04-02 19:34:31 +00:00
|
|
|
|
|
|
|
// Clear old deltas after a period of non action
|
|
|
|
if (OutOfTime(gPixelScrollDeltaTimeout, nsMouseWheelTransaction::GetTimeoutTime())) {
|
|
|
|
gPixelScrollDeltaX = gPixelScrollDeltaY = 0;
|
|
|
|
}
|
|
|
|
gPixelScrollDeltaTimeout = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
|
|
|
|
// If needed send a line scroll event for pixel scrolls with kNoLines
|
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kNoLines) {
|
|
|
|
nscoord pixelHeight = aPresContext->AppUnitsToIntCSSPixels(
|
2010-01-11 21:45:04 +00:00
|
|
|
GetScrollableLineHeight(aTargetFrame));
|
2009-04-02 19:34:31 +00:00
|
|
|
|
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsVertical) {
|
|
|
|
gPixelScrollDeltaX += msEvent->delta;
|
|
|
|
if (!gPixelScrollDeltaX || !pixelHeight)
|
|
|
|
break;
|
|
|
|
|
2011-06-02 12:56:50 +00:00
|
|
|
if (NS_ABS(gPixelScrollDeltaX) >= pixelHeight) {
|
2009-04-02 19:34:31 +00:00
|
|
|
PRInt32 numLines = (PRInt32)ceil((float)gPixelScrollDeltaX/(float)pixelHeight);
|
|
|
|
|
|
|
|
gPixelScrollDeltaX -= numLines*pixelHeight;
|
|
|
|
|
|
|
|
nsWeakFrame weakFrame(aTargetFrame);
|
|
|
|
SendLineScrollEvent(aTargetFrame, msEvent, aPresContext,
|
|
|
|
aStatus, numLines);
|
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
|
|
|
}
|
|
|
|
} else if (msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) {
|
|
|
|
gPixelScrollDeltaY += msEvent->delta;
|
|
|
|
if (!gPixelScrollDeltaY || !pixelHeight)
|
|
|
|
break;
|
|
|
|
|
2011-06-02 12:56:50 +00:00
|
|
|
if (NS_ABS(gPixelScrollDeltaY) >= pixelHeight) {
|
2009-04-02 19:34:31 +00:00
|
|
|
PRInt32 numLines = (PRInt32)ceil((float)gPixelScrollDeltaY/(float)pixelHeight);
|
|
|
|
|
|
|
|
gPixelScrollDeltaY -= numLines*pixelHeight;
|
|
|
|
|
|
|
|
nsWeakFrame weakFrame(aTargetFrame);
|
|
|
|
SendLineScrollEvent(aTargetFrame, msEvent, aPresContext,
|
|
|
|
aStatus, numLines);
|
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the last line scroll has been canceled, eat the pixel scroll event
|
2008-09-17 11:27:19 +00:00
|
|
|
if ((msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) ?
|
|
|
|
mLastLineScrollConsumedX : mLastLineScrollConsumedY) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-02-20 07:40:04 +00:00
|
|
|
case NS_QUERY_SELECTED_TEXT:
|
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
if (RemoteQueryContentEvent(aEvent))
|
|
|
|
break;
|
2009-02-10 20:56:51 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
2008-02-20 07:40:04 +00:00
|
|
|
handler.OnQuerySelectedText((nsQueryContentEvent*)aEvent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_QUERY_TEXT_CONTENT:
|
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
if (RemoteQueryContentEvent(aEvent))
|
|
|
|
break;
|
2009-02-10 20:56:51 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
2008-02-20 07:40:04 +00:00
|
|
|
handler.OnQueryTextContent((nsQueryContentEvent*)aEvent);
|
|
|
|
}
|
|
|
|
break;
|
2009-02-10 20:56:51 +00:00
|
|
|
case NS_QUERY_CARET_RECT:
|
2009-02-10 11:15:36 +00:00
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
// XXX remote event
|
2009-02-10 20:56:51 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryCaretRect((nsQueryContentEvent*)aEvent);
|
2009-02-10 11:15:36 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-02-10 20:56:51 +00:00
|
|
|
case NS_QUERY_TEXT_RECT:
|
2009-02-10 11:15:36 +00:00
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
// XXX remote event
|
2009-02-10 20:56:51 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryTextRect((nsQueryContentEvent*)aEvent);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_QUERY_EDITOR_RECT:
|
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
// XXX remote event
|
2009-02-10 20:56:51 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryEditorRect((nsQueryContentEvent*)aEvent);
|
|
|
|
}
|
|
|
|
break;
|
2009-03-18 02:04:01 +00:00
|
|
|
case NS_QUERY_CONTENT_STATE:
|
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
// XXX remote event
|
2009-03-18 02:04:01 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryContentState(static_cast<nsQueryContentEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_QUERY_SELECTION_AS_TRANSFERABLE:
|
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
// XXX remote event
|
2009-03-18 02:04:01 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQuerySelectionAsTransferable(static_cast<nsQueryContentEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2009-05-15 00:46:24 +00:00
|
|
|
case NS_QUERY_CHARACTER_AT_POINT:
|
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
// XXX remote event
|
2009-05-15 00:46:24 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryCharacterAtPoint(static_cast<nsQueryContentEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2011-03-01 21:15:23 +00:00
|
|
|
case NS_QUERY_DOM_WIDGET_HITTEST:
|
|
|
|
{
|
|
|
|
// XXX remote event
|
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnQueryDOMWidgetHittest(static_cast<nsQueryContentEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2011-05-17 00:23:23 +00:00
|
|
|
case NS_QUERY_SCROLL_TARGET_INFO:
|
|
|
|
{
|
|
|
|
DoQueryScrollTargetInfo(static_cast<nsQueryContentEvent*>(aEvent),
|
|
|
|
aTargetFrame);
|
|
|
|
break;
|
|
|
|
}
|
2009-02-10 20:56:51 +00:00
|
|
|
case NS_SELECTION_SET:
|
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
nsSelectionEvent *selectionEvent =
|
|
|
|
static_cast<nsSelectionEvent*>(aEvent);
|
|
|
|
if (IsTargetCrossProcess(selectionEvent)) {
|
|
|
|
// Will not be handled locally, remote the event
|
|
|
|
if (GetCrossProcessTarget()->SendSelectionEvent(*selectionEvent))
|
|
|
|
selectionEvent->mSucceeded = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-10 20:56:51 +00:00
|
|
|
nsContentEventHandler handler(mPresContext);
|
|
|
|
handler.OnSelectionEvent((nsSelectionEvent*)aEvent);
|
2008-02-20 07:40:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-08-07 15:11:17 +00: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-11 01:45:45 +00:00
|
|
|
case NS_CONTENT_COMMAND_PASTE_TRANSFERABLE:
|
2009-08-07 15:11:17 +00:00
|
|
|
{
|
|
|
|
DoContentCommandEvent(static_cast<nsContentCommandEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2010-03-11 05:25:29 +00:00
|
|
|
case NS_CONTENT_COMMAND_SCROLL:
|
|
|
|
{
|
|
|
|
DoContentCommandScrollEvent(static_cast<nsContentCommandEvent*>(aEvent));
|
|
|
|
}
|
|
|
|
break;
|
2010-08-17 08:07:44 +00:00
|
|
|
case NS_TEXT_TEXT:
|
|
|
|
{
|
|
|
|
nsTextEvent *textEvent = static_cast<nsTextEvent*>(aEvent);
|
|
|
|
if (IsTargetCrossProcess(textEvent)) {
|
|
|
|
// Will not be handled locally, remote the event
|
2010-09-24 03:28:15 +00:00
|
|
|
if (GetCrossProcessTarget()->SendTextEvent(*textEvent)) {
|
2010-08-17 08:07:44 +00:00
|
|
|
// Cancel local dispatching
|
2010-09-24 03:28:15 +00:00
|
|
|
aEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
|
2010-08-17 08:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_COMPOSITION_START:
|
|
|
|
case NS_COMPOSITION_END:
|
|
|
|
{
|
|
|
|
nsCompositionEvent *compositionEvent =
|
|
|
|
static_cast<nsCompositionEvent*>(aEvent);
|
|
|
|
if (IsTargetCrossProcess(compositionEvent)) {
|
|
|
|
// Will not be handled locally, remote the event
|
2010-09-24 03:28:15 +00:00
|
|
|
if (GetCrossProcessTarget()->SendCompositionEvent(*compositionEvent)) {
|
2010-08-17 08:07:44 +00:00
|
|
|
// Cancel local dispatching
|
2010-09-24 03:28:15 +00:00
|
|
|
aEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
|
2010-08-17 08:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-16 10:22:20 +00:00
|
|
|
|
2006-07-13 10:18:12 +00:00
|
|
|
static PRInt32
|
|
|
|
GetAccessModifierMask(nsISupports* aDocShell)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(aDocShell));
|
|
|
|
if (!treeItem)
|
|
|
|
return -1; // invalid modifier
|
|
|
|
|
|
|
|
PRInt32 itemType;
|
|
|
|
treeItem->GetItemType(&itemType);
|
|
|
|
switch (itemType) {
|
|
|
|
|
|
|
|
case nsIDocShellTreeItem::typeChrome:
|
|
|
|
return sChromeAccessModifier;
|
|
|
|
|
|
|
|
case nsIDocShellTreeItem::typeContent:
|
|
|
|
return sContentAccessModifier;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1; // invalid modifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:14:12 +00:00
|
|
|
static PRBool
|
2008-04-15 04:16:24 +00:00
|
|
|
IsAccessKeyTarget(nsIContent* aContent, nsIFrame* aFrame, nsAString& aKey)
|
2007-11-28 20:14:12 +00:00
|
|
|
{
|
2008-12-30 14:09:14 +00:00
|
|
|
if (!aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::accesskey, aKey,
|
|
|
|
eIgnoreCase))
|
2007-11-28 20:14:12 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-12-30 14:09:14 +00:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc =
|
|
|
|
do_QueryInterface(aContent->GetOwnerDoc());
|
2009-08-24 20:02:07 +00:00
|
|
|
if (!xulDoc && !aContent->IsXUL())
|
2008-12-30 14:09:14 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
// For XUL we do visibility checks.
|
|
|
|
if (!aFrame)
|
2007-11-28 20:14:12 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aFrame->IsFocusable())
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
if (!aFrame->GetStyleVisibility()->IsVisible())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (!aFrame->AreAncestorViewsVisible())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-12-30 14:09:14 +00:00
|
|
|
// XUL controls can be activated.
|
2007-11-28 20:14:12 +00:00
|
|
|
nsCOMPtr<nsIDOMXULControlElement> control(do_QueryInterface(aContent));
|
|
|
|
if (control)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2009-08-24 20:02:07 +00:00
|
|
|
if (aContent->IsHTML()) {
|
2008-05-08 20:00:24 +00: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)
|
|
|
|
return PR_TRUE;
|
2009-07-10 12:17:15 +00:00
|
|
|
|
2009-08-24 20:02:07 +00:00
|
|
|
} else if (aContent->IsXUL()) {
|
2009-07-10 12:17:15 +00:00
|
|
|
// XUL label elements are never focusable, so we need to check for them
|
|
|
|
// explicitly before giving up.
|
|
|
|
if (aContent->Tag() == nsGkAtoms::label)
|
|
|
|
return PR_TRUE;
|
2008-05-08 20:00:24 +00:00
|
|
|
}
|
|
|
|
|
2007-11-28 20:14:12 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-04-15 04:16:24 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::ExecuteAccessKey(nsTArray<PRUint32>& aAccessCharCodes,
|
|
|
|
PRBool aIsTrustedEvent)
|
2002-09-03 05:48:06 +00:00
|
|
|
{
|
2008-04-15 04:16:24 +00:00
|
|
|
PRInt32 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 18:00:39 +00:00
|
|
|
nsIContent* focusedContent = GetFocusedContent();
|
|
|
|
if (focusedContent) {
|
|
|
|
start = mAccessKeys.IndexOf(focusedContent);
|
|
|
|
if (start == -1 && focusedContent->GetBindingParent())
|
|
|
|
start = mAccessKeys.IndexOf(focusedContent->GetBindingParent());
|
2008-04-15 04:16:24 +00:00
|
|
|
}
|
|
|
|
nsIContent *content;
|
|
|
|
nsIFrame *frame;
|
2007-11-28 20:14:12 +00:00
|
|
|
PRInt32 length = mAccessKeys.Count();
|
2008-04-15 04:16:24 +00:00
|
|
|
for (PRUint32 i = 0; i < aAccessCharCodes.Length(); ++i) {
|
|
|
|
PRUint32 ch = aAccessCharCodes[i];
|
|
|
|
nsAutoString accessKey;
|
|
|
|
AppendUCS4ToUTF16(ch, accessKey);
|
2007-11-28 20:14:12 +00:00
|
|
|
for (count = 1; count <= length; ++count) {
|
|
|
|
content = mAccessKeys[(start + count) % length];
|
2009-12-24 21:20:05 +00:00
|
|
|
frame = content->GetPrimaryFrame();
|
2008-04-15 04:16:24 +00:00
|
|
|
if (IsAccessKeyTarget(content, frame, accessKey)) {
|
2007-11-28 20:14:12 +00:00
|
|
|
PRBool shouldActivate = sKeyCausesActivation;
|
|
|
|
while (shouldActivate && ++count <= length) {
|
|
|
|
nsIContent *oc = mAccessKeys[(start + count) % length];
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame *of = oc->GetPrimaryFrame();
|
2008-04-15 04:16:24 +00:00
|
|
|
if (IsAccessKeyTarget(oc, of, accessKey))
|
2007-11-28 20:14:12 +00:00
|
|
|
shouldActivate = PR_FALSE;
|
|
|
|
}
|
|
|
|
if (shouldActivate)
|
2008-04-15 04:16:24 +00: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 18:00:39 +00:00
|
|
|
else {
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(content);
|
|
|
|
fm->SetFocus(element, nsIFocusManager::FLAG_BYKEY);
|
|
|
|
}
|
|
|
|
}
|
2008-04-15 04:16:24 +00:00
|
|
|
return PR_TRUE;
|
2007-11-28 20:14:12 +00:00
|
|
|
}
|
2000-05-16 10:22:20 +00:00
|
|
|
}
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
2008-04-15 04:16:24 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::HandleAccessKey(nsPresContext* aPresContext,
|
|
|
|
nsKeyEvent *aEvent,
|
|
|
|
nsEventStatus* aStatus,
|
|
|
|
nsIDocShellTreeItem* aBubbledFrom,
|
|
|
|
ProcessingAccessKeyState aAccessKeyState,
|
|
|
|
PRInt32 aModifierMask)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
PRBool isTrusted = NS_IS_TRUSTED_EVENT(aEvent);
|
|
|
|
nsAutoTArray<PRUint32, 10> accessCharCodes;
|
|
|
|
nsContentUtils::GetAccessKeyCandidates(aEvent, accessCharCodes);
|
|
|
|
if (ExecuteAccessKey(accessCharCodes, isTrusted)) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-02-13 15:02:57 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
// after the local accesskey handling
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
// checking all sub docshells
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShell(do_QueryInterface(pcContainer));
|
2006-06-29 19:57:01 +00:00
|
|
|
if (!docShell) {
|
|
|
|
NS_WARNING("no docShellTreeNode for presContext");
|
|
|
|
return;
|
|
|
|
}
|
2002-09-03 05:48:06 +00:00
|
|
|
|
|
|
|
PRInt32 childCount;
|
|
|
|
docShell->GetChildCount(&childCount);
|
|
|
|
for (PRInt32 counter = 0; counter < childCount; counter++) {
|
|
|
|
// Not processing the child which bubbles up the handling
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> subShellItem;
|
|
|
|
docShell->GetChildAt(counter, getter_AddRefs(subShellItem));
|
2007-05-18 03:49:14 +00:00
|
|
|
if (aAccessKeyState == eAccessKeyProcessingUp &&
|
|
|
|
subShellItem == aBubbledFrom)
|
|
|
|
continue;
|
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
nsCOMPtr<nsIDocShell> subDS = do_QueryInterface(subShellItem);
|
|
|
|
if (subDS && IsShellVisible(subDS)) {
|
2007-05-18 03:49:14 +00:00
|
|
|
nsCOMPtr<nsIPresShell> subPS;
|
2002-09-03 05:48:06 +00:00
|
|
|
subDS->GetPresShell(getter_AddRefs(subPS));
|
|
|
|
|
2002-09-07 02:02:24 +00: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;
|
|
|
|
}
|
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *subPC = subPS->GetPresContext();
|
2002-09-03 05:48:06 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
nsEventStateManager* esm =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsEventStateManager *>(subPC->EventStateManager());
|
2002-09-03 05:48:06 +00:00
|
|
|
|
|
|
|
if (esm)
|
2007-05-18 03:49:14 +00:00
|
|
|
esm->HandleAccessKey(subPC, aEvent, aStatus, nsnull,
|
2006-07-13 10:18:12 +00:00
|
|
|
eAccessKeyProcessingDown, aModifierMask);
|
2002-09-03 05:48:06 +00:00
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aStatus)
|
|
|
|
break;
|
1999-07-27 20:55:03 +00:00
|
|
|
}
|
1999-07-27 14:38:07 +00:00
|
|
|
}
|
2002-09-03 05:48:06 +00:00
|
|
|
}// if end . checking all sub docshell ends here.
|
|
|
|
|
2007-05-18 03:49:14 +00:00
|
|
|
// bubble up the process to the parent docshell if necessary
|
2002-09-03 05:48:06 +00:00
|
|
|
if (eAccessKeyProcessingDown != aAccessKeyState && nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(pcContainer));
|
2006-06-29 19:57:01 +00:00
|
|
|
if (!docShell) {
|
2007-05-18 03:49:14 +00:00
|
|
|
NS_WARNING("no docShellTreeItem for presContext");
|
2006-06-29 19:57:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentShellItem;
|
|
|
|
docShell->GetParent(getter_AddRefs(parentShellItem));
|
|
|
|
nsCOMPtr<nsIDocShell> parentDS = do_QueryInterface(parentShellItem);
|
|
|
|
if (parentDS) {
|
|
|
|
nsCOMPtr<nsIPresShell> parentPS;
|
|
|
|
|
|
|
|
parentDS->GetPresShell(getter_AddRefs(parentPS));
|
2002-09-07 02:02:24 +00:00
|
|
|
NS_ASSERTION(parentPS, "Our PresShell exists but the parent's does not?");
|
2002-09-03 05:48:06 +00:00
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *parentPC = parentPS->GetPresContext();
|
2002-09-07 02:02:24 +00:00
|
|
|
NS_ASSERTION(parentPC, "PresShell without PresContext");
|
2002-09-03 05:48:06 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
nsEventStateManager* esm =
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsEventStateManager *>(parentPC->EventStateManager());
|
2002-09-03 05:48:06 +00:00
|
|
|
|
|
|
|
if (esm)
|
2007-05-18 03:49:14 +00:00
|
|
|
esm->HandleAccessKey(parentPC, aEvent, aStatus, docShell,
|
2006-07-13 10:18:12 +00:00
|
|
|
eAccessKeyProcessingUp, aModifierMask);
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
|
|
|
}// if end. bubble up process
|
|
|
|
}// end of HandleAccessKey
|
1998-06-23 21:53:02 +00:00
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
|
2001-03-30 04:45:40 +00: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
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::CreateClickHoldTimer(nsPresContext* inPresContext,
|
2005-03-30 02:14:41 +00:00
|
|
|
nsIFrame* inDownFrame,
|
2003-11-19 01:20:56 +00:00
|
|
|
nsGUIEvent* inMouseDownEvent)
|
2001-03-30 04:45:40 +00:00
|
|
|
{
|
2005-04-28 23:48:28 +00:00
|
|
|
if (!NS_IS_TRUSTED_EVENT(inMouseDownEvent))
|
2004-10-23 22:28:25 +00:00
|
|
|
return;
|
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
// just to be anal (er, safe)
|
2003-11-19 01:20:56 +00:00
|
|
|
if (mClickHoldTimer) {
|
2001-03-30 04:45:40 +00:00
|
|
|
mClickHoldTimer->Cancel();
|
|
|
|
mClickHoldTimer = nsnull;
|
|
|
|
}
|
2003-11-19 01:20:56 +00:00
|
|
|
|
2001-04-26 19:12:31 +00:00
|
|
|
// if content clicked on has a popup, don't even start the timer
|
|
|
|
// since we'll end up conflicting and both will show.
|
2005-03-30 02:14:41 +00:00
|
|
|
if (mGestureDownContent) {
|
|
|
|
// check for the |popup| attribute
|
2006-01-18 04:09:33 +00:00
|
|
|
if (nsContentUtils::HasNonEmptyAttr(mGestureDownContent, kNameSpaceID_None,
|
2006-12-26 17:47:52 +00:00
|
|
|
nsGkAtoms::popup))
|
2005-03-30 02:14:41 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// check for a <menubutton> like bookmarks
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mGestureDownContent->Tag() == nsGkAtoms::menubutton)
|
2005-03-30 02:14:41 +00:00
|
|
|
return;
|
2001-04-26 19:12:31 +00:00
|
|
|
}
|
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
mClickHoldTimer = do_CreateInstance("@mozilla.org/timer;1");
|
2010-06-16 07:36:11 +00:00
|
|
|
if (mClickHoldTimer) {
|
|
|
|
PRInt32 clickHoldDelay =
|
2011-05-25 06:32:00 +00:00
|
|
|
Preferences::GetInt("ui.click_hold_context_menus.delay", 500);
|
2003-11-19 01:20:56 +00:00
|
|
|
mClickHoldTimer->InitWithFuncCallback(sClickHoldCallback, this,
|
2010-06-16 07:36:11 +00:00
|
|
|
clickHoldDelay,
|
2002-09-07 07:17:59 +00:00
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2010-06-16 07:36:11 +00:00
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
} // CreateClickHoldTimer
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// KillClickHoldTimer
|
|
|
|
//
|
|
|
|
// Stop the timer that would show the context menu dead in its tracks
|
|
|
|
//
|
|
|
|
void
|
2003-11-19 01:20:56 +00:00
|
|
|
nsEventStateManager::KillClickHoldTimer()
|
2001-03-30 04:45:40 +00:00
|
|
|
{
|
2003-11-19 01:20:56 +00:00
|
|
|
if (mClickHoldTimer) {
|
2001-03-30 04:45:40 +00:00
|
|
|
mClickHoldTimer->Cancel();
|
|
|
|
mClickHoldTimer = nsnull;
|
|
|
|
}
|
2005-04-19 23:03:23 +00:00
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// sClickHoldCallback
|
|
|
|
//
|
2004-07-23 07:27:57 +00:00
|
|
|
// This fires after the mouse has been down for a certain length of time.
|
2001-03-30 04:45:40 +00:00
|
|
|
//
|
|
|
|
void
|
2004-04-13 07:09:54 +00:00
|
|
|
nsEventStateManager::sClickHoldCallback(nsITimer *aTimer, void* aESM)
|
2001-03-30 04:45:40 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
nsEventStateManager* self = static_cast<nsEventStateManager*>(aESM);
|
2010-06-16 07:36:11 +00:00
|
|
|
if (self)
|
2001-03-30 04:45:40 +00:00
|
|
|
self->FireContextClick();
|
|
|
|
|
|
|
|
// NOTE: |aTimer| and |self->mAutoHideTimer| are invalid after calling ClosePopup();
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
} // 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
|
2003-11-19 01:20:56 +00:00
|
|
|
nsEventStateManager::FireContextClick()
|
2001-03-30 04:45:40 +00:00
|
|
|
{
|
2010-06-16 07:36:11 +00:00
|
|
|
if (!mGestureDownContent)
|
2001-03-30 04:45:40 +00:00
|
|
|
return;
|
|
|
|
|
2005-08-13 00:20:46 +00:00
|
|
|
#ifdef XP_MACOSX
|
2009-09-18 16:34:37 +00: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
|
2002-03-26 00:59:03 +00:00
|
|
|
// us from handling any OS events. See bug 117589.
|
2009-09-18 16:34:37 +00:00
|
|
|
if (!CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft))
|
2002-03-26 00:59:03 +00:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
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 21:20:05 +00:00
|
|
|
mCurrentTarget = mPresContext->GetPrimaryFrameFor(mGestureDownContent);
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
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();
|
|
|
|
PRBool allowedToDispatch = PR_TRUE;
|
|
|
|
|
|
|
|
if (mGestureDownContent->IsXUL()) {
|
|
|
|
if (tag == nsGkAtoms::scrollbar ||
|
|
|
|
tag == nsGkAtoms::scrollbarbutton ||
|
|
|
|
tag == nsGkAtoms::button)
|
|
|
|
allowedToDispatch = PR_FALSE;
|
|
|
|
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)) {
|
2003-11-19 01:20:56 +00:00
|
|
|
allowedToDispatch = PR_FALSE;
|
2009-12-24 21:20:05 +00:00
|
|
|
} else {
|
|
|
|
// If the toolbar button has an open menu, don't attempt to open
|
2006-01-18 04:09:33 +00:00
|
|
|
// a second menu
|
2009-12-24 21:20:05 +00:00
|
|
|
if (mGestureDownContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::open,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
|
|
|
allowedToDispatch = PR_FALSE;
|
2006-01-18 04:09:33 +00:00
|
|
|
}
|
2001-03-31 23:32:14 +00:00
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
2009-12-24 21:20:05 +00:00
|
|
|
}
|
|
|
|
else if (mGestureDownContent->IsHTML()) {
|
|
|
|
nsCOMPtr<nsIFormControl> formCtrl(do_QueryInterface(mGestureDownContent));
|
|
|
|
|
|
|
|
if (formCtrl) {
|
|
|
|
// of all form controls, only ones dealing with text are
|
|
|
|
// allowed to have context menus
|
|
|
|
PRInt32 type = formCtrl->GetType();
|
|
|
|
|
|
|
|
allowedToDispatch = (type == NS_FORM_INPUT_TEXT ||
|
2010-08-18 18:31:54 +00:00
|
|
|
type == NS_FORM_INPUT_EMAIL ||
|
2010-05-17 10:20:22 +00:00
|
|
|
type == NS_FORM_INPUT_SEARCH ||
|
2010-05-12 07:17:07 +00:00
|
|
|
type == NS_FORM_INPUT_TEL ||
|
2010-08-18 18:33:37 +00:00
|
|
|
type == NS_FORM_INPUT_URL ||
|
2009-12-24 21:20:05 +00:00
|
|
|
type == NS_FORM_INPUT_PASSWORD ||
|
|
|
|
type == NS_FORM_INPUT_FILE ||
|
|
|
|
type == NS_FORM_TEXTAREA);
|
2002-03-31 17:38:52 +00:00
|
|
|
}
|
2009-12-24 21:20:05 +00:00
|
|
|
else if (tag == nsGkAtoms::applet ||
|
|
|
|
tag == nsGkAtoms::embed ||
|
|
|
|
tag == nsGkAtoms::object) {
|
|
|
|
allowedToDispatch = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2003-11-19 01:20:56 +00:00
|
|
|
|
2009-12-24 21:20:05 +00:00
|
|
|
if (allowedToDispatch) {
|
|
|
|
// make sure the widget sticks around
|
2010-07-02 19:11:04 +00:00
|
|
|
nsCOMPtr<nsIWidget> targetWidget(mCurrentTarget->GetNearestWidget());
|
2009-12-24 21:20:05 +00:00
|
|
|
// init the event while mCurrentTarget is still good
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_CONTEXTMENU,
|
|
|
|
targetWidget,
|
|
|
|
nsMouseEvent::eReal);
|
|
|
|
event.clickCount = 1;
|
|
|
|
FillInEventFromGestureDown(&event);
|
2005-07-15 00:44:28 +00:00
|
|
|
|
2009-12-24 21:20:05 +00:00
|
|
|
// stop selection tracking, we're in control now
|
|
|
|
if (mCurrentTarget)
|
|
|
|
{
|
2011-05-19 03:10:49 +00:00
|
|
|
nsRefPtr<nsFrameSelection> frameSel =
|
2009-12-24 21:20:05 +00:00
|
|
|
mCurrentTarget->GetFrameSelection();
|
2006-04-26 01:57:22 +00:00
|
|
|
|
2009-12-24 21:20:05 +00: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
|
|
|
|
frameSel->SetMouseDownState(PR_FALSE);
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
2009-12-24 21:20:05 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2009-12-24 21:20:05 +00:00
|
|
|
// dispatch to DOM
|
|
|
|
nsEventDispatcher::Dispatch(mGestureDownContent, mPresContext, &event,
|
|
|
|
nsnull, &status);
|
2002-05-21 00:00:46 +00:00
|
|
|
|
2009-12-24 21:20:05 +00: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.
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
// now check if the event has been handled. If so, stop tracking a drag
|
2010-06-16 07:36:11 +00:00
|
|
|
if (status == nsEventStatus_eConsumeNoDefault) {
|
2001-03-30 04:45:40 +00:00
|
|
|
StopTrackingDragGesture();
|
2005-06-28 21:40:15 +00:00
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
|
|
|
|
KillClickHoldTimer();
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
} // FireContextClick
|
|
|
|
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
//
|
1999-08-19 19:48:45 +00:00
|
|
|
// BeginTrackingDragGesture
|
|
|
|
//
|
|
|
|
// Record that the mouse has gone down and that we should move to TRACKING state
|
|
|
|
// of d&d gesture tracker.
|
|
|
|
//
|
2010-06-16 07:36:11 +00:00
|
|
|
// We also use this to track click-hold context menus. When the mouse goes down,
|
2001-03-30 04:45:40 +00: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.
|
|
|
|
//
|
1999-08-19 19:48:45 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::BeginTrackingDragGesture(nsPresContext* aPresContext,
|
2005-04-19 23:03:23 +00:00
|
|
|
nsMouseEvent* inDownEvent,
|
2003-11-19 01:20:56 +00:00
|
|
|
nsIFrame* inDownFrame)
|
1999-08-19 19:48:45 +00:00
|
|
|
{
|
2010-06-16 07:36:11 +00:00
|
|
|
if (!inDownEvent->widget)
|
|
|
|
return;
|
|
|
|
|
2004-06-22 04:32:52 +00:00
|
|
|
// Note that |inDownEvent| could be either a mouse down event or a
|
|
|
|
// synthesized mouse move event.
|
2010-06-16 07:36:11 +00:00
|
|
|
mGestureDownPoint = inDownEvent->refPoint +
|
2009-02-19 00:11:49 +00:00
|
|
|
inDownEvent->widget->WidgetToScreenOffset();
|
2005-03-30 02:14:41 +00:00
|
|
|
|
|
|
|
inDownFrame->GetContentForEvent(aPresContext, inDownEvent,
|
|
|
|
getter_AddRefs(mGestureDownContent));
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2005-06-28 21:40:15 +00:00
|
|
|
mGestureDownFrameOwner = inDownFrame->GetContent();
|
2005-04-19 23:03:23 +00:00
|
|
|
mGestureDownShift = inDownEvent->isShift;
|
|
|
|
mGestureDownControl = inDownEvent->isControl;
|
|
|
|
mGestureDownAlt = inDownEvent->isAlt;
|
|
|
|
mGestureDownMeta = inDownEvent->isMeta;
|
|
|
|
|
2010-06-16 07:36:11 +00:00
|
|
|
if (mClickHoldContextMenu) {
|
|
|
|
// fire off a timer to track click-hold
|
|
|
|
CreateClickHoldTimer(aPresContext, inDownFrame, inDownEvent);
|
|
|
|
}
|
1999-08-19 19:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// StopTrackingDragGesture
|
|
|
|
//
|
2004-07-23 07:27:57 +00:00
|
|
|
// Record that the mouse has gone back up so that we should leave the TRACKING
|
1999-08-19 19:48:45 +00:00
|
|
|
// state of d&d gesture tracker and return to the START state.
|
|
|
|
//
|
|
|
|
void
|
2003-11-19 01:20:56 +00:00
|
|
|
nsEventStateManager::StopTrackingDragGesture()
|
1999-08-19 19:48:45 +00:00
|
|
|
{
|
2005-03-30 02:14:41 +00:00
|
|
|
mGestureDownContent = nsnull;
|
2005-06-28 21:40:15 +00:00
|
|
|
mGestureDownFrameOwner = nsnull;
|
1999-08-19 19:48:45 +00:00
|
|
|
}
|
|
|
|
|
2005-04-19 23:03:23 +00:00
|
|
|
void
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEventStateManager::FillInEventFromGestureDown(nsMouseEvent* aEvent)
|
2005-04-19 23:03:23 +00:00
|
|
|
{
|
2010-07-02 19:11:04 +00:00
|
|
|
NS_ASSERTION(aEvent->widget == mCurrentTarget->GetNearestWidget(),
|
2005-04-19 23:03:23 +00: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-19 00:11:49 +00:00
|
|
|
nsIntPoint tmpPoint = aEvent->widget->WidgetToScreenOffset();
|
|
|
|
aEvent->refPoint = mGestureDownPoint - tmpPoint;
|
2005-04-19 23:03:23 +00:00
|
|
|
aEvent->isShift = mGestureDownShift;
|
|
|
|
aEvent->isControl = mGestureDownControl;
|
|
|
|
aEvent->isAlt = mGestureDownAlt;
|
|
|
|
aEvent->isMeta = mGestureDownMeta;
|
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
|
1999-08-19 19:48:45 +00: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
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::GenerateDragGesture(nsPresContext* aPresContext,
|
2005-04-19 23:03:23 +00:00
|
|
|
nsMouseEvent *aEvent)
|
1999-08-19 19:48:45 +00:00
|
|
|
{
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(aPresContext, "This shouldn't happen.");
|
2010-06-16 07:36:11 +00:00
|
|
|
if (IsTrackingDragGesture()) {
|
2009-12-24 21:20:05 +00:00
|
|
|
mCurrentTarget = mGestureDownFrameOwner->GetPrimaryFrame();
|
2005-08-22 22:24:29 +00:00
|
|
|
|
2005-03-30 02:14:41 +00:00
|
|
|
if (!mCurrentTarget) {
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
return;
|
|
|
|
}
|
2000-05-25 20:04:02 +00:00
|
|
|
|
|
|
|
// Check if selection is tracking drag gestures, if so
|
|
|
|
// don't interfere!
|
2006-04-26 01:57:22 +00:00
|
|
|
if (mCurrentTarget)
|
|
|
|
{
|
2011-05-19 03:10:49 +00:00
|
|
|
nsRefPtr<nsFrameSelection> frameSel = mCurrentTarget->GetFrameSelection();
|
2006-04-26 01:57:22 +00:00
|
|
|
if (frameSel && frameSel->GetMouseDownState()) {
|
2001-03-30 04:45:40 +00:00
|
|
|
StopTrackingDragGesture();
|
|
|
|
return;
|
2000-05-25 20:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-03 02:07:08 +00:00
|
|
|
// If non-native code is capturing the mouse don't start a drag.
|
|
|
|
if (nsIPresShell::IsMouseCapturePreventingDrag()) {
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-02 18:20:38 +00:00
|
|
|
static PRInt32 pixelThresholdX = 0;
|
|
|
|
static PRInt32 pixelThresholdY = 0;
|
|
|
|
|
2003-05-02 19:10:18 +00:00
|
|
|
if (!pixelThresholdX) {
|
2004-01-21 09:35:59 +00:00
|
|
|
nsILookAndFeel *lf = aPresContext->LookAndFeel();
|
2003-05-02 18:20:38 +00:00
|
|
|
lf->GetMetric(nsILookAndFeel::eMetric_DragThresholdX, pixelThresholdX);
|
|
|
|
lf->GetMetric(nsILookAndFeel::eMetric_DragThresholdY, pixelThresholdY);
|
|
|
|
if (!pixelThresholdX)
|
|
|
|
pixelThresholdX = 5;
|
|
|
|
if (!pixelThresholdY)
|
|
|
|
pixelThresholdY = 5;
|
|
|
|
}
|
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
// fire drag gesture if mouse has moved enough
|
2009-02-19 00:11:49 +00:00
|
|
|
nsIntPoint pt = aEvent->refPoint + aEvent->widget->WidgetToScreenOffset();
|
2011-06-02 12:56:50 +00:00
|
|
|
if (NS_ABS(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
|
|
|
|
NS_ABS(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
|
2010-06-16 07:36:11 +00:00
|
|
|
if (mClickHoldContextMenu) {
|
|
|
|
// stop the click-hold before we fire off the drag gesture, in case
|
|
|
|
// it takes a long time
|
|
|
|
KillClickHoldTimer();
|
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
|
2008-08-27 12:07:27 +00:00
|
|
|
nsRefPtr<nsDOMDataTransfer> dataTransfer = new nsDOMDataTransfer();
|
|
|
|
if (!dataTransfer)
|
|
|
|
return;
|
|
|
|
|
2008-09-25 14:45:03 +00:00
|
|
|
PRBool isInEditor = PR_FALSE;
|
2008-08-27 12:07:27 +00:00
|
|
|
PRBool isSelection = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIContent> eventContent, targetContent;
|
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent,
|
|
|
|
getter_AddRefs(eventContent));
|
|
|
|
if (eventContent)
|
|
|
|
DetermineDragTarget(aPresContext, eventContent, dataTransfer,
|
2008-09-25 14:45:03 +00:00
|
|
|
&isSelection, &isInEditor,
|
|
|
|
getter_AddRefs(targetContent));
|
2008-08-27 12:07:27 +00:00
|
|
|
|
2005-04-18 00:48:59 +00:00
|
|
|
// Stop tracking the drag gesture now. This should stop us from
|
|
|
|
// reentering GenerateDragGesture inside DOM event processing.
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
|
2008-08-27 12:07:27 +00:00
|
|
|
if (!targetContent)
|
|
|
|
return;
|
|
|
|
|
2010-07-02 19:11:04 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = mCurrentTarget->GetNearestWidget();
|
2007-04-12 04:37:39 +00:00
|
|
|
|
2003-04-19 00:46:28 +00:00
|
|
|
// get the widget from the target frame
|
2008-08-27 12:07:27 +00:00
|
|
|
nsDragEvent startEvent(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_START, widget);
|
|
|
|
FillInEventFromGestureDown(&startEvent);
|
|
|
|
|
|
|
|
nsDragEvent gestureEvent(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_GESTURE, widget);
|
2007-04-12 04:37:39 +00:00
|
|
|
FillInEventFromGestureDown(&gestureEvent);
|
1999-08-19 19:48:45 +00:00
|
|
|
|
2008-08-27 12:07:27 +00:00
|
|
|
startEvent.dataTransfer = gestureEvent.dataTransfer = dataTransfer;
|
2010-04-06 12:59:24 +00:00
|
|
|
startEvent.inputSource = gestureEvent.inputSource = aEvent->inputSource;
|
2008-08-27 12:07:27 +00:00
|
|
|
|
2005-03-30 02:14:41 +00: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;
|
2005-04-18 00:48:59 +00:00
|
|
|
|
2005-03-30 02:14:41 +00:00
|
|
|
// Set the current target to the content for the mouse down
|
2005-04-18 00:48:59 +00:00
|
|
|
mCurrentTargetContent = targetContent;
|
2005-03-30 02:14:41 +00:00
|
|
|
|
2008-09-25 14:45:03 +00: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-12 04:37:39 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2008-09-25 14:45:03 +00:00
|
|
|
if (!isInEditor)
|
|
|
|
nsEventDispatcher::Dispatch(targetContent, aPresContext, &startEvent, nsnull,
|
|
|
|
&status);
|
2005-03-30 02:14:41 +00:00
|
|
|
|
2008-08-27 12:07:27 +00:00
|
|
|
nsDragEvent* event = &startEvent;
|
|
|
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
|
|
|
status = nsEventStatus_eIgnore;
|
|
|
|
nsEventDispatcher::Dispatch(targetContent, aPresContext, &gestureEvent, nsnull,
|
|
|
|
&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 14:55:53 +00:00
|
|
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
|
|
|
PRBool dragStarted = DoDefaultDragStart(aPresContext, event, dataTransfer,
|
|
|
|
targetContent, isSelection);
|
|
|
|
if (dragStarted) {
|
2010-10-28 14:11:15 +00:00
|
|
|
sActiveESM = nsnull;
|
2009-11-09 14:55:53 +00:00
|
|
|
aEvent->flags |= NS_EVENT_FLAG_STOP_DISPATCH;
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 12:07:27 +00:00
|
|
|
|
2005-03-30 02:14:41 +00: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;
|
1999-08-19 19:48:45 +00:00
|
|
|
}
|
2000-10-16 21:52:22 +00:00
|
|
|
|
2005-01-20 03:39:09 +00:00
|
|
|
// Now flush all pending notifications, for better responsiveness
|
|
|
|
// while dragging.
|
|
|
|
FlushPendingEvents(aPresContext);
|
|
|
|
}
|
1999-08-19 19:48:45 +00:00
|
|
|
} // GenerateDragGesture
|
|
|
|
|
2008-08-27 12:07:27 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::DetermineDragTarget(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aSelectionTarget,
|
|
|
|
nsDOMDataTransfer* aDataTransfer,
|
|
|
|
PRBool* aIsSelection,
|
2008-09-25 14:45:03 +00:00
|
|
|
PRBool* aIsInEditor,
|
2008-08-27 12:07:27 +00:00
|
|
|
nsIContent** aTargetNode)
|
|
|
|
{
|
|
|
|
*aTargetNode = nsnull;
|
2008-09-25 14:45:03 +00:00
|
|
|
*aIsInEditor = PR_FALSE;
|
2008-08-27 12:07:27 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container = aPresContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_GetInterface(container);
|
|
|
|
|
|
|
|
// GetDragData determines if a selection, link or image in the content
|
|
|
|
// should be dragged, and places the data associated with the drag in the
|
|
|
|
// data transfer. Skip this check for chrome shells.
|
|
|
|
PRBool canDrag;
|
|
|
|
nsCOMPtr<nsIContent> dragDataNode;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(container);
|
|
|
|
if (dsti) {
|
|
|
|
PRInt32 type = -1;
|
|
|
|
if (NS_SUCCEEDED(dsti->GetItemType(&type)) &&
|
|
|
|
type != nsIDocShellTreeItem::typeChrome) {
|
|
|
|
// mGestureDownContent is the node where the mousedown event for the drag
|
2010-05-13 12:19:50 +00:00
|
|
|
// occurred, and aSelectionTarget is the node to use when a selection is used
|
2008-08-27 12:07:27 +00:00
|
|
|
nsresult rv =
|
|
|
|
nsContentAreaDragDrop::GetDragData(window, mGestureDownContent,
|
|
|
|
aSelectionTarget, mGestureDownAlt,
|
|
|
|
aDataTransfer, &canDrag, aIsSelection,
|
|
|
|
getter_AddRefs(dragDataNode));
|
|
|
|
if (NS_FAILED(rv) || !canDrag)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
else if (*aIsSelection)
|
|
|
|
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.
|
|
|
|
if (!*aIsSelection) {
|
|
|
|
while (dragContent) {
|
|
|
|
nsCOMPtr<nsIDOMNSHTMLElement> htmlElement = do_QueryInterface(dragContent);
|
|
|
|
if (htmlElement) {
|
|
|
|
PRBool draggable = PR_FALSE;
|
|
|
|
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();
|
2008-09-25 14:45:03 +00:00
|
|
|
|
|
|
|
// if an editable parent is encountered, then we don't look at any
|
|
|
|
// ancestors. This is used because the editor attaches a draggesture
|
|
|
|
// listener to the editable element and we want to call it without
|
|
|
|
// making the editable element draggable. This should be removed once
|
|
|
|
// the editor is switched over to using the proper drag and drop api.
|
|
|
|
nsCOMPtr<nsIDOMNSEditableElement> editableElement = do_QueryInterface(dragContent);
|
|
|
|
if (editableElement) {
|
|
|
|
*aIsInEditor = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no node in the hierarchy was found to drag, but the GetDragData method
|
2008-09-08 16:09:35 +00:00
|
|
|
// returned a node, use that returned node. Otherwise, nothing is draggable.
|
|
|
|
if (!dragContent && dragDataNode)
|
|
|
|
dragContent = dragDataNode;
|
2008-08-27 12:07:27 +00: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-09 14:55:53 +00:00
|
|
|
PRBool
|
2008-08-27 12:07:27 +00:00
|
|
|
nsEventStateManager::DoDefaultDragStart(nsPresContext* aPresContext,
|
|
|
|
nsDragEvent* aDragEvent,
|
|
|
|
nsDOMDataTransfer* aDataTransfer,
|
|
|
|
nsIContent* aDragTarget,
|
|
|
|
PRBool aIsSelection)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDragService> dragService =
|
|
|
|
do_GetService("@mozilla.org/widget/dragservice;1");
|
|
|
|
if (!dragService)
|
2009-11-09 14:55:53 +00:00
|
|
|
return PR_FALSE;
|
2008-08-27 12:07:27 +00: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 14:55:53 +00:00
|
|
|
// drag and drop manually. Make sure to return true to indicate that a drag
|
|
|
|
// began.
|
2008-08-27 12:07:27 +00:00
|
|
|
nsCOMPtr<nsIDragSession> dragSession;
|
|
|
|
dragService->GetCurrentSession(getter_AddRefs(dragSession));
|
|
|
|
if (dragSession)
|
2009-11-09 14:55:53 +00:00
|
|
|
return PR_TRUE;
|
2008-08-27 12:07:27 +00: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.
|
|
|
|
PRUint32 count = 0;
|
|
|
|
if (aDataTransfer)
|
|
|
|
aDataTransfer->GetMozItemCount(&count);
|
|
|
|
if (!count)
|
2009-11-09 14:55:53 +00:00
|
|
|
return PR_FALSE;
|
2008-08-27 12:07:27 +00: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)
|
2009-11-09 14:55:53 +00:00
|
|
|
return PR_FALSE;
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
|
2008-09-01 19:51:12 +00: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.
|
|
|
|
PRUint32 action;
|
|
|
|
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 12:07:27 +00:00
|
|
|
|
|
|
|
// get any custom drag image that was set
|
|
|
|
PRInt32 imageX, imageY;
|
|
|
|
nsIDOMElement* dragImage = aDataTransfer->GetDragImage(&imageX, &imageY);
|
|
|
|
|
|
|
|
// If a selection is being dragged, and no custom drag image was
|
|
|
|
// set, get the selection so that the drag region can be created
|
|
|
|
// from the selection area. If a custom image was set, it doesn't
|
|
|
|
// matter what the selection is since the image will be used instead.
|
|
|
|
nsISelection* selection = nsnull;
|
|
|
|
if (aIsSelection && !dragImage) {
|
|
|
|
nsIDocument* doc = aDragTarget->GetCurrentDoc();
|
|
|
|
if (doc) {
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell* presShell = doc->GetShell();
|
2008-08-27 12:07:27 +00:00
|
|
|
if (presShell) {
|
|
|
|
selection = presShell->GetCurrentSelection(
|
|
|
|
nsISelectionController::SELECTION_NORMAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsArray> transArray;
|
|
|
|
aDataTransfer->GetTransferables(getter_AddRefs(transArray));
|
|
|
|
if (!transArray)
|
2009-11-09 14:55:53 +00:00
|
|
|
return PR_FALSE;
|
2008-08-27 12:07:27 +00: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;
|
|
|
|
NS_NewDOMDragEvent(getter_AddRefs(domEvent), aPresContext, aDragEvent);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDragEvent> domDragEvent = do_QueryInterface(domEvent);
|
|
|
|
// if creating a drag event failed, starting a drag session will
|
|
|
|
// just fail.
|
|
|
|
if (selection) {
|
|
|
|
dragService->InvokeDragSessionWithSelection(selection, transArray,
|
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(dragTarget);
|
|
|
|
if (content->NodeInfo()->Equals(nsGkAtoms::treechildren,
|
|
|
|
kNameSpaceID_XUL)) {
|
2009-12-24 21:20:05 +00:00
|
|
|
nsTreeBodyFrame* treeBody = do_QueryFrame(content->GetPrimaryFrame());
|
|
|
|
if (treeBody) {
|
|
|
|
treeBody->GetSelectionRegion(getter_AddRefs(region));
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dragService->InvokeDragSessionWithImage(dragTarget, transArray,
|
|
|
|
region, action, dragImage,
|
|
|
|
imageX, imageY, domDragEvent,
|
|
|
|
aDataTransfer);
|
|
|
|
}
|
2009-11-09 14:55:53 +00:00
|
|
|
|
|
|
|
return PR_TRUE;
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 02:10:11 +00:00
|
|
|
nsresult
|
2007-10-30 19:13:37 +00:00
|
|
|
nsEventStateManager::GetMarkupDocumentViewer(nsIMarkupDocumentViewer** aMv)
|
2000-05-15 02:10:11 +00:00
|
|
|
{
|
2007-10-30 19:13:37 +00:00
|
|
|
*aMv = nsnull;
|
|
|
|
|
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 18:00:39 +00:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if(!fm) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> focusedWindow;
|
|
|
|
fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
2000-09-10 05:35:36 +00: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 18:00:39 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(focusedWindow);
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!ourWindow) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
2004-05-03 21:48:36 +00:00
|
|
|
nsIDOMWindowInternal *rootWindow = ourWindow->GetPrivateRoot();
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!rootWindow) return NS_ERROR_FAILURE;
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2005-07-30 20:57:07 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> contentWindow;
|
|
|
|
rootWindow->GetContent(getter_AddRefs(contentWindow));
|
|
|
|
if(!contentWindow) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsIDocument *doc = GetDocumentFromWindow(contentWindow);
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!doc) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell *presShell = doc->GetShell();
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!presShell) return NS_ERROR_FAILURE;
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!presContext) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer = presContext->GetContainer();
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!pcContainer) return NS_ERROR_FAILURE;
|
2000-05-15 02:10:11 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docshell(do_QueryInterface(pcContainer));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!docshell) return NS_ERROR_FAILURE;
|
2000-05-15 02:10:11 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docshell->GetContentViewer(getter_AddRefs(cv));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!cv) return NS_ERROR_FAILURE;
|
2000-05-15 02:10:11 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mv(do_QueryInterface(cv));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!mv) return NS_ERROR_FAILURE;
|
2000-05-15 02:10:11 +00:00
|
|
|
|
2007-10-30 19:13:37 +00:00
|
|
|
*aMv = mv;
|
|
|
|
NS_IF_ADDREF(*aMv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::ChangeTextSize(PRInt32 change)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mv;
|
|
|
|
nsresult rv = GetMarkupDocumentViewer(getter_AddRefs(mv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
float textzoom;
|
2011-05-25 06:32:00 +00:00
|
|
|
float zoomMin = ((float)Preferences::GetInt("zoom.minPercent", 50)) / 100;
|
|
|
|
float zoomMax = ((float)Preferences::GetInt("zoom.maxPercent", 300)) / 100;
|
2007-10-30 19:13:37 +00:00
|
|
|
mv->GetTextZoom(&textzoom);
|
|
|
|
textzoom += ((float)change) / 10;
|
2008-10-22 14:15:14 +00:00
|
|
|
if (textzoom < zoomMin)
|
|
|
|
textzoom = zoomMin;
|
|
|
|
else if (textzoom > zoomMax)
|
|
|
|
textzoom = zoomMax;
|
|
|
|
mv->SetTextZoom(textzoom);
|
2007-10-30 19:13:37 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::ChangeFullZoom(PRInt32 change)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mv;
|
|
|
|
nsresult rv = GetMarkupDocumentViewer(getter_AddRefs(mv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-10-25 23:02:20 +00:00
|
|
|
float fullzoom;
|
2011-05-25 06:32:00 +00:00
|
|
|
float zoomMin = ((float)Preferences::GetInt("zoom.minPercent", 50)) / 100;
|
|
|
|
float zoomMax = ((float)Preferences::GetInt("zoom.maxPercent", 300)) / 100;
|
2007-10-25 23:02:20 +00:00
|
|
|
mv->GetFullZoom(&fullzoom);
|
|
|
|
fullzoom += ((float)change) / 10;
|
|
|
|
if (fullzoom < zoomMin)
|
|
|
|
fullzoom = zoomMin;
|
|
|
|
else if (fullzoom > zoomMax)
|
|
|
|
fullzoom = zoomMax;
|
|
|
|
mv->SetFullZoom(fullzoom);
|
2000-05-15 02:10:11 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-19 19:48:45 +00:00
|
|
|
|
2004-04-19 15:48:14 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::DoScrollHistory(PRInt32 direction)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> pcContainer(mPresContext->GetContainer());
|
|
|
|
if (pcContainer) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(pcContainer));
|
|
|
|
if (webNav) {
|
2004-04-29 07:01:50 +00:00
|
|
|
// positive direction to go back one step, nonpositive to go forward
|
|
|
|
if (direction > 0)
|
2004-04-19 15:48:14 +00:00
|
|
|
webNav->GoBack();
|
|
|
|
else
|
|
|
|
webNav->GoForward();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-02-13 11:00:45 +00:00
|
|
|
nsEventStateManager::DoScrollZoom(nsIFrame *aTargetFrame,
|
|
|
|
PRInt32 adjustment)
|
2004-04-19 15:48:14 +00:00
|
|
|
{
|
|
|
|
// Exclude form controls and XUL content.
|
|
|
|
nsIContent *content = aTargetFrame->GetContent();
|
|
|
|
if (content &&
|
2006-05-05 06:52:21 +00:00
|
|
|
!content->IsNodeOfType(nsINode::eHTML_FORM_CONTROL) &&
|
2009-08-24 20:02:07 +00:00
|
|
|
!content->IsXUL())
|
2004-04-19 15:48:14 +00:00
|
|
|
{
|
2008-02-13 11:00:45 +00:00
|
|
|
// positive adjustment to decrease zoom, negative to increase
|
|
|
|
PRInt32 change = (adjustment > 0) ? -1 : 1;
|
2007-10-30 19:13:37 +00:00
|
|
|
|
2011-05-25 06:31:59 +00:00
|
|
|
if (Preferences::GetBool("browser.zoom.full")) {
|
2008-02-13 11:00:45 +00:00
|
|
|
ChangeFullZoom(change);
|
2011-05-25 06:31:59 +00:00
|
|
|
} else {
|
2008-02-13 11:00:45 +00:00
|
|
|
ChangeTextSize(change);
|
2011-05-25 06:31:59 +00:00
|
|
|
}
|
2004-04-19 15:48:14 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-15 22:07:06 +00:00
|
|
|
|
2006-02-01 19:55:35 +00:00
|
|
|
static nsIFrame*
|
2010-01-11 21:45:02 +00:00
|
|
|
GetParentFrameToScroll(nsIFrame* aFrame)
|
2006-02-01 19:55:35 +00:00
|
|
|
{
|
2010-01-11 21:45:02 +00:00
|
|
|
if (!aFrame)
|
2006-02-01 19:55:35 +00:00
|
|
|
return nsnull;
|
|
|
|
|
2008-11-25 23:22:39 +00:00
|
|
|
if (aFrame->GetStyleDisplay()->mPosition == NS_STYLE_POSITION_FIXED &&
|
|
|
|
nsLayoutUtils::IsReallyFixedPos(aFrame))
|
2010-01-11 21:45:02 +00:00
|
|
|
return aFrame->PresContext()->GetPresShell()->GetRootScrollFrame();
|
2006-02-01 19:55:35 +00:00
|
|
|
|
|
|
|
return aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
2010-01-11 21:45:04 +00:00
|
|
|
static nscoord
|
|
|
|
GetScrollableLineHeight(nsIFrame* aTargetFrame)
|
2008-09-17 11:27:19 +00:00
|
|
|
{
|
2010-01-11 21:45:04 +00:00
|
|
|
for (nsIFrame* f = aTargetFrame; f; f = GetParentFrameToScroll(f)) {
|
|
|
|
nsIScrollableFrame* sf = f->GetScrollTargetFrame();
|
|
|
|
if (sf)
|
|
|
|
return sf->GetLineScrollAmount().height;
|
2008-09-17 11:27:19 +00:00
|
|
|
}
|
|
|
|
|
2010-01-11 21:45:04 +00:00
|
|
|
// Fall back to the font height of the target frame.
|
|
|
|
const nsStyleFont* font = aTargetFrame->GetStyleFont();
|
|
|
|
const nsFont& f = font->mFont;
|
2011-04-08 01:05:49 +00:00
|
|
|
nsRefPtr<nsFontMetrics> fm = aTargetFrame->PresContext()->GetMetricsFor(f);
|
2010-01-11 21:45:04 +00:00
|
|
|
NS_ASSERTION(fm, "FontMetrics is null!");
|
|
|
|
if (fm)
|
2011-04-08 04:18:43 +00:00
|
|
|
return fm->MaxHeight();
|
|
|
|
return 0;
|
2009-04-02 19:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::SendLineScrollEvent(nsIFrame* aTargetFrame,
|
|
|
|
nsMouseScrollEvent* aEvent,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsEventStatus* aStatus,
|
|
|
|
PRInt32 aNumLines)
|
|
|
|
{
|
|
|
|
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 18:00:39 +00:00
|
|
|
targetContent = GetFocusedContent();
|
2009-04-02 19:34:31 +00:00
|
|
|
if (!targetContent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (targetContent->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
targetContent = targetContent->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool isTrusted = (aEvent->flags & NS_EVENT_FLAG_TRUSTED) != 0;
|
|
|
|
nsMouseScrollEvent event(isTrusted, NS_MOUSE_SCROLL, nsnull);
|
|
|
|
event.refPoint = aEvent->refPoint;
|
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.time = aEvent->time;
|
|
|
|
event.isShift = aEvent->isShift;
|
|
|
|
event.isControl = aEvent->isControl;
|
|
|
|
event.isAlt = aEvent->isAlt;
|
|
|
|
event.isMeta = aEvent->isMeta;
|
|
|
|
event.scrollFlags = aEvent->scrollFlags;
|
|
|
|
event.delta = aNumLines;
|
2010-04-06 12:59:24 +00:00
|
|
|
event.inputSource = static_cast<nsMouseEvent_base*>(aEvent)->inputSource;
|
2009-04-02 19:34:31 +00:00
|
|
|
|
|
|
|
nsEventDispatcher::Dispatch(targetContent, aPresContext, &event, nsnull, aStatus);
|
|
|
|
}
|
|
|
|
|
2008-09-17 11:27:19 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::SendPixelScrollEvent(nsIFrame* aTargetFrame,
|
|
|
|
nsMouseScrollEvent* aEvent,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsEventStatus* aStatus)
|
|
|
|
{
|
|
|
|
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 18:00:39 +00:00
|
|
|
if (!targetContent) {
|
|
|
|
targetContent = GetFocusedContent();
|
|
|
|
if (!targetContent)
|
|
|
|
return;
|
|
|
|
}
|
2008-09-17 11:27:19 +00:00
|
|
|
|
|
|
|
while (targetContent->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
targetContent = targetContent->GetParent();
|
|
|
|
}
|
|
|
|
|
2010-01-11 21:45:04 +00:00
|
|
|
nscoord lineHeight = GetScrollableLineHeight(aTargetFrame);
|
2008-09-17 11:27:19 +00:00
|
|
|
|
|
|
|
PRBool isTrusted = (aEvent->flags & NS_EVENT_FLAG_TRUSTED) != 0;
|
|
|
|
nsMouseScrollEvent event(isTrusted, NS_MOUSE_PIXEL_SCROLL, nsnull);
|
|
|
|
event.refPoint = aEvent->refPoint;
|
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.time = aEvent->time;
|
|
|
|
event.isShift = aEvent->isShift;
|
|
|
|
event.isControl = aEvent->isControl;
|
|
|
|
event.isAlt = aEvent->isAlt;
|
|
|
|
event.isMeta = aEvent->isMeta;
|
|
|
|
event.scrollFlags = aEvent->scrollFlags;
|
2010-04-06 12:59:24 +00:00
|
|
|
event.inputSource = static_cast<nsMouseEvent_base*>(aEvent)->inputSource;
|
2008-09-17 11:27:19 +00:00
|
|
|
event.delta = aPresContext->AppUnitsToIntCSSPixels(aEvent->delta * lineHeight);
|
|
|
|
|
|
|
|
nsEventDispatcher::Dispatch(targetContent, aPresContext, &event, nsnull, aStatus);
|
|
|
|
}
|
|
|
|
|
2011-05-22 05:39:16 +00:00
|
|
|
PRInt32
|
|
|
|
nsEventStateManager::ComputeWheelActionFor(nsMouseScrollEvent* aMouseEvent,
|
|
|
|
PRBool aUseSystemSettings)
|
|
|
|
{
|
|
|
|
PRInt32 action = GetWheelActionFor(aMouseEvent);
|
|
|
|
if (aUseSystemSettings &&
|
|
|
|
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)) {
|
|
|
|
action = MOUSE_SCROLL_PAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMouseEvent->message == NS_MOUSE_PIXEL_SCROLL) {
|
|
|
|
if (action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE ||
|
|
|
|
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
|
|
|
|
action = MOUSE_SCROLL_PIXELS;
|
|
|
|
} else {
|
|
|
|
// Do not scroll pixels when zooming
|
|
|
|
action = -1;
|
|
|
|
}
|
|
|
|
} else if (aMouseEvent->scrollFlags & nsMouseScrollEvent::kHasPixels) {
|
|
|
|
if (aUseSystemSettings ||
|
|
|
|
action == MOUSE_SCROLL_N_LINES || action == MOUSE_SCROLL_PAGE ||
|
|
|
|
(aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsMomentum)) {
|
|
|
|
// Don't scroll lines when a pixel scroll event will follow.
|
|
|
|
// Also, don't do history scrolling or zooming for momentum scrolls.
|
|
|
|
action = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsEventStateManager::GetWheelActionFor(nsMouseScrollEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
nsCAutoString prefName;
|
|
|
|
GetBasePrefKeyForMouseWheel(aMouseEvent, prefName);
|
|
|
|
prefName.Append(".action");
|
2011-05-25 06:32:00 +00:00
|
|
|
return Preferences::GetInt(prefName.get());
|
2011-05-22 05:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsEventStateManager::GetScrollLinesFor(nsMouseScrollEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!UseSystemScrollSettingFor(aMouseEvent),
|
|
|
|
"GetScrollLinesFor() called when should use system settings");
|
|
|
|
nsCAutoString prefName;
|
|
|
|
GetBasePrefKeyForMouseWheel(aMouseEvent, prefName);
|
|
|
|
prefName.Append(".numlines");
|
2011-05-25 06:32:00 +00:00
|
|
|
return Preferences::GetInt(prefName.get());
|
2011-05-22 05:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsEventStateManager::UseSystemScrollSettingFor(nsMouseScrollEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
nsCAutoString prefName;
|
|
|
|
GetBasePrefKeyForMouseWheel(aMouseEvent, prefName);
|
|
|
|
prefName.Append(".sysnumlines");
|
2011-05-25 06:31:59 +00:00
|
|
|
return Preferences::GetBool(prefName.get());
|
2011-05-22 05:39:16 +00:00
|
|
|
}
|
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
nsresult
|
2010-01-11 21:45:02 +00:00
|
|
|
nsEventStateManager::DoScrollText(nsIFrame* aTargetFrame,
|
2009-05-20 02:05:59 +00:00
|
|
|
nsMouseScrollEvent* aMouseEvent,
|
2010-01-11 21:45:02 +00:00
|
|
|
nsIScrollableFrame::ScrollUnit aScrollQuantity,
|
2011-05-17 00:23:23 +00:00
|
|
|
PRBool aAllowScrollSpeedOverride,
|
|
|
|
nsQueryContentEvent* aQueryEvent)
|
2000-12-09 07:28:19 +00:00
|
|
|
{
|
2010-01-11 21:45:02 +00:00
|
|
|
nsIScrollableFrame* frameToScroll = nsnull;
|
2004-08-07 14:30:30 +00:00
|
|
|
nsIFrame* scrollFrame = aTargetFrame;
|
2009-05-20 02:05:59 +00:00
|
|
|
PRInt32 numLines = aMouseEvent->delta;
|
|
|
|
PRBool isHorizontal = aMouseEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal;
|
|
|
|
aMouseEvent->scrollOverflow = 0;
|
2006-07-12 04:15:42 +00: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) {
|
2010-01-11 21:45:02 +00:00
|
|
|
frameToScroll = lastScrollFrame->GetScrollTargetFrame();
|
|
|
|
if (frameToScroll) {
|
2009-05-20 02:05:59 +00:00
|
|
|
nsMouseWheelTransaction::UpdateTransaction(numLines, isHorizontal);
|
2009-02-17 15:55:53 +00: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 keep handling this scroll event.
|
|
|
|
if (!nsMouseWheelTransaction::GetTargetFrame())
|
|
|
|
return NS_OK;
|
2006-07-12 04:15:42 +00:00
|
|
|
} else {
|
|
|
|
nsMouseWheelTransaction::EndTransaction();
|
|
|
|
lastScrollFrame = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PRBool passToParent = lastScrollFrame ? PR_FALSE : PR_TRUE;
|
2000-12-09 07:28:19 +00:00
|
|
|
|
2006-02-01 19:55:35 +00:00
|
|
|
for (; scrollFrame && passToParent;
|
2010-01-11 21:45:02 +00:00
|
|
|
scrollFrame = GetParentFrameToScroll(scrollFrame)) {
|
2004-08-07 14:30:30 +00:00
|
|
|
// Check whether the frame wants to provide us with a scrollable view.
|
2010-01-11 21:45:02 +00:00
|
|
|
frameToScroll = scrollFrame->GetScrollTargetFrame();
|
|
|
|
if (!frameToScroll) {
|
2004-10-09 05:15:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-01-11 21:45:02 +00:00
|
|
|
nsPresContext::ScrollbarStyles ss = frameToScroll->GetScrollbarStyles();
|
2004-10-09 05:15:08 +00:00
|
|
|
if (NS_STYLE_OVERFLOW_HIDDEN ==
|
2009-05-20 02:05:59 +00:00
|
|
|
(isHorizontal ? ss.mHorizontal : ss.mVertical)) {
|
2004-08-07 14:30:30 +00:00
|
|
|
continue;
|
|
|
|
}
|
2006-04-11 01:48:48 +00:00
|
|
|
|
2004-08-07 14:30:30 +00:00
|
|
|
// Check if the scrollable view can be scrolled any further.
|
2010-01-11 21:45:02 +00:00
|
|
|
nscoord lineHeight = frameToScroll->GetLineScrollAmount().height;
|
2004-08-07 14:30:30 +00:00
|
|
|
if (lineHeight != 0) {
|
2010-01-11 21:45:02 +00:00
|
|
|
if (CanScrollOn(frameToScroll, numLines, isHorizontal)) {
|
2006-07-12 04:15:42 +00:00
|
|
|
passToParent = PR_FALSE;
|
2009-02-12 10:44:38 +00:00
|
|
|
nsMouseWheelTransaction::BeginTransaction(scrollFrame,
|
2009-05-20 02:05:59 +00:00
|
|
|
numLines, isHorizontal);
|
2006-07-12 04:15:42 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2004-08-07 14:30:30 +00:00
|
|
|
// Comboboxes need special care.
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIComboboxControlFrame* comboBox = do_QueryFrame(scrollFrame);
|
2004-08-07 14:30:30 +00:00
|
|
|
if (comboBox) {
|
2006-02-18 01:52:03 +00:00
|
|
|
if (comboBox->IsDroppedDown()) {
|
2004-08-07 14:30:30 +00:00
|
|
|
// Don't propagate to parent when drop down menu is active.
|
|
|
|
if (passToParent) {
|
|
|
|
passToParent = PR_FALSE;
|
2010-01-11 21:45:02 +00:00
|
|
|
frameToScroll = nsnull;
|
2006-07-12 04:15:42 +00:00
|
|
|
nsMouseWheelTransaction::EndTransaction();
|
2004-08-07 14:30:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Always propagate when not dropped down (even if focused).
|
2008-03-15 08:52:18 +00:00
|
|
|
if (!passToParent) {
|
|
|
|
passToParent = PR_TRUE;
|
|
|
|
nsMouseWheelTransaction::EndTransaction();
|
|
|
|
}
|
2003-04-15 13:17:36 +00:00
|
|
|
}
|
2004-08-07 14:30:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2010-01-11 21:45:02 +00:00
|
|
|
if (!passToParent && frameToScroll) {
|
2011-05-23 14:56:59 +00:00
|
|
|
if (aScrollQuantity == nsIScrollableFrame::LINES) {
|
|
|
|
// When this is called for querying the scroll target information,
|
|
|
|
// we shouldn't limit the scrolling amount to less one page.
|
|
|
|
// Otherwise, we shouldn't scroll more one page at once.
|
|
|
|
numLines =
|
|
|
|
nsMouseWheelTransaction::AccelerateWheelDelta(numLines, isHorizontal,
|
|
|
|
aAllowScrollSpeedOverride,
|
|
|
|
&aScrollQuantity,
|
|
|
|
!aQueryEvent);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(!aAllowScrollSpeedOverride,
|
|
|
|
"aAllowScrollSpeedOverride is true but the quantity isn't by-line scrolling.");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aScrollQuantity == nsIScrollableFrame::PAGES) {
|
|
|
|
numLines = (numLines > 0) ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2011-05-17 00:23:23 +00:00
|
|
|
if (aQueryEvent) {
|
2011-05-18 23:12:34 +00:00
|
|
|
// If acceleration is enabled, pixel scroll shouldn't be used for
|
|
|
|
// high resolution scrolling.
|
|
|
|
if (nsMouseWheelTransaction::IsAccelerationEnabled()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-17 00:23:23 +00:00
|
|
|
nscoord appUnitsPerDevPixel =
|
|
|
|
aTargetFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
aQueryEvent->mReply.mLineHeight =
|
|
|
|
frameToScroll->GetLineScrollAmount().height / appUnitsPerDevPixel;
|
|
|
|
aQueryEvent->mReply.mPageHeight =
|
|
|
|
frameToScroll->GetPageScrollAmount().height / appUnitsPerDevPixel;
|
|
|
|
aQueryEvent->mReply.mPageWidth =
|
|
|
|
frameToScroll->GetPageScrollAmount().width / appUnitsPerDevPixel;
|
2011-05-23 14:56:59 +00:00
|
|
|
|
|
|
|
// Returns computed numLines to widget which is needed to compute the
|
|
|
|
// pixel scrolling amout for high resolution scrolling.
|
|
|
|
aQueryEvent->mReply.mComputedScrollAmount = numLines;
|
|
|
|
|
2011-05-17 00:23:23 +00:00
|
|
|
aQueryEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-07 14:30:30 +00:00
|
|
|
PRInt32 scrollX = 0;
|
2009-05-20 02:05:59 +00:00
|
|
|
PRInt32 scrollY = numLines;
|
2004-08-07 14:30:30 +00:00
|
|
|
|
2009-05-20 02:05:59 +00:00
|
|
|
if (isHorizontal) {
|
2004-08-07 14:30:30 +00:00
|
|
|
scrollX = scrollY;
|
|
|
|
scrollY = 0;
|
2003-04-15 13:17:36 +00:00
|
|
|
}
|
2011-05-23 14:56:59 +00:00
|
|
|
|
2011-02-04 08:00:06 +00:00
|
|
|
nsIScrollableFrame::ScrollMode mode;
|
|
|
|
if (aMouseEvent->scrollFlags & nsMouseScrollEvent::kNoDefer) {
|
|
|
|
mode = nsIScrollableFrame::INSTANT;
|
2011-05-17 00:23:23 +00:00
|
|
|
} else if (aScrollQuantity != nsIScrollableFrame::DEVICE_PIXELS ||
|
|
|
|
(aMouseEvent->scrollFlags &
|
|
|
|
nsMouseScrollEvent::kAllowSmoothScroll) != 0) {
|
2011-02-04 08:00:06 +00:00
|
|
|
mode = nsIScrollableFrame::SMOOTH;
|
|
|
|
} else {
|
|
|
|
mode = nsIScrollableFrame::NORMAL;
|
|
|
|
}
|
|
|
|
|
2011-05-23 14:56:59 +00:00
|
|
|
// XXX Why don't we limit the pixel scroll amount to less one page??
|
|
|
|
|
2010-01-11 21:45:02 +00:00
|
|
|
nsIntPoint overflow;
|
|
|
|
frameToScroll->ScrollBy(nsIntPoint(scrollX, scrollY), aScrollQuantity,
|
2011-02-04 08:00:06 +00:00
|
|
|
mode, &overflow);
|
2010-01-11 21:45:02 +00:00
|
|
|
aMouseEvent->scrollOverflow = isHorizontal ? overflow.x : overflow.y;
|
2009-05-20 02:05:59 +00:00
|
|
|
return NS_OK;
|
2004-08-07 14:30:30 +00:00
|
|
|
}
|
2009-05-20 02:05:59 +00:00
|
|
|
|
2001-09-07 21:00:57 +00:00
|
|
|
if (passToParent) {
|
2010-01-11 21:45:02 +00:00
|
|
|
nsIFrame* newFrame = nsLayoutUtils::GetCrossDocParentFrame(
|
|
|
|
aTargetFrame->PresContext()->FrameManager()->GetRootFrame());
|
|
|
|
if (newFrame)
|
|
|
|
return DoScrollText(newFrame, aMouseEvent, aScrollQuantity,
|
2011-05-17 00:23:23 +00:00
|
|
|
aAllowScrollSpeedOverride, aQueryEvent);
|
2000-12-09 07:28:19 +00:00
|
|
|
}
|
|
|
|
|
2009-05-20 02:05:59 +00:00
|
|
|
aMouseEvent->scrollOverflow = numLines;
|
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-08-13 20:54:09 +00: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;
|
|
|
|
PRBool displayPanFeedback = PR_FALSE;
|
|
|
|
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)) {
|
2010-01-11 21:45:04 +00:00
|
|
|
displayPanFeedback = PR_TRUE;
|
2009-08-13 20:54:09 +00:00
|
|
|
|
2010-01-11 21:45:04 +00:00
|
|
|
nsRect scrollRange = scrollableFrame->GetScrollRange();
|
|
|
|
PRBool canScrollHorizontally = scrollRange.width > 0;
|
2009-08-13 20:54:09 +00:00
|
|
|
|
2010-01-11 21:45:04 +00:00
|
|
|
if (targetFrame->GetType() == nsGkAtoms::menuFrame) {
|
|
|
|
// menu frames report horizontal scroll when they have submenus
|
|
|
|
// and we don't want that
|
|
|
|
canScrollHorizontally = PR_FALSE;
|
|
|
|
displayPanFeedback = PR_FALSE;
|
|
|
|
}
|
2009-08-13 20:54:09 +00:00
|
|
|
|
2010-01-11 21:45:04 +00: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 20:54:09 +00:00
|
|
|
}
|
|
|
|
|
2010-01-11 21:45:04 +00:00
|
|
|
if (canScrollHorizontally) {
|
|
|
|
panDirection = nsGestureNotifyEvent::ePanHorizontal;
|
|
|
|
displayPanFeedback = PR_FALSE;
|
|
|
|
}
|
2009-08-13 20:54:09 +00:00
|
|
|
} else { //Not a XUL box
|
2010-01-14 13:00:00 +00:00
|
|
|
PRUint32 scrollbarVisibility = scrollableFrame->GetScrollbarVisibility();
|
2009-08-13 20:54:09 +00:00
|
|
|
|
|
|
|
//Check if we have visible scrollbars
|
2010-01-14 13:00:00 +00:00
|
|
|
if (scrollbarVisibility & nsIScrollableFrame::VERTICAL) {
|
2009-08-13 20:54:09 +00:00
|
|
|
panDirection = nsGestureNotifyEvent::ePanVertical;
|
|
|
|
displayPanFeedback = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-14 13:00:00 +00:00
|
|
|
if (scrollbarVisibility & nsIScrollableFrame::HORIZONTAL) {
|
2009-08-13 20:54:09 +00:00
|
|
|
panDirection = nsGestureNotifyEvent::ePanHorizontal;
|
|
|
|
displayPanFeedback = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} //scrollableFrame
|
|
|
|
} //ancestor chain
|
|
|
|
|
|
|
|
aEvent->displayPanFeedback = displayPanFeedback;
|
|
|
|
aEvent->panDirection = panDirection;
|
|
|
|
}
|
|
|
|
|
2010-11-24 09:49:02 +00:00
|
|
|
#ifdef XP_MACOSX
|
2010-07-16 12:50:28 +00:00
|
|
|
static bool
|
|
|
|
NodeAllowsClickThrough(nsINode* aNode)
|
|
|
|
{
|
|
|
|
while (aNode) {
|
|
|
|
if (aNode->IsElement() && aNode->AsElement()->IsXUL()) {
|
|
|
|
mozilla::dom::Element* element = aNode->AsElement();
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
|
|
|
{&nsGkAtoms::always, &nsGkAtoms::never, nsnull};
|
|
|
|
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 09:49:02 +00:00
|
|
|
#endif
|
2010-07-16 12:50:28 +00:00
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::PostHandleEvent(nsPresContext* aPresContext,
|
2000-04-24 04:41:27 +00:00
|
|
|
nsEvent *aEvent,
|
1999-09-16 14:54:59 +00:00
|
|
|
nsIFrame* aTargetFrame,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aStatus,
|
1999-09-16 14:54:59 +00:00
|
|
|
nsIView* aView)
|
1998-11-24 07:46:58 +00:00
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
NS_ENSURE_ARG(aPresContext);
|
|
|
|
NS_ENSURE_ARG_POINTER(aStatus);
|
2007-03-24 09:45:01 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
mCurrentTarget = aTargetFrame;
|
2002-12-17 02:10:57 +00:00
|
|
|
mCurrentTargetContent = nsnull;
|
2007-03-24 09:45:01 +00:00
|
|
|
|
2007-11-20 22:30:27 +00:00
|
|
|
// Most of the events we handle below require a frame.
|
|
|
|
// Add special cases here.
|
2010-10-09 19:09:22 +00:00
|
|
|
if (!mCurrentTarget && aEvent->message != NS_MOUSE_BUTTON_UP &&
|
|
|
|
aEvent->message != NS_MOUSE_BUTTON_DOWN) {
|
2007-03-24 09:45:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-12 03:49:38 +00:00
|
|
|
//Keep the prescontext alive, we might need it after event dispatch
|
|
|
|
nsRefPtr<nsPresContext> presContext = aPresContext;
|
2007-03-24 09:45:01 +00:00
|
|
|
nsresult ret = NS_OK;
|
2000-05-05 14:43:20 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
switch (aEvent->message) {
|
2006-11-16 21:35:39 +00:00
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
1999-01-28 23:14:36 +00:00
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
if (static_cast<nsMouseEvent*>(aEvent)->button == nsMouseEvent::eLeftButton &&
|
2010-09-08 17:41:37 +00:00
|
|
|
!sNormalLMouseEventInProcess) {
|
2009-09-13 13:13:16 +00:00
|
|
|
// We got a mouseup event while a mousedown event was being processed.
|
|
|
|
// Make sure that the capturing content is cleared.
|
|
|
|
nsIPresShell::SetCapturingContent(nsnull, 0);
|
2002-02-20 07:22:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2010-10-15 16:41:02 +00:00
|
|
|
nsCOMPtr<nsIContent> activeContent;
|
1999-11-24 06:03:41 +00:00
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
2010-10-15 16:41:02 +00:00
|
|
|
nsCOMPtr<nsIContent> newFocus;
|
2000-04-04 23:55:31 +00:00
|
|
|
PRBool suppressBlur = PR_FALSE;
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
mCurrentTarget->GetContentForEvent(mPresContext, aEvent, getter_AddRefs(newFocus));
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleUserInterface* ui = mCurrentTarget->GetStyleUserInterface();
|
2000-04-04 23:55:31 +00:00
|
|
|
suppressBlur = (ui->mUserFocus == NS_STYLE_USER_FOCUS_IGNORE);
|
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 18:00:39 +00:00
|
|
|
activeContent = mCurrentTarget->GetContent();
|
2000-04-04 23:55:31 +00:00
|
|
|
}
|
1999-08-24 00:42:38 +00:00
|
|
|
|
2010-04-21 13:13:08 +00: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 13:12:05 +00:00
|
|
|
if (doc && newFocus == doc->GetRootElement()) {
|
2010-04-21 13:13:08 +00: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 18:00:39 +00:00
|
|
|
// When the mouse is pressed, the default action is to focus the
|
|
|
|
// target. Look for the nearest enclosing focusable frame.
|
2000-04-04 23:55:31 +00:00
|
|
|
while (currFrame) {
|
2003-03-12 04:19:53 +00:00
|
|
|
// If the mousedown happened inside a popup, don't
|
|
|
|
// try to set focus on one of its containing elements
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleDisplay* display = currFrame->GetStyleDisplay();
|
2003-03-12 04:19:53 +00:00
|
|
|
if (display->mDisplay == NS_STYLE_DISPLAY_POPUP) {
|
|
|
|
newFocus = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-10-19 02:24:27 +00:00
|
|
|
PRInt32 tabIndexUnused;
|
|
|
|
if (currFrame->IsFocusable(&tabIndexUnused, PR_TRUE)) {
|
2003-08-06 03:07:12 +00:00
|
|
|
newFocus = currFrame->GetContent();
|
2000-05-11 04:25:43 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(newFocus));
|
|
|
|
if (domElement)
|
|
|
|
break;
|
1999-08-24 00:42:38 +00:00
|
|
|
}
|
2003-08-06 03:07:12 +00:00
|
|
|
currFrame = currFrame->GetParent();
|
2000-04-04 23:55:31 +00:00
|
|
|
}
|
1999-09-30 11:40:42 +00: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 18:00:39 +00: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 14:53:42 +00: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 18:00:39 +00:00
|
|
|
fm->SetFocusedWindow(mDocument->GetWindow());
|
|
|
|
}
|
|
|
|
}
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
1999-09-30 11:40:42 +00:00
|
|
|
|
2001-06-20 05:46:38 +00:00
|
|
|
// The rest is left button-specific.
|
2007-07-08 07:08:04 +00:00
|
|
|
if (static_cast<nsMouseEvent*>(aEvent)->button !=
|
2006-11-16 21:35:39 +00:00
|
|
|
nsMouseEvent::eLeftButton)
|
2001-06-20 05:46:38 +00:00
|
|
|
break;
|
|
|
|
|
2000-09-19 07:25:45 +00:00
|
|
|
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) {
|
2003-07-28 21:17:26 +00:00
|
|
|
nsIContent* par = activeContent->GetParent();
|
2001-06-20 05:46:38 +00:00
|
|
|
if (par)
|
|
|
|
activeContent = par;
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
2000-09-19 07:25:45 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
2000-09-13 01:45:23 +00:00
|
|
|
else {
|
|
|
|
// if we're here, the event handler returned false, so stop
|
|
|
|
// any of our own processing of a drag. Workaround for bug 43258.
|
2004-07-23 07:27:57 +00:00
|
|
|
StopTrackingDragGesture();
|
2011-01-24 14:50:37 +00: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));
|
|
|
|
if (currentWindow && currentWindow != mDocument->GetWindow() &&
|
|
|
|
!nsContentUtils::IsChromeDoc(mDocument)) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(currentWindow);
|
|
|
|
nsCOMPtr<nsIDocument> currentDoc = do_QueryInterface(win->GetExtantDocument());
|
|
|
|
if (nsContentUtils::IsChromeDoc(currentDoc)) {
|
|
|
|
fm->SetFocusedWindow(mDocument->GetWindow());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-13 01:45:23 +00:00
|
|
|
}
|
2010-10-28 14:11:15 +00:00
|
|
|
SetActiveManager(this, activeContent);
|
1999-01-08 21:13:59 +00:00
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
break;
|
2006-11-16 21:35:39 +00:00
|
|
|
case NS_MOUSE_BUTTON_UP:
|
1999-05-07 21:12:59 +00:00
|
|
|
{
|
2010-10-28 14:11:15 +00:00
|
|
|
ClearGlobalActiveContent(this);
|
2010-03-24 03:36:27 +00:00
|
|
|
if (IsMouseEventReal(aEvent)) {
|
|
|
|
if (!mCurrentTarget) {
|
2011-04-21 17:35:52 +00:00
|
|
|
GetEventTarget();
|
2010-03-24 03:36:27 +00:00
|
|
|
}
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
ret = CheckForAndDispatchClick(presContext, (nsMouseEvent*)aEvent,
|
|
|
|
aStatus);
|
|
|
|
}
|
2007-11-20 22:30:27 +00:00
|
|
|
}
|
2009-09-13 13:13:16 +00:00
|
|
|
|
2006-05-12 03:49:38 +00:00
|
|
|
nsIPresShell *shell = presContext->GetPresShell();
|
2003-12-21 05:36:36 +00:00
|
|
|
if (shell) {
|
2011-05-19 03:10:49 +00:00
|
|
|
nsRefPtr<nsFrameSelection> frameSelection = shell->FrameSelection();
|
2007-11-22 20:47:33 +00:00
|
|
|
frameSelection->SetMouseDownState(PR_FALSE);
|
1999-05-07 21:12:59 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-24 07:46:58 +00:00
|
|
|
break;
|
1999-11-21 01:46:41 +00:00
|
|
|
case NS_MOUSE_SCROLL:
|
2008-09-17 11:27:19 +00:00
|
|
|
case NS_MOUSE_PIXEL_SCROLL:
|
|
|
|
{
|
|
|
|
nsMouseScrollEvent *msEvent = static_cast<nsMouseScrollEvent*>(aEvent);
|
|
|
|
|
|
|
|
if (aEvent->message == NS_MOUSE_SCROLL) {
|
|
|
|
// Mark the subsequent pixel scrolls as valid / invalid, based on the
|
|
|
|
// observation if the previous line scroll has been canceled
|
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal) {
|
|
|
|
mLastLineScrollConsumedX = (nsEventStatus_eConsumeNoDefault == *aStatus);
|
|
|
|
} else if (msEvent->scrollFlags & nsMouseScrollEvent::kIsVertical) {
|
|
|
|
mLastLineScrollConsumedY = (nsEventStatus_eConsumeNoDefault == *aStatus);
|
|
|
|
}
|
|
|
|
if (!(msEvent->scrollFlags & nsMouseScrollEvent::kHasPixels)) {
|
|
|
|
// No generated pixel scroll event will follow.
|
|
|
|
// Create and send a pixel scroll DOM event now.
|
2008-12-03 10:33:31 +00:00
|
|
|
nsWeakFrame weakFrame(aTargetFrame);
|
2008-09-17 11:27:19 +00:00
|
|
|
SendPixelScrollEvent(aTargetFrame, msEvent, presContext, aStatus);
|
2008-12-03 10:33:31 +00:00
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
2008-09-17 11:27:19 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-19 15:48:14 +00:00
|
|
|
|
2008-09-17 11:27:19 +00:00
|
|
|
if (*aStatus != nsEventStatus_eConsumeNoDefault) {
|
2011-05-22 05:39:16 +00:00
|
|
|
PRBool useSysNumLines = UseSystemScrollSettingFor(msEvent);
|
|
|
|
PRInt32 action = ComputeWheelActionFor(msEvent, useSysNumLines);
|
2000-04-01 20:09:54 +00:00
|
|
|
|
2008-09-17 11:27:19 +00:00
|
|
|
switch (action) {
|
|
|
|
case MOUSE_SCROLL_N_LINES:
|
2010-01-11 21:45:02 +00:00
|
|
|
DoScrollText(aTargetFrame, msEvent, nsIScrollableFrame::LINES,
|
2009-09-24 10:58:04 +00:00
|
|
|
useSysNumLines);
|
2008-09-17 11:27:19 +00:00
|
|
|
break;
|
2000-01-16 05:30:49 +00:00
|
|
|
|
2008-09-17 11:27:19 +00:00
|
|
|
case MOUSE_SCROLL_PAGE:
|
2010-01-11 21:45:02 +00:00
|
|
|
DoScrollText(aTargetFrame, msEvent, nsIScrollableFrame::PAGES,
|
2009-09-24 10:58:04 +00:00
|
|
|
PR_FALSE);
|
2008-09-17 11:27:19 +00:00
|
|
|
break;
|
2000-02-17 23:52:45 +00:00
|
|
|
|
2008-09-17 11:27:19 +00:00
|
|
|
case MOUSE_SCROLL_PIXELS:
|
2010-01-11 21:45:02 +00:00
|
|
|
DoScrollText(aTargetFrame, msEvent, nsIScrollableFrame::DEVICE_PIXELS,
|
2009-09-24 10:58:04 +00:00
|
|
|
PR_FALSE);
|
2008-09-17 11:27:19 +00:00
|
|
|
break;
|
2004-04-19 15:48:14 +00:00
|
|
|
|
2008-09-17 11:27:19 +00:00
|
|
|
case MOUSE_SCROLL_HISTORY:
|
2009-05-20 02:05:59 +00:00
|
|
|
DoScrollHistory(msEvent->delta);
|
2008-09-17 11:27:19 +00:00
|
|
|
break;
|
2000-02-17 23:52:45 +00:00
|
|
|
|
2008-09-17 11:27:19 +00:00
|
|
|
case MOUSE_SCROLL_ZOOM:
|
2009-05-20 02:05:59 +00:00
|
|
|
DoScrollZoom(aTargetFrame, msEvent->delta);
|
2008-09-17 11:27:19 +00:00
|
|
|
break;
|
1999-12-28 23:02:38 +00:00
|
|
|
|
2008-09-17 11:27:19 +00:00
|
|
|
default: // Including -1 (do nothing)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
2000-01-06 06:22:00 +00:00
|
|
|
break;
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2009-08-13 20:54:09 +00:00
|
|
|
case NS_GESTURENOTIFY_EVENT_START:
|
|
|
|
{
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus)
|
|
|
|
DecideGestureEvent(static_cast<nsGestureNotifyEvent*>(aEvent), mCurrentTarget);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-08-27 12:07:27 +00: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 11:11:02 +00:00
|
|
|
// Reset the flag.
|
|
|
|
dragSession->SetOnlyChromeDrop(PR_FALSE);
|
|
|
|
if (mPresContext) {
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
}
|
|
|
|
PRBool isChromeDoc = nsContentUtils::IsChromeDoc(mDocument);
|
|
|
|
|
2008-08-27 12:07:27 +00:00
|
|
|
// the initial dataTransfer is the one from the dragstart event that
|
|
|
|
// was set on the dragSession when the drag began.
|
|
|
|
nsCOMPtr<nsIDOMNSDataTransfer> dataTransfer;
|
|
|
|
nsCOMPtr<nsIDOMDataTransfer> initialDataTransfer;
|
|
|
|
dragSession->GetDataTransfer(getter_AddRefs(initialDataTransfer));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNSDataTransfer> initialDataTransferNS =
|
|
|
|
do_QueryInterface(initialDataTransfer);
|
|
|
|
|
2009-10-07 02:51:02 +00:00
|
|
|
nsDragEvent *dragEvent = (nsDragEvent*)aEvent;
|
|
|
|
|
|
|
|
// collect any changes to moz cursor settings stored in the event's
|
|
|
|
// data transfer.
|
|
|
|
UpdateDragDataTransfer(dragEvent);
|
|
|
|
|
2008-08-27 12:07:27 +00: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.
|
|
|
|
PRUint32 dropEffect = nsIDragService::DRAGDROP_ACTION_NONE;
|
|
|
|
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.
|
|
|
|
dataTransfer = initialDataTransferNS;
|
|
|
|
|
|
|
|
PRUint32 action;
|
|
|
|
dragSession->GetDragAction(&action);
|
|
|
|
|
|
|
|
// filter the drop effect based on the action. Use UNINITIALIZED as
|
|
|
|
// any effect is allowed.
|
2009-06-24 17:12:33 +00:00
|
|
|
dropEffect = nsContentUtils::FilterDropEffect(action,
|
2008-08-27 12:07:27 +00: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.
|
|
|
|
PRUint32 effectAllowed = nsIDragService::DRAGDROP_ACTION_UNINITIALIZED;
|
|
|
|
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.
|
|
|
|
PRUint32 action = nsIDragService::DRAGDROP_ACTION_NONE;
|
|
|
|
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 11:11:02 +00: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(
|
|
|
|
!(aEvent->flags & NS_EVENT_FLAG_NO_DEFAULT_CALLED_IN_CONTENT));
|
|
|
|
}
|
|
|
|
} else if (aEvent->message == NS_DRAGDROP_OVER && !isChromeDoc) {
|
2009-11-05 14:39:18 +00:00
|
|
|
// No one called preventDefault(), so handle drop only in chrome.
|
|
|
|
dragSession->SetOnlyChromeDrop(PR_TRUE);
|
2008-08-27 12:07:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now set the drop effect in the initial dataTransfer. This ensures
|
|
|
|
// that we can get the desired drop effect in the drop event.
|
|
|
|
if (initialDataTransferNS)
|
|
|
|
initialDataTransferNS->SetDropEffectInt(dropEffect);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-11-12 01:02:14 +00:00
|
|
|
case NS_DRAGDROP_DROP:
|
2008-08-27 12:07:27 +00:00
|
|
|
{
|
|
|
|
// now fire the dragdrop event, for compatibility with XUL
|
|
|
|
if (mCurrentTarget && nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
|
|
|
mCurrentTarget->GetContentForEvent(presContext, aEvent,
|
|
|
|
getter_AddRefs(targetContent));
|
|
|
|
|
2010-07-02 19:11:04 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = mCurrentTarget->GetNearestWidget();
|
2008-08-27 12:07:27 +00:00
|
|
|
nsDragEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_DRAGDROP, widget);
|
|
|
|
|
|
|
|
nsMouseEvent* mouseEvent = static_cast<nsMouseEvent*>(aEvent);
|
|
|
|
event.refPoint = mouseEvent->refPoint;
|
2010-06-25 21:51:17 +00:00
|
|
|
if (mouseEvent->widget) {
|
|
|
|
event.refPoint += mouseEvent->widget->WidgetToScreenOffset();
|
|
|
|
}
|
|
|
|
event.refPoint -= widget->WidgetToScreenOffset();
|
2008-08-27 12:07:27 +00:00
|
|
|
event.isShift = mouseEvent->isShift;
|
|
|
|
event.isControl = mouseEvent->isControl;
|
|
|
|
event.isAlt = mouseEvent->isAlt;
|
|
|
|
event.isMeta = mouseEvent->isMeta;
|
2010-04-06 12:59:24 +00:00
|
|
|
event.inputSource = mouseEvent->inputSource;
|
2008-08-27 12:07:27 +00:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
presShell->HandleEventWithTarget(&event, mCurrentTarget,
|
|
|
|
targetContent, &status);
|
|
|
|
}
|
|
|
|
}
|
2010-10-28 14:11:15 +00:00
|
|
|
ClearGlobalActiveContent(this);
|
2008-08-27 12:07:27 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-11-12 01:02:14 +00:00
|
|
|
case NS_DRAGDROP_EXIT:
|
2008-08-27 12:07:27 +00:00
|
|
|
// make sure to fire the enter and exit_synth events after the
|
|
|
|
// NS_DRAGDROP_EXIT event, otherwise we'll clean up too early
|
2006-05-12 03:49:38 +00:00
|
|
|
GenerateDragDropEnterExit(presContext, (nsGUIEvent*)aEvent);
|
1999-11-12 01:02:14 +00:00
|
|
|
break;
|
2001-02-15 05:07:46 +00:00
|
|
|
|
|
|
|
case NS_KEY_UP:
|
|
|
|
break;
|
|
|
|
|
landing keyEvent_19991004_BRANCH
bugs # see the log of the check in into branch
author/reviewer:
mozilla/layout/base/src/nsRangeList.cpp brade/mjudge
mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp brade/ftang
mozilla/layout/events/src/nsDOMEvent.cpp brade/joki
mozilla/layout/events/src/nsEventStateManager.cpp brade/joki
mozilla/widget/public/nsGUIEvent.h akkana/ftang
mozilla/widget/src/windows/nsWindow.cpp ftang/mjudge
mozilla/widget/src/windows/nsWindow.h ftang/mjudge
mozilla/widget/src/mac/nsTextAreaWidget.cpp brade/ftang
mozilla/widget/src/mac/nsMacEventHandler.cpp brade/simon
mozilla/widget/src/xpwidgets/nsKeyBindMgr.cpp brade/ftang
mozilla/widget/src/gtk/nsGtkEventHandler.cpp akkana/?
mozilla/widget/src/gtk/nsWidget.cpp erik/ftang
mozilla/layout/xul/base/src/nsTreeCellFrame.cpp brade/ftang
mozilla/editor/base/nsEditorEventListeners.cpp brade/akkana
mozilla/editor/base/nsHTMLEditor.cpp brade/akkana
mozilla/rdf/content/src/nsXULKeyListener.cpp ftang/saari
fix the master bug- 15693
fix at least, but not limited to, the following bugs
10158,11956,6053,9333,10901,14348,6449,11845,13016,14410,15657,15307,15842,13856
1999-10-14 18:27:01 +00:00
|
|
|
case NS_KEY_PRESS:
|
1999-11-24 06:03:41 +00:00
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
1999-11-22 19:45:13 +00:00
|
|
|
nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent;
|
|
|
|
//This is to prevent keyboard scrolling while alt modifier in use.
|
|
|
|
if (!keyEvent->isAlt) {
|
|
|
|
switch(keyEvent->keyCode) {
|
|
|
|
case NS_VK_TAB:
|
2001-05-22 23:52:17 +00:00
|
|
|
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 18:00:39 +00:00
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm && mDocument) {
|
|
|
|
// Shift focus forward or back depending on shift key
|
|
|
|
PRBool isDocMove = ((nsInputEvent*)aEvent)->isControl ||
|
|
|
|
(keyEvent->keyCode == NS_VK_F6);
|
2011-04-14 12:04:12 +00:00
|
|
|
PRUint32 dir =
|
|
|
|
static_cast<nsInputEvent*>(aEvent)->isShift ?
|
|
|
|
(isDocMove ? static_cast<PRUint32>(nsIFocusManager::MOVEFOCUS_BACKWARDDOC) :
|
|
|
|
static_cast<PRUint32>(nsIFocusManager::MOVEFOCUS_BACKWARD)) :
|
|
|
|
(isDocMove ? static_cast<PRUint32>(nsIFocusManager::MOVEFOCUS_FORWARDDOC) :
|
|
|
|
static_cast<PRUint32>(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 18:00:39 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> result;
|
|
|
|
fm->MoveFocus(mDocument->GetWindow(), nsnull, dir,
|
|
|
|
nsIFocusManager::FLAG_BYKEY,
|
|
|
|
getter_AddRefs(result));
|
|
|
|
}
|
1999-11-24 06:03:41 +00:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
1999-11-22 19:45:13 +00:00
|
|
|
break;
|
1999-07-06 22:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-06 23:25:20 +00:00
|
|
|
break;
|
|
|
|
|
2001-01-06 05:58:47 +00:00
|
|
|
case NS_MOUSE_ENTER:
|
|
|
|
if (mCurrentTarget) {
|
2002-12-06 03:41:43 +00:00
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
2006-05-12 03:49:38 +00:00
|
|
|
mCurrentTarget->GetContentForEvent(presContext, aEvent,
|
2001-01-06 05:58:47 +00:00
|
|
|
getter_AddRefs(targetContent));
|
|
|
|
SetContentState(targetContent, NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
|
|
|
break;
|
2010-07-16 12:50:28 +00:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case NS_MOUSE_ACTIVATE:
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
|
|
|
mCurrentTarget->GetContentForEvent(presContext, aEvent,
|
|
|
|
getter_AddRefs(targetContent));
|
|
|
|
if (!NodeAllowsClickThrough(targetContent)) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
|
2001-12-23 23:23:41 +00:00
|
|
|
//Reset target frame to null to avoid mistargeting after reentrant event
|
1999-11-08 21:30:22 +00:00
|
|
|
mCurrentTarget = nsnull;
|
2010-08-27 23:15:08 +00:00
|
|
|
mCurrentTargetContent = nsnull;
|
1999-11-08 21:30:22 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-24 03:28:15 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::RemoteQueryContentEvent(nsEvent *aEvent)
|
|
|
|
{
|
|
|
|
nsQueryContentEvent *queryEvent =
|
|
|
|
static_cast<nsQueryContentEvent*>(aEvent);
|
|
|
|
if (!IsTargetCrossProcess(queryEvent)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
// Will not be handled locally, remote the event
|
|
|
|
GetCrossProcessTarget()->HandleQueryContentEvent(*queryEvent);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TabParent*
|
2010-08-17 08:07:44 +00:00
|
|
|
nsEventStateManager::GetCrossProcessTarget()
|
|
|
|
{
|
2010-09-24 03:28:15 +00:00
|
|
|
return TabParent::GetIMETabParent();
|
2010-08-17 08:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsEventStateManager::IsTargetCrossProcess(nsGUIEvent *aEvent)
|
|
|
|
{
|
2010-09-27 21:46:51 +00: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())
|
|
|
|
return PR_FALSE;
|
2010-09-24 03:28:15 +00:00
|
|
|
return TabParent::GetIMETabParent() != nsnull;
|
2010-08-17 08:07:44 +00:00
|
|
|
}
|
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
void
|
2006-04-11 16:37:58 +00:00
|
|
|
nsEventStateManager::NotifyDestroyPresContext(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsIMEStateManager::OnDestroyPresContext(aPresContext);
|
|
|
|
}
|
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::SetPresContext(nsPresContext* aPresContext)
|
1998-06-23 21:53:02 +00:00
|
|
|
{
|
1998-11-18 05:25:26 +00:00
|
|
|
mPresContext = aPresContext;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
void
|
1998-11-19 00:43:36 +00:00
|
|
|
nsEventStateManager::ClearFrameRefs(nsIFrame* aFrame)
|
|
|
|
{
|
2006-07-14 07:55:51 +00:00
|
|
|
if (aFrame && aFrame == mCurrentTarget) {
|
|
|
|
mCurrentTargetContent = aFrame->GetContent();
|
1998-11-19 00:43:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::UpdateCursor(nsPresContext* aPresContext,
|
2004-07-23 07:27:57 +00:00
|
|
|
nsEvent* aEvent, nsIFrame* aTargetFrame,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aStatus)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
2005-02-04 00:14:06 +00:00
|
|
|
PRInt32 cursor = NS_STYLE_CURSOR_DEFAULT;
|
2004-12-30 21:56:11 +00:00
|
|
|
imgIContainer* container = nsnull;
|
2005-07-01 04:29:42 +00:00
|
|
|
PRBool haveHotspot = PR_FALSE;
|
|
|
|
float hotspotX = 0.0f, hotspotY = 0.0f;
|
1999-12-04 02:22:21 +00:00
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
//If cursor is locked just use the locked one
|
|
|
|
if (mLockCursor) {
|
|
|
|
cursor = mLockCursor;
|
1999-12-04 02:22:21 +00:00
|
|
|
}
|
2000-04-24 04:41:27 +00:00
|
|
|
//If not locked, look for correct cursor
|
2005-04-04 10:35:50 +00:00
|
|
|
else if (aTargetFrame) {
|
|
|
|
nsIFrame::Cursor framecursor;
|
2005-08-23 03:57:07 +00:00
|
|
|
nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent,
|
|
|
|
aTargetFrame);
|
|
|
|
if (NS_FAILED(aTargetFrame->GetCursor(pt, framecursor)))
|
2005-04-04 10:35:50 +00:00
|
|
|
return; // don't update the cursor if we failed to get it from the frame see bug 118877
|
|
|
|
cursor = framecursor.mCursor;
|
|
|
|
container = framecursor.mContainer;
|
2005-07-01 04:29:42 +00:00
|
|
|
haveHotspot = framecursor.mHaveHotspot;
|
|
|
|
hotspotX = framecursor.mHotspotX;
|
|
|
|
hotspotY = framecursor.mHotspotY;
|
1999-12-04 02:22:21 +00:00
|
|
|
}
|
2000-04-24 04:41:27 +00:00
|
|
|
|
2011-05-25 06:31:59 +00:00
|
|
|
if (Preferences::GetBool("ui.use_activity_cursor", PR_FALSE)) {
|
2009-09-17 13:04:08 +00:00
|
|
|
// Check whether or not to show the busy cursor
|
|
|
|
nsCOMPtr<nsISupports> pcContainer = aPresContext->GetContainer();
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(pcContainer));
|
|
|
|
if (!docShell) return;
|
|
|
|
PRUint32 busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
|
|
|
|
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;
|
|
|
|
container = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
if (aTargetFrame) {
|
2005-07-01 04:29:42 +00:00
|
|
|
SetCursor(cursor, container, haveHotspot, hotspotX, hotspotY,
|
2010-07-02 19:11:04 +00:00
|
|
|
aTargetFrame->GetNearestWidget(), PR_FALSE);
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mLockCursor || NS_STYLE_CURSOR_AUTO != cursor) {
|
|
|
|
*aStatus = nsEventStatus_eConsumeDoDefault;
|
1999-12-04 02:22:21 +00:00
|
|
|
}
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
nsresult
|
2004-12-30 21:56:11 +00:00
|
|
|
nsEventStateManager::SetCursor(PRInt32 aCursor, imgIContainer* aContainer,
|
2005-07-01 04:29:42 +00:00
|
|
|
PRBool aHaveHotspot,
|
|
|
|
float aHotspotX, float aHotspotY,
|
2004-12-30 21:56:11 +00:00
|
|
|
nsIWidget* aWidget, PRBool aLockCursor)
|
2000-04-24 04:41:27 +00:00
|
|
|
{
|
2010-09-17 18:56:53 +00:00
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
|
|
|
|
sMouseOverDocument = mDocument.get();
|
|
|
|
|
2000-04-24 04:41:27 +00: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) {
|
1998-11-18 05:25:26 +00:00
|
|
|
default:
|
|
|
|
case NS_STYLE_CURSOR_AUTO:
|
|
|
|
case NS_STYLE_CURSOR_DEFAULT:
|
|
|
|
c = eCursor_standard;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_POINTER:
|
|
|
|
c = eCursor_hyperlink;
|
|
|
|
break;
|
1999-07-07 07:50:03 +00:00
|
|
|
case NS_STYLE_CURSOR_CROSSHAIR:
|
|
|
|
c = eCursor_crosshair;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_MOVE:
|
|
|
|
c = eCursor_move;
|
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_TEXT:
|
|
|
|
c = eCursor_select;
|
|
|
|
break;
|
1999-07-07 07:50:03 +00:00
|
|
|
case NS_STYLE_CURSOR_WAIT:
|
|
|
|
c = eCursor_wait;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_HELP:
|
|
|
|
c = eCursor_help;
|
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_N_RESIZE:
|
2004-09-11 23:24:30 +00:00
|
|
|
c = eCursor_n_resize;
|
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_S_RESIZE:
|
2004-09-11 23:24:30 +00:00
|
|
|
c = eCursor_s_resize;
|
1998-11-18 05:25:26 +00:00
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_W_RESIZE:
|
2004-09-11 23:24:30 +00:00
|
|
|
c = eCursor_w_resize;
|
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_E_RESIZE:
|
2004-09-11 23:24:30 +00:00
|
|
|
c = eCursor_e_resize;
|
1998-11-18 05:25:26 +00:00
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NW_RESIZE:
|
2004-09-11 23:24:30 +00:00
|
|
|
c = eCursor_nw_resize;
|
2000-04-30 15:29:32 +00:00
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_SE_RESIZE:
|
2004-09-11 23:24:30 +00:00
|
|
|
c = eCursor_se_resize;
|
2000-04-30 15:29:32 +00:00
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NE_RESIZE:
|
2004-09-11 23:24:30 +00:00
|
|
|
c = eCursor_ne_resize;
|
2000-04-30 15:29:32 +00:00
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_SW_RESIZE:
|
2004-09-11 23:24:30 +00:00
|
|
|
c = eCursor_sw_resize;
|
1998-11-18 05:25:26 +00:00
|
|
|
break;
|
2000-05-07 05:14:43 +00:00
|
|
|
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;
|
2003-05-02 22:23:55 +00:00
|
|
|
case NS_STYLE_CURSOR_MOZ_ZOOM_IN:
|
|
|
|
c = eCursor_zoom_in;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_MOZ_ZOOM_OUT:
|
|
|
|
c = eCursor_zoom_out;
|
|
|
|
break;
|
2004-09-11 23:24:30 +00:00
|
|
|
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 18:39:49 +00:00
|
|
|
case NS_STYLE_CURSOR_NONE:
|
|
|
|
c = eCursor_none;
|
|
|
|
break;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
1998-12-03 03:07:16 +00:00
|
|
|
|
2004-12-30 21:56:11 +00:00
|
|
|
// First, try the imgIContainer, if non-null
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2005-07-01 04:29:42 +00:00
|
|
|
if (aContainer) {
|
|
|
|
PRUint32 hotspotX, hotspotY;
|
|
|
|
|
|
|
|
// css3-ui says to use the CSS-specified hotspot if present,
|
|
|
|
// otherwise use the intrinsic hotspot, otherwise use the top left
|
|
|
|
// corner.
|
|
|
|
if (aHaveHotspot) {
|
2005-07-02 22:24:38 +00:00
|
|
|
PRInt32 imgWidth, imgHeight;
|
|
|
|
aContainer->GetWidth(&imgWidth);
|
|
|
|
aContainer->GetHeight(&imgHeight);
|
|
|
|
|
2010-02-22 19:41:19 +00:00
|
|
|
// XXX NS_MAX(NS_lround(x), 0)?
|
2005-07-01 04:29:42 +00:00
|
|
|
hotspotX = aHotspotX > 0.0f
|
2007-02-28 21:29:53 +00:00
|
|
|
? PRUint32(aHotspotX + 0.5f) : PRUint32(0);
|
2005-07-02 22:24:38 +00:00
|
|
|
if (hotspotX >= PRUint32(imgWidth))
|
|
|
|
hotspotX = imgWidth - 1;
|
2005-07-01 04:29:42 +00:00
|
|
|
hotspotY = aHotspotY > 0.0f
|
2007-02-28 21:29:53 +00:00
|
|
|
? PRUint32(aHotspotY + 0.5f) : PRUint32(0);
|
2005-07-02 22:24:38 +00:00
|
|
|
if (hotspotY >= PRUint32(imgHeight))
|
|
|
|
hotspotY = imgHeight - 1;
|
2005-07-01 04:29:42 +00:00
|
|
|
} 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);
|
|
|
|
}
|
2004-12-30 21:56:11 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
aWidget->SetCursor(c);
|
1998-12-03 03:07:16 +00:00
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
return NS_OK;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
|
|
|
|
2008-07-01 01:03:50 +00:00
|
|
|
class NS_STACK_CLASS nsESMEventCB : public nsDispatchingCallback
|
2006-05-15 17:31:28 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsESMEventCB(nsIContent* aTarget) : mTarget(aTarget) {}
|
|
|
|
|
|
|
|
virtual void HandleEvent(nsEventChainPostVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
if (aVisitor.mPresContext) {
|
2009-12-24 21:20:05 +00:00
|
|
|
nsIFrame* frame = aVisitor.mPresContext->GetPrimaryFrameFor(mTarget);
|
|
|
|
if (frame) {
|
|
|
|
frame->HandleEvent(aVisitor.mPresContext,
|
|
|
|
(nsGUIEvent*) aVisitor.mEvent,
|
|
|
|
&aVisitor.mEventStatus);
|
2006-05-15 17:31:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> mTarget;
|
|
|
|
};
|
|
|
|
|
2005-03-28 23:39:13 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsEventStateManager::DispatchMouseEvent(nsGUIEvent* aEvent, PRUint32 aMessage,
|
2002-12-17 02:10:57 +00:00
|
|
|
nsIContent* aTargetContent,
|
|
|
|
nsIContent* aRelatedContent)
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-28 23:48:28 +00:00
|
|
|
nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), aMessage, aEvent->widget,
|
|
|
|
nsMouseEvent::eReal);
|
2002-12-17 02:10:57 +00:00
|
|
|
event.refPoint = aEvent->refPoint;
|
|
|
|
event.isShift = ((nsMouseEvent*)aEvent)->isShift;
|
|
|
|
event.isControl = ((nsMouseEvent*)aEvent)->isControl;
|
|
|
|
event.isAlt = ((nsMouseEvent*)aEvent)->isAlt;
|
|
|
|
event.isMeta = ((nsMouseEvent*)aEvent)->isMeta;
|
2009-11-10 21:55:38 +00:00
|
|
|
event.pluginEvent = ((nsMouseEvent*)aEvent)->pluginEvent;
|
2006-07-13 07:51:54 +00:00
|
|
|
event.relatedTarget = aRelatedContent;
|
2010-04-06 12:59:24 +00:00
|
|
|
event.inputSource = static_cast<nsMouseEvent*>(aEvent)->inputSource;
|
2002-12-17 02:10:57 +00:00
|
|
|
|
2010-08-27 23:15:08 +00:00
|
|
|
nsWeakFrame previousTarget = mCurrentTarget;
|
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
mCurrentTargetContent = aTargetContent;
|
|
|
|
|
2005-03-28 23:39:13 +00:00
|
|
|
nsIFrame* targetFrame = nsnull;
|
2002-12-17 02:10:57 +00:00
|
|
|
if (aTargetContent) {
|
2006-05-15 17:31:28 +00:00
|
|
|
nsESMEventCB callback(aTargetContent);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(aTargetContent, mPresContext, &event, nsnull,
|
2006-05-15 17:31:28 +00:00
|
|
|
&status, &callback);
|
2005-03-28 23:39:13 +00:00
|
|
|
|
2009-12-24 21:20:05 +00: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);
|
2002-12-18 07:13:51 +00:00
|
|
|
}
|
2002-12-17 02:10:57 +00:00
|
|
|
}
|
2006-05-15 17:31:28 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
mCurrentTargetContent = nsnull;
|
2010-08-27 23:15:08 +00:00
|
|
|
mCurrentTarget = previousTarget;
|
2005-03-28 23:39:13 +00:00
|
|
|
|
|
|
|
return targetFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-04-07 00:19:08 +00:00
|
|
|
nsEventStateManager::NotifyMouseOut(nsGUIEvent* aEvent, nsIContent* aMovingInto)
|
2005-03-28 23:39:13 +00:00
|
|
|
{
|
|
|
|
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-31 00:49:07 +00:00
|
|
|
nsSubDocumentFrame* subdocFrame = do_QueryFrame(mLastMouseOverFrame.GetFrame());
|
2005-03-28 23:39:13 +00:00
|
|
|
if (subdocFrame) {
|
|
|
|
nsCOMPtr<nsIDocShell> docshell;
|
|
|
|
subdocFrame->GetDocShell(getter_AddRefs(docshell));
|
|
|
|
if (docshell) {
|
2010-03-25 13:17:11 +00:00
|
|
|
nsRefPtr<nsPresContext> presContext;
|
2005-03-28 23:39:13 +00:00
|
|
|
docshell->GetPresContext(getter_AddRefs(presContext));
|
2010-03-25 13:17:11 +00:00
|
|
|
|
2005-03-28 23:39:13 +00:00
|
|
|
if (presContext) {
|
2011-04-21 17:35:52 +00:00
|
|
|
nsEventStateManager* kidESM = presContext->EventStateManager();
|
2005-04-07 00:19:08 +00:00
|
|
|
// Not moving into any element in this subdocument
|
|
|
|
kidESM->NotifyMouseOut(aEvent, nsnull);
|
2005-03-28 23:39:13 +00: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;
|
2005-05-03 16:05:48 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
2005-03-28 23:39:13 +00:00
|
|
|
|
|
|
|
// Fire mouseout
|
|
|
|
DispatchMouseEvent(aEvent, NS_MOUSE_EXIT_SYNTH,
|
2005-04-07 00:19:08 +00:00
|
|
|
mLastMouseOverElement, aMovingInto);
|
2005-03-28 23:39:13 +00:00
|
|
|
|
|
|
|
mLastMouseOverFrame = nsnull;
|
|
|
|
mLastMouseOverElement = nsnull;
|
|
|
|
|
|
|
|
// Turn recursion protection back off
|
|
|
|
mFirstMouseOutEventElement = nsnull;
|
2002-12-17 02:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-03-28 23:39:13 +00:00
|
|
|
nsEventStateManager::NotifyMouseOver(nsGUIEvent* aEvent, nsIContent* aContent)
|
2002-12-17 02:10:57 +00:00
|
|
|
{
|
2005-03-28 23:39:13 +00:00
|
|
|
NS_ASSERTION(aContent, "Mouse must be over something");
|
|
|
|
|
|
|
|
if (mLastMouseOverElement == aContent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Before firing mouseover, check for recursion
|
2006-06-06 23:18:38 +00:00
|
|
|
if (aContent == mFirstMouseOverEventElement)
|
2005-03-28 23:39:13 +00:00
|
|
|
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);
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIDocument *parentDoc = mDocument->GetParentDocument();
|
2002-12-17 02:10:57 +00:00
|
|
|
if (parentDoc) {
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIContent *docContent = parentDoc->FindContentForSubDocument(mDocument);
|
2002-12-17 02:10:57 +00:00
|
|
|
if (docContent) {
|
2010-06-25 13:59:57 +00:00
|
|
|
nsIPresShell *parentShell = parentDoc->GetShell();
|
2005-03-28 23:39:13 +00:00
|
|
|
if (parentShell) {
|
2011-04-21 17:35:52 +00:00
|
|
|
nsEventStateManager* parentESM = parentShell->GetPresContext()->EventStateManager();
|
2005-03-28 23:39:13 +00:00
|
|
|
parentESM->NotifyMouseOver(aEvent, docContent);
|
2002-12-17 02:10:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-28 23:48:28 +00:00
|
|
|
// Firing the DOM event in the parent document could cause all kinds
|
|
|
|
// of havoc. Reverify and take care.
|
2005-03-28 23:39:13 +00:00
|
|
|
if (mLastMouseOverElement == aContent)
|
|
|
|
return;
|
2002-12-17 02:10:57 +00:00
|
|
|
|
2005-06-25 01:32:02 +00:00
|
|
|
// Remember mLastMouseOverElement as the related content for the
|
|
|
|
// DispatchMouseEvent() call below, since NotifyMouseOut() resets it, bug 298477.
|
|
|
|
nsCOMPtr<nsIContent> lastMouseOverElement = mLastMouseOverElement;
|
|
|
|
|
2005-04-07 00:19:08 +00:00
|
|
|
NotifyMouseOut(aEvent, aContent);
|
2005-03-28 23:39:13 +00:00
|
|
|
|
|
|
|
// 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,
|
2005-06-25 01:32:02 +00:00
|
|
|
aContent, lastMouseOverElement);
|
2005-03-28 23:39:13 +00:00
|
|
|
mLastMouseOverElement = aContent;
|
|
|
|
|
|
|
|
// Turn recursion protection back off
|
|
|
|
mFirstMouseOverEventElement = nsnull;
|
|
|
|
}
|
2002-12-17 02:10:57 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
void
|
2005-03-28 23:39:13 +00:00
|
|
|
nsEventStateManager::GenerateMouseEnterExit(nsGUIEvent* aEvent)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
2005-04-10 23:35:18 +00:00
|
|
|
EnsureDocument(mPresContext);
|
2005-04-07 04:04:06 +00:00
|
|
|
if (!mDocument)
|
|
|
|
return;
|
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Hold onto old target content through the event and reset after.
|
1999-11-03 07:11:45 +00:00
|
|
|
nsCOMPtr<nsIContent> targetBeforeEvent = mCurrentTargetContent;
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
{
|
2003-02-14 21:43:06 +00:00
|
|
|
// Get the target content target (mousemove target == mouseover target)
|
2011-04-21 17:35:52 +00:00
|
|
|
nsCOMPtr<nsIContent> targetElement = GetEventTargetContent(aEvent);
|
2005-04-07 04:04:06 +00: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 13:12:05 +00:00
|
|
|
targetElement = mDocument->GetRootElement();
|
2005-04-07 04:04:06 +00:00
|
|
|
}
|
2005-03-28 23:39:13 +00:00
|
|
|
if (targetElement) {
|
|
|
|
NotifyMouseOver(aEvent, targetElement);
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_EXIT:
|
|
|
|
{
|
2005-04-07 00:19:08 +00:00
|
|
|
// This is actually the window mouse exit event. We're not moving
|
|
|
|
// into any new element.
|
2007-12-03 05:46:22 +00:00
|
|
|
|
|
|
|
if (mLastMouseOverFrame &&
|
|
|
|
nsContentUtils::GetTopLevelWidget(aEvent->widget) !=
|
2010-07-02 19:11:04 +00:00
|
|
|
nsContentUtils::GetTopLevelWidget(mLastMouseOverFrame->GetNearestWidget())) {
|
2007-12-03 05:46:22 +00:00
|
|
|
// the MouseOut event widget doesn't have same top widget with
|
|
|
|
// mLastMouseOverFrame, it's a spurious event for mLastMouseOverFrame
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-07 00:19:08 +00:00
|
|
|
NotifyMouseOut(aEvent, nsnull);
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// reset mCurretTargetContent to what it was
|
1999-11-03 07:11:45 +00:00
|
|
|
mCurrentTargetContent = targetBeforeEvent;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
1999-05-04 14:44:51 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::GenerateDragDropEnterExit(nsPresContext* aPresContext,
|
2003-11-19 01:20:56 +00:00
|
|
|
nsGUIEvent* aEvent)
|
1999-05-04 14:44:51 +00:00
|
|
|
{
|
1999-11-03 07:11:45 +00:00
|
|
|
//Hold onto old target content through the event and reset after.
|
|
|
|
nsCOMPtr<nsIContent> targetBeforeEvent = mCurrentTargetContent;
|
|
|
|
|
1999-05-04 14:44:51 +00:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_DRAGDROP_OVER:
|
|
|
|
{
|
2010-12-03 16:19:55 +00:00
|
|
|
// when dragging from one frame to another, events are fired in the
|
|
|
|
// order: dragexit, dragenter, dragleave
|
1999-05-04 14:44:51 +00:00
|
|
|
if (mLastDragOverFrame != mCurrentTarget) {
|
|
|
|
//We'll need the content, too, to check if it changed separately from the frames.
|
1999-11-02 03:55:14 +00:00
|
|
|
nsCOMPtr<nsIContent> lastContent;
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
2000-02-11 01:24:59 +00:00
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(targetContent));
|
1999-05-04 14:44:51 +00:00
|
|
|
|
2010-06-16 07:36:11 +00:00
|
|
|
if (mLastDragOverFrame) {
|
2007-04-12 04:37:39 +00:00
|
|
|
//The frame has changed but the content may not have. Check before dispatching to content
|
2000-02-11 01:24:59 +00:00
|
|
|
mLastDragOverFrame->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(lastContent));
|
1999-05-04 14:44:51 +00:00
|
|
|
|
2007-04-12 04:37:39 +00:00
|
|
|
FireDragEnterOrExit(aPresContext, aEvent, NS_DRAGDROP_EXIT_SYNTH,
|
|
|
|
targetContent, lastContent, mLastDragOverFrame);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
2007-04-12 04:37:39 +00:00
|
|
|
FireDragEnterOrExit(aPresContext, aEvent, NS_DRAGDROP_ENTER,
|
|
|
|
lastContent, targetContent, mCurrentTarget);
|
1999-05-04 14:44:51 +00:00
|
|
|
|
2010-12-03 16:19:55 +00:00
|
|
|
if (mLastDragOverFrame) {
|
|
|
|
FireDragEnterOrExit(aPresContext, aEvent, NS_DRAGDROP_LEAVE_SYNTH,
|
|
|
|
targetContent, lastContent, mLastDragOverFrame);
|
|
|
|
}
|
|
|
|
|
1999-05-04 14:44:51 +00:00
|
|
|
mLastDragOverFrame = mCurrentTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-06-22 14:20:14 +00:00
|
|
|
case NS_DRAGDROP_EXIT:
|
1999-05-04 14:44:51 +00:00
|
|
|
{
|
1999-11-03 07:11:45 +00:00
|
|
|
//This is actually the window mouse exit event.
|
2010-06-16 07:36:11 +00:00
|
|
|
if (mLastDragOverFrame) {
|
1999-11-02 03:55:14 +00:00
|
|
|
nsCOMPtr<nsIContent> lastContent;
|
2000-02-11 01:24:59 +00:00
|
|
|
mLastDragOverFrame->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(lastContent));
|
1999-11-03 07:11:45 +00:00
|
|
|
|
2007-04-12 04:37:39 +00:00
|
|
|
FireDragEnterOrExit(aPresContext, aEvent, NS_DRAGDROP_EXIT_SYNTH,
|
|
|
|
nsnull, lastContent, mLastDragOverFrame);
|
2010-12-03 16:19:55 +00:00
|
|
|
FireDragEnterOrExit(aPresContext, aEvent, NS_DRAGDROP_LEAVE_SYNTH,
|
|
|
|
nsnull, lastContent, mLastDragOverFrame);
|
1999-05-04 14:44:51 +00:00
|
|
|
|
2007-04-12 04:37:39 +00:00
|
|
|
mLastDragOverFrame = nsnull;
|
|
|
|
}
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
|
|
|
|
//reset mCurretTargetContent to what it was
|
|
|
|
mCurrentTargetContent = targetBeforeEvent;
|
2000-10-16 21:52:22 +00:00
|
|
|
|
2005-01-20 03:39:09 +00:00
|
|
|
// Now flush all pending notifications, for better responsiveness.
|
2001-01-20 04:59:39 +00:00
|
|
|
FlushPendingEvents(aPresContext);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
2007-04-12 04:37:39 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::FireDragEnterOrExit(nsPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent,
|
|
|
|
PRUint32 aMsg,
|
|
|
|
nsIContent* aRelatedTarget,
|
|
|
|
nsIContent* aTargetContent,
|
|
|
|
nsWeakFrame& aTargetFrame)
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2008-08-27 12:07:27 +00:00
|
|
|
nsDragEvent event(NS_IS_TRUSTED_EVENT(aEvent), aMsg, aEvent->widget);
|
2007-04-12 04:37:39 +00:00
|
|
|
event.refPoint = aEvent->refPoint;
|
|
|
|
event.isShift = ((nsMouseEvent*)aEvent)->isShift;
|
|
|
|
event.isControl = ((nsMouseEvent*)aEvent)->isControl;
|
|
|
|
event.isAlt = ((nsMouseEvent*)aEvent)->isAlt;
|
|
|
|
event.isMeta = ((nsMouseEvent*)aEvent)->isMeta;
|
|
|
|
event.relatedTarget = aRelatedTarget;
|
2010-04-06 12:59:24 +00:00
|
|
|
event.inputSource = static_cast<nsMouseEvent*>(aEvent)->inputSource;
|
2007-04-12 04:37:39 +00:00
|
|
|
|
|
|
|
mCurrentTargetContent = aTargetContent;
|
|
|
|
|
|
|
|
if (aTargetContent != aRelatedTarget) {
|
|
|
|
//XXX This event should still go somewhere!!
|
|
|
|
if (aTargetContent)
|
|
|
|
nsEventDispatcher::Dispatch(aTargetContent, aPresContext, &event,
|
|
|
|
nsnull, &status);
|
|
|
|
|
2008-09-25 14:44:53 +00: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)
|
2007-04-12 04:37:39 +00:00
|
|
|
SetContentState((aMsg == NS_DRAGDROP_ENTER) ? aTargetContent : nsnull,
|
|
|
|
NS_EVENT_STATE_DRAGOVER);
|
2009-10-07 02:51:02 +00: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-12 04:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Finally dispatch the event to the frame
|
|
|
|
if (aTargetFrame)
|
|
|
|
aTargetFrame->HandleEvent(aPresContext, &event, &status);
|
|
|
|
}
|
|
|
|
|
2009-10-07 02:51:02 +00: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));
|
|
|
|
|
|
|
|
// grab the interface that has GetMozCursor.
|
|
|
|
nsCOMPtr<nsIDOMNSDataTransfer> initialDataTransferNS =
|
|
|
|
do_QueryInterface(initialDataTransfer);
|
|
|
|
nsCOMPtr<nsIDOMNSDataTransfer> eventTransferNS =
|
|
|
|
do_QueryInterface(dragEvent->dataTransfer);
|
|
|
|
|
|
|
|
if (initialDataTransferNS && eventTransferNS) {
|
|
|
|
// retrieve the current moz cursor setting and save it.
|
|
|
|
nsAutoString mozCursor;
|
|
|
|
eventTransferNS->GetMozCursor(mozCursor);
|
|
|
|
initialDataTransferNS->SetMozCursor(mozCursor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::SetClickCount(nsPresContext* aPresContext,
|
1999-09-22 02:29:33 +00:00
|
|
|
nsMouseEvent *aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aStatus)
|
1998-11-24 07:46:58 +00:00
|
|
|
{
|
1999-09-16 14:54:59 +00:00
|
|
|
nsCOMPtr<nsIContent> mouseContent;
|
2011-05-07 09:42:45 +00:00
|
|
|
nsIContent* mouseContentParent = nsnull;
|
2000-02-11 01:24:59 +00:00
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(mouseContent));
|
2011-05-07 09:42:45 +00:00
|
|
|
if (mouseContent) {
|
|
|
|
if (mouseContent->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
mouseContent = mouseContent->GetParent();
|
|
|
|
}
|
|
|
|
if (mouseContent && mouseContent->IsRootOfNativeAnonymousSubtree()) {
|
|
|
|
mouseContentParent = mouseContent->GetParent();
|
|
|
|
}
|
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
|
2006-11-16 21:35:39 +00:00
|
|
|
switch (aEvent->button) {
|
|
|
|
case nsMouseEvent::eLeftButton:
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
mLastLeftMouseDownContent = mouseContent;
|
2010-09-02 02:38:54 +00:00
|
|
|
mLastLeftMouseDownContentParent = mouseContentParent;
|
2006-11-16 21:35:39 +00:00
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
2010-01-25 09:21:33 +00:00
|
|
|
if (mLastLeftMouseDownContent == mouseContent ||
|
2010-09-02 02:38:54 +00:00
|
|
|
mLastLeftMouseDownContentParent == mouseContent ||
|
|
|
|
mLastLeftMouseDownContent == mouseContentParent) {
|
2006-11-16 21:35:39 +00:00
|
|
|
aEvent->clickCount = mLClickCount;
|
|
|
|
mLClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
|
|
|
mLastLeftMouseDownContent = nsnull;
|
2010-01-25 09:21:33 +00:00
|
|
|
mLastLeftMouseDownContentParent = nsnull;
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-09-16 14:54:59 +00:00
|
|
|
|
2006-11-16 21:35:39 +00:00
|
|
|
case nsMouseEvent::eMiddleButton:
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
mLastMiddleMouseDownContent = mouseContent;
|
2010-09-02 02:38:54 +00:00
|
|
|
mLastMiddleMouseDownContentParent = mouseContentParent;
|
2006-11-16 21:35:39 +00:00
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
2010-01-25 09:21:33 +00:00
|
|
|
if (mLastMiddleMouseDownContent == mouseContent ||
|
2010-09-02 02:38:54 +00:00
|
|
|
mLastMiddleMouseDownContentParent == mouseContent ||
|
2010-09-08 13:25:21 +00:00
|
|
|
mLastMiddleMouseDownContent == mouseContentParent) {
|
2006-11-16 21:35:39 +00:00
|
|
|
aEvent->clickCount = mMClickCount;
|
|
|
|
mMClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
2010-01-25 09:21:33 +00:00
|
|
|
mLastMiddleMouseDownContent = nsnull;
|
|
|
|
mLastMiddleMouseDownContentParent = nsnull;
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-09-16 14:54:59 +00:00
|
|
|
|
2006-11-16 21:35:39 +00:00
|
|
|
case nsMouseEvent::eRightButton:
|
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
mLastRightMouseDownContent = mouseContent;
|
2010-09-02 02:38:54 +00:00
|
|
|
mLastRightMouseDownContentParent = mouseContentParent;
|
2006-11-16 21:35:39 +00:00
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
2010-01-25 09:21:33 +00:00
|
|
|
if (mLastRightMouseDownContent == mouseContent ||
|
2010-09-02 02:38:54 +00:00
|
|
|
mLastRightMouseDownContentParent == mouseContent ||
|
2010-09-08 13:25:21 +00:00
|
|
|
mLastRightMouseDownContent == mouseContentParent) {
|
2006-11-16 21:35:39 +00:00
|
|
|
aEvent->clickCount = mRClickCount;
|
|
|
|
mRClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
2010-01-25 09:21:33 +00:00
|
|
|
mLastRightMouseDownContent = nsnull;
|
|
|
|
mLastRightMouseDownContentParent = nsnull;
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-11-16 21:35:39 +00:00
|
|
|
return NS_OK;
|
1999-09-22 02:29:33 +00:00
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::CheckForAndDispatchClick(nsPresContext* aPresContext,
|
1999-09-22 02:29:33 +00:00
|
|
|
nsMouseEvent *aEvent,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aStatus)
|
1999-09-22 02:29:33 +00:00
|
|
|
{
|
|
|
|
nsresult ret = NS_OK;
|
2006-03-07 17:08:51 +00:00
|
|
|
PRInt32 flags = NS_EVENT_FLAG_NONE;
|
1999-09-22 02:29:33 +00:00
|
|
|
|
|
|
|
//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) {
|
2007-02-21 19:26:49 +00:00
|
|
|
//Check that the window isn't disabled before firing a click
|
|
|
|
//(see bug 366544).
|
|
|
|
if (aEvent->widget) {
|
|
|
|
PRBool enabled;
|
|
|
|
aEvent->widget->IsEnabled(&enabled);
|
|
|
|
if (!enabled) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
1998-11-24 07:46:58 +00:00
|
|
|
//fire click
|
2006-11-16 21:35:39 +00:00
|
|
|
if (aEvent->button == nsMouseEvent::eMiddleButton ||
|
|
|
|
aEvent->button == nsMouseEvent::eRightButton) {
|
|
|
|
flags |=
|
|
|
|
sLeftClickOnly ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE;
|
1999-09-22 02:29:33 +00:00
|
|
|
}
|
|
|
|
|
2006-11-16 21:35:39 +00:00
|
|
|
nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_MOUSE_CLICK, aEvent->widget,
|
2005-04-28 23:48:28 +00:00
|
|
|
nsMouseEvent::eReal);
|
2000-01-15 17:21:20 +00:00
|
|
|
event.refPoint = aEvent->refPoint;
|
1999-09-22 02:29:33 +00:00
|
|
|
event.clickCount = aEvent->clickCount;
|
1999-12-09 21:02:09 +00:00
|
|
|
event.isShift = aEvent->isShift;
|
|
|
|
event.isControl = aEvent->isControl;
|
|
|
|
event.isAlt = aEvent->isAlt;
|
|
|
|
event.isMeta = aEvent->isMeta;
|
2005-07-13 18:52:09 +00:00
|
|
|
event.time = aEvent->time;
|
2006-03-07 17:08:51 +00:00
|
|
|
event.flags |= flags;
|
2006-11-16 21:35:39 +00:00
|
|
|
event.button = aEvent->button;
|
2010-04-06 12:59:24 +00:00
|
|
|
event.inputSource = aEvent->inputSource;
|
1998-11-24 07:46:58 +00:00
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
|
2000-04-24 04:41:27 +00:00
|
|
|
if (presShell) {
|
2011-04-21 17:35:52 +00:00
|
|
|
nsCOMPtr<nsIContent> mouseContent = GetEventTargetContent(aEvent);
|
2003-02-14 21:43:06 +00:00
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
ret = presShell->HandleEventWithTarget(&event, mCurrentTarget,
|
|
|
|
mouseContent, aStatus);
|
2000-08-08 20:32:09 +00:00
|
|
|
if (NS_SUCCEEDED(ret) && aEvent->clickCount == 2) {
|
|
|
|
//fire double click
|
2006-11-16 21:35:39 +00:00
|
|
|
nsMouseEvent event2(NS_IS_TRUSTED_EVENT(aEvent), NS_MOUSE_DOUBLECLICK,
|
2005-04-28 23:48:28 +00:00
|
|
|
aEvent->widget, nsMouseEvent::eReal);
|
2000-08-08 20:32:09 +00:00
|
|
|
event2.refPoint = aEvent->refPoint;
|
|
|
|
event2.clickCount = aEvent->clickCount;
|
|
|
|
event2.isShift = aEvent->isShift;
|
|
|
|
event2.isControl = aEvent->isControl;
|
|
|
|
event2.isAlt = aEvent->isAlt;
|
|
|
|
event2.isMeta = aEvent->isMeta;
|
2006-03-07 17:08:51 +00:00
|
|
|
event2.flags |= flags;
|
2006-11-16 21:35:39 +00:00
|
|
|
event2.button = aEvent->button;
|
2010-04-06 12:59:24 +00:00
|
|
|
event2.inputSource = aEvent->inputSource;
|
2000-08-08 20:32:09 +00:00
|
|
|
|
2005-04-28 23:48:28 +00:00
|
|
|
ret = presShell->HandleEventWithTarget(&event2, mCurrentTarget,
|
2006-03-07 17:08:51 +00:00
|
|
|
mouseContent, aStatus);
|
2000-08-08 20:32:09 +00:00
|
|
|
}
|
1999-04-13 00:27:58 +00:00
|
|
|
}
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsEventStateManager::GetEventTarget()
|
1999-03-02 19:19:24 +00:00
|
|
|
{
|
2009-07-22 22:31:01 +00:00
|
|
|
nsIPresShell *shell;
|
|
|
|
if (mCurrentTarget ||
|
|
|
|
!mPresContext ||
|
|
|
|
!(shell = mPresContext->GetPresShell())) {
|
2011-04-21 17:35:52 +00:00
|
|
|
return mCurrentTarget;
|
2005-09-18 11:32:52 +00:00
|
|
|
}
|
|
|
|
|
2009-07-22 22:31:01 +00:00
|
|
|
if (mCurrentTargetContent) {
|
2009-12-24 21:20:05 +00:00
|
|
|
mCurrentTarget = mPresContext->GetPrimaryFrameFor(mCurrentTargetContent);
|
2009-07-22 22:31:01 +00:00
|
|
|
if (mCurrentTarget) {
|
2011-04-21 17:35:52 +00:00
|
|
|
return mCurrentTarget;
|
2002-12-07 00:56:03 +00: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 18:00:39 +00:00
|
|
|
|
2010-03-31 12:43:01 +00:00
|
|
|
nsIFrame* frame = shell->GetEventTargetFrame();
|
2011-04-21 17:35:52 +00:00
|
|
|
return (mCurrentTarget = frame);
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
already_AddRefed<nsIContent>
|
|
|
|
nsEventStateManager::GetEventTargetContent(nsEvent* aEvent)
|
1998-11-18 05:25:26 +00: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 18:00:39 +00:00
|
|
|
if (aEvent &&
|
|
|
|
(aEvent->message == NS_FOCUS_CONTENT ||
|
|
|
|
aEvent->message == NS_BLUR_CONTENT)) {
|
2011-04-21 17:35:52 +00:00
|
|
|
nsCOMPtr<nsIContent> content = GetFocusedContent();
|
|
|
|
return content.forget();
|
2000-04-04 23:55:31 +00: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 18:00:39 +00:00
|
|
|
if (mCurrentTargetContent) {
|
2011-04-21 17:35:52 +00:00
|
|
|
nsCOMPtr<nsIContent> content = mCurrentTargetContent;
|
|
|
|
return content.forget();
|
Fixes bug 66597, bug 103284, bug 114440, bug 120023, bug 128741, bug 19259. Cleans up browse with caret, makes it work with XML content docs, creates keyboard toggle for it (Accel+shift+K), synchronizes focus and document selection so that users can tab navigate relative to their last find or click in text, or vice versa, makes tabbing move relative to named anchor that has been jumped to. r=bryner, sr=alecf, a=asa
2002-03-10 06:21:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
nsIContent *content = nsnull;
|
2004-04-13 09:39:16 +00: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 18:00:39 +00:00
|
|
|
nsIPresShell *presShell = mPresContext->GetPresShell();
|
|
|
|
if (presShell) {
|
2011-04-21 17:35:52 +00:00
|
|
|
content = presShell->GetEventTargetContent(aEvent).get();
|
2004-04-13 09:39:16 +00:00
|
|
|
}
|
2001-06-22 07:25:28 +00: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 18:00:39 +00:00
|
|
|
// Some events here may set mCurrentTarget but not set the corresponding
|
|
|
|
// event target in the PresShell.
|
2011-04-21 17:35:52 +00:00
|
|
|
if (!content && mCurrentTarget) {
|
|
|
|
mCurrentTarget->GetContentForEvent(mPresContext, aEvent, &content);
|
2003-02-27 22:59:08 +00:00
|
|
|
}
|
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
return content;
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
2011-05-25 00:18:40 +00:00
|
|
|
static Element*
|
|
|
|
GetLabelTarget(nsIContent* aPossibleLabel)
|
2010-05-31 17:49:55 +00:00
|
|
|
{
|
2011-05-25 00:18:40 +00:00
|
|
|
nsHTMLLabelElement* label = nsHTMLLabelElement::FromContent(aPossibleLabel);
|
2010-05-31 17:49:55 +00:00
|
|
|
if (!label)
|
|
|
|
return nsnull;
|
|
|
|
|
2011-05-25 00:18:40 +00:00
|
|
|
return label->GetLabeledElement();
|
2010-05-31 17:49:55 +00:00
|
|
|
}
|
|
|
|
|
2004-07-14 22:27:24 +00: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.
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-06-01 01:46:56 +00:00
|
|
|
/* static */
|
|
|
|
inline void
|
|
|
|
nsEventStateManager::DoStateChange(Element* aElement, nsEventStates aState,
|
|
|
|
PRBool aAddState)
|
2010-05-31 17:47:11 +00:00
|
|
|
{
|
2011-06-01 01:46:56 +00:00
|
|
|
if (aAddState) {
|
|
|
|
aElement->AddStates(aState);
|
|
|
|
} else {
|
|
|
|
aElement->RemoveStates(aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 01:46:56 +00:00
|
|
|
/* static */
|
|
|
|
inline void
|
|
|
|
nsEventStateManager::DoStateChange(nsIContent* aContent, nsEventStates aState,
|
|
|
|
PRBool aStateAdded)
|
|
|
|
{
|
|
|
|
if (aContent->IsElement()) {
|
|
|
|
DoStateChange(aContent->AsElement(), aState, aStateAdded);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 01:46:56 +00:00
|
|
|
/* static */
|
|
|
|
void
|
|
|
|
nsEventStateManager::UpdateAncestorState(nsIContent* aStartNode,
|
|
|
|
nsIContent* aStopBefore,
|
|
|
|
nsEventStates aState,
|
|
|
|
PRBool aAddState)
|
|
|
|
{
|
|
|
|
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 17:49:55 +00:00
|
|
|
if (labelTarget) {
|
2011-06-01 01:46:56 +00:00
|
|
|
DoStateChange(labelTarget, aState, aAddState);
|
2010-05-31 17:49:55 +00:00
|
|
|
}
|
2010-05-31 17:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-24 19:06:07 +00:00
|
|
|
PRBool
|
2010-10-20 11:26:32 +00:00
|
|
|
nsEventStateManager::SetContentState(nsIContent *aContent, nsEventStates aState)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
2011-03-29 03:32:11 +00: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-06-01 01:46:56 +00:00
|
|
|
PRBool updateAncestors;
|
2011-03-29 03:32:11 +00:00
|
|
|
|
|
|
|
if (aState == NS_EVENT_STATE_HOVER || aState == NS_EVENT_STATE_ACTIVE) {
|
|
|
|
// Hover and active are hierarchical
|
2011-06-01 01:46:56 +00:00
|
|
|
updateAncestors = PR_TRUE;
|
2011-03-29 03:32:11 +00:00
|
|
|
|
|
|
|
// check to see that this state is allowed by style. Check dragover too?
|
|
|
|
// XXX Is this even what we want?
|
|
|
|
if (mCurrentTarget)
|
|
|
|
{
|
|
|
|
const nsStyleUserInterface* ui = mCurrentTarget->GetStyleUserInterface();
|
|
|
|
if (ui->mUserInput == NS_STYLE_USER_INPUT_NONE)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2006-11-01 13:56:48 +00:00
|
|
|
|
2011-03-29 03:32:11 +00:00
|
|
|
if (aState == NS_EVENT_STATE_ACTIVE) {
|
|
|
|
if (aContent != mActiveContent) {
|
|
|
|
notifyContent1 = aContent;
|
|
|
|
notifyContent2 = mActiveContent;
|
|
|
|
mActiveContent = aContent;
|
|
|
|
}
|
2006-11-01 13:56:48 +00:00
|
|
|
} else {
|
2011-03-29 03:32:11 +00:00
|
|
|
NS_ASSERTION(aState == NS_EVENT_STATE_HOVER, "How did that happen?");
|
|
|
|
nsIContent* newHover;
|
|
|
|
|
|
|
|
if (mPresContext->IsDynamic()) {
|
2006-11-01 13:56:48 +00:00
|
|
|
newHover = aContent;
|
|
|
|
} else {
|
2011-03-29 03:32:11 +00:00
|
|
|
NS_ASSERTION(!aContent ||
|
|
|
|
aContent->GetCurrentDoc() == mPresContext->PresShell()->GetDocument(),
|
|
|
|
"Unexpected document");
|
|
|
|
nsIFrame *frame = aContent ? aContent->GetPrimaryFrame() : nsnull;
|
|
|
|
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.
|
|
|
|
newHover = nsnull;
|
|
|
|
}
|
2006-11-01 13:56:48 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
|
2011-03-29 03:32:11 +00:00
|
|
|
if (newHover != mHoverContent) {
|
|
|
|
notifyContent1 = newHover;
|
|
|
|
notifyContent2 = mHoverContent;
|
|
|
|
mHoverContent = newHover;
|
1999-04-20 00:03:30 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-29 03:32:11 +00:00
|
|
|
} else {
|
2011-06-01 01:46:56 +00:00
|
|
|
updateAncestors = PR_FALSE;
|
2011-03-29 03:32:11 +00:00
|
|
|
if (aState == NS_EVENT_STATE_DRAGOVER) {
|
|
|
|
if (aContent != mDragOverContent) {
|
|
|
|
notifyContent1 = aContent;
|
|
|
|
notifyContent2 = mDragOverContent;
|
|
|
|
mDragOverContent = aContent;
|
1999-04-20 00:03:30 +00:00
|
|
|
}
|
2011-03-29 03:32:11 +00:00
|
|
|
} else if (aState == NS_EVENT_STATE_URLTARGET) {
|
|
|
|
if (aContent != mURLTargetContent) {
|
|
|
|
notifyContent1 = aContent;
|
|
|
|
notifyContent2 = mURLTargetContent;
|
|
|
|
mURLTargetContent = aContent;
|
1999-04-12 21:24:07 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 01:46:56 +00: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.
|
|
|
|
PRBool content1StateSet = PR_TRUE;
|
2011-03-29 03:32:11 +00:00
|
|
|
if (!notifyContent1) {
|
|
|
|
// This is ok because FindCommonAncestor wouldn't find anything
|
|
|
|
// anyway if notifyContent1 is null.
|
|
|
|
notifyContent1 = notifyContent2;
|
|
|
|
notifyContent2 = nsnull;
|
2011-06-01 01:46:56 +00:00
|
|
|
content1StateSet = PR_FALSE;
|
2011-03-29 03:32:11 +00:00
|
|
|
}
|
2001-05-14 01:49:07 +00:00
|
|
|
|
2011-03-29 03:32:11 +00:00
|
|
|
if (notifyContent1 && mPresContext) {
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
if (mDocument) {
|
2011-05-31 21:38:25 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2011-03-29 03:32:11 +00:00
|
|
|
|
2011-06-01 01:46:56 +00:00
|
|
|
if (updateAncestors) {
|
2011-03-29 03:32:11 +00:00
|
|
|
nsCOMPtr<nsIContent> commonAncestor =
|
|
|
|
FindCommonAncestor(notifyContent1, notifyContent2);
|
|
|
|
if (notifyContent2) {
|
2011-06-01 01:46:56 +00: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).
|
|
|
|
UpdateAncestorState(notifyContent2, commonAncestor, aState, PR_FALSE);
|
2011-03-29 03:32:11 +00:00
|
|
|
}
|
2011-06-01 01:46:56 +00:00
|
|
|
UpdateAncestorState(notifyContent1, commonAncestor, aState,
|
|
|
|
content1StateSet);
|
2011-03-29 03:32:11 +00:00
|
|
|
} else {
|
|
|
|
if (notifyContent2) {
|
2011-06-01 01:46:56 +00:00
|
|
|
DoStateChange(notifyContent2, aState, PR_FALSE);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
2011-06-01 01:46:56 +00:00
|
|
|
DoStateChange(notifyContent1, aState, content1StateSet);
|
1999-04-20 00:03:30 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00: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 18:00:39 +00:00
|
|
|
return PR_TRUE;
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
2011-04-21 17:35:52 +00: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 18:00:39 +00:00
|
|
|
nsEventStateManager::ContentRemoved(nsIDocument* aDocument, nsIContent* aContent)
|
2005-08-30 20:22:55 +00: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 18:00:39 +00: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 09:58:58 +00: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 18:00:39 +00:00
|
|
|
if (fm)
|
|
|
|
fm->ContentRemoved(aDocument, aContent);
|
2005-08-30 20:22:55 +00: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 18:00:39 +00:00
|
|
|
if (mHoverContent &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mHoverContent, aContent)) {
|
|
|
|
// Since hover is hierarchical, set the current hover to the
|
|
|
|
// content's parent node.
|
2010-05-31 17:49:55 +00:00
|
|
|
SetContentState(aContent->GetParent(), NS_EVENT_STATE_HOVER);
|
2005-08-30 20:22:55 +00: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 18:00:39 +00:00
|
|
|
if (mActiveContent &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mActiveContent, aContent)) {
|
|
|
|
// Active is hierarchical, so set the current active to the
|
|
|
|
// content's parent node.
|
2010-05-31 17:49:55 +00:00
|
|
|
SetContentState(aContent->GetParent(), NS_EVENT_STATE_ACTIVE);
|
2005-08-30 20:22:55 +00: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 18:00:39 +00:00
|
|
|
if (mDragOverContent &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mDragOverContent, aContent)) {
|
|
|
|
mDragOverContent = nsnull;
|
2005-08-30 20:22:55 +00: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 18:00:39 +00:00
|
|
|
if (mLastMouseOverElement &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mLastMouseOverElement, aContent)) {
|
|
|
|
// See bug 292146 for why we want to null this out
|
|
|
|
mLastMouseOverElement = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2003-07-01 22:46:55 +00:00
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
PRBool
|
|
|
|
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 18:00:39 +00:00
|
|
|
{
|
2011-04-21 17:35:52 +00: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 18:00:39 +00:00
|
|
|
}
|
2003-08-29 21:52:25 +00: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 18:00:39 +00:00
|
|
|
//-------------------------------------------
|
|
|
|
// Access Key Registration
|
|
|
|
//-------------------------------------------
|
2011-04-21 17:35:52 +00: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 18:00:39 +00:00
|
|
|
nsEventStateManager::RegisterAccessKey(nsIContent* aContent, PRUint32 aKey)
|
|
|
|
{
|
|
|
|
if (aContent && mAccessKeys.IndexOf(aContent) == -1)
|
|
|
|
mAccessKeys.AppendObject(aContent);
|
|
|
|
}
|
2000-02-09 15:14:55 +00:00
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
void
|
2002-05-22 00:14:51 +00:00
|
|
|
nsEventStateManager::UnregisterAccessKey(nsIContent* aContent, PRUint32 aKey)
|
2000-02-09 15:14:55 +00:00
|
|
|
{
|
2007-11-28 20:14:12 +00:00
|
|
|
if (aContent)
|
|
|
|
mAccessKeys.RemoveObject(aContent);
|
2000-02-09 15:14:55 +00:00
|
|
|
}
|
|
|
|
|
2011-04-21 17:35:52 +00:00
|
|
|
PRUint32
|
|
|
|
nsEventStateManager::GetRegisteredAccessKey(nsIContent* aContent)
|
2007-08-29 06:52:46 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aContent);
|
|
|
|
|
2007-11-28 20:14:12 +00:00
|
|
|
if (mAccessKeys.IndexOf(aContent) == -1)
|
2011-04-21 17:35:52 +00:00
|
|
|
return 0;
|
2007-08-29 06:52:46 +00:00
|
|
|
|
2007-11-28 20:14:12 +00:00
|
|
|
nsAutoString accessKey;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
|
2011-04-21 17:35:52 +00:00
|
|
|
return accessKey.First();
|
2007-08-29 06:52:46 +00:00
|
|
|
}
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::EnsureDocument(nsPresContext* aPresContext)
|
2003-11-19 01:20:56 +00:00
|
|
|
{
|
2003-12-21 05:36:36 +00:00
|
|
|
if (!mDocument)
|
2006-05-19 10:26:44 +00:00
|
|
|
mDocument = aPresContext->Document();
|
2000-06-28 20:35:32 +00:00
|
|
|
}
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::FlushPendingEvents(nsPresContext* aPresContext)
|
2003-11-19 01:20:56 +00:00
|
|
|
{
|
2001-01-20 04:59:39 +00:00
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "nsnull ptr");
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *shell = aPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
2009-04-21 23:53:52 +00:00
|
|
|
shell->FlushPendingNotifications(Flush_InterruptibleLayout);
|
2001-01-20 04:59:39 +00: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 18:00:39 +00:00
|
|
|
nsIContent*
|
|
|
|
nsEventStateManager::GetFocusedContent()
|
2001-05-22 23:52:17 +00: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 18:00:39 +00:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm || !mDocument)
|
|
|
|
return nsnull;
|
2004-07-23 07:27:57 +00: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 18:00:39 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
|
|
|
return nsFocusManager::GetFocusedDescendant(mDocument->GetWindow(), PR_FALSE,
|
|
|
|
getter_AddRefs(focusedWindow));
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------
|
2001-10-22 22:43:52 +00:00
|
|
|
// Return PR_TRUE if the docshell is visible
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::IsShellVisible(nsIDocShell* aShell)
|
2001-05-22 23:52:17 +00:00
|
|
|
{
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(aShell, "docshell is null");
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIBaseWindow> basewin = do_QueryInterface(aShell);
|
|
|
|
if (!basewin)
|
|
|
|
return PR_TRUE;
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
PRBool isVisible = PR_TRUE;
|
|
|
|
basewin->GetVisibility(&isVisible);
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
// We should be doing some additional checks here so that
|
|
|
|
// we don't tab into hidden tabs of tabbrowser. -bryner
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
return isVisible;
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
2009-08-07 15:11:17 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::DoContentCommandEvent(nsContentCommandEvent* aEvent)
|
|
|
|
{
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
|
2010-02-20 16:07:03 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
|
2009-08-07 15:11:17 +00:00
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
2010-02-20 16:07:03 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsPIWindowRoot> root = window->GetTopWindowRoot();
|
|
|
|
NS_ENSURE_TRUE(root, NS_ERROR_FAILURE);
|
2009-08-07 15:11:17 +00: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-11 01:45:45 +00:00
|
|
|
case NS_CONTENT_COMMAND_PASTE_TRANSFERABLE:
|
|
|
|
cmd = "cmd_pasteTransferable";
|
|
|
|
break;
|
2009-08-07 15:11:17 +00:00
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIController> controller;
|
2010-02-20 16:07:03 +00:00
|
|
|
nsresult rv = root->GetControllerForCommand(cmd, getter_AddRefs(controller));
|
2009-08-07 15:11:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!controller) {
|
|
|
|
// When GetControllerForCommand succeeded but there is no controller, the
|
|
|
|
// command isn't supported.
|
|
|
|
aEvent->mIsEnabled = PR_FALSE;
|
|
|
|
} else {
|
|
|
|
PRBool canDoIt;
|
|
|
|
rv = controller->IsCommandEnabled(cmd, &canDoIt);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
aEvent->mIsEnabled = canDoIt;
|
|
|
|
if (canDoIt && !aEvent->mOnlyEnabledCheck) {
|
2010-01-11 01:45:45 +00: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 15:11:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-03-11 05:25:29 +00: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
aEvent->mSucceeded = PR_TRUE;
|
|
|
|
|
|
|
|
nsIScrollableFrame* sf =
|
|
|
|
ps->GetFrameToScrollAsScrollable(nsIPresShell::eEither);
|
|
|
|
aEvent->mIsEnabled = sf ? CanScrollOn(sf, aEvent->mScroll.mAmount,
|
|
|
|
aEvent->mScroll.mIsHorizontal) :
|
|
|
|
PR_FALSE;
|
|
|
|
|
|
|
|
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 13:10:18 +00:00
|
|
|
|
2011-05-17 00:23:23 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::DoQueryScrollTargetInfo(nsQueryContentEvent* aEvent,
|
|
|
|
nsIFrame* aTargetFrame)
|
|
|
|
{
|
|
|
|
nsMouseScrollEvent* msEvent = aEvent->mInput.mMouseScrollEvent;
|
2011-05-22 05:39:16 +00:00
|
|
|
|
|
|
|
// Don't use high resolution scrolling when user customize the scrolling
|
|
|
|
// speed.
|
|
|
|
if (!UseSystemScrollSettingFor(msEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-17 00:23:23 +00:00
|
|
|
nsIScrollableFrame::ScrollUnit unit;
|
2011-05-22 05:39:16 +00:00
|
|
|
PRBool allowOverrideSystemSettings;
|
|
|
|
switch (ComputeWheelActionFor(msEvent, PR_TRUE)) {
|
|
|
|
case MOUSE_SCROLL_N_LINES:
|
|
|
|
unit = nsIScrollableFrame::LINES;
|
|
|
|
allowOverrideSystemSettings = PR_TRUE;
|
|
|
|
break;
|
|
|
|
case MOUSE_SCROLL_PAGE:
|
|
|
|
unit = nsIScrollableFrame::PAGES;
|
|
|
|
allowOverrideSystemSettings = PR_FALSE;
|
|
|
|
break;
|
|
|
|
case MOUSE_SCROLL_PIXELS:
|
|
|
|
unit = nsIScrollableFrame::DEVICE_PIXELS;
|
|
|
|
allowOverrideSystemSettings = PR_FALSE;
|
|
|
|
default:
|
|
|
|
// Don't use high resolution scrolling when the action doesn't scroll
|
|
|
|
// contents.
|
|
|
|
return;
|
2011-05-17 00:23:23 +00:00
|
|
|
}
|
2011-05-22 05:39:16 +00:00
|
|
|
|
|
|
|
DoScrollText(aTargetFrame, msEvent, unit,
|
|
|
|
allowOverrideSystemSettings, aEvent);
|
2011-05-17 00:23:23 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 13:10:18 +00:00
|
|
|
void
|
2010-10-28 14:11:15 +00:00
|
|
|
nsEventStateManager::SetActiveManager(nsEventStateManager* aNewESM,
|
|
|
|
nsIContent* aContent)
|
2010-09-16 13:10:18 +00:00
|
|
|
{
|
|
|
|
if (sActiveESM && aNewESM != sActiveESM) {
|
|
|
|
sActiveESM->SetContentState(nsnull, NS_EVENT_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
sActiveESM = aNewESM;
|
2010-10-28 14:11:15 +00:00
|
|
|
if (sActiveESM && aContent) {
|
2010-09-16 13:10:18 +00:00
|
|
|
sActiveESM->SetContentState(aContent, NS_EVENT_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
}
|
2010-10-15 16:41:02 +00:00
|
|
|
|
|
|
|
void
|
2010-10-28 14:11:15 +00:00
|
|
|
nsEventStateManager::ClearGlobalActiveContent(nsEventStateManager* aClearer)
|
2010-10-15 16:41:02 +00:00
|
|
|
{
|
2010-10-28 14:11:15 +00:00
|
|
|
if (aClearer) {
|
|
|
|
aClearer->SetContentState(nsnull, NS_EVENT_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
if (sActiveESM && aClearer != sActiveESM) {
|
2010-10-15 16:41:02 +00:00
|
|
|
sActiveESM->SetContentState(nsnull, NS_EVENT_STATE_ACTIVE);
|
|
|
|
}
|
|
|
|
sActiveESM = nsnull;
|
|
|
|
}
|