1998-06-23 21:53:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +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
|
|
|
*
|
1999-11-06 03:40:37 +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.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-06-23 21:53:02 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-06-23 21:53:02 +00:00
|
|
|
*/
|
2000-03-16 03:34:52 +00:00
|
|
|
#define FORCE_PR_LOG
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-06-23 21:53:02 +00:00
|
|
|
#include "nsIEventStateManager.h"
|
|
|
|
#include "nsEventStateManager.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 "nsIStyleContext.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsDOMEvent.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#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"
|
|
|
|
#include "nsINameSpaceManager.h" // for kNameSpaceID_HTML
|
|
|
|
#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"
|
1999-05-07 21:12:59 +00:00
|
|
|
#include "nsIDOMSelection.h"
|
|
|
|
#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"
|
1999-12-18 04:02:28 +00:00
|
|
|
#include "nsIGfxTextControlFrame.h"
|
2000-02-11 23:41:13 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
1999-12-18 04:02:28 +00:00
|
|
|
#include "nsPIDOMWindow.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"
|
|
|
|
#include "nsIWebNavigation.h"
|
1999-08-19 19:48:45 +00:00
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPref.h"
|
|
|
|
|
2000-01-13 11:43:54 +00:00
|
|
|
#include "nsXULAtoms.h"
|
2000-02-11 23:41:13 +00:00
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
#include "nsIDOMXULCommandDispatcher.h"
|
2000-03-15 04:03:44 +00:00
|
|
|
#include "nsIObserverService.h"
|
2000-04-15 03:43:09 +00:00
|
|
|
#include "prlog.h"
|
2000-05-15 02:10:11 +00:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIMarkupDocumentViewer.h"
|
2000-06-28 20:35:32 +00:00
|
|
|
#include "nsITreeFrame.h"
|
2000-01-13 11:43:54 +00:00
|
|
|
|
1999-12-11 00:02:08 +00:00
|
|
|
//we will use key binding by default now. this wil lbreak viewer for now
|
|
|
|
#define NON_KEYBINDING 0
|
|
|
|
|
2000-03-15 04:03:44 +00:00
|
|
|
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
|
|
|
|
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
|
|
|
|
2000-03-16 03:34:52 +00:00
|
|
|
PRLogModuleInfo *MOUSEWHEEL;
|
|
|
|
|
1999-12-01 09:09:46 +00:00
|
|
|
PRUint32 nsEventStateManager::mInstanceCount = 0;
|
|
|
|
|
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),
|
|
|
|
m_haveShutdown(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;
|
1999-06-15 03:14:28 +00:00
|
|
|
mCurrentTargetContent = nsnull;
|
1999-11-03 07:11:45 +00:00
|
|
|
mCurrentRelatedContent = nsnull;
|
1999-03-28 22:22:54 +00:00
|
|
|
mLastLeftMouseDownContent = nsnull;
|
|
|
|
mLastMiddleMouseDownContent = nsnull;
|
|
|
|
mLastRightMouseDownContent = 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;
|
1999-03-28 22:22:54 +00:00
|
|
|
mActiveContent = nsnull;
|
|
|
|
mHoverContent = nsnull;
|
1999-05-04 14:44:51 +00:00
|
|
|
mDragOverContent = nsnull;
|
1998-11-18 05:25:26 +00:00
|
|
|
mCurrentFocus = nsnull;
|
|
|
|
mDocument = nsnull;
|
|
|
|
mPresContext = nsnull;
|
1999-03-02 19:19:24 +00:00
|
|
|
mCurrentTabIndex = 0;
|
1999-09-20 22:18:57 +00:00
|
|
|
mLastWindowToHaveFocus = nsnull;
|
2000-02-11 05:20:44 +00:00
|
|
|
mFirstBlurEvent = nsnull;
|
|
|
|
mFirstFocusEvent = nsnull;
|
2000-05-16 10:22:20 +00:00
|
|
|
mAccessKeys = nsnull;
|
1998-06-25 14:51:48 +00:00
|
|
|
NS_INIT_REFCNT();
|
1999-12-01 09:09:46 +00:00
|
|
|
|
|
|
|
++mInstanceCount;
|
2000-03-16 03:34:52 +00:00
|
|
|
if (!MOUSEWHEEL)
|
|
|
|
MOUSEWHEEL = PR_NewLogModule("MOUSEWHEEL");
|
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;
|
|
|
|
NS_WITH_SERVICE(nsIObserverService, observerService,
|
|
|
|
NS_OBSERVERSERVICE_PROGID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2000-04-03 11:20:35 +00:00
|
|
|
nsAutoString topic; topic.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
2000-03-15 04:03:44 +00:00
|
|
|
observerService->AddObserver(this, topic.GetUnicode());
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = getPrefService();
|
|
|
|
return rv;
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
1999-09-16 14:54:59 +00:00
|
|
|
nsEventStateManager::~nsEventStateManager()
|
|
|
|
{
|
1999-06-15 03:14:28 +00:00
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
1999-11-03 07:11:45 +00:00
|
|
|
NS_IF_RELEASE(mCurrentRelatedContent);
|
1999-09-16 14:54:59 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mLastLeftMouseDownContent);
|
|
|
|
NS_IF_RELEASE(mLastMiddleMouseDownContent);
|
|
|
|
NS_IF_RELEASE(mLastRightMouseDownContent);
|
|
|
|
|
1999-03-28 22:22:54 +00:00
|
|
|
NS_IF_RELEASE(mActiveContent);
|
|
|
|
NS_IF_RELEASE(mHoverContent);
|
1999-05-04 14:44:51 +00:00
|
|
|
NS_IF_RELEASE(mDragOverContent);
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IF_RELEASE(mCurrentFocus);
|
1999-09-16 14:54:59 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IF_RELEASE(mDocument);
|
1999-09-20 22:18:57 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mLastWindowToHaveFocus);
|
2000-02-11 05:20:44 +00:00
|
|
|
NS_IF_RELEASE(mFirstBlurEvent);
|
|
|
|
NS_IF_RELEASE(mFirstFocusEvent);
|
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;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE (nsIObserverService, observerService,
|
|
|
|
NS_OBSERVERSERVICE_PROGID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2000-04-03 11:20:35 +00:00
|
|
|
nsAutoString topic; topic.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
2000-03-15 04:03:44 +00:00
|
|
|
observerService->RemoveObserver(this, topic.GetUnicode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
2000-03-15 04:03:44 +00:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::Shutdown()
|
|
|
|
{
|
|
|
|
if (mPrefService) {
|
|
|
|
mPrefService = null_nsCOMPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_haveShutdown = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEventStateManager::getPrefService()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mPrefService) {
|
|
|
|
mPrefService = do_GetService(kPrefCID, &rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!mPrefService) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::Observe(nsISupports *aSubject, const PRUnichar *aTopic,
|
|
|
|
const PRUnichar *someData) {
|
|
|
|
nsAutoString topicString(aTopic);
|
2000-04-03 11:20:35 +00:00
|
|
|
nsAutoString shutdownString; shutdownString.AssignWithConversion(NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
2000-03-15 04:03:44 +00:00
|
|
|
|
|
|
|
if (topicString == shutdownString)
|
|
|
|
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,
|
2000-04-24 04:41:27 +00:00
|
|
|
nsEvent *aEvent,
|
1998-11-18 05:25:26 +00:00
|
|
|
nsIFrame* aTargetFrame,
|
1999-11-24 06:03:41 +00:00
|
|
|
nsEventStatus* aStatus,
|
1999-06-15 03:14:28 +00:00
|
|
|
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;
|
1999-06-15 03:14:28 +00:00
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
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;
|
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:
|
2000-04-24 04:41:27 +00:00
|
|
|
BeginTrackingDragGesture ( (nsGUIEvent*)aEvent, aTargetFrame );
|
1999-09-22 02:29:33 +00:00
|
|
|
mLClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
|
|
|
|
mMClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_DOWN:
|
|
|
|
mRClickCount = ((nsMouseEvent*)aEvent)->clickCount;
|
|
|
|
SetClickCount(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
1999-08-19 19:48:45 +00:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
StopTrackingDragGesture();
|
1999-09-22 02:29:33 +00:00
|
|
|
case NS_MOUSE_MIDDLE_BUTTON_UP:
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
|
|
|
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);
|
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;
|
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-02-16 06:26:41 +00:00
|
|
|
#ifdef DEBUG_hyatt
|
2000-02-11 23:41:13 +00:00
|
|
|
printf("Got focus.\n");
|
2000-02-16 06:26:41 +00:00
|
|
|
#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)
|
1999-12-18 04:02:28 +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-05-03 00:49:37 +00:00
|
|
|
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
|
2000-06-23 05:37:08 +00:00
|
|
|
|
2000-05-03 00:49:37 +00:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> ourGlobal;
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
|
|
|
nsCOMPtr<nsIDOMWindow> rootWindow;
|
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(ourGlobal);
|
|
|
|
if(ourWindow) {
|
2000-06-23 05:37:08 +00:00
|
|
|
ourWindow->GetRootCommandDispatcher(gLastFocusedDocument, getter_AddRefs(commandDispatcher));
|
|
|
|
if (commandDispatcher)
|
|
|
|
commandDispatcher->SetSuppressFocus(PR_TRUE);
|
2000-05-03 00:49:37 +00:00
|
|
|
}
|
|
|
|
|
2000-06-14 02:59:54 +00:00
|
|
|
gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &blurevent, nsnull, NS_EVENT_FLAG_INIT, &blurstatus);
|
|
|
|
if (!mCurrentFocus && gLastFocusedContent)// must send it to the element that is loosing focus. since SendFocusBlur wont be called
|
|
|
|
gLastFocusedContent->HandleDOMEvent(gLastFocusedPresContext, &blurevent, nsnull, NS_EVENT_FLAG_INIT, &blurstatus);
|
|
|
|
|
2000-06-29 05:27:05 +00:00
|
|
|
|
2000-05-03 00:49:37 +00:00
|
|
|
if (commandDispatcher) {
|
|
|
|
commandDispatcher->SetSuppressFocus(PR_FALSE);
|
|
|
|
}
|
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) {
|
|
|
|
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
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
globalObject->HandleDOMEvent(aPresContext, &focusevent, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
mCurrentFocus = currentFocus;
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_LOSTFOCUS:
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
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);
|
1999-07-27 20:55:03 +00:00
|
|
|
|
2000-02-11 23:41:13 +00:00
|
|
|
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
|
|
|
|
nsCOMPtr<nsIDOMElement> focusedElement;
|
|
|
|
nsCOMPtr<nsIDOMWindow> focusedWindow;
|
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(mDocument);
|
2000-02-26 01:02:31 +00:00
|
|
|
|
2000-02-11 23:41:13 +00:00
|
|
|
if (xulDoc) {
|
|
|
|
// See if we have a command dispatcher attached.
|
|
|
|
xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));
|
|
|
|
if (commandDispatcher) {
|
|
|
|
// Obtain focus info from the command dispatcher.
|
|
|
|
commandDispatcher->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
|
|
|
commandDispatcher->GetFocusedElement(getter_AddRefs(focusedElement));
|
2000-05-11 22:40:51 +00:00
|
|
|
|
|
|
|
commandDispatcher->SetSuppressFocusScroll(PR_TRUE);
|
2000-02-11 23:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
1999-11-13 05:16:33 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
if (!focusedWindow) {
|
|
|
|
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
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
// Sill no focused XULDocument, that is bad
|
|
|
|
if(!xulDoc && focusedWindow)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> privateWindow = do_QueryInterface(focusedWindow);
|
2000-02-26 01:02:31 +00:00
|
|
|
if(privateWindow){
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> privateRootWindow;
|
|
|
|
privateWindow->GetPrivateRoot(getter_AddRefs(privateRootWindow));
|
|
|
|
if(privateRootWindow) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> privateParentDoc;
|
|
|
|
privateRootWindow->GetDocument(getter_AddRefs(privateParentDoc));
|
2000-02-26 01:02:31 +00:00
|
|
|
xulDoc = do_QueryInterface(privateParentDoc);
|
2000-04-04 23:55:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xulDoc) {
|
2000-02-26 01:02:31 +00:00
|
|
|
// See if we have a command dispatcher attached.
|
|
|
|
xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));
|
|
|
|
if (commandDispatcher) {
|
|
|
|
// Obtain focus info from the command dispatcher.
|
|
|
|
commandDispatcher->GetFocusedWindow(getter_AddRefs(focusedWindow));
|
|
|
|
commandDispatcher->GetFocusedElement(getter_AddRefs(focusedElement));
|
2000-05-11 22:40:51 +00:00
|
|
|
|
|
|
|
commandDispatcher->SetSuppressFocusScroll(PR_TRUE);
|
2000-04-04 23:55:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-26 01:02:31 +00:00
|
|
|
|
2000-02-11 23:41:13 +00:00
|
|
|
// Focus the DOM window.
|
2000-06-23 22:18:54 +00:00
|
|
|
if(focusedWindow)
|
|
|
|
focusedWindow->Focus();
|
2000-02-11 23:41:13 +00:00
|
|
|
|
|
|
|
if (focusedElement) {
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIContent> focusContent = do_QueryInterface(focusedElement);
|
2000-02-11 23:41:13 +00:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
nsCOMPtr<nsIDocument> document;
|
|
|
|
focusedWindow->GetDocument(getter_AddRefs(domDoc));
|
2000-06-23 01:54:20 +00:00
|
|
|
if (domDoc) {
|
|
|
|
document = do_QueryInterface(domDoc);
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsCOMPtr<nsIPresContext> context;
|
|
|
|
shell = getter_AddRefs(document->GetShellAt(0));
|
|
|
|
shell->GetPresContext(getter_AddRefs(context));
|
|
|
|
focusContent->SetFocus(context);
|
|
|
|
}
|
2000-02-11 23:41:13 +00:00
|
|
|
}
|
|
|
|
|
2000-02-26 01:02:31 +00:00
|
|
|
if (commandDispatcher) {
|
|
|
|
commandDispatcher->SetActive(PR_TRUE);
|
2000-02-29 03:54:49 +00:00
|
|
|
commandDispatcher->SetSuppressFocus(PR_FALSE); // Unsuppress and let the command dispatcher listen again.
|
2000-05-11 22:40:51 +00:00
|
|
|
commandDispatcher->SetSuppressFocusScroll(PR_FALSE);
|
2000-02-29 03:54:49 +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
|
|
|
|
|
|
|
// 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));
|
2000-02-15 00:28:43 +00:00
|
|
|
if(doc)
|
|
|
|
doc->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
|
|
|
else {
|
|
|
|
mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
|
|
|
NS_RELEASE(gLastFocusedContent);
|
|
|
|
}
|
|
|
|
}
|
2000-02-11 23:41:13 +00:00
|
|
|
else mDocument->GetScriptGlobalObject(getter_AddRefs(ourGlobal));
|
|
|
|
|
|
|
|
// 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.
|
2000-03-21 00:47:19 +00:00
|
|
|
nsCOMPtr<nsIDOMXULCommandDispatcher> commandDispatcher;
|
2000-02-11 23:41:13 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> rootWindow;
|
|
|
|
nsCOMPtr<nsPIDOMWindow> ourWindow = do_QueryInterface(ourGlobal);
|
2000-03-21 00:47:19 +00:00
|
|
|
if(ourWindow) {
|
|
|
|
ourWindow->GetPrivateRoot(getter_AddRefs(rootWindow));
|
|
|
|
if(rootWindow) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> rootDocument;
|
|
|
|
rootWindow->GetDocument(getter_AddRefs(rootDocument));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(rootDocument);
|
|
|
|
if (xulDoc) {
|
|
|
|
// See if we have a command dispatcher attached.
|
|
|
|
xulDoc->GetCommandDispatcher(getter_AddRefs(commandDispatcher));
|
|
|
|
if (commandDispatcher) {
|
|
|
|
// Suppress the command dispatcher.
|
|
|
|
commandDispatcher->SetSuppressFocus(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
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.
|
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(0));
|
2000-04-05 02:10:25 +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);
|
|
|
|
}
|
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
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
2000-03-21 00:47:19 +00:00
|
|
|
if(gLastFocusedDocument) {
|
|
|
|
gLastFocusedDocument->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
2000-06-09 21:13:03 +00:00
|
|
|
//gLastFocusedDocument->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
2000-03-21 00:47:19 +00:00
|
|
|
if(globalObject)
|
|
|
|
globalObject->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
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-02-26 01:02:31 +00:00
|
|
|
if (commandDispatcher) {
|
|
|
|
commandDispatcher->SetActive(PR_FALSE);
|
2000-06-23 05:37:08 +00:00
|
|
|
//commandDispatcher->SetSuppressFocus(PR_FALSE);
|
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;
|
2000-06-02 14:20:50 +00:00
|
|
|
#ifdef XP_MAC
|
2000-06-05 13:48:06 +00:00
|
|
|
PRBool isSpecialAccessKeyDown = keyEvent->isMeta;
|
2000-06-02 14:20:50 +00:00
|
|
|
#else
|
|
|
|
PRBool isSpecialAccessKeyDown = keyEvent->isAlt;
|
|
|
|
#endif
|
2000-05-16 10:22:20 +00:00
|
|
|
//This is to prevent keyboard scrolling while alt modifier in use.
|
2000-06-02 14:20:50 +00:00
|
|
|
if (isSpecialAccessKeyDown) {
|
2000-05-16 10:22:20 +00:00
|
|
|
//Alt key is down, we may need to do an accesskey
|
|
|
|
if (mAccessKeys) {
|
|
|
|
//Someone registered an accesskey. Find and activate it.
|
|
|
|
nsVoidKey key((void*)keyEvent->charCode);
|
|
|
|
if (mAccessKeys->Exists(&key)) {
|
|
|
|
nsCOMPtr<nsIContent> content = getter_AddRefs(NS_STATIC_CAST(nsIContent*, mAccessKeys->Get(&key)));
|
|
|
|
|
|
|
|
//Its hard to say what HTML4 wants us to do in all cases. So for now we'll settle for
|
|
|
|
//A) Set focus
|
|
|
|
ChangeFocus(content, nsnull, PR_TRUE);
|
|
|
|
|
|
|
|
//B) Click on it.
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_GUI_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);
|
|
|
|
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-27 20:55:03 +00:00
|
|
|
case NS_KEY_DOWN:
|
|
|
|
case NS_KEY_UP:
|
1999-11-21 01:46:41 +00:00
|
|
|
case NS_MOUSE_SCROLL:
|
1999-07-27 14:38:07 +00:00
|
|
|
{
|
1999-07-27 20:55:03 +00:00
|
|
|
if (mCurrentFocus) {
|
|
|
|
mCurrentTargetContent = mCurrentFocus;
|
|
|
|
NS_ADDREF(mCurrentTargetContent);
|
|
|
|
}
|
1999-07-27 14:38:07 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
void
|
|
|
|
nsEventStateManager :: BeginTrackingDragGesture ( nsGUIEvent* inDownEvent, nsIFrame* inDownFrame )
|
|
|
|
{
|
|
|
|
mIsTrackingDragGesture = PR_TRUE;
|
|
|
|
mGestureDownPoint = inDownEvent->point;
|
|
|
|
mGestureDownFrame = inDownFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// a drag too early, or very similiar which might not trigger a drag.
|
|
|
|
//
|
|
|
|
// 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!
|
|
|
|
|
2000-05-31 03:20:02 +00:00
|
|
|
if (mGestureDownFrame) {
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
nsresult rv = mGestureDownFrame->GetSelectionController(aPresContext, getter_AddRefs(selCon));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && selCon) {
|
|
|
|
nsCOMPtr<nsIFrameSelection> frameSel;
|
|
|
|
|
|
|
|
frameSel = do_QueryInterface(selCon);
|
|
|
|
|
|
|
|
if (! frameSel) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult rv = aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && shell)
|
|
|
|
rv = shell->GetFrameSelection(getter_AddRefs(frameSel));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && 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 ) {
|
|
|
|
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
|
|
|
|
|
|
|
// dispatch to the DOM
|
|
|
|
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 )
|
1999-11-24 06:03:41 +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
|
1999-11-02 03:55:14 +00:00
|
|
|
if ( mGestureDownFrame )
|
1999-11-24 06:03:41 +00:00
|
|
|
mGestureDownFrame->HandleEvent(aPresContext, &event, &status);
|
1999-08-19 19:48:45 +00:00
|
|
|
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // GenerateDragGesture
|
|
|
|
|
2000-05-15 02:10:11 +00:00
|
|
|
nsresult
|
|
|
|
nsEventStateManager::ChangeTextSize(PRInt32 change)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> pcContainer;
|
|
|
|
mPresContext->GetContainer(getter_AddRefs(pcContainer));
|
|
|
|
NS_ENSURE_TRUE(pcContainer, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docshell(do_QueryInterface(pcContainer));
|
|
|
|
NS_ENSURE_TRUE(docshell, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
|
|
|
docshell->GetContentViewer(getter_AddRefs(cv));
|
|
|
|
NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMarkupDocumentViewer> mv(do_QueryInterface(cv));
|
|
|
|
NS_ENSURE_TRUE(mv, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
float textzoom;
|
|
|
|
mv->GetTextZoom(&textzoom);
|
|
|
|
mv->SetTextZoom(textzoom + 0.1*change);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-19 19:48:45 +00:00
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 06:03:41 +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;
|
1999-06-15 03:14:28 +00:00
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
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:
|
|
|
|
{
|
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;
|
|
|
|
mCurrentTarget->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));;
|
|
|
|
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;
|
|
|
|
// Look for the nearest enclosing focusable frame.
|
|
|
|
while (currFrame) {
|
|
|
|
const nsStyleUserInterface* ui;
|
|
|
|
currFrame->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));;
|
|
|
|
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)
|
|
|
|
ChangeFocus(newFocus, currFrame, PR_TRUE);
|
|
|
|
else if (!suppressBlur)
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
1999-09-30 11:40:42 +00:00
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
SetContentState(newFocus, NS_EVENT_STATE_ACTIVE);
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
ret = CheckForAndDispatchClick(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
1999-09-22 02:29:33 +00:00
|
|
|
|
1999-05-07 21:12:59 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_ACTIVE);
|
|
|
|
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;
|
|
|
|
rv = getPrefService();
|
|
|
|
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-03-15 04:03:44 +00:00
|
|
|
PRBool aBool;
|
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
|
|
|
|
if (msEvent->isShift) {
|
2000-03-15 04:03:44 +00:00
|
|
|
mPrefService->GetIntPref("mousewheel.withshiftkey.action", &action);
|
|
|
|
mPrefService->GetBoolPref("mousewheel.withshiftkey.sysnumlines", &aBool);
|
|
|
|
if (aBool)
|
2000-01-06 06:22:00 +00:00
|
|
|
numLines = msEvent->deltaLines;
|
|
|
|
else
|
2000-03-15 04:03:44 +00:00
|
|
|
mPrefService->GetIntPref("mousewheel.withshiftkey.numlines", &numLines);
|
2000-01-06 06:22:00 +00:00
|
|
|
} else if (msEvent->isControl) {
|
2000-03-15 04:03:44 +00:00
|
|
|
mPrefService->GetIntPref("mousewheel.withcontrolkey.action", &action);
|
|
|
|
mPrefService->GetBoolPref("mousewheel.withcontrolkey.sysnumlines", &aBool);
|
|
|
|
if (aBool)
|
2000-01-06 06:22:00 +00:00
|
|
|
numLines = msEvent->deltaLines;
|
|
|
|
else
|
2000-03-15 04:03:44 +00:00
|
|
|
mPrefService->GetIntPref("mousewheel.withcontrolkey.numlines", &numLines);
|
2000-01-06 06:22:00 +00:00
|
|
|
} else if (msEvent->isAlt) {
|
2000-03-15 04:03:44 +00:00
|
|
|
mPrefService->GetIntPref("mousewheel.withaltkey.action", &action);
|
|
|
|
mPrefService->GetBoolPref("mousewheel.withaltkey.sysnumlines", &aBool);
|
|
|
|
if (aBool)
|
2000-01-06 06:22:00 +00:00
|
|
|
numLines = msEvent->deltaLines;
|
|
|
|
else
|
2000-03-15 04:03:44 +00:00
|
|
|
mPrefService->GetIntPref("mousewheel.withaltkey.numlines", &numLines);
|
2000-01-06 06:22:00 +00:00
|
|
|
} else {
|
2000-03-15 04:03:44 +00:00
|
|
|
mPrefService->GetIntPref("mousewheel.withnokey.action", &action);
|
|
|
|
mPrefService->GetBoolPref("mousewheel.withnokey.sysnumlines", &aBool);
|
|
|
|
if (aBool)
|
2000-01-06 06:22:00 +00:00
|
|
|
numLines = msEvent->deltaLines;
|
|
|
|
else
|
2000-03-15 04:03:44 +00:00
|
|
|
mPrefService->GetIntPref("mousewheel.withnokey.numlines", &numLines);
|
2000-01-06 06:22:00 +00:00
|
|
|
}
|
1999-11-21 01:46:41 +00:00
|
|
|
|
2000-01-06 06:22:00 +00:00
|
|
|
if ((msEvent->deltaLines < 0) && (numLines > 0))
|
|
|
|
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
|
|
|
{
|
|
|
|
nsIView* focusView = nsnull;
|
2000-01-11 22:30:22 +00:00
|
|
|
nsIScrollableView* sv = nsnull;
|
2000-06-28 20:35:32 +00:00
|
|
|
nsIFrame* focusFrame = nsnull;
|
|
|
|
|
|
|
|
// Special case for tree frames - they handle their own scrolling
|
2000-07-06 02:44:48 +00:00
|
|
|
nsITreeFrame* treeFrame = nsnull;
|
2000-06-28 20:35:32 +00:00
|
|
|
nsIFrame* curFrame = aTargetFrame;
|
|
|
|
|
|
|
|
while (curFrame) {
|
|
|
|
if (NS_OK == curFrame->QueryInterface(NS_GET_IID(nsITreeFrame), (void**) &treeFrame))
|
|
|
|
break;
|
|
|
|
curFrame->GetParent(&curFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (treeFrame) {
|
|
|
|
PRInt32 scrollIndex, visibleRows;
|
|
|
|
treeFrame->GetIndexOfFirstVisibleRow(&scrollIndex);
|
|
|
|
treeFrame->GetNumberOfVisibleRows(&visibleRows);
|
|
|
|
|
|
|
|
if (action == MOUSE_SCROLL_N_LINES)
|
|
|
|
scrollIndex += numLines;
|
|
|
|
else
|
|
|
|
scrollIndex += ((numLines > 0) ? visibleRows : -visibleRows);
|
|
|
|
|
|
|
|
if (scrollIndex < 0)
|
|
|
|
scrollIndex = 0;
|
|
|
|
else {
|
|
|
|
PRInt32 numRows, lastPageTopRow;
|
|
|
|
treeFrame->GetRowCount(&numRows);
|
|
|
|
lastPageTopRow = numRows - visibleRows;
|
|
|
|
if (scrollIndex > lastPageTopRow)
|
|
|
|
scrollIndex = lastPageTopRow;
|
1999-11-21 01:46:41 +00:00
|
|
|
}
|
2000-04-01 20:09:54 +00:00
|
|
|
|
2000-06-28 20:35:32 +00:00
|
|
|
treeFrame->ScrollToIndex(scrollIndex);
|
|
|
|
break;
|
|
|
|
}
|
2000-04-01 20:09:54 +00:00
|
|
|
|
2000-06-28 20:35:32 +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);
|
|
|
|
focusContent = dont_AddRef(mDocument->GetRootContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!focusContent)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Get the content's view and scroll it.
|
|
|
|
presShell->GetPrimaryFrameFor(focusContent, &focusFrame);
|
|
|
|
if (focusFrame) {
|
|
|
|
focusFrame->GetView(aPresContext, &focusView);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!focusView) {
|
|
|
|
nsIFrame* frameWithView;
|
|
|
|
focusFrame->GetParentWithView(aPresContext, &frameWithView);
|
|
|
|
if (frameWithView)
|
|
|
|
frameWithView->GetView(aPresContext, &focusView);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sv = GetNearestScrollingView(focusView);
|
|
|
|
if (sv) {
|
|
|
|
if (action == MOUSE_SCROLL_N_LINES)
|
|
|
|
sv->ScrollByLines(0, numLines);
|
|
|
|
else
|
|
|
|
sv->ScrollByPages((numLines > 0) ? 1 : -1);
|
|
|
|
ForceViewUpdate(focusView);
|
|
|
|
}
|
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) {
|
|
|
|
if (numLines > 0)
|
|
|
|
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:
|
2000-05-15 02:10:11 +00:00
|
|
|
ChangeTextSize((numLines > 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;
|
|
|
|
|
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;
|
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:
|
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
|
|
|
|
ShiftFocus(!((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
|
|
|
|
|
|
|
//the problem is that viewer does not have xul so we cannot completely eliminate these
|
|
|
|
#if NON_KEYBINDING
|
1999-11-22 19:45:13 +00:00
|
|
|
case NS_VK_PAGE_DOWN:
|
|
|
|
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;
|
|
|
|
if (NS_OK == aView->GetViewManager(vm) && nsnull != vm) {
|
|
|
|
// I'd use Composite here, but it doesn't always work.
|
|
|
|
// 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;
|
|
|
|
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();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
|
1999-11-08 21:30:22 +00:00
|
|
|
//Reset target frame to null to avoid mistargetting after reentrant event
|
|
|
|
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;
|
|
|
|
if (aFrame == mGestureDownFrame)
|
|
|
|
mGestureDownFrame = nsnull;
|
1998-11-24 07:46:58 +00:00
|
|
|
if (aFrame == mCurrentTarget) {
|
1999-06-15 03:14:28 +00:00
|
|
|
if (aFrame) {
|
|
|
|
aFrame->GetContent(&mCurrentTargetContent);
|
|
|
|
}
|
1998-11-19 00:43:36 +00:00
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-30 19:38:39 +00:00
|
|
|
nsIScrollableView*
|
|
|
|
nsEventStateManager::GetNearestScrollingView(nsIView* aView)
|
|
|
|
{
|
|
|
|
nsIScrollableView* sv;
|
2000-02-05 00:58:29 +00:00
|
|
|
if (NS_OK == aView->QueryInterface(NS_GET_IID(nsIScrollableView),
|
|
|
|
(void**)&sv)) {
|
1999-04-30 19:38:39 +00:00
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* parent;
|
|
|
|
aView->GetParent(parent);
|
|
|
|
|
|
|
|
if (nsnull != parent) {
|
|
|
|
return GetNearestScrollingView(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1999-12-04 02:22:21 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::CheckDisabled(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
PRBool disabled = PR_FALSE;
|
|
|
|
|
2000-01-12 06:54:58 +00:00
|
|
|
nsCOMPtr<nsIAtom> tag;
|
|
|
|
aContent->GetTag(*getter_AddRefs(tag));
|
1999-12-04 02:22:21 +00:00
|
|
|
|
2000-01-12 07:39:00 +00:00
|
|
|
if (nsHTMLAtoms::input == tag.get() ||
|
|
|
|
nsHTMLAtoms::select == tag.get() ||
|
|
|
|
nsHTMLAtoms::textarea == tag.get() ||
|
|
|
|
nsHTMLAtoms::button == tag.get()) {
|
1999-12-04 02:22:21 +00:00
|
|
|
nsAutoString empty;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttribute(kNameSpaceID_HTML,
|
|
|
|
nsHTMLAtoms::disabled,
|
|
|
|
empty)) {
|
|
|
|
disabled = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return disabled;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
void
|
2000-02-11 01:24:59 +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) {
|
|
|
|
aTargetFrame->GetCursor(aPresContext, aEvent->point, cursor);
|
|
|
|
}
|
|
|
|
}
|
1999-12-04 02:22:21 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
1999-11-03 07:11:45 +00:00
|
|
|
//Hold onto old target content through the event and reset after.
|
|
|
|
nsCOMPtr<nsIContent> targetBeforeEvent = mCurrentTargetContent;
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
{
|
2000-02-11 01:24:59 +00:00
|
|
|
nsCOMPtr<nsIContent> targetContent;
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
mCurrentTarget->GetContentForEvent(aPresContext, aEvent, getter_AddRefs(targetContent));
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2000-02-11 01:24:59 +00:00
|
|
|
if (mLastMouseOverContent.get() != targetContent.get()) {
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2000-02-16 03:52:45 +00:00
|
|
|
//Before firing mouseout, check for recursion
|
|
|
|
if (mLastMouseOverContent.get() != mFirstMouseOutEventContent.get()) {
|
|
|
|
|
|
|
|
//Store the first mouseOut event we fire and don't refire mouseOut
|
|
|
|
//to that element while the first mouseOut is still ongoing.
|
|
|
|
mFirstMouseOutEventContent = mLastMouseOverContent;
|
|
|
|
|
|
|
|
if (mLastMouseOverFrame) {
|
|
|
|
//fire mouseout
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
2000-04-24 04:41:27 +00:00
|
|
|
event.message = NS_MOUSE_EXIT_SYNTH;
|
2000-02-16 03:52:45 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
mCurrentTargetContent = mLastMouseOverContent;
|
|
|
|
NS_IF_ADDREF(mCurrentTargetContent);
|
|
|
|
mCurrentRelatedContent = targetContent;
|
|
|
|
NS_IF_ADDREF(mCurrentRelatedContent);
|
|
|
|
|
|
|
|
//XXX This event should still go somewhere!!
|
|
|
|
if (mLastMouseOverContent) {
|
|
|
|
mLastMouseOverContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now dispatch to the frame
|
|
|
|
if (mLastMouseOverFrame) {
|
|
|
|
//XXX Get the new frame
|
|
|
|
mLastMouseOverFrame->HandleEvent(aPresContext, &event, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
|
|
|
NS_IF_RELEASE(mCurrentRelatedContent);
|
|
|
|
|
|
|
|
mFirstMouseOutEventContent = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Before firing mouseover, check for recursion
|
|
|
|
if (targetContent.get() != mFirstMouseOverEventContent.get()) {
|
|
|
|
|
|
|
|
//Store the first mouseOver event we fire and don't refire mouseOver
|
|
|
|
//to that element while the first mouseOver is still ongoing.
|
|
|
|
mFirstMouseOverEventContent = targetContent;
|
|
|
|
|
|
|
|
//fire mouseover
|
1998-11-18 05:25:26 +00:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
2000-04-24 04:41:27 +00:00
|
|
|
event.message = NS_MOUSE_ENTER_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;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2000-02-16 03:52:45 +00:00
|
|
|
mCurrentTargetContent = targetContent;
|
1999-11-03 07:11:45 +00:00
|
|
|
NS_IF_ADDREF(mCurrentTargetContent);
|
2000-02-16 03:52:45 +00:00
|
|
|
mCurrentRelatedContent = mLastMouseOverContent;
|
1999-11-03 07:11:45 +00:00
|
|
|
NS_IF_ADDREF(mCurrentRelatedContent);
|
|
|
|
|
2000-02-11 01:24:59 +00:00
|
|
|
//XXX This event should still go somewhere!!
|
2000-02-16 03:52:45 +00:00
|
|
|
if (targetContent) {
|
|
|
|
targetContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
SetContentState(targetContent, NS_EVENT_STATE_HOVER);
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Now dispatch to the frame
|
2000-02-16 03:52:45 +00:00
|
|
|
if (mCurrentTarget) {
|
1999-01-28 23:14:36 +00:00
|
|
|
//XXX Get the new frame
|
2000-02-16 03:52:45 +00:00
|
|
|
mCurrentTarget->HandleEvent(aPresContext, &event, &status);
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
|
|
|
NS_IF_RELEASE(mCurrentRelatedContent);
|
2000-02-16 03:52:45 +00:00
|
|
|
mLastMouseOverFrame = mCurrentTarget;
|
|
|
|
mLastMouseOverContent = targetContent;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2000-02-16 03:52:45 +00:00
|
|
|
mFirstMouseOverEventContent = nsnull;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_EXIT:
|
|
|
|
{
|
1999-11-03 07:11:45 +00:00
|
|
|
//This is actually the window mouse exit event.
|
1998-11-18 05:25:26 +00:00
|
|
|
if (nsnull != mLastMouseOverFrame) {
|
2000-02-16 03:52:45 +00:00
|
|
|
//Before firing mouseout, check for recursion
|
|
|
|
if (mLastMouseOverContent.get() != mFirstMouseOutEventContent.get()) {
|
|
|
|
|
|
|
|
//Store the first mouseOut event we fire and don't refire mouseOut
|
|
|
|
//to that element while the first mouseOut is still ongoing.
|
|
|
|
mFirstMouseOutEventContent = mLastMouseOverContent;
|
1999-06-22 14:20:14 +00:00
|
|
|
|
2000-02-16 03:52:45 +00:00
|
|
|
//fire mouseout
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
2000-04-24 04:41:27 +00:00
|
|
|
event.message = NS_MOUSE_EXIT_SYNTH;
|
2000-02-16 03:52:45 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
mCurrentTargetContent = mLastMouseOverContent;
|
|
|
|
NS_IF_ADDREF(mCurrentTargetContent);
|
|
|
|
mCurrentRelatedContent = nsnull;
|
|
|
|
|
|
|
|
if (mLastMouseOverContent) {
|
|
|
|
mLastMouseOverContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
1999-06-22 14:20:14 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
1999-06-22 14:20:14 +00:00
|
|
|
|
2000-02-16 03:52:45 +00:00
|
|
|
//Now dispatch to the frame
|
|
|
|
if (nsnull != mLastMouseOverFrame) {
|
|
|
|
//XXX Get the new frame
|
|
|
|
mLastMouseOverFrame->HandleEvent(aPresContext, &event, &status);
|
|
|
|
mLastMouseOverFrame = nsnull;
|
|
|
|
mLastMouseOverContent = nsnull;
|
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
|
2000-02-16 03:52:45 +00:00
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
|
|
|
|
|
|
|
mFirstMouseOutEventContent = nsnull;
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-11-03 07:11:45 +00:00
|
|
|
|
|
|
|
//reset mCurretTargetContent to what it was
|
|
|
|
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;
|
|
|
|
NS_IF_ADDREF(mCurrentTargetContent);
|
|
|
|
mCurrentRelatedContent = targetContent;
|
|
|
|
NS_IF_ADDREF(mCurrentRelatedContent);
|
|
|
|
|
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
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
|
|
|
NS_IF_RELEASE(mCurrentRelatedContent);
|
|
|
|
|
|
|
|
}
|
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;
|
|
|
|
NS_IF_ADDREF(mCurrentTargetContent);
|
|
|
|
mCurrentRelatedContent = lastContent;
|
|
|
|
NS_IF_ADDREF(mCurrentRelatedContent);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-11-03 07:11:45 +00:00
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
|
|
|
NS_IF_RELEASE(mCurrentRelatedContent);
|
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;
|
|
|
|
NS_IF_ADDREF(mCurrentTargetContent);
|
|
|
|
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
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentTargetContent);
|
|
|
|
}
|
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;
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
NS_IMETHODIMP
|
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-09-16 14:54:59 +00:00
|
|
|
NS_IF_RELEASE(mLastLeftMouseDownContent);
|
1999-03-28 22:22:54 +00:00
|
|
|
mLastLeftMouseDownContent = mouseContent;
|
|
|
|
NS_IF_ADDREF(mLastLeftMouseDownContent);
|
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:
|
1999-09-16 14:54:59 +00:00
|
|
|
if (mLastLeftMouseDownContent == mouseContent.get()) {
|
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
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
NS_IF_RELEASE(mLastLeftMouseDownContent);
|
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-09-16 14:54:59 +00:00
|
|
|
NS_IF_RELEASE(mLastMiddleMouseDownContent);
|
1999-03-28 22:22:54 +00:00
|
|
|
mLastMiddleMouseDownContent = mouseContent;
|
|
|
|
NS_IF_ADDREF(mLastMiddleMouseDownContent);
|
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:
|
1999-09-16 14:54:59 +00:00
|
|
|
if (mLastMiddleMouseDownContent == mouseContent.get()) {
|
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
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
NS_IF_RELEASE(mLastMiddleMouseDownContent);
|
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-09-16 14:54:59 +00:00
|
|
|
NS_IF_RELEASE(mLastRightMouseDownContent);
|
1999-03-28 22:22:54 +00:00
|
|
|
mLastRightMouseDownContent = mouseContent;
|
|
|
|
NS_IF_ADDREF(mLastRightMouseDownContent);
|
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:
|
1999-09-16 14:54:59 +00:00
|
|
|
if (mLastRightMouseDownContent == mouseContent.get()) {
|
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
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
NS_IF_RELEASE(mLastRightMouseDownContent);
|
1998-11-24 07:46:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-09-22 02:29:33 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
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;
|
|
|
|
|
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;
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_RIGHT_BUTTON_UP:
|
|
|
|
event.message = NS_MOUSE_RIGHT_CLICK;
|
|
|
|
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;
|
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) {
|
|
|
|
ret = presShell->HandleEventWithTarget(&event, mCurrentTarget, mouseContent, aStatus);
|
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
|
1999-12-08 04:54:29 +00:00
|
|
|
nsEventStateManager::ChangeFocus(nsIContent* aFocusContent, nsIFrame* aTargetFrame, PRBool aSetFocus)
|
1999-03-02 19:19:24 +00:00
|
|
|
{
|
2000-04-04 23:55:31 +00:00
|
|
|
aFocusContent->SetFocus(mPresContext);
|
1999-03-02 19:19:24 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
void
|
1999-03-02 19:19:24 +00:00
|
|
|
nsEventStateManager::ShiftFocus(PRBool forward)
|
1998-11-18 05:25:26 +00:00
|
|
|
{
|
1999-04-12 21:24:07 +00:00
|
|
|
PRBool topOfDoc = PR_FALSE;
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
if (nsnull == mPresContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-28 20:35:32 +00:00
|
|
|
EnsureDocument(mPresContext);
|
2000-04-10 20:52:52 +00:00
|
|
|
if (nsnull == mDocument) {
|
2000-06-28 20:35:32 +00:00
|
|
|
return;
|
2000-04-10 20:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull == mCurrentFocus) {
|
1998-11-18 05:25:26 +00:00
|
|
|
mCurrentFocus = mDocument->GetRootContent();
|
|
|
|
if (nsnull == mCurrentFocus) {
|
|
|
|
return;
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
mCurrentTabIndex = forward ? 1 : 0;
|
1999-04-12 21:24:07 +00:00
|
|
|
topOfDoc = PR_TRUE;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
nsIFrame* primaryFrame;
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
if (mPresContext) {
|
|
|
|
nsresult rv = mPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
if (NS_SUCCEEDED(rv) && shell){
|
|
|
|
shell->GetPrimaryFrameFor(mCurrentFocus, &primaryFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> rootContent = getter_AddRefs(mDocument->GetRootContent());
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIContent> next;
|
|
|
|
GetNextTabbableContent(rootContent, primaryFrame, forward, getter_AddRefs(next));
|
|
|
|
|
|
|
|
if (!next) {
|
1999-04-12 21:24:07 +00:00
|
|
|
PRBool focusTaken = PR_FALSE;
|
|
|
|
|
1999-07-19 21:23:57 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
1999-03-02 19:19:24 +00:00
|
|
|
|
2000-02-11 01:56:01 +00:00
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
mPresContext->GetContainer(getter_AddRefs(container));
|
|
|
|
nsCOMPtr<nsIBaseWindow> docShellAsWin(do_QueryInterface(container));
|
|
|
|
if (docShellAsWin) {
|
|
|
|
docShellAsWin->FocusAvailable(docShellAsWin, &focusTaken);
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2000-02-11 01:56:01 +00:00
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
if (!focusTaken && !topOfDoc) {
|
|
|
|
ShiftFocus(forward);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-21 19:35:13 +00:00
|
|
|
// Now we need to get the content node's frame and reset
|
|
|
|
// the mCurrentTarget target. Otherwise the focus
|
|
|
|
// code will be slightly out of sync (with regards to
|
2000-04-04 23:55:31 +00:00
|
|
|
// focusing widgets within the current target)
|
|
|
|
if (shell)
|
|
|
|
shell->GetPrimaryFrameFor(next, &mCurrentTarget);
|
|
|
|
|
1999-11-13 05:16:33 +00:00
|
|
|
ChangeFocus(next, mCurrentTarget, PR_TRUE);
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentFocus);
|
|
|
|
mCurrentFocus = next;
|
2000-04-04 23:55:31 +00:00
|
|
|
NS_IF_ADDREF(mCurrentFocus);
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At some point this will need to be linked into HTML 4.0 tabindex
|
|
|
|
*/
|
2000-04-04 23:55:31 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* aFrame, PRBool forward,
|
|
|
|
nsIContent** aResult)
|
1998-11-18 05:25:26 +00:00
|
|
|
{
|
2000-04-04 23:55:31 +00:00
|
|
|
*aResult = nsnull;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIBidirectionalEnumerator> frameTraversal;
|
|
|
|
nsresult result = NS_NewFrameTraversal(getter_AddRefs(frameTraversal), EXTENSIVE,
|
|
|
|
mPresContext, aFrame);
|
1998-11-18 05:25:26 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_OK;
|
1999-03-02 19:19:24 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
if (forward)
|
|
|
|
frameTraversal->Next();
|
|
|
|
else frameTraversal->Prev();
|
|
|
|
|
|
|
|
nsISupports* currentItem;
|
|
|
|
frameTraversal->CurrentItem(¤tItem);
|
|
|
|
nsIFrame* currentFrame = (nsIFrame*)currentItem;
|
|
|
|
|
|
|
|
while (currentFrame) {
|
|
|
|
nsCOMPtr<nsIContent> child;
|
|
|
|
currentFrame->GetContent(getter_AddRefs(child));
|
|
|
|
|
|
|
|
const nsStyleDisplay* disp;
|
|
|
|
currentFrame->GetStyleData(eStyleStruct_Display, ((const nsStyleStruct *&)disp));
|
|
|
|
|
|
|
|
const nsStyleUserInterface* ui;
|
|
|
|
currentFrame->GetStyleData(eStyleStruct_UserInterface, ((const nsStyleStruct*&)ui));;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(child));
|
|
|
|
|
|
|
|
// if collapsed or hidden, we don't get tabbed into.
|
|
|
|
if ((disp->mVisible != NS_STYLE_VISIBILITY_COLLAPSE) &&
|
|
|
|
(disp->mVisible != NS_STYLE_VISIBILITY_HIDDEN) &&
|
|
|
|
(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
|
|
|
|
2000-01-12 06:54:58 +00:00
|
|
|
child->GetTag(*getter_AddRefs(tag));
|
2000-04-04 23:55:31 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLElement> htmlElement(do_QueryInterface(child));
|
|
|
|
if (htmlElement) {
|
|
|
|
if (nsHTMLAtoms::input==tag.get()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLInputElement> nextInput(do_QueryInterface(child));
|
|
|
|
if (nextInput) {
|
|
|
|
nextInput->GetDisabled(&disabled);
|
|
|
|
nextInput->GetTabIndex(&tabIndex);
|
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
nextInput->GetType(type);
|
|
|
|
if (type.EqualsIgnoreCase("hidden")) {
|
|
|
|
hidden = PR_TRUE;
|
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
else if (nsHTMLAtoms::select==tag.get()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLSelectElement> nextSelect(do_QueryInterface(child));
|
|
|
|
if (nextSelect) {
|
|
|
|
nextSelect->GetDisabled(&disabled);
|
|
|
|
nextSelect->GetTabIndex(&tabIndex);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
else if (nsHTMLAtoms::textarea==tag.get()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLTextAreaElement> nextTextArea(do_QueryInterface(child));
|
|
|
|
if (nextTextArea) {
|
|
|
|
nextTextArea->GetDisabled(&disabled);
|
|
|
|
nextTextArea->GetTabIndex(&tabIndex);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
else if(nsHTMLAtoms::a==tag.get()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLAnchorElement> nextAnchor(do_QueryInterface(child));
|
|
|
|
if (nextAnchor)
|
|
|
|
nextAnchor->GetTabIndex(&tabIndex);
|
2000-05-11 01:43:04 +00:00
|
|
|
nsAutoString href;
|
|
|
|
nextAnchor->GetAttribute(NS_ConvertASCIItoUCS2("href"), href);
|
|
|
|
if (!href.Length()) {
|
|
|
|
disabled = PR_TRUE; // Don't tab unless href, bug 17605
|
|
|
|
} else {
|
|
|
|
disabled = PR_FALSE;
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
else if(nsHTMLAtoms::button==tag.get()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLButtonElement> nextButton(do_QueryInterface(child));
|
|
|
|
if (nextButton) {
|
|
|
|
nextButton->GetTabIndex(&tabIndex);
|
|
|
|
nextButton->GetDisabled(&disabled);
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
else if(nsHTMLAtoms::area==tag.get()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLAreaElement> nextArea(do_QueryInterface(child));
|
|
|
|
if (nextArea)
|
|
|
|
nextArea->GetTabIndex(&tabIndex);
|
|
|
|
disabled = PR_FALSE;
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
else if(nsHTMLAtoms::object==tag.get()) {
|
|
|
|
nsCOMPtr<nsIDOMHTMLObjectElement> nextObject(do_QueryInterface(child));
|
|
|
|
if (nextObject)
|
|
|
|
nextObject->GetTabIndex(&tabIndex);
|
|
|
|
disabled = PR_FALSE;
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
2000-03-23 09:56:58 +00:00
|
|
|
else {
|
2000-04-04 23:55:31 +00:00
|
|
|
nsAutoString value;
|
|
|
|
child->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, value);
|
|
|
|
nsAutoString tabStr;
|
|
|
|
child->GetAttribute(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
|
|
|
}
|
2000-04-04 23:55:31 +00:00
|
|
|
if (!value.EqualsWithConversion("true"))
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!disabled && !hidden && mCurrentTabIndex == tabIndex) {
|
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);
|
2000-06-02 14:20:50 +00:00
|
|
|
return GetNextTabbableContent(aRootContent, aFrame, forward, 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;
|
|
|
|
child->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::tabindex, tabIndexStr);
|
|
|
|
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;
|
|
|
|
child->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::tabindex, tabIndexStr);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-24 03:58:13 +00:00
|
|
|
if (!mCurrentTarget) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
presShell->GetEventTargetFrame(&mCurrentTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-06-24 03:58:13 +00:00
|
|
|
|
|
|
|
if (!mCurrentTarget) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
presShell->GetEventTargetFrame(&mCurrentTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
if (aContent == mHoverContent) {
|
|
|
|
aState |= NS_EVENT_STATE_HOVER;
|
1999-01-28 23:14:36 +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;
|
|
|
|
}
|
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
|
|
|
{
|
1999-05-04 14:44:51 +00:00
|
|
|
const PRInt32 maxNotify = 5;
|
|
|
|
nsIContent *notifyContent[maxNotify] = {nsnull, nsnull, nsnull, nsnull, nsnull};
|
|
|
|
|
|
|
|
if ((aState & NS_EVENT_STATE_DRAGOVER) && (aContent != mDragOverContent)) {
|
|
|
|
//transferring ref to notifyContent from mDragOverContent
|
|
|
|
notifyContent[4] = mDragOverContent; // notify dragover first, since more common case
|
|
|
|
mDragOverContent = aContent;
|
|
|
|
NS_IF_ADDREF(mDragOverContent);
|
|
|
|
}
|
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;
|
|
|
|
mActiveContent = aContent;
|
|
|
|
NS_IF_ADDREF(mActiveContent);
|
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
|
1999-04-20 00:03:30 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_HOVER) && (aContent != mHoverContent)) {
|
|
|
|
//transferring ref to notifyContent from mHoverContent
|
|
|
|
notifyContent[1] = mHoverContent; // notify hover first, since more common case
|
|
|
|
mHoverContent = aContent;
|
|
|
|
NS_IF_ADDREF(mHoverContent);
|
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);
|
1999-12-08 04:54:29 +00:00
|
|
|
} else {
|
2000-04-12 00:24:07 +00:00
|
|
|
notifyContent[3] = gLastFocusedContent;
|
|
|
|
NS_IF_ADDREF(gLastFocusedContent);
|
2000-04-04 23:55:31 +00:00
|
|
|
SendFocusBlur(mPresContext, aContent);
|
1999-12-08 04:54:29 +00:00
|
|
|
}
|
1998-08-07 04:45:03 +00:00
|
|
|
}
|
1999-01-28 23:14:36 +00:00
|
|
|
|
1999-04-20 00:03:30 +00:00
|
|
|
if (aContent) { // notify about new content too
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-20 00:03:30 +00:00
|
|
|
if (notifyContent[0]) { // have at least one to notify about
|
|
|
|
nsIDocument *document; // this presumes content can't get/lose state if not connected to doc
|
|
|
|
notifyContent[0]->GetDocument(document);
|
1999-04-12 21:24:07 +00:00
|
|
|
if (document) {
|
2000-01-28 23:43:12 +00:00
|
|
|
document->BeginUpdate();
|
1999-04-20 00:03:30 +00:00
|
|
|
document->ContentStatesChanged(notifyContent[0], notifyContent[1]);
|
|
|
|
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))
|
|
|
|
document->ContentStatesChanged(notifyContent[2], notifyContent[3]);
|
1999-05-04 14:44:51 +00:00
|
|
|
if (notifyContent[4]) { // more that two notifications are needed (should be rare)
|
|
|
|
document->ContentStatesChanged(notifyContent[4], nsnull);
|
|
|
|
}
|
1999-04-20 00:03:30 +00:00
|
|
|
}
|
2000-01-28 23:43:12 +00:00
|
|
|
document->EndUpdate();
|
1999-04-12 21:24:07 +00:00
|
|
|
NS_RELEASE(document);
|
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;
|
|
|
|
}
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
NS_IMETHODIMP
|
1999-10-26 04:44:41 +00:00
|
|
|
nsEventStateManager::SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aContent)
|
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;
|
|
|
|
NS_ADDREF(mFirstBlurEvent);
|
|
|
|
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) {
|
1999-12-21 01:12:40 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = getter_AddRefs(doc->GetShellAt(0));
|
2000-04-05 02:10:25 +00:00
|
|
|
if (shell) {
|
|
|
|
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) {
|
|
|
|
nsCOMPtr<nsIDOMXULCommandDispatcher> newCommandDispatcher;
|
2000-06-23 05:37:08 +00:00
|
|
|
nsCOMPtr<nsIDOMXULCommandDispatcher> oldCommandDispatcher;
|
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);
|
|
|
|
|
|
|
|
newWindow->GetRootCommandDispatcher(mDocument, getter_AddRefs(newCommandDispatcher));
|
|
|
|
oldWindow->GetRootCommandDispatcher(gLastFocusedDocument, getter_AddRefs(oldCommandDispatcher));
|
2000-06-23 05:37:08 +00:00
|
|
|
if(oldCommandDispatcher && oldCommandDispatcher != newCommandDispatcher)
|
2000-06-28 20:35:32 +00:00
|
|
|
oldCommandDispatcher->SetSuppressFocus(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
temp->HandleDOMEvent(oldPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
|
|
|
esm->SetFocusedContent(nsnull);
|
|
|
|
}
|
1999-12-21 01:12:40 +00:00
|
|
|
}
|
2000-02-11 05:20:44 +00:00
|
|
|
|
|
|
|
if (clearFirstBlurEvent) {
|
|
|
|
NS_RELEASE(mFirstBlurEvent);
|
|
|
|
}
|
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;
|
|
|
|
|
2000-06-23 05:37:08 +00:00
|
|
|
// Make sure we're not switching command dispatchers, if so, surpress the blurred one
|
|
|
|
if(mDocument) {
|
|
|
|
nsCOMPtr<nsIDOMXULCommandDispatcher> newCommandDispatcher;
|
|
|
|
nsCOMPtr<nsIDOMXULCommandDispatcher> oldCommandDispatcher;
|
|
|
|
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);
|
|
|
|
|
|
|
|
newWindow->GetRootCommandDispatcher(mDocument, getter_AddRefs(newCommandDispatcher));
|
|
|
|
oldWindow->GetRootCommandDispatcher(gLastFocusedDocument, getter_AddRefs(oldCommandDispatcher));
|
|
|
|
if(oldCommandDispatcher && oldCommandDispatcher != newCommandDispatcher)
|
|
|
|
oldCommandDispatcher->SetSuppressFocus(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
temp->HandleDOMEvent(gLastFocusedPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
|
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);
|
|
|
|
NS_IF_RELEASE(mCurrentFocus);
|
|
|
|
gLastFocusedContent = aContent;
|
|
|
|
mCurrentFocus = aContent;
|
|
|
|
NS_IF_ADDREF(aContent);
|
|
|
|
NS_IF_ADDREF(aContent);
|
|
|
|
|
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;
|
|
|
|
NS_ADDREF(mFirstFocusEvent);
|
|
|
|
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) {
|
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;
|
|
|
|
aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::tabindex, tabIndex);
|
|
|
|
PRInt32 ec, val = tabIndex.ToInteger(&ec);
|
|
|
|
if (NS_OK == ec) {
|
|
|
|
mCurrentTabIndex = val;
|
|
|
|
}
|
2000-02-11 05:20:44 +00:00
|
|
|
|
|
|
|
if (clearFirstFocusEvent) {
|
|
|
|
NS_RELEASE(mFirstFocusEvent);
|
|
|
|
}
|
1999-12-08 04:54:29 +00:00
|
|
|
}
|
1999-09-20 22:18:57 +00:00
|
|
|
|
2000-04-04 23:55:31 +00:00
|
|
|
nsIFrame * currentFocusFrame = nsnull;
|
|
|
|
if (mCurrentFocus)
|
|
|
|
presShell->GetPrimaryFrameFor(mCurrentFocus, ¤tFocusFrame);
|
|
|
|
if (!currentFocusFrame)
|
|
|
|
currentFocusFrame = mCurrentTarget;
|
1999-12-08 04:54:29 +00:00
|
|
|
|
|
|
|
// Find the window that this frame is in and
|
|
|
|
// make sure it has focus
|
1999-12-21 19:35:13 +00:00
|
|
|
// GFX Text Control frames handle their own focus
|
|
|
|
// and must be special-cased.
|
|
|
|
nsCOMPtr<nsIGfxTextControlFrame> gfxFrame = do_QueryInterface(currentFocusFrame);
|
|
|
|
if (gfxFrame) {
|
|
|
|
gfxFrame->SetInnerFocus();
|
|
|
|
}
|
|
|
|
else if (currentFocusFrame) {
|
1999-12-08 04:54:29 +00:00
|
|
|
nsIFrame * parentFrame;
|
|
|
|
currentFocusFrame->GetParentWithView(aPresContext, &parentFrame);
|
|
|
|
if (nsnull != parentFrame) {
|
|
|
|
nsIView * pView;
|
|
|
|
parentFrame->GetView(aPresContext, &pView);
|
|
|
|
if (nsnull != pView) {
|
1999-09-20 22:18:57 +00:00
|
|
|
nsIWidget *window = nsnull;
|
|
|
|
|
1999-12-08 04:54:29 +00:00
|
|
|
nsIView *ancestor = pView;
|
|
|
|
while (nsnull != ancestor) {
|
|
|
|
ancestor->GetWidget(window); // addrefs
|
|
|
|
if (nsnull != window) {
|
2000-01-19 03:03:09 +00:00
|
|
|
window->SetFocus();
|
|
|
|
NS_RELEASE(window); // releases. Duh.
|
1999-12-08 04:54:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ancestor->GetParent(ancestor);
|
1999-09-20 22:18:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-11-13 05:16:33 +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)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mCurrentFocus);
|
|
|
|
mCurrentFocus = aContent;
|
|
|
|
NS_IF_ADDREF(mCurrentFocus);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-02-09 15:14:55 +00:00
|
|
|
//-------------------------------------------
|
|
|
|
// Access Key Registration
|
|
|
|
//-------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2000-05-16 10:22:20 +00:00
|
|
|
nsEventStateManager::RegisterAccessKey(nsIFrame * aFrame, 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (!aContent) {
|
|
|
|
aFrame->GetContent(getter_AddRefs(content));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
content = aContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content) {
|
|
|
|
nsVoidKey key((void*)aKey);
|
|
|
|
|
2000-06-06 22:06:56 +00:00
|
|
|
mAccessKeys->Put(&key, content);
|
2000-05-16 10:22:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-02-09 15:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-16 10:22:20 +00:00
|
|
|
nsEventStateManager::UnregisterAccessKey(nsIFrame * aFrame, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
if (!aContent) {
|
|
|
|
aFrame->GetContent(getter_AddRefs(content));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
content = aContent;
|
|
|
|
}
|
|
|
|
if (content) {
|
|
|
|
nsVoidKey key((void*)aKey);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> oldContent = getter_AddRefs(NS_STATIC_CAST(nsIContent*, mAccessKeys->Get(&key)));
|
|
|
|
if (oldContent != content) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent)
|
|
|
|
{
|
2000-05-17 05:27:22 +00:00
|
|
|
nsresult ret = NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privEvt(do_QueryInterface(aEvent));
|
|
|
|
if (aEvent) {
|
|
|
|
nsEvent* innerEvent;
|
|
|
|
privEvt->GetInternalNSEvent(&innerEvent);
|
|
|
|
if (innerEvent) {
|
|
|
|
nsEventStatus status;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
aPresShell->GetDocument(&mDocument);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2000-03-15 04:03:44 +00:00
|
|
|
rv = manager->QueryInterface(NS_GET_IID(nsIEventStateManager),
|
2000-02-05 00:58:29 +00:00
|
|
|
(void **) 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
|
|
|
}
|
|
|
|
|