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>
|
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
|
|
|
|
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"
|
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"
|
2005-11-14 23:55:24 +00:00
|
|
|
#include "nsIKBStateControl.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"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
2004-07-05 01:31:30 +00:00
|
|
|
#include "nsIDOMNSHTMLInputElement.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"
|
2001-04-18 00:14:34 +00:00
|
|
|
#include "nsImageMapUtils.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 "nsIHTMLDocument.h"
|
2002-11-29 23:44:07 +00:00
|
|
|
#include "nsINameSpaceManager.h"
|
2000-02-11 01:56:01 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
1999-04-30 19:38:39 +00:00
|
|
|
#include "nsIScrollableView.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-08-19 19:48:45 +00:00
|
|
|
#include "nsIDeviceContext.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"
|
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"
|
2005-02-25 20:46:35 +00:00
|
|
|
#include "nsIPrefBranch2.h"
|
2005-10-29 12:50:22 +00:00
|
|
|
#include "nsIObjectFrame.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
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
#include "nsIFocusController.h"
|
|
|
|
|
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"
|
2000-12-09 07:28:19 +00:00
|
|
|
#include "nsIScrollableViewProvider.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
#include "nsIDOMDocumentRange.h"
|
2001-11-14 10:06:21 +00:00
|
|
|
#include "nsIDOMDocumentEvent.h"
|
|
|
|
#include "nsIDOMMouseEvent.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIDOMDocumentView.h"
|
|
|
|
#include "nsIDOMAbstractView.h"
|
|
|
|
#include "nsIDOMNSUIEvent.h"
|
2001-02-15 05:07:46 +00:00
|
|
|
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsICaret.h"
|
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2000-01-13 11:43:54 +00:00
|
|
|
|
2005-03-28 23:39:13 +00:00
|
|
|
#include "nsIFrameFrame.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"
|
2007-05-22 21:45:03 +00:00
|
|
|
#include "nsPresShellIterator.h"
|
2004-12-30 21:56:11 +00:00
|
|
|
|
2005-08-13 00:20:46 +00:00
|
|
|
#ifdef XP_MACOSX
|
2002-03-26 00:59:03 +00:00
|
|
|
#include <Events.h>
|
|
|
|
#endif
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
#if defined(DEBUG_rods) || defined(DEBUG_bryner)
|
2001-05-22 23:52:17 +00:00
|
|
|
//#define DEBUG_DOCSHELL_FOCUS
|
|
|
|
#endif
|
2001-03-30 04:45:40 +00:00
|
|
|
|
2001-02-19 12:55:42 +00:00
|
|
|
static NS_DEFINE_CID(kFrameTraversalCID, NS_FRAMETRAVERSAL_CID);
|
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
|
1999-12-11 00:02:08 +00:00
|
|
|
//we will use key binding by default now. this wil lbreak viewer for now
|
2001-02-15 05:07:46 +00:00
|
|
|
#define NON_KEYBINDING 0
|
1999-12-11 00:02:08 +00:00
|
|
|
|
2001-02-15 05:07:46 +00:00
|
|
|
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
2000-03-15 04:03:44 +00:00
|
|
|
|
1999-12-08 20:18:16 +00:00
|
|
|
nsIContent * gLastFocusedContent = 0; // Strong reference
|
1999-12-01 09:09:46 +00:00
|
|
|
nsIDocument * gLastFocusedDocument = 0; // Strong reference
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* gLastFocusedPresContext = 0; // Weak reference
|
1999-12-01 09:09:46 +00:00
|
|
|
|
2004-04-13 06:41:35 +00:00
|
|
|
enum nsTextfieldSelectModel {
|
|
|
|
eTextfieldSelect_unset = -1,
|
|
|
|
eTextfieldSelect_manual = 0,
|
|
|
|
eTextfieldSelect_auto = 1 // select textfields when focused with keyboard
|
|
|
|
};
|
2002-09-18 21:24:57 +00:00
|
|
|
|
2004-04-13 06:41:35 +00:00
|
|
|
// Tab focus policy (static, constant across the app):
|
|
|
|
// Which types of elements are in the tab order?
|
|
|
|
static PRInt8 sTextfieldSelectModel = eTextfieldSelect_unset;
|
|
|
|
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;
|
1999-12-01 09:09:46 +00:00
|
|
|
|
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,
|
2006-07-20 15:38:43 +00:00
|
|
|
MOUSE_SCROLL_TEXTSIZE,
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
PRInt32 accessKey = nsContentUtils::GetIntPref("ui.key.generalAccessKey", -1);
|
|
|
|
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:
|
|
|
|
return nsContentUtils::GetIntPref("ui.key.chromeAccess", 0);
|
|
|
|
case nsIDocShellTreeItem::typeContent:
|
|
|
|
return nsContentUtils::GetIntPref("ui.key.contentAccess", 0);
|
|
|
|
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,
|
|
|
|
nsGUIEvent* aEvent);
|
|
|
|
static void UpdateTransaction();
|
|
|
|
static void EndTransaction();
|
|
|
|
static void OnEvent(nsEvent* aEvent);
|
|
|
|
protected:
|
|
|
|
static nsPoint GetScreenPoint(nsGUIEvent* aEvent);
|
2006-08-07 06:33:46 +00:00
|
|
|
static PRUint32 GetTimeoutTime();
|
|
|
|
static PRUint32 GetIgnoreMoveDelayTime();
|
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
|
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;
|
2006-07-12 04:15:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::BeginTransaction(nsIFrame* aTargetFrame,
|
|
|
|
nsGUIEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!sTargetFrame, "previous transaction is not finished!");
|
|
|
|
sTargetFrame = aTargetFrame;
|
|
|
|
UpdateTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::UpdateTransaction()
|
|
|
|
{
|
|
|
|
// 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;
|
2006-07-12 04:15:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::EndTransaction()
|
|
|
|
{
|
|
|
|
sTargetFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
|
|
|
OutOfTime(PRUint32 aBaseTime, PRUint32 aThreshold)
|
|
|
|
{
|
|
|
|
PRUint32 now = PR_IntervalToMilliseconds(PR_IntervalNow());
|
|
|
|
return (now - aBaseTime > aThreshold);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMouseWheelTransaction::OnEvent(nsEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!sTargetFrame)
|
|
|
|
return;
|
|
|
|
|
2006-08-07 06:33:46 +00:00
|
|
|
if (OutOfTime(sTime, GetTimeoutTime())) {
|
2006-07-12 04:15:42 +00:00
|
|
|
// Time out the current transaction.
|
|
|
|
EndTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_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:
|
|
|
|
if (((nsMouseEvent*)aEvent)->reason == nsMouseEvent::eReal) {
|
2006-08-07 06:33:46 +00:00
|
|
|
// If the cursor is moving to be outside the frame,
|
|
|
|
// terminate the scrollwheel transaction.
|
2006-07-12 04:15:42 +00:00
|
|
|
nsPoint pt = GetScreenPoint((nsGUIEvent*)aEvent);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsMouseWheelTransaction::GetScreenPoint(nsGUIEvent* aEvent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent, "aEvent is null");
|
|
|
|
NS_ASSERTION(aEvent->widget, "aEvent-widget is null");
|
|
|
|
nsRect tmpRect;
|
|
|
|
aEvent->widget->WidgetToScreen(nsRect(aEvent->refPoint, nsSize(1, 1)),
|
|
|
|
tmpRect);
|
|
|
|
return tmpRect.TopLeft();
|
|
|
|
}
|
|
|
|
|
2006-08-07 06:33:46 +00:00
|
|
|
PRUint32
|
|
|
|
nsMouseWheelTransaction::GetTimeoutTime()
|
|
|
|
{
|
|
|
|
return (PRUint32)
|
|
|
|
nsContentUtils::GetIntPref("mousewheel.transaction.timeout", 1500);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsMouseWheelTransaction::GetIgnoreMoveDelayTime()
|
|
|
|
{
|
|
|
|
return (PRUint32)
|
|
|
|
nsContentUtils::GetIntPref("mousewheel.transaction.ignoremovedelay", 100);
|
|
|
|
}
|
|
|
|
|
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),
|
2003-03-18 23:41:44 +00:00
|
|
|
mCurrentFocusFrame(nsnull),
|
2004-04-29 23:34:19 +00:00
|
|
|
mCurrentTabIndex(0),
|
2005-10-11 03:33:48 +00:00
|
|
|
mLastFocusedWith(eEventFocusedByUnknown),
|
2004-04-29 23:34:19 +00:00
|
|
|
mPresContext(nsnull),
|
|
|
|
mLClickCount(0),
|
|
|
|
mMClickCount(0),
|
|
|
|
mRClickCount(0),
|
|
|
|
mNormalLMouseEventInProcess(PR_FALSE),
|
2002-12-24 20:21:40 +00:00
|
|
|
m_haveShutdown(PR_FALSE),
|
2004-04-29 23:34:19 +00:00
|
|
|
mBrowseWithCaret(PR_FALSE),
|
|
|
|
mTabbedThroughDocument(PR_FALSE),
|
|
|
|
mAccessKeys(nsnull)
|
|
|
|
{
|
2004-04-13 06:41:35 +00:00
|
|
|
++sESMInstanceCount;
|
2000-03-15 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2000-03-15 05:02:23 +00:00
|
|
|
NS_IMETHODIMP
|
2000-03-15 04:03:44 +00:00
|
|
|
nsEventStateManager::Init()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2004-07-23 07:27:57 +00:00
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
2001-10-22 22:01:27 +00:00
|
|
|
do_GetService("@mozilla.org/observer-service;1", &rv);
|
2004-04-29 23:34:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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
|
|
|
|
2005-02-25 20:46:35 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch2> prefBranch =
|
2004-04-29 23:34:19 +00:00
|
|
|
do_QueryInterface(nsContentUtils::GetPrefBranch());
|
|
|
|
|
|
|
|
if (prefBranch) {
|
2004-04-13 06:41:35 +00:00
|
|
|
if (sESMInstanceCount == 1) {
|
2004-04-29 23:34:19 +00:00
|
|
|
sLeftClickOnly =
|
|
|
|
nsContentUtils::GetBoolPref("nglayout.events.dispatchLeftClickOnly",
|
|
|
|
sLeftClickOnly);
|
2002-11-25 23:26:06 +00:00
|
|
|
|
2006-07-13 10:18:12 +00:00
|
|
|
sChromeAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeChrome);
|
|
|
|
sContentAccessModifier =
|
|
|
|
GetAccessModifierMaskFromPref(nsIDocShellTreeItem::typeContent);
|
2005-01-29 23:47:35 +00:00
|
|
|
|
|
|
|
nsIContent::sTabFocusModelAppliesToXUL =
|
|
|
|
nsContentUtils::GetBoolPref("accessibility.tabfocus_applies_to_xul",
|
|
|
|
nsIContent::sTabFocusModelAppliesToXUL);
|
2004-04-13 06:41:35 +00:00
|
|
|
}
|
2004-04-29 23:34:19 +00:00
|
|
|
prefBranch->AddObserver("accessibility.accesskeycausesactivation", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("accessibility.browsewithcaret", this, PR_TRUE);
|
2005-01-29 23:47:35 +00:00
|
|
|
prefBranch->AddObserver("accessibility.tabfocus_applies_to_xul", this, PR_TRUE);
|
2004-04-29 23:34:19 +00:00
|
|
|
prefBranch->AddObserver("nglayout.events.dispatchLeftClickOnly", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("ui.key.generalAccessKey", this, PR_TRUE);
|
2006-07-13 10:18:12 +00:00
|
|
|
prefBranch->AddObserver("ui.key.chromeAccess", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("ui.key.contentAccess", this, PR_TRUE);
|
2004-04-13 06:41:35 +00:00
|
|
|
#if 0
|
2004-04-29 23:34:19 +00:00
|
|
|
prefBranch->AddObserver("mousewheel.withaltkey.action", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withaltkey.numlines", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withaltkey.sysnumlines", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withcontrolkey.action", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withcontrolkey.numlines", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withcontrolkey.sysnumlines", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withnokey.action", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withnokey.numlines", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withnokey.sysnumlines", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withshiftkey.action", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withshiftkey.numlines", this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver("mousewheel.withshiftkey.sysnumlines", this, PR_TRUE);
|
2004-04-13 06:41:35 +00:00
|
|
|
#endif
|
2004-09-04 19:28:46 +00:00
|
|
|
|
|
|
|
prefBranch->AddObserver("dom.popup_allowed_events", this, PR_TRUE);
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
|
|
|
|
2004-04-13 06:41:35 +00:00
|
|
|
if (sTextfieldSelectModel == eTextfieldSelect_unset) {
|
2002-10-05 15:39:33 +00:00
|
|
|
nsCOMPtr<nsILookAndFeel> lookNFeel(do_GetService(kLookAndFeelCID));
|
|
|
|
PRInt32 selectTextfieldsOnKeyFocus = 0;
|
|
|
|
lookNFeel->GetMetric(nsILookAndFeel::eMetric_SelectTextfieldsOnKeyFocus,
|
|
|
|
selectTextfieldsOnKeyFocus);
|
|
|
|
sTextfieldSelectModel = selectTextfieldsOnKeyFocus ? eTextfieldSelect_auto:
|
|
|
|
eTextfieldSelect_manual;
|
|
|
|
}
|
|
|
|
|
2000-03-15 04:03:44 +00:00
|
|
|
return rv;
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 14:54:59 +00:00
|
|
|
nsEventStateManager::~nsEventStateManager()
|
|
|
|
{
|
2001-04-26 19:12:31 +00:00
|
|
|
#if CLICK_HOLD_CONTEXT_MENUS
|
2005-04-19 23:03:23 +00:00
|
|
|
KillClickHoldTimer();
|
2001-04-26 19:12:31 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-13 06:41:35 +00:00
|
|
|
--sESMInstanceCount;
|
|
|
|
if(sESMInstanceCount == 0) {
|
1999-12-01 09:09:46 +00:00
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
|
|
|
}
|
2000-03-15 04:03:44 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
delete mAccessKeys;
|
2000-05-16 10:22:20 +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.
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
2001-10-22 22:01:27 +00:00
|
|
|
do_GetService("@mozilla.org/observer-service;1", &rv);
|
2004-04-13 06:41:35 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
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()
|
|
|
|
{
|
2005-02-25 20:46:35 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch2> prefBranch =
|
2004-04-29 23:34:19 +00:00
|
|
|
do_QueryInterface(nsContentUtils::GetPrefBranch());
|
|
|
|
|
|
|
|
if (prefBranch) {
|
|
|
|
prefBranch->RemoveObserver("accessibility.accesskeycausesactivation", this);
|
|
|
|
prefBranch->RemoveObserver("accessibility.browsewithcaret", this);
|
2005-01-29 23:47:35 +00:00
|
|
|
prefBranch->RemoveObserver("accessibility.tabfocus_applies_to_xul", this);
|
2004-04-29 23:34:19 +00:00
|
|
|
prefBranch->RemoveObserver("nglayout.events.dispatchLeftClickOnly", this);
|
|
|
|
prefBranch->RemoveObserver("ui.key.generalAccessKey", this);
|
2006-07-13 10:18:12 +00:00
|
|
|
prefBranch->RemoveObserver("ui.key.chromeAccess", this);
|
|
|
|
prefBranch->RemoveObserver("ui.key.contentAccess", this);
|
2004-04-13 06:41:35 +00:00
|
|
|
#if 0
|
2004-04-29 23:34:19 +00:00
|
|
|
prefBranch->RemoveObserver("mousewheel.withshiftkey.action", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withshiftkey.numlines", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withshiftkey.sysnumlines", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withcontrolkey.action", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withcontrolkey.numlines", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withcontrolkey.sysnumlines", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withaltkey.action", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withaltkey.numlines", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withaltkey.sysnumlines", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withnokey.action", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withnokey.numlines", this);
|
|
|
|
prefBranch->RemoveObserver("mousewheel.withnokey.sysnumlines", this);
|
2004-04-13 06:41:35 +00:00
|
|
|
#endif
|
2004-09-04 19:28:46 +00:00
|
|
|
|
|
|
|
prefBranch->RemoveObserver("dom.popup_allowed_events", this);
|
2004-04-13 06:41:35 +00:00
|
|
|
}
|
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 =
|
|
|
|
nsContentUtils::GetBoolPref("accessibility.accesskeycausesactivation",
|
|
|
|
sKeyCausesActivation);
|
2004-05-22 22:15:22 +00:00
|
|
|
} else if (data.EqualsLiteral("accessibility.browsewithcaret")) {
|
2004-04-29 23:34:19 +00:00
|
|
|
ResetBrowseWithCaret();
|
2005-01-29 23:47:35 +00:00
|
|
|
} else if (data.EqualsLiteral("accessibility.tabfocus_applies_to_xul")) {
|
|
|
|
nsIContent::sTabFocusModelAppliesToXUL =
|
|
|
|
nsContentUtils::GetBoolPref("accessibility.tabfocus_applies_to_xul",
|
|
|
|
nsIContent::sTabFocusModelAppliesToXUL);
|
2004-05-22 22:15:22 +00:00
|
|
|
} else if (data.EqualsLiteral("nglayout.events.dispatchLeftClickOnly")) {
|
2004-04-29 23:34:19 +00:00
|
|
|
sLeftClickOnly =
|
|
|
|
nsContentUtils::GetBoolPref("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);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-09 19:04:13 +00:00
|
|
|
NS_IMPL_ISUPPORTS3(nsEventStateManager, nsIEventStateManager, nsIObserver, nsISupportsWeakReference)
|
1998-06-23 21:53:02 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
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
|
|
|
|
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:
|
|
|
|
switch (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button) {
|
|
|
|
case nsMouseEvent::eLeftButton:
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifndef XP_OS2
|
2006-11-16 21:35:39 +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);
|
|
|
|
mNormalLMouseEventInProcess = PR_TRUE;
|
|
|
|
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
|
2006-11-16 21:35:39 +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:
|
|
|
|
switch (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button) {
|
|
|
|
case nsMouseEvent::eLeftButton:
|
2001-03-30 04:45:40 +00:00
|
|
|
#ifdef CLICK_HOLD_CONTEXT_MENUS
|
2006-11-16 21:35:39 +00:00
|
|
|
KillClickHoldTimer();
|
2001-03-30 04:45:40 +00:00
|
|
|
#endif
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifndef XP_OS2
|
2006-11-16 21:35:39 +00:00
|
|
|
StopTrackingDragGesture();
|
2002-05-10 03:07:06 +00:00
|
|
|
#endif
|
2006-11-16 21:35:39 +00:00
|
|
|
mNormalLMouseEventInProcess = PR_FALSE;
|
|
|
|
case nsMouseEvent::eRightButton:
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifdef XP_OS2
|
2006-11-16 21:35:39 +00:00
|
|
|
StopTrackingDragGesture();
|
2002-05-10 03:07:06 +00:00
|
|
|
#endif
|
2006-11-16 21:35:39 +00:00
|
|
|
case nsMouseEvent::eMiddleButton:
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
|
|
|
}
|
1999-08-19 19:48:45 +00:00
|
|
|
break;
|
2005-02-23 21:46:43 +00:00
|
|
|
case NS_MOUSE_EXIT:
|
|
|
|
// If the event coordinate is within the bounds of the view,
|
2005-07-17 21:50:56 +00:00
|
|
|
// and this is not the top-level window, then it's not really
|
|
|
|
// an exit --- we may have traversed widget boundaries but
|
|
|
|
// we're still in our toplevel window.
|
|
|
|
// On the other hand, if we exit a toplevel window, then
|
|
|
|
// it's really an exit even if the mouse is still in the
|
|
|
|
// window bounds --- the mouse probably moved into some
|
|
|
|
// "on top" window.
|
|
|
|
{
|
|
|
|
nsMouseEvent* mouseEvent = NS_STATIC_CAST(nsMouseEvent*, aEvent);
|
2006-03-22 18:00:28 +00:00
|
|
|
nsIWidget* parentWidget = mouseEvent->widget->GetParent();
|
2005-08-23 03:57:07 +00:00
|
|
|
nsPoint eventPoint;
|
|
|
|
eventPoint = nsLayoutUtils::TranslateWidgetToView(aPresContext,
|
|
|
|
mouseEvent->widget,
|
|
|
|
mouseEvent->refPoint,
|
|
|
|
aView);
|
2005-07-17 21:50:56 +00:00
|
|
|
if (parentWidget &&
|
2005-08-23 03:57:07 +00:00
|
|
|
(aView->GetBounds() - aView->GetPosition()).Contains(eventPoint)) {
|
2005-07-17 21:50:56 +00:00
|
|
|
// treat it as a move so we don't generate spurious "exit"
|
|
|
|
// events Any necessary exit events will be generated by
|
|
|
|
// GenerateMouseEnterExit
|
|
|
|
aEvent->message = NS_MOUSE_MOVE;
|
|
|
|
// 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
|
|
|
#ifdef CLICK_HOLD_CONTEXT_MENUS
|
|
|
|
case NS_DRAGDROP_GESTURE:
|
|
|
|
// an external drag gesture event came in, not generated internally
|
|
|
|
// by Gecko. Make sure we get rid of the click-hold timer.
|
|
|
|
KillClickHoldTimer();
|
|
|
|
break;
|
|
|
|
#endif
|
1999-06-22 14:20:14 +00:00
|
|
|
case NS_DRAGDROP_OVER:
|
2000-04-24 04:41:27 +00:00
|
|
|
GenerateDragDropEnterExit(aPresContext, (nsGUIEvent*)aEvent);
|
1999-06-22 14:20:14 +00:00
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_GOTFOCUS:
|
1999-11-13 05:16:33 +00:00
|
|
|
{
|
2003-05-12 07:11:16 +00:00
|
|
|
// This is called when a child widget has received focus.
|
|
|
|
// We need to take care of sending a blur event for the previously
|
|
|
|
// focused content and document, then dispatching a focus
|
|
|
|
// event to the target content, its document, and its window.
|
2000-02-11 23:41:13 +00:00
|
|
|
|
2000-06-28 20:35:32 +00:00
|
|
|
EnsureDocument(aPresContext);
|
1999-12-08 20:55:45 +00:00
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
// If the document didn't change, then the only thing that could have
|
|
|
|
// changed is the focused content node. That's handled elsewhere
|
|
|
|
// (SetContentState and SendFocusBlur).
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
if (gLastFocusedDocument == mDocument)
|
2001-06-18 07:34:41 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
if (mDocument) {
|
2003-05-12 07:11:16 +00:00
|
|
|
if (gLastFocusedDocument && gLastFocusedPresContext) {
|
2005-07-30 20:57:07 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow =
|
2005-11-17 18:31:22 +00:00
|
|
|
gLastFocusedDocument->GetWindow();
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
// If the focus controller is already suppressed, it means that we
|
|
|
|
// are in the middle of an activate sequence. In this case, we do
|
|
|
|
// _not_ want to fire a blur on the previously focused content, since
|
|
|
|
// we will be focusing it again later when we receive the NS_ACTIVATE
|
|
|
|
// event. See bug 120209.
|
|
|
|
|
2005-07-02 22:58:22 +00:00
|
|
|
// Hold a strong ref to the focus controller, since we need
|
|
|
|
// it after event dispatch.
|
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
2003-05-12 07:11:16 +00:00
|
|
|
PRBool isAlreadySuppressed = PR_FALSE;
|
|
|
|
|
|
|
|
if (ourWindow) {
|
2004-05-03 21:48:36 +00:00
|
|
|
focusController = ourWindow->GetRootFocusController();
|
2003-05-12 07:11:16 +00:00
|
|
|
if (focusController) {
|
|
|
|
focusController->GetSuppressFocus(&isAlreadySuppressed);
|
|
|
|
focusController->SetSuppressFocus(PR_TRUE,
|
|
|
|
"NS_GOTFOCUS ESM Suppression");
|
2000-05-03 00:49:37 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!isAlreadySuppressed) {
|
|
|
|
|
|
|
|
// Fire the blur event on the previously focused document.
|
|
|
|
|
|
|
|
nsEventStatus blurstatus = nsEventStatus_eIgnore;
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEvent blurevent(PR_TRUE, NS_BLUR_CONTENT);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(gLastFocusedDocument,
|
|
|
|
gLastFocusedPresContext,
|
|
|
|
&blurevent, nsnull, &blurstatus);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
if (!mCurrentFocus && gLastFocusedContent) {
|
|
|
|
// We also need to blur the previously focused content node here,
|
|
|
|
// if we don't have a focused content node in this document.
|
|
|
|
// (SendFocusBlur isn't called in this case).
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> blurContent = gLastFocusedContent;
|
2006-03-07 17:08:51 +00:00
|
|
|
blurevent.target = nsnull;
|
|
|
|
nsEventDispatcher::Dispatch(gLastFocusedContent,
|
|
|
|
gLastFocusedPresContext,
|
|
|
|
&blurevent, nsnull, &blurstatus);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
// XXX bryner this isn't quite right -- it can result in
|
|
|
|
// firing two blur events on the content.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2006-03-07 17:08:51 +00:00
|
|
|
if (gLastFocusedContent) // could have changed in Dispatch
|
2003-07-28 21:17:26 +00:00
|
|
|
doc = gLastFocusedContent->GetDocument();
|
2003-05-12 07:11:16 +00:00
|
|
|
if (doc) {
|
2007-05-01 22:24:20 +00:00
|
|
|
nsIPresShell *shell = doc->GetPrimaryShell();
|
2003-05-12 07:11:16 +00:00
|
|
|
if (shell) {
|
2004-08-20 20:34:37 +00:00
|
|
|
nsCOMPtr<nsPresContext> oldPresContext =
|
|
|
|
shell->GetPresContext();
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
2004-02-27 17:17:37 +00:00
|
|
|
esm = oldPresContext->EventStateManager();
|
2003-05-12 07:11:16 +00:00
|
|
|
esm->SetFocusedContent(gLastFocusedContent);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(gLastFocusedContent,
|
|
|
|
oldPresContext,
|
|
|
|
&blurevent, nsnull, &blurstatus);
|
2003-05-12 07:11:16 +00:00
|
|
|
esm->SetFocusedContent(nsnull);
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
2001-04-24 22:52:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-14 21:49:34 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
if (focusController)
|
|
|
|
focusController->SetSuppressFocus(PR_FALSE,
|
|
|
|
"NS_GOTFOCUS ESM Suppression");
|
2000-04-14 21:49:34 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
// Now we should fire the focus event. We fire it on the document,
|
|
|
|
// then the content node, then the window.
|
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
if (window) {
|
2003-05-12 07:11:16 +00:00
|
|
|
// We don't want there to be a focused content node while we're
|
|
|
|
// dispatching the focus event.
|
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
nsCOMPtr<nsIContent> currentFocus = mCurrentFocus;
|
2003-05-12 07:11:16 +00:00
|
|
|
// "leak" this reference, but we take it back later
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(nsnull);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
nsIMEStateManager::OnChangeFocus(mPresContext, currentFocus);
|
2005-11-14 23:55:24 +00:00
|
|
|
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent focusevent(PR_TRUE, NS_FOCUS_CONTENT);
|
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
if (gLastFocusedDocument != mDocument) {
|
2006-03-07 17:08:51 +00:00
|
|
|
//XXXsmaug bubbling for now, because in the old event dispatching
|
|
|
|
// code focus event did bubble from document to window.
|
|
|
|
nsEventDispatcher::Dispatch(mDocument, aPresContext,
|
|
|
|
&focusevent, nsnull, &status);
|
2005-11-14 23:55:24 +00:00
|
|
|
if (currentFocus && currentFocus != gLastFocusedContent) {
|
2006-03-07 17:08:51 +00:00
|
|
|
// Clear the target so that Dispatch can set it back correctly.
|
|
|
|
focusevent.target = nsnull;
|
|
|
|
nsEventDispatcher::Dispatch(currentFocus, aPresContext,
|
|
|
|
&focusevent, nsnull, &status);
|
2005-11-14 23:55:24 +00:00
|
|
|
}
|
2000-06-29 05:27:05 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
// Clear the target so that Dispatch can set it back correctly.
|
|
|
|
focusevent.target = nsnull;
|
|
|
|
nsEventDispatcher::Dispatch(window, aPresContext, &focusevent,
|
|
|
|
nsnull, &status);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(currentFocus); // we kept this reference above
|
2000-06-29 05:27:05 +00:00
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
gLastFocusedContent = mCurrentFocus;
|
|
|
|
NS_IF_ADDREF(gLastFocusedContent);
|
1999-12-08 04:54:29 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2002-06-12 05:00:35 +00:00
|
|
|
// Try to keep the focus controllers and the globals in synch
|
2003-05-12 07:11:16 +00:00
|
|
|
if (gLastFocusedDocument && gLastFocusedDocument != mDocument) {
|
|
|
|
|
2004-05-03 21:48:36 +00:00
|
|
|
nsIFocusController *lastController = nsnull;
|
2005-11-17 18:31:22 +00:00
|
|
|
nsPIDOMWindow* lastWindow = gLastFocusedDocument->GetWindow();
|
2003-10-22 06:09:48 +00:00
|
|
|
if (lastWindow)
|
2004-05-03 21:48:36 +00:00
|
|
|
lastController = lastWindow->GetRootFocusController();
|
2002-06-12 05:00:35 +00:00
|
|
|
|
2004-05-03 21:48:36 +00:00
|
|
|
nsIFocusController *nextController = nsnull;
|
2005-11-17 18:31:22 +00:00
|
|
|
nsPIDOMWindow* nextWindow = mDocument->GetWindow();
|
2003-10-22 06:09:48 +00:00
|
|
|
if (nextWindow)
|
2004-05-03 21:48:36 +00:00
|
|
|
nextController = nextWindow->GetRootFocusController();
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
if (lastController != nextController && lastController && nextController)
|
2002-06-12 05:00:35 +00:00
|
|
|
lastController->SetActive(PR_FALSE);
|
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
|
|
|
gLastFocusedDocument = mDocument;
|
|
|
|
gLastFocusedPresContext = aPresContext;
|
|
|
|
NS_IF_ADDREF(gLastFocusedDocument);
|
1999-11-13 05:16:33 +00:00
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
ResetBrowseWithCaret();
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
|
|
|
|
1999-11-13 05:16:33 +00:00
|
|
|
break;
|
2001-02-15 05:07:46 +00:00
|
|
|
|
1999-11-13 05:16:33 +00:00
|
|
|
case NS_LOSTFOCUS:
|
|
|
|
{
|
2004-07-23 07:27:57 +00:00
|
|
|
// Hide the caret used in "browse with caret mode"
|
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
|
|
|
if (mBrowseWithCaret && mPresContext) {
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *presShell = mPresContext->GetPresShell();
|
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
|
|
|
if (presShell)
|
|
|
|
SetContentCaretVisible(presShell, mCurrentFocus, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
// If focus is going to another mozilla window, we wait for the
|
|
|
|
// focus event and fire a blur on the old focused content at that time.
|
|
|
|
// This allows "-moz-user-focus: ignore" to work.
|
|
|
|
|
2002-02-01 15:14:35 +00:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2003-05-12 07:11:16 +00:00
|
|
|
if (!NS_STATIC_CAST(nsFocusEvent*, aEvent)->isMozWindowTakingFocus) {
|
|
|
|
|
|
|
|
// This situation occurs when focus goes to a non-gecko child window
|
|
|
|
// in an embedding application. In this case we do fire a blur
|
|
|
|
// immediately.
|
|
|
|
|
2001-05-18 12:07:42 +00:00
|
|
|
EnsureDocument(aPresContext);
|
|
|
|
|
2005-11-17 18:31:22 +00:00
|
|
|
if (gLastFocusedContent && !gLastFocusedContent->IsInDoc()) {
|
|
|
|
NS_RELEASE(gLastFocusedContent);
|
2005-07-30 20:57:07 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
// Now fire blurs. We fire a blur on the focused document, element,
|
|
|
|
// and window.
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEvent event(PR_TRUE, NS_BLUR_CONTENT);
|
2001-05-18 12:07:42 +00:00
|
|
|
|
|
|
|
if (gLastFocusedDocument && gLastFocusedPresContext) {
|
|
|
|
if (gLastFocusedContent) {
|
2003-05-12 07:11:16 +00:00
|
|
|
// Retrieve this content node's pres context. it can be out of sync
|
|
|
|
// in the Ender widget case.
|
2003-07-28 21:17:26 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = gLastFocusedContent->GetDocument();
|
2001-05-18 12:07:42 +00:00
|
|
|
if (doc) {
|
2007-05-22 22:08:36 +00:00
|
|
|
nsIPresShell *shell = doc->GetPrimaryShell();
|
2001-05-18 12:07:42 +00:00
|
|
|
if (shell) {
|
2004-08-20 20:34:37 +00:00
|
|
|
nsCOMPtr<nsPresContext> oldPresContext =
|
|
|
|
shell->GetPresContext();
|
2001-05-18 12:07:42 +00:00
|
|
|
|
2004-02-27 17:43:15 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> esm =
|
|
|
|
oldPresContext->EventStateManager();
|
2001-05-18 12:07:42 +00:00
|
|
|
esm->SetFocusedContent(gLastFocusedContent);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(gLastFocusedContent, oldPresContext,
|
|
|
|
&event, nsnull, &status);
|
2001-05-18 12:07:42 +00:00
|
|
|
esm->SetFocusedContent(nsnull);
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fire blur on document and window
|
2003-05-12 07:11:16 +00:00
|
|
|
if (gLastFocusedDocument) {
|
|
|
|
// get the window here, in case the event causes
|
|
|
|
// gLastFocusedDocument to change.
|
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(gLastFocusedDocument->GetWindow());
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
event.target = nsnull;
|
|
|
|
nsEventDispatcher::Dispatch(gLastFocusedDocument,
|
|
|
|
gLastFocusedPresContext,
|
|
|
|
&event, nsnull, &status);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
if (window) {
|
2006-03-07 17:08:51 +00:00
|
|
|
event.target = nsnull;
|
|
|
|
nsEventDispatcher::Dispatch(window, gLastFocusedPresContext,
|
|
|
|
&event, nsnull, &status);
|
2005-11-28 23:56:44 +00:00
|
|
|
}
|
2001-05-18 12:07:42 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2001-05-18 12:07:42 +00:00
|
|
|
// Now clear our our global variables
|
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
|
|
|
gLastFocusedPresContext = nsnull;
|
2004-07-23 07:27:57 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-18 12:07:42 +00:00
|
|
|
#endif
|
2001-05-18 12:59:32 +00:00
|
|
|
}
|
1999-11-13 05:16:33 +00:00
|
|
|
break;
|
2001-02-15 05:07:46 +00:00
|
|
|
|
1999-11-13 05:16:33 +00:00
|
|
|
case NS_ACTIVATE:
|
1999-07-27 20:55:03 +00:00
|
|
|
{
|
2003-05-12 07:11:16 +00:00
|
|
|
// If we have a focus controller, and if it has a focused window and a
|
2000-02-11 23:41:13 +00:00
|
|
|
// focused element in its focus memory, then restore the focus to those
|
|
|
|
// objects.
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2000-06-28 20:35:32 +00:00
|
|
|
EnsureDocument(aPresContext);
|
2000-02-26 01:02:31 +00:00
|
|
|
|
2005-11-17 18:31:22 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> win = mDocument->GetWindow();
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
if (!win) {
|
|
|
|
NS_ERROR("win is null. this happens [often on xlib builds]. see bug #79213");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2005-07-02 22:58:22 +00:00
|
|
|
// Hold a strong ref to the focus controller, since we need
|
|
|
|
// it after event dispatch.
|
2005-07-30 20:57:07 +00:00
|
|
|
nsCOMPtr<nsIFocusController> focusController =
|
|
|
|
win->GetRootFocusController();
|
2003-05-12 07:11:16 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> focusedWindow;
|
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
if (focusController) {
|
2003-05-12 07:11:16 +00:00
|
|
|
// Obtain focus info from the focus controller.
|
2000-11-04 08:21:20 +00:00
|
|
|
focusController->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
|
|
|
focusController->GetFocusedElement(getter_AddRefs(focusedElement));
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
focusController->SetSuppressFocusScroll(PR_TRUE);
|
2001-04-20 00:16:39 +00:00
|
|
|
focusController->SetActive(PR_TRUE);
|
2000-02-11 23:41:13 +00:00
|
|
|
}
|
1999-11-13 05:16:33 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
if (!focusedWindow)
|
2004-05-03 21:48:36 +00:00
|
|
|
focusedWindow = win;
|
2000-02-11 23:41:13 +00:00
|
|
|
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(focusedWindow,"check why focusedWindow is null!!!");
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
// Focus the DOM window.
|
|
|
|
if (focusedWindow) {
|
2000-06-23 22:18:54 +00:00
|
|
|
focusedWindow->Focus();
|
2000-02-11 23:41:13 +00:00
|
|
|
|
2005-08-12 04:11:00 +00:00
|
|
|
nsCOMPtr<nsIDocument> document = GetDocumentFromWindow(focusedWindow);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2005-07-30 20:57:07 +00:00
|
|
|
if (document) {
|
2006-01-26 16:12:30 +00:00
|
|
|
// Use a strong ref to make sure that the shell is alive still
|
|
|
|
// when calling FrameSelection().
|
2007-05-01 22:24:20 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = document->GetPrimaryShell();
|
2002-02-20 07:22:55 +00:00
|
|
|
NS_ASSERTION(shell, "Focus events should not be getting thru when this is null!");
|
|
|
|
if (shell) {
|
2006-04-11 16:37:58 +00:00
|
|
|
nsPresContext* context = shell->GetPresContext();
|
|
|
|
nsIMEStateManager::OnActivate(context);
|
2002-02-20 07:22:55 +00:00
|
|
|
if (focusedElement) {
|
|
|
|
nsCOMPtr<nsIContent> focusContent = do_QueryInterface(focusedElement);
|
2001-11-15 13:15:54 +00:00
|
|
|
focusContent->SetFocus(context);
|
2006-04-11 16:37:58 +00:00
|
|
|
} else {
|
|
|
|
nsIMEStateManager::OnChangeFocus(context, nsnull);
|
2001-11-15 13:15:54 +00:00
|
|
|
}
|
2002-02-20 07:22:55 +00:00
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
// disable selection mousedown state on activation
|
2004-08-29 03:08:44 +00:00
|
|
|
shell->FrameSelection()->SetMouseDownState(PR_FALSE);
|
2000-07-28 21:48:08 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
}
|
2000-07-28 21:48:08 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
if (focusController) {
|
2005-09-06 22:27:41 +00:00
|
|
|
// Make sure the focus controller is up-to-date, since restoring
|
|
|
|
// focus memory may have caused focus to go elsewhere.
|
|
|
|
|
|
|
|
if (gLastFocusedDocument && gLastFocusedDocument == mDocument) {
|
|
|
|
nsCOMPtr<nsIDOMElement> focusElement = do_QueryInterface(mCurrentFocus);
|
|
|
|
focusController->SetFocusedElement(focusElement);
|
|
|
|
}
|
2003-05-27 22:47:21 +00:00
|
|
|
|
2000-09-15 07:02:58 +00:00
|
|
|
PRBool isSuppressed;
|
2000-11-04 08:21:20 +00:00
|
|
|
focusController->GetSuppressFocus(&isSuppressed);
|
2003-05-12 07:11:16 +00:00
|
|
|
while (isSuppressed) {
|
|
|
|
// Unsuppress and let the focus controller listen again.
|
|
|
|
focusController->SetSuppressFocus(PR_FALSE,
|
|
|
|
"Activation Suppression");
|
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
focusController->GetSuppressFocus(&isSuppressed);
|
2000-09-15 07:02:58 +00:00
|
|
|
}
|
2000-11-04 08:21:20 +00:00
|
|
|
focusController->SetSuppressFocusScroll(PR_FALSE);
|
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
|
|
|
}
|
1999-06-15 03:14:28 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
break;
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-11-13 05:16:33 +00:00
|
|
|
case NS_DEACTIVATE:
|
1999-07-27 20:55:03 +00:00
|
|
|
{
|
2000-06-28 20:35:32 +00:00
|
|
|
EnsureDocument(aPresContext);
|
2000-02-11 23:41:13 +00:00
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
nsIMEStateManager::OnDeactivate(aPresContext);
|
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow(mDocument->GetWindow());
|
2001-06-18 07:34:41 +00:00
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
// Suppress the focus controller for the duration of the
|
2000-02-11 23:41:13 +00:00
|
|
|
// de-activation. This will cause it to remember the last
|
|
|
|
// focused sub-window and sub-element for this top-level
|
|
|
|
// window.
|
|
|
|
|
2004-05-17 23:36:34 +00:00
|
|
|
nsCOMPtr<nsIFocusController> focusController =
|
2004-05-03 21:48:36 +00:00
|
|
|
GetFocusControllerForDocument(mDocument);
|
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
if (focusController)
|
|
|
|
focusController->SetSuppressFocus(PR_TRUE, "Deactivate Suppression");
|
|
|
|
|
|
|
|
// Now fire blurs. Blur the content, then the document, then the window.
|
|
|
|
|
2001-07-20 08:14:44 +00:00
|
|
|
if (gLastFocusedDocument && gLastFocusedDocument == mDocument) {
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEvent event(PR_TRUE, NS_BLUR_CONTENT);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
2000-02-11 23:41:13 +00:00
|
|
|
if (gLastFocusedContent) {
|
2007-05-01 22:24:20 +00:00
|
|
|
nsIPresShell *shell = gLastFocusedDocument->GetPrimaryShell();
|
2001-06-18 07:34:41 +00:00
|
|
|
if (shell) {
|
2004-08-20 20:34:37 +00:00
|
|
|
nsCOMPtr<nsPresContext> oldPresContext = shell->GetPresContext();
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2003-05-12 07:11:16 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
|
|
|
if (focusController)
|
|
|
|
focusController->GetFocusedElement(getter_AddRefs(focusedElement));
|
|
|
|
|
2001-06-18 07:34:41 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
2004-02-27 17:17:37 +00:00
|
|
|
esm = oldPresContext->EventStateManager();
|
2001-06-18 07:34:41 +00:00
|
|
|
esm->SetFocusedContent(gLastFocusedContent);
|
2003-05-12 07:11:16 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> focusedContent = do_QueryInterface(focusedElement);
|
|
|
|
if (focusedContent) {
|
|
|
|
// Blur the element.
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(focusedContent, oldPresContext,
|
|
|
|
&event, nsnull, &status);
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
|
|
|
|
2001-06-18 07:34:41 +00:00
|
|
|
esm->SetFocusedContent(nsnull);
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
2000-02-11 23:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fire blur on document and window
|
2006-03-07 17:08:51 +00:00
|
|
|
event.target = nsnull;
|
|
|
|
nsEventDispatcher::Dispatch(mDocument, aPresContext, &event, nsnull,
|
|
|
|
&status);
|
|
|
|
|
|
|
|
if (ourWindow) {
|
|
|
|
event.target = nsnull;
|
|
|
|
nsEventDispatcher::Dispatch(ourWindow, aPresContext, &event, nsnull,
|
|
|
|
&status);
|
|
|
|
}
|
2001-06-18 07:34:41 +00:00
|
|
|
|
2000-02-11 23:41:13 +00:00
|
|
|
// Now clear our our global variables
|
2000-03-21 00:47:19 +00:00
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
2000-02-11 23:41:13 +00:00
|
|
|
gLastFocusedPresContext = nsnull;
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
2000-02-11 23:41:13 +00:00
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
if (focusController) {
|
|
|
|
focusController->SetActive(PR_FALSE);
|
2001-04-18 01:41:20 +00:00
|
|
|
focusController->SetSuppressFocus(PR_FALSE, "Deactivate Suppression");
|
2000-02-29 03:54:49 +00:00
|
|
|
}
|
2003-05-12 07:11:16 +00:00
|
|
|
}
|
|
|
|
|
1999-05-18 23:51:04 +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
|
|
|
}
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
case NS_KEY_UP:
|
2007-02-20 14:57:52 +00:00
|
|
|
{
|
|
|
|
if (mCurrentFocus) {
|
|
|
|
mCurrentTargetContent = mCurrentFocus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-09-03 05:48:06 +00:00
|
|
|
case NS_MOUSE_SCROLL:
|
|
|
|
{
|
|
|
|
if (mCurrentFocus) {
|
|
|
|
mCurrentTargetContent = mCurrentFocus;
|
|
|
|
}
|
2007-02-20 14:57:52 +00:00
|
|
|
|
|
|
|
nsMouseScrollEvent* msEvent = NS_STATIC_CAST(nsMouseScrollEvent*, aEvent);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(actionslot, ".action");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(numlinesslot, ".numlines");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(sysnumlinesslot, ".sysnumlines");
|
|
|
|
|
|
|
|
nsCAutoString baseKey;
|
|
|
|
GetBasePrefKeyForMouseWheel(msEvent, baseKey);
|
|
|
|
|
|
|
|
nsCAutoString sysNumLinesKey(baseKey);
|
|
|
|
sysNumLinesKey.Append(sysnumlinesslot);
|
|
|
|
PRBool useSysNumLines = nsContentUtils::GetBoolPref(sysNumLinesKey.get());
|
|
|
|
|
|
|
|
nsCAutoString actionKey(baseKey);
|
|
|
|
actionKey.Append(actionslot);
|
|
|
|
PRInt32 action = nsContentUtils::GetIntPref(actionKey.get());
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
nsCAutoString numLinesKey(baseKey);
|
|
|
|
numLinesKey.Append(numlinesslot);
|
|
|
|
PRInt32 numLines = nsContentUtils::GetIntPref(numLinesKey.get());
|
|
|
|
|
|
|
|
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)
|
|
|
|
? nsIDOMNSUIEvent::SCROLL_PAGE_DOWN
|
|
|
|
: nsIDOMNSUIEvent::SCROLL_PAGE_UP;
|
|
|
|
}
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
void
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::HandleAccessKey(nsPresContext* aPresContext,
|
2002-09-03 05:48:06 +00:00
|
|
|
nsKeyEvent *aEvent,
|
|
|
|
nsEventStatus* aStatus,
|
2007-05-18 03:49:14 +00:00
|
|
|
nsIDocShellTreeItem* aBubbledFrom,
|
2006-07-13 10:18:12 +00:00
|
|
|
ProcessingAccessKeyState aAccessKeyState,
|
|
|
|
PRInt32 aModifierMask)
|
2002-09-03 05:48:06 +00:00
|
|
|
{
|
2006-07-13 10:18:12 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer = aPresContext->GetContainer();
|
2000-05-16 10:22:20 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
// Alt or other accesskey modifier is down, we may need to do an accesskey
|
2006-07-13 10:18:12 +00:00
|
|
|
if (mAccessKeys && aModifierMask == GetAccessModifierMask(pcContainer)) {
|
2002-09-03 05:48:06 +00:00
|
|
|
// Someone registered an accesskey. Find and activate it.
|
2005-07-03 12:19:26 +00:00
|
|
|
PRUint32 accKey = (IS_IN_BMP(aEvent->charCode)) ?
|
|
|
|
ToLowerCase((PRUnichar)aEvent->charCode) : aEvent->charCode;
|
2002-09-03 05:48:06 +00:00
|
|
|
|
|
|
|
nsVoidKey key(NS_INT32_TO_PTR(accKey));
|
|
|
|
if (mAccessKeys->Exists(&key)) {
|
2007-02-13 15:02:57 +00:00
|
|
|
nsCOMPtr<nsIContent> content =
|
|
|
|
dont_AddRef(NS_STATIC_CAST(nsIContent*, mAccessKeys->Get(&key)));
|
|
|
|
content->PerformAccesskey(sKeyCausesActivation,
|
|
|
|
NS_IS_TRUSTED_EVENT(aEvent));
|
2002-09-03 05:48:06 +00:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
2000-05-16 10:22:20 +00:00
|
|
|
}
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
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 =
|
|
|
|
NS_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 =
|
|
|
|
NS_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
|
|
|
#ifdef CLICK_HOLD_CONTEXT_MENUS
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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");
|
|
|
|
if ( mClickHoldTimer )
|
2003-11-19 01:20:56 +00:00
|
|
|
mClickHoldTimer->InitWithFuncCallback(sClickHoldCallback, this,
|
2004-07-23 07:27:57 +00:00
|
|
|
kClickHoldDelay,
|
2002-09-07 07:17:59 +00:00
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
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
|
|
|
{
|
|
|
|
nsEventStateManager* self = NS_STATIC_CAST(nsEventStateManager*, aESM);
|
|
|
|
if ( self )
|
|
|
|
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
|
|
|
{
|
2005-04-19 23:03:23 +00:00
|
|
|
if ( !mGestureDownContent )
|
2001-03-30 04:45:40 +00:00
|
|
|
return;
|
|
|
|
|
2005-08-13 00:20:46 +00:00
|
|
|
#ifdef XP_MACOSX
|
2002-03-26 00:59:03 +00:00
|
|
|
// hacky OS call to ensure that we don't show a context menu when the user
|
|
|
|
// let go of the mouse already, after a long, cpu-hogging operation prevented
|
|
|
|
// us from handling any OS events. See bug 117589.
|
|
|
|
if (!::StillDown())
|
|
|
|
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).
|
2005-03-30 02:14:41 +00:00
|
|
|
mCurrentTarget = nsnull;
|
2005-09-16 00:05:39 +00:00
|
|
|
nsIPresShell *shell = mPresContext->GetPresShell();
|
|
|
|
if ( shell ) {
|
|
|
|
mCurrentTarget = shell->GetPrimaryFrameFor(mGestureDownFrameOwner);
|
2005-03-30 02:14:41 +00:00
|
|
|
|
|
|
|
if ( mCurrentTarget ) {
|
2007-03-30 21:11:41 +00:00
|
|
|
NS_ASSERTION(mPresContext == mCurrentTarget->PresContext(),
|
2005-03-30 02:14:41 +00:00
|
|
|
"a prescontext returned a primary frame that didn't belong to it?");
|
2003-11-19 01:20:56 +00:00
|
|
|
|
|
|
|
// before dispatching, check that we're not on something that
|
|
|
|
// doesn't get a context menu
|
2005-03-30 02:14:41 +00:00
|
|
|
nsIAtom *tag = mGestureDownContent->Tag();
|
2001-03-30 04:45:40 +00:00
|
|
|
PRBool allowedToDispatch = PR_TRUE;
|
|
|
|
|
2006-05-05 06:52:21 +00:00
|
|
|
if (mGestureDownContent->IsNodeOfType(nsINode::eXUL)) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (tag == nsGkAtoms::scrollbar ||
|
|
|
|
tag == nsGkAtoms::scrollbarbutton ||
|
|
|
|
tag == nsGkAtoms::button)
|
2003-11-19 01:20:56 +00:00
|
|
|
allowedToDispatch = PR_FALSE;
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (tag == nsGkAtoms::toolbarbutton) {
|
2003-11-19 01:20:56 +00:00
|
|
|
// a <toolbarbutton> that has the container attribute set
|
|
|
|
// will already have its own dropdown.
|
2006-01-18 04:09:33 +00:00
|
|
|
if (nsContentUtils::HasNonEmptyAttr(mGestureDownContent,
|
2006-12-26 17:47:52 +00:00
|
|
|
kNameSpaceID_None, nsGkAtoms::container)) {
|
2005-07-25 21:41:56 +00:00
|
|
|
allowedToDispatch = PR_FALSE;
|
2006-01-18 04:09:33 +00:00
|
|
|
} else {
|
|
|
|
// If the toolbar button has an open menu, don't attempt to open
|
|
|
|
// a second menu
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mGestureDownContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::open,
|
|
|
|
nsGkAtoms::_true, eCaseMatters)) {
|
2006-01-18 04:09:33 +00:00
|
|
|
allowedToDispatch = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-03-31 23:32:14 +00:00
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
2006-05-05 06:52:21 +00:00
|
|
|
else if (mGestureDownContent->IsNodeOfType(nsINode::eHTML)) {
|
2005-03-30 02:14:41 +00:00
|
|
|
nsCOMPtr<nsIFormControl> formCtrl(do_QueryInterface(mGestureDownContent));
|
2003-11-19 01:20:56 +00:00
|
|
|
|
|
|
|
if (formCtrl) {
|
|
|
|
// of all form controls, only ones dealing with text are
|
|
|
|
// allowed to have context menus
|
2003-11-19 02:23:25 +00:00
|
|
|
PRInt32 type = formCtrl->GetType();
|
2003-11-19 01:20:56 +00:00
|
|
|
|
|
|
|
allowedToDispatch = (type == NS_FORM_INPUT_TEXT ||
|
|
|
|
type == NS_FORM_INPUT_PASSWORD ||
|
|
|
|
type == NS_FORM_INPUT_FILE ||
|
|
|
|
type == NS_FORM_TEXTAREA);
|
|
|
|
}
|
2006-12-26 17:47:52 +00:00
|
|
|
else if (tag == nsGkAtoms::applet ||
|
|
|
|
tag == nsGkAtoms::embed ||
|
|
|
|
tag == nsGkAtoms::object) {
|
2002-03-31 17:38:52 +00:00
|
|
|
allowedToDispatch = PR_FALSE;
|
2003-11-19 01:20:56 +00:00
|
|
|
}
|
2002-03-31 17:38:52 +00:00
|
|
|
}
|
2003-11-19 01:20:56 +00:00
|
|
|
|
|
|
|
if (allowedToDispatch) {
|
2005-07-15 00:44:28 +00:00
|
|
|
// make sure the widget sticks around
|
|
|
|
nsCOMPtr<nsIWidget> targetWidget(mCurrentTarget->GetWindow());
|
|
|
|
// init the event while mCurrentTarget is still good
|
|
|
|
nsMouseEvent event(PR_TRUE, NS_CONTEXTMENU,
|
|
|
|
targetWidget,
|
|
|
|
nsMouseEvent::eReal);
|
|
|
|
event.clickCount = 1;
|
|
|
|
FillInEventFromGestureDown(&event);
|
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
// stop selection tracking, we're in control now
|
2006-04-26 01:57:22 +00:00
|
|
|
if (mCurrentTarget)
|
|
|
|
{
|
|
|
|
nsFrameSelection* frameSel = mCurrentTarget->GetFrameSelection();
|
|
|
|
|
|
|
|
if (frameSel && frameSel->GetMouseDownState()) {
|
2005-07-15 00:44:28 +00:00
|
|
|
// note that this can cause selection changed events to fire if we're in
|
|
|
|
// a text field, which will null out mCurrentTarget
|
2001-03-30 04:45:40 +00:00
|
|
|
frameSel->SetMouseDownState(PR_FALSE);
|
2005-07-15 00:44:28 +00:00
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
// dispatch to DOM
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(mGestureDownContent, mPresContext, &event,
|
|
|
|
nsnull, &status);
|
2002-05-21 00:00:46 +00:00
|
|
|
|
2005-03-30 02:14:41 +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
|
2005-06-28 21:40:15 +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
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
//
|
2001-03-30 04:45:40 +00:00
|
|
|
// We also use this to track click-hold context menus on mac. When the mouse goes down,
|
|
|
|
// 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
|
|
|
{
|
2004-06-22 04:32:52 +00:00
|
|
|
// Note that |inDownEvent| could be either a mouse down event or a
|
|
|
|
// synthesized mouse move event.
|
2005-03-30 02:14:41 +00:00
|
|
|
nsRect screenPt;
|
|
|
|
inDownEvent->widget->WidgetToScreen(nsRect(inDownEvent->refPoint, nsSize(1, 1)),
|
|
|
|
screenPt);
|
|
|
|
mGestureDownPoint = screenPt.TopLeft();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
#ifdef CLICK_HOLD_CONTEXT_MENUS
|
|
|
|
// fire off a timer to track click-hold
|
2006-04-08 10:11:19 +00:00
|
|
|
if (nsContentUtils::GetBoolPref("ui.click_hold_context_menus", PR_TRUE))
|
|
|
|
CreateClickHoldTimer ( aPresContext, inDownFrame, inDownEvent );
|
2001-03-30 04:45:40 +00:00
|
|
|
#endif
|
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
|
|
|
{
|
|
|
|
NS_ASSERTION(aEvent->widget == mCurrentTarget->GetWindow(),
|
|
|
|
"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
|
|
|
|
nsRect tmpRect(0, 0, 1, 1);
|
|
|
|
aEvent->widget->WidgetToScreen(tmpRect, tmpRect);
|
|
|
|
aEvent->refPoint = mGestureDownPoint - tmpRect.TopLeft();
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
// Note that when the mouse enters a new child window with its own view, the event's
|
|
|
|
// coordinates will be in relation to the origin of the inner child window, which could
|
|
|
|
// either be very different from that of the mouse coords of the mouse down and trigger
|
2004-07-23 07:27:57 +00:00
|
|
|
// a drag too early, or very similar which might not trigger a drag.
|
1999-08-19 19:48:45 +00:00
|
|
|
//
|
|
|
|
// Do we need to do anything about this? Let's wait and see.
|
|
|
|
//
|
|
|
|
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.");
|
1999-08-19 19:48:45 +00:00
|
|
|
if ( IsTrackingDragGesture() ) {
|
2005-08-22 22:24:29 +00:00
|
|
|
mCurrentTarget = aPresContext->GetPresShell()->GetPrimaryFrameFor(mGestureDownFrameOwner);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
nsFrameSelection* frameSel = mCurrentTarget->GetFrameSelection();
|
|
|
|
if (frameSel && frameSel->GetMouseDownState()) {
|
2001-03-30 04:45:40 +00:00
|
|
|
StopTrackingDragGesture();
|
|
|
|
return;
|
2000-05-25 20:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2005-03-30 02:14:41 +00:00
|
|
|
nsRect tmpRect;
|
|
|
|
aEvent->widget->WidgetToScreen(nsRect(aEvent->refPoint, nsSize(1, 1)),
|
|
|
|
tmpRect);
|
|
|
|
nsPoint pt = tmpRect.TopLeft();
|
|
|
|
if (PR_ABS(pt.x - mGestureDownPoint.x) > pixelThresholdX ||
|
|
|
|
PR_ABS(pt.y - mGestureDownPoint.y) > pixelThresholdY) {
|
2001-03-30 04:45:40 +00:00
|
|
|
#ifdef CLICK_HOLD_CONTEXT_MENUS
|
|
|
|
// stop the click-hold before we fire off the drag gesture, in case
|
|
|
|
// it takes a long time
|
|
|
|
KillClickHoldTimer();
|
|
|
|
#endif
|
|
|
|
|
2005-04-18 00:48:59 +00:00
|
|
|
nsCOMPtr<nsIContent> targetContent = mGestureDownContent;
|
|
|
|
// Stop tracking the drag gesture now. This should stop us from
|
|
|
|
// reentering GenerateDragGesture inside DOM event processing.
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
|
2007-04-12 04:37:39 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = mCurrentTarget->GetWindow();
|
|
|
|
|
2003-04-19 00:46:28 +00:00
|
|
|
// get the widget from the target frame
|
2007-04-12 04:37:39 +00:00
|
|
|
nsMouseEvent startEvent(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_START,
|
|
|
|
widget, nsMouseEvent::eReal);
|
|
|
|
FillInEventFromGestureDown(&startEvent);
|
|
|
|
|
|
|
|
nsMouseEvent gestureEvent(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_GESTURE,
|
|
|
|
widget, nsMouseEvent::eReal);
|
|
|
|
FillInEventFromGestureDown(&gestureEvent);
|
1999-08-19 19:48:45 +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
|
|
|
|
2007-04-12 04:37:39 +00:00
|
|
|
// Dispatch both the dragstart and draggesture events to the DOM
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEventDispatcher::Dispatch(targetContent, aPresContext, &startEvent, nsnull,
|
2006-03-07 17:08:51 +00:00
|
|
|
&status);
|
2005-03-30 02:14:41 +00:00
|
|
|
|
2007-04-12 04:37:39 +00:00
|
|
|
if (status != nsEventStatus_eConsumeNoDefault) {
|
|
|
|
status = nsEventStatus_eIgnore;
|
|
|
|
nsEventDispatcher::Dispatch(targetContent, aPresContext, &gestureEvent, nsnull,
|
|
|
|
&status);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2000-05-15 02:10:11 +00:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::ChangeTextSize(PRInt32 change)
|
|
|
|
{
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!gLastFocusedDocument) return NS_ERROR_FAILURE;
|
|
|
|
|
2005-11-17 18:31:22 +00:00
|
|
|
nsPIDOMWindow* ourWindow = gLastFocusedDocument->GetWindow();
|
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
|
|
|
|
2007-05-01 22:24:20 +00:00
|
|
|
nsIPresShell *presShell = doc->GetPrimaryShell();
|
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
|
|
|
|
|
|
|
float textzoom;
|
|
|
|
mv->GetTextZoom(&textzoom);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
textzoom += ((float)change) / 10;
|
2001-01-05 23:06:09 +00:00
|
|
|
if (textzoom > 0 && textzoom <= 20)
|
|
|
|
mv->SetTextZoom(textzoom);
|
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
|
|
|
|
nsEventStateManager::DoScrollTextsize(nsIFrame *aTargetFrame,
|
|
|
|
PRInt32 adjustment)
|
|
|
|
{
|
|
|
|
// 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) &&
|
|
|
|
!content->IsNodeOfType(nsINode::eXUL))
|
2004-04-19 15:48:14 +00:00
|
|
|
{
|
|
|
|
// positive adjustment to increase text size, non-positive to decrease
|
|
|
|
ChangeTextSize((adjustment > 0) ? 1 : -1);
|
|
|
|
}
|
|
|
|
}
|
2001-02-15 22:07:06 +00:00
|
|
|
|
2006-02-01 19:55:35 +00:00
|
|
|
static nsIFrame*
|
|
|
|
GetParentFrameToScroll(nsPresContext* aPresContext, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aPresContext || !aFrame)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
if (aFrame->GetStyleDisplay()->mPosition == NS_STYLE_POSITION_FIXED)
|
|
|
|
return aPresContext->GetPresShell()->GetRootScrollFrame();
|
|
|
|
|
|
|
|
return aFrame->GetParent();
|
|
|
|
}
|
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::DoScrollText(nsPresContext* aPresContext,
|
2004-04-19 15:48:14 +00:00
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsInputEvent* aEvent,
|
|
|
|
PRInt32 aNumLines,
|
|
|
|
PRBool aScrollHorizontal,
|
2006-07-20 15:38:43 +00:00
|
|
|
ScrollQuantity aScrollQuantity)
|
2000-12-09 07:28:19 +00:00
|
|
|
{
|
2006-07-12 04:15:42 +00:00
|
|
|
nsIScrollableView* scrollView = nsnull;
|
2004-08-07 14:30:30 +00:00
|
|
|
nsIFrame* scrollFrame = aTargetFrame;
|
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) {
|
|
|
|
nsCOMPtr<nsIScrollableViewProvider> svp =
|
|
|
|
do_QueryInterface(lastScrollFrame);
|
|
|
|
if (svp) {
|
|
|
|
scrollView = svp->GetScrollableView();
|
|
|
|
nsMouseWheelTransaction::UpdateTransaction();
|
|
|
|
} 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;
|
|
|
|
scrollFrame = GetParentFrameToScroll(aPresContext, scrollFrame)) {
|
2004-08-07 14:30:30 +00:00
|
|
|
// Check whether the frame wants to provide us with a scrollable view.
|
|
|
|
scrollView = nsnull;
|
|
|
|
nsCOMPtr<nsIScrollableViewProvider> svp = do_QueryInterface(scrollFrame);
|
|
|
|
if (svp) {
|
2004-09-06 02:44:43 +00:00
|
|
|
scrollView = svp->GetScrollableView();
|
2004-08-07 14:30:30 +00:00
|
|
|
}
|
|
|
|
if (!scrollView) {
|
2004-10-09 05:15:08 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresContext::ScrollbarStyles ss =
|
|
|
|
nsLayoutUtils::ScrollbarStylesOfView(scrollView);
|
|
|
|
if (NS_STYLE_OVERFLOW_HIDDEN ==
|
|
|
|
(aScrollHorizontal ? 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.
|
2003-08-25 21:47:58 +00:00
|
|
|
nscoord lineHeight;
|
2004-08-07 14:30:30 +00:00
|
|
|
scrollView->GetLineHeight(&lineHeight);
|
2003-08-25 21:47:58 +00:00
|
|
|
|
2004-08-07 14:30:30 +00:00
|
|
|
if (lineHeight != 0) {
|
2005-07-07 15:53:07 +00:00
|
|
|
PRBool canScroll;
|
|
|
|
nsresult rv = scrollView->CanScroll(aScrollHorizontal,
|
|
|
|
(aNumLines > 0), canScroll);
|
2006-07-12 04:15:42 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && canScroll) {
|
|
|
|
passToParent = PR_FALSE;
|
|
|
|
nsMouseWheelTransaction::BeginTransaction(scrollFrame, aEvent);
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2004-08-07 14:30:30 +00:00
|
|
|
// Comboboxes need special care.
|
2006-02-27 04:13:51 +00:00
|
|
|
nsIComboboxControlFrame* comboBox = nsnull;
|
|
|
|
CallQueryInterface(scrollFrame, &comboBox);
|
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;
|
|
|
|
scrollView = 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).
|
|
|
|
passToParent = PR_TRUE;
|
2003-04-15 13:17:36 +00:00
|
|
|
}
|
2004-08-07 14:30:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2004-08-07 14:30:30 +00:00
|
|
|
if (!passToParent && scrollView) {
|
|
|
|
PRInt32 scrollX = 0;
|
|
|
|
PRInt32 scrollY = aNumLines;
|
|
|
|
|
2006-07-20 15:38:43 +00:00
|
|
|
if (aScrollQuantity == eScrollByPage)
|
2004-08-07 14:30:30 +00:00
|
|
|
scrollY = (scrollY > 0) ? 1 : -1;
|
|
|
|
|
|
|
|
if (aScrollHorizontal) {
|
|
|
|
scrollX = scrollY;
|
|
|
|
scrollY = 0;
|
2003-04-15 13:17:36 +00:00
|
|
|
}
|
2004-08-07 14:30:30 +00:00
|
|
|
|
2006-07-20 15:38:43 +00:00
|
|
|
if (aScrollQuantity == eScrollByPage)
|
2004-08-07 14:30:30 +00:00
|
|
|
scrollView->ScrollByPages(scrollX, scrollY);
|
2006-07-20 15:38:43 +00:00
|
|
|
else if (aScrollQuantity == eScrollByPixel)
|
|
|
|
scrollView->ScrollByPixels(scrollX, scrollY);
|
2004-08-07 14:30:30 +00:00
|
|
|
else
|
|
|
|
scrollView->ScrollByLines(scrollX, scrollY);
|
2001-09-07 21:00:57 +00:00
|
|
|
|
2004-09-20 22:25:07 +00:00
|
|
|
ForceViewUpdate(scrollView->View());
|
2004-08-07 14:30:30 +00:00
|
|
|
}
|
2001-09-07 21:00:57 +00:00
|
|
|
if (passToParent) {
|
2000-12-09 07:28:19 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsIFrame* newFrame = nsnull;
|
2004-07-31 23:15:21 +00:00
|
|
|
nsCOMPtr<nsPresContext> newPresContext;
|
2004-04-19 15:48:14 +00:00
|
|
|
rv = GetParentScrollingView(aEvent, aPresContext, newFrame,
|
2000-12-09 07:28:19 +00:00
|
|
|
*getter_AddRefs(newPresContext));
|
2002-04-17 04:17:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && newFrame)
|
2004-04-19 15:48:14 +00:00
|
|
|
return DoScrollText(newPresContext, newFrame, aEvent, aNumLines,
|
2006-07-20 15:38:43 +00:00
|
|
|
aScrollHorizontal, aScrollQuantity);
|
2000-12-09 07:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-04-19 15:48:14 +00:00
|
|
|
nsEventStateManager::GetParentScrollingView(nsInputEvent *aEvent,
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* aPresContext,
|
2000-12-09 07:28:19 +00:00
|
|
|
nsIFrame* &targetOuterFrame,
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* &presCtxOuter)
|
2000-12-09 07:28:19 +00:00
|
|
|
{
|
2002-04-17 04:17:16 +00:00
|
|
|
targetOuterFrame = nsnull;
|
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
if (!aEvent) return NS_ERROR_FAILURE;
|
|
|
|
if (!aPresContext) return NS_ERROR_FAILURE;
|
|
|
|
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = aPresContext->PresShell()->GetDocument();
|
2002-04-17 04:17:16 +00:00
|
|
|
NS_ASSERTION(doc, "No document in prescontext!");
|
2001-09-07 21:00:57 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIDocument *parentDoc = doc->GetParentDocument();
|
2001-09-07 21:00:57 +00:00
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
if (!parentDoc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-09-07 21:00:57 +00:00
|
|
|
|
2005-12-21 14:37:24 +00:00
|
|
|
nsIPresShell *pPresShell = nsnull;
|
2007-05-22 21:45:03 +00:00
|
|
|
nsPresShellIterator iter(parentDoc);
|
|
|
|
nsCOMPtr<nsIPresShell> tmpPresShell;
|
|
|
|
while ((tmpPresShell = iter.GetNextShell())) {
|
2005-12-21 14:37:24 +00:00
|
|
|
NS_ENSURE_TRUE(tmpPresShell->GetPresContext(), NS_ERROR_FAILURE);
|
|
|
|
if (tmpPresShell->GetPresContext()->Type() == aPresContext->Type()) {
|
|
|
|
pPresShell = tmpPresShell;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-04-11 01:48:48 +00:00
|
|
|
if (!pPresShell)
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-09-07 21:00:57 +00:00
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
/* now find the content node in our parent docshell's document that
|
|
|
|
corresponds to our docshell */
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIContent *frameContent = parentDoc->FindContentForSubDocument(doc);
|
2002-04-17 04:17:16 +00:00
|
|
|
NS_ENSURE_TRUE(frameContent, NS_ERROR_FAILURE);
|
2001-09-07 21:00:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
get this content node's frame, and use it as the new event target,
|
|
|
|
so the event can be processed in the parent docshell.
|
|
|
|
Note that we don't actually need to translate the event coordinates
|
2004-04-19 15:48:14 +00:00
|
|
|
because they are not used by DoScrollText().
|
2001-09-07 21:00:57 +00:00
|
|
|
*/
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2005-08-22 22:24:29 +00:00
|
|
|
nsIFrame* frameFrame = pPresShell->GetPrimaryFrameFor(frameContent);
|
2001-09-07 21:00:57 +00:00
|
|
|
if (!frameFrame) return NS_ERROR_FAILURE;
|
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
NS_IF_ADDREF(presCtxOuter = pPresShell->GetPresContext());
|
2001-09-07 21:00:57 +00:00
|
|
|
targetOuterFrame = frameFrame;
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
NS_IMETHODIMP
|
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-03-24 09:48:17 +00:00
|
|
|
// All the events we handle below require a frame.
|
2007-03-24 09:45:01 +00:00
|
|
|
if (!mCurrentTarget) {
|
|
|
|
if (NS_EVENT_NEEDS_FRAME(aEvent)) {
|
|
|
|
NS_ERROR("Null frame for an event that requires a frame");
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2006-11-16 21:35:39 +00:00
|
|
|
if (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton &&
|
|
|
|
!mNormalLMouseEventInProcess) {
|
2002-02-20 07:22:55 +00:00
|
|
|
//Our state is out of whack. We got a mouseup while still processing
|
|
|
|
//the mousedown. Kill View-level mouse capture or it'll stay stuck
|
|
|
|
if (aView) {
|
2003-08-06 03:07:12 +00:00
|
|
|
nsIViewManager* viewMan = aView->GetViewManager();
|
2002-02-20 07:22:55 +00:00
|
|
|
if (viewMan) {
|
|
|
|
nsIView* grabbingView;
|
|
|
|
viewMan->GetMouseEventGrabber(grabbingView);
|
|
|
|
if (grabbingView == aView) {
|
|
|
|
PRBool result;
|
|
|
|
viewMan->GrabMouseEvents(nsnull, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
1999-09-30 11:40:42 +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);
|
|
|
|
}
|
1999-08-24 00:42:38 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
nsIFrame* currFrame = mCurrentTarget;
|
2003-08-06 03:07:12 +00:00
|
|
|
nsIContent* activeContent = nsnull;
|
2000-09-19 01:24:44 +00:00
|
|
|
if (mCurrentTarget)
|
2003-08-06 03:07:12 +00:00
|
|
|
activeContent = mCurrentTarget->GetContent();
|
2000-09-19 01:24:44 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
// Look for the nearest enclosing focusable frame.
|
|
|
|
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
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
if (newFocus && currFrame)
|
2004-10-29 13:40:25 +00:00
|
|
|
ChangeFocusWith(newFocus, eEventFocusedByMouse);
|
2001-05-22 23:52:17 +00:00
|
|
|
else if (!suppressBlur) {
|
2001-08-14 00:44:13 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
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.
|
2006-11-16 21:35:39 +00:00
|
|
|
if (NS_STATIC_CAST(nsMouseEvent*, aEvent)->button !=
|
|
|
|
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
|
|
|
}
|
2001-06-20 05:46:38 +00:00
|
|
|
SetContentState(activeContent, NS_EVENT_STATE_ACTIVE);
|
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();
|
2000-09-13 01:45:23 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_ACTIVE);
|
2001-06-20 06:12:19 +00:00
|
|
|
if (!mCurrentTarget) {
|
|
|
|
nsIFrame* targ;
|
|
|
|
GetEventTarget(&targ);
|
|
|
|
if (!targ) return NS_ERROR_FAILURE;
|
|
|
|
}
|
2006-05-12 03:49:38 +00:00
|
|
|
ret = CheckForAndDispatchClick(presContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
nsIPresShell *shell = presContext->GetPresShell();
|
2003-12-21 05:36:36 +00:00
|
|
|
if (shell) {
|
2004-08-29 03:08:44 +00:00
|
|
|
shell->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:
|
1999-11-24 06:03:41 +00:00
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
2000-03-15 04:03:44 +00:00
|
|
|
|
2004-04-19 15:48:14 +00:00
|
|
|
// Build the preference keys, based on the event properties.
|
2000-01-06 06:22:00 +00:00
|
|
|
nsMouseScrollEvent *msEvent = (nsMouseScrollEvent*) aEvent;
|
2004-04-19 15:48:14 +00:00
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(actionslot, ".action");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(sysnumlinesslot, ".sysnumlines");
|
|
|
|
|
2007-02-20 14:57:52 +00:00
|
|
|
nsCAutoString baseKey;
|
|
|
|
GetBasePrefKeyForMouseWheel(msEvent, baseKey);
|
2004-04-19 15:48:14 +00:00
|
|
|
|
|
|
|
// Extract the preferences
|
|
|
|
nsCAutoString actionKey(baseKey);
|
|
|
|
actionKey.Append(actionslot);
|
|
|
|
|
|
|
|
nsCAutoString sysNumLinesKey(baseKey);
|
|
|
|
sysNumLinesKey.Append(sysnumlinesslot);
|
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
PRInt32 action = nsContentUtils::GetIntPref(actionKey.get());
|
|
|
|
PRBool useSysNumLines =
|
|
|
|
nsContentUtils::GetBoolPref(sysNumLinesKey.get());
|
2004-04-19 15:48:14 +00:00
|
|
|
|
|
|
|
if (useSysNumLines) {
|
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)
|
|
|
|
action = MOUSE_SCROLL_PAGE;
|
2006-07-20 15:38:43 +00:00
|
|
|
else if (msEvent->scrollFlags & nsMouseScrollEvent::kIsPixels)
|
|
|
|
action = MOUSE_SCROLL_PIXELS;
|
2000-01-06 06:22:00 +00:00
|
|
|
}
|
1999-11-21 01:46:41 +00:00
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
switch (action) {
|
|
|
|
case MOUSE_SCROLL_N_LINES:
|
2006-07-20 15:38:43 +00:00
|
|
|
{
|
2007-02-20 14:57:52 +00:00
|
|
|
DoScrollText(presContext, aTargetFrame, msEvent, msEvent->delta,
|
2006-07-20 15:38:43 +00:00
|
|
|
(msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal),
|
|
|
|
eScrollByLine);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-05-15 02:10:11 +00:00
|
|
|
case MOUSE_SCROLL_PAGE:
|
2000-01-06 06:22:00 +00:00
|
|
|
{
|
2007-02-20 14:57:52 +00:00
|
|
|
DoScrollText(presContext, aTargetFrame, msEvent, msEvent->delta,
|
2004-04-19 15:48:14 +00:00
|
|
|
(msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal),
|
2006-07-20 15:38:43 +00:00
|
|
|
eScrollByPage);
|
2000-01-06 06:22:00 +00:00
|
|
|
}
|
2006-07-20 15:38:43 +00:00
|
|
|
break;
|
2000-04-01 20:09:54 +00:00
|
|
|
|
2006-07-20 15:38:43 +00:00
|
|
|
case MOUSE_SCROLL_PIXELS:
|
|
|
|
{
|
2007-02-20 14:57:52 +00:00
|
|
|
DoScrollText(presContext, aTargetFrame, msEvent, msEvent->delta,
|
2006-07-20 15:38:43 +00:00
|
|
|
(msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal),
|
|
|
|
eScrollByPixel);
|
|
|
|
}
|
2000-01-16 05:30:49 +00:00
|
|
|
break;
|
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
case MOUSE_SCROLL_HISTORY:
|
|
|
|
{
|
2007-02-20 14:57:52 +00:00
|
|
|
DoScrollHistory(msEvent->delta);
|
2000-01-06 06:22:00 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-02-17 23:52:45 +00:00
|
|
|
|
2000-04-25 06:25:43 +00:00
|
|
|
case MOUSE_SCROLL_TEXTSIZE:
|
2002-10-01 01:28:51 +00:00
|
|
|
{
|
2007-02-20 14:57:52 +00:00
|
|
|
DoScrollTextsize(aTargetFrame, msEvent->delta);
|
2002-10-01 01:28:51 +00:00
|
|
|
}
|
2000-04-25 06:25:43 +00:00
|
|
|
break;
|
2004-04-19 15:48:14 +00:00
|
|
|
|
|
|
|
default: // Including -1 (do nothing)
|
|
|
|
break;
|
1999-11-21 01:46:41 +00:00
|
|
|
}
|
2000-02-17 23:52:45 +00:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
1999-11-21 01:46:41 +00:00
|
|
|
}
|
1999-12-28 23:02:38 +00:00
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
break;
|
2001-02-15 05:07:46 +00:00
|
|
|
|
1999-11-12 01:02:14 +00:00
|
|
|
case NS_DRAGDROP_DROP:
|
2007-04-12 04:37:39 +00:00
|
|
|
{
|
|
|
|
// now fire the dragdrop event, for compatibility with XUL
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
|
|
|
mCurrentTarget->GetContentForEvent(presContext, aEvent,
|
|
|
|
getter_AddRefs(targetContent));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget = mCurrentTarget->GetWindow();
|
|
|
|
nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), NS_DRAGDROP_DRAGDROP,
|
|
|
|
widget, nsMouseEvent::eReal);
|
|
|
|
|
|
|
|
nsMouseEvent* mouseEvent = NS_STATIC_CAST(nsMouseEvent*, aEvent);
|
|
|
|
event.refPoint = mouseEvent->refPoint;
|
|
|
|
event.isShift = mouseEvent->isShift;
|
|
|
|
event.isControl = mouseEvent->isControl;
|
|
|
|
event.isAlt = mouseEvent->isAlt;
|
|
|
|
event.isMeta = mouseEvent->isMeta;
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
presShell->HandleEventWithTarget(&event, mCurrentTarget,
|
|
|
|
targetContent, &status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fall through and call GenerateDragDropEnterExit
|
|
|
|
}
|
|
|
|
|
1999-11-12 01:02:14 +00:00
|
|
|
case NS_DRAGDROP_EXIT:
|
|
|
|
// clean up after ourselves. make sure we do this _after_ the event, else 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
|
|
|
if (!((nsInputEvent*)aEvent)->isControl) {
|
|
|
|
//Shift focus forward or back depending on shift key
|
|
|
|
ShiftFocus(!((nsInputEvent*)aEvent)->isShift);
|
|
|
|
} else {
|
|
|
|
ShiftFocusByDoc(!((nsInputEvent*)aEvent)->isShift);
|
|
|
|
}
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_VK_F6:
|
1999-11-22 19:45:13 +00:00
|
|
|
//Shift focus forward or back depending on shift key
|
2001-05-22 23:52:17 +00:00
|
|
|
ShiftFocusByDoc(!((nsInputEvent*)aEvent)->isShift);
|
1999-11-24 06:03:41 +00:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
1999-11-22 19:45:13 +00:00
|
|
|
break;
|
1999-12-11 00:02:08 +00:00
|
|
|
|
2001-02-15 05:07:46 +00:00
|
|
|
//the problem is that viewer does not have xul so we cannot completely eliminate these
|
1999-12-11 00:02:08 +00:00
|
|
|
#if NON_KEYBINDING
|
2001-02-15 05:07:46 +00:00
|
|
|
case NS_VK_PAGE_DOWN:
|
1999-11-22 19:45:13 +00:00
|
|
|
case NS_VK_PAGE_UP:
|
|
|
|
if (!mCurrentFocus) {
|
2004-09-21 04:41:08 +00:00
|
|
|
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eVertical);
|
1999-11-22 19:45:13 +00:00
|
|
|
if (sv) {
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
2003-03-12 03:22:11 +00:00
|
|
|
sv->ScrollByPages(0, (keyEvent->keyCode != NS_VK_PAGE_UP) ? 1 : -1);
|
1999-11-22 19:45:13 +00:00
|
|
|
}
|
1999-09-21 14:18:52 +00:00
|
|
|
}
|
1999-11-22 19:45:13 +00:00
|
|
|
break;
|
2004-07-23 07:27:57 +00:00
|
|
|
case NS_VK_HOME:
|
1999-11-22 19:45:13 +00:00
|
|
|
case NS_VK_END:
|
|
|
|
if (!mCurrentFocus) {
|
2004-09-21 04:41:08 +00:00
|
|
|
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eVertical);
|
1999-11-22 19:45:13 +00:00
|
|
|
if (sv) {
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
sv->ScrollByWhole((keyEvent->keyCode != NS_VK_HOME) ? PR_FALSE : PR_TRUE);
|
1999-05-31 01:45:23 +00:00
|
|
|
}
|
1999-04-30 19:38:39 +00:00
|
|
|
}
|
1999-11-22 19:45:13 +00:00
|
|
|
break;
|
2004-07-23 07:27:57 +00:00
|
|
|
case NS_VK_DOWN:
|
1999-11-22 19:45:13 +00:00
|
|
|
case NS_VK_UP:
|
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
|
|
|
if (!mCurrentFocus) {
|
2004-09-21 04:41:08 +00:00
|
|
|
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eVertical);
|
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
|
|
|
if (sv) {
|
1999-11-22 19:45:13 +00:00
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
2000-05-16 11:35:12 +00:00
|
|
|
sv->ScrollByLines(0, (keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1);
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
// force the update to happen now, otherwise multiple scrolls can
|
|
|
|
// occur before the update is processed. (bug #7354)
|
2003-08-06 03:07:12 +00:00
|
|
|
nsIViewManager* vm = aView->GetViewManager();
|
|
|
|
if (vm) {
|
2002-02-21 13:39:39 +00:00
|
|
|
// I'd use Composite here, but it doesn't always work.
|
2000-05-16 11:35:12 +00:00
|
|
|
// vm->Composite();
|
|
|
|
vm->ForceUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-07-23 07:27:57 +00:00
|
|
|
case NS_VK_LEFT:
|
2000-05-16 11:35:12 +00:00
|
|
|
case NS_VK_RIGHT:
|
|
|
|
if (!mCurrentFocus) {
|
2004-09-21 04:41:08 +00:00
|
|
|
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eHorizontal);
|
2000-05-16 11:35:12 +00:00
|
|
|
if (sv) {
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
sv->ScrollByLines((keyEvent->keyCode == NS_VK_RIGHT) ? 1 : -1, 0);
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-11-22 19:45:13 +00:00
|
|
|
// force the update to happen now, otherwise multiple scrolls can
|
|
|
|
// occur before the update is processed. (bug #7354)
|
2003-08-06 03:07:12 +00:00
|
|
|
nsIViewManager* vm = aView->GetViewManager();
|
|
|
|
if (vm) {
|
2002-02-21 13:39:39 +00:00
|
|
|
// I'd use Composite here, but it doesn't always work.
|
1999-11-22 19:45:13 +00:00
|
|
|
// vm->Composite();
|
2000-01-26 23:04:40 +00:00
|
|
|
vm->ForceUpdate();
|
1999-11-22 19:45:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0: /* check charcode since keycode is 0 */
|
|
|
|
{
|
|
|
|
//Spacebar
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
if (keyEvent->charCode == 0x20) {
|
|
|
|
if (!mCurrentFocus) {
|
2004-09-21 04:41:08 +00:00
|
|
|
nsIScrollableView* sv = nsLayoutUtils::GetNearestScrollingView(aView, nsLayoutUtils::eVertical);
|
1999-11-22 19:45:13 +00:00
|
|
|
if (sv) {
|
2003-03-12 03:22:11 +00:00
|
|
|
sv->ScrollByPages(0, 1);
|
1999-11-22 19:45:13 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
1999-07-06 22:55:46 +00:00
|
|
|
}
|
1999-11-22 19:45:13 +00:00
|
|
|
break;
|
1999-12-11 00:02:08 +00:00
|
|
|
#endif //NON_KEYBINDING
|
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;
|
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;
|
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-11 16:37:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::NotifyDestroyPresContext(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
nsIMEStateManager::OnDestroyPresContext(aPresContext);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::SetPresContext(nsPresContext* aPresContext)
|
1998-06-23 21:53:02 +00:00
|
|
|
{
|
1999-12-08 20:18:16 +00:00
|
|
|
if (aPresContext == nsnull) {
|
2006-04-11 16:37:58 +00:00
|
|
|
// XXX should we move this block to |NotifyDestroyPresContext|?
|
1999-12-08 20:18:16 +00:00
|
|
|
// A pres context is going away. Make sure we do cleanup.
|
|
|
|
if (mPresContext == gLastFocusedPresContext) {
|
|
|
|
gLastFocusedPresContext = nsnull;
|
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
1999-12-11 05:42:18 +00:00
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
1999-12-08 20:18:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
mPresContext = aPresContext;
|
1998-07-17 04:52:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-19 00:43:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
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
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
|
1998-11-19 00:43:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2001-01-26 12:35:32 +00:00
|
|
|
// Check whether or not to show the busy cursor
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer = aPresContext->GetContainer();
|
2004-07-23 07:27:57 +00:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(pcContainer));
|
2001-03-19 23:01:59 +00:00
|
|
|
if (!docShell) return;
|
2001-01-26 12:35:32 +00:00
|
|
|
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;
|
2004-12-30 21:56:11 +00:00
|
|
|
container = nsnull;
|
2001-01-26 12:35:32 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
if (aTargetFrame) {
|
2005-07-01 04:29:42 +00:00
|
|
|
SetCursor(cursor, container, haveHotspot, hotspotX, hotspotY,
|
|
|
|
aTargetFrame->GetWindow(), 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
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
NS_IMETHODIMP
|
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
|
|
|
{
|
|
|
|
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;
|
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);
|
|
|
|
|
2007-02-28 21:29:53 +00:00
|
|
|
// XXX PR_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
|
|
|
}
|
|
|
|
|
2006-05-15 17:31:28 +00:00
|
|
|
class nsESMEventCB : public nsDispatchingCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsESMEventCB(nsIContent* aTarget) : mTarget(aTarget) {}
|
|
|
|
|
|
|
|
virtual void HandleEvent(nsEventChainPostVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
if (aVisitor.mPresContext) {
|
|
|
|
nsIPresShell* shell = aVisitor.mPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
|
|
|
nsIFrame* frame = shell->GetPrimaryFrameFor(mTarget);
|
|
|
|
if (frame) {
|
|
|
|
frame->HandleEvent(aVisitor.mPresContext,
|
|
|
|
(nsGUIEvent*) aVisitor.mEvent,
|
|
|
|
&aVisitor.mEventStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
event.nativeMsg = ((nsMouseEvent*)aEvent)->nativeMsg;
|
2006-07-13 07:51:54 +00:00
|
|
|
event.relatedTarget = aRelatedContent;
|
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
|
|
|
|
2006-05-15 17:31:28 +00:00
|
|
|
nsIPresShell *shell = mPresContext ? mPresContext->GetPresShell() : nsnull;
|
2005-03-28 23:39:13 +00:00
|
|
|
if (shell) {
|
2006-05-15 17:31:28 +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.
|
2005-08-22 22:24:29 +00:00
|
|
|
targetFrame = shell->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;
|
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
|
|
|
|
nsIFrameFrame* subdocFrame;
|
2006-07-14 07:55:51 +00:00
|
|
|
CallQueryInterface(mLastMouseOverFrame.GetFrame(), &subdocFrame);
|
2005-03-28 23:39:13 +00:00
|
|
|
if (subdocFrame) {
|
|
|
|
nsCOMPtr<nsIDocShell> docshell;
|
|
|
|
subdocFrame->GetDocShell(getter_AddRefs(docshell));
|
|
|
|
if (docshell) {
|
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
|
|
|
docshell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
|
|
|
|
if (presContext) {
|
|
|
|
nsEventStateManager* kidESM =
|
|
|
|
NS_STATIC_CAST(nsEventStateManager*, 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) {
|
2007-05-01 22:24:20 +00:00
|
|
|
nsIPresShell *parentShell = parentDoc->GetPrimaryShell();
|
2005-03-28 23:39:13 +00:00
|
|
|
if (parentShell) {
|
|
|
|
nsEventStateManager* parentESM =
|
2005-04-28 23:48:28 +00:00
|
|
|
NS_STATIC_CAST(nsEventStateManager*,
|
|
|
|
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)
|
2002-12-17 02:10:57 +00:00
|
|
|
nsCOMPtr<nsIContent> targetElement;
|
2003-02-14 21:43:06 +00:00
|
|
|
GetEventTargetContent(aEvent, getter_AddRefs(targetElement));
|
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
|
|
|
|
targetElement = mDocument->GetRootContent();
|
|
|
|
}
|
2005-03-28 23:39:13 +00:00
|
|
|
NS_ASSERTION(targetElement, "Mouse move must have some target content");
|
|
|
|
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.
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
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
|
|
|
|
1999-09-09 00:28:23 +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_LEAVE_SYNTH,
|
|
|
|
targetContent, lastContent, mLastDragOverFrame);
|
|
|
|
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
|
|
|
|
|
|
|
mLastDragOverFrame = mCurrentTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-06-22 14:20:14 +00:00
|
|
|
case NS_DRAGDROP_DROP:
|
|
|
|
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.
|
1999-11-02 03:55:14 +00:00
|
|
|
if ( mLastDragOverFrame ) {
|
|
|
|
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_LEAVE_SYNTH,
|
|
|
|
nsnull, lastContent, mLastDragOverFrame);
|
|
|
|
FireDragEnterOrExit(aPresContext, aEvent, NS_DRAGDROP_EXIT_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;
|
|
|
|
nsMouseEvent event(NS_IS_TRUSTED_EVENT(aEvent), aMsg,
|
|
|
|
aEvent->widget, nsMouseEvent::eReal);
|
|
|
|
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;
|
|
|
|
|
|
|
|
mCurrentTargetContent = aTargetContent;
|
|
|
|
|
|
|
|
if (aTargetContent != aRelatedTarget) {
|
|
|
|
//XXX This event should still go somewhere!!
|
|
|
|
if (aTargetContent)
|
|
|
|
nsEventDispatcher::Dispatch(aTargetContent, aPresContext, &event,
|
|
|
|
nsnull, &status);
|
|
|
|
|
|
|
|
// adjust the drag hover
|
|
|
|
if (status != nsEventStatus_eConsumeNoDefault)
|
|
|
|
SetContentState((aMsg == NS_DRAGDROP_ENTER) ? aTargetContent : nsnull,
|
|
|
|
NS_EVENT_STATE_DRAGOVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally dispatch the event to the frame
|
|
|
|
if (aTargetFrame)
|
|
|
|
aTargetFrame->HandleEvent(aPresContext, &event, &status);
|
|
|
|
}
|
|
|
|
|
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;
|
2000-02-11 01:24:59 +00:00
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(mouseContent));
|
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;
|
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
|
|
|
if (mLastLeftMouseDownContent == mouseContent) {
|
|
|
|
aEvent->clickCount = mLClickCount;
|
|
|
|
mLClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
|
|
|
mLastLeftMouseDownContent = 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;
|
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
|
|
|
if (mLastMiddleMouseDownContent == mouseContent) {
|
|
|
|
aEvent->clickCount = mMClickCount;
|
|
|
|
mMClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
|
|
|
// XXX Why we don't clear mLastMiddleMouseDownContent here?
|
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;
|
|
|
|
} else if (aEvent->message == NS_MOUSE_BUTTON_UP) {
|
|
|
|
if (mLastRightMouseDownContent == mouseContent) {
|
|
|
|
aEvent->clickCount = mRClickCount;
|
|
|
|
mRClickCount = 0;
|
|
|
|
} else {
|
|
|
|
aEvent->clickCount = 0;
|
|
|
|
}
|
|
|
|
// XXX Why we don't clear mLastRightMouseDownContent here?
|
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;
|
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) {
|
2003-02-14 21:43:06 +00:00
|
|
|
nsCOMPtr<nsIContent> mouseContent;
|
|
|
|
GetEventTargetContent(aEvent, getter_AddRefs(mouseContent));
|
|
|
|
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
2004-10-29 13:40:25 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::ChangeFocusWith(nsIContent* aFocusContent,
|
|
|
|
EFocusedWithType aFocusedWith)
|
1999-03-02 19:19:24 +00:00
|
|
|
{
|
2005-10-11 03:33:48 +00:00
|
|
|
mLastFocusedWith = aFocusedWith;
|
2004-10-29 13:40:25 +00:00
|
|
|
if (!aFocusContent) {
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-09-18 11:32:52 +00:00
|
|
|
|
|
|
|
// Get focus controller.
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
nsCOMPtr<nsIFocusController> focusController = nsnull;
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
|
2005-09-18 11:32:52 +00:00
|
|
|
if (window)
|
|
|
|
focusController = window->GetRootFocusController();
|
|
|
|
|
|
|
|
// If this is called from mouse event, we lock to scroll.
|
|
|
|
// Because the part of element is always in view. See bug 105894.
|
|
|
|
PRBool suppressFocusScroll =
|
|
|
|
focusController && (aFocusedWith == eEventFocusedByMouse);
|
|
|
|
if (suppressFocusScroll) {
|
|
|
|
PRBool currentState = PR_FALSE;
|
|
|
|
focusController->GetSuppressFocusScroll(¤tState);
|
|
|
|
NS_ASSERTION(!currentState, "locked scroll already!");
|
|
|
|
focusController->SetSuppressFocusScroll(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
aFocusContent->SetFocus(mPresContext);
|
2002-12-07 00:56:03 +00:00
|
|
|
if (aFocusedWith != eEventFocusedByMouse) {
|
2002-03-31 04:53:53 +00:00
|
|
|
MoveCaretToFocus();
|
2002-12-07 00:56:03 +00:00
|
|
|
// Select text fields when focused via keyboard (tab or accesskey)
|
2004-07-23 07:27:57 +00:00
|
|
|
if (sTextfieldSelectModel == eTextfieldSelect_auto &&
|
|
|
|
mCurrentFocus &&
|
2006-05-05 06:52:21 +00:00
|
|
|
mCurrentFocus->IsNodeOfType(nsINode::eHTML_FORM_CONTROL)) {
|
2002-12-07 00:56:03 +00:00
|
|
|
nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(mCurrentFocus));
|
2002-12-18 23:38:09 +00:00
|
|
|
PRInt32 controlType = formControl->GetType();
|
2002-12-07 00:56:03 +00:00
|
|
|
if (controlType == NS_FORM_INPUT_TEXT ||
|
|
|
|
controlType == NS_FORM_INPUT_PASSWORD) {
|
2004-07-23 07:27:57 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElement =
|
2002-12-07 00:56:03 +00:00
|
|
|
do_QueryInterface(mCurrentFocus);
|
|
|
|
if (inputElement) {
|
|
|
|
inputElement->Select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2005-09-18 11:32:52 +00:00
|
|
|
// Unlock scroll
|
|
|
|
if (suppressFocusScroll)
|
|
|
|
focusController->SetSuppressFocusScroll(PR_FALSE);
|
|
|
|
|
2004-10-29 13:40:25 +00:00
|
|
|
return NS_OK;
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
|
2001-05-22 23:52:17 +00:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// Debug Helpers
|
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
2004-07-23 07:27:57 +00:00
|
|
|
static void
|
2001-05-22 23:52:17 +00:00
|
|
|
PrintDocTree(nsIDocShellTreeNode * aParentNode, int aLevel)
|
|
|
|
{
|
|
|
|
for (PRInt32 i=0;i<aLevel;i++) printf(" ");
|
|
|
|
|
|
|
|
PRInt32 childWebshellCount;
|
|
|
|
aParentNode->GetChildCount(&childWebshellCount);
|
|
|
|
nsCOMPtr<nsIDocShell> parentAsDocShell(do_QueryInterface(aParentNode));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentAsItem(do_QueryInterface(aParentNode));
|
|
|
|
PRInt32 type;
|
|
|
|
parentAsItem->GetItemType(&type);
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
parentAsDocShell->GetPresShell(getter_AddRefs(presShell));
|
2004-07-31 23:15:21 +00:00
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
2001-05-22 23:52:17 +00:00
|
|
|
parentAsDocShell->GetPresContext(getter_AddRefs(presContext));
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = presShell->GetDocument();
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2005-11-17 18:31:22 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domwin = doc->GetWindow();
|
2001-05-22 23:52:17 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
2003-08-06 03:07:12 +00:00
|
|
|
nsIViewManager* vm = presShell->GetViewManager();
|
2001-05-22 23:52:17 +00:00
|
|
|
if (vm) {
|
|
|
|
vm->GetWidget(getter_AddRefs(widget));
|
|
|
|
}
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
printf("DS %p Type %s Cnt %d Doc %p DW %p EM %p\n",
|
|
|
|
parentAsDocShell.get(),
|
|
|
|
type==nsIDocShellTreeItem::typeChrome?"Chrome":"Content",
|
2005-06-21 22:55:39 +00:00
|
|
|
childWebshellCount, doc, domwin.get(),
|
2004-02-27 17:17:37 +00:00
|
|
|
presContext->EventStateManager());
|
2001-05-22 23:52:17 +00:00
|
|
|
|
|
|
|
if (childWebshellCount > 0) {
|
|
|
|
for (PRInt32 i=0;i<childWebshellCount;i++) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> child;
|
|
|
|
aParentNode->GetChildAt(i, getter_AddRefs(child));
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> childAsNode(do_QueryInterface(child));
|
|
|
|
PrintDocTree(childAsNode, aLevel+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // end debug helpers
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_IMETHODIMP
|
2002-02-01 05:14:44 +00:00
|
|
|
nsEventStateManager::ShiftFocus(PRBool aForward, nsIContent* aStart)
|
|
|
|
{
|
2005-01-06 23:41:52 +00:00
|
|
|
nsCOMPtr<nsILookAndFeel> lookNFeel(do_GetService(kLookAndFeelCID));
|
|
|
|
lookNFeel->GetMetric(nsILookAndFeel::eMetric_TabFocusModel,
|
|
|
|
nsIContent::sTabFocusModel);
|
|
|
|
|
2002-02-01 05:14:44 +00:00
|
|
|
// We use mTabbedThroughDocument to indicate that we have passed
|
|
|
|
// the end (or beginning) of the document we started tabbing from,
|
|
|
|
// without finding anything else to focus. If we pass the end of
|
|
|
|
// the same document again (and the flag is set), we know that there
|
|
|
|
// is no focusable content anywhere in the tree, and should stop.
|
|
|
|
|
|
|
|
mTabbedThroughDocument = PR_FALSE;
|
|
|
|
return ShiftFocusInternal(aForward, aStart);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::ShiftFocusInternal(PRBool aForward, nsIContent* aStart)
|
1998-11-18 05:25:26 +00:00
|
|
|
{
|
2001-06-26 01:19:11 +00:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
2003-03-17 23:08:36 +00:00
|
|
|
printf("[%p] ShiftFocusInternal: aForward=%d, aStart=%p, mCurrentFocus=%p\n",
|
2003-11-07 03:35:05 +00:00
|
|
|
this, aForward, aStart, mCurrentFocus.get());
|
2001-05-22 23:52:17 +00:00
|
|
|
#endif
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(mPresContext, "no pres context");
|
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
NS_ASSERTION(mDocument, "no document");
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsIContent> rootContent = mDocument->GetRootContent();
|
2001-10-22 22:43:52 +00:00
|
|
|
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer = mPresContext->GetContainer();
|
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
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(pcContainer));
|
2007-03-24 11:47:28 +00:00
|
|
|
NS_ENSURE_STATE(docShell);
|
2001-06-22 07:25:28 +00:00
|
|
|
PRBool docHasFocus = PR_FALSE;
|
1999-04-12 21:24:07 +00:00
|
|
|
|
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
|
|
|
// ignoreTabIndex allows the user to tab to the next link after clicking before it link in the page
|
2004-07-23 07:27:57 +00:00
|
|
|
// or using find text to get to the link. Without ignoreTabIndex in those cases, pages that
|
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
|
|
|
// use tabindex would still enforce that order in those situations.
|
|
|
|
PRBool ignoreTabIndex = PR_FALSE;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
if (!aStart && !mCurrentFocus) {
|
2001-10-22 22:43:52 +00:00
|
|
|
// mCurrentFocus is ambiguous for determining whether
|
|
|
|
// we're in document-focus mode, because it's nulled out
|
|
|
|
// when the document is blurred, and it's also nulled out
|
|
|
|
// when the document/canvas has focus.
|
|
|
|
//
|
|
|
|
// So, use the docshell focus state to disambiguate.
|
|
|
|
|
|
|
|
docShell->GetHasFocus(&docHasFocus);
|
2000-04-04 23:55:31 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
nsIFrame* selectionFrame = nsnull;
|
|
|
|
nsIFrame* curFocusFrame = nsnull; // This will hold the location we're moving away from
|
|
|
|
|
|
|
|
// If in content, navigate from last cursor position rather than last focus
|
|
|
|
// If we're in UI, selection location will return null
|
2007-03-07 19:08:36 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = mPresContext->PresShell();
|
2001-05-22 23:52:17 +00:00
|
|
|
|
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
|
|
|
// We might use the selection position, rather than mCurrentFocus, as our position to shift focus from
|
|
|
|
PRInt32 itemType;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> shellItem(do_QueryInterface(docShell));
|
|
|
|
shellItem->GetItemType(&itemType);
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2004-04-13 09:39:16 +00:00
|
|
|
// Tab from the selection if it exists, but not if we're in chrome or an explicit starting
|
|
|
|
// point was given.
|
2004-12-01 16:15:02 +00:00
|
|
|
if (!aStart && itemType != nsIDocShellTreeItem::typeChrome) {
|
2004-07-23 07:27:57 +00:00
|
|
|
// We're going to tab from the selection position
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!mCurrentFocus || (mLastFocusedWith != eEventFocusedByMouse && mCurrentFocus->Tag() != nsGkAtoms::area)) {
|
2002-03-21 02:37:48 +00:00
|
|
|
nsCOMPtr<nsIContent> selectionContent, endSelectionContent; // We won't be using this, need arg for method call
|
|
|
|
PRUint32 selectionOffset; // We won't be using this either, need arg for method call
|
|
|
|
GetDocSelectionLocation(getter_AddRefs(selectionContent), getter_AddRefs(endSelectionContent), &selectionFrame, &selectionOffset);
|
|
|
|
if (selectionContent == rootContent) // If selection on rootContent, same as null -- we have no selection yet
|
|
|
|
selectionFrame = nsnull;
|
|
|
|
// Only use tabindex if selection is synchronized with focus
|
|
|
|
// That way, if the user clicks in content, or does a find text that lands between focusable elements,
|
|
|
|
// they can then tab relative to that selection
|
|
|
|
if (selectionFrame) {
|
|
|
|
PRBool selectionWithFocus;
|
|
|
|
MoveFocusToCaret(PR_FALSE, &selectionWithFocus);
|
|
|
|
ignoreTabIndex = !selectionWithFocus;
|
2006-01-07 04:08:05 +00:00
|
|
|
// Refresh |selectionFrame| since MoveFocusToCaret() could have
|
|
|
|
// destroyed it. (bug 308086)
|
|
|
|
GetDocSelectionLocation(getter_AddRefs(selectionContent),
|
|
|
|
getter_AddRefs(endSelectionContent),
|
|
|
|
&selectionFrame, &selectionOffset);
|
2002-03-21 02:37:48 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 09:39:16 +00:00
|
|
|
nsIContent *startContent = nsnull;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2004-04-13 09:39:16 +00:00
|
|
|
if (aStart) {
|
2005-08-22 22:24:29 +00:00
|
|
|
curFocusFrame = presShell->GetPrimaryFrameFor(aStart);
|
2004-04-13 09:39:16 +00:00
|
|
|
|
|
|
|
// If there is no frame, we can't navigate from this content node, and we
|
|
|
|
// fall back to navigating from the document root.
|
|
|
|
if (curFocusFrame)
|
|
|
|
startContent = aStart;
|
|
|
|
} else if (selectionFrame) {
|
|
|
|
// We moved focus to the caret location above, so mCurrentFocus
|
|
|
|
// reflects the starting content node.
|
|
|
|
startContent = mCurrentFocus;
|
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
|
|
|
curFocusFrame = selectionFrame;
|
2004-04-13 09:39:16 +00:00
|
|
|
} else if (!docHasFocus) {
|
|
|
|
startContent = mCurrentFocus;
|
2003-03-18 23:41:44 +00:00
|
|
|
GetFocusedFrame(&curFocusFrame);
|
2004-04-13 09:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aStart) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aStart->HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
|
2004-08-03 12:52:42 +00:00
|
|
|
aStart->IsFocusable(&mCurrentTabIndex);
|
2005-01-16 16:39:35 +00:00
|
|
|
} else {
|
|
|
|
ignoreTabIndex = PR_TRUE; // ignore current tabindex, bug 81481
|
2004-08-03 12:52:42 +00:00
|
|
|
}
|
2004-04-13 09:39:16 +00:00
|
|
|
} else if (!mCurrentFocus) { // Get tabindex ready
|
|
|
|
if (aForward) {
|
|
|
|
mCurrentTabIndex = docHasFocus && selectionFrame ? 0 : 1;
|
|
|
|
} else if (!docHasFocus) {
|
|
|
|
mCurrentTabIndex = 0;
|
|
|
|
} else if (selectionFrame) {
|
|
|
|
mCurrentTabIndex = 1; // will keep it from wrapping around to end
|
|
|
|
}
|
|
|
|
}
|
2001-06-22 07:25:28 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIContent> nextFocus;
|
2003-03-18 23:41:44 +00:00
|
|
|
nsIFrame* nextFocusFrame;
|
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
|
|
|
if (aForward || !docHasFocus || selectionFrame)
|
2004-04-13 09:39:16 +00:00
|
|
|
GetNextTabbableContent(rootContent, startContent, curFocusFrame,
|
2004-08-03 12:52:42 +00:00
|
|
|
aForward, ignoreTabIndex || mCurrentTabIndex < 0,
|
2004-04-13 09:39:16 +00:00
|
|
|
getter_AddRefs(nextFocus), &nextFocusFrame);
|
2001-05-22 23:52:17 +00:00
|
|
|
|
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
|
|
|
// Clear out mCurrentTabIndex. It has a garbage value because of GetNextTabbableContent()'s side effects
|
2004-10-29 13:40:25 +00:00
|
|
|
// It will be set correctly when focus is changed via ChangeFocusWith()
|
2004-07-23 07:27:57 +00:00
|
|
|
mCurrentTabIndex = 0;
|
2001-05-22 23:52:17 +00:00
|
|
|
|
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
|
|
|
if (nextFocus) {
|
2001-10-22 22:43:52 +00:00
|
|
|
// Check to see if the next focused element has a subshell.
|
|
|
|
// This is the case for an IFRAME or FRAME element. If it
|
|
|
|
// does, we send focus into the subshell.
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> sub_shell;
|
2003-07-28 21:17:26 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = nextFocus->GetDocument();
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
if (doc) {
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIDocument *sub_doc = doc->GetSubDocumentFor(nextFocus);
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
if (sub_doc) {
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsISupports> container = sub_doc->GetContainer();
|
2002-04-17 04:17:16 +00:00
|
|
|
sub_shell = do_QueryInterface(container);
|
2001-04-18 06:18:10 +00:00
|
|
|
}
|
2002-04-17 04:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sub_shell) {
|
2005-01-12 02:42:39 +00:00
|
|
|
// Make sure to scroll before possibly dispatching focus/blur events.
|
2007-03-07 19:08:36 +00:00
|
|
|
presShell->ScrollContentIntoView(nextFocus,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2005-01-12 02:42:39 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
// if we are in the middle of tabbing into
|
2003-03-17 23:08:36 +00:00
|
|
|
// sub_shell, bail out, to avoid recursion
|
|
|
|
// see bug #195011 and bug #137191
|
|
|
|
if (mTabbingFromDocShells.IndexOf(sub_shell) != -1)
|
|
|
|
return NS_OK;
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
TabIntoDocument(sub_shell, aForward);
|
2001-10-22 22:43:52 +00:00
|
|
|
} else {
|
|
|
|
// there is no subshell, so just focus nextFocus
|
2001-05-22 23:52:17 +00:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
2001-10-22 22:43:52 +00:00
|
|
|
printf("focusing next focusable content: %p\n", nextFocus.get());
|
2001-05-22 23:52:17 +00:00
|
|
|
#endif
|
2003-03-18 23:41:44 +00:00
|
|
|
mCurrentTarget = nextFocusFrame;
|
2002-07-22 21:36:36 +00:00
|
|
|
|
2003-02-01 00:05:46 +00:00
|
|
|
nsCOMPtr<nsIContent> oldFocus(mCurrentFocus);
|
2004-10-29 13:40:25 +00:00
|
|
|
ChangeFocusWith(nextFocus, eEventFocusedByKey);
|
2003-11-07 03:35:05 +00:00
|
|
|
if (!mCurrentFocus && oldFocus) {
|
2004-10-29 13:40:25 +00:00
|
|
|
// ChangeFocusWith failed to move focus to nextFocus because a blur handler
|
2003-11-07 03:35:05 +00:00
|
|
|
// made it unfocusable. (bug #118685)
|
2004-02-11 07:47:06 +00:00
|
|
|
// Try again unless it's from the same point, bug 232368.
|
2005-06-21 22:55:39 +00:00
|
|
|
if (oldFocus != aStart && oldFocus->GetDocument()) {
|
2004-02-11 07:47:06 +00:00
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
return ShiftFocusInternal(aForward, oldFocus);
|
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-11-07 03:35:05 +00:00
|
|
|
} else {
|
2004-05-27 21:25:22 +00:00
|
|
|
if (mCurrentFocus != nextFocus) {
|
|
|
|
// A focus or blur handler switched the focus from one of
|
|
|
|
// its focus/blur/change handlers, don't mess with what the
|
|
|
|
// page wanted...
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-14 07:55:51 +00:00
|
|
|
nsIFrame* focusedFrame = nsnull;
|
|
|
|
GetFocusedFrame(&focusedFrame);
|
|
|
|
mCurrentTarget = focusedFrame;
|
2003-11-07 03:35:05 +00:00
|
|
|
}
|
2003-02-01 00:05:46 +00:00
|
|
|
|
|
|
|
// It's possible that the act of removing focus from our previously
|
|
|
|
// focused element caused nextFocus to be removed from the document.
|
|
|
|
// In this case, we can restart the frame traversal from our previously
|
|
|
|
// focused content.
|
|
|
|
|
2003-11-07 03:35:05 +00:00
|
|
|
if (oldFocus && doc != nextFocus->GetDocument()) {
|
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
return ShiftFocusInternal(aForward, oldFocus);
|
2003-02-01 00:05:46 +00:00
|
|
|
}
|
|
|
|
|
2004-03-09 19:34:34 +00:00
|
|
|
if (!docHasFocus)
|
2001-10-22 22:43:52 +00:00
|
|
|
docShell->SetHasFocus(PR_TRUE);
|
|
|
|
}
|
2001-05-22 23:52:17 +00:00
|
|
|
} else {
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
// If we're going backwards past the first content,
|
|
|
|
// focus the document.
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
PRBool focusDocument;
|
|
|
|
if (itemType == nsIDocShellTreeItem::typeChrome)
|
|
|
|
focusDocument = PR_FALSE;
|
|
|
|
else {
|
|
|
|
// Check for a frameset document
|
|
|
|
focusDocument = !(IsFrameSetDoc(docShell));
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2002-02-01 05:14:44 +00:00
|
|
|
if (!aForward && !docHasFocus && focusDocument) {
|
2001-05-22 23:52:17 +00:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
2001-10-22 22:43:52 +00:00
|
|
|
printf("Focusing document\n");
|
2001-05-22 23:52:17 +00:00
|
|
|
#endif
|
2001-10-22 22:43:52 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
|
|
|
docShell->SetHasFocus(PR_TRUE);
|
|
|
|
docShell->SetCanvasHasFocus(PR_TRUE);
|
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
|
|
|
// Next time forward we start at the beginning of the document
|
|
|
|
// Next time backward we go to URL bar
|
2004-07-23 07:27:57 +00:00
|
|
|
// We need to move the caret to the document root, so that we don't
|
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
|
|
|
// tab from the most recently focused element next time around
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(rootContent);
|
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
|
|
|
MoveCaretToFocus();
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(nsnull);
|
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
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
} else {
|
|
|
|
// If there's nothing left to focus in this document,
|
|
|
|
// pop out to our parent document, and have it shift focus
|
|
|
|
// in the same direction starting at the content element
|
|
|
|
// corresponding to our docshell.
|
2002-02-01 05:14:44 +00:00
|
|
|
// Guard against infinite recursion (see explanation in ShiftFocus)
|
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
|
|
|
|
2002-02-01 05:14:44 +00:00
|
|
|
if (mTabbedThroughDocument)
|
|
|
|
return NS_OK;
|
|
|
|
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(rootContent);
|
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
|
|
|
mCurrentTabIndex = 0;
|
|
|
|
MoveCaretToFocus();
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(nsnull);
|
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
|
|
|
|
2002-02-01 05:14:44 +00:00
|
|
|
mTabbedThroughDocument = PR_TRUE;
|
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
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(pcContainer);
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeParent;
|
|
|
|
treeItem->GetParent(getter_AddRefs(treeParent));
|
|
|
|
if (treeParent) {
|
|
|
|
nsCOMPtr<nsIDocShell> parentDS = do_QueryInterface(treeParent);
|
|
|
|
if (parentDS) {
|
|
|
|
nsCOMPtr<nsIPresShell> parentShell;
|
|
|
|
parentDS->GetPresShell(getter_AddRefs(parentShell));
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2005-09-14 05:03:20 +00:00
|
|
|
nsCOMPtr<nsIDocument> parent_doc = parentShell->GetDocument();
|
|
|
|
nsCOMPtr<nsIContent> docContent = parent_doc->FindContentForSubDocument(mDocument);
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
nsCOMPtr<nsPresContext> parentPC = parentShell->GetPresContext();
|
2004-02-27 17:17:37 +00:00
|
|
|
nsIEventStateManager *parentESM = parentPC->EventStateManager();
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2005-09-14 05:03:20 +00:00
|
|
|
nsCOMPtr<nsISupports> parentContainer = parentPC->GetContainer();
|
|
|
|
if (parentContainer && docContent && docContent->GetCurrentDoc() == parent_doc) {
|
2001-10-22 22:43:52 +00:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
2005-09-14 05:03:20 +00:00
|
|
|
printf("popping out focus to parent docshell\n");
|
2001-10-22 22:43:52 +00:00
|
|
|
#endif
|
2005-09-14 05:03:20 +00:00
|
|
|
parentESM->MoveCaretToFocus();
|
|
|
|
parentESM->ShiftFocus(aForward, docContent);
|
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
} else {
|
|
|
|
printf("can't pop out focus to parent docshell\n"); // bug 308025
|
|
|
|
#endif
|
|
|
|
}
|
2001-10-22 22:43:52 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
} else {
|
2001-10-22 22:43:52 +00:00
|
|
|
PRBool tookFocus = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIDocShell> subShell = do_QueryInterface(pcContainer);
|
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
|
|
|
if (subShell) {
|
2002-02-01 05:14:44 +00:00
|
|
|
subShell->TabToTreeOwner(aForward, &tookFocus);
|
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
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
#ifdef DEBUG_DOCSHEL_FOCUS
|
|
|
|
printf("offered focus to tree owner, tookFocus=%d\n",
|
|
|
|
tookFocus);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (tookFocus) {
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
|
|
|
docShell->SetHasFocus(PR_FALSE);
|
|
|
|
} else {
|
|
|
|
// there is nowhere else to send the focus, so
|
|
|
|
// refocus ourself.
|
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
|
|
|
// Next time forward we start at the beginning of the document
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
printf("wrapping around within this document\n");
|
|
|
|
#endif
|
|
|
|
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(nsnull);
|
2001-10-22 22:43:52 +00:00
|
|
|
docShell->SetHasFocus(PR_FALSE);
|
2002-02-01 05:14:44 +00:00
|
|
|
ShiftFocusInternal(aForward);
|
2001-10-22 22:43:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
return NS_OK;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsresult
|
2003-03-18 23:41:44 +00:00
|
|
|
nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent,
|
2004-04-13 09:39:16 +00:00
|
|
|
nsIContent* aStartContent,
|
2004-07-23 07:27:57 +00:00
|
|
|
nsIFrame* aStartFrame,
|
2004-04-13 09:39:16 +00:00
|
|
|
PRBool forward,
|
2004-07-23 07:27:57 +00:00
|
|
|
PRBool aIgnoreTabIndex,
|
2003-03-18 23:41:44 +00:00
|
|
|
nsIContent** aResultNode,
|
|
|
|
nsIFrame** aResultFrame)
|
1998-11-18 05:25:26 +00:00
|
|
|
{
|
2003-03-18 23:41:44 +00:00
|
|
|
*aResultNode = nsnull;
|
|
|
|
*aResultFrame = nsnull;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2004-07-24 21:12:43 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFrameTraversal> trav(do_CreateInstance(kFrameTraversalCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIBidirectionalEnumerator> frameTraversal;
|
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
|
|
|
|
2004-07-24 21:12:43 +00:00
|
|
|
// --- Get frame to start with ---
|
2004-04-13 09:39:16 +00:00
|
|
|
if (!aStartFrame) {
|
2004-07-24 21:12:43 +00:00
|
|
|
// No frame means we need to start with the root content again.
|
|
|
|
NS_ENSURE_TRUE(mPresContext, NS_ERROR_FAILURE);
|
|
|
|
nsIPresShell *presShell = mPresContext->GetPresShell();
|
|
|
|
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
2005-08-22 22:24:29 +00:00
|
|
|
aStartFrame = presShell->GetPrimaryFrameFor(aRootContent);
|
2004-07-24 21:12:43 +00:00
|
|
|
NS_ENSURE_TRUE(aStartFrame, NS_ERROR_FAILURE);
|
2006-08-30 13:38:16 +00:00
|
|
|
rv = trav->NewFrameTraversal(getter_AddRefs(frameTraversal),
|
|
|
|
mPresContext, aStartFrame,
|
|
|
|
ePreOrder,
|
|
|
|
PR_FALSE, // aVisual
|
|
|
|
PR_FALSE, // aLockInScrollView
|
|
|
|
PR_TRUE // aFollowOOFs
|
|
|
|
);
|
2004-07-24 21:12:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!forward) {
|
|
|
|
rv = frameTraversal->Last();
|
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
|
|
|
}
|
|
|
|
}
|
2004-07-24 21:12:43 +00:00
|
|
|
else {
|
2006-08-30 13:38:16 +00:00
|
|
|
rv = trav->NewFrameTraversal(getter_AddRefs(frameTraversal),
|
|
|
|
mPresContext, aStartFrame,
|
|
|
|
ePreOrder,
|
|
|
|
PR_FALSE, // aVisual
|
|
|
|
PR_FALSE, // aLockInScrollView
|
|
|
|
PR_TRUE // aFollowOOFs
|
|
|
|
);
|
2004-07-24 21:12:43 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-12-26 17:47:52 +00:00
|
|
|
if (!aStartContent || aStartContent->Tag() != nsGkAtoms::area ||
|
2006-05-05 06:52:21 +00:00
|
|
|
!aStartContent->IsNodeOfType(nsINode::eHTML)) {
|
2004-07-24 21:12:43 +00:00
|
|
|
// Need to do special check in case we're in an imagemap which has multiple
|
|
|
|
// content per frame, so don't skip over the starting frame.
|
|
|
|
rv = forward ? frameTraversal->Next() : frameTraversal->Prev();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-24 21:12:43 +00:00
|
|
|
// -- Walk frames to find something tabbable matching mCurrentTabIndex --
|
|
|
|
while (NS_SUCCEEDED(rv)) {
|
|
|
|
nsISupports* currentItem;
|
|
|
|
frameTraversal->CurrentItem(¤tItem);
|
|
|
|
*aResultFrame = (nsIFrame*)currentItem;
|
|
|
|
if (!*aResultFrame) {
|
|
|
|
break;
|
2004-07-07 00:58:57 +00:00
|
|
|
}
|
2004-04-30 14:05:27 +00:00
|
|
|
|
2004-07-24 21:12:43 +00:00
|
|
|
// TabIndex not set defaults to 0 for form elements, anchors and other
|
|
|
|
// elements that are normally focusable. Tabindex defaults to -1
|
|
|
|
// for elements that are not normally focusable.
|
|
|
|
// The returned computed tabindex from IsFocusable() is as follows:
|
|
|
|
// < 0 not tabbable at all
|
|
|
|
// == 0 in normal tab order (last after positive tabindex'd items)
|
|
|
|
// > 0 can be tabbed to in the order specified by this value
|
|
|
|
PRInt32 tabIndex;
|
|
|
|
nsIContent* currentContent = (*aResultFrame)->GetContent();
|
|
|
|
(*aResultFrame)->IsFocusable(&tabIndex);
|
|
|
|
if (tabIndex >= 0) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (currentContent->Tag() == nsGkAtoms::img &&
|
|
|
|
currentContent->HasAttr(kNameSpaceID_None, nsGkAtoms::usemap)) {
|
2004-07-24 21:12:43 +00:00
|
|
|
// Must be an image w/ a map -- it's tabbable but no tabindex is specified
|
|
|
|
// Special case for image maps: they don't get walked by nsIFrameTraversal
|
|
|
|
nsIContent *areaContent = GetNextTabbableMapArea(forward, currentContent);
|
|
|
|
if (areaContent) {
|
|
|
|
NS_ADDREF(*aResultNode = areaContent);
|
|
|
|
return NS_OK;
|
2003-03-26 02:55:19 +00:00
|
|
|
}
|
2000-01-13 11:43:54 +00:00
|
|
|
}
|
2004-07-24 21:12:43 +00:00
|
|
|
else if ((aIgnoreTabIndex || mCurrentTabIndex == tabIndex) &&
|
|
|
|
currentContent != aStartContent) {
|
|
|
|
NS_ADDREF(*aResultNode = currentContent);
|
2000-04-04 23:55:31 +00:00
|
|
|
return NS_OK;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-24 21:12:43 +00:00
|
|
|
rv = forward ? frameTraversal->Next() : frameTraversal->Prev();
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
2004-07-24 21:12:43 +00:00
|
|
|
// -- Reached end or beginning of document --
|
|
|
|
|
|
|
|
// If already at lowest priority tab (0), end search completely.
|
|
|
|
// A bit counterintuitive but true, tabindex order goes 1, 2, ... 32767, 0
|
|
|
|
if (mCurrentTabIndex == (forward? 0: 1)) {
|
2000-04-04 23:55:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-07-24 21:12:43 +00:00
|
|
|
|
|
|
|
// else continue looking for next highest priority tabindex
|
2000-04-04 23:55:31 +00:00
|
|
|
mCurrentTabIndex = GetNextTabIndex(aRootContent, forward);
|
2004-04-13 09:39:16 +00:00
|
|
|
return GetNextTabbableContent(aRootContent, aStartContent, nsnull, forward,
|
2003-03-18 23:41:44 +00:00
|
|
|
aIgnoreTabIndex, aResultNode, aResultFrame);
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
2004-07-24 21:12:43 +00:00
|
|
|
nsIContent*
|
|
|
|
nsEventStateManager::GetNextTabbableMapArea(PRBool aForward,
|
|
|
|
nsIContent *aImageContent)
|
|
|
|
{
|
|
|
|
nsAutoString useMap;
|
2006-12-26 17:47:52 +00:00
|
|
|
aImageContent->GetAttr(kNameSpaceID_None, nsGkAtoms::usemap, useMap);
|
2004-07-24 21:12:43 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = aImageContent->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLMapElement> imageMap = nsImageMapUtils::FindImageMap(doc, useMap);
|
|
|
|
nsCOMPtr<nsIContent> mapContent = do_QueryInterface(imageMap);
|
|
|
|
PRUint32 count = mapContent->GetChildCount();
|
|
|
|
// First see if mCurrentFocus is in this map
|
|
|
|
PRInt32 index = mapContent->IndexOf(mCurrentFocus);
|
|
|
|
PRInt32 tabIndex;
|
|
|
|
if (index < 0 || (mCurrentFocus->IsFocusable(&tabIndex) &&
|
|
|
|
tabIndex != mCurrentTabIndex)) {
|
|
|
|
// If mCurrentFocus is in this map we must start iterating past it.
|
|
|
|
// We skip the case where mCurrentFocus has tabindex == mCurrentTabIndex
|
|
|
|
// since the next tab ordered element might be before it
|
|
|
|
// (or after for backwards) in the child list.
|
2005-04-28 23:48:28 +00:00
|
|
|
index = aForward ? -1 : (PRInt32)count;
|
2004-07-24 21:12:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetChildAt will return nsnull if our index < 0 or index >= count
|
|
|
|
nsCOMPtr<nsIContent> areaContent;
|
|
|
|
while ((areaContent = mapContent->GetChildAt(aForward? ++index : --index)) != nsnull) {
|
|
|
|
if (areaContent->IsFocusable(&tabIndex) && tabIndex == mCurrentTabIndex) {
|
|
|
|
return areaContent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
PRInt32
|
|
|
|
nsEventStateManager::GetNextTabIndex(nsIContent* aParent, PRBool forward)
|
|
|
|
{
|
2003-09-27 04:18:26 +00:00
|
|
|
PRInt32 tabIndex, childTabIndex;
|
|
|
|
nsIContent *child;
|
|
|
|
|
|
|
|
PRUint32 count = aParent->GetChildCount();
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-07-19 21:23:57 +00:00
|
|
|
if (forward) {
|
|
|
|
tabIndex = 0;
|
2003-09-27 04:18:26 +00:00
|
|
|
for (PRUint32 index = 0; index < count; index++) {
|
|
|
|
child = aParent->GetChildAt(index);
|
1999-07-19 21:23:57 +00:00
|
|
|
childTabIndex = GetNextTabIndex(child, forward);
|
|
|
|
if (childTabIndex > mCurrentTabIndex && childTabIndex != tabIndex) {
|
2004-07-23 07:27:57 +00:00
|
|
|
tabIndex = (tabIndex == 0 || childTabIndex < tabIndex) ? childTabIndex : tabIndex;
|
1999-07-19 21:23:57 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-07-19 21:23:57 +00:00
|
|
|
nsAutoString tabIndexStr;
|
2006-12-26 17:47:52 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsGkAtoms::tabindex, tabIndexStr);
|
1999-07-19 21:23:57 +00:00
|
|
|
PRInt32 ec, val = tabIndexStr.ToInteger(&ec);
|
2003-03-12 03:22:11 +00:00
|
|
|
if (NS_SUCCEEDED (ec) && val > mCurrentTabIndex && val != tabIndex) {
|
2004-07-23 07:27:57 +00:00
|
|
|
tabIndex = (tabIndex == 0 || val < tabIndex) ? val : tabIndex;
|
1999-07-19 21:23:57 +00:00
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
}
|
1999-07-19 21:23:57 +00:00
|
|
|
else { /* !forward */
|
|
|
|
tabIndex = 1;
|
2003-09-27 04:18:26 +00:00
|
|
|
for (PRUint32 index = 0; index < count; index++) {
|
|
|
|
child = aParent->GetChildAt(index);
|
1999-07-19 21:23:57 +00:00
|
|
|
childTabIndex = GetNextTabIndex(child, forward);
|
2003-09-27 04:18:26 +00:00
|
|
|
if ((mCurrentTabIndex == 0 && childTabIndex > tabIndex) ||
|
1999-07-19 21:23:57 +00:00
|
|
|
(childTabIndex < mCurrentTabIndex && childTabIndex > tabIndex)) {
|
|
|
|
tabIndex = childTabIndex;
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-07-19 21:23:57 +00:00
|
|
|
nsAutoString tabIndexStr;
|
2006-12-26 17:47:52 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsGkAtoms::tabindex, tabIndexStr);
|
1999-07-19 21:23:57 +00:00
|
|
|
PRInt32 ec, val = tabIndexStr.ToInteger(&ec);
|
2003-03-12 03:22:11 +00:00
|
|
|
if (NS_SUCCEEDED (ec)) {
|
2003-09-27 04:18:26 +00:00
|
|
|
if ((mCurrentTabIndex == 0 && val > tabIndex) ||
|
1999-07-19 21:23:57 +00:00
|
|
|
(val < mCurrentTabIndex && val > tabIndex) ) {
|
|
|
|
tabIndex = val;
|
|
|
|
}
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return tabIndex;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::GetEventTarget(nsIFrame **aFrame)
|
|
|
|
{
|
1999-06-15 03:14:28 +00:00
|
|
|
if (!mCurrentTarget && mCurrentTargetContent) {
|
|
|
|
if (mPresContext) {
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *shell = mPresContext->GetPresShell();
|
|
|
|
if (shell) {
|
2005-08-22 22:24:29 +00:00
|
|
|
mCurrentTarget = shell->GetPrimaryFrameFor(mCurrentTargetContent);
|
1999-06-15 03:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-24 03:58:13 +00:00
|
|
|
if (!mCurrentTarget) {
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *presShell = mPresContext->GetPresShell();
|
2002-02-21 13:39:39 +00:00
|
|
|
if (presShell) {
|
2006-07-14 07:55:51 +00:00
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
presShell->GetEventTargetFrame(&frame);
|
|
|
|
mCurrentTarget = frame;
|
2002-02-21 13:39:39 +00:00
|
|
|
}
|
2000-06-24 03:58:13 +00:00
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
*aFrame = mCurrentTarget;
|
1999-07-27 20:55:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-11-19 01:20:56 +00:00
|
|
|
nsEventStateManager::GetEventTargetContent(nsEvent* aEvent,
|
|
|
|
nsIContent** aContent)
|
1999-07-27 20:55:03 +00:00
|
|
|
{
|
1999-12-08 09:01:06 +00:00
|
|
|
if (aEvent &&
|
|
|
|
(aEvent->message == NS_FOCUS_CONTENT ||
|
|
|
|
aEvent->message == NS_BLUR_CONTENT)) {
|
1999-12-08 04:54:29 +00:00
|
|
|
*aContent = mCurrentFocus;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-27 20:55:03 +00:00
|
|
|
if (mCurrentTargetContent) {
|
|
|
|
*aContent = mCurrentTargetContent;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
2000-08-14 22:29:03 +00:00
|
|
|
return NS_OK;
|
1999-07-27 20:55:03 +00:00
|
|
|
}
|
2000-06-24 03:58:13 +00:00
|
|
|
|
2003-02-27 22:59:08 +00:00
|
|
|
*aContent = nsnull;
|
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *presShell = mPresContext->GetPresShell();
|
2003-02-14 21:43:06 +00:00
|
|
|
if (presShell) {
|
|
|
|
presShell->GetEventTargetContent(aEvent, aContent);
|
1999-07-27 20:55:03 +00:00
|
|
|
}
|
1999-06-15 03:14:28 +00:00
|
|
|
|
2003-02-27 22:59:08 +00:00
|
|
|
// Some events here may set mCurrentTarget but not set the corresponding
|
|
|
|
// event target in the PresShell.
|
|
|
|
if (!*aContent && mCurrentTarget) {
|
|
|
|
mCurrentTarget->GetContentForEvent(mPresContext, aEvent, aContent);
|
|
|
|
}
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
1999-03-28 22:22:54 +00:00
|
|
|
nsEventStateManager::GetContentState(nsIContent *aContent, PRInt32& aState)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
2005-06-03 02:02:45 +00:00
|
|
|
aState = aContent->IntrinsicState();
|
1999-03-28 22:22:54 +00:00
|
|
|
|
2004-07-14 22:27:24 +00:00
|
|
|
// Hierchical active: Check the ancestor chain of mActiveContent to see
|
|
|
|
// if we are on it.
|
|
|
|
for (nsIContent* activeContent = mActiveContent; activeContent;
|
|
|
|
activeContent = activeContent->GetParent()) {
|
|
|
|
if (aContent == activeContent) {
|
|
|
|
aState |= NS_EVENT_STATE_ACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
2002-04-11 03:49:30 +00:00
|
|
|
// Hierchical hover: Check the ancestor chain of mHoverContent to see
|
|
|
|
// if we are on it.
|
2003-07-28 21:17:26 +00:00
|
|
|
for (nsIContent* hoverContent = mHoverContent; hoverContent;
|
|
|
|
hoverContent = hoverContent->GetParent()) {
|
2002-04-11 03:49:30 +00:00
|
|
|
if (aContent == hoverContent) {
|
2000-09-15 06:17:54 +00:00
|
|
|
aState |= NS_EVENT_STATE_HOVER;
|
2002-04-11 03:49:30 +00:00
|
|
|
break;
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
2000-10-16 21:52:22 +00:00
|
|
|
|
1999-03-28 22:22:54 +00:00
|
|
|
if (aContent == mCurrentFocus) {
|
|
|
|
aState |= NS_EVENT_STATE_FOCUS;
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
1999-05-04 14:44:51 +00:00
|
|
|
if (aContent == mDragOverContent) {
|
|
|
|
aState |= NS_EVENT_STATE_DRAGOVER;
|
|
|
|
}
|
2003-01-13 23:10:53 +00:00
|
|
|
if (aContent == mURLTargetContent) {
|
|
|
|
aState |= NS_EVENT_STATE_URLTARGET;
|
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-08-24 19:06:07 +00:00
|
|
|
PRBool
|
1999-04-12 21:24:07 +00:00
|
|
|
nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
2004-07-14 22:27:24 +00:00
|
|
|
const PRInt32 maxNotify = 5;
|
2002-04-30 08:03:01 +00:00
|
|
|
// We must initialize this array with memset for the sake of the boneheaded
|
|
|
|
// OS X compiler. See bug 134934.
|
|
|
|
nsIContent *notifyContent[maxNotify];
|
|
|
|
memset(notifyContent, 0, sizeof(notifyContent));
|
1999-05-04 14:44:51 +00:00
|
|
|
|
2000-08-08 23:48:42 +00:00
|
|
|
// check to see that this state is allowed by style. Check dragover too?
|
2002-04-11 03:49:30 +00:00
|
|
|
// XXX This doesn't consider that |aState| is a bitfield.
|
2004-07-14 22:27:24 +00:00
|
|
|
// XXX Is this even what we want?
|
2000-08-08 23:48:42 +00:00
|
|
|
if (mCurrentTarget && (aState == NS_EVENT_STATE_ACTIVE || aState == NS_EVENT_STATE_HOVER))
|
|
|
|
{
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleUserInterface* ui = mCurrentTarget->GetStyleUserInterface();
|
2000-08-08 23:48:42 +00:00
|
|
|
if (ui->mUserInput == NS_STYLE_USER_INPUT_NONE)
|
2005-08-24 19:06:07 +00:00
|
|
|
return PR_FALSE;
|
2000-08-08 23:48:42 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2005-08-24 19:06:07 +00:00
|
|
|
PRBool didContentChangeAllStates = PR_TRUE;
|
|
|
|
|
1999-05-04 14:44:51 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_DRAGOVER) && (aContent != mDragOverContent)) {
|
2004-07-14 22:27:24 +00:00
|
|
|
notifyContent[3] = mDragOverContent; // notify dragover first, since more common case
|
|
|
|
NS_IF_ADDREF(notifyContent[3]);
|
1999-05-04 14:44:51 +00:00
|
|
|
mDragOverContent = aContent;
|
|
|
|
}
|
1999-04-20 00:03:30 +00:00
|
|
|
|
2003-01-13 23:10:53 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_URLTARGET) && (aContent != mURLTargetContent)) {
|
2004-07-14 22:27:24 +00:00
|
|
|
notifyContent[4] = mURLTargetContent;
|
|
|
|
NS_IF_ADDREF(notifyContent[4]);
|
2003-01-13 23:10:53 +00:00
|
|
|
mURLTargetContent = aContent;
|
|
|
|
}
|
|
|
|
|
2004-07-14 22:27:24 +00:00
|
|
|
nsCOMPtr<nsIContent> commonActiveAncestor, oldActive, newActive;
|
1999-04-20 00:03:30 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_ACTIVE) && (aContent != mActiveContent)) {
|
2004-07-14 22:27:24 +00:00
|
|
|
oldActive = mActiveContent;
|
|
|
|
newActive = aContent;
|
|
|
|
commonActiveAncestor = FindCommonAncestor(mActiveContent, aContent);
|
1999-04-20 00:03:30 +00:00
|
|
|
mActiveContent = aContent;
|
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
|
2002-04-11 03:49:30 +00:00
|
|
|
nsCOMPtr<nsIContent> commonHoverAncestor, oldHover, newHover;
|
1999-04-20 00:03:30 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_HOVER) && (aContent != mHoverContent)) {
|
2002-04-11 03:49:30 +00:00
|
|
|
oldHover = mHoverContent;
|
2006-11-01 13:56:48 +00:00
|
|
|
|
|
|
|
if (!mPresContext || mPresContext->IsDynamic()) {
|
|
|
|
newHover = aContent;
|
|
|
|
} else {
|
2007-01-05 15:50:29 +00:00
|
|
|
nsIFrame *frame = aContent ?
|
|
|
|
mPresContext->PresShell()->GetPrimaryFrameFor(aContent) : nsnull;
|
|
|
|
if (frame && nsLayoutUtils::IsViewportScrollbarFrame(frame)) {
|
2006-11-01 13:56:48 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 22:27:24 +00:00
|
|
|
commonHoverAncestor = FindCommonAncestor(mHoverContent, aContent);
|
1999-04-20 00:03:30 +00:00
|
|
|
mHoverContent = aContent;
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_FOCUS)) {
|
2004-05-20 07:17:03 +00:00
|
|
|
EnsureDocument(mPresContext);
|
2006-04-11 16:37:58 +00:00
|
|
|
nsIMEStateManager::OnChangeFocus(mPresContext, aContent);
|
2000-06-14 02:59:54 +00:00
|
|
|
if (aContent && (aContent == mCurrentFocus) && gLastFocusedDocument == mDocument) {
|
2000-03-02 23:15:01 +00:00
|
|
|
// gLastFocusedDocument appears to always be correct, that is why
|
|
|
|
// I'm not setting it here. This is to catch an edge case.
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
gLastFocusedContent = mCurrentFocus;
|
|
|
|
NS_IF_ADDREF(gLastFocusedContent);
|
2001-02-07 07:05:56 +00:00
|
|
|
//If this notification was for focus alone then get rid of aContent
|
|
|
|
//ref to avoid unnecessary notification.
|
|
|
|
if (!(aState & ~NS_EVENT_STATE_FOCUS)) {
|
|
|
|
aContent = nsnull;
|
|
|
|
}
|
1999-12-08 04:54:29 +00:00
|
|
|
} else {
|
2003-09-09 21:09:22 +00:00
|
|
|
// see comments in ShiftFocusInternal on mCurrentFocus overloading
|
|
|
|
PRBool fcActive = PR_FALSE;
|
|
|
|
if (mDocument) {
|
2004-05-03 21:48:36 +00:00
|
|
|
nsIFocusController *fc = GetFocusControllerForDocument(mDocument);
|
2003-09-09 21:09:22 +00:00
|
|
|
if (fc)
|
|
|
|
fc->GetActive(&fcActive);
|
|
|
|
}
|
2004-07-14 22:27:24 +00:00
|
|
|
notifyContent[2] = gLastFocusedContent;
|
2000-04-12 00:24:07 +00:00
|
|
|
NS_IF_ADDREF(gLastFocusedContent);
|
2003-09-09 21:09:22 +00:00
|
|
|
// only raise window if the the focus controller is active
|
2004-07-23 07:27:57 +00:00
|
|
|
SendFocusBlur(mPresContext, aContent, fcActive);
|
2005-08-24 19:06:07 +00:00
|
|
|
if (mCurrentFocus != aContent) {
|
|
|
|
didContentChangeAllStates = PR_FALSE;
|
|
|
|
}
|
2004-03-09 19:34:34 +00:00
|
|
|
|
2005-08-16 17:54:29 +00:00
|
|
|
#ifdef DEBUG_aleventhal
|
2005-11-28 23:56:44 +00:00
|
|
|
nsPIDOMWindow *currentWindow = mDocument->GetWindow();
|
2005-08-16 17:54:29 +00:00
|
|
|
if (currentWindow) {
|
|
|
|
nsIFocusController *fc = currentWindow->GetRootFocusController();
|
|
|
|
if (fc) {
|
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
|
|
|
fc->GetFocusedElement(getter_AddRefs(focusedElement));
|
|
|
|
if (!SameCOMIdentity(mCurrentFocus, focusedElement)) {
|
|
|
|
printf("\n\nFocus out of whack!!!\n\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2004-03-09 19:34:34 +00:00
|
|
|
// If we now have focused content, ensure that the canvas focus ring
|
|
|
|
// is removed.
|
|
|
|
if (mDocument) {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell =
|
|
|
|
do_QueryInterface(nsCOMPtr<nsISupports>(mDocument->GetContainer()));
|
|
|
|
|
|
|
|
if (docShell && mCurrentFocus)
|
|
|
|
docShell->SetCanvasHasFocus(PR_FALSE);
|
|
|
|
}
|
1999-12-08 04:54:29 +00:00
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
|
2004-07-14 22:27:24 +00:00
|
|
|
PRInt32 simpleStates = aState & ~(NS_EVENT_STATE_ACTIVE|NS_EVENT_STATE_HOVER);
|
|
|
|
|
|
|
|
if (aContent && simpleStates != 0) {
|
|
|
|
// notify about new content too
|
1999-04-20 00:03:30 +00:00
|
|
|
notifyContent[0] = aContent;
|
|
|
|
NS_ADDREF(aContent); // everything in notify array has a ref
|
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
|
1999-05-04 14:44:51 +00:00
|
|
|
// remove duplicates
|
|
|
|
if ((notifyContent[4] == notifyContent[3]) || (notifyContent[4] == notifyContent[2]) || (notifyContent[4] == notifyContent[1])) {
|
1999-06-08 19:01:56 +00:00
|
|
|
NS_IF_RELEASE(notifyContent[4]);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
1999-04-20 00:03:30 +00:00
|
|
|
// remove duplicates
|
|
|
|
if ((notifyContent[3] == notifyContent[2]) || (notifyContent[3] == notifyContent[1])) {
|
1999-06-08 19:01:56 +00:00
|
|
|
NS_IF_RELEASE(notifyContent[3]);
|
1999-04-20 00:03:30 +00:00
|
|
|
}
|
|
|
|
if (notifyContent[2] == notifyContent[1]) {
|
1999-06-08 19:01:56 +00:00
|
|
|
NS_IF_RELEASE(notifyContent[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove notifications for content not in document.
|
|
|
|
// we may decide this is possible later but right now it has problems.
|
|
|
|
for (int i = 0; i < maxNotify; i++) {
|
2003-06-13 20:10:01 +00:00
|
|
|
if (notifyContent[i] &&
|
2003-07-28 21:17:26 +00:00
|
|
|
!notifyContent[i]->GetDocument()) {
|
1999-06-08 19:01:56 +00:00
|
|
|
NS_RELEASE(notifyContent[i]);
|
|
|
|
}
|
1999-04-20 00:03:30 +00:00
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
|
1999-04-20 00:03:30 +00:00
|
|
|
// compress the notify array to group notifications tighter
|
|
|
|
nsIContent** from = &(notifyContent[0]);
|
|
|
|
nsIContent** to = &(notifyContent[0]);
|
|
|
|
nsIContent** end = &(notifyContent[maxNotify]);
|
|
|
|
|
|
|
|
while (from < end) {
|
|
|
|
if (! *from) {
|
|
|
|
while (++from < end) {
|
|
|
|
if (*from) {
|
|
|
|
*to++ = *from;
|
|
|
|
*from = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (from == to) {
|
|
|
|
to++;
|
|
|
|
from++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*to++ = *from;
|
|
|
|
*from++ = nsnull;
|
1999-04-12 21:24:07 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-07-14 22:27:24 +00:00
|
|
|
if (notifyContent[0] || newHover || oldHover || newActive || oldActive) {
|
|
|
|
// have at least one to notify about
|
2001-05-14 01:49:07 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc1, doc2; // this presumes content can't get/lose state if not connected to doc
|
2000-09-15 06:17:54 +00:00
|
|
|
if (notifyContent[0]) {
|
2003-07-28 21:17:26 +00:00
|
|
|
doc1 = notifyContent[0]->GetDocument();
|
2001-05-14 01:49:07 +00:00
|
|
|
if (notifyContent[1]) {
|
|
|
|
//For :focus this might be a different doc so check
|
2003-07-28 21:17:26 +00:00
|
|
|
doc2 = notifyContent[1]->GetDocument();
|
2001-05-14 01:49:07 +00:00
|
|
|
if (doc1 == doc2) {
|
|
|
|
doc2 = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
2004-07-14 22:27:24 +00:00
|
|
|
else {
|
2005-06-01 15:38:09 +00:00
|
|
|
EnsureDocument(mPresContext);
|
|
|
|
doc1 = mDocument;
|
2004-07-14 22:27:24 +00:00
|
|
|
}
|
2001-05-14 01:49:07 +00:00
|
|
|
if (doc1) {
|
2003-10-02 21:29:40 +00:00
|
|
|
doc1->BeginUpdate(UPDATE_CONTENT_STATE);
|
2000-09-15 06:17:54 +00:00
|
|
|
|
2004-07-14 22:27:24 +00:00
|
|
|
// Notify all content from newActive to the commonActiveAncestor
|
|
|
|
while (newActive && newActive != commonActiveAncestor) {
|
|
|
|
doc1->ContentStatesChanged(newActive, nsnull, NS_EVENT_STATE_ACTIVE);
|
|
|
|
newActive = newActive->GetParent();
|
|
|
|
}
|
|
|
|
// Notify all content from oldActive to the commonActiveAncestor
|
|
|
|
while (oldActive && oldActive != commonActiveAncestor) {
|
|
|
|
doc1->ContentStatesChanged(oldActive, nsnull, NS_EVENT_STATE_ACTIVE);
|
|
|
|
oldActive = oldActive->GetParent();
|
|
|
|
}
|
|
|
|
|
2002-04-11 03:49:30 +00:00
|
|
|
// Notify all content from newHover to the commonHoverAncestor
|
|
|
|
while (newHover && newHover != commonHoverAncestor) {
|
|
|
|
doc1->ContentStatesChanged(newHover, nsnull, NS_EVENT_STATE_HOVER);
|
2003-07-28 21:17:26 +00:00
|
|
|
newHover = newHover->GetParent();
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
2002-04-11 03:49:30 +00:00
|
|
|
// Notify all content from oldHover to the commonHoverAncestor
|
|
|
|
while (oldHover && oldHover != commonHoverAncestor) {
|
|
|
|
doc1->ContentStatesChanged(oldHover, nsnull, NS_EVENT_STATE_HOVER);
|
2003-07-28 21:17:26 +00:00
|
|
|
oldHover = oldHover->GetParent();
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
|
|
|
|
2002-04-11 03:49:30 +00:00
|
|
|
if (notifyContent[0]) {
|
|
|
|
doc1->ContentStatesChanged(notifyContent[0], notifyContent[1],
|
2004-07-14 22:27:24 +00:00
|
|
|
simpleStates);
|
2002-04-11 03:49:30 +00:00
|
|
|
if (notifyContent[2]) {
|
|
|
|
// more that two notifications are needed (should be rare)
|
|
|
|
// XXX a further optimization here would be to group the
|
|
|
|
// notification pairs together by parent/child, only needed if
|
|
|
|
// more than two content changed (ie: if [0] and [2] are
|
|
|
|
// parent/child, then notify (0,2) (1,3))
|
|
|
|
doc1->ContentStatesChanged(notifyContent[2], notifyContent[3],
|
2004-07-14 22:27:24 +00:00
|
|
|
simpleStates);
|
2002-04-11 03:49:30 +00:00
|
|
|
if (notifyContent[4]) {
|
|
|
|
// more that four notifications are needed (should be rare)
|
|
|
|
doc1->ContentStatesChanged(notifyContent[4], nsnull,
|
2004-07-14 22:27:24 +00:00
|
|
|
simpleStates);
|
2002-04-11 03:49:30 +00:00
|
|
|
}
|
2001-05-14 01:49:07 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-02 21:29:40 +00:00
|
|
|
doc1->EndUpdate(UPDATE_CONTENT_STATE);
|
2001-05-14 01:49:07 +00:00
|
|
|
|
|
|
|
if (doc2) {
|
2003-10-02 21:29:40 +00:00
|
|
|
doc2->BeginUpdate(UPDATE_CONTENT_STATE);
|
2002-04-11 03:49:30 +00:00
|
|
|
doc2->ContentStatesChanged(notifyContent[1], notifyContent[2],
|
2004-07-14 22:27:24 +00:00
|
|
|
simpleStates);
|
2001-05-14 01:49:07 +00:00
|
|
|
if (notifyContent[3]) {
|
2002-04-11 03:49:30 +00:00
|
|
|
doc1->ContentStatesChanged(notifyContent[3], notifyContent[4],
|
2004-07-14 22:27:24 +00:00
|
|
|
simpleStates);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
2003-10-02 21:29:40 +00:00
|
|
|
doc2->EndUpdate(UPDATE_CONTENT_STATE);
|
1999-04-20 00:03:30 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
1999-04-20 00:03:30 +00:00
|
|
|
|
|
|
|
from = &(notifyContent[0]);
|
|
|
|
while (from < to) { // release old refs now that we are through
|
|
|
|
nsIContent* notify = *from++;
|
|
|
|
NS_RELEASE(notify);
|
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
|
|
|
|
2005-08-24 19:06:07 +00:00
|
|
|
return didContentChangeAllStates;
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
2005-08-30 20:22:55 +00:00
|
|
|
static PRBool
|
|
|
|
IsFocusable(nsIPresShell* aPresShell, nsIContent* aContent)
|
|
|
|
{
|
|
|
|
// Flush pending updates to the frame tree first (bug 305840).
|
|
|
|
aPresShell->FlushPendingNotifications(Flush_Frames);
|
|
|
|
|
|
|
|
nsIFrame* focusFrame = aPresShell->GetPrimaryFrameFor(aContent);
|
|
|
|
if (!focusFrame) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XUL frames in general have a somewhat confusing notion of
|
|
|
|
// focusability so we only require a visible frame and that
|
|
|
|
// the content is focusable (not disabled).
|
|
|
|
// We don't use nsIFrame::IsFocusable() because it defaults
|
|
|
|
// tabindex to -1 for -moz-user-focus:ignore (bug 305840).
|
2006-05-05 06:52:21 +00:00
|
|
|
if (aContent->IsNodeOfType(nsINode::eXUL)) {
|
2005-09-01 18:18:08 +00:00
|
|
|
// XXX Eventually we should have a better check, but for
|
|
|
|
// now checking for style visibility and focusability caused
|
|
|
|
// too many regressions.
|
|
|
|
return focusFrame->AreAncestorViewsVisible();
|
2005-08-30 20:22:55 +00:00
|
|
|
}
|
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
if (aContent->Tag() != nsGkAtoms::area) {
|
2005-08-30 20:22:55 +00:00
|
|
|
return focusFrame->IsFocusable();
|
|
|
|
}
|
|
|
|
// HTML areas do not have their own frame, and the img frame we get from
|
|
|
|
// GetPrimaryFrameFor() is not relevant to whether it is focusable or not,
|
|
|
|
// so we have to do all the relevant checks manually for them.
|
|
|
|
return focusFrame->AreAncestorViewsVisible() &&
|
|
|
|
focusFrame->GetStyleVisibility()->IsVisible() &&
|
|
|
|
aContent->IsFocusable();
|
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsEventStateManager::SendFocusBlur(nsPresContext* aPresContext,
|
2003-11-19 01:20:56 +00:00
|
|
|
nsIContent *aContent,
|
|
|
|
PRBool aEnsureWindowHasFocus)
|
1999-03-02 19:19:24 +00:00
|
|
|
{
|
2003-12-21 05:36:36 +00:00
|
|
|
// Keep a ref to presShell since dispatching the DOM event may cause
|
|
|
|
// the document to be destroyed.
|
2006-05-19 10:26:44 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = aPresContext->GetPresShell();
|
2005-03-10 22:53:29 +00:00
|
|
|
if (!presShell)
|
|
|
|
return NS_OK;
|
2003-07-01 22:46:55 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> previousFocus = mCurrentFocus;
|
|
|
|
|
2003-08-29 21:52:25 +00:00
|
|
|
// Make sure previousFocus is in a document. If it's not, then
|
|
|
|
// we should never abort firing events based on what happens when we
|
|
|
|
// send it a blur.
|
|
|
|
|
|
|
|
if (previousFocus && !previousFocus->GetDocument())
|
|
|
|
previousFocus = nsnull;
|
|
|
|
|
2005-10-24 07:38:55 +00:00
|
|
|
// Track the old focus controller if any focus suppressions is used on it.
|
|
|
|
nsFocusSuppressor oldFocusSuppressor;
|
|
|
|
|
1999-12-18 04:02:28 +00:00
|
|
|
if (nsnull != gLastFocusedPresContext) {
|
2003-07-01 22:46:55 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> focusAfterBlur;
|
|
|
|
|
2000-02-11 05:20:44 +00:00
|
|
|
if (gLastFocusedContent && gLastFocusedContent != mFirstBlurEvent) {
|
|
|
|
|
|
|
|
//Store the first blur event we fire and don't refire blur
|
|
|
|
//to that element while the first blur is still ongoing.
|
|
|
|
PRBool clearFirstBlurEvent = PR_FALSE;
|
|
|
|
if (!mFirstBlurEvent) {
|
|
|
|
mFirstBlurEvent = gLastFocusedContent;
|
|
|
|
clearFirstBlurEvent = PR_TRUE;
|
|
|
|
}
|
1999-12-18 04:02:28 +00:00
|
|
|
|
|
|
|
// Retrieve this content node's pres context. it can be out of sync in
|
|
|
|
// the Ender widget case.
|
2003-07-28 21:17:26 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = gLastFocusedContent->GetDocument();
|
1999-12-21 19:35:13 +00:00
|
|
|
if (doc) {
|
2000-10-18 17:41:14 +00:00
|
|
|
// The order of the nsIViewManager and nsIPresShell COM pointers is
|
|
|
|
// important below. We want the pres shell to get released before the
|
|
|
|
// associated view manager on exit from this function.
|
|
|
|
// See bug 53763.
|
|
|
|
nsCOMPtr<nsIViewManager> kungFuDeathGrip;
|
2007-05-01 22:24:20 +00:00
|
|
|
nsIPresShell *shell = doc->GetPrimaryShell();
|
2000-04-05 02:10:25 +00:00
|
|
|
if (shell) {
|
2003-08-06 03:07:12 +00:00
|
|
|
kungFuDeathGrip = shell->GetViewManager();
|
2000-10-18 17:41:14 +00:00
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
nsCOMPtr<nsPresContext> oldPresContext = shell->GetPresContext();
|
1999-12-21 01:12:40 +00:00
|
|
|
|
2000-04-05 02:10:25 +00:00
|
|
|
//fire blur
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEvent event(PR_TRUE, NS_BLUR_CONTENT);
|
2004-02-03 02:22:01 +00:00
|
|
|
|
2000-06-29 20:53:08 +00:00
|
|
|
EnsureDocument(presShell);
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2005-09-06 19:41:31 +00:00
|
|
|
// Make sure we're not switching command dispatchers, if so,
|
|
|
|
// surpress the blurred one
|
|
|
|
if(gLastFocusedDocument && mDocument) {
|
2005-11-28 23:56:44 +00:00
|
|
|
nsPIDOMWindow *newWindow = mDocument->GetWindow();
|
2005-09-06 19:54:55 +00:00
|
|
|
if (newWindow) {
|
|
|
|
nsIFocusController *newFocusController =
|
2005-11-28 23:56:44 +00:00
|
|
|
newWindow->GetRootFocusController();
|
|
|
|
nsPIDOMWindow *oldWindow = gLastFocusedDocument->GetWindow();
|
2005-09-06 19:54:55 +00:00
|
|
|
if (oldWindow) {
|
2005-11-28 23:56:44 +00:00
|
|
|
nsIFocusController *suppressed =
|
|
|
|
oldWindow->GetRootFocusController();
|
|
|
|
|
2005-10-24 07:38:55 +00:00
|
|
|
if (suppressed != newFocusController) {
|
|
|
|
oldFocusSuppressor.Suppress(suppressed, "SendFocusBlur Window Switch #1");
|
2005-09-06 19:54:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-06 19:41:31 +00:00
|
|
|
}
|
|
|
|
|
2000-04-05 02:10:25 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
2004-02-27 17:17:37 +00:00
|
|
|
esm = oldPresContext->EventStateManager();
|
2000-04-05 02:10:25 +00:00
|
|
|
esm->SetFocusedContent(gLastFocusedContent);
|
|
|
|
nsCOMPtr<nsIContent> temp = gLastFocusedContent;
|
2004-04-13 09:39:16 +00:00
|
|
|
NS_RELEASE(gLastFocusedContent); // nulls out gLastFocusedContent
|
2002-07-24 06:13:18 +00:00
|
|
|
|
|
|
|
nsCxPusher pusher(temp);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(temp, oldPresContext, &event, nsnull,
|
|
|
|
&status);
|
2002-07-24 06:13:18 +00:00
|
|
|
pusher.Pop();
|
|
|
|
|
2003-07-01 22:46:55 +00:00
|
|
|
focusAfterBlur = mCurrentFocus;
|
2003-10-27 19:52:49 +00:00
|
|
|
if (!previousFocus || previousFocus == focusAfterBlur)
|
|
|
|
esm->SetFocusedContent(nsnull);
|
2000-04-05 02:10:25 +00:00
|
|
|
}
|
1999-12-21 01:12:40 +00:00
|
|
|
}
|
2000-02-11 05:20:44 +00:00
|
|
|
|
|
|
|
if (clearFirstBlurEvent) {
|
2002-12-17 02:10:57 +00:00
|
|
|
mFirstBlurEvent = nsnull;
|
2000-02-11 05:20:44 +00:00
|
|
|
}
|
2003-07-01 22:46:55 +00:00
|
|
|
|
2003-08-29 21:52:25 +00:00
|
|
|
if (previousFocus && previousFocus != focusAfterBlur) {
|
2003-07-01 22:46:55 +00:00
|
|
|
// The content node's blur handler focused something else.
|
|
|
|
// In this case, abort firing any more blur or focus events.
|
2005-08-16 17:54:29 +00:00
|
|
|
EnsureFocusSynchronization();
|
2003-07-01 22:46:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-12-18 04:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Go ahead and fire a blur on the window.
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window;
|
2000-02-11 01:24:59 +00:00
|
|
|
|
2000-02-12 08:33:12 +00:00
|
|
|
if(gLastFocusedDocument)
|
2005-11-28 23:56:44 +00:00
|
|
|
window = gLastFocusedDocument->GetWindow();
|
2000-06-28 20:35:32 +00:00
|
|
|
|
|
|
|
EnsureDocument(presShell);
|
1999-12-18 04:02:28 +00:00
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
if (gLastFocusedDocument && (gLastFocusedDocument != mDocument) &&
|
|
|
|
window) {
|
1999-12-18 04:02:28 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEvent event(PR_TRUE, NS_BLUR_CONTENT);
|
1999-12-18 04:02:28 +00:00
|
|
|
|
2005-09-06 19:41:31 +00:00
|
|
|
// Make sure we're not switching command dispatchers, if so,
|
2005-10-24 07:38:55 +00:00
|
|
|
// suppress the blurred one if it isn't already suppressed
|
|
|
|
if (mDocument && !oldFocusSuppressor.Suppressing()) {
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> newWindow(mDocument->GetWindow());
|
2005-09-06 19:54:55 +00:00
|
|
|
|
|
|
|
if (newWindow) {
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> oldWindow(gLastFocusedDocument->GetWindow());
|
|
|
|
nsIFocusController *newFocusController =
|
|
|
|
newWindow->GetRootFocusController();
|
2005-09-06 19:54:55 +00:00
|
|
|
if (oldWindow) {
|
2005-11-28 23:56:44 +00:00
|
|
|
nsIFocusController *suppressed =
|
|
|
|
oldWindow->GetRootFocusController();
|
2005-10-24 07:38:55 +00:00
|
|
|
if (suppressed != newFocusController) {
|
|
|
|
oldFocusSuppressor.Suppress(suppressed, "SendFocusBlur Window Switch #2");
|
2005-09-06 19:54:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-09-06 19:41:31 +00:00
|
|
|
}
|
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
gLastFocusedPresContext->EventStateManager()->SetFocusedContent(nsnull);
|
2000-02-12 08:33:12 +00:00
|
|
|
nsCOMPtr<nsIDocument> temp = gLastFocusedDocument;
|
|
|
|
NS_RELEASE(gLastFocusedDocument);
|
|
|
|
gLastFocusedDocument = nsnull;
|
2002-07-24 06:13:18 +00:00
|
|
|
|
|
|
|
nsCxPusher pusher(temp);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(temp, gLastFocusedPresContext, &event, nsnull,
|
|
|
|
&status);
|
2002-07-24 06:13:18 +00:00
|
|
|
pusher.Pop();
|
|
|
|
|
2003-08-29 21:52:25 +00:00
|
|
|
if (previousFocus && mCurrentFocus != previousFocus) {
|
2003-07-01 22:46:55 +00:00
|
|
|
// The document's blur handler focused something else.
|
2005-08-16 17:54:29 +00:00
|
|
|
// Abort firing any additional blur or focus events, and make sure
|
|
|
|
// nsFocusController:mFocusedElement is not nulled out, but agrees
|
|
|
|
// with our current concept of focus.
|
|
|
|
EnsureFocusSynchronization();
|
2003-07-01 22:46:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
pusher.Push(window);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(window, gLastFocusedPresContext, &event,
|
|
|
|
nsnull, &status);
|
2003-07-01 22:46:55 +00:00
|
|
|
|
2003-08-29 21:52:25 +00:00
|
|
|
if (previousFocus && mCurrentFocus != previousFocus) {
|
2003-07-01 22:46:55 +00:00
|
|
|
// The window's blur handler focused something else.
|
|
|
|
// Abort firing any additional blur or focus events.
|
2005-08-16 17:54:29 +00:00
|
|
|
EnsureFocusSynchronization();
|
2003-07-01 22:46:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-12-18 04:02:28 +00:00
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
// Check if the nsEventDispatcher::Dispatch calls above destroyed our frame
|
|
|
|
// (bug #118685) or made it not focusable in any way.
|
2005-08-30 20:22:55 +00:00
|
|
|
if (aContent && !::IsFocusable(presShell, aContent)) {
|
|
|
|
aContent = nsnull;
|
2003-11-07 03:35:05 +00:00
|
|
|
}
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
gLastFocusedContent = aContent;
|
2002-12-17 02:10:57 +00:00
|
|
|
NS_IF_ADDREF(gLastFocusedContent);
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(aContent);
|
2006-10-19 01:59:00 +00:00
|
|
|
EnsureFocusSynchronization();
|
2003-03-18 23:41:44 +00:00
|
|
|
|
2002-05-17 04:04:24 +00:00
|
|
|
// Moved widget focusing code here, from end of SendFocusBlur
|
2004-07-23 07:27:57 +00:00
|
|
|
// This fixes the order of accessibility focus events, so that
|
2002-05-17 04:04:24 +00:00
|
|
|
// the window focus event goes first, and then the focus event for the control
|
|
|
|
if (aEnsureWindowHasFocus) {
|
2005-10-29 12:50:22 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
// Plug-ins with native widget need a special handling
|
|
|
|
nsIFrame* currentFocusFrame = nsnull;
|
|
|
|
if (mCurrentFocus)
|
|
|
|
currentFocusFrame = presShell->GetPrimaryFrameFor(mCurrentFocus);
|
|
|
|
if (!currentFocusFrame)
|
|
|
|
currentFocusFrame = mCurrentTarget;
|
2005-11-01 04:18:11 +00:00
|
|
|
nsIObjectFrame* objFrame = nsnull;
|
2005-10-29 12:50:22 +00:00
|
|
|
if (currentFocusFrame)
|
2005-11-01 04:18:11 +00:00
|
|
|
CallQueryInterface(currentFocusFrame, &objFrame);
|
2005-10-29 12:50:22 +00:00
|
|
|
if (objFrame) {
|
|
|
|
nsIView* view = currentFocusFrame->GetViewExternal();
|
|
|
|
NS_ASSERTION(view, "Object frames must have views");
|
|
|
|
widget = view->GetWidget();
|
2002-05-17 04:04:24 +00:00
|
|
|
}
|
2005-10-29 12:50:22 +00:00
|
|
|
if (!widget) {
|
|
|
|
// This raises the window that has both content and scroll bars in it
|
|
|
|
// instead of the child window just below it that contains only the content
|
|
|
|
// That way we focus the same window that gets focused by a mouse click
|
|
|
|
nsIViewManager* vm = presShell->GetViewManager();
|
|
|
|
if (vm) {
|
|
|
|
vm->GetWidget(getter_AddRefs(widget));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (widget)
|
|
|
|
widget->SetFocus(PR_TRUE);
|
2002-05-17 04:04:24 +00:00
|
|
|
}
|
|
|
|
|
2000-02-11 05:20:44 +00:00
|
|
|
if (nsnull != aContent && aContent != mFirstFocusEvent) {
|
|
|
|
|
|
|
|
//Store the first focus event we fire and don't refire focus
|
|
|
|
//to that element while the first focus is still ongoing.
|
|
|
|
PRBool clearFirstFocusEvent = PR_FALSE;
|
|
|
|
if (!mFirstFocusEvent) {
|
|
|
|
mFirstFocusEvent = aContent;
|
|
|
|
clearFirstFocusEvent = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
//fire focus
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEvent event(PR_TRUE, NS_FOCUS_CONTENT);
|
1999-03-02 19:19:24 +00:00
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
if (nsnull != mPresContext) {
|
2002-07-24 06:13:18 +00:00
|
|
|
nsCxPusher pusher(aContent);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(aContent, mPresContext, &event, nsnull,
|
|
|
|
&status);
|
|
|
|
nsAutoString name;
|
|
|
|
aContent->Tag()->ToString(name);
|
1999-04-12 21:24:07 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
nsAutoString tabIndex;
|
2006-12-26 17:47:52 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::tabindex, tabIndex);
|
1999-04-12 21:24:07 +00:00
|
|
|
PRInt32 ec, val = tabIndex.ToInteger(&ec);
|
2003-03-12 03:22:11 +00:00
|
|
|
if (NS_SUCCEEDED (ec)) {
|
1999-04-12 21:24:07 +00:00
|
|
|
mCurrentTabIndex = val;
|
|
|
|
}
|
2000-02-11 05:20:44 +00:00
|
|
|
|
|
|
|
if (clearFirstFocusEvent) {
|
2002-12-17 02:10:57 +00:00
|
|
|
mFirstFocusEvent = nsnull;
|
2003-03-12 03:22:11 +00:00
|
|
|
}
|
2001-08-21 02:27:34 +00:00
|
|
|
} else if (!aContent) {
|
|
|
|
//fire focus on document even if the content isn't focusable (ie. text)
|
|
|
|
//see bugzilla bug 93521
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2005-04-28 23:48:28 +00:00
|
|
|
nsEvent event(PR_TRUE, NS_FOCUS_CONTENT);
|
2004-02-03 02:22:01 +00:00
|
|
|
|
2001-08-21 02:27:34 +00:00
|
|
|
if (nsnull != mPresContext && mDocument) {
|
2002-07-24 06:13:18 +00:00
|
|
|
nsCxPusher pusher(mDocument);
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventDispatcher::Dispatch(mDocument, mPresContext, &event, nsnull,
|
|
|
|
&status);
|
2001-08-14 00:44:13 +00:00
|
|
|
}
|
1999-12-08 04:54:29 +00:00
|
|
|
}
|
1999-09-20 22:18:57 +00:00
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
if (mBrowseWithCaret)
|
|
|
|
SetContentCaretVisible(presShell, aContent, PR_TRUE);
|
2001-02-15 05:07:46 +00:00
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-26 15:02:19 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::GetFocusedContent(nsIContent** aContent)
|
|
|
|
{
|
|
|
|
*aContent = mCurrentFocus;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-16 17:54:29 +00:00
|
|
|
void nsEventStateManager::EnsureFocusSynchronization()
|
|
|
|
{
|
|
|
|
// Sometimes the focus can get out of whack due to a blur handler
|
|
|
|
// resetting focus. In addition, we fire onchange from the blur handler
|
|
|
|
// for some controls, which is another place where focus can be changed.
|
|
|
|
// XXX Ideally we will eventually store focus in one place instead of
|
|
|
|
// the focus controller, esm, tabbrowser and some frames, so that it
|
|
|
|
// cannot get out of sync.
|
|
|
|
// See Bug 304751, calling FireOnChange() inside
|
|
|
|
// nsComboboxControlFrame::SetFocus() is bad
|
2005-11-28 23:56:44 +00:00
|
|
|
nsPIDOMWindow *currentWindow = mDocument->GetWindow();
|
2005-08-16 17:54:29 +00:00
|
|
|
if (currentWindow) {
|
|
|
|
nsIFocusController *fc = currentWindow->GetRootFocusController();
|
|
|
|
if (fc) {
|
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement = do_QueryInterface(mCurrentFocus);
|
|
|
|
fc->SetFocusedElement(focusedElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::SetFocusedContent(nsIContent* aContent)
|
|
|
|
{
|
2005-08-02 13:44:55 +00:00
|
|
|
|
|
|
|
if (aContent &&
|
|
|
|
(!mPresContext || mPresContext->Type() == nsPresContext::eContext_PrintPreview)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
mCurrentFocus = aContent;
|
2005-06-24 04:25:43 +00:00
|
|
|
if (mCurrentFocus)
|
|
|
|
mLastFocus = mCurrentFocus;
|
2003-03-18 23:41:44 +00:00
|
|
|
mCurrentFocusFrame = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-06-24 04:25:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::GetLastFocusedContent(nsIContent** aContent)
|
|
|
|
{
|
|
|
|
*aContent = mLastFocus;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-18 23:41:44 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::GetFocusedFrame(nsIFrame** aFrame)
|
|
|
|
{
|
|
|
|
if (!mCurrentFocusFrame && mCurrentFocus) {
|
2003-07-28 21:17:26 +00:00
|
|
|
nsIDocument* doc = mCurrentFocus->GetDocument();
|
2003-03-18 23:41:44 +00:00
|
|
|
if (doc) {
|
2007-05-01 22:24:20 +00:00
|
|
|
nsIPresShell *shell = doc->GetPrimaryShell();
|
2003-03-18 23:41:44 +00:00
|
|
|
if (shell) {
|
2005-08-22 22:24:29 +00:00
|
|
|
mCurrentFocusFrame = shell->GetPrimaryFrameFor(mCurrentFocus);
|
2003-03-18 23:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aFrame = mCurrentFocusFrame;
|
1999-12-08 04:54:29 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-29 00:04:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::ContentRemoved(nsIContent* aContent)
|
|
|
|
{
|
2005-05-19 16:18:32 +00:00
|
|
|
if (mCurrentFocus &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mCurrentFocus, aContent)) {
|
2001-11-29 00:04:31 +00:00
|
|
|
// Note that we don't use SetContentState() here because
|
|
|
|
// we don't want to fire a blur. Blurs should only be fired
|
|
|
|
// in response to clicks or tabbing.
|
2006-04-11 16:37:58 +00:00
|
|
|
nsIMEStateManager::OnRemoveContent(mPresContext, mCurrentFocus);
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(nsnull);
|
2001-11-29 00:04:31 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 04:25:43 +00:00
|
|
|
if (mLastFocus &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mLastFocus, aContent)) {
|
|
|
|
mLastFocus = nsnull;
|
|
|
|
}
|
|
|
|
|
2005-05-19 16:18:32 +00:00
|
|
|
if (mHoverContent &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mHoverContent, aContent)) {
|
2002-08-19 18:31:59 +00:00
|
|
|
// Since hover is hierarchical, set the current hover to the
|
|
|
|
// content's parent node.
|
2003-07-28 21:17:26 +00:00
|
|
|
mHoverContent = aContent->GetParent();
|
2002-08-19 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
2005-06-01 15:36:11 +00:00
|
|
|
if (mActiveContent &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mActiveContent, aContent)) {
|
|
|
|
// Active is hierarchical, so set the current active to the
|
|
|
|
// content's parent node.
|
|
|
|
mActiveContent = aContent->GetParent();
|
2002-08-19 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
2005-06-01 15:36:11 +00:00
|
|
|
if (mDragOverContent &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mDragOverContent, aContent)) {
|
2002-12-17 02:10:57 +00:00
|
|
|
mDragOverContent = nsnull;
|
2002-08-19 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
2005-06-01 15:36:11 +00:00
|
|
|
if (mLastMouseOverElement &&
|
|
|
|
nsContentUtils::ContentIsDescendantOf(mLastMouseOverElement, aContent)) {
|
|
|
|
// See bug 292146 for why we want to null this out
|
2005-04-28 20:47:53 +00:00
|
|
|
mLastMouseOverElement = nsnull;
|
|
|
|
}
|
|
|
|
|
2001-11-29 00:04:31 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-20 07:22:55 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::EventStatusOK(nsGUIEvent* aEvent, PRBool *aOK)
|
|
|
|
{
|
|
|
|
*aOK = PR_TRUE;
|
2006-11-16 21:35:39 +00:00
|
|
|
if (aEvent->message == NS_MOUSE_BUTTON_DOWN &&
|
|
|
|
NS_STATIC_CAST(nsMouseEvent*, aEvent)->button == nsMouseEvent::eLeftButton) {
|
2002-02-20 07:22:55 +00:00
|
|
|
if (!mNormalLMouseEventInProcess) {
|
|
|
|
*aOK = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-29 00:04:31 +00:00
|
|
|
|
2000-02-09 15:14:55 +00:00
|
|
|
//-------------------------------------------
|
|
|
|
// Access Key Registration
|
|
|
|
//-------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2002-05-22 00:14:51 +00:00
|
|
|
nsEventStateManager::RegisterAccessKey(nsIContent* aContent, PRUint32 aKey)
|
2000-02-09 15:14:55 +00:00
|
|
|
{
|
2000-05-16 10:22:20 +00:00
|
|
|
if (!mAccessKeys) {
|
|
|
|
mAccessKeys = new nsSupportsHashtable();
|
|
|
|
if (!mAccessKeys) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-22 00:14:51 +00:00
|
|
|
if (aContent) {
|
2005-07-03 12:19:26 +00:00
|
|
|
PRUint32 accKey = (IS_IN_BMP(aKey)) ? ToLowerCase((PRUnichar)aKey) : aKey;
|
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
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
nsVoidKey key(NS_INT32_TO_PTR(accKey));
|
2000-05-16 10:22:20 +00:00
|
|
|
|
2002-02-21 13:39:39 +00:00
|
|
|
#ifdef DEBUG_jag
|
|
|
|
nsCOMPtr<nsIContent> oldContent = dont_AddRef(NS_STATIC_CAST(nsIContent*, mAccessKeys->Get(&key)));
|
|
|
|
NS_ASSERTION(!oldContent, "Overwriting accesskey registration");
|
|
|
|
#endif
|
2002-05-22 00:14:51 +00:00
|
|
|
mAccessKeys->Put(&key, aContent);
|
2000-05-16 10:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-09 15:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-22 00:14:51 +00:00
|
|
|
nsEventStateManager::UnregisterAccessKey(nsIContent* aContent, PRUint32 aKey)
|
2000-02-09 15:14:55 +00:00
|
|
|
{
|
2000-05-16 10:22:20 +00:00
|
|
|
if (!mAccessKeys) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-05-22 00:14:51 +00:00
|
|
|
if (aContent) {
|
2005-07-03 12:19:26 +00:00
|
|
|
PRUint32 accKey = (IS_IN_BMP(aKey)) ? ToLowerCase((PRUnichar)aKey) : aKey;
|
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
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
nsVoidKey key(NS_INT32_TO_PTR(accKey));
|
2000-05-16 10:22:20 +00:00
|
|
|
|
2002-02-21 13:39:39 +00:00
|
|
|
nsCOMPtr<nsIContent> oldContent = dont_AddRef(NS_STATIC_CAST(nsIContent*, mAccessKeys->Get(&key)));
|
|
|
|
#ifdef DEBUG_jag
|
2002-05-22 00:14:51 +00:00
|
|
|
NS_ASSERTION(oldContent == aContent, "Trying to unregister wrong content");
|
2002-02-21 13:39:39 +00:00
|
|
|
#endif
|
2002-05-22 00:14:51 +00:00
|
|
|
if (oldContent != aContent)
|
2000-05-16 10:22:20 +00:00
|
|
|
return NS_OK;
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2000-05-16 10:22:20 +00:00
|
|
|
mAccessKeys->Remove(&key);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2000-02-09 15:14:55 +00:00
|
|
|
}
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::ForceViewUpdate(nsIView* aView)
|
2000-01-11 22:30:22 +00:00
|
|
|
{
|
|
|
|
// force the update to happen now, otherwise multiple scrolls can
|
|
|
|
// occur before the update is processed. (bug #7354)
|
|
|
|
|
2003-08-06 03:07:12 +00:00
|
|
|
nsIViewManager* vm = aView->GetViewManager();
|
|
|
|
if (vm) {
|
2000-01-11 22:30:22 +00:00
|
|
|
// I'd use Composite here, but it doesn't always work.
|
|
|
|
// vm->Composite();
|
2000-01-26 23:04:40 +00:00
|
|
|
vm->ForceUpdate();
|
2000-01-11 22:30:22 +00:00
|
|
|
}
|
|
|
|
}
|
1999-11-21 01:46:41 +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
|
|
|
|
nsEventStateManager::EnsureDocument(nsIPresShell* aPresShell)
|
|
|
|
{
|
2000-06-28 20:35:32 +00:00
|
|
|
if (!mDocument && aPresShell)
|
2004-08-02 04:52:55 +00:00
|
|
|
mDocument = aPresShell->GetDocument();
|
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) {
|
2005-01-20 03:39:09 +00:00
|
|
|
shell->FlushPendingNotifications(Flush_Display);
|
2001-01-20 04:59:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-01 14:58:34 +00:00
|
|
|
nsresult
|
2003-09-27 04:18:26 +00:00
|
|
|
nsEventStateManager::GetDocSelectionLocation(nsIContent **aStartContent,
|
|
|
|
nsIContent **aEndContent,
|
|
|
|
nsIFrame **aStartFrame,
|
|
|
|
PRUint32* aStartOffset)
|
2001-02-15 05:07:46 +00:00
|
|
|
{
|
|
|
|
// In order to return the nsIContent and nsIFrame of the caret's position,
|
|
|
|
// we need to get a pres shell, and then get the selection from it
|
|
|
|
|
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
|
|
|
*aStartOffset = 0;
|
2004-07-23 07:27:57 +00:00
|
|
|
*aStartFrame = nsnull;
|
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
|
|
|
*aStartContent = *aEndContent = nsnull;
|
2001-02-15 05:07:46 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2005-07-13 16:03:57 +00:00
|
|
|
NS_ASSERTION(mPresContext, "mPresContent is null!!");
|
|
|
|
EnsureDocument(mPresContext);
|
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
|
|
|
if (!mDocument)
|
|
|
|
return rv;
|
2005-07-13 16:03:57 +00:00
|
|
|
nsIPresShell *shell;
|
|
|
|
shell = mPresContext->GetPresShell();
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2006-04-26 01:57:22 +00:00
|
|
|
nsFrameSelection *frameSelection = nsnull;
|
2004-07-23 07:27:57 +00:00
|
|
|
if (shell)
|
2004-08-29 03:08:44 +00:00
|
|
|
frameSelection = shell->FrameSelection();
|
2001-02-15 05:07:46 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> domSelection;
|
2006-04-26 01:57:22 +00:00
|
|
|
if (frameSelection) {
|
|
|
|
domSelection = frameSelection->
|
|
|
|
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
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
|
|
|
nsCOMPtr<nsIDOMNode> startNode, endNode;
|
|
|
|
PRBool isCollapsed = PR_FALSE;
|
2002-03-21 02:37:48 +00:00
|
|
|
nsCOMPtr<nsIContent> startContent, endContent;
|
2001-02-15 05:07:46 +00:00
|
|
|
if (domSelection) {
|
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
|
|
|
domSelection->GetIsCollapsed(&isCollapsed);
|
|
|
|
nsCOMPtr<nsIDOMRange> domRange;
|
|
|
|
rv = domSelection->GetRangeAt(0, getter_AddRefs(domRange));
|
|
|
|
if (domRange) {
|
|
|
|
domRange->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
domRange->GetEndContainer(getter_AddRefs(endNode));
|
2003-09-27 04:18:26 +00:00
|
|
|
domRange->GetStartOffset(NS_REINTERPRET_CAST(PRInt32 *, aStartOffset));
|
2002-03-21 02:37:48 +00:00
|
|
|
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIContent *childContent = nsnull;
|
2002-03-21 02:37:48 +00:00
|
|
|
|
|
|
|
startContent = do_QueryInterface(startNode);
|
2006-07-20 05:25:20 +00:00
|
|
|
if (startContent && startContent->IsNodeOfType(nsINode::eELEMENT)) {
|
2004-11-19 04:28:56 +00:00
|
|
|
NS_ASSERTION(*aStartOffset >= 0, "Start offset cannot be negative");
|
2003-09-27 04:18:26 +00:00
|
|
|
childContent = startContent->GetChildAt(*aStartOffset);
|
2004-11-19 04:28:56 +00:00
|
|
|
if (childContent) {
|
2002-03-21 02:37:48 +00:00
|
|
|
startContent = childContent;
|
2004-11-19 04:28:56 +00:00
|
|
|
}
|
2002-03-21 02:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
endContent = do_QueryInterface(endNode);
|
2006-07-20 05:25:20 +00:00
|
|
|
if (endContent && endContent->IsNodeOfType(nsINode::eELEMENT)) {
|
2002-03-21 02:37:48 +00:00
|
|
|
PRInt32 endOffset = 0;
|
|
|
|
domRange->GetEndOffset(&endOffset);
|
2004-11-19 04:28:56 +00:00
|
|
|
NS_ASSERTION(endOffset >= 0, "End offset cannot be negative");
|
|
|
|
childContent = endContent->GetChildAt(endOffset);
|
|
|
|
if (childContent) {
|
|
|
|
endContent = childContent;
|
2004-09-01 14:58:34 +00:00
|
|
|
}
|
2002-03-21 02:37:48 +00:00
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
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
|
|
|
}
|
2006-04-26 01:57:22 +00:00
|
|
|
else {
|
|
|
|
rv = NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
nsIFrame *startFrame = nsnull;
|
|
|
|
if (startContent) {
|
2005-08-22 22:24:29 +00:00
|
|
|
startFrame = shell->GetPrimaryFrameFor(startContent);
|
|
|
|
if (isCollapsed) {
|
2004-08-02 17:56:43 +00:00
|
|
|
// First check to see if we're in a <label>
|
|
|
|
// We don't want to return the selection in a label, because
|
|
|
|
// we we should be tabbing relative to what the label
|
|
|
|
// points to (the current focus), not relative to the label itself.
|
|
|
|
nsIContent *parentContent = startContent;
|
|
|
|
while ((parentContent = parentContent->GetParent()) != nsnull) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (parentContent->Tag() == nsGkAtoms::label) {
|
2004-08-02 17:56:43 +00:00
|
|
|
return NS_OK; // Don't return selection location, we're on a label
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Next check to see if our caret is at the very end of a node
|
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
|
|
|
// If so, the caret is actually sitting in front of the next
|
|
|
|
// logical frame's primary node - so for this case we need to
|
|
|
|
// change caretContent to that node.
|
2002-04-27 01:20:48 +00:00
|
|
|
|
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
|
|
|
nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(startContent));
|
2002-04-27 01:20:48 +00:00
|
|
|
PRUint16 nodeType;
|
|
|
|
domNode->GetNodeType(&nodeType);
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
if (nodeType == nsIDOMNode::TEXT_NODE) {
|
2002-04-27 01:20:48 +00:00
|
|
|
nsAutoString nodeValue;
|
|
|
|
domNode->GetNodeValue(nodeValue);
|
|
|
|
|
2002-08-06 08:32:19 +00:00
|
|
|
PRBool isFormControl =
|
2006-05-05 06:52:21 +00:00
|
|
|
startContent->IsNodeOfType(nsINode::eHTML_FORM_CONTROL);
|
2002-04-27 01:20:48 +00:00
|
|
|
|
2002-08-06 08:32:19 +00:00
|
|
|
if (nodeValue.Length() == *aStartOffset && !isFormControl &&
|
2003-10-22 06:09:48 +00:00
|
|
|
startContent != mDocument->GetRootContent()) {
|
2002-04-27 01:20:48 +00:00
|
|
|
// Yes, indeed we were at the end of the last node
|
|
|
|
nsCOMPtr<nsIBidirectionalEnumerator> frameTraversal;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFrameTraversal> trav(do_CreateInstance(kFrameTraversalCID,
|
|
|
|
&rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-08-30 13:38:16 +00:00
|
|
|
rv = trav->NewFrameTraversal(getter_AddRefs(frameTraversal),
|
|
|
|
mPresContext, startFrame,
|
|
|
|
eLeaf,
|
|
|
|
PR_FALSE, // aVisual
|
|
|
|
PR_FALSE, // aLockInScrollView
|
|
|
|
PR_FALSE // aFollowOOFs
|
|
|
|
);
|
2002-04-27 01:20:48 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-04-04 18:11:14 +00:00
|
|
|
nsIFrame *newCaretFrame = nsnull;
|
|
|
|
nsCOMPtr<nsIContent> newCaretContent = startContent;
|
|
|
|
PRBool endOfSelectionInStartNode(startContent == endContent);
|
2004-07-23 07:27:57 +00:00
|
|
|
do {
|
2005-04-04 18:11:14 +00:00
|
|
|
// Continue getting the next frame until the primary content for the frame
|
2002-04-27 01:20:48 +00:00
|
|
|
// we are on changes - we don't want to be stuck in the same place
|
|
|
|
frameTraversal->Next();
|
|
|
|
nsISupports* currentItem;
|
|
|
|
frameTraversal->CurrentItem(¤tItem);
|
2005-04-04 18:11:14 +00:00
|
|
|
if (nsnull == (newCaretFrame = NS_STATIC_CAST(nsIFrame*, currentItem))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
newCaretContent = newCaretFrame->GetContent();
|
|
|
|
} while (!newCaretContent || newCaretContent == startContent);
|
|
|
|
|
|
|
|
if (newCaretFrame && newCaretContent) {
|
|
|
|
// If the caret is exactly at the same position of the new frame,
|
|
|
|
// then we can use the newCaretFrame and newCaretContent for our position
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
|
|
|
shell->GetCaret(getter_AddRefs(caret));
|
|
|
|
nsRect caretRect;
|
|
|
|
nsIView *caretView;
|
|
|
|
caret->GetCaretCoordinates(nsICaret::eClosestViewCoordinates,
|
|
|
|
domSelection, &caretRect,
|
|
|
|
&isCollapsed, &caretView);
|
|
|
|
nsPoint framePt;
|
|
|
|
nsIView *frameClosestView = newCaretFrame->GetClosestView(&framePt);
|
|
|
|
if (caretView == frameClosestView && caretRect.y == framePt.y &&
|
|
|
|
caretRect.x == framePt.x) {
|
|
|
|
// The caret is at the start of the new element.
|
|
|
|
startFrame = newCaretFrame;
|
|
|
|
startContent = newCaretContent;
|
|
|
|
if (endOfSelectionInStartNode) {
|
|
|
|
endContent = newCaretContent; // Ensure end of selection is not before start
|
|
|
|
}
|
2002-04-27 01:20:48 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
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
|
|
|
*aStartFrame = startFrame;
|
|
|
|
*aStartContent = startContent;
|
|
|
|
*aEndContent = endContent;
|
|
|
|
NS_IF_ADDREF(*aStartContent);
|
|
|
|
NS_IF_ADDREF(*aEndContent);
|
2001-02-15 05:07:46 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::FocusElementButNotDocument(nsIContent *aContent)
|
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
|
|
|
{
|
|
|
|
// Focus an element in the current document, but don't switch document/window focus!
|
|
|
|
|
2003-03-06 18:42:49 +00:00
|
|
|
if (gLastFocusedDocument == mDocument) {
|
2004-07-23 07:27:57 +00:00
|
|
|
// If we're already focused in this document,
|
2003-01-07 02:09:06 +00:00
|
|
|
// use normal focus method
|
2002-06-25 22:57:48 +00:00
|
|
|
if (mCurrentFocus != aContent) {
|
2004-07-23 07:27:57 +00:00
|
|
|
if (aContent)
|
2002-06-25 22:57:48 +00:00
|
|
|
aContent->SetFocus(mPresContext);
|
|
|
|
else
|
2002-07-09 06:29:45 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
2002-06-25 22:57:48 +00:00
|
|
|
}
|
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
|
|
|
return;
|
|
|
|
}
|
2003-01-07 02:09:06 +00:00
|
|
|
|
2003-08-01 09:41:12 +00:00
|
|
|
/**
|
|
|
|
* The last focus wasn't in this document, so we may be getting our position from the selection
|
|
|
|
* while the window focus is currently somewhere else such as the find dialog
|
|
|
|
*/
|
|
|
|
|
2004-05-03 21:48:36 +00:00
|
|
|
nsIFocusController *focusController =
|
|
|
|
GetFocusControllerForDocument(mDocument);
|
2003-08-01 09:41:12 +00:00
|
|
|
if (!focusController)
|
|
|
|
return;
|
2003-03-06 18:42:49 +00:00
|
|
|
|
2003-08-01 09:41:12 +00:00
|
|
|
// Get previous focus
|
|
|
|
nsCOMPtr<nsIDOMElement> oldFocusedElement;
|
|
|
|
focusController->GetFocusedElement(getter_AddRefs(oldFocusedElement));
|
|
|
|
nsCOMPtr<nsIContent> oldFocusedContent(do_QueryInterface(oldFocusedElement));
|
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
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
// Temporarily set mCurrentFocus so that esm::GetContentState() tells
|
|
|
|
// layout system to show focus on this element.
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(aContent); // Reset back to null at the end of this method.
|
2003-10-02 21:29:40 +00:00
|
|
|
mDocument->BeginUpdate(UPDATE_CONTENT_STATE);
|
2004-07-23 07:27:57 +00:00
|
|
|
mDocument->ContentStatesChanged(oldFocusedContent, aContent,
|
2003-08-01 09:41:12 +00:00
|
|
|
NS_EVENT_STATE_FOCUS);
|
2003-10-02 21:29:40 +00:00
|
|
|
mDocument->EndUpdate(UPDATE_CONTENT_STATE);
|
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
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
// Reset mCurrentFocus = nsnull for this doc, so when this document
|
2003-08-01 09:41:12 +00:00
|
|
|
// does get focus next time via preHandleEvent() NS_GOTFOCUS,
|
|
|
|
// the old document gets blurred
|
2003-11-07 03:35:05 +00:00
|
|
|
SetFocusedContent(nsnull);
|
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
|
|
|
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::MoveFocusToCaret(PRBool aCanFocusDoc,
|
|
|
|
PRBool *aIsSelectionWithFocus)
|
2001-02-15 05:07:46 +00:00
|
|
|
{
|
|
|
|
// mBrowseWithCaret equals the pref accessibility.browsewithcaret
|
|
|
|
// When it's true, the user can arrow around the browser as if it's a
|
|
|
|
// read only text editor.
|
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
|
|
|
|
|
|
|
// If the user cursors over a focusable element or gets there with find text, then send focus to it
|
|
|
|
|
|
|
|
*aIsSelectionWithFocus= PR_FALSE;
|
|
|
|
nsCOMPtr<nsIContent> selectionContent, endSelectionContent;
|
|
|
|
nsIFrame *selectionFrame;
|
|
|
|
PRUint32 selectionOffset;
|
|
|
|
GetDocSelectionLocation(getter_AddRefs(selectionContent), getter_AddRefs(endSelectionContent),
|
|
|
|
&selectionFrame, &selectionOffset);
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
if (!selectionContent)
|
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
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> testContent(selectionContent);
|
|
|
|
nsCOMPtr<nsIContent> nextTestContent(endSelectionContent);
|
|
|
|
|
|
|
|
// We now have the correct start node in selectionContent!
|
|
|
|
// Search for focusable elements, starting with selectionContent
|
|
|
|
|
|
|
|
// Method #1: Keep going up while we look - an ancestor might be focusable
|
|
|
|
// We could end the loop earlier, such as when we're no longer
|
|
|
|
// in the same frame, by comparing getPrimaryFrameFor(selectionContent)
|
|
|
|
// with a variable holding the starting selectionContent
|
|
|
|
while (testContent) {
|
|
|
|
// Keep testing while selectionContent is equal to something,
|
|
|
|
// eventually we'll run out of ancestors
|
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
if (testContent == mCurrentFocus) {
|
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
|
|
|
*aIsSelectionWithFocus = PR_TRUE;
|
|
|
|
return NS_OK; // already focused on this node, this whole thing's moot
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
nsIAtom *tag = testContent->Tag();
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
// Add better focusable test here later if necessary ...
|
2006-12-26 17:47:52 +00:00
|
|
|
if (tag == nsGkAtoms::a &&
|
2006-05-05 06:52:21 +00:00
|
|
|
testContent->IsNodeOfType(nsINode::eHTML)) {
|
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
|
|
|
*aIsSelectionWithFocus = PR_TRUE;
|
2002-09-27 22:31:05 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-01-18 04:09:33 +00:00
|
|
|
// Xlink must be type="simple"
|
|
|
|
*aIsSelectionWithFocus =
|
2006-12-26 17:47:52 +00:00
|
|
|
testContent->HasAttr(kNameSpaceID_XLink, nsGkAtoms::href) &&
|
|
|
|
testContent->AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::simple, eCaseMatters);
|
2002-09-27 22:31:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*aIsSelectionWithFocus) {
|
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
|
|
|
FocusElementButNotDocument(testContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
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
|
|
|
// Get the parent
|
2003-07-28 21:17:26 +00:00
|
|
|
testContent = testContent->GetParent();
|
2001-02-15 05:07:46 +00:00
|
|
|
|
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
|
|
|
if (!testContent) {
|
|
|
|
// We run this loop again, checking the ancestor chain of the selection's end point
|
|
|
|
testContent = nextTestContent;
|
|
|
|
nextTestContent = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
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
|
|
|
// We couldn't find an anchor that was an ancestor of the selection start
|
|
|
|
// Method #2: look for anchor in selection's primary range (depth first search)
|
2004-07-23 07:27:57 +00:00
|
|
|
|
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
|
|
|
// Turn into nodes so that we can use GetNextSibling() and GetFirstChild()
|
|
|
|
nsCOMPtr<nsIDOMNode> selectionNode(do_QueryInterface(selectionContent));
|
|
|
|
nsCOMPtr<nsIDOMNode> endSelectionNode(do_QueryInterface(endSelectionContent));
|
|
|
|
nsCOMPtr<nsIDOMNode> testNode;
|
|
|
|
|
|
|
|
do {
|
|
|
|
testContent = do_QueryInterface(selectionNode);
|
|
|
|
|
|
|
|
// We're looking for any focusable item that could be part of the
|
|
|
|
// main document's selection.
|
|
|
|
// Right now we only look for elements with the <a> tag.
|
2004-07-23 07:27:57 +00:00
|
|
|
// Add better focusable test here later if necessary ...
|
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
|
|
|
if (testContent) {
|
2006-12-26 17:47:52 +00:00
|
|
|
if (testContent->Tag() == nsGkAtoms::a &&
|
2006-05-05 06:52:21 +00:00
|
|
|
testContent->IsNodeOfType(nsINode::eHTML)) {
|
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
|
|
|
*aIsSelectionWithFocus = PR_TRUE;
|
|
|
|
FocusElementButNotDocument(testContent);
|
|
|
|
return NS_OK;
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
selectionNode->GetFirstChild(getter_AddRefs(testNode));
|
|
|
|
if (testNode) {
|
|
|
|
selectionNode = testNode;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectionNode == endSelectionNode)
|
|
|
|
break;
|
|
|
|
selectionNode->GetNextSibling(getter_AddRefs(testNode));
|
|
|
|
if (testNode) {
|
|
|
|
selectionNode = testNode;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
selectionNode->GetParentNode(getter_AddRefs(testNode));
|
Bug 131089, bug 131238, and bug 131918. Fixes regressions caused from 'browse with caret' checkins in bug 66597. a) bug 131089 - crash in ResetBrowseWithCaret(), r=bryner, sr=alecf, a=scc. b) bug 131238 - assertions caused by SetCaretContentVisible, r=bryner, sr=alecf, a=scc. c) bug 131918 - infinite loop in MoveFocusToCaret(), r=jgaunt, sr=alecf, a=asa
2002-03-20 06:42:26 +00:00
|
|
|
if (!testNode || testNode == endSelectionNode) {
|
|
|
|
selectionNode = nsnull;
|
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
|
|
|
break;
|
Bug 131089, bug 131238, and bug 131918. Fixes regressions caused from 'browse with caret' checkins in bug 66597. a) bug 131089 - crash in ResetBrowseWithCaret(), r=bryner, sr=alecf, a=scc. b) bug 131238 - assertions caused by SetCaretContentVisible, r=bryner, sr=alecf, a=scc. c) bug 131918 - infinite loop in MoveFocusToCaret(), r=jgaunt, sr=alecf, a=asa
2002-03-20 06:42:26 +00:00
|
|
|
}
|
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
|
|
|
testNode->GetNextSibling(getter_AddRefs(selectionNode));
|
|
|
|
if (selectionNode)
|
|
|
|
break;
|
|
|
|
selectionNode = testNode;
|
|
|
|
} while (PR_TRUE);
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
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
|
|
|
while (selectionNode && selectionNode != endSelectionNode);
|
|
|
|
|
2002-06-25 22:57:48 +00:00
|
|
|
if (aCanFocusDoc)
|
|
|
|
FocusElementButNotDocument(nsnull);
|
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
|
|
|
|
|
|
|
return NS_OK; // no errors, but caret not inside focusable element other than doc itself
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::MoveCaretToFocus()
|
2001-02-15 05:07:46 +00:00
|
|
|
{
|
|
|
|
// If in HTML content and the pref accessibility.browsewithcaret is TRUE,
|
|
|
|
// then always move the caret to beginning of a new focus
|
|
|
|
|
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
|
|
|
PRInt32 itemType = nsIDocShellTreeItem::typeChrome;
|
|
|
|
|
|
|
|
if (mPresContext) {
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer = mPresContext->GetContainer();
|
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
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(pcContainer));
|
2004-07-23 07:27:57 +00:00
|
|
|
if (treeItem)
|
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
|
|
|
treeItem->GetItemType(&itemType);
|
2003-05-11 21:14:07 +00:00
|
|
|
nsCOMPtr<nsIEditorDocShell> editorDocShell(do_QueryInterface(treeItem));
|
|
|
|
if (editorDocShell) {
|
|
|
|
PRBool isEditable;
|
|
|
|
editorDocShell->GetEditable(&isEditable);
|
|
|
|
if (isEditable) {
|
|
|
|
return NS_OK; // Move focus to caret only if browsing, not editing
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (itemType != nsIDocShellTreeItem::typeChrome) {
|
|
|
|
nsCOMPtr<nsIContent> selectionContent, endSelectionContent;
|
|
|
|
nsIFrame *selectionFrame;
|
|
|
|
PRUint32 selectionOffset;
|
2002-05-20 22:47:02 +00:00
|
|
|
GetDocSelectionLocation(getter_AddRefs(selectionContent),
|
|
|
|
getter_AddRefs(endSelectionContent),
|
|
|
|
&selectionFrame, &selectionOffset);
|
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
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *shell = mPresContext->GetPresShell();
|
2001-02-15 05:07:46 +00:00
|
|
|
if (shell) {
|
|
|
|
// rangeDoc is a document interface we can create a range with
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
nsCOMPtr<nsIDOMDocumentRange> rangeDoc(do_QueryInterface(mDocument));
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2004-08-29 03:08:44 +00:00
|
|
|
if (rangeDoc) {
|
2006-04-26 01:57:22 +00:00
|
|
|
nsISelection* domSelection = shell->FrameSelection()->
|
|
|
|
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
2001-02-15 05:07:46 +00:00
|
|
|
if (domSelection) {
|
2004-08-29 03:08:44 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> currentFocusNode(do_QueryInterface(mCurrentFocus));
|
2001-02-15 05:07:46 +00:00
|
|
|
// First clear the selection
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
domSelection->RemoveAllRanges();
|
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
|
|
|
if (currentFocusNode) {
|
2003-07-24 08:53:48 +00:00
|
|
|
nsCOMPtr<nsIDOMRange> newRange;
|
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
|
|
|
nsresult rv = rangeDoc->CreateRange(getter_AddRefs(newRange));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-03-08 01:09:26 +00:00
|
|
|
// Set the range to the start of the currently focused node
|
|
|
|
// Make sure it's collapsed
|
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
|
|
|
newRange->SelectNodeContents(currentFocusNode);
|
2003-03-08 01:09:26 +00:00
|
|
|
nsCOMPtr<nsIDOMNode> firstChild;
|
|
|
|
currentFocusNode->GetFirstChild(getter_AddRefs(firstChild));
|
2005-09-22 22:07:31 +00:00
|
|
|
if (!firstChild ||
|
2006-05-05 06:52:21 +00:00
|
|
|
mCurrentFocus->IsNodeOfType(nsINode::eHTML_FORM_CONTROL)) {
|
2003-03-08 01:09:26 +00:00
|
|
|
// If current focus node is a leaf, set range to before the
|
|
|
|
// node by using the parent as a container.
|
|
|
|
// This prevents it from appearing as selected.
|
|
|
|
newRange->SetStartBefore(currentFocusNode);
|
|
|
|
newRange->SetEndBefore(currentFocusNode);
|
|
|
|
}
|
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
|
|
|
domSelection->AddRange(newRange);
|
|
|
|
domSelection->CollapseToStart();
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::SetCaretEnabled(nsIPresShell *aPresShell, PRBool aEnabled)
|
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
|
|
|
{
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
|
|
|
aPresShell->GetCaret(getter_AddRefs(caret));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionController> selCon(do_QueryInterface(aPresShell));
|
|
|
|
if (!selCon || !caret)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
selCon->SetCaretEnabled(aEnabled);
|
|
|
|
caret->SetCaretVisible(aEnabled);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2003-11-19 01:20:56 +00:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::SetContentCaretVisible(nsIPresShell* aPresShell,
|
|
|
|
nsIContent *aFocusedContent,
|
|
|
|
PRBool aVisible)
|
|
|
|
{
|
2001-02-15 05:07:46 +00:00
|
|
|
// When browsing with caret, make sure caret is visible after new focus
|
|
|
|
nsCOMPtr<nsICaret> caret;
|
|
|
|
aPresShell->GetCaret(getter_AddRefs(caret));
|
|
|
|
|
2006-04-26 01:57:22 +00:00
|
|
|
nsFrameSelection* frameSelection = nsnull;
|
Bug 131089, bug 131238, and bug 131918. Fixes regressions caused from 'browse with caret' checkins in bug 66597. a) bug 131089 - crash in ResetBrowseWithCaret(), r=bryner, sr=alecf, a=scc. b) bug 131238 - assertions caused by SetCaretContentVisible, r=bryner, sr=alecf, a=scc. c) bug 131918 - infinite loop in MoveFocusToCaret(), r=jgaunt, sr=alecf, a=asa
2002-03-20 06:42:26 +00:00
|
|
|
if (aFocusedContent) {
|
2005-08-22 22:24:29 +00:00
|
|
|
nsIFrame *focusFrame = aPresShell->GetPrimaryFrameFor(aFocusedContent);
|
2006-04-26 01:57:22 +00:00
|
|
|
|
|
|
|
if (focusFrame)
|
|
|
|
frameSelection = focusFrame->GetFrameSelection();
|
Bug 131089, bug 131238, and bug 131918. Fixes regressions caused from 'browse with caret' checkins in bug 66597. a) bug 131089 - crash in ResetBrowseWithCaret(), r=bryner, sr=alecf, a=scc. b) bug 131238 - assertions caused by SetCaretContentVisible, r=bryner, sr=alecf, a=scc. c) bug 131918 - infinite loop in MoveFocusToCaret(), r=jgaunt, sr=alecf, a=asa
2002-03-20 06:42:26 +00:00
|
|
|
}
|
2004-08-29 03:08:44 +00:00
|
|
|
|
2006-04-26 01:57:22 +00:00
|
|
|
nsFrameSelection *docFrameSelection = aPresShell->FrameSelection();
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
if (docFrameSelection && caret &&
|
|
|
|
(frameSelection == docFrameSelection || !aFocusedContent)) {
|
2006-04-26 01:57:22 +00:00
|
|
|
nsISelection* domSelection = docFrameSelection->
|
|
|
|
GetSelection(nsISelectionController::SELECTION_NORMAL);
|
2001-02-15 05:07:46 +00:00
|
|
|
if (domSelection) {
|
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
|
|
|
// First, tell the caret which selection to use
|
|
|
|
caret->SetCaretDOMSelection(domSelection);
|
|
|
|
|
|
|
|
// In content, we need to set the caret
|
|
|
|
// the only other case is edit fields, where they have a different frame selection from the doc's
|
|
|
|
// in that case they'll take care of making the caret visible themselves
|
|
|
|
|
|
|
|
// Then make sure it's visible
|
|
|
|
return SetCaretEnabled(aPresShell, aVisible);
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-02-15 05:07:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2003-04-12 03:03:27 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::GetBrowseWithCaret()
|
2003-04-12 03:03:27 +00:00
|
|
|
{
|
2004-04-29 23:34:19 +00:00
|
|
|
return mBrowseWithCaret;
|
2003-04-12 03:03:27 +00:00
|
|
|
}
|
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::ResetBrowseWithCaret()
|
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
|
|
|
{
|
|
|
|
// This is called when browse with caret changes on the fly
|
2004-07-23 07:27:57 +00:00
|
|
|
// or when a document gets focused
|
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
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
if (!mPresContext)
|
|
|
|
return;
|
|
|
|
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer = mPresContext->GetContainer();
|
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
|
|
|
PRInt32 itemType;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> shellItem(do_QueryInterface(pcContainer));
|
Bug 131089, bug 131238, and bug 131918. Fixes regressions caused from 'browse with caret' checkins in bug 66597. a) bug 131089 - crash in ResetBrowseWithCaret(), r=bryner, sr=alecf, a=scc. b) bug 131238 - assertions caused by SetCaretContentVisible, r=bryner, sr=alecf, a=scc. c) bug 131918 - infinite loop in MoveFocusToCaret(), r=jgaunt, sr=alecf, a=asa
2002-03-20 06:42:26 +00:00
|
|
|
if (!shellItem)
|
2004-04-29 23:34:19 +00:00
|
|
|
return;
|
Bug 131089, bug 131238, and bug 131918. Fixes regressions caused from 'browse with caret' checkins in bug 66597. a) bug 131089 - crash in ResetBrowseWithCaret(), r=bryner, sr=alecf, a=scc. b) bug 131238 - assertions caused by SetCaretContentVisible, r=bryner, sr=alecf, a=scc. c) bug 131918 - infinite loop in MoveFocusToCaret(), r=jgaunt, sr=alecf, a=asa
2002-03-20 06:42:26 +00:00
|
|
|
|
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
|
|
|
shellItem->GetItemType(&itemType);
|
|
|
|
|
2004-07-23 07:27:57 +00:00
|
|
|
if (itemType == nsIDocShellTreeItem::typeChrome)
|
2004-04-29 23:34:19 +00:00
|
|
|
return; // Never browse with caret in chrome
|
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
|
|
|
|
2004-09-23 04:04:50 +00:00
|
|
|
nsCOMPtr<nsIEditorDocShell> editorDocShell(do_QueryInterface(shellItem));
|
|
|
|
if (editorDocShell) {
|
|
|
|
PRBool isEditable;
|
|
|
|
editorDocShell->GetEditable(&isEditable);
|
|
|
|
if (isEditable) {
|
|
|
|
return; // Reset caret visibility only if browsing, not editing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
PRPackedBool browseWithCaret =
|
|
|
|
nsContentUtils::GetBoolPref("accessibility.browsewithcaret");
|
2002-04-02 01:56:22 +00:00
|
|
|
|
2004-04-29 23:34:19 +00:00
|
|
|
mBrowseWithCaret = browseWithCaret;
|
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
|
|
|
|
2003-12-21 05:36:36 +00:00
|
|
|
nsIPresShell *presShell = mPresContext->GetPresShell();
|
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
|
|
|
|
|
|
|
// Make caret visible or not, depending on what's appropriate
|
2005-11-18 03:44:50 +00:00
|
|
|
// Set caret visibility for focused document only
|
|
|
|
// Others will be set when they get focused again
|
|
|
|
if (presShell && gLastFocusedDocument && gLastFocusedDocument == mDocument) {
|
|
|
|
SetContentCaretVisible(presShell, mCurrentFocus, browseWithCaret);
|
2002-08-19 02:58:15 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2001-05-22 23:52:17 +00:00
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
//-- DocShell Focus Traversal Methods
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// Returns PR_TRUE if this doc contains a frameset
|
2001-10-22 22:43:52 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::IsFrameSetDoc(nsIDocShell* aDocShell)
|
2001-05-22 23:52:17 +00:00
|
|
|
{
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(aDocShell, "docshell is null");
|
|
|
|
PRBool isFrameSet = PR_FALSE;
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
// a frameset element will always be the immediate child
|
|
|
|
// of the root content (the HTML tag)
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aDocShell->GetPresShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *doc = presShell->GetDocument();
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
|
|
|
|
if (htmlDoc) {
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIContent *rootContent = doc->GetRootContent();
|
2001-10-22 22:43:52 +00:00
|
|
|
if (rootContent) {
|
2003-09-27 04:18:26 +00:00
|
|
|
PRUint32 childCount = rootContent->GetChildCount();
|
|
|
|
for (PRUint32 i = 0; i < childCount; ++i) {
|
|
|
|
nsIContent *childContent = rootContent->GetChildAt(i);
|
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
nsINodeInfo *ni = childContent->NodeInfo();
|
2003-09-27 04:18:26 +00:00
|
|
|
|
2006-05-05 06:52:21 +00:00
|
|
|
if (childContent->IsNodeOfType(nsINode::eHTML) &&
|
2006-12-26 17:47:52 +00:00
|
|
|
ni->Equals(nsGkAtoms::frameset)) {
|
2001-10-22 22:43:52 +00:00
|
|
|
isFrameSet = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
return isFrameSet;
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
2001-10-22 22:43:52 +00:00
|
|
|
// Returns PR_TRUE if this doc is an IFRAME
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::IsIFrameDoc(nsIDocShell* aDocShell)
|
2001-05-22 23:52:17 +00:00
|
|
|
{
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(aDocShell, "docshell is null");
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2005-11-28 23:56:44 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> domWindow(do_GetInterface(aDocShell));
|
2004-07-15 06:05:27 +00:00
|
|
|
if (!domWindow) {
|
|
|
|
NS_ERROR("We're a child of a docshell without a window?");
|
2002-09-09 19:32:04 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2004-07-15 06:05:27 +00:00
|
|
|
nsCOMPtr<nsIContent> docContent =
|
|
|
|
do_QueryInterface(domWindow->GetFrameElementInternal());
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2004-07-15 06:05:27 +00:00
|
|
|
if (!docContent) {
|
2001-10-22 22:43:52 +00:00
|
|
|
return PR_FALSE;
|
2004-07-15 06:05:27 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2006-12-26 17:47:52 +00:00
|
|
|
return docContent->Tag() == nsGkAtoms::iframe;
|
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
|
|
|
}
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
//------------------------------------------------
|
|
|
|
// This method should be called when tab or F6/ctrl-tab
|
|
|
|
// traversal wants to focus a new document. It will focus
|
2004-07-23 07:27:57 +00:00
|
|
|
// the docshell, traverse into the document if this type
|
|
|
|
// of document does not get document focus (i.e. framsets
|
2001-10-22 22:43:52 +00:00
|
|
|
// and chrome), and update the canvas focus state on the docshell.
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::TabIntoDocument(nsIDocShell* aDocShell,
|
|
|
|
PRBool aForward)
|
2001-05-22 23:52:17 +00:00
|
|
|
{
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(aDocShell, "null docshell");
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domwin = do_GetInterface(aDocShell);
|
|
|
|
if (domwin)
|
|
|
|
domwin->Focus();
|
|
|
|
|
|
|
|
PRInt32 itemType;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(aDocShell);
|
|
|
|
treeItem->GetItemType(&itemType);
|
|
|
|
|
2005-07-21 00:15:27 +00:00
|
|
|
nsCOMPtr<nsPresContext> presContext;
|
|
|
|
aDocShell->GetPresContext(getter_AddRefs(presContext));
|
2001-10-22 22:43:52 +00:00
|
|
|
PRBool focusDocument;
|
2005-07-21 00:15:27 +00:00
|
|
|
if (presContext &&
|
|
|
|
presContext->Type() == nsPresContext::eContext_PrintPreview) {
|
|
|
|
// Don't focus any content in print preview mode, bug 244128.
|
|
|
|
focusDocument = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
if (!aForward || (itemType == nsIDocShellTreeItem::typeChrome))
|
|
|
|
focusDocument = PR_FALSE;
|
|
|
|
else {
|
|
|
|
// Check for a frameset document
|
|
|
|
focusDocument = !(IsFrameSetDoc(aDocShell));
|
|
|
|
}
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
if (focusDocument) {
|
|
|
|
// make sure we're in view
|
|
|
|
aDocShell->SetCanvasHasFocus(PR_TRUE);
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
2001-10-22 22:43:52 +00:00
|
|
|
else {
|
|
|
|
aDocShell->SetHasFocus(PR_FALSE);
|
|
|
|
|
2005-07-21 00:15:27 +00:00
|
|
|
if (presContext) {
|
|
|
|
nsIEventStateManager *docESM = presContext->EventStateManager();
|
2004-02-27 17:17:37 +00:00
|
|
|
|
|
|
|
// we are about to shift focus to aDocShell
|
|
|
|
// keep track of the document, so we don't try to go back into it.
|
|
|
|
mTabbingFromDocShells.AppendObject(aDocShell);
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
// clear out any existing focus state
|
|
|
|
docESM->SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
|
|
|
// now focus the first (or last) focusable content
|
|
|
|
docESM->ShiftFocus(aForward, nsnull);
|
2003-03-17 23:08:36 +00:00
|
|
|
|
2004-02-27 17:17:37 +00:00
|
|
|
// remove the document from the list
|
2004-07-23 07:27:57 +00:00
|
|
|
mTabbingFromDocShells.RemoveObject(aDocShell);
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::GetLastChildDocShell(nsIDocShellTreeItem* aItem,
|
|
|
|
nsIDocShellTreeItem** aResult)
|
2001-05-22 23:52:17 +00:00
|
|
|
{
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(aItem, "null docshell");
|
|
|
|
NS_ASSERTION(aResult, "null out pointer");
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> curItem = do_QueryInterface(aItem);
|
|
|
|
while (1) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> curNode = do_QueryInterface(curItem);
|
|
|
|
PRInt32 childCount = 0;
|
|
|
|
curNode->GetChildCount(&childCount);
|
|
|
|
if (!childCount) {
|
|
|
|
*aResult = curItem;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return;
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
curNode->GetChildAt(childCount - 1, getter_AddRefs(curItem));
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::GetNextDocShell(nsIDocShellTreeNode* aNode,
|
|
|
|
nsIDocShellTreeItem** aResult)
|
2001-05-22 23:52:17 +00:00
|
|
|
{
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(aNode, "null docshell");
|
|
|
|
NS_ASSERTION(aResult, "null out pointer");
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2002-03-27 04:43:52 +00:00
|
|
|
*aResult = nsnull;
|
|
|
|
|
2007-04-04 22:21:33 +00:00
|
|
|
PRInt32 childCount = 0;
|
|
|
|
aNode->GetChildCount(&childCount);
|
|
|
|
if (childCount) {
|
2002-03-27 04:43:52 +00:00
|
|
|
aNode->GetChildAt(0, aResult);
|
|
|
|
if (*aResult)
|
|
|
|
return;
|
2002-02-01 23:56:48 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> curNode = aNode;
|
|
|
|
while (curNode) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> curItem = do_QueryInterface(curNode);
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
curItem->GetParent(getter_AddRefs(parentItem));
|
|
|
|
if (!parentItem) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
return;
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2007-04-04 22:21:33 +00:00
|
|
|
// Note that we avoid using GetChildOffset() here because docshell
|
|
|
|
// child offsets can't be trusted to be correct. bug 162283.
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> parentNode = do_QueryInterface(parentItem);
|
2007-04-04 22:21:33 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> iterItem;
|
|
|
|
childCount = 0;
|
|
|
|
parentNode->GetChildCount(&childCount);
|
|
|
|
for (PRInt32 index = 0; index < childCount; ++index) {
|
|
|
|
parentNode->GetChildAt(index, getter_AddRefs(iterItem));
|
|
|
|
if (iterItem == curItem) {
|
|
|
|
++index;
|
|
|
|
if (index < childCount) {
|
|
|
|
parentNode->GetChildAt(index, aResult);
|
|
|
|
if (*aResult)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-02-01 23:56:48 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
curNode = do_QueryInterface(parentItem);
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::GetPrevDocShell(nsIDocShellTreeNode* aNode,
|
|
|
|
nsIDocShellTreeItem** aResult)
|
2001-05-22 23:52:17 +00:00
|
|
|
{
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(aNode, "null docshell");
|
|
|
|
NS_ASSERTION(aResult, "null out pointer");
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2007-04-04 22:21:33 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> curItem = do_QueryInterface(aNode);
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
curItem->GetParent(getter_AddRefs(parentItem));
|
|
|
|
if (!parentItem) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2007-04-04 22:21:33 +00:00
|
|
|
// Note that we avoid using GetChildOffset() here because docshell
|
|
|
|
// child offsets can't be trusted to be correct. bug 162283.
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> parentNode = do_QueryInterface(parentItem);
|
|
|
|
PRInt32 childCount = 0;
|
|
|
|
parentNode->GetChildCount(&childCount);
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> prevItem, iterItem;
|
|
|
|
for (PRInt32 index = 0; index < childCount; ++index) {
|
|
|
|
parentNode->GetChildAt(index, getter_AddRefs(iterItem));
|
|
|
|
if (iterItem == curItem)
|
|
|
|
break;
|
|
|
|
prevItem = iterItem;
|
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2007-04-04 22:21:33 +00:00
|
|
|
if (prevItem) {
|
|
|
|
curItem = prevItem;
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> curNode;
|
|
|
|
// Get the last child recursively of this node.
|
2001-10-22 22:43:52 +00:00
|
|
|
while (1) {
|
|
|
|
curNode = do_QueryInterface(curItem);
|
2007-04-04 22:21:33 +00:00
|
|
|
childCount = 0;
|
2001-10-22 22:43:52 +00:00
|
|
|
curNode->GetChildCount(&childCount);
|
|
|
|
if (!childCount)
|
|
|
|
break;
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
curNode->GetChildAt(childCount - 1, getter_AddRefs(curItem));
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
*aResult = curItem;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return;
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
*aResult = parentItem;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return;
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------
|
|
|
|
// Traversal by document/DocShell only
|
2001-10-22 22:43:52 +00:00
|
|
|
// this does not include any content inside the doc
|
2001-05-22 23:52:17 +00:00
|
|
|
// or IFrames
|
|
|
|
void
|
2001-10-22 22:43:52 +00:00
|
|
|
nsEventStateManager::ShiftFocusByDoc(PRBool aForward)
|
2001-05-22 23:52:17 +00:00
|
|
|
{
|
2001-10-22 22:43:52 +00:00
|
|
|
// Note that we use the docshell tree here instead of iteratively calling
|
|
|
|
// ShiftFocus. The docshell tree should be kept in depth-first frame tree
|
|
|
|
// order, the same as we use for tabbing, so the effect should be the same,
|
|
|
|
// but this is much faster.
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
NS_ASSERTION(mPresContext, "no prescontext");
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2004-02-01 10:09:07 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer = mPresContext->GetContainer();
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeNode> curNode = do_QueryInterface(pcContainer);
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
// perform a depth first search (preorder) of the docshell tree
|
|
|
|
// looking for an HTML Frame or a chrome document
|
2004-07-23 07:27:57 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> nextItem;
|
|
|
|
nsCOMPtr<nsIDocShell> nextShell;
|
|
|
|
do {
|
|
|
|
if (aForward) {
|
|
|
|
GetNextDocShell(curNode, getter_AddRefs(nextItem));
|
|
|
|
if (!nextItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> curItem = do_QueryInterface(pcContainer);
|
|
|
|
// wrap around to the beginning, which is the top of the tree
|
|
|
|
curItem->GetRootTreeItem(getter_AddRefs(nextItem));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GetPrevDocShell(curNode, getter_AddRefs(nextItem));
|
|
|
|
if (!nextItem) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> curItem = do_QueryInterface(pcContainer);
|
|
|
|
// wrap around to the end, which is the last node in the tree
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
|
|
|
curItem->GetRootTreeItem(getter_AddRefs(rootItem));
|
|
|
|
GetLastChildDocShell(rootItem, getter_AddRefs(nextItem));
|
|
|
|
}
|
|
|
|
}
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
curNode = do_QueryInterface(nextItem);
|
|
|
|
nextShell = do_QueryInterface(nextItem);
|
|
|
|
} while (IsFrameSetDoc(nextShell) || IsIFrameDoc(nextShell) || !IsShellVisible(nextShell));
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
if (nextShell) {
|
|
|
|
// NOTE: always tab forward into the document, this ensures that we
|
|
|
|
// focus the document itself, not its last focusable content.
|
|
|
|
// chrome documents will get their first focusable content focused.
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
|
|
|
TabIntoDocument(nextShell, PR_TRUE);
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
// Get the FocusController given an nsIDocument
|
2004-05-03 21:48:36 +00:00
|
|
|
nsIFocusController*
|
2002-09-06 00:19:58 +00:00
|
|
|
nsEventStateManager::GetFocusControllerForDocument(nsIDocument* aDocument)
|
|
|
|
{
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsISupports> container = aDocument->GetContainer();
|
2002-09-06 00:19:58 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> windowPrivate = do_GetInterface(container);
|
|
|
|
|
2004-05-03 21:48:36 +00:00
|
|
|
return windowPrivate ? windowPrivate->GetRootFocusController() : nsnull;
|
2002-09-06 00:19:58 +00:00
|
|
|
}
|
2005-11-14 23:55:24 +00:00
|
|
|
|