2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-23 21:53:02 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
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.
|
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* 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>
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** 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"
|
1998-08-07 04:45:03 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsHTMLAtoms.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"
|
1998-11-18 05:25:26 +00:00
|
|
|
#include "nsIDOMHTMLAnchorElement.h"
|
|
|
|
#include "nsIDOMHTMLInputElement.h"
|
|
|
|
#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"
|
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"
|
1999-03-02 19:19:24 +00:00
|
|
|
#include "nsIWebShell.h"
|
2000-02-11 01:56:01 +00:00
|
|
|
#include "nsIBaseWindow.h"
|
1999-04-30 19:38:39 +00:00
|
|
|
#include "nsIScrollableView.h"
|
2000-09-14 11:45:01 +00:00
|
|
|
#include "nsISelection.h"
|
1999-05-07 21:12:59 +00:00
|
|
|
#include "nsIFrameSelection.h"
|
1999-08-19 19:48:45 +00:00
|
|
|
#include "nsIDeviceContext.h"
|
1999-11-13 05:16:33 +00:00
|
|
|
#include "nsIScriptGlobalObject.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"
|
|
|
|
#include "nsFrameTraversal.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"
|
1999-08-19 19:48:45 +00:00
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2002-11-25 23:26:06 +00:00
|
|
|
#include "nsIPrefService.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 "nsIChromeEventHandler.h"
|
|
|
|
#include "nsIFocusController.h"
|
|
|
|
|
2000-01-13 11:43:54 +00:00
|
|
|
#include "nsXULAtoms.h"
|
2002-02-21 13:39:39 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
2000-02-11 23:41:13 +00:00
|
|
|
#include "nsIDOMXULDocument.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
|
|
|
|
2001-02-19 12:55:42 +00:00
|
|
|
#include "nsIFrameTraversal.h"
|
|
|
|
#include "nsLayoutCID.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
|
|
|
|
2002-03-26 00:59:03 +00:00
|
|
|
#if defined (XP_MAC) || defined(XP_MACOSX)
|
|
|
|
#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-05-22 23:52:17 +00:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
static char* gDocTypeNames[] = {"eChrome", "eGenericContent", "eFrameSet", "eFrame", "eIFrame"};
|
|
|
|
#endif
|
2001-04-12 23:39:19 +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
|
1999-12-08 20:18:16 +00:00
|
|
|
nsIPresContext* gLastFocusedPresContext = 0; // Weak reference
|
1999-12-01 09:09:46 +00:00
|
|
|
|
2002-10-05 15:39:33 +00:00
|
|
|
PRInt8 nsEventStateManager::sTextfieldSelectModel = eTextfieldSelect_unset;
|
2002-09-18 21:24:57 +00:00
|
|
|
|
1999-12-01 09:09:46 +00:00
|
|
|
PRUint32 nsEventStateManager::mInstanceCount = 0;
|
2002-05-08 20:43:49 +00:00
|
|
|
PRInt32 nsEventStateManager::gGeneralAccesskeyModifier = -1; // magic value of -1 means uninitialized
|
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,
|
|
|
|
MOUSE_SCROLL_TEXTSIZE
|
2000-01-06 06:22:00 +00:00
|
|
|
};
|
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
nsEventStateManager::nsEventStateManager()
|
2000-03-15 04:03:44 +00:00
|
|
|
: mGestureDownPoint(0,0),
|
2002-12-24 20:21:40 +00:00
|
|
|
m_haveShutdown(PR_FALSE),
|
|
|
|
mDOMEventLevel(0),
|
|
|
|
mClearedFrameRefsDuringEvent(PR_FALSE)
|
1999-08-19 19:48:45 +00:00
|
|
|
{
|
1998-11-18 05:25:26 +00:00
|
|
|
mLastMouseOverFrame = nsnull;
|
1999-05-04 14:44:51 +00:00
|
|
|
mLastDragOverFrame = nsnull;
|
1998-11-18 05:25:26 +00:00
|
|
|
mCurrentTarget = nsnull;
|
1998-11-24 07:46:58 +00:00
|
|
|
|
1999-12-18 04:02:28 +00:00
|
|
|
mConsumeFocusEvents = PR_FALSE;
|
2000-04-24 04:41:27 +00:00
|
|
|
mLockCursor = 0;
|
1999-12-18 04:02:28 +00:00
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
// init d&d gesture state machine variables
|
|
|
|
mIsTrackingDragGesture = PR_FALSE;
|
|
|
|
mGestureDownFrame = nsnull;
|
|
|
|
|
1999-09-22 02:29:33 +00:00
|
|
|
mLClickCount = 0;
|
|
|
|
mMClickCount = 0;
|
|
|
|
mRClickCount = 0;
|
2002-03-31 04:53:53 +00:00
|
|
|
mLastFocusedWith = eEventFocusedByUnknown;
|
1998-11-18 05:25:26 +00:00
|
|
|
mPresContext = nsnull;
|
1999-03-02 19:19:24 +00:00
|
|
|
mCurrentTabIndex = 0;
|
2000-05-16 10:22:20 +00:00
|
|
|
mAccessKeys = nsnull;
|
2001-02-15 05:07:46 +00:00
|
|
|
mBrowseWithCaret = PR_FALSE;
|
2001-11-07 06:29:29 +00:00
|
|
|
mLeftClickOnly = PR_TRUE;
|
2002-02-20 07:22:55 +00:00
|
|
|
mNormalLMouseEventInProcess = PR_FALSE;
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
|
|
|
|
#ifdef CLICK_HOLD_CONTEXT_MENUS
|
|
|
|
mEventDownWidget = nsnull;
|
|
|
|
#endif
|
1999-12-01 09:09:46 +00:00
|
|
|
|
|
|
|
++mInstanceCount;
|
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;
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
2001-10-22 22:01:27 +00:00
|
|
|
do_GetService("@mozilla.org/observer-service;1", &rv);
|
2000-03-15 04:03:44 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2001-10-19 20:52:59 +00:00
|
|
|
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
|
2000-03-15 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
2002-11-25 23:26:06 +00:00
|
|
|
rv = getPrefBranch();
|
2000-09-15 06:17:54 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetBoolPref("nglayout.events.dispatchLeftClickOnly",
|
|
|
|
&mLeftClickOnly);
|
|
|
|
|
|
|
|
// magic value of -1 means uninitialized
|
|
|
|
if (nsEventStateManager::gGeneralAccesskeyModifier == -1) {
|
|
|
|
mPrefBranch->GetIntPref("ui.key.generalAccessKey",
|
|
|
|
&nsEventStateManager::gGeneralAccesskeyModifier);
|
|
|
|
}
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
|
|
|
|
2002-10-05 15:39:33 +00:00
|
|
|
if (nsEventStateManager::sTextfieldSelectModel == eTextfieldSelect_unset) {
|
|
|
|
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
|
|
|
|
if ( mClickHoldTimer ) {
|
|
|
|
mClickHoldTimer->Cancel();
|
|
|
|
mClickHoldTimer = nsnull;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-12-01 09:09:46 +00:00
|
|
|
--mInstanceCount;
|
|
|
|
if(mInstanceCount == 0) {
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
|
|
|
}
|
2000-03-15 04:03:44 +00:00
|
|
|
|
2000-05-16 10:22:20 +00:00
|
|
|
if (mAccessKeys) {
|
|
|
|
delete mAccessKeys;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
2001-10-22 22:01:27 +00:00
|
|
|
do_GetService("@mozilla.org/observer-service;1", &rv);
|
2000-03-15 04:03:44 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2001-10-19 20:52:59 +00:00
|
|
|
observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
2000-03-15 04:03:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
2000-03-15 04:03:44 +00:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::Shutdown()
|
|
|
|
{
|
2002-11-25 23:27:29 +00:00
|
|
|
mPrefBranch = nsnull;
|
2000-03-15 04:03:44 +00:00
|
|
|
|
|
|
|
m_haveShutdown = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-11-25 23:26:06 +00:00
|
|
|
nsEventStateManager::getPrefBranch()
|
2000-03-15 04:03:44 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-11-25 23:26:06 +00:00
|
|
|
if (!mPrefBranch) {
|
|
|
|
mPrefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
2000-03-15 04:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-11-25 23:26:06 +00:00
|
|
|
if (!mPrefBranch) return NS_ERROR_FAILURE;
|
2000-03-15 04:03:44 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-10-19 20:52:59 +00:00
|
|
|
nsEventStateManager::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *someData)
|
|
|
|
{
|
|
|
|
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
|
2000-03-15 04:03:44 +00:00
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
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
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStateManager::PreHandleEvent(nsIPresContext* 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);
|
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
|
|
|
|
|
|
|
nsFrameState state;
|
1999-09-02 07:22:47 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(mCurrentTarget, "mCurrentTarget is null. this should not happen. see bug #13007");
|
|
|
|
if (!mCurrentTarget) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-02-10 04:17:06 +00:00
|
|
|
mCurrentTarget->GetFrameState(&state);
|
1998-11-19 00:43:36 +00:00
|
|
|
state |= NS_FRAME_EXTERNAL_REFERENCE;
|
|
|
|
mCurrentTarget->SetFrameState(state);
|
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
*aStatus = nsEventStatus_eIgnore;
|
2001-01-20 04:59:39 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
|
1999-09-02 07:22:47 +00:00
|
|
|
NS_ASSERTION(aEvent, "aEvent is null. this should never happen");
|
|
|
|
if (!aEvent) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
switch (aEvent->message) {
|
1999-08-19 19:48:45 +00:00
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifndef XP_OS2
|
2001-03-30 04:45:40 +00:00
|
|
|
BeginTrackingDragGesture ( aPresContext, (nsGUIEvent*)aEvent, aTargetFrame );
|
2002-05-10 03:07:06 +00:00
|
|
|
#endif
|
1999-09-22 02:29:33 +00:00
|
|
|
mLClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
2002-02-20 07:22:55 +00:00
|
|
|
mNormalLMouseEventInProcess = PR_TRUE;
|
1999-09-22 02:29:33 +00:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
|
|
|
mMClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_DOWN:
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifdef XP_OS2
|
|
|
|
BeginTrackingDragGesture ( aPresContext, (nsGUIEvent*)aEvent, aTargetFrame );
|
|
|
|
#endif
|
1999-09-22 02:29:33 +00:00
|
|
|
mRClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
1999-08-19 19:48:45 +00:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
2001-03-30 04:45:40 +00:00
|
|
|
#ifdef CLICK_HOLD_CONTEXT_MENUS
|
|
|
|
KillClickHoldTimer();
|
|
|
|
#endif
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifndef XP_OS2
|
1999-08-19 19:48:45 +00:00
|
|
|
StopTrackingDragGesture();
|
2002-05-10 03:07:06 +00:00
|
|
|
#endif
|
2002-02-20 07:22:55 +00:00
|
|
|
mNormalLMouseEventInProcess = PR_FALSE;
|
1999-09-22 02:29:33 +00:00
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
2002-05-10 03:07:06 +00:00
|
|
|
#ifdef XP_OS2
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
#endif
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
1999-09-22 02:29:33 +00:00
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
1999-08-19 19:48:45 +00:00
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_MOUSE_MOVE:
|
2000-02-24 03:41:14 +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|
|
|
|
|
// into UpdateCursor().
|
2000-04-24 04:41:27 +00:00
|
|
|
GenerateDragGesture(aPresContext, (nsGUIEvent*)aEvent);
|
2000-02-24 03:41:14 +00:00
|
|
|
UpdateCursor(aPresContext, aEvent, mCurrentTarget, aStatus);
|
2000-04-24 04:41:27 +00:00
|
|
|
GenerateMouseEnterExit(aPresContext, (nsGUIEvent*)aEvent);
|
2001-01-20 04:59:39 +00:00
|
|
|
// Flush reflows and invalidates to eliminate flicker when both a reflow
|
|
|
|
// and visual change occur in an event callback. See bug #36849
|
|
|
|
FlushPendingEvents(aPresContext);
|
1998-11-18 05:25:26 +00:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_EXIT:
|
2000-04-24 04:41:27 +00:00
|
|
|
GenerateMouseEnterExit(aPresContext, (nsGUIEvent*)aEvent);
|
2000-03-03 23:07:31 +00:00
|
|
|
//This is a window level mouseenter event and should stop here
|
|
|
|
aEvent->message = 0;
|
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
|
|
|
{
|
2000-10-28 22:17:53 +00:00
|
|
|
#ifdef DEBUG_hyatt
|
|
|
|
printf("Got focus.\n");
|
|
|
|
#endif
|
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
|
|
|
|
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
|
|
|
//fire focus
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent focusevent;
|
|
|
|
focusevent.eventStructType = NS_EVENT;
|
|
|
|
focusevent.message = NS_FOCUS_CONTENT;
|
1999-11-13 05:16:33 +00:00
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
if (mDocument) {
|
2000-04-14 21:49:34 +00:00
|
|
|
|
2000-06-14 02:59:54 +00:00
|
|
|
if(gLastFocusedDocument) {
|
2000-04-14 21:49:34 +00:00
|
|
|
// fire a blur, on the document only to keep ender happy
|
|
|
|
nsEventStatus blurstatus = nsEventStatus_eIgnore;
|
|
|
|
nsEvent blurevent;
|
|
|
|
blurevent.eventStructType = NS_EVENT;
|
|
|
|
blurevent.message = NS_BLUR_CONTENT;
|
|
|
|
|
|
|
|
if(gLastFocusedPresContext) {
|
2000-11-04 08:21:20 +00:00
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
2000-06-23 05:37:08 +00:00
|
|
|
|
2000-05-03 00:49:37 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
2000-09-01 01:54:35 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> rootWindow;
|
2000-05-03 00:49:37 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(ourGlobal);
|
2002-03-08 04:00:37 +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.
|
|
|
|
|
|
|
|
PRBool isAlreadySuppressed = PR_FALSE;
|
2000-05-03 00:49:37 +00:00
|
|
|
if(ourWindow) {
|
2000-11-04 08:21:20 +00:00
|
|
|
ourWindow->GetRootFocusController(getter_AddRefs(focusController));
|
2002-03-08 04:00:37 +00:00
|
|
|
if (focusController) {
|
|
|
|
focusController->GetSuppressFocus(&isAlreadySuppressed);
|
2001-04-18 01:41:20 +00:00
|
|
|
focusController->SetSuppressFocus(PR_TRUE, "NS_GOTFOCUS ESM Suppression");
|
2002-03-08 04:00:37 +00:00
|
|
|
}
|
2000-05-03 00:49:37 +00:00
|
|
|
}
|
|
|
|
|
2002-03-08 04:00:37 +00:00
|
|
|
if (!isAlreadySuppressed) {
|
|
|
|
gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &blurevent, nsnull, NS_EVENT_FLAG_INIT, &blurstatus);
|
|
|
|
if (!mCurrentFocus && gLastFocusedContent) {
|
|
|
|
// must send it to the element that is losing focus,
|
|
|
|
// since SendFocusBlur wont be called
|
|
|
|
gLastFocusedContent->HandleDOMEvent(gLastFocusedPresContext, &blurevent, nsnull, NS_EVENT_FLAG_INIT, &blurstatus);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2002-05-09 21:53:54 +00:00
|
|
|
if (gLastFocusedContent) // could have changed in HandleDOMEvent
|
|
|
|
gLastFocusedContent->GetDocument(*getter_AddRefs(doc));
|
2002-03-08 04:00:37 +00:00
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
doc->GetShellAt(0, getter_AddRefs(shell));
|
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIPresContext> oldPresContext;
|
|
|
|
shell->GetPresContext(getter_AddRefs(oldPresContext));
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
oldPresContext->GetEventStateManager(getter_AddRefs(esm));
|
|
|
|
esm->SetFocusedContent(gLastFocusedContent);
|
|
|
|
gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
esm->SetFocusedContent(nsnull);
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
}
|
2001-04-24 22:52:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-08 04:00:37 +00:00
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
if (focusController) {
|
2001-04-18 01:41:20 +00:00
|
|
|
focusController->SetSuppressFocus(PR_FALSE, "NS_GOTFOCUS ESM Suppression");
|
2000-05-03 00:49:37 +00:00
|
|
|
}
|
2000-04-14 21:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
// fire focus on window, not document
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
|
|
|
if (globalObject) {
|
2002-12-17 02:10:57 +00:00
|
|
|
nsCOMPtr<nsIContent> currentFocus = mCurrentFocus;
|
|
|
|
mCurrentFocus = nsnull;
|
2000-06-29 05:27:05 +00:00
|
|
|
if(gLastFocusedDocument != mDocument) {
|
2000-06-09 21:13:03 +00:00
|
|
|
mDocument->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
2000-06-29 05:27:05 +00:00
|
|
|
if (currentFocus && currentFocus != gLastFocusedContent)
|
|
|
|
currentFocus->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
2000-06-09 21:13:03 +00:00
|
|
|
|
2001-02-15 05:07:46 +00:00
|
|
|
globalObject->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
2000-11-08 03:00:02 +00:00
|
|
|
mCurrentFocus = 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
|
|
|
}
|
1999-12-18 04:02:28 +00:00
|
|
|
|
2002-06-12 05:00:35 +00:00
|
|
|
// Try to keep the focus controllers and the globals in synch
|
|
|
|
if(gLastFocusedDocument != mDocument && gLastFocusedDocument && mDocument) {
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> lastGlobal;
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(lastGlobal));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> lastWindow;
|
|
|
|
nsCOMPtr<nsIFocusController> lastController;
|
|
|
|
if(lastGlobal) {
|
|
|
|
lastWindow = do_QueryInterface(lastGlobal);
|
|
|
|
|
|
|
|
if(lastWindow)
|
|
|
|
lastWindow->GetRootFocusController(getter_AddRefs(lastController));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> nextGlobal;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(nextGlobal));
|
|
|
|
nsCOMPtr<nsIFocusController> nextController;
|
|
|
|
if(nextGlobal) {
|
|
|
|
nsCOMPtr<nsPIDOMWindow> nextWindow = do_QueryInterface(nextGlobal);
|
|
|
|
if(nextWindow) {
|
|
|
|
nextWindow->GetRootFocusController(getter_AddRefs(nextController));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lastController != nextController && lastController && nextController) {
|
|
|
|
lastController->SetActive(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
ResetBrowseWithCaret(&mBrowseWithCaret);
|
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:
|
|
|
|
{
|
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
|
|
|
// Hide the caret used in "browse with caret mode"
|
|
|
|
if (mBrowseWithCaret && mPresContext) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell)
|
|
|
|
SetContentCaretVisible(presShell, mCurrentFocus, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
1999-11-13 05:16:33 +00:00
|
|
|
// Hold the blur, wait for the focus so we can query the style of the focus
|
|
|
|
// target as to what to do with the event. If appropriate we fire the blur
|
|
|
|
// at that time.
|
2002-02-01 15:14:35 +00:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
2001-05-18 12:07:42 +00:00
|
|
|
if(! NS_STATIC_CAST(nsFocusEvent*, aEvent)->isMozWindowTakingFocus) {
|
|
|
|
EnsureDocument(aPresContext);
|
|
|
|
|
|
|
|
// We can get a deactivate on an Ender widget. In this
|
|
|
|
// case, we would like to obtain the DOM Window to start
|
|
|
|
// with by looking at gLastFocusedContent.
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
|
|
|
|
if (gLastFocusedContent) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
gLastFocusedContent->GetDocument(*getter_AddRefs(doc));
|
2002-02-21 13:39:39 +00:00
|
|
|
if(doc)
|
2001-05-18 12:07:42 +00:00
|
|
|
doc->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
|
|
|
else {
|
2002-02-21 13:39:39 +00:00
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
|
|
|
NS_RELEASE(gLastFocusedContent);
|
2001-05-18 12:07:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
|
|
|
|
|
|
|
// Now fire blurs. We have to fire a blur on the focused window
|
|
|
|
// and on the focused element if there is one.
|
|
|
|
if (gLastFocusedDocument && gLastFocusedPresContext) {
|
|
|
|
// Blur the element.
|
|
|
|
if (gLastFocusedContent) {
|
|
|
|
// Retrieve this content node's pres context. it can be out of sync in
|
|
|
|
// the Ender widget case.
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
gLastFocusedContent->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
doc->GetShellAt(0, getter_AddRefs(shell));
|
2001-05-18 12:07:42 +00:00
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIPresContext> oldPresContext;
|
|
|
|
shell->GetPresContext(getter_AddRefs(oldPresContext));
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
oldPresContext->GetEventStateManager(getter_AddRefs(esm));
|
|
|
|
esm->SetFocusedContent(gLastFocusedContent);
|
|
|
|
gLastFocusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
esm->SetFocusedContent(nsnull);
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
|
|
|
|
|
|
|
// fire blur on document and window
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
|
|
|
if(gLastFocusedDocument) {
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
|
|
|
gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
if(globalObject)
|
|
|
|
globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
|
|
|
// Now clear our our global variables
|
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
|
|
|
gLastFocusedPresContext = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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
|
|
|
{
|
2000-02-11 23:41:13 +00:00
|
|
|
// If we have a command dispatcher, and if it has a focused window and a
|
|
|
|
// focused element in its focus memory, then restore the focus to those
|
|
|
|
// objects.
|
2000-06-28 20:35:32 +00:00
|
|
|
EnsureDocument(aPresContext);
|
2001-04-20 00:16:39 +00:00
|
|
|
#ifdef DEBUG_hyatt
|
|
|
|
printf("ESM: GOT ACTIVATE.\n");
|
|
|
|
#endif
|
2000-11-04 08:21:20 +00:00
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
2000-02-11 23:41:13 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
2000-09-01 01:54:35 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> focusedWindow;
|
2000-02-11 23:41:13 +00:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(mDocument);
|
2000-02-26 01:02:31 +00:00
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(globalObj));
|
2001-05-11 06:22:11 +00:00
|
|
|
NS_ASSERTION(win, "win is null. this happens [often on xlib builds]. see bug #79213");
|
|
|
|
if (!win) return NS_ERROR_NULL_POINTER;
|
2000-11-04 08:21:20 +00:00
|
|
|
win->GetRootFocusController(getter_AddRefs(focusController));
|
|
|
|
|
|
|
|
if (focusController) {
|
|
|
|
// Obtain focus info from the command dispatcher.
|
|
|
|
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
|
|
|
|
2002-02-21 13:39:39 +00:00
|
|
|
if (!focusedWindow) {
|
2000-11-04 08:21:20 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
|
|
|
focusedWindow = do_QueryInterface(globalObject);
|
1999-06-15 03:14:28 +00:00
|
|
|
}
|
2000-02-11 23:41:13 +00:00
|
|
|
|
|
|
|
// Focus the DOM window.
|
2000-07-28 21:48:08 +00:00
|
|
|
NS_WARN_IF_FALSE(focusedWindow,"check why focusedWindow is null!!!");
|
|
|
|
if(focusedWindow) {
|
2000-06-23 22:18:54 +00:00
|
|
|
focusedWindow->Focus();
|
2000-02-11 23:41:13 +00:00
|
|
|
|
2002-02-20 07:22:55 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
focusedWindow->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
if (domDoc) {
|
|
|
|
document = do_QueryInterface(domDoc);
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
document->GetShellAt(0, getter_AddRefs(shell));
|
|
|
|
NS_ASSERTION(shell, "Focus events should not be getting thru when this is null!");
|
|
|
|
if (shell) {
|
|
|
|
if (focusedElement) {
|
|
|
|
nsCOMPtr<nsIContent> focusContent = do_QueryInterface(focusedElement);
|
|
|
|
nsCOMPtr<nsIPresContext> context;
|
2001-11-15 13:15:54 +00:00
|
|
|
shell->GetPresContext(getter_AddRefs(context));
|
|
|
|
focusContent->SetFocus(context);
|
|
|
|
}
|
2002-02-20 07:22:55 +00:00
|
|
|
|
|
|
|
//disable selection mousedown state on activation
|
|
|
|
nsCOMPtr<nsIFrameSelection> frameSel;
|
|
|
|
shell->GetFrameSelection(getter_AddRefs(frameSel));
|
|
|
|
if (frameSel) {
|
|
|
|
frameSel->SetMouseDownState(PR_FALSE);
|
|
|
|
}
|
2000-07-28 21:48:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-02-20 07:22:55 +00:00
|
|
|
|
2000-11-04 08:21:20 +00:00
|
|
|
if (focusController) {
|
2000-09-15 07:02:58 +00:00
|
|
|
PRBool isSuppressed;
|
2000-11-04 08:21:20 +00:00
|
|
|
focusController->GetSuppressFocus(&isSuppressed);
|
2000-09-15 07:02:58 +00:00
|
|
|
while(isSuppressed){
|
2001-04-18 01:41:20 +00:00
|
|
|
focusController->SetSuppressFocus(PR_FALSE, "Activation Suppression"); // Unsuppress and let the command dispatcher listen again.
|
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
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
break;
|
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
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
|
2001-06-18 07:34:41 +00:00
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
|
|
|
|
2000-02-11 23:41:13 +00:00
|
|
|
// Suppress the command dispatcher for the duration of the
|
|
|
|
// de-activation. This will cause it to remember the last
|
|
|
|
// focused sub-window and sub-element for this top-level
|
|
|
|
// window.
|
2002-09-06 00:19:58 +00:00
|
|
|
nsCOMPtr<nsIFocusController> focusController = getter_AddRefs(GetFocusControllerForDocument(mDocument));
|
2000-11-04 08:21:20 +00:00
|
|
|
if (focusController) {
|
|
|
|
// Suppress the command dispatcher.
|
2001-04-18 01:41:20 +00:00
|
|
|
focusController->SetSuppressFocus(PR_TRUE, "Deactivate Suppression");
|
2000-02-11 23:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now fire blurs. We have to fire a blur on the focused window
|
|
|
|
// and on the focused element if there is one.
|
2001-07-20 08:14:44 +00:00
|
|
|
if (gLastFocusedDocument && gLastFocusedDocument == mDocument) {
|
2000-02-11 23:41:13 +00:00
|
|
|
if (gLastFocusedContent) {
|
2001-06-18 07:34:41 +00:00
|
|
|
// Blur the element.
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
2001-07-20 08:14:44 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
2002-10-01 01:25:00 +00:00
|
|
|
if (focusController)
|
|
|
|
focusController->GetFocusedElement(getter_AddRefs(focusedElement));
|
2001-07-20 08:14:44 +00:00
|
|
|
nsCOMPtr<nsIContent> focusedContent = do_QueryInterface(focusedElement);
|
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
gLastFocusedDocument->GetShellAt(0, getter_AddRefs(shell));
|
2001-06-18 07:34:41 +00:00
|
|
|
if (shell) {
|
|
|
|
nsCOMPtr<nsIPresContext> oldPresContext;
|
|
|
|
shell->GetPresContext(getter_AddRefs(oldPresContext));
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
2002-02-14 04:23:48 +00:00
|
|
|
event.flags = 0;
|
2001-06-18 07:34:41 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
oldPresContext->GetEventStateManager(getter_AddRefs(esm));
|
|
|
|
esm->SetFocusedContent(gLastFocusedContent);
|
2001-07-20 08:14:44 +00:00
|
|
|
if(focusedContent)
|
|
|
|
focusedContent->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
2001-06-18 07:34:41 +00:00
|
|
|
esm->SetFocusedContent(nsnull);
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
2000-02-11 23:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
|
|
|
|
|
|
|
// fire blur on document and window
|
2001-06-18 07:34:41 +00:00
|
|
|
mDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
if (ourGlobal)
|
|
|
|
ourGlobal->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
2001-07-20 08:14:44 +00:00
|
|
|
else {
|
|
|
|
// If the document is being torn down, we can't fire a blur on
|
|
|
|
// the window, but we still need to tell the focus controller
|
|
|
|
// that it isn't active.
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsCOMPtr<nsIFocusController> fc = getter_AddRefs(GetFocusControllerForDocument(gLastFocusedDocument));
|
2001-07-20 08:14:44 +00:00
|
|
|
if (fc)
|
|
|
|
fc->SetActive(PR_FALSE);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
1999-11-13 05:16:33 +00:00
|
|
|
}
|
2000-02-29 03:54:49 +00:00
|
|
|
|
1999-05-18 23:51:04 +00:00
|
|
|
break;
|
1999-11-13 05:16:33 +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
|
|
|
|
|
|
|
PRBool isSpecialAccessKeyDown = PR_FALSE;
|
|
|
|
switch (gGeneralAccesskeyModifier) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL: isSpecialAccessKeyDown = keyEvent->isControl; break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT: isSpecialAccessKeyDown = keyEvent->isAlt; break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META: isSpecialAccessKeyDown = keyEvent->isMeta; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//This is to prevent keyboard scrolling while alt or other accesskey modifier in use.
|
2002-09-03 05:48:06 +00:00
|
|
|
if (isSpecialAccessKeyDown)
|
|
|
|
HandleAccessKey(aPresContext, keyEvent, aStatus, -1, eAccessKeyProcessingNormal);
|
|
|
|
}
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
case NS_KEY_UP:
|
|
|
|
case NS_MOUSE_SCROLL:
|
|
|
|
{
|
|
|
|
if (mCurrentFocus) {
|
|
|
|
mCurrentTargetContent = mCurrentFocus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-16 10:22:20 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
// Note: for the in parameter aChildOffset,
|
|
|
|
// -1 stands for not bubbling from the child docShell
|
|
|
|
// 0 -- childCount - 1 stands for the child docShell's offset
|
|
|
|
// which bubbles up the access key handling
|
|
|
|
void
|
|
|
|
nsEventStateManager::HandleAccessKey(nsIPresContext* aPresContext,
|
|
|
|
nsKeyEvent *aEvent,
|
|
|
|
nsEventStatus* aStatus,
|
|
|
|
PRInt32 aChildOffset,
|
|
|
|
ProcessingAccessKeyState aAccessKeyState)
|
|
|
|
{
|
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
|
|
|
|
if (mAccessKeys) {
|
|
|
|
// Someone registered an accesskey. Find and activate it.
|
|
|
|
PRUnichar accKey = nsCRT::ToLower((char)aEvent->charCode);
|
|
|
|
|
|
|
|
nsVoidKey key(NS_INT32_TO_PTR(accKey));
|
|
|
|
if (mAccessKeys->Exists(&key)) {
|
|
|
|
nsCOMPtr<nsIContent> content = dont_AddRef(NS_STATIC_CAST(nsIContent*, mAccessKeys->Get(&key)));
|
|
|
|
|
|
|
|
PRBool isXUL = content->IsContentOfType(nsIContent::eXUL);
|
|
|
|
|
|
|
|
// if it's a XUL element...
|
|
|
|
if (isXUL) {
|
|
|
|
|
|
|
|
// find out what type of content node this is
|
|
|
|
nsCOMPtr<nsIAtom> atom;
|
|
|
|
nsresult rv = content->GetTag(*getter_AddRefs(atom));
|
|
|
|
if (NS_SUCCEEDED(rv) && atom) {
|
|
|
|
if (atom == nsXULAtoms::label) {
|
|
|
|
// If anything fails, this will be null ...
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
|
|
|
|
nsAutoString control;
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsXULAtoms::control, control);
|
|
|
|
if (!control.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
content->GetDocument(*getter_AddRefs(document));
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument = do_QueryInterface(document);
|
|
|
|
if (domDocument)
|
|
|
|
domDocument->GetElementById(control, getter_AddRefs(element));
|
|
|
|
}
|
|
|
|
// ... that here we'll either change |content| to the element
|
|
|
|
// referenced by |element|, or clear it.
|
|
|
|
content = do_QueryInterface(element);
|
|
|
|
}
|
|
|
|
}
|
2001-05-23 06:35:32 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
if (!content)
|
|
|
|
return;
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
nsIFrame* frame = nsnull;
|
|
|
|
presShell->GetPrimaryFrameFor(content, &frame);
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
if (frame) {
|
|
|
|
const nsStyleVisibility* vis;
|
|
|
|
frame->GetStyleData(eStyleStruct_Visibility,
|
|
|
|
((const nsStyleStruct *&)vis));
|
|
|
|
PRBool viewShown = PR_TRUE;
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
nsIView* frameView = nsnull;
|
|
|
|
frame->GetView(mPresContext, &frameView);
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
if (!frameView) {
|
|
|
|
nsIFrame* parentWithView = nsnull;
|
|
|
|
frame->GetParentWithView(mPresContext, &parentWithView);
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
if (parentWithView)
|
|
|
|
parentWithView->GetView(mPresContext, &frameView);
|
|
|
|
}
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
while (frameView) {
|
|
|
|
nsViewVisibility visib;
|
|
|
|
frameView->GetVisibility(visib);
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
if (visib == nsViewVisibility_kHide) {
|
|
|
|
viewShown = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
frameView->GetParent(frameView);
|
|
|
|
}
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
// get the XUL element
|
|
|
|
nsCOMPtr<nsIDOMXULElement> element = do_QueryInterface(content);
|
|
|
|
|
|
|
|
// if collapsed or hidden, we don't get tabbed into.
|
|
|
|
if (viewShown &&
|
|
|
|
vis->mVisible != NS_STYLE_VISIBILITY_COLLAPSE &&
|
|
|
|
vis->mVisible != NS_STYLE_VISIBILITY_HIDDEN &&
|
|
|
|
element) {
|
|
|
|
|
|
|
|
// find out what type of content node this is
|
|
|
|
nsCOMPtr<nsIAtom> atom;
|
|
|
|
nsresult rv = content->GetTag(*getter_AddRefs(atom));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && atom) {
|
|
|
|
// define behavior for each type of XUL element:
|
|
|
|
if (atom == nsXULAtoms::textbox || atom == nsXULAtoms::menulist) {
|
|
|
|
// if it's a text box or menulist, give it focus
|
|
|
|
element->Focus();
|
2002-12-04 05:38:07 +00:00
|
|
|
} else if (atom == nsXULAtoms::toolbarbutton) {
|
|
|
|
// if it's a toolbar button, just click
|
|
|
|
element->Click();
|
2002-09-03 05:48:06 +00:00
|
|
|
} else {
|
|
|
|
// otherwise, focus and click in it
|
|
|
|
element->Focus();
|
|
|
|
element->Click();
|
2002-02-21 13:39:39 +00:00
|
|
|
}
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { // otherwise, it must be HTML
|
|
|
|
// It's hard to say what HTML4 wants us to do in all cases.
|
|
|
|
// So for now we'll settle for A) Set focus
|
|
|
|
ChangeFocus(content, eEventFocusedByKey);
|
2002-02-21 13:39:39 +00:00
|
|
|
|
2002-11-25 23:26:06 +00:00
|
|
|
nsresult rv = getPrefBranch();
|
2002-09-03 05:48:06 +00:00
|
|
|
PRBool activate = PR_TRUE;
|
2001-05-23 06:35:32 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetBoolPref("accessibility.accesskeycausesactivation", &activate);
|
2002-09-03 05:48:06 +00:00
|
|
|
}
|
2000-05-16 10:22:20 +00:00
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
if (activate) {
|
|
|
|
// B) Click on it if the users prefs indicate to do so.
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
|
|
|
event.message = NS_MOUSE_LEFT_CLICK;
|
|
|
|
event.isShift = PR_FALSE;
|
|
|
|
event.isControl = PR_FALSE;
|
|
|
|
event.isAlt = PR_FALSE;
|
|
|
|
event.isMeta = PR_FALSE;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.widget = nsnull;
|
|
|
|
content->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
2000-05-16 10:22:20 +00:00
|
|
|
}
|
2002-09-03 05:48:06 +00:00
|
|
|
|
2000-05-16 10:22:20 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
// after the local accesskey handling
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
// checking all sub docshells
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
aPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
NS_ASSERTION(pcContainer, "no container for presContext");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShell(do_QueryInterface(pcContainer));
|
|
|
|
NS_ASSERTION(docShell, "no docShellTreeNode for presContext");
|
|
|
|
|
|
|
|
PRInt32 childCount;
|
|
|
|
docShell->GetChildCount(&childCount);
|
|
|
|
for (PRInt32 counter = 0; counter < childCount; counter++) {
|
|
|
|
// Not processing the child which bubbles up the handling
|
|
|
|
if (aAccessKeyState == eAccessKeyProcessingUp && counter == aChildOffset)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> subShellItem;
|
|
|
|
nsCOMPtr<nsIPresShell> subPS;
|
|
|
|
nsCOMPtr<nsIPresContext> subPC;
|
|
|
|
nsCOMPtr<nsIEventStateManager> subESM;
|
|
|
|
|
|
|
|
|
|
|
|
docShell->GetChildAt(counter, getter_AddRefs(subShellItem));
|
|
|
|
nsCOMPtr<nsIDocShell> subDS = do_QueryInterface(subShellItem);
|
|
|
|
if (subDS && IsShellVisible(subDS)) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-09-03 05:48:06 +00:00
|
|
|
subPS->GetPresContext(getter_AddRefs(subPC));
|
2002-09-07 02:02:24 +00:00
|
|
|
NS_ASSERTION(subPC, "PresShell without PresContext");
|
2002-09-03 05:48:06 +00:00
|
|
|
|
|
|
|
subPC->GetEventStateManager(getter_AddRefs(subESM));
|
|
|
|
|
|
|
|
nsEventStateManager* esm = NS_STATIC_CAST(nsEventStateManager *, NS_STATIC_CAST(nsIEventStateManager *, subESM.get()));
|
|
|
|
if (esm)
|
|
|
|
esm->HandleAccessKey(subPC, aEvent, aStatus, -1, eAccessKeyProcessingDown);
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
// bubble up the process to the parent docShell if necesary
|
|
|
|
if (eAccessKeyProcessingDown != aAccessKeyState && nsEventStatus_eConsumeNoDefault != *aStatus) {
|
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
aPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
NS_ASSERTION(pcContainer, "no container for presContext");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShell(do_QueryInterface(pcContainer));
|
|
|
|
NS_ASSERTION(docShell, "no docShellTreeItem for presContext");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentShellItem;
|
|
|
|
docShell->GetParent(getter_AddRefs(parentShellItem));
|
|
|
|
nsCOMPtr<nsIDocShell> parentDS = do_QueryInterface(parentShellItem);
|
|
|
|
if (parentDS) {
|
|
|
|
PRInt32 myOffset;
|
|
|
|
docShell->GetChildOffset(&myOffset);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> parentPS;
|
|
|
|
nsCOMPtr<nsIPresContext> parentPC;
|
|
|
|
nsCOMPtr<nsIEventStateManager> parentESM;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
parentPS->GetPresContext(getter_AddRefs(parentPC));
|
2002-09-07 02:02:24 +00:00
|
|
|
NS_ASSERTION(parentPC, "PresShell without PresContext");
|
2002-09-03 05:48:06 +00:00
|
|
|
|
|
|
|
parentPC->GetEventStateManager(getter_AddRefs(parentESM));
|
|
|
|
|
|
|
|
nsEventStateManager* esm = NS_STATIC_CAST(nsEventStateManager *, NS_STATIC_CAST(nsIEventStateManager *, parentESM.get()));
|
|
|
|
if (esm)
|
|
|
|
esm->HandleAccessKey(parentPC, aEvent, aStatus, myOffset, eAccessKeyProcessingUp);
|
|
|
|
}
|
|
|
|
}// 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
|
|
|
|
nsEventStateManager :: CreateClickHoldTimer ( nsIPresContext* inPresContext, nsGUIEvent* inMouseDownEvent )
|
|
|
|
{
|
|
|
|
// just to be anal (er, safe)
|
|
|
|
if ( mClickHoldTimer ) {
|
|
|
|
mClickHoldTimer->Cancel();
|
|
|
|
mClickHoldTimer = nsnull;
|
|
|
|
}
|
2002-03-26 00:59:03 +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.
|
|
|
|
nsCOMPtr<nsIContent> clickedContent;
|
|
|
|
if ( mGestureDownFrame ) {
|
|
|
|
mGestureDownFrame->GetContent(getter_AddRefs(clickedContent));
|
|
|
|
if ( clickedContent ) {
|
|
|
|
// check for the |popup| attribute
|
|
|
|
nsAutoString popup;
|
2001-08-17 08:14:14 +00:00
|
|
|
clickedContent->GetAttr(kNameSpaceID_None, nsXULAtoms::popup, popup);
|
2001-04-26 19:12:31 +00:00
|
|
|
if ( popup != NS_LITERAL_STRING("") )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// check for a <menubutton> like bookmarks
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
clickedContent->GetTag ( *getter_AddRefs(tag) );
|
|
|
|
if ( tag == nsXULAtoms::menubutton )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
mClickHoldTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if ( mClickHoldTimer )
|
2002-09-07 07:17:59 +00:00
|
|
|
mClickHoldTimer->InitWithFuncCallback(sClickHoldCallback, this, kClickHoldDelay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
2001-03-30 04:45:40 +00:00
|
|
|
|
|
|
|
mEventPoint = inMouseDownEvent->point;
|
|
|
|
mEventRefPoint = inMouseDownEvent->refPoint;
|
|
|
|
mEventDownWidget = inMouseDownEvent->widget;
|
|
|
|
|
|
|
|
mEventPresContext = inPresContext;
|
|
|
|
|
|
|
|
} // CreateClickHoldTimer
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// KillClickHoldTimer
|
|
|
|
//
|
|
|
|
// Stop the timer that would show the context menu dead in its tracks
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager :: KillClickHoldTimer ( )
|
|
|
|
{
|
|
|
|
if ( mClickHoldTimer ) {
|
|
|
|
mClickHoldTimer->Cancel();
|
|
|
|
mClickHoldTimer = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEventDownWidget = nsnull;
|
|
|
|
mEventPresContext = nsnull;
|
|
|
|
|
|
|
|
} // KillTooltipTimer
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// sClickHoldCallback
|
|
|
|
//
|
|
|
|
// This fires after the mouse has been down for a certain length of time.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager :: sClickHoldCallback ( nsITimer *aTimer, void* aESM )
|
|
|
|
{
|
|
|
|
nsEventStateManager* self = NS_STATIC_CAST(nsEventStateManager*, aESM);
|
|
|
|
if ( self )
|
|
|
|
self->FireContextClick();
|
|
|
|
|
|
|
|
// NOTE: |aTimer| and |self->mAutoHideTimer| are invalid after calling ClosePopup();
|
|
|
|
|
|
|
|
} // sAutoHideCallback
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// FireContextClick
|
|
|
|
//
|
|
|
|
// If we're this far, our timer has fired, which means the mouse has been down
|
|
|
|
// for a certain period of time and has not moved enough to generate a dragGesture.
|
|
|
|
// We can be certain the user wants a context-click at this stage, so generate
|
|
|
|
// a dom event and fire it in.
|
|
|
|
//
|
|
|
|
// After the event fires, check if PreventDefault() has been set on the event which
|
|
|
|
// means that someone either ate the event or put up a context menu. This is our cue
|
|
|
|
// to stop tracking the drag gesture. If we always did this, draggable items w/out
|
|
|
|
// a context menu wouldn't be draggable after a certain length of time, which is
|
|
|
|
// _not_ what we want.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager :: FireContextClick ( )
|
|
|
|
{
|
|
|
|
if ( !mEventDownWidget || !mEventPresContext )
|
|
|
|
return;
|
|
|
|
|
2002-03-26 00:59:03 +00:00
|
|
|
#if defined (XP_MAC) || defined(XP_MACOSX)
|
|
|
|
// 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;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
|
|
|
event.message = NS_CONTEXTMENU;
|
|
|
|
event.widget = mEventDownWidget;
|
|
|
|
event.clickCount = 1;
|
|
|
|
event.point = mEventPoint;
|
|
|
|
event.refPoint = mEventRefPoint;
|
|
|
|
event.isShift = PR_FALSE;
|
|
|
|
event.isControl = PR_FALSE;
|
|
|
|
event.isAlt = PR_FALSE;
|
|
|
|
event.isMeta = PR_FALSE;
|
|
|
|
|
|
|
|
// 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).
|
|
|
|
mCurrentTarget = mGestureDownFrame;
|
|
|
|
nsCOMPtr<nsIContent> lastContent;
|
|
|
|
if ( mGestureDownFrame ) {
|
|
|
|
mGestureDownFrame->GetContent(getter_AddRefs(lastContent));
|
|
|
|
|
|
|
|
if ( lastContent ) {
|
|
|
|
// before dispatching, check that we're not on something that doesn't get a context menu
|
|
|
|
PRBool allowedToDispatch = PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
lastContent->GetTag ( *getter_AddRefs(tag) );
|
2001-03-31 23:32:14 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElm ( do_QueryInterface(lastContent) );
|
2002-08-06 08:32:19 +00:00
|
|
|
PRBool isFormControl =
|
|
|
|
lastContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL);
|
2001-03-31 23:32:14 +00:00
|
|
|
if ( inputElm ) {
|
2001-03-31 23:50:25 +00:00
|
|
|
// of all input elements, only ones dealing with text are allowed to have context menus
|
|
|
|
if ( tag == nsHTMLAtoms::input ) {
|
2001-03-31 23:32:14 +00:00
|
|
|
nsAutoString type;
|
2001-08-17 08:14:14 +00:00
|
|
|
lastContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::type, type);
|
2001-03-31 23:32:14 +00:00
|
|
|
if ( type != NS_LITERAL_STRING("") && type != NS_LITERAL_STRING("text") &&
|
|
|
|
type != NS_LITERAL_STRING("password") && type != NS_LITERAL_STRING("file") )
|
|
|
|
allowedToDispatch = PR_FALSE;
|
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
2002-08-06 08:32:19 +00:00
|
|
|
else if ( isFormControl && tag != nsHTMLAtoms::textarea )
|
|
|
|
// catches combo-boxes, <object>
|
2001-03-31 23:32:14 +00:00
|
|
|
allowedToDispatch = PR_FALSE;
|
|
|
|
else if ( tag == nsXULAtoms::scrollbar || tag == nsXULAtoms::scrollbarbutton || tag == nsXULAtoms::button )
|
2001-03-30 04:45:40 +00:00
|
|
|
allowedToDispatch = PR_FALSE;
|
2002-08-06 08:32:19 +00:00
|
|
|
else if ( tag == nsHTMLAtoms::applet || tag == nsHTMLAtoms::embed )
|
2001-06-04 22:39:49 +00:00
|
|
|
allowedToDispatch = PR_FALSE;
|
2002-03-31 17:38:52 +00:00
|
|
|
else if ( tag == nsXULAtoms::toolbarbutton ) {
|
|
|
|
// a <toolbarbutton> that has the container attribute set will already have its
|
|
|
|
// own dropdown.
|
|
|
|
nsAutoString container;
|
|
|
|
lastContent->GetAttr(kNameSpaceID_None, nsXULAtoms::container, container);
|
|
|
|
if ( container.Length() )
|
|
|
|
allowedToDispatch = PR_FALSE;
|
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
|
|
|
|
if ( allowedToDispatch ) {
|
|
|
|
// stop selection tracking, we're in control now
|
|
|
|
nsCOMPtr<nsIFrameSelection> frameSel;
|
|
|
|
GetSelection ( mGestureDownFrame, mEventPresContext, getter_AddRefs(frameSel) );
|
|
|
|
if ( frameSel ) {
|
|
|
|
PRBool mouseDownState = PR_TRUE;
|
|
|
|
frameSel->GetMouseDownState(&mouseDownState);
|
|
|
|
if (mouseDownState)
|
|
|
|
frameSel->SetMouseDownState(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// dispatch to DOM
|
|
|
|
lastContent->HandleDOMEvent(mEventPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
|
2002-05-21 00:00:46 +00:00
|
|
|
// Firing the DOM event could have caused mGestureDownFrame to
|
|
|
|
// be destroyed. So, null-check it again.
|
|
|
|
|
|
|
|
if (mGestureDownFrame) {
|
|
|
|
// dispatch to the frame
|
|
|
|
mGestureDownFrame->HandleEvent(mEventPresContext, &event, &status);
|
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check if the event has been handled. If so, stop tracking a drag
|
|
|
|
if ( status == nsEventStatus_eConsumeNoDefault )
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
|
|
|
|
KillClickHoldTimer();
|
|
|
|
|
|
|
|
} // FireContextClick
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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
|
2001-03-30 04:45:40 +00:00
|
|
|
nsEventStateManager :: BeginTrackingDragGesture ( nsIPresContext* aPresContext, nsGUIEvent* inDownEvent, nsIFrame* inDownFrame )
|
1999-08-19 19:48:45 +00:00
|
|
|
{
|
|
|
|
mIsTrackingDragGesture = PR_TRUE;
|
|
|
|
mGestureDownPoint = inDownEvent->point;
|
|
|
|
mGestureDownFrame = inDownFrame;
|
2001-03-30 04:45:40 +00:00
|
|
|
|
|
|
|
#ifdef CLICK_HOLD_CONTEXT_MENUS
|
|
|
|
// fire off a timer to track click-hold
|
|
|
|
CreateClickHoldTimer ( aPresContext, inDownEvent );
|
|
|
|
#endif
|
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// StopTrackingDragGesture
|
|
|
|
//
|
|
|
|
// Record that the mouse has gone back up so that we should leave the TRACKING
|
|
|
|
// state of d&d gesture tracker and return to the START state.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager :: StopTrackingDragGesture ( )
|
|
|
|
{
|
|
|
|
mIsTrackingDragGesture = PR_FALSE;
|
|
|
|
mGestureDownPoint = nsPoint(0,0);
|
|
|
|
mGestureDownFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-30 04:45:40 +00:00
|
|
|
//
|
|
|
|
// GetSelection
|
|
|
|
//
|
|
|
|
// Helper routine to get an nsIFrameSelection from the given frame
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager :: GetSelection ( nsIFrame* inFrame, nsIPresContext* inPresContext, nsIFrameSelection** outSelection )
|
|
|
|
{
|
|
|
|
*outSelection = nsnull;
|
|
|
|
|
|
|
|
if (inFrame) {
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
nsresult rv = inFrame->GetSelectionController(inPresContext, getter_AddRefs(selCon));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && selCon) {
|
|
|
|
nsCOMPtr<nsIFrameSelection> frameSel;
|
|
|
|
|
|
|
|
frameSel = do_QueryInterface(selCon);
|
|
|
|
|
|
|
|
if (! frameSel) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
rv = inPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && shell)
|
2001-04-02 18:18:53 +00:00
|
|
|
rv = shell->GetFrameSelection(getter_AddRefs(frameSel));
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
2001-04-02 18:18:53 +00:00
|
|
|
|
|
|
|
*outSelection = frameSel.get();
|
|
|
|
NS_IF_ADDREF(*outSelection);
|
2001-03-30 04:45:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // GetSelection
|
|
|
|
|
|
|
|
|
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
|
2002-03-19 04:30:17 +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
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStateManager :: GenerateDragGesture ( nsIPresContext* aPresContext, nsGUIEvent *aEvent )
|
1999-08-19 19:48:45 +00:00
|
|
|
{
|
1999-11-24 06:03:41 +00:00
|
|
|
NS_WARN_IF_FALSE(aPresContext, "This shouldn't happen.");
|
1999-08-19 19:48:45 +00:00
|
|
|
if ( IsTrackingDragGesture() ) {
|
2000-05-25 20:04:02 +00:00
|
|
|
|
|
|
|
// Check if selection is tracking drag gestures, if so
|
|
|
|
// don't interfere!
|
2001-03-30 04:45:40 +00:00
|
|
|
nsCOMPtr<nsIFrameSelection> frameSel;
|
|
|
|
GetSelection ( mGestureDownFrame, aPresContext, getter_AddRefs(frameSel) );
|
|
|
|
if ( frameSel ) {
|
|
|
|
PRBool mouseDownState = PR_TRUE;
|
|
|
|
frameSel->GetMouseDownState(&mouseDownState);
|
|
|
|
if (mouseDownState) {
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
return;
|
2000-05-25 20:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
// figure out the delta in twips, since that is how it is in the event.
|
|
|
|
// Do we need to do this conversion every time? Will the pres context really change on
|
|
|
|
// us or can we cache it?
|
|
|
|
long twipDeltaToStartDrag = 0;
|
|
|
|
const long pixelDeltaToStartDrag = 5;
|
|
|
|
nsCOMPtr<nsIDeviceContext> devContext;
|
1999-11-24 06:03:41 +00:00
|
|
|
aPresContext->GetDeviceContext ( getter_AddRefs(devContext) );
|
1999-08-19 19:48:45 +00:00
|
|
|
if ( devContext ) {
|
|
|
|
float pixelsToTwips = 0.0;
|
|
|
|
devContext->GetDevUnitsToTwips(pixelsToTwips);
|
1999-08-24 09:37:28 +00:00
|
|
|
twipDeltaToStartDrag = (long)(pixelDeltaToStartDrag * pixelsToTwips);
|
1999-08-19 19:48:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fire drag gesture if mouse has moved enough
|
|
|
|
if ( abs(aEvent->point.x - mGestureDownPoint.x) > twipDeltaToStartDrag ||
|
|
|
|
abs(aEvent->point.y - mGestureDownPoint.y) > twipDeltaToStartDrag ) {
|
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
|
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_DRAGDROP_EVENT;
|
|
|
|
event.message = NS_DRAGDROP_GESTURE;
|
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
2000-01-15 17:21:20 +00:00
|
|
|
event.isShift = ((nsMouseEvent*)aEvent)->isShift;
|
|
|
|
event.isControl = ((nsMouseEvent*)aEvent)->isControl;
|
|
|
|
event.isAlt = ((nsMouseEvent*)aEvent)->isAlt;
|
|
|
|
event.isMeta = ((nsMouseEvent*)aEvent)->isMeta;
|
1999-08-19 19:48:45 +00:00
|
|
|
|
2000-08-01 00:35:23 +00:00
|
|
|
// 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).
|
|
|
|
mCurrentTarget = mGestureDownFrame;
|
1999-08-19 19:48:45 +00:00
|
|
|
nsCOMPtr<nsIContent> lastContent;
|
1999-11-09 07:10:46 +00:00
|
|
|
if ( mGestureDownFrame ) {
|
2000-02-11 01:24:59 +00:00
|
|
|
mGestureDownFrame->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(lastContent));
|
1999-11-09 07:10:46 +00:00
|
|
|
if ( lastContent )
|
2000-08-01 00:35:23 +00:00
|
|
|
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
1999-11-09 07:10:46 +00:00
|
|
|
}
|
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
// dispatch to the frame
|
2000-08-14 22:29:03 +00:00
|
|
|
if ( mGestureDownFrame )
|
1999-11-24 06:03:41 +00:00
|
|
|
mGestureDownFrame->HandleEvent(aPresContext, &event, &status);
|
2000-08-14 22:29:03 +00:00
|
|
|
|
2000-08-01 00:35:23 +00:00
|
|
|
StopTrackingDragGesture();
|
1999-08-19 19:48:45 +00:00
|
|
|
}
|
|
|
|
}
|
2000-10-16 21:52:22 +00:00
|
|
|
|
|
|
|
// Now flush all pending notifications.
|
2001-01-20 04:59:39 +00:00
|
|
|
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;
|
|
|
|
|
2000-08-06 04:15:02 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!ourGlobal) return NS_ERROR_FAILURE;
|
|
|
|
|
2000-08-06 04:15:02 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(ourGlobal);
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!ourWindow) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
2000-09-10 05:35:36 +00:00
|
|
|
nsCOMPtr<nsIDOMWindowInternal> rootWindow;
|
2000-08-06 04:15:02 +00:00
|
|
|
ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!rootWindow) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
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<nsIDOMWindow> windowContent;
|
|
|
|
rootWindow->GetContent(getter_AddRefs(windowContent));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!windowContent) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
windowContent->GetDocument(getter_AddRefs(domDoc));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!domDoc) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!doc) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
doc->GetShellAt(0, getter_AddRefs(presShell));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!presShell) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
presShell->GetPresContext(getter_AddRefs(presContext));
|
2000-09-10 05:35:36 +00:00
|
|
|
if(!presContext) return NS_ERROR_FAILURE;
|
2000-08-06 04:15:02 +00:00
|
|
|
|
2000-05-15 02:10:11 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
2000-08-06 04:15:02 +00:00
|
|
|
presContext->GetContainer(getter_AddRefs(pcContainer));
|
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
|
|
|
|
2001-02-15 22:07:06 +00:00
|
|
|
|
|
|
|
//
|
2000-12-09 07:28:19 +00:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::DoWheelScroll(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsMouseScrollEvent* msEvent,
|
|
|
|
PRInt32 numLines, PRBool scrollPage,
|
|
|
|
PRBool aUseTargetFrame)
|
|
|
|
{
|
2001-11-14 10:06:21 +00:00
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
|
|
|
aTargetFrame->GetContent(getter_AddRefs(targetContent));
|
2001-11-16 04:52:16 +00:00
|
|
|
if (!targetContent)
|
|
|
|
GetFocusedContent(getter_AddRefs(targetContent));
|
|
|
|
if (!targetContent) return NS_OK;
|
2001-11-14 10:06:21 +00:00
|
|
|
nsCOMPtr<nsIDocument> targetDoc;
|
|
|
|
targetContent->GetDocument(*getter_AddRefs(targetDoc));
|
|
|
|
if (!targetDoc) return NS_OK;
|
|
|
|
nsCOMPtr<nsIDOMDocumentEvent> targetDOMDoc(do_QueryInterface(targetDoc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
targetDOMDoc->CreateEvent(NS_LITERAL_STRING("MouseScrollEvents"), getter_AddRefs(event));
|
|
|
|
if (event) {
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(event));
|
|
|
|
nsCOMPtr<nsIDOMDocumentView> docView = do_QueryInterface(targetDoc);
|
|
|
|
if (!docView) return nsnull;
|
|
|
|
nsCOMPtr<nsIDOMAbstractView> view;
|
|
|
|
docView->GetDefaultView(getter_AddRefs(view));
|
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
if (scrollPage) {
|
|
|
|
if (numLines > 0) {
|
|
|
|
numLines = nsIDOMNSUIEvent::SCROLL_PAGE_DOWN;
|
|
|
|
} else {
|
|
|
|
numLines = nsIDOMNSUIEvent::SCROLL_PAGE_UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-14 10:06:21 +00:00
|
|
|
mouseEvent->InitMouseEvent(NS_LITERAL_STRING("DOMMouseScroll"), PR_TRUE, PR_TRUE,
|
|
|
|
view, numLines,
|
|
|
|
msEvent->refPoint.x, msEvent->refPoint.y,
|
|
|
|
msEvent->point.x, msEvent->point.y,
|
|
|
|
msEvent->isControl, msEvent->isAlt, msEvent->isShift, msEvent->isMeta,
|
|
|
|
0, nsnull);
|
|
|
|
PRBool allowDefault;
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(targetContent));
|
|
|
|
if (target) {
|
|
|
|
target->DispatchEvent(event, &allowDefault);
|
|
|
|
if (!allowDefault)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2001-03-06 22:16:42 +00:00
|
|
|
|
2001-11-14 10:06:21 +00:00
|
|
|
targetDOMDoc->CreateEvent(NS_LITERAL_STRING("MouseScrollEvents"), getter_AddRefs(event));
|
|
|
|
if (event) {
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(event));
|
2000-12-09 07:28:19 +00:00
|
|
|
}
|
2001-11-14 10:06:21 +00:00
|
|
|
|
|
|
|
nsIView* focusView = nsnull;
|
|
|
|
nsIScrollableView* sv = nsnull;
|
|
|
|
nsIFrame* focusFrame = nsnull;
|
2001-03-06 22:16:42 +00:00
|
|
|
|
2001-04-30 08:11:03 +00:00
|
|
|
// Create a mouseout event that we fire to the content before
|
|
|
|
// scrolling, to allow tooltips to disappear, etc.
|
|
|
|
|
|
|
|
nsMouseEvent mouseOutEvent;
|
|
|
|
mouseOutEvent.eventStructType = NS_MOUSE_EVENT;
|
2002-10-29 23:59:08 +00:00
|
|
|
mouseOutEvent.message = NS_MOUSE_EXIT;
|
2001-04-30 08:11:03 +00:00
|
|
|
mouseOutEvent.widget = msEvent->widget;
|
|
|
|
mouseOutEvent.clickCount = 0;
|
|
|
|
mouseOutEvent.point = nsPoint(0,0);
|
|
|
|
mouseOutEvent.refPoint = nsPoint(0,0);
|
|
|
|
mouseOutEvent.isShift = PR_FALSE;
|
|
|
|
mouseOutEvent.isControl = PR_FALSE;
|
|
|
|
mouseOutEvent.isAlt = PR_FALSE;
|
|
|
|
mouseOutEvent.isMeta = PR_FALSE;
|
|
|
|
|
2002-06-28 17:43:38 +00:00
|
|
|
// initialize nativeMsg field otherwise plugin code will crash when trying to access it
|
|
|
|
mouseOutEvent.nativeMsg = nsnull;
|
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
|
|
|
|
// Otherwise, check for a focused content element
|
|
|
|
nsCOMPtr<nsIContent> focusContent;
|
|
|
|
if (mCurrentFocus) {
|
|
|
|
focusContent = mCurrentFocus;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If there is no focused content, get the document content
|
|
|
|
EnsureDocument(presShell);
|
2001-06-20 03:27:48 +00:00
|
|
|
mDocument->GetRootContent(getter_AddRefs(focusContent));
|
2000-12-09 07:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!focusContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (aUseTargetFrame)
|
|
|
|
focusFrame = aTargetFrame;
|
|
|
|
else
|
|
|
|
presShell->GetPrimaryFrameFor(focusContent, &focusFrame);
|
|
|
|
|
|
|
|
if (!focusFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Now check whether this frame wants to provide us with an
|
|
|
|
// nsIScrollableView to use for scrolling.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScrollableViewProvider> svp = do_QueryInterface(focusFrame);
|
|
|
|
if (svp) {
|
|
|
|
svp->GetScrollableView(&sv);
|
2001-01-04 22:24:07 +00:00
|
|
|
if (sv)
|
2002-12-11 14:24:49 +00:00
|
|
|
CallQueryInterface(sv, &focusView);
|
2000-12-09 07:28:19 +00:00
|
|
|
} else {
|
|
|
|
focusFrame->GetView(aPresContext, &focusView);
|
|
|
|
if (!focusView) {
|
|
|
|
nsIFrame* frameWithView;
|
|
|
|
focusFrame->GetParentWithView(aPresContext, &frameWithView);
|
|
|
|
if (frameWithView)
|
|
|
|
frameWithView->GetView(aPresContext, &focusView);
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sv = GetNearestScrollingView(focusView);
|
|
|
|
}
|
|
|
|
|
2001-09-07 21:00:57 +00:00
|
|
|
PRBool passToParent = PR_FALSE;
|
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
if (sv) {
|
2002-10-29 23:59:08 +00:00
|
|
|
GenerateMouseEnterExit(aPresContext, &mouseOutEvent);
|
2001-04-30 08:11:03 +00:00
|
|
|
|
2001-09-07 21:00:57 +00:00
|
|
|
// Check the scroll position before and after calling ScrollBy[Page|Line]s.
|
|
|
|
// This allows us to detect whether the view is not scrollable
|
|
|
|
// (for whatever reason) and bubble up the scroll to the parent document.
|
|
|
|
|
|
|
|
nscoord xPos, yPos;
|
|
|
|
sv->GetScrollPosition(xPos, yPos);
|
|
|
|
|
2000-12-09 07:28:19 +00:00
|
|
|
if (scrollPage)
|
|
|
|
sv->ScrollByPages((numLines > 0) ? 1 : -1);
|
2003-01-07 05:35:42 +00:00
|
|
|
else {
|
|
|
|
PRInt32 vertLines = 0, horizLines = 0;
|
|
|
|
|
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsHorizontal)
|
|
|
|
horizLines = numLines;
|
|
|
|
|
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsVertical)
|
|
|
|
vertLines = numLines;
|
|
|
|
|
|
|
|
sv->ScrollByLines(horizLines, vertLines);
|
|
|
|
}
|
2000-12-09 07:28:19 +00:00
|
|
|
|
2001-09-07 21:00:57 +00:00
|
|
|
nscoord newXPos, newYPos;
|
|
|
|
sv->GetScrollPosition(newXPos, newYPos);
|
|
|
|
|
|
|
|
if (newYPos != yPos) {
|
|
|
|
if (focusView)
|
|
|
|
ForceViewUpdate(focusView);
|
|
|
|
} else
|
|
|
|
passToParent = PR_TRUE;
|
|
|
|
} else
|
|
|
|
passToParent = PR_TRUE;
|
|
|
|
|
|
|
|
if (passToParent) {
|
2000-12-09 07:28:19 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsIFrame* newFrame = nsnull;
|
|
|
|
nsCOMPtr<nsIPresContext> newPresContext;
|
|
|
|
|
|
|
|
rv = GetParentScrollingView(msEvent, aPresContext, newFrame,
|
|
|
|
*getter_AddRefs(newPresContext));
|
2002-04-17 04:17:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && newFrame)
|
2000-12-09 07:28:19 +00:00
|
|
|
return DoWheelScroll(newPresContext, newFrame, msEvent, numLines,
|
|
|
|
scrollPage, PR_TRUE);
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::GetParentScrollingView(nsMouseScrollEvent *aEvent,
|
|
|
|
nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* &targetOuterFrame,
|
|
|
|
nsIPresContext* &presCtxOuter)
|
|
|
|
{
|
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;
|
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2002-04-04 22:42:19 +00:00
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
NS_ASSERTION(presShell, "No presshell in prescontext!");
|
|
|
|
|
|
|
|
presShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(doc, "No document in prescontext!");
|
2001-09-07 21:00:57 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> parentDoc;
|
2002-04-17 04:17:16 +00:00
|
|
|
doc->GetParentDocument(getter_AddRefs(parentDoc));
|
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
|
|
|
|
2002-04-17 04:17:16 +00:00
|
|
|
nsCOMPtr<nsIPresShell> pPresShell;
|
|
|
|
parentDoc->GetShellAt(0, getter_AddRefs(pPresShell));
|
|
|
|
NS_ENSURE_TRUE(pPresShell, 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 */
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIContent> frameContent;
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
parentDoc->FindContentForSubDocument(doc, getter_AddRefs(frameContent));
|
|
|
|
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
|
|
|
|
because they are not used by DoWheelScroll().
|
|
|
|
*/
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2001-09-07 21:00:57 +00:00
|
|
|
nsIFrame* frameFrame = nsnull;
|
|
|
|
pPresShell->GetPrimaryFrameFor(frameContent, &frameFrame);
|
|
|
|
if (!frameFrame) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
pPresShell->GetPresContext(&presCtxOuter); //addrefs
|
|
|
|
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
|
2001-02-15 05:07:46 +00:00
|
|
|
nsEventStateManager::PostHandleEvent(nsIPresContext* 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);
|
1998-11-24 07:46:58 +00:00
|
|
|
mCurrentTarget = aTargetFrame;
|
2002-12-17 02:10:57 +00:00
|
|
|
mCurrentTargetContent = nsnull;
|
1998-11-24 07:46:58 +00:00
|
|
|
nsresult ret = NS_OK;
|
|
|
|
|
2000-05-05 14:43:20 +00:00
|
|
|
NS_ASSERTION(mCurrentTarget, "mCurrentTarget is null");
|
|
|
|
if (!mCurrentTarget) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
nsFrameState state;
|
1999-02-10 04:17:06 +00:00
|
|
|
mCurrentTarget->GetFrameState(&state);
|
1998-11-24 07:46:58 +00:00
|
|
|
state |= NS_FRAME_EXTERNAL_REFERENCE;
|
|
|
|
mCurrentTarget->SetFrameState(state);
|
|
|
|
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
1999-01-28 23:14:36 +00:00
|
|
|
case NS_MOUSE_RIGHT_BUTTON_DOWN:
|
|
|
|
{
|
2002-02-20 07:22:55 +00:00
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN && !mNormalLMouseEventInProcess) {
|
|
|
|
//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
|
|
|
|
nsCOMPtr<nsIViewManager> viewMan;
|
|
|
|
if (aView) {
|
|
|
|
aView->GetViewManager(*getter_AddRefs(viewMan));
|
|
|
|
if (viewMan) {
|
|
|
|
nsIView* grabbingView;
|
|
|
|
viewMan->GetMouseEventGrabber(grabbingView);
|
|
|
|
if (grabbingView == aView) {
|
|
|
|
PRBool result;
|
|
|
|
viewMan->GrabMouseEvents(nsnull, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-12-18 04:02:28 +00:00
|
|
|
if (mConsumeFocusEvents) {
|
|
|
|
mConsumeFocusEvents = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
const nsStyleUserInterface* ui;
|
2000-08-08 23:48:42 +00:00
|
|
|
mCurrentTarget->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));
|
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;
|
2000-09-19 01:24:44 +00:00
|
|
|
nsCOMPtr<nsIContent> activeContent;
|
|
|
|
if (mCurrentTarget)
|
|
|
|
mCurrentTarget->GetContent(getter_AddRefs(activeContent));
|
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
// Look for the nearest enclosing focusable frame.
|
|
|
|
while (currFrame) {
|
|
|
|
const nsStyleUserInterface* ui;
|
2000-08-08 23:48:42 +00:00
|
|
|
currFrame->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));
|
2000-04-04 23:55:31 +00:00
|
|
|
if ((ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE) &&
|
|
|
|
(ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE)) {
|
|
|
|
currFrame->GetContent(getter_AddRefs(newFocus));
|
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
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
currFrame->GetParent(&currFrame);
|
|
|
|
}
|
1999-09-30 11:40:42 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
if (newFocus && currFrame)
|
2002-03-31 04:53:53 +00:00
|
|
|
ChangeFocus(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.
|
|
|
|
if (aEvent->message != NS_MOUSE_LEFT_BUTTON_DOWN)
|
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsIContent> par;
|
|
|
|
activeContent->GetParent(*getter_AddRefs(par));
|
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.
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
}
|
1999-01-08 21:13:59 +00:00
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
break;
|
1998-11-24 07:46:58 +00:00
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
|
|
|
case NS_MOUSE_RIGHT_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;
|
|
|
|
}
|
2001-04-05 19:53:13 +00:00
|
|
|
ret = CheckForAndDispatchClick(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
1999-05-07 21:12:59 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
1999-11-24 06:03:41 +00:00
|
|
|
nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));
|
1999-05-07 21:12:59 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && shell){
|
1999-07-18 02:27:19 +00:00
|
|
|
nsCOMPtr<nsIFrameSelection> frameSel;
|
|
|
|
rv = shell->GetFrameSelection(getter_AddRefs(frameSel));
|
|
|
|
if (NS_SUCCEEDED(rv) && frameSel){
|
1999-05-07 21:12:59 +00:00
|
|
|
frameSel->SetMouseDownState(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
nsresult rv;
|
2002-11-25 23:26:06 +00:00
|
|
|
rv = getPrefBranch();
|
2000-03-15 04:03:44 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
nsMouseScrollEvent *msEvent = (nsMouseScrollEvent*) aEvent;
|
|
|
|
PRInt32 action = 0;
|
|
|
|
PRInt32 numLines = 0;
|
2000-11-02 05:15:34 +00:00
|
|
|
PRBool aBool;
|
2000-01-06 06:22:00 +00:00
|
|
|
if (msEvent->isShift) {
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetIntPref("mousewheel.withshiftkey.action", &action);
|
|
|
|
mPrefBranch->GetBoolPref("mousewheel.withshiftkey.sysnumlines",
|
|
|
|
&aBool);
|
2000-11-02 05:15:34 +00:00
|
|
|
if (aBool) {
|
|
|
|
numLines = msEvent->delta;
|
2000-11-13 18:16:43 +00:00
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)
|
2000-11-02 05:15:34 +00:00
|
|
|
action = MOUSE_SCROLL_PAGE;
|
|
|
|
}
|
2000-01-06 06:22:00 +00:00
|
|
|
else
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetIntPref("mousewheel.withshiftkey.numlines",
|
|
|
|
&numLines);
|
2000-01-06 06:22:00 +00:00
|
|
|
} else if (msEvent->isControl) {
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetIntPref("mousewheel.withcontrolkey.action", &action);
|
|
|
|
mPrefBranch->GetBoolPref("mousewheel.withcontrolkey.sysnumlines",
|
|
|
|
&aBool);
|
2000-11-02 05:15:34 +00:00
|
|
|
if (aBool) {
|
|
|
|
numLines = msEvent->delta;
|
2000-11-13 18:16:43 +00:00
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)
|
2000-11-02 05:15:34 +00:00
|
|
|
action = MOUSE_SCROLL_PAGE;
|
|
|
|
}
|
2000-01-06 06:22:00 +00:00
|
|
|
else
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetIntPref("mousewheel.withcontrolkey.numlines",
|
|
|
|
&numLines);
|
2000-01-06 06:22:00 +00:00
|
|
|
} else if (msEvent->isAlt) {
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetIntPref("mousewheel.withaltkey.action", &action);
|
|
|
|
mPrefBranch->GetBoolPref("mousewheel.withaltkey.sysnumlines", &aBool);
|
2000-11-02 05:15:34 +00:00
|
|
|
if (aBool) {
|
|
|
|
numLines = msEvent->delta;
|
2000-11-13 18:16:43 +00:00
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)
|
2000-11-02 05:15:34 +00:00
|
|
|
action = MOUSE_SCROLL_PAGE;
|
|
|
|
}
|
2000-01-06 06:22:00 +00:00
|
|
|
else
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetIntPref("mousewheel.withaltkey.numlines",
|
|
|
|
&numLines);
|
2000-01-06 06:22:00 +00:00
|
|
|
} else {
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetIntPref("mousewheel.withnokey.action", &action);
|
|
|
|
mPrefBranch->GetBoolPref("mousewheel.withnokey.sysnumlines", &aBool);
|
2000-11-02 05:15:34 +00:00
|
|
|
if (aBool) {
|
|
|
|
numLines = msEvent->delta;
|
2000-11-13 18:16:43 +00:00
|
|
|
if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage)
|
2000-11-02 05:15:34 +00:00
|
|
|
action = MOUSE_SCROLL_PAGE;
|
|
|
|
}
|
2000-01-06 06:22:00 +00:00
|
|
|
else
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetIntPref("mousewheel.withnokey.numlines", &numLines);
|
2000-01-06 06:22:00 +00:00
|
|
|
}
|
1999-11-21 01:46:41 +00:00
|
|
|
|
2000-11-02 05:15:34 +00:00
|
|
|
if ((msEvent->delta < 0) && (numLines > 0))
|
2000-01-06 06:22:00 +00:00
|
|
|
numLines = -numLines;
|
1999-11-21 01:46:41 +00:00
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
switch (action) {
|
|
|
|
case MOUSE_SCROLL_N_LINES:
|
2000-05-15 02:10:11 +00:00
|
|
|
case MOUSE_SCROLL_PAGE:
|
2000-01-06 06:22:00 +00:00
|
|
|
{
|
2001-02-19 12:55:42 +00:00
|
|
|
DoWheelScroll(aPresContext, aTargetFrame, msEvent, numLines,
|
|
|
|
(action == MOUSE_SCROLL_PAGE), PR_FALSE);
|
2000-06-28 20:35:32 +00:00
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
}
|
2000-04-01 20:09:54 +00:00
|
|
|
|
2000-01-16 05:30:49 +00:00
|
|
|
break;
|
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
case MOUSE_SCROLL_HISTORY:
|
|
|
|
{
|
2000-03-12 01:19:39 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
mPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
if (pcContainer) {
|
2000-04-16 06:14:38 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(pcContainer));
|
|
|
|
if (webNav) {
|
2000-11-02 05:15:34 +00:00
|
|
|
if (msEvent->delta > 0)
|
2000-04-16 06:14:38 +00:00
|
|
|
webNav->GoBack();
|
|
|
|
else
|
|
|
|
webNav->GoForward();
|
2000-03-12 01:19:39 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
// Exclude form controls and XUL content.
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
aTargetFrame->GetContent(getter_AddRefs(content));
|
|
|
|
if (content &&
|
|
|
|
!content->IsContentOfType(nsIContent::eHTML_FORM_CONTROL) &&
|
|
|
|
!content->IsContentOfType(nsIContent::eXUL))
|
|
|
|
{
|
|
|
|
ChangeTextSize((msEvent->delta > 0) ? 1 : -1);
|
|
|
|
}
|
|
|
|
}
|
2000-04-25 06:25:43 +00:00
|
|
|
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:
|
|
|
|
case NS_DRAGDROP_EXIT:
|
|
|
|
// clean up after ourselves. make sure we do this _after_ the event, else we'll
|
|
|
|
// clean up too early!
|
2000-04-24 04:41:27 +00:00
|
|
|
GenerateDragDropEnterExit(aPresContext, (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 (mConsumeFocusEvents) {
|
|
|
|
mConsumeFocusEvents = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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-12-21 19:35:13 +00:00
|
|
|
if (mConsumeFocusEvents) {
|
|
|
|
mConsumeFocusEvents = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
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) {
|
|
|
|
nsIScrollableView* sv = GetNearestScrollingView(aView);
|
|
|
|
if (sv) {
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
sv->ScrollByPages((keyEvent->keyCode != NS_VK_PAGE_UP) ? 1 : -1);
|
|
|
|
}
|
1999-09-21 14:18:52 +00:00
|
|
|
}
|
1999-11-22 19:45:13 +00:00
|
|
|
break;
|
|
|
|
case NS_VK_HOME:
|
|
|
|
case NS_VK_END:
|
|
|
|
if (!mCurrentFocus) {
|
|
|
|
nsIScrollableView* sv = GetNearestScrollingView(aView);
|
|
|
|
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;
|
|
|
|
case NS_VK_DOWN:
|
|
|
|
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) {
|
|
|
|
nsIScrollableView* sv = GetNearestScrollingView(aView);
|
|
|
|
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);
|
|
|
|
|
|
|
|
// force the update to happen now, otherwise multiple scrolls can
|
|
|
|
// occur before the update is processed. (bug #7354)
|
|
|
|
nsIViewManager* vm = nsnull;
|
2002-02-21 13:39:39 +00:00
|
|
|
if (NS_OK == aView->GetViewManager(vm) && nsnull != vm) {
|
|
|
|
// I'd use Composite here, but it doesn't always work.
|
2000-05-16 11:35:12 +00:00
|
|
|
// vm->Composite();
|
|
|
|
vm->ForceUpdate();
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_VK_LEFT:
|
|
|
|
case NS_VK_RIGHT:
|
|
|
|
if (!mCurrentFocus) {
|
|
|
|
nsIScrollableView* sv = GetNearestScrollingView(aView);
|
|
|
|
if (sv) {
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
sv->ScrollByLines((keyEvent->keyCode == NS_VK_RIGHT) ? 1 : -1, 0);
|
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)
|
|
|
|
nsIViewManager* vm = nsnull;
|
2002-02-21 13:39:39 +00:00
|
|
|
if (NS_OK == aView->GetViewManager(vm) && nsnull != vm) {
|
|
|
|
// 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
|
|
|
NS_RELEASE(vm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0: /* check charcode since keycode is 0 */
|
|
|
|
{
|
|
|
|
//Spacebar
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
if (keyEvent->charCode == 0x20) {
|
|
|
|
if (!mCurrentFocus) {
|
|
|
|
nsIScrollableView* sv = GetNearestScrollingView(aView);
|
|
|
|
if (sv) {
|
|
|
|
sv->ScrollByPages(1);
|
|
|
|
}
|
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;
|
2001-01-06 05:58:47 +00:00
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent,
|
|
|
|
getter_AddRefs(targetContent));
|
|
|
|
SetContentState(targetContent, NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-12-06 03:41:43 +00:00
|
|
|
//
|
|
|
|
// OS custom application event, such as from MS IntelliMouse
|
|
|
|
//
|
|
|
|
case NS_APPCOMMAND:
|
|
|
|
// by default, tell the driver we're not handling the event
|
|
|
|
ret = PR_FALSE;
|
|
|
|
|
|
|
|
nsAppCommandEvent* appCommandEvent = (nsAppCommandEvent*) aEvent;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
switch (appCommandEvent->appCommand) {
|
|
|
|
case NS_APPCOMMAND_BACK:
|
|
|
|
case NS_APPCOMMAND_FORWARD:
|
|
|
|
case NS_APPCOMMAND_REFRESH:
|
|
|
|
case NS_APPCOMMAND_STOP:
|
|
|
|
// handle these commands using nsIWebNavigation
|
|
|
|
mPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
if (pcContainer) {
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(pcContainer));
|
|
|
|
if (webNav) {
|
|
|
|
// tell the driver we're handling the event
|
|
|
|
ret = PR_TRUE;
|
|
|
|
|
|
|
|
switch (appCommandEvent->appCommand) {
|
|
|
|
case NS_APPCOMMAND_BACK:
|
|
|
|
webNav->GoBack();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_APPCOMMAND_FORWARD:
|
|
|
|
webNav->GoForward();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_APPCOMMAND_REFRESH:
|
|
|
|
webNav->Reload(nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_APPCOMMAND_STOP:
|
|
|
|
webNav->Stop(nsIWebNavigation::STOP_ALL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
} // switch (appCommandEvent->appCommand)
|
|
|
|
} // if (webNav)
|
|
|
|
} // if (pcContainer)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// XXX todo: handle these commands
|
|
|
|
// case NS_APPCOMMAND_SEARCH:
|
|
|
|
// case NS_APPCOMMAND_FAVORITES:
|
|
|
|
// case NS_APPCOMMAND_HOME:
|
|
|
|
|
|
|
|
// tell the driver we're handling the event
|
|
|
|
// ret = PR_TRUE;
|
|
|
|
// break;
|
|
|
|
|
|
|
|
} // switch (appCommandEvent->appCommand)
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::SetPresContext(nsIPresContext* aPresContext)
|
1998-06-23 21:53:02 +00:00
|
|
|
{
|
1999-12-08 20:18:16 +00:00
|
|
|
if (aPresContext == nsnull) {
|
|
|
|
// 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)
|
|
|
|
{
|
1999-11-02 03:55:14 +00:00
|
|
|
if (aFrame == mLastMouseOverFrame)
|
1998-11-19 00:43:36 +00:00
|
|
|
mLastMouseOverFrame = nsnull;
|
1999-11-02 03:55:14 +00:00
|
|
|
if (aFrame == mLastDragOverFrame)
|
|
|
|
mLastDragOverFrame = nsnull;
|
2001-03-30 04:45:40 +00:00
|
|
|
if (aFrame == mGestureDownFrame) {
|
1999-11-02 03:55:14 +00:00
|
|
|
mGestureDownFrame = nsnull;
|
2001-03-30 04:45:40 +00:00
|
|
|
#if CLICK_HOLD_CONTEXT_MENUS
|
|
|
|
mEventDownWidget = nsnull;
|
|
|
|
mEventPresContext = nsnull;
|
|
|
|
#endif
|
|
|
|
}
|
1998-11-24 07:46:58 +00:00
|
|
|
if (aFrame == mCurrentTarget) {
|
1999-06-15 03:14:28 +00:00
|
|
|
if (aFrame) {
|
2002-12-17 02:10:57 +00:00
|
|
|
aFrame->GetContent(getter_AddRefs(mCurrentTargetContent));
|
1999-06-15 03:14:28 +00:00
|
|
|
}
|
1998-11-19 00:43:36 +00:00
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
}
|
2002-12-24 20:21:40 +00:00
|
|
|
if (mDOMEventLevel > 0) {
|
|
|
|
mClearedFrameRefsDuringEvent = PR_TRUE;
|
|
|
|
}
|
2001-03-30 04:45:40 +00:00
|
|
|
|
|
|
|
|
1998-11-19 00:43:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-30 19:38:39 +00:00
|
|
|
nsIScrollableView*
|
|
|
|
nsEventStateManager::GetNearestScrollingView(nsIView* aView)
|
|
|
|
{
|
2002-12-11 14:24:49 +00:00
|
|
|
nsIScrollableView* sv = nsnull;
|
|
|
|
CallQueryInterface(aView, &sv);
|
|
|
|
if (sv) {
|
1999-04-30 19:38:39 +00:00
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* parent;
|
|
|
|
aView->GetParent(parent);
|
|
|
|
|
2002-12-11 14:24:49 +00:00
|
|
|
if (parent) {
|
1999-04-30 19:38:39 +00:00
|
|
|
return GetNearestScrollingView(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1999-12-04 02:22:21 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::CheckDisabled(nsIContent* aContent)
|
|
|
|
{
|
2000-01-12 06:54:58 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
1999-12-04 02:22:21 +00:00
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
if (tag == nsHTMLAtoms::input ||
|
|
|
|
tag == nsHTMLAtoms::select ||
|
|
|
|
tag == nsHTMLAtoms::textarea ||
|
|
|
|
tag == nsHTMLAtoms::button) {
|
|
|
|
return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::disabled);
|
1999-12-04 02:22:21 +00:00
|
|
|
}
|
|
|
|
|
2002-05-20 22:47:02 +00:00
|
|
|
return PR_FALSE;
|
1999-12-04 02:22:21 +00:00
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
void
|
2002-05-20 22:47:02 +00:00
|
|
|
nsEventStateManager::UpdateCursor(nsIPresContext* aPresContext,
|
|
|
|
nsEvent* aEvent, nsIFrame* aTargetFrame,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aStatus)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
1998-11-18 05:25:26 +00:00
|
|
|
PRInt32 cursor;
|
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
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
mCurrentTarget->GetContent(getter_AddRefs(targetContent));
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
//Check if the current target is disabled. If so use the default pointer.
|
|
|
|
if (targetContent && CheckDisabled(targetContent)) {
|
|
|
|
cursor = NS_STYLE_CURSOR_DEFAULT;
|
|
|
|
}
|
|
|
|
//If not disabled, check for the right cursor.
|
|
|
|
else {
|
|
|
|
if (aTargetFrame) {
|
2002-01-26 00:39:43 +00:00
|
|
|
if (NS_FAILED(aTargetFrame->GetCursor(aPresContext, aEvent->point, cursor)))
|
|
|
|
return; // don't update the cursor if we failed to get it from the frame see bug 118877
|
2000-04-24 04:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
aPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
if (aTargetFrame) {
|
|
|
|
nsCOMPtr<nsIWidget> window;
|
|
|
|
aTargetFrame->GetWindow(aPresContext, getter_AddRefs(window));
|
|
|
|
SetCursor(cursor, window, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
nsEventStateManager::SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor)
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
case NS_STYLE_CURSOR_S_RESIZE:
|
|
|
|
c = eCursor_sizeNS;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_W_RESIZE:
|
|
|
|
case NS_STYLE_CURSOR_E_RESIZE:
|
|
|
|
c = eCursor_sizeWE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NW_RESIZE:
|
2000-04-30 15:29:32 +00:00
|
|
|
c = eCursor_sizeNW;
|
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_SE_RESIZE:
|
2000-04-30 15:29:32 +00:00
|
|
|
c = eCursor_sizeSE;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_NE_RESIZE:
|
|
|
|
c = eCursor_sizeNE;
|
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_SW_RESIZE:
|
2000-04-30 15:29:32 +00:00
|
|
|
c = eCursor_sizeSW;
|
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;
|
|
|
|
case NS_STYLE_CURSOR_COUNT_UP:
|
|
|
|
c = eCursor_count_up;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_COUNT_DOWN:
|
|
|
|
c = eCursor_count_down;
|
|
|
|
break;
|
|
|
|
case NS_STYLE_CURSOR_COUNT_UP_DOWN:
|
|
|
|
c = eCursor_count_up_down;
|
|
|
|
break;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
1998-12-03 03:07:16 +00:00
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2002-12-24 20:21:40 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::AfterDispatchEvent()
|
|
|
|
{
|
|
|
|
mDOMEventLevel--;
|
|
|
|
if (mClearedFrameRefsDuringEvent && mDOMEventLevel == 0) {
|
|
|
|
mClearedFrameRefsDuringEvent = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::DispatchMouseEvent(nsIPresContext* aPresContext,
|
|
|
|
nsGUIEvent* aEvent, PRUint32 aMessage,
|
|
|
|
nsIContent* aTargetContent,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsIContent* aRelatedContent)
|
|
|
|
{
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
|
|
|
event.message = aMessage;
|
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
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;
|
|
|
|
|
|
|
|
mCurrentTargetContent = aTargetContent;
|
|
|
|
mCurrentRelatedContent = aRelatedContent;
|
|
|
|
|
2002-12-24 20:21:40 +00:00
|
|
|
mDOMEventLevel++;
|
|
|
|
BeforeDispatchEvent();
|
2002-12-18 07:13:51 +00:00
|
|
|
nsIFrame* targetFrame = aTargetFrame;
|
2002-12-17 02:10:57 +00:00
|
|
|
if (aTargetContent) {
|
|
|
|
aTargetContent->HandleDOMEvent(aPresContext, &event, nsnull,
|
|
|
|
NS_EVENT_FLAG_INIT, &status);
|
2002-12-24 20:21:40 +00:00
|
|
|
// If frame refs were cleared, we need to re-resolve the frame
|
|
|
|
if (mClearedFrameRefsDuringEvent) {
|
2002-12-18 07:13:51 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
shell->GetPrimaryFrameFor(aTargetContent, &targetFrame);
|
|
|
|
}
|
2002-12-17 02:10:57 +00:00
|
|
|
}
|
2002-12-18 07:13:51 +00:00
|
|
|
if (targetFrame) {
|
|
|
|
targetFrame->HandleEvent(aPresContext, &event, &status);
|
2002-12-17 02:10:57 +00:00
|
|
|
}
|
2002-12-24 20:21:40 +00:00
|
|
|
AfterDispatchEvent();
|
2002-12-17 02:10:57 +00:00
|
|
|
|
|
|
|
mCurrentTargetContent = nsnull;
|
|
|
|
mCurrentRelatedContent = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsEventStateManager::MaybeDispatchMouseEventToIframe(
|
|
|
|
nsIPresContext* aPresContext, nsGUIEvent* aEvent, PRUint32 aMessage)
|
|
|
|
{
|
|
|
|
// Check to see if we're an IFRAME and if so dispatch the given event
|
|
|
|
// (mouseover / mouseout) to the IFRAME element above us. This will result
|
|
|
|
// in over-out-over combo to the IFRAME but as long as IFRAMEs are native
|
|
|
|
// windows this will serve as a workaround to maintain IFRAME mouseover state.
|
|
|
|
nsCOMPtr<nsIDocument> parentDoc;
|
|
|
|
// If this is the first event in this window then mDocument might not be set
|
|
|
|
// yet. Call EnsureDocument to set it.
|
|
|
|
EnsureDocument(aPresContext);
|
|
|
|
mDocument->GetParentDocument(getter_AddRefs(parentDoc));
|
|
|
|
if (parentDoc) {
|
|
|
|
nsCOMPtr<nsIContent> docContent;
|
|
|
|
parentDoc->FindContentForSubDocument(mDocument, getter_AddRefs(docContent));
|
|
|
|
if (docContent) {
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
docContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (tag == nsHTMLAtoms::iframe) {
|
|
|
|
// We're an IFRAME. Send an event to our IFRAME tag.
|
|
|
|
nsCOMPtr<nsIPresShell> parentShell;
|
|
|
|
parentDoc->GetShellAt(0, getter_AddRefs(parentShell));
|
|
|
|
if (parentShell) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
|
|
|
event.message = aMessage;
|
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
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;
|
|
|
|
|
|
|
|
parentShell->HandleDOMEventWithTarget(docContent, &event, &status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
void
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStateManager::GenerateMouseEnterExit(nsIPresContext* aPresContext, nsGUIEvent* aEvent)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
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:
|
|
|
|
{
|
2002-12-17 02:10:57 +00:00
|
|
|
// Optimization if we're over the same frame as before
|
|
|
|
if (mCurrentTarget == mLastMouseOverFrame) {
|
|
|
|
break;
|
2000-02-11 01:24:59 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Check whether we are over the same element as before
|
|
|
|
nsCOMPtr<nsIContent> targetElement;
|
|
|
|
nsIFrame* targetFrame;
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent,
|
|
|
|
getter_AddRefs(targetElement));
|
|
|
|
targetFrame = mCurrentTarget;
|
|
|
|
}
|
2000-02-16 03:52:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
if (mLastMouseOverElement == targetElement) {
|
|
|
|
break;
|
|
|
|
}
|
2000-02-16 03:52:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Before firing mouseout, check for recursion
|
|
|
|
// XXX is it wise to fire mouseover / mouseout when the target is null?
|
|
|
|
if (mLastMouseOverElement != mFirstMouseOutEventElement ||
|
|
|
|
!mFirstMouseOutEventElement) {
|
|
|
|
|
|
|
|
// Store the first mouseOut event we fire and don't refire mouseOut
|
|
|
|
// to that element while the first mouseOut is still ongoing.
|
|
|
|
mFirstMouseOutEventElement = mLastMouseOverElement;
|
2000-02-16 03:52:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
if (mLastMouseOverFrame) {
|
|
|
|
DispatchMouseEvent(aPresContext, aEvent, NS_MOUSE_EXIT_SYNTH,
|
|
|
|
mLastMouseOverElement, mLastMouseOverFrame,
|
|
|
|
targetElement);
|
2000-02-16 03:52:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Turn off recursion protection
|
|
|
|
mFirstMouseOutEventElement = nsnull;
|
2000-02-16 03:52:45 +00:00
|
|
|
}
|
2002-12-17 02:10:57 +00:00
|
|
|
else {
|
|
|
|
// If there is no previous frame, we are entering this widget
|
|
|
|
MaybeDispatchMouseEventToIframe(aPresContext, aEvent,
|
|
|
|
NS_MOUSE_ENTER_SYNTH);
|
|
|
|
}
|
|
|
|
}
|
2000-02-16 03:52:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Before firing mouseover, check for recursion
|
|
|
|
if (targetElement != mFirstMouseOverEventElement) {
|
|
|
|
|
|
|
|
// If we actually went and got a parent element, we need to fetch its
|
|
|
|
// frame so we can send it events
|
|
|
|
if (!targetFrame) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
shell->GetPrimaryFrameFor(targetElement, &targetFrame);
|
|
|
|
}
|
2000-02-16 03:52:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +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 = targetElement;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
if (targetElement) {
|
|
|
|
SetContentState(targetElement, NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Fire mouseover
|
|
|
|
DispatchMouseEvent(aPresContext, aEvent, NS_MOUSE_ENTER_SYNTH,
|
|
|
|
targetElement, targetFrame,
|
|
|
|
mLastMouseOverElement);
|
1999-11-03 07:11:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
mLastMouseOverFrame = targetFrame;
|
|
|
|
mLastMouseOverElement = targetElement;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Turn recursion protection back off
|
|
|
|
mFirstMouseOverEventElement = nsnull;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_EXIT:
|
|
|
|
{
|
2002-12-17 02:10:57 +00:00
|
|
|
// This is actually the window mouse exit event.
|
|
|
|
if (mLastMouseOverFrame) {
|
|
|
|
// Before firing mouseout, check for recursion
|
|
|
|
if (mLastMouseOverElement != mFirstMouseOutEventElement) {
|
2000-02-16 03:52:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Store the first mouseOut event we fire and don't refire mouseOut
|
|
|
|
// to that element while the first mouseOut is still ongoing.
|
|
|
|
mFirstMouseOutEventElement = mLastMouseOverElement;
|
1999-06-22 14:20:14 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Unset :hover
|
|
|
|
if (mLastMouseOverElement) {
|
2002-04-11 03:49:30 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_HOVER);
|
1999-06-22 14:20:14 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Fire mouseout
|
|
|
|
DispatchMouseEvent(aPresContext, aEvent, NS_MOUSE_EXIT_SYNTH,
|
|
|
|
mLastMouseOverElement, mLastMouseOverFrame,
|
|
|
|
nsnull);
|
1999-11-03 07:11:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// XXX Get the new frame
|
|
|
|
mLastMouseOverFrame = nsnull;
|
|
|
|
mLastMouseOverElement = nsnull;
|
2000-02-16 03:52:45 +00:00
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
// Turn recursion protection back off
|
|
|
|
mFirstMouseOutEventElement = nsnull;
|
2002-06-14 04:14:55 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-17 02:10:57 +00:00
|
|
|
|
|
|
|
// If we are over an iframe and got this event, fire mouseout at the
|
|
|
|
// iframe's content
|
|
|
|
MaybeDispatchMouseEventToIframe(aPresContext, aEvent,
|
|
|
|
NS_MOUSE_EXIT_SYNTH);
|
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
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStateManager::GenerateDragDropEnterExit(nsIPresContext* aPresContext, 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 ) {
|
|
|
|
//fire drag exit
|
1999-05-04 14:44:51 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_DRAGDROP_EVENT;
|
2000-04-24 04:41:27 +00:00
|
|
|
event.message = NS_DRAGDROP_EXIT_SYNTH;
|
1999-07-01 04:12:42 +00:00
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
1999-12-09 21:02:09 +00:00
|
|
|
event.isShift = ((nsMouseEvent*)aEvent)->isShift;
|
|
|
|
event.isControl = ((nsMouseEvent*)aEvent)->isControl;
|
|
|
|
event.isAlt = ((nsMouseEvent*)aEvent)->isAlt;
|
|
|
|
event.isMeta = ((nsMouseEvent*)aEvent)->isMeta;
|
1999-05-04 14:44:51 +00:00
|
|
|
|
|
|
|
//The frame has change 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
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
mCurrentTargetContent = lastContent;
|
|
|
|
mCurrentRelatedContent = targetContent;
|
|
|
|
|
1999-11-02 03:55:14 +00:00
|
|
|
if ( lastContent != targetContent ) {
|
1999-05-04 14:44:51 +00:00
|
|
|
//XXX This event should still go somewhere!!
|
1999-09-09 00:28:23 +00:00
|
|
|
if (lastContent)
|
1999-11-24 06:03:41 +00:00
|
|
|
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
1999-05-04 14:44:51 +00:00
|
|
|
|
1999-11-02 03:55:14 +00:00
|
|
|
// clear the drag hover
|
|
|
|
if (status != nsEventStatus_eConsumeNoDefault )
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_DRAGOVER);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
1999-11-02 03:55:14 +00:00
|
|
|
|
|
|
|
// Finally dispatch exit to the frame
|
1999-11-03 07:11:45 +00:00
|
|
|
if ( mLastDragOverFrame ) {
|
1999-11-24 06:03:41 +00:00
|
|
|
mLastDragOverFrame->HandleEvent(aPresContext, &event, &status);
|
1999-11-03 07:11:45 +00:00
|
|
|
|
|
|
|
}
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
1999-09-09 00:28:23 +00:00
|
|
|
//fire drag enter
|
1999-05-04 14:44:51 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_DRAGDROP_EVENT;
|
|
|
|
event.message = NS_DRAGDROP_ENTER;
|
1999-07-01 04:12:42 +00:00
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
1999-12-09 21:02:09 +00:00
|
|
|
event.isShift = ((nsMouseEvent*)aEvent)->isShift;
|
|
|
|
event.isControl = ((nsMouseEvent*)aEvent)->isControl;
|
|
|
|
event.isAlt = ((nsMouseEvent*)aEvent)->isAlt;
|
|
|
|
event.isMeta = ((nsMouseEvent*)aEvent)->isMeta;
|
1999-05-04 14:44:51 +00:00
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
mCurrentTargetContent = targetContent;
|
|
|
|
mCurrentRelatedContent = lastContent;
|
|
|
|
|
1999-05-04 14:44:51 +00:00
|
|
|
//The frame has change but the content may not have. Check before dispatching to content
|
1999-11-02 03:55:14 +00:00
|
|
|
if ( lastContent != targetContent ) {
|
1999-05-04 14:44:51 +00:00
|
|
|
//XXX This event should still go somewhere!!
|
1999-09-09 00:28:23 +00:00
|
|
|
if ( targetContent )
|
1999-11-24 06:03:41 +00:00
|
|
|
targetContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
1999-05-04 14:44:51 +00:00
|
|
|
|
1999-11-02 03:55:14 +00:00
|
|
|
// set drag hover on this frame
|
|
|
|
if ( status != nsEventStatus_eConsumeNoDefault )
|
1999-05-04 14:44:51 +00:00
|
|
|
SetContentState(targetContent, NS_EVENT_STATE_DRAGOVER);
|
|
|
|
}
|
|
|
|
|
1999-11-02 03:55:14 +00:00
|
|
|
// Finally dispatch to the frame
|
1999-09-09 00:28:23 +00:00
|
|
|
if (mCurrentTarget) {
|
1999-05-04 14:44:51 +00:00
|
|
|
//XXX Get the new frame
|
1999-11-24 06:03:41 +00:00
|
|
|
mCurrentTarget->HandleEvent(aPresContext, &event, &status);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mLastDragOverFrame = mCurrentTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-11-02 03:55:14 +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 ) {
|
|
|
|
|
|
|
|
// fire mouseout
|
1999-05-04 14:44:51 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_DRAGDROP_EVENT;
|
2000-04-24 04:41:27 +00:00
|
|
|
event.message = NS_DRAGDROP_EXIT_SYNTH;
|
1999-07-01 04:12:42 +00:00
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
1999-12-09 21:02:09 +00:00
|
|
|
event.isShift = ((nsMouseEvent*)aEvent)->isShift;
|
|
|
|
event.isControl = ((nsMouseEvent*)aEvent)->isControl;
|
|
|
|
event.isAlt = ((nsMouseEvent*)aEvent)->isAlt;
|
|
|
|
event.isMeta = ((nsMouseEvent*)aEvent)->isMeta;
|
1999-05-04 14:44:51 +00:00
|
|
|
|
1999-11-02 03:55:14 +00:00
|
|
|
// dispatch to content via DOM
|
|
|
|
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
|
|
|
|
|
|
|
mCurrentTargetContent = lastContent;
|
|
|
|
mCurrentRelatedContent = nsnull;
|
|
|
|
|
1999-11-02 03:55:14 +00:00
|
|
|
if ( lastContent ) {
|
1999-11-24 06:03:41 +00:00
|
|
|
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
1999-11-02 03:55:14 +00:00
|
|
|
if ( status != nsEventStatus_eConsumeNoDefault )
|
1999-06-22 14:20:14 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_DRAGOVER);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
1999-11-02 03:55:14 +00:00
|
|
|
// Finally dispatch to the frame
|
|
|
|
if ( mLastDragOverFrame ) {
|
1999-05-04 14:44:51 +00:00
|
|
|
//XXX Get the new frame
|
1999-11-24 06:03:41 +00:00
|
|
|
mLastDragOverFrame->HandleEvent(aPresContext, &event, &status);
|
1999-06-22 14:20:14 +00:00
|
|
|
mLastDragOverFrame = nsnull;
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
// Now flush all pending notifications.
|
2001-01-20 04:59:39 +00:00
|
|
|
FlushPendingEvents(aPresContext);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsresult
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStateManager::SetClickCount(nsIPresContext* 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-03-11 05:56:11 +00:00
|
|
|
nsresult ret = NS_OK;
|
1999-09-16 14:54:59 +00:00
|
|
|
nsCOMPtr<nsIContent> mouseContent;
|
1998-11-24 07:46:58 +00:00
|
|
|
|
2000-02-11 01:24:59 +00:00
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(mouseContent));
|
1999-03-28 22:22:54 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
1999-03-28 22:22:54 +00:00
|
|
|
mLastLeftMouseDownContent = mouseContent;
|
1998-11-24 07:46:58 +00:00
|
|
|
break;
|
1999-09-16 14:54:59 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
2002-12-17 02:10:57 +00:00
|
|
|
if (mLastLeftMouseDownContent == mouseContent) {
|
1999-09-22 02:29:33 +00:00
|
|
|
aEvent->clickCount = mLClickCount;
|
|
|
|
mLClickCount = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aEvent->clickCount = 0;
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
2002-12-17 02:10:57 +00:00
|
|
|
mLastLeftMouseDownContent = nsnull;
|
1998-11-24 07:46:58 +00:00
|
|
|
break;
|
1999-09-16 14:54:59 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
1999-03-28 22:22:54 +00:00
|
|
|
mLastMiddleMouseDownContent = mouseContent;
|
1998-11-24 07:46:58 +00:00
|
|
|
break;
|
1999-09-16 14:54:59 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
2002-12-17 02:10:57 +00:00
|
|
|
if (mLastMiddleMouseDownContent == mouseContent) {
|
1999-09-22 02:29:33 +00:00
|
|
|
aEvent->clickCount = mMClickCount;
|
|
|
|
mMClickCount = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aEvent->clickCount = 0;
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
break;
|
1999-09-16 14:54:59 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
case NS_MOUSE_RIGHT_BUTTON_DOWN:
|
1999-03-28 22:22:54 +00:00
|
|
|
mLastRightMouseDownContent = mouseContent;
|
1998-11-24 07:46:58 +00:00
|
|
|
break;
|
1999-09-16 14:54:59 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
2002-12-17 02:10:57 +00:00
|
|
|
if (mLastRightMouseDownContent == mouseContent) {
|
1999-09-22 02:29:33 +00:00
|
|
|
aEvent->clickCount = mRClickCount;
|
|
|
|
mRClickCount = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aEvent->clickCount = 0;
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-09-22 02:29:33 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsresult
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStateManager::CheckForAndDispatchClick(nsIPresContext* 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;
|
|
|
|
nsMouseEvent event;
|
|
|
|
nsCOMPtr<nsIContent> mouseContent;
|
2001-11-07 06:29:29 +00:00
|
|
|
PRInt32 flags = NS_EVENT_FLAG_INIT;
|
1999-09-22 02:29:33 +00:00
|
|
|
|
2000-02-11 01:24:59 +00:00
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(mouseContent));
|
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) {
|
1998-11-24 07:46:58 +00:00
|
|
|
//fire click
|
1999-09-22 02:29:33 +00:00
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
event.message = NS_MOUSE_LEFT_CLICK;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
|
|
|
event.message = NS_MOUSE_MIDDLE_CLICK;
|
2001-11-07 06:29:29 +00:00
|
|
|
flags |= mLeftClickOnly ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE;
|
1999-09-22 02:29:33 +00:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
|
|
|
event.message = NS_MOUSE_RIGHT_CLICK;
|
2001-11-07 06:29:29 +00:00
|
|
|
flags |= mLeftClickOnly ? NS_EVENT_FLAG_NO_CONTENT_DISPATCH : NS_EVENT_FLAG_NONE;
|
1999-09-22 02:29:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
1999-06-09 07:38:26 +00:00
|
|
|
event.widget = aEvent->widget;
|
2002-03-08 19:42:44 +00:00
|
|
|
event.nativeMsg = nsnull;
|
2000-01-15 17:21:20 +00:00
|
|
|
event.point = aEvent->point;
|
|
|
|
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;
|
1998-11-24 07:46:58 +00:00
|
|
|
|
2000-04-24 04:41:27 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
2001-11-07 06:29:29 +00:00
|
|
|
ret = presShell->HandleEventWithTarget(&event, mCurrentTarget, mouseContent, flags, aStatus);
|
2000-08-08 20:32:09 +00:00
|
|
|
if (NS_SUCCEEDED(ret) && aEvent->clickCount == 2) {
|
|
|
|
nsMouseEvent event2;
|
|
|
|
//fire double click
|
|
|
|
switch (aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
event2.message = NS_MOUSE_LEFT_DOUBLECLICK;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
|
|
|
event2.message = NS_MOUSE_MIDDLE_DOUBLECLICK;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
|
|
|
event2.message = NS_MOUSE_RIGHT_DOUBLECLICK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
event2.eventStructType = NS_MOUSE_EVENT;
|
|
|
|
event2.widget = aEvent->widget;
|
2002-03-08 19:42:44 +00:00
|
|
|
event2.nativeMsg = nsnull;
|
2000-08-08 20:32:09 +00:00
|
|
|
event2.point = aEvent->point;
|
|
|
|
event2.refPoint = aEvent->refPoint;
|
|
|
|
event2.clickCount = aEvent->clickCount;
|
|
|
|
event2.isShift = aEvent->isShift;
|
|
|
|
event2.isControl = aEvent->isControl;
|
|
|
|
event2.isAlt = aEvent->isAlt;
|
|
|
|
event2.isMeta = aEvent->isMeta;
|
|
|
|
|
2001-11-07 06:29:29 +00:00
|
|
|
ret = presShell->HandleEventWithTarget(&event2, mCurrentTarget, mouseContent, flags, 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;
|
|
|
|
}
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
PRBool
|
2002-03-31 04:53:53 +00:00
|
|
|
nsEventStateManager::ChangeFocus(nsIContent* aFocusContent, PRInt32 aFocusedWith)
|
1999-03-02 19:19:24 +00:00
|
|
|
{
|
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)
|
|
|
|
if (sTextfieldSelectModel == eTextfieldSelect_auto &&
|
|
|
|
mCurrentFocus &&
|
|
|
|
mCurrentFocus->IsContentOfType(nsIContent::eHTML_FORM_CONTROL)) {
|
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> inputElement =
|
|
|
|
do_QueryInterface(mCurrentFocus);
|
|
|
|
if (inputElement) {
|
|
|
|
inputElement->Select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
|
2002-03-31 04:53:53 +00:00
|
|
|
mLastFocusedWith = aFocusedWith;
|
1999-03-02 19:19:24 +00:00
|
|
|
return PR_FALSE;
|
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
|
|
|
|
static void
|
|
|
|
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));
|
|
|
|
nsCOMPtr<nsIPresContext> presContext;
|
|
|
|
parentAsDocShell->GetPresContext(getter_AddRefs(presContext));
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
presShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
doc->GetScriptGlobalObject(getter_AddRefs(sgo));
|
|
|
|
nsCOMPtr<nsIDOMWindowInternal> domwin(do_QueryInterface(sgo));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
presShell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
if (vm) {
|
|
|
|
vm->GetWidget(getter_AddRefs(widget));
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
presContext->GetEventStateManager(getter_AddRefs(esm));
|
|
|
|
|
|
|
|
printf("DS %p Type %s Cnt %d Doc %p DW %p EM %p\n",
|
|
|
|
parentAsDocShell.get(),
|
|
|
|
type==nsIDocShellTreeItem::typeChrome?"Chrome":"Content",
|
|
|
|
childWebshellCount, doc.get(), domwin.get(), esm.get());
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
// 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
|
2002-02-01 05:14:44 +00:00
|
|
|
printf("[%p] ShiftFocus: aForward=%d, aStart=%p, mCurrentFocus=%p\n",
|
|
|
|
this, aForward, aStart, mCurrentFocus);
|
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
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
mDocument->GetRootContent(getter_AddRefs(rootContent));
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
mPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
NS_ASSERTION(pcContainer, "no container for presContext");
|
2002-04-17 04:17:16 +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<nsIDocShell> docShell(do_QueryInterface(pcContainer));
|
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
|
|
|
|
// or using find text to get to the link. Without ignoreTabIndex in those cases, pages that
|
|
|
|
// use tabindex would still enforce that order in those situations.
|
|
|
|
PRBool ignoreTabIndex = PR_FALSE;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
if (aStart) {
|
|
|
|
mCurrentFocus = aStart;
|
1998-11-18 05:25: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
|
|
|
TabIndexFrom(mCurrentFocus, &mCurrentTabIndex);
|
|
|
|
} else if (!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
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(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);
|
2002-03-21 02:37:48 +00:00
|
|
|
|
2002-03-31 04:53:53 +00:00
|
|
|
if (itemType != nsIDocShellTreeItem::typeChrome && mLastFocusedWith != eEventFocusedByMouse) {
|
2002-12-07 00:56:03 +00:00
|
|
|
// We're going to tab from the selection position
|
2002-03-21 02:37:48 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLAreaElement> areaElement(do_QueryInterface(mCurrentFocus));
|
|
|
|
if (!areaElement) {
|
|
|
|
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;
|
|
|
|
}
|
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 (!mCurrentFocus) // Get tabindex ready
|
|
|
|
if (aForward) {
|
|
|
|
if (docHasFocus && selectionFrame)
|
|
|
|
mCurrentTabIndex = 0;
|
|
|
|
else {
|
|
|
|
mCurrentFocus = rootContent;
|
|
|
|
mCurrentTabIndex = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!docHasFocus)
|
|
|
|
mCurrentTabIndex = 0;
|
|
|
|
else if (selectionFrame)
|
|
|
|
mCurrentTabIndex = 1; // will keep it from wrapping around to end
|
1998-11-18 05:25: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
|
|
|
if (selectionFrame)
|
|
|
|
curFocusFrame = selectionFrame;
|
|
|
|
else if (mCurrentFocus && !docHasFocus) // If selection is not found in doc, use mCurrentFocus
|
2001-10-22 22:43:52 +00:00
|
|
|
presShell->GetPrimaryFrameFor(mCurrentFocus, &curFocusFrame);
|
2001-06-22 07:25:28 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIContent> nextFocus;
|
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)
|
|
|
|
GetNextTabbableContent(rootContent, curFocusFrame, aForward, ignoreTabIndex,
|
|
|
|
getter_AddRefs(nextFocus));
|
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
|
|
|
|
// It will be set correctly when focus is changed via ChangeFocus()
|
|
|
|
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;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc, sub_doc;
|
|
|
|
nextFocus->GetDocument(*getter_AddRefs(doc));
|
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
doc->GetSubDocumentFor(nextFocus, getter_AddRefs(sub_doc));
|
|
|
|
|
|
|
|
if (sub_doc) {
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
sub_doc->GetContainer(getter_AddRefs(container));
|
|
|
|
|
|
|
|
sub_shell = do_QueryInterface(container);
|
2001-04-18 06:18:10 +00:00
|
|
|
}
|
2002-04-17 04:17:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sub_shell) {
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
|
|
|
|
|
|
|
nsIFrame* nextFocusFrame = nsnull;
|
|
|
|
presShell->GetPrimaryFrameFor(nextFocus, &nextFocusFrame);
|
|
|
|
presShell->ScrollFrameIntoView(nextFocusFrame,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE,
|
|
|
|
NS_PRESSHELL_SCROLL_ANYWHERE);
|
|
|
|
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
|
2001-10-22 22:43:52 +00:00
|
|
|
presShell->GetPrimaryFrameFor(nextFocus, &mCurrentTarget);
|
2002-07-22 21:36:36 +00:00
|
|
|
|
|
|
|
//This may be new frame that hasn't been through the ESM so we
|
|
|
|
//must set its NS_FRAME_EXTERNAL_REFERENCE bit.
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
nsFrameState state;
|
|
|
|
mCurrentTarget->GetFrameState(&state);
|
|
|
|
state |= NS_FRAME_EXTERNAL_REFERENCE;
|
|
|
|
mCurrentTarget->SetFrameState(state);
|
|
|
|
}
|
|
|
|
|
2002-03-31 04:53:53 +00:00
|
|
|
ChangeFocus(nextFocus, eEventFocusedByKey);
|
2000-02-11 01:56:01 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
mCurrentFocus = nextFocus;
|
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
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
if (docHasFocus)
|
|
|
|
docShell->SetCanvasHasFocus(PR_FALSE);
|
|
|
|
else
|
|
|
|
docShell->SetHasFocus(PR_TRUE);
|
|
|
|
}
|
2001-05-22 23:52:17 +00:00
|
|
|
} else {
|
2001-10-22 22:43:52 +00:00
|
|
|
|
|
|
|
// If we're going backwards past the first content,
|
|
|
|
// focus the document.
|
|
|
|
|
|
|
|
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
|
|
|
|
// We need to move the caret to the document root, so that we don't
|
|
|
|
// tab from the most recently focused element next time around
|
|
|
|
mCurrentFocus = rootContent;
|
|
|
|
MoveCaretToFocus();
|
|
|
|
mCurrentFocus = nsnull;
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
mCurrentFocus = rootContent;
|
|
|
|
mCurrentTabIndex = 0;
|
|
|
|
MoveCaretToFocus();
|
|
|
|
mCurrentFocus = nsnull;
|
|
|
|
|
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
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> docContent;
|
|
|
|
nsCOMPtr<nsIDocument> parent_doc;
|
|
|
|
|
|
|
|
parentShell->GetDocument(getter_AddRefs(parent_doc));
|
|
|
|
|
|
|
|
parent_doc->FindContentForSubDocument(mDocument,
|
|
|
|
getter_AddRefs(docContent));
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIPresContext> parentPC;
|
|
|
|
parentShell->GetPresContext(getter_AddRefs(parentPC));
|
2002-04-17 04:17:16 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> parentESM;
|
|
|
|
parentPC->GetEventStateManager(getter_AddRefs(parentESM));
|
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
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
#ifdef DEBUG_DOCSHELL_FOCUS
|
|
|
|
printf("popping out focus to parent docshell\n");
|
|
|
|
#endif
|
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
|
|
|
parentESM->MoveCaretToFocus();
|
2002-04-17 04:17:16 +00:00
|
|
|
parentESM->ShiftFocus(aForward, docContent);
|
2001-10-22 22:43:52 +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
|
|
|
} 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
|
|
|
}
|
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
|
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
mCurrentFocus = 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
|
|
|
}
|
|
|
|
|
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
|
|
|
void nsEventStateManager::TabIndexFrom(nsIContent *aFrom, PRInt32 *aOutIndex)
|
|
|
|
{
|
2003-01-10 10:07:30 +00:00
|
|
|
if (aFrom->IsContentOfType(nsIContent::eHTML)) {
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
aFrom->GetTag(*getter_AddRefs(tag));
|
|
|
|
if (nsHTMLAtoms::a != tag && nsHTMLAtoms::area != tag && nsHTMLAtoms::button != tag &&
|
|
|
|
nsHTMLAtoms::input != tag && nsHTMLAtoms::object != tag && nsHTMLAtoms::select != tag && nsHTMLAtoms::textarea != tag)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
nsAutoString tabIndexStr;
|
|
|
|
aFrom->GetAttr(kNameSpaceID_None, nsHTMLAtoms::tabindex, tabIndexStr);
|
|
|
|
if (!tabIndexStr.IsEmpty()) {
|
|
|
|
PRInt32 ec, tabIndexVal = tabIndexStr.ToInteger(&ec);
|
|
|
|
if (NS_SUCCEEDED(ec))
|
|
|
|
*aOutIndex = tabIndexVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsresult
|
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
|
|
|
nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* aFrame, PRBool forward, PRBool aIgnoreTabIndex,
|
2000-04-04 23:55:31 +00:00
|
|
|
nsIContent** aResult)
|
1998-11-18 05:25:26 +00:00
|
|
|
{
|
2000-04-04 23:55:31 +00:00
|
|
|
*aResult = nsnull;
|
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
|
|
|
PRBool keepFirstFrame = PR_FALSE;
|
2001-09-05 22:52:18 +00:00
|
|
|
PRBool findLastFrame = PR_FALSE;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
if (!aFrame) {
|
|
|
|
//No frame means we need to start with the root content again.
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
if (mPresContext) {
|
|
|
|
nsIFrame* result = nsnull;
|
|
|
|
if (NS_SUCCEEDED(mPresContext->GetShell(getter_AddRefs(presShell))) && presShell) {
|
|
|
|
presShell->GetPrimaryFrameFor(aRootContent, &result);
|
|
|
|
}
|
2001-09-05 22:52:18 +00:00
|
|
|
|
|
|
|
aFrame = result;
|
|
|
|
|
|
|
|
if (!forward)
|
|
|
|
findLastFrame = PR_TRUE;
|
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
|
|
|
}
|
|
|
|
if (!aFrame) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
keepFirstFrame = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Need to do special check in case we're in an imagemap which has multiple content per frame
|
|
|
|
if (mCurrentFocus) {
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
mCurrentFocus->GetTag(*getter_AddRefs(tag));
|
2002-09-18 21:24:57 +00:00
|
|
|
if(nsHTMLAtoms::area==tag) {
|
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
|
|
|
//Focus is in an imagemap area
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
if (mPresContext) {
|
|
|
|
nsIFrame* result = nsnull;
|
|
|
|
if (NS_SUCCEEDED(mPresContext->GetShell(getter_AddRefs(presShell))) && presShell) {
|
|
|
|
presShell->GetPrimaryFrameFor(mCurrentFocus, &result);
|
|
|
|
}
|
|
|
|
if (result == aFrame) {
|
|
|
|
//The current focus map area is in the current frame, don't skip over it.
|
|
|
|
keepFirstFrame = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-19 12:55:42 +00:00
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsIFrameTraversal> trav(do_CreateInstance(kFrameTraversalCID,&result));
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2001-09-05 22:52:18 +00:00
|
|
|
result = trav->NewFrameTraversal(getter_AddRefs(frameTraversal), FOCUS,
|
2001-02-19 12:55:42 +00:00
|
|
|
mPresContext, aFrame);
|
2000-04-04 23:55:31 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_OK;
|
1999-03-02 19:19:24 +00:00
|
|
|
|
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
|
|
|
if (!keepFirstFrame) {
|
|
|
|
if (forward)
|
|
|
|
frameTraversal->Next();
|
|
|
|
else frameTraversal->Prev();
|
2001-09-05 22:52:18 +00:00
|
|
|
} else if (findLastFrame)
|
|
|
|
frameTraversal->Last();
|
2000-04-04 23:55:31 +00:00
|
|
|
|
|
|
|
nsISupports* currentItem;
|
|
|
|
frameTraversal->CurrentItem(¤tItem);
|
|
|
|
nsIFrame* currentFrame = (nsIFrame*)currentItem;
|
|
|
|
|
|
|
|
while (currentFrame) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
currentFrame->GetContent(getter_AddRefs(child));
|
|
|
|
|
2001-05-31 22:19:43 +00:00
|
|
|
const nsStyleVisibility* vis;
|
|
|
|
currentFrame->GetStyleData(eStyleStruct_Visibility, ((const nsStyleStruct *&)vis));
|
2000-04-04 23:55:31 +00:00
|
|
|
|
|
|
|
const nsStyleUserInterface* ui;
|
2000-08-08 23:48:42 +00:00
|
|
|
currentFrame->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));
|
2001-02-27 04:43:04 +00:00
|
|
|
|
|
|
|
PRBool viewShown = PR_TRUE;
|
|
|
|
|
|
|
|
nsIView* frameView = nsnull;
|
|
|
|
currentFrame->GetView(mPresContext, &frameView);
|
|
|
|
if (!frameView) {
|
|
|
|
nsIFrame* parentWithView = nsnull;
|
|
|
|
currentFrame->GetParentWithView(mPresContext, &parentWithView);
|
|
|
|
if (parentWithView)
|
|
|
|
parentWithView->GetView(mPresContext, &frameView);
|
|
|
|
}
|
|
|
|
while (frameView) {
|
|
|
|
nsViewVisibility visib;
|
|
|
|
frameView->GetVisibility(visib);
|
|
|
|
if (visib == nsViewVisibility_kHide) {
|
|
|
|
viewShown = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frameView->GetParent(frameView);
|
|
|
|
}
|
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(child));
|
|
|
|
|
|
|
|
// if collapsed or hidden, we don't get tabbed into.
|
2001-02-27 04:43:04 +00:00
|
|
|
if (viewShown &&
|
2001-05-31 22:19:43 +00:00
|
|
|
(vis->mVisible != NS_STYLE_VISIBILITY_COLLAPSE) &&
|
|
|
|
(vis->mVisible != NS_STYLE_VISIBILITY_HIDDEN) &&
|
2000-04-04 23:55:31 +00:00
|
|
|
(ui->mUserFocus != NS_STYLE_USER_FOCUS_IGNORE) &&
|
|
|
|
(ui->mUserFocus != NS_STYLE_USER_FOCUS_NONE) && element) {
|
2000-01-12 06:54:58 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
1999-03-02 19:19:24 +00:00
|
|
|
PRInt32 tabIndex = -1;
|
1998-11-18 05:25:26 +00:00
|
|
|
PRBool disabled = PR_TRUE;
|
1999-01-28 23:14:36 +00:00
|
|
|
PRBool hidden = PR_FALSE;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2003-01-13 20:05:36 +00:00
|
|
|
PRInt32 tabFocusModel = eTabFocus_any;
|
|
|
|
if (mPrefBranch) {
|
|
|
|
// This could be done via a pref observer, but because there are
|
|
|
|
// no static pref callbacks we'd have to create a singleton object
|
|
|
|
// just to observe this pref. Since mPrefBranch is already cached, and
|
|
|
|
// GetIntPref() is fairly fast, that would probably be overkill.
|
|
|
|
// This only happens once per tab press.
|
|
|
|
mPrefBranch->GetIntPref("accessibility.tabfocus", &tabFocusModel);
|
2003-01-09 23:19:55 +00:00
|
|
|
}
|
|
|
|
|
2000-01-12 06:54:58 +00:00
|
|
|
child->GetTag(*getter_AddRefs(tag));
|
2002-11-06 01:54:04 +00:00
|
|
|
if (child->IsContentOfType(nsIContent::eHTML)) {
|
2002-09-18 21:24:57 +00:00
|
|
|
if (nsHTMLAtoms::input==tag) {
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> nextInput(do_QueryInterface(child));
|
|
|
|
if (nextInput) {
|
|
|
|
nextInput->GetDisabled(&disabled);
|
|
|
|
nextInput->GetTabIndex(&tabIndex);
|
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
nextInput->GetType(type);
|
2003-01-07 02:09:06 +00:00
|
|
|
if (type.EqualsIgnoreCase("text")
|
|
|
|
|| type.EqualsIgnoreCase("autocomplete")
|
2002-09-20 04:10:55 +00:00
|
|
|
|| type.EqualsIgnoreCase("password")) {
|
|
|
|
// It's a text field or password field
|
2003-01-13 20:05:36 +00:00
|
|
|
disabled = PR_FALSE;
|
2002-09-18 21:24:57 +00:00
|
|
|
}
|
|
|
|
else if (type.EqualsIgnoreCase("hidden")) {
|
2000-04-04 23:55:31 +00:00
|
|
|
hidden = PR_TRUE;
|
|
|
|
}
|
2002-03-20 04:50:15 +00:00
|
|
|
else if (type.EqualsIgnoreCase("file")) {
|
|
|
|
disabled = PR_TRUE;
|
|
|
|
}
|
2002-09-18 21:24:57 +00:00
|
|
|
else {
|
|
|
|
// it's some other type of form element
|
2002-11-06 01:54:04 +00:00
|
|
|
disabled =
|
2003-01-13 20:05:36 +00:00
|
|
|
disabled || !(tabFocusModel & eTabFocus_formElementsMask);
|
2002-09-18 21:24:57 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2002-09-18 21:24:57 +00:00
|
|
|
else if (nsHTMLAtoms::select==tag) {
|
|
|
|
// Select counts as form but not as text
|
2003-01-13 20:05:36 +00:00
|
|
|
disabled = !(tabFocusModel & eTabFocus_formElementsMask);
|
2002-09-18 21:24:57 +00:00
|
|
|
if (!disabled) {
|
2002-09-20 04:10:55 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLSelectElement> nextSelect(do_QueryInterface(child));
|
|
|
|
if (nextSelect) {
|
|
|
|
nextSelect->GetDisabled(&disabled);
|
|
|
|
nextSelect->GetTabIndex(&tabIndex);
|
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2002-09-18 21:24:57 +00:00
|
|
|
else if (nsHTMLAtoms::textarea==tag) {
|
|
|
|
// it's a textarea
|
2003-01-13 20:05:36 +00:00
|
|
|
disabled = PR_FALSE;
|
2003-01-09 23:19:55 +00:00
|
|
|
if (!disabled) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> nextTextArea(do_QueryInterface(child));
|
|
|
|
if (nextTextArea) {
|
|
|
|
nextTextArea->GetDisabled(&disabled);
|
|
|
|
nextTextArea->GetTabIndex(&tabIndex);
|
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2002-09-18 21:24:57 +00:00
|
|
|
else if (nsHTMLAtoms::a==tag) {
|
|
|
|
// it's a link
|
2003-01-13 20:05:36 +00:00
|
|
|
disabled = !(tabFocusModel & eTabFocus_linksMask);
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> nextAnchor(do_QueryInterface(child));
|
2002-09-18 21:24:57 +00:00
|
|
|
if (!disabled) {
|
2002-09-20 04:10:55 +00:00
|
|
|
if (nextAnchor)
|
|
|
|
nextAnchor->GetTabIndex(&tabIndex);
|
|
|
|
nsAutoString href;
|
|
|
|
nextAnchor->GetAttribute(NS_LITERAL_STRING("href"), href);
|
|
|
|
if (href.IsEmpty()) {
|
|
|
|
disabled = PR_TRUE; // Don't tab unless href, bug 17605
|
|
|
|
} else {
|
|
|
|
disabled = PR_FALSE;
|
|
|
|
}
|
2000-05-11 01:43:04 +00:00
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2002-09-18 21:24:57 +00:00
|
|
|
else if (nsHTMLAtoms::button==tag) {
|
|
|
|
// Button counts as a form element but not as text
|
2003-01-13 20:05:36 +00:00
|
|
|
disabled = !(tabFocusModel & eTabFocus_formElementsMask);
|
2002-09-18 21:24:57 +00:00
|
|
|
if (!disabled) {
|
2002-09-20 04:10:55 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLButtonElement> nextButton(do_QueryInterface(child));
|
|
|
|
if (nextButton) {
|
|
|
|
nextButton->GetTabIndex(&tabIndex);
|
|
|
|
nextButton->GetDisabled(&disabled);
|
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2002-09-18 21:24:57 +00:00
|
|
|
else if (nsHTMLAtoms::img==tag) {
|
2002-10-24 04:02:42 +00:00
|
|
|
// Don't need to set disabled here, because if we
|
|
|
|
// match an imagemap, we'll return from there.
|
2003-01-13 20:05:36 +00:00
|
|
|
if (tabFocusModel & eTabFocus_linksMask) {
|
2002-09-20 04:10:55 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLImageElement> nextImage(do_QueryInterface(child));
|
|
|
|
nsAutoString usemap;
|
|
|
|
if (nextImage) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
if (NS_SUCCEEDED(child->GetDocument(*getter_AddRefs(doc))) && doc) {
|
|
|
|
nextImage->GetAttribute(NS_LITERAL_STRING("usemap"), usemap);
|
|
|
|
nsCOMPtr<nsIDOMHTMLMapElement> imageMap;
|
|
|
|
if (NS_SUCCEEDED(nsImageMapUtils::FindImageMap(doc,usemap,getter_AddRefs(imageMap))) && imageMap) {
|
|
|
|
nsCOMPtr<nsIContent> map(do_QueryInterface(imageMap));
|
|
|
|
if (map) {
|
|
|
|
nsCOMPtr<nsIContent> childArea;
|
|
|
|
PRInt32 count, index;
|
|
|
|
map->ChildCount(count);
|
|
|
|
//First see if mCurrentFocus is in this map
|
|
|
|
for (index = 0; index < count; index++) {
|
|
|
|
map->ChildAt(index, *getter_AddRefs(childArea));
|
2002-12-17 02:10:57 +00:00
|
|
|
if (childArea == mCurrentFocus) {
|
2002-09-20 04:10:55 +00:00
|
|
|
PRInt32 val = 0;
|
|
|
|
TabIndexFrom(childArea, &val);
|
|
|
|
if (mCurrentTabIndex == val) {
|
2002-09-18 21:24:57 +00:00
|
|
|
// mCurrentFocus is in this map so we must start
|
|
|
|
// iterating past it.
|
|
|
|
// We skip the case where mCurrentFocus has the
|
|
|
|
// same tab index as mCurrentTabIndex since the
|
|
|
|
// next tab ordered element might be before it
|
|
|
|
// (or after for backwards) in the child list.
|
2002-09-20 04:10:55 +00:00
|
|
|
break;
|
|
|
|
}
|
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-09-20 04:10:55 +00:00
|
|
|
PRInt32 increment = forward ? 1 : - 1;
|
|
|
|
PRInt32 start = index < count ? index + increment : (forward ? 0 : count - 1);
|
|
|
|
for (index = start; index < count && index >= 0; index += increment) {
|
|
|
|
//Iterate over the children.
|
|
|
|
map->ChildAt(index, *getter_AddRefs(childArea));
|
|
|
|
|
|
|
|
//Got the map area, check its tabindex.
|
|
|
|
PRInt32 val = 0;
|
|
|
|
TabIndexFrom(childArea, &val);
|
|
|
|
if (mCurrentTabIndex == val) {
|
|
|
|
//tabindex == the current one, use it.
|
|
|
|
*aResult = childArea;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-18 00:14:34 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2002-09-18 21:24:57 +00:00
|
|
|
else if (nsHTMLAtoms::object==tag) {
|
|
|
|
// OBJECT is treated as a form element.
|
2003-01-13 20:05:36 +00:00
|
|
|
disabled = !(tabFocusModel & eTabFocus_formElementsMask);
|
2002-09-18 21:24:57 +00:00
|
|
|
if (!disabled) {
|
2002-09-20 04:10:55 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLObjectElement> nextObject(do_QueryInterface(child));
|
|
|
|
if (nextObject)
|
|
|
|
nextObject->GetTabIndex(&tabIndex);
|
|
|
|
disabled = PR_FALSE;
|
|
|
|
}
|
2002-09-18 21:24:57 +00:00
|
|
|
}
|
2003-01-07 02:09:06 +00:00
|
|
|
else if (nsHTMLAtoms::iframe==tag || nsHTMLAtoms::frame==tag) {
|
|
|
|
disabled = PR_TRUE;
|
|
|
|
if (child) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
child->GetDocument(*getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
|
|
|
nsCOMPtr<nsIDocument> subDoc;
|
|
|
|
doc->GetSubDocumentFor(child, getter_AddRefs(subDoc));
|
2003-01-15 00:29:02 +00:00
|
|
|
if (subDoc) {
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
subDoc->GetContainer(getter_AddRefs(container));
|
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container));
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
|
|
|
docShell->GetContentViewer(getter_AddRefs(contentViewer));
|
|
|
|
if (contentViewer) {
|
|
|
|
nsCOMPtr<nsIContentViewer> zombieViewer;
|
|
|
|
contentViewer->GetPreviousViewer(getter_AddRefs(zombieViewer));
|
|
|
|
if (!zombieViewer) {
|
|
|
|
// If there are 2 viewers for the current docshell, that
|
|
|
|
// means the current document is a zombie document.
|
|
|
|
// Only navigate into the frame/iframe if it's not a zombie
|
|
|
|
disabled = PR_FALSE;
|
|
|
|
}
|
2003-01-07 02:09:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-22 22:43:52 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2003-01-07 02:09:06 +00:00
|
|
|
else {
|
|
|
|
// Is it disabled?
|
2000-04-04 23:55:31 +00:00
|
|
|
nsAutoString value;
|
2001-08-17 08:14:14 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsHTMLAtoms::disabled, value);
|
2003-01-07 02:09:06 +00:00
|
|
|
// Check the tabindex attribute
|
2000-04-04 23:55:31 +00:00
|
|
|
nsAutoString tabStr;
|
2001-08-17 08:14:14 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsHTMLAtoms::tabindex, tabStr);
|
2000-04-15 20:15:37 +00:00
|
|
|
if (!tabStr.IsEmpty()) {
|
2000-04-04 23:55:31 +00:00
|
|
|
PRInt32 errorCode;
|
|
|
|
tabIndex = tabStr.ToInteger(&errorCode);
|
2000-03-23 09:56:58 +00:00
|
|
|
}
|
2001-12-16 11:58:03 +00:00
|
|
|
if (!value.Equals(NS_LITERAL_STRING("true")))
|
2000-04-04 23:55:31 +00:00
|
|
|
disabled = PR_FALSE;
|
2000-01-13 11:43:54 +00:00
|
|
|
}
|
2000-03-23 09:56:58 +00:00
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
//TabIndex not set (-1) treated at same level as set to 0
|
|
|
|
tabIndex = tabIndex < 0 ? 0 : tabIndex;
|
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
if (!disabled && !hidden && (aIgnoreTabIndex ||
|
|
|
|
mCurrentTabIndex == tabIndex) &&
|
|
|
|
child != mCurrentFocus) {
|
2000-04-04 23:55:31 +00:00
|
|
|
*aResult = child;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
if (forward)
|
|
|
|
frameTraversal->Next();
|
|
|
|
else frameTraversal->Prev();
|
|
|
|
|
|
|
|
frameTraversal->CurrentItem(¤tItem);
|
|
|
|
currentFrame = (nsIFrame*)currentItem;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
// Reached end or beginning of document
|
|
|
|
//If already at lowest priority tab (0), end
|
|
|
|
if (((forward) && (0 == mCurrentTabIndex)) ||
|
|
|
|
((!forward) && (1 == mCurrentTabIndex))) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
//else continue looking for next highest priority tab
|
|
|
|
mCurrentTabIndex = GetNextTabIndex(aRootContent, forward);
|
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 GetNextTabbableContent(aRootContent, nsnull, forward, aIgnoreTabIndex, aResult);
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
PRInt32
|
|
|
|
nsEventStateManager::GetNextTabIndex(nsIContent* aParent, PRBool forward)
|
|
|
|
{
|
1999-07-19 21:23:57 +00:00
|
|
|
PRInt32 count, tabIndex, childTabIndex;
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIContent> child;
|
1999-07-19 21:23:57 +00:00
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
aParent->ChildCount(count);
|
1999-07-19 21:23:57 +00:00
|
|
|
|
|
|
|
if (forward) {
|
|
|
|
tabIndex = 0;
|
|
|
|
for (PRInt32 index = 0; index < count; index++) {
|
2000-04-04 23:55:31 +00:00
|
|
|
aParent->ChildAt(index, *getter_AddRefs(child));
|
1999-07-19 21:23:57 +00:00
|
|
|
childTabIndex = GetNextTabIndex(child, forward);
|
|
|
|
if (childTabIndex > mCurrentTabIndex && childTabIndex != tabIndex) {
|
|
|
|
tabIndex = (tabIndex == 0 || childTabIndex < tabIndex) ? childTabIndex : tabIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString tabIndexStr;
|
2001-10-22 22:43:52 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsHTMLAtoms::tabindex, tabIndexStr);
|
1999-07-19 21:23:57 +00:00
|
|
|
PRInt32 ec, val = tabIndexStr.ToInteger(&ec);
|
|
|
|
if (NS_OK == ec && val > mCurrentTabIndex && val != tabIndex) {
|
|
|
|
tabIndex = (tabIndex == 0 || val < tabIndex) ? val : tabIndex;
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
1999-07-19 21:23:57 +00:00
|
|
|
}
|
|
|
|
else { /* !forward */
|
|
|
|
tabIndex = 1;
|
|
|
|
for (PRInt32 index = 0; index < count; index++) {
|
2000-04-04 23:55:31 +00:00
|
|
|
aParent->ChildAt(index, *getter_AddRefs(child));
|
1999-07-19 21:23:57 +00:00
|
|
|
childTabIndex = GetNextTabIndex(child, forward);
|
|
|
|
if ((mCurrentTabIndex==0 && childTabIndex > tabIndex) ||
|
|
|
|
(childTabIndex < mCurrentTabIndex && childTabIndex > tabIndex)) {
|
|
|
|
tabIndex = childTabIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString tabIndexStr;
|
2001-10-22 22:43:52 +00:00
|
|
|
child->GetAttr(kNameSpaceID_None, nsHTMLAtoms::tabindex, tabIndexStr);
|
1999-07-19 21:23:57 +00:00
|
|
|
PRInt32 ec, val = tabIndexStr.ToInteger(&ec);
|
|
|
|
if (NS_OK == ec) {
|
|
|
|
if ((mCurrentTabIndex==0 && val > tabIndex) ||
|
|
|
|
(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) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
if (mPresContext) {
|
|
|
|
nsresult rv = mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell){
|
|
|
|
shell->GetPrimaryFrameFor(mCurrentTargetContent, &mCurrentTarget);
|
2002-07-22 21:36:36 +00:00
|
|
|
|
|
|
|
//This may be new frame that hasn't been through the ESM so we
|
|
|
|
//must set its NS_FRAME_EXTERNAL_REFERENCE bit.
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
nsFrameState state;
|
|
|
|
mCurrentTarget->GetFrameState(&state);
|
|
|
|
state |= NS_FRAME_EXTERNAL_REFERENCE;
|
|
|
|
mCurrentTarget->SetFrameState(state);
|
|
|
|
}
|
1999-06-15 03:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-24 03:58:13 +00:00
|
|
|
if (!mCurrentTarget) {
|
2002-02-21 13:39:39 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
presShell->GetEventTargetFrame(&mCurrentTarget);
|
2002-07-22 21:36:36 +00:00
|
|
|
|
|
|
|
//This may be new frame that hasn't been through the ESM so we
|
|
|
|
//must set its NS_FRAME_EXTERNAL_REFERENCE bit.
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
nsFrameState state;
|
|
|
|
mCurrentTarget->GetFrameState(&state);
|
|
|
|
state |= NS_FRAME_EXTERNAL_REFERENCE;
|
|
|
|
mCurrentTarget->SetFrameState(state);
|
|
|
|
}
|
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
|
1999-12-08 04:54:29 +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
|
|
|
|
|
|
|
if (!mCurrentTarget) {
|
2002-02-21 13:39:39 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
presShell->GetEventTargetFrame(&mCurrentTarget);
|
2002-07-22 21:36:36 +00:00
|
|
|
|
|
|
|
//This may be new frame that hasn't been through the ESM so we
|
|
|
|
//must set its NS_FRAME_EXTERNAL_REFERENCE bit.
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
nsFrameState state;
|
|
|
|
mCurrentTarget->GetFrameState(&state);
|
|
|
|
state |= NS_FRAME_EXTERNAL_REFERENCE;
|
|
|
|
mCurrentTarget->SetFrameState(state);
|
|
|
|
}
|
2002-02-21 13:39:39 +00:00
|
|
|
}
|
2000-06-24 03:58:13 +00:00
|
|
|
}
|
|
|
|
|
1999-07-27 20:55:03 +00:00
|
|
|
if (mCurrentTarget) {
|
2000-02-11 01:24:59 +00:00
|
|
|
mCurrentTarget->GetContentForEvent(mPresContext, aEvent, aContent);
|
1999-07-27 20:55:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-15 03:14:28 +00:00
|
|
|
|
1999-07-27 20:55:03 +00:00
|
|
|
*aContent = nsnull;
|
1998-06-23 21:53:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::GetEventRelatedContent(nsIContent** aContent)
|
|
|
|
{
|
|
|
|
if (mCurrentRelatedContent) {
|
|
|
|
*aContent = mCurrentRelatedContent;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aContent = nsnull;
|
|
|
|
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
|
|
|
{
|
1999-03-28 22:22:54 +00:00
|
|
|
aState = NS_EVENT_STATE_UNSPECIFIED;
|
|
|
|
|
|
|
|
if (aContent == mActiveContent) {
|
|
|
|
aState |= NS_EVENT_STATE_ACTIVE;
|
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.
|
|
|
|
nsCOMPtr<nsIContent> hoverContent = mHoverContent;
|
|
|
|
while (hoverContent) {
|
|
|
|
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
|
|
|
}
|
2002-04-11 03:49:30 +00:00
|
|
|
nsIContent *parent;
|
|
|
|
hoverContent->GetParent(parent);
|
|
|
|
hoverContent = dont_AddRef(parent);
|
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;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
1999-04-12 21:24:07 +00:00
|
|
|
nsEventStateManager::SetContentState(nsIContent *aContent, PRInt32 aState)
|
1998-08-07 04:45:03 +00:00
|
|
|
{
|
2003-01-13 23:10:53 +00:00
|
|
|
const PRInt32 maxNotify = 6;
|
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.
|
2000-08-08 23:48:42 +00:00
|
|
|
if (mCurrentTarget && (aState == NS_EVENT_STATE_ACTIVE || aState == NS_EVENT_STATE_HOVER))
|
|
|
|
{
|
|
|
|
const nsStyleUserInterface* ui;
|
|
|
|
mCurrentTarget->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));
|
|
|
|
if (ui->mUserInput == NS_STYLE_USER_INPUT_NONE)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-04 14:44:51 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_DRAGOVER) && (aContent != mDragOverContent)) {
|
|
|
|
notifyContent[4] = mDragOverContent; // notify dragover first, since more common case
|
2002-12-17 02:10:57 +00:00
|
|
|
NS_IF_ADDREF(notifyContent[4]);
|
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)) {
|
|
|
|
notifyContent[5] = mURLTargetContent;
|
|
|
|
NS_IF_ADDREF(notifyContent[5]);
|
|
|
|
mURLTargetContent = aContent;
|
|
|
|
}
|
|
|
|
|
1999-04-20 00:03:30 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_ACTIVE) && (aContent != mActiveContent)) {
|
|
|
|
//transferring ref to notifyContent from mActiveContent
|
|
|
|
notifyContent[2] = mActiveContent;
|
2002-12-17 02:10:57 +00:00
|
|
|
NS_IF_ADDREF(notifyContent[2]);
|
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;
|
|
|
|
newHover = aContent;
|
|
|
|
// Find closest common ancestor (commonHoverAncestor)
|
|
|
|
if (mHoverContent && aContent) {
|
|
|
|
// Find the nearest common ancestor by counting the distance to the
|
|
|
|
// root and then walking up again, in pairs.
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
nsCOMPtr<nsIContent> oldAncestor = mHoverContent;
|
|
|
|
for (;;) {
|
|
|
|
++offset;
|
|
|
|
nsIContent *parent;
|
|
|
|
oldAncestor->GetParent(parent);
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
oldAncestor = dont_AddRef(parent);
|
2000-09-27 14:34:50 +00:00
|
|
|
}
|
2002-04-11 03:49:30 +00:00
|
|
|
nsCOMPtr<nsIContent> newAncestor = aContent;
|
|
|
|
for (;;) {
|
|
|
|
--offset;
|
|
|
|
nsIContent *parent;
|
|
|
|
newAncestor->GetParent(parent);
|
|
|
|
if (!parent)
|
|
|
|
break;
|
|
|
|
newAncestor = dont_AddRef(parent);
|
2000-09-27 14:34:50 +00:00
|
|
|
}
|
2002-04-20 12:36:45 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (oldAncestor != newAncestor) {
|
|
|
|
// This could be a performance problem.
|
|
|
|
nsCOMPtr<nsIDocument> oldDoc;
|
|
|
|
oldAncestor->GetDocument(*getter_AddRefs(oldDoc));
|
|
|
|
// The |!oldDoc| case (that the old hover node has been removed
|
|
|
|
// from the document) could be a slight performance problem.
|
|
|
|
// It's rare enough that it shouldn't be an issue, but common
|
|
|
|
// enough that we don't want to assert..
|
|
|
|
NS_ASSERTION(!oldDoc,
|
|
|
|
"moved hover between nodes in different documents");
|
|
|
|
// XXX Why don't we ever hit this code because we're not using
|
|
|
|
// |GetBindingParent|?
|
|
|
|
}
|
|
|
|
#endif
|
2002-04-11 03:49:30 +00:00
|
|
|
if (oldAncestor == newAncestor) {
|
|
|
|
oldAncestor = mHoverContent;
|
|
|
|
newAncestor = aContent;
|
|
|
|
while (offset > 0) {
|
|
|
|
nsIContent *parent;
|
|
|
|
oldAncestor->GetParent(parent);
|
|
|
|
oldAncestor = dont_AddRef(parent);
|
|
|
|
--offset;
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
2002-04-11 03:49:30 +00:00
|
|
|
while (offset < 0) {
|
|
|
|
nsIContent *parent;
|
|
|
|
newAncestor->GetParent(parent);
|
|
|
|
newAncestor = dont_AddRef(parent);
|
|
|
|
++offset;
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
2002-04-11 03:49:30 +00:00
|
|
|
while (oldAncestor != newAncestor) {
|
|
|
|
nsIContent *parent;
|
|
|
|
oldAncestor->GetParent(parent);
|
|
|
|
oldAncestor = dont_AddRef(parent);
|
|
|
|
newAncestor->GetParent(parent);
|
|
|
|
newAncestor = dont_AddRef(parent);
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
2002-04-11 03:49:30 +00:00
|
|
|
commonHoverAncestor = oldAncestor;
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-11 03:49:30 +00:00
|
|
|
|
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)) {
|
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 {
|
2000-04-12 00:24:07 +00:00
|
|
|
notifyContent[3] = gLastFocusedContent;
|
|
|
|
NS_IF_ADDREF(gLastFocusedContent);
|
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
|
|
|
SendFocusBlur(mPresContext, aContent, PR_TRUE);
|
1999-12-08 04:54:29 +00:00
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
|
2002-04-11 03:49:30 +00:00
|
|
|
if (aContent && aContent != newHover) { // 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.
|
|
|
|
nsIDocument* doc = nsnull;
|
|
|
|
for (int i = 0; i < maxNotify; i++) {
|
|
|
|
if (notifyContent[i] && NS_SUCCEEDED(notifyContent[i]->GetDocument(doc)) && !doc) {
|
|
|
|
NS_RELEASE(notifyContent[i]);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(doc);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-09-15 06:17:54 +00:00
|
|
|
if (notifyContent[0] || newHover || oldHover) { // 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]) {
|
2001-05-14 01:49:07 +00:00
|
|
|
notifyContent[0]->GetDocument(*getter_AddRefs(doc1));
|
|
|
|
if (notifyContent[1]) {
|
|
|
|
//For :focus this might be a different doc so check
|
|
|
|
notifyContent[1]->GetDocument(*getter_AddRefs(doc2));
|
|
|
|
if (doc1 == doc2) {
|
|
|
|
doc2 = nsnull;
|
|
|
|
}
|
|
|
|
}
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
|
|
|
else if (newHover) {
|
2001-05-14 01:49:07 +00:00
|
|
|
newHover->GetDocument(*getter_AddRefs(doc1));
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-04-11 03:49:30 +00:00
|
|
|
oldHover->GetDocument(*getter_AddRefs(doc1));
|
2000-09-15 06:17:54 +00:00
|
|
|
}
|
2001-05-14 01:49:07 +00:00
|
|
|
if (doc1) {
|
|
|
|
doc1->BeginUpdate();
|
2000-09-15 06:17:54 +00:00
|
|
|
|
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);
|
|
|
|
nsIContent *parent;
|
|
|
|
newHover->GetParent(parent);
|
|
|
|
newHover = dont_AddRef(parent);
|
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);
|
|
|
|
nsIContent *parent;
|
|
|
|
oldHover->GetParent(parent);
|
|
|
|
oldHover = dont_AddRef(parent);
|
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],
|
|
|
|
aState & ~NS_EVENT_STATE_HOVER);
|
|
|
|
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],
|
|
|
|
aState & ~NS_EVENT_STATE_HOVER);
|
|
|
|
if (notifyContent[4]) {
|
|
|
|
// more that four notifications are needed (should be rare)
|
|
|
|
doc1->ContentStatesChanged(notifyContent[4], nsnull,
|
|
|
|
aState & ~NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
2001-05-14 01:49:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
doc1->EndUpdate();
|
|
|
|
|
|
|
|
if (doc2) {
|
|
|
|
doc2->BeginUpdate();
|
2002-04-11 03:49:30 +00:00
|
|
|
doc2->ContentStatesChanged(notifyContent[1], notifyContent[2],
|
|
|
|
aState & ~NS_EVENT_STATE_HOVER);
|
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],
|
|
|
|
aState & ~NS_EVENT_STATE_HOVER);
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
2001-05-14 01:49:07 +00:00
|
|
|
doc2->EndUpdate();
|
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
|
|
|
}
|
|
|
|
|
1998-08-07 04:45:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-09-06 00:19:58 +00:00
|
|
|
nsresult
|
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
|
|
|
nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aContent, PRBool aEnsureWindowHasFocus)
|
1999-03-02 19:19:24 +00:00
|
|
|
{
|
1999-12-21 19:35:13 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
2000-04-04 23:55:31 +00:00
|
|
|
|
1999-12-18 04:02:28 +00:00
|
|
|
if (nsnull != gLastFocusedPresContext) {
|
|
|
|
|
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.
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
gLastFocusedContent->GetDocument(*getter_AddRefs(doc));
|
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;
|
2001-06-20 03:27:48 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
doc->GetShellAt(0, getter_AddRefs(shell));
|
2000-04-05 02:10:25 +00:00
|
|
|
if (shell) {
|
2000-10-18 17:41:14 +00:00
|
|
|
shell->GetViewManager(getter_AddRefs(kungFuDeathGrip));
|
|
|
|
|
2000-04-05 02:10:25 +00:00
|
|
|
nsCOMPtr<nsIPresContext> oldPresContext;
|
|
|
|
shell->GetPresContext(getter_AddRefs(oldPresContext));
|
1999-12-21 01:12:40 +00:00
|
|
|
|
2000-04-05 02:10:25 +00:00
|
|
|
//fire blur
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
2000-06-28 20:35:32 +00:00
|
|
|
|
2000-06-29 20:53:08 +00:00
|
|
|
EnsureDocument(presShell);
|
2000-06-28 20:35:32 +00:00
|
|
|
|
|
|
|
// Make sure we're not switching command dispatchers, if so, surpress the blurred one
|
|
|
|
if(gLastFocusedDocument && mDocument) {
|
2000-11-04 08:21:20 +00:00
|
|
|
nsCOMPtr<nsIFocusController> newFocusController;
|
|
|
|
nsCOMPtr<nsIFocusController> oldFocusController;
|
2000-06-28 20:35:32 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> oldPIDOMWindow;
|
|
|
|
nsCOMPtr<nsPIDOMWindow> newPIDOMWindow;
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> oldGlobal;
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> newGlobal;
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(oldGlobal));
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(newGlobal));
|
2000-06-23 05:37:08 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> newWindow = do_QueryInterface(newGlobal);
|
2000-06-28 20:35:32 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindow> oldWindow = do_QueryInterface(oldGlobal);
|
2000-07-07 22:17:00 +00:00
|
|
|
if(newWindow)
|
2000-11-04 08:21:20 +00:00
|
|
|
newWindow->GetRootFocusController(getter_AddRefs(newFocusController));
|
2000-07-07 22:17:00 +00:00
|
|
|
if(oldWindow)
|
2002-02-21 13:39:39 +00:00
|
|
|
oldWindow->GetRootFocusController(getter_AddRefs(oldFocusController));
|
2000-11-04 08:21:20 +00:00
|
|
|
if(oldFocusController && oldFocusController != newFocusController)
|
2001-04-18 01:41:20 +00:00
|
|
|
oldFocusController->SetSuppressFocus(PR_TRUE, "SendFocusBlur Window Switch");
|
2000-06-28 20:35:32 +00:00
|
|
|
}
|
|
|
|
|
2000-04-05 02:10:25 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
oldPresContext->GetEventStateManager(getter_AddRefs(esm));
|
|
|
|
esm->SetFocusedContent(gLastFocusedContent);
|
|
|
|
nsCOMPtr<nsIContent> temp = gLastFocusedContent;
|
|
|
|
NS_RELEASE(gLastFocusedContent);
|
|
|
|
gLastFocusedContent = nsnull;
|
2002-07-24 06:13:18 +00:00
|
|
|
|
|
|
|
nsCxPusher pusher(temp);
|
2000-04-05 02:10:25 +00:00
|
|
|
temp->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
2002-07-24 06:13:18 +00:00
|
|
|
pusher.Pop();
|
|
|
|
|
2000-04-05 02:10:25 +00:00
|
|
|
esm->SetFocusedContent(nsnull);
|
|
|
|
}
|
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
|
|
|
}
|
1999-12-18 04:02:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Go ahead and fire a blur on the window.
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
2000-02-11 01:24:59 +00:00
|
|
|
|
2000-02-12 08:33:12 +00:00
|
|
|
if(gLastFocusedDocument)
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
2000-06-28 20:35:32 +00:00
|
|
|
|
|
|
|
EnsureDocument(presShell);
|
1999-12-18 04:02:28 +00:00
|
|
|
|
2000-02-12 08:33:12 +00:00
|
|
|
if (gLastFocusedDocument && (gLastFocusedDocument != mDocument) && globalObject) {
|
1999-12-18 04:02:28 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
|
|
|
|
2002-02-21 13:39:39 +00:00
|
|
|
// Make sure we're not switching command dispatchers, if so, surpress the blurred one
|
|
|
|
if (mDocument) {
|
|
|
|
nsCOMPtr<nsIFocusController> newFocusController;
|
|
|
|
nsCOMPtr<nsIFocusController> oldFocusController;
|
|
|
|
nsCOMPtr<nsPIDOMWindow> oldPIDOMWindow;
|
|
|
|
nsCOMPtr<nsPIDOMWindow> newPIDOMWindow;
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> oldGlobal;
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> newGlobal;
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(oldGlobal));
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(newGlobal));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> newWindow = do_QueryInterface(newGlobal);
|
|
|
|
nsCOMPtr<nsPIDOMWindow> oldWindow = do_QueryInterface(oldGlobal);
|
2000-06-23 05:37:08 +00:00
|
|
|
|
2001-05-01 22:54:11 +00:00
|
|
|
if (newWindow)
|
|
|
|
newWindow->GetRootFocusController(getter_AddRefs(newFocusController));
|
2002-02-21 13:39:39 +00:00
|
|
|
oldWindow->GetRootFocusController(getter_AddRefs(oldFocusController));
|
|
|
|
if(oldFocusController && oldFocusController != newFocusController)
|
|
|
|
oldFocusController->SetSuppressFocus(PR_TRUE, "SendFocusBlur Window Switch #2");
|
|
|
|
}
|
2000-06-23 05:37:08 +00:00
|
|
|
|
1999-12-18 04:02:28 +00:00
|
|
|
nsCOMPtr<nsIEventStateManager> esm;
|
|
|
|
gLastFocusedPresContext->GetEventStateManager(getter_AddRefs(esm));
|
|
|
|
esm->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);
|
2000-02-12 08:33:12 +00:00
|
|
|
temp->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
2002-07-24 06:13:18 +00:00
|
|
|
pusher.Pop();
|
|
|
|
|
|
|
|
pusher.Push(globalObject);
|
1999-12-18 04:02:28 +00:00
|
|
|
globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
1999-03-02 19:19:24 +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);
|
1999-12-08 04:54:29 +00:00
|
|
|
mCurrentFocus = aContent;
|
|
|
|
|
2002-05-17 04:04:24 +00:00
|
|
|
// Moved widget focusing code here, from end of SendFocusBlur
|
|
|
|
// This fixes the order of accessibility focus events, so that
|
|
|
|
// the window focus event goes first, and then the focus event for the control
|
|
|
|
if (aEnsureWindowHasFocus) {
|
|
|
|
// 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
|
|
|
|
nsCOMPtr<nsIViewManager> vm;
|
|
|
|
presShell->GetViewManager(getter_AddRefs(vm));
|
|
|
|
if (vm) {
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
vm->GetWidget(getter_AddRefs(widget));
|
|
|
|
if (widget)
|
|
|
|
widget->SetFocus(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = 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);
|
1999-11-24 06:03:41 +00:00
|
|
|
aContent->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
1999-04-12 21:24:07 +00:00
|
|
|
}
|
1999-12-08 04:54:29 +00:00
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
nsAutoString tabIndex;
|
2001-10-22 22:43:52 +00:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::tabindex, tabIndex);
|
1999-04-12 21:24:07 +00:00
|
|
|
PRInt32 ec, val = tabIndex.ToInteger(&ec);
|
|
|
|
if (NS_OK == ec) {
|
|
|
|
mCurrentTabIndex = val;
|
|
|
|
}
|
2000-02-11 05:20:44 +00:00
|
|
|
|
|
|
|
if (clearFirstFocusEvent) {
|
2002-12-17 02:10:57 +00:00
|
|
|
mFirstFocusEvent = nsnull;
|
|
|
|
}
|
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;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_FOCUS_CONTENT;
|
|
|
|
if (nsnull != mPresContext && mDocument) {
|
2002-07-24 06:13:18 +00:00
|
|
|
nsCxPusher pusher(mDocument);
|
2001-08-21 02:27:34 +00:00
|
|
|
mDocument->HandleDOMEvent(mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &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
|
|
|
|
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)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::SetFocusedContent(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
mCurrentFocus = aContent;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-29 00:04:31 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::ContentRemoved(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (aContent == mCurrentFocus) {
|
|
|
|
// 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.
|
|
|
|
|
2002-12-17 02:10:57 +00:00
|
|
|
mCurrentFocus = nsnull;
|
2001-11-29 00:04:31 +00:00
|
|
|
}
|
|
|
|
|
2002-08-19 18:31:59 +00:00
|
|
|
if (aContent == mHoverContent) {
|
|
|
|
// Since hover is hierarchical, set the current hover to the
|
|
|
|
// content's parent node.
|
2002-12-17 02:10:57 +00:00
|
|
|
aContent->GetParent(*getter_AddRefs(mHoverContent));
|
2002-08-19 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aContent == mActiveContent) {
|
2002-12-17 02:10:57 +00:00
|
|
|
mActiveContent = nsnull;
|
2002-08-19 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aContent == mDragOverContent) {
|
2002-12-17 02:10:57 +00:00
|
|
|
mDragOverContent = nsnull;
|
2002-08-19 18:31:59 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) {
|
|
|
|
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) {
|
2002-02-21 13:39:39 +00:00
|
|
|
PRUnichar accKey = nsCRT::ToLower((char)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) {
|
2002-02-21 13:39:39 +00:00
|
|
|
PRUnichar accKey = nsCRT::ToLower((char)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
|
|
|
}
|
|
|
|
|
2000-01-11 22:30:22 +00:00
|
|
|
void nsEventStateManager::ForceViewUpdate(nsIView* aView)
|
|
|
|
{
|
|
|
|
// force the update to happen now, otherwise multiple scrolls can
|
|
|
|
// occur before the update is processed. (bug #7354)
|
|
|
|
|
|
|
|
nsIViewManager* vm = nsnull;
|
|
|
|
if (NS_OK == aView->GetViewManager(vm) && nsnull != vm) {
|
|
|
|
// 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
|
|
|
NS_RELEASE(vm);
|
|
|
|
}
|
|
|
|
}
|
1999-11-21 01:46:41 +00:00
|
|
|
|
2000-05-16 11:35:12 +00:00
|
|
|
NS_IMETHODIMP
|
2001-09-27 21:43:00 +00:00
|
|
|
nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent, PRBool *aPreventDefault)
|
2000-05-16 11:35:12 +00:00
|
|
|
{
|
2000-05-17 05:27:22 +00:00
|
|
|
nsresult ret = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privEvt(do_QueryInterface(aEvent));
|
2002-09-14 10:28:14 +00:00
|
|
|
if (privEvt) {
|
2001-11-06 09:02:55 +00:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> eventTarget(do_QueryInterface(aTarget));
|
|
|
|
privEvt->SetTarget(eventTarget);
|
|
|
|
|
2001-11-20 08:40:54 +00:00
|
|
|
//Key and mouse events have additional security to prevent event spoofing
|
2002-11-09 00:25:25 +00:00
|
|
|
nsEvent * innerEvent;
|
|
|
|
privEvt->GetInternalNSEvent(&innerEvent);
|
|
|
|
if (innerEvent && (innerEvent->eventStructType == NS_KEY_EVENT ||
|
|
|
|
innerEvent->eventStructType == NS_MOUSE_EVENT)) {
|
2001-11-20 08:40:54 +00:00
|
|
|
//Check security state to determine if dispatcher is trusted
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager>
|
|
|
|
securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(securityManager, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRBool enabled;
|
|
|
|
nsresult res = securityManager->IsCapabilityEnabled("UniversalBrowserWrite", &enabled);
|
|
|
|
if (NS_SUCCEEDED(res) && enabled) {
|
|
|
|
privEvt->SetTrusted(PR_TRUE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
privEvt->SetTrusted(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
privEvt->SetTrusted(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2000-05-17 05:27:22 +00:00
|
|
|
if (innerEvent) {
|
2000-11-08 00:33:37 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2000-05-17 05:27:22 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> target(do_QueryInterface(aTarget));
|
|
|
|
if (target) {
|
|
|
|
ret = target->HandleDOMEvent(mPresContext, innerEvent, &aEvent, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIDocument> target(do_QueryInterface(aTarget));
|
|
|
|
if (target) {
|
|
|
|
ret = target->HandleDOMEvent(mPresContext, innerEvent, &aEvent, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIContent> target(do_QueryInterface(aTarget));
|
|
|
|
if (target) {
|
|
|
|
ret = target->HandleDOMEvent(mPresContext, innerEvent, &aEvent, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
2000-11-04 08:21:20 +00:00
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIChromeEventHandler> target(do_QueryInterface(aTarget));
|
|
|
|
if (target) {
|
|
|
|
ret = target->HandleChromeEvent(mPresContext, innerEvent, &aEvent, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
|
|
|
}
|
2000-05-17 05:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-27 21:43:00 +00:00
|
|
|
|
|
|
|
*aPreventDefault = status == nsEventStatus_eConsumeNoDefault ? PR_FALSE : PR_TRUE;
|
2000-05-17 05:27:22 +00:00
|
|
|
}
|
|
|
|
}
|
2001-09-27 21:43:00 +00:00
|
|
|
|
2000-05-17 05:27:22 +00:00
|
|
|
return ret;
|
2000-05-16 11:35:12 +00:00
|
|
|
}
|
|
|
|
|
2000-06-28 20:35:32 +00:00
|
|
|
void nsEventStateManager::EnsureDocument(nsIPresContext* aPresContext) {
|
|
|
|
if (!mDocument) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
EnsureDocument(presShell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsEventStateManager::EnsureDocument(nsIPresShell* aPresShell) {
|
|
|
|
if (!mDocument && aPresShell)
|
2002-12-17 02:10:57 +00:00
|
|
|
aPresShell->GetDocument(getter_AddRefs(mDocument));
|
2000-06-28 20:35:32 +00:00
|
|
|
}
|
|
|
|
|
2001-01-20 04:59:39 +00:00
|
|
|
void nsEventStateManager::FlushPendingEvents(nsIPresContext* aPresContext) {
|
|
|
|
NS_PRECONDITION(nsnull != aPresContext, "nsnull ptr");
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (nsnull != shell) {
|
2001-08-31 04:28:26 +00:00
|
|
|
shell->FlushPendingNotifications(PR_FALSE);
|
2001-01-20 04:59:39 +00:00
|
|
|
nsCOMPtr<nsIViewManager> viewManager;
|
2001-02-19 12:55:42 +00:00
|
|
|
shell->GetViewManager(getter_AddRefs(viewManager));
|
|
|
|
if (viewManager) {
|
2001-01-20 04:59:39 +00:00
|
|
|
viewManager->FlushPendingInvalidates();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult)
|
|
|
|
{
|
2000-03-15 04:03:44 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "nsnull ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsIEventStateManager* manager = new nsEventStateManager();
|
|
|
|
if (nsnull == manager) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2002-12-11 14:24:49 +00:00
|
|
|
rv = CallQueryInterface(manager, aInstancePtrResult);
|
2000-03-15 04:03:44 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return manager->Init();
|
1998-06-23 21:53:02 +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
|
|
|
nsresult 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;
|
|
|
|
*aStartFrame = nsnull;
|
|
|
|
*aStartContent = *aEndContent = nsnull;
|
2001-02-15 05:07:46 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
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;
|
2001-02-15 05:07:46 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
if (mPresContext)
|
|
|
|
rv = mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
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<nsIFrameSelection> frameSelection;
|
2001-02-15 05:07:46 +00:00
|
|
|
if (shell)
|
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
|
|
|
rv = shell->GetFrameSelection(getter_AddRefs(frameSelection));
|
2001-02-15 05:07:46 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsISelection> 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
|
|
|
if (frameSelection)
|
|
|
|
rv = frameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
2001-02-15 05:07:46 +00:00
|
|
|
getter_AddRefs(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
|
|
|
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));
|
|
|
|
typedef PRInt32* PRInt32_ptr;
|
|
|
|
domRange->GetStartOffset(PRInt32_ptr(aStartOffset));
|
2002-03-21 02:37:48 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> childContent;
|
|
|
|
PRBool canContainChildren;
|
|
|
|
|
|
|
|
startContent = do_QueryInterface(startNode);
|
2002-04-25 05:59:02 +00:00
|
|
|
if (NS_SUCCEEDED(startContent->CanContainChildren(canContainChildren)) &&
|
2002-03-21 02:37:48 +00:00
|
|
|
canContainChildren) {
|
|
|
|
startContent->ChildAt(*aStartOffset, *getter_AddRefs(childContent));
|
|
|
|
if (childContent)
|
|
|
|
startContent = childContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
endContent = do_QueryInterface(endNode);
|
2002-04-25 05:59:02 +00:00
|
|
|
if (NS_SUCCEEDED(endContent->CanContainChildren(canContainChildren)) &&
|
2002-03-21 02:37:48 +00:00
|
|
|
canContainChildren) {
|
|
|
|
PRInt32 endOffset = 0;
|
|
|
|
domRange->GetEndOffset(&endOffset);
|
|
|
|
endContent->ChildAt(endOffset, *getter_AddRefs(childContent));
|
|
|
|
if (childContent)
|
|
|
|
endContent = childContent;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *startFrame = nsnull;
|
|
|
|
if (startContent) {
|
|
|
|
rv = shell->GetPrimaryFrameFor(startContent, &startFrame);
|
|
|
|
if (isCollapsed && NS_SUCCEEDED(rv)) {
|
|
|
|
// First check to see if our caret is at the very end of a node
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
if (nodeType == nsIDOMNode::TEXT_NODE) {
|
|
|
|
nsCOMPtr<nsIContent> origStartContent(startContent), rootContent;
|
|
|
|
mDocument->GetRootContent(getter_AddRefs(rootContent));
|
|
|
|
nsAutoString nodeValue;
|
|
|
|
domNode->GetNodeValue(nodeValue);
|
|
|
|
|
2002-08-06 08:32:19 +00:00
|
|
|
PRBool isFormControl =
|
|
|
|
startContent->IsContentOfType(nsIContent::eHTML_FORM_CONTROL);
|
2002-04-27 01:20:48 +00:00
|
|
|
|
2002-08-06 08:32:19 +00:00
|
|
|
if (nodeValue.Length() == *aStartOffset && !isFormControl &&
|
|
|
|
startContent != rootContent) {
|
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);
|
|
|
|
|
|
|
|
rv = trav->NewFrameTraversal(getter_AddRefs(frameTraversal), LEAF,
|
|
|
|
mPresContext, startFrame);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
do {
|
|
|
|
// Get the next logical frame, and set the start of
|
|
|
|
// focusable elements. Search for focusable elements from there.
|
|
|
|
// Continue getting next frame until the primary node for the frame
|
|
|
|
// we are on changes - we don't want to be stuck in the same place
|
|
|
|
frameTraversal->Next();
|
|
|
|
nsISupports* currentItem;
|
|
|
|
frameTraversal->CurrentItem(¤tItem);
|
|
|
|
startFrame = NS_STATIC_CAST(nsIFrame*, currentItem);
|
|
|
|
if (startFrame) {
|
|
|
|
PRBool endEqualsStart(startContent == endContent);
|
|
|
|
startFrame->GetContent(getter_AddRefs(startContent));
|
|
|
|
if (endEqualsStart)
|
|
|
|
endContent = startContent;
|
|
|
|
}
|
|
|
|
else break;
|
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-04-27 01:20:48 +00:00
|
|
|
while (startContent == origStartContent);
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void nsEventStateManager::FocusElementButNotDocument(nsIContent *aContent)
|
|
|
|
{
|
|
|
|
// Focus an element in the current document, but don't switch document/window focus!
|
|
|
|
|
2003-01-07 02:09:06 +00:00
|
|
|
if (gLastFocusedDocument == mDocument || !gLastFocusedContent) {
|
|
|
|
// If we're already focused in this document,
|
|
|
|
// or if there was no last focus
|
|
|
|
// use normal focus method
|
2002-06-25 22:57:48 +00:00
|
|
|
if (mCurrentFocus != aContent) {
|
|
|
|
if (aContent)
|
|
|
|
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
|
|
|
|
|
|
|
// The last focus wasn't in this document, so we may be getting our position from the selection
|
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 the window focus is currently somewhere else such as the find dialog
|
|
|
|
|
|
|
|
// Temporarily save the current focus globals so we can leave them undisturbed after this method
|
|
|
|
nsCOMPtr<nsIContent> lastFocusedContent(gLastFocusedContent);
|
|
|
|
nsCOMPtr<nsIDocument> lastFocusedDocument(gLastFocusedDocument);
|
|
|
|
nsCOMPtr<nsIContent> lastFocusInThisDoc(mCurrentFocus);
|
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
gLastFocusedContent = mCurrentFocus;
|
|
|
|
gLastFocusedDocument = mDocument;
|
|
|
|
NS_IF_ADDREF(gLastFocusedDocument);
|
|
|
|
NS_IF_ADDREF(gLastFocusedContent);
|
|
|
|
|
|
|
|
// Focus the content, but don't change the document
|
|
|
|
SendFocusBlur(mPresContext, aContent, PR_FALSE);
|
|
|
|
mDocument->BeginUpdate();
|
|
|
|
if (!lastFocusInThisDoc)
|
|
|
|
lastFocusInThisDoc = mCurrentFocus;
|
2002-06-25 22:57:48 +00:00
|
|
|
if (mCurrentFocus)
|
|
|
|
mDocument->ContentStatesChanged(lastFocusInThisDoc, mCurrentFocus,
|
|
|
|
NS_EVENT_STATE_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
|
|
|
mDocument->EndUpdate();
|
|
|
|
FlushPendingEvents(mPresContext);
|
|
|
|
|
|
|
|
// Restore the global focus state
|
|
|
|
NS_IF_RELEASE(gLastFocusedDocument);
|
|
|
|
NS_IF_RELEASE(gLastFocusedContent);
|
|
|
|
gLastFocusedContent = lastFocusedContent;
|
|
|
|
gLastFocusedDocument = lastFocusedDocument;
|
|
|
|
NS_IF_ADDREF(gLastFocusedDocument);
|
|
|
|
NS_IF_ADDREF(gLastFocusedContent);
|
|
|
|
|
|
|
|
// Make sure our document's window's focus controller knows the focus has changed
|
|
|
|
// That way when our window is activated (PreHandleEvent get NS_ACTIVATE), the correct element & doc get focused
|
|
|
|
nsCOMPtr<nsIFocusController> focusController;
|
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement(do_QueryInterface(mCurrentFocus));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObj;
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(globalObj));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(globalObj));
|
|
|
|
NS_ASSERTION(win, "win is null. this happens [often on xlib builds]. see bug #79213");
|
|
|
|
if (win) {
|
|
|
|
win->GetRootFocusController(getter_AddRefs(focusController));
|
|
|
|
if (focusController && focusedElement)
|
|
|
|
focusController->SetFocusedElement(focusedElement);
|
|
|
|
}
|
|
|
|
|
2002-06-25 22:57:48 +00:00
|
|
|
if (mCurrentFocus)
|
|
|
|
TabIndexFrom(mCurrentFocus, &mCurrentTabIndex);
|
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
|
|
|
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);
|
|
|
|
|
|
|
|
if (!selectionContent)
|
|
|
|
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
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
testContent->GetTag(*getter_AddRefs(tag));
|
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
|
|
|
// Add better focusable test here later if necessary ...
|
|
|
|
if (nsHTMLAtoms::a == tag.get()) {
|
|
|
|
*aIsSelectionWithFocus = PR_TRUE;
|
2002-09-27 22:31:05 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aIsSelectionWithFocus = testContent->HasAttr(kNameSpaceID_XLink, nsHTMLAtoms::href);
|
|
|
|
if (*aIsSelectionWithFocus) {
|
|
|
|
nsAutoString xlinkType;
|
|
|
|
testContent->GetAttr(kNameSpaceID_XLink, nsHTMLAtoms::type, xlinkType);
|
|
|
|
if (!xlinkType.Equals(NS_LITERAL_STRING("simple"))) {
|
|
|
|
*aIsSelectionWithFocus = PR_FALSE; // Xlink must be type="simple"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
nsIContent* parent;
|
|
|
|
testContent->GetParent(parent);
|
|
|
|
testContent = dont_AddRef(parent);
|
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)
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
// Add better focusable test here later if necessary ...
|
|
|
|
if (testContent) {
|
|
|
|
testContent->GetTag(*getter_AddRefs(tag));
|
2001-02-15 05:07:46 +00:00
|
|
|
if (nsHTMLAtoms::a == tag.get()) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
mPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(pcContainer));
|
|
|
|
if (treeItem)
|
|
|
|
treeItem->GetItemType(&itemType);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
while (selectionContent) {
|
|
|
|
nsCOMPtr<nsIContent> parentContent;
|
|
|
|
selectionContent->GetParent(*getter_AddRefs(parentContent));
|
|
|
|
if (mCurrentFocus == selectionContent && parentContent)
|
|
|
|
return NS_OK; // selection is already within focus node that isn't the root content
|
|
|
|
selectionContent = parentContent; // Keep checking up chain of parents, focus may be in a link above us
|
|
|
|
}
|
|
|
|
|
2001-02-15 05:07:46 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
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
|
|
|
nsCOMPtr<nsIDOMNode> currentFocusNode(do_QueryInterface(mCurrentFocus));
|
|
|
|
nsCOMPtr<nsIFrameSelection> frameSelection;
|
|
|
|
shell->GetFrameSelection(getter_AddRefs(frameSelection));
|
|
|
|
|
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 (frameSelection && rangeDoc) {
|
2001-02-15 05:07:46 +00:00
|
|
|
nsCOMPtr<nsISelection> domSelection;
|
|
|
|
frameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
getter_AddRefs(domSelection));
|
|
|
|
if (domSelection) {
|
|
|
|
// 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();
|
2001-02-15 05:07:46 +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
|
|
|
if (currentFocusNode) {
|
|
|
|
nsresult rv = rangeDoc->CreateRange(getter_AddRefs(newRange));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// If we could create a new range, then set it to the current focus node
|
|
|
|
// And then collapse the selection
|
|
|
|
newRange->SelectNodeContents(currentFocusNode);
|
|
|
|
domSelection->AddRange(newRange);
|
|
|
|
domSelection->CollapseToStart();
|
|
|
|
}
|
2001-02-15 05:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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 nsEventStateManager::SetCaretEnabled(nsIPresShell *aPresShell, PRBool aEnabled)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (aEnabled) {
|
|
|
|
PRInt32 pixelWidth = 1;
|
|
|
|
nsCOMPtr<nsILookAndFeel> lookNFeel(do_GetService(kLookAndFeelCID));
|
|
|
|
if (lookNFeel)
|
|
|
|
lookNFeel->GetMetric(nsILookAndFeel::eMetric_MultiLineCaretWidth, pixelWidth);
|
|
|
|
caret->SetCaretWidth(pixelWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
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));
|
|
|
|
|
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<nsIFrameSelection> frameSelection, docFrameSelection;
|
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) {
|
|
|
|
nsIFrame *focusFrame = nsnull;
|
|
|
|
aPresShell->GetPrimaryFrameFor(aFocusedContent, &focusFrame);
|
|
|
|
|
|
|
|
GetSelection(focusFrame, mPresContext, getter_AddRefs(frameSelection));
|
|
|
|
}
|
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
|
|
|
aPresShell->GetFrameSelection(getter_AddRefs(docFrameSelection));
|
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 (docFrameSelection && caret &&
|
|
|
|
(frameSelection == docFrameSelection || !aFocusedContent)) {
|
|
|
|
nsCOMPtr<nsISelection> domSelection;
|
|
|
|
docFrameSelection->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSelection));
|
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
|
|
|
}
|
|
|
|
}
|
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
|
|
|
return NS_OK;
|
|
|
|
}
|
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
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::ResetBrowseWithCaret(PRBool *aBrowseWithCaret)
|
|
|
|
{
|
|
|
|
// This is called when browse with caret changes on the fly
|
|
|
|
// or when a document gets focused
|
|
|
|
|
2002-04-02 01:56:22 +00:00
|
|
|
*aBrowseWithCaret = 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
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
mPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
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)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (itemType == nsIDocShellTreeItem::typeChrome)
|
|
|
|
return NS_OK; // Never browse with caret in chrome
|
|
|
|
|
2002-11-25 23:26:06 +00:00
|
|
|
mPrefBranch->GetBoolPref("accessibility.browsewithcaret", aBrowseWithCaret);
|
2002-04-02 01:56:22 +00:00
|
|
|
|
|
|
|
if (mBrowseWithCaret == *aBrowseWithCaret)
|
|
|
|
return NS_OK; // already set this way, don't change caret at all
|
|
|
|
|
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
|
|
|
mBrowseWithCaret = *aBrowseWithCaret;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
|
|
|
|
// Make caret visible or not, depending on what's appropriate
|
2002-08-19 02:58:15 +00:00
|
|
|
if (presShell) {
|
|
|
|
return SetContentCaretVisible(presShell, mCurrentFocus,
|
|
|
|
*aBrowseWithCaret &&
|
|
|
|
(!gLastFocusedDocument ||
|
|
|
|
gLastFocusedDocument == mDocument));
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
presShell->GetDocument(getter_AddRefs(doc));
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(doc);
|
|
|
|
if (htmlDoc) {
|
|
|
|
nsCOMPtr<nsIContent> rootContent;
|
|
|
|
doc->GetRootContent(getter_AddRefs(rootContent));
|
|
|
|
if (rootContent) {
|
|
|
|
PRInt32 childCount;
|
|
|
|
rootContent->ChildCount(childCount);
|
|
|
|
for (PRInt32 i = 0; i < childCount; ++i) {
|
|
|
|
nsCOMPtr<nsIContent> childContent;
|
|
|
|
rootContent->ChildAt(i, *getter_AddRefs(childContent));
|
|
|
|
nsCOMPtr<nsIAtom> childTag;
|
|
|
|
childContent->GetTag(*getter_AddRefs(childTag));
|
|
|
|
if (childTag == nsHTMLAtoms::frameset) {
|
|
|
|
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
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(aDocShell);
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentItem;
|
|
|
|
treeItem->GetParent(getter_AddRefs(parentItem));
|
|
|
|
if (!parentItem)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> parentDS = do_QueryInterface(parentItem);
|
2002-04-17 04:17:16 +00:00
|
|
|
nsCOMPtr<nsIPresShell> parentPresShell;
|
|
|
|
parentDS->GetPresShell(getter_AddRefs(parentPresShell));
|
|
|
|
NS_ASSERTION(parentPresShell, "presshell is null");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> parentDoc;
|
|
|
|
parentPresShell->GetDocument(getter_AddRefs(parentDoc));
|
|
|
|
|
2002-09-09 19:32:04 +00:00
|
|
|
// The current docshell may not have a presshell, eg if it's a display:none
|
|
|
|
// iframe or if the presshell just hasn't been created yet. Get the
|
|
|
|
// document off the docshell directly.
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_GetInterface(aDocShell);
|
|
|
|
if (!domDoc) {
|
|
|
|
NS_ERROR("No document in docshell! How are we to decide whether this"
|
|
|
|
" is an iframe? Arbitrarily deciding it's not.");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
|
|
|
NS_ASSERTION(doc, "DOM document not implementing nsIDocument");
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsIContent> docContent;
|
2002-04-17 04:17:16 +00:00
|
|
|
|
|
|
|
parentDoc->FindContentForSubDocument(doc, getter_AddRefs(docContent));
|
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
if (!docContent)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
docContent->GetTag(*getter_AddRefs(tag));
|
|
|
|
return (tag == nsHTMLAtoms::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;
|
|
|
|
|
|
|
|
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
|
|
|
|
// the docshell, traverse into the document if this type
|
|
|
|
// of document does not get document focus (i.e. framsets
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
PRBool focusDocument;
|
|
|
|
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);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresContext> pc;
|
|
|
|
aDocShell->GetPresContext(getter_AddRefs(pc));
|
|
|
|
if (pc) {
|
|
|
|
nsCOMPtr<nsIEventStateManager> docESM;
|
|
|
|
pc->GetEventStateManager(getter_AddRefs(docESM));
|
|
|
|
if (docESM) {
|
|
|
|
// 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);
|
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");
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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");
|
2002-02-01 23:56:48 +00:00
|
|
|
PRInt32 numChildren = 0;
|
2001-10-22 22:43:52 +00:00
|
|
|
|
2002-03-27 04:43:52 +00:00
|
|
|
*aResult = nsnull;
|
|
|
|
|
2002-02-01 23:56:48 +00:00
|
|
|
aNode->GetChildCount(&numChildren);
|
2002-03-27 04:43:52 +00:00
|
|
|
if (numChildren) {
|
|
|
|
aNode->GetChildAt(0, aResult);
|
|
|
|
if (*aResult)
|
|
|
|
return;
|
2002-02-01 23:56:48 +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
|
|
|
}
|
2001-10-22 22:43:52 +00:00
|
|
|
|
|
|
|
PRInt32 childOffset = 0;
|
|
|
|
curItem->GetChildOffset(&childOffset);
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> parentNode = do_QueryInterface(parentItem);
|
2002-02-01 23:56:48 +00:00
|
|
|
numChildren = 0;
|
|
|
|
parentNode->GetChildCount(&numChildren);
|
2002-03-31 04:53:53 +00:00
|
|
|
if (childOffset+1 < numChildren) {
|
|
|
|
parentNode->GetChildAt(childOffset+1, aResult);
|
|
|
|
if (*aResult)
|
|
|
|
return;
|
2002-02-01 23:56:48 +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");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> curNode = aNode;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> curItem = do_QueryInterface(curNode);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 childOffset = 0;
|
|
|
|
curItem->GetChildOffset(&childOffset);
|
|
|
|
if (childOffset) {
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> parentNode = do_QueryInterface(parentItem);
|
|
|
|
parentNode->GetChildAt(childOffset - 1, getter_AddRefs(curItem));
|
|
|
|
|
|
|
|
// get the last child recursively of this node
|
|
|
|
while (1) {
|
|
|
|
PRInt32 childCount = 0;
|
|
|
|
curNode = do_QueryInterface(curItem);
|
|
|
|
curNode->GetChildCount(&childCount);
|
|
|
|
if (!childCount)
|
|
|
|
break;
|
|
|
|
|
|
|
|
curNode->GetChildAt(childCount - 1, getter_AddRefs(curItem));
|
2001-05-22 23:52:17 +00:00
|
|
|
}
|
2001-10-22 22:43:52 +00:00
|
|
|
|
|
|
|
*aResult = curItem;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return;
|
2001-05-22 23:52:17 +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.
|
|
|
|
|
|
|
|
NS_ASSERTION(mPresContext, "no prescontext");
|
2001-05-22 23:52:17 +00:00
|
|
|
|
2001-10-22 22:43:52 +00:00
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
mPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> curNode = do_QueryInterface(pcContainer);
|
|
|
|
|
|
|
|
// perform a depth first search (preorder) of the docshell tree
|
|
|
|
// looking for an HTML Frame or a chrome document
|
|
|
|
|
|
|
|
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
|
|
|
|
nsIFocusController*
|
|
|
|
nsEventStateManager::GetFocusControllerForDocument(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
aDocument->GetContainer(getter_AddRefs(container));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> windowPrivate = do_GetInterface(container);
|
|
|
|
nsIFocusController* fc;
|
|
|
|
if (windowPrivate)
|
|
|
|
windowPrivate->GetRootFocusController(&fc);
|
|
|
|
else
|
|
|
|
fc = nsnull;
|
|
|
|
|
|
|
|
return fc;
|
|
|
|
}
|