1998-06-23 21:53:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
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"
|
|
|
|
#include "nsIFocusableContent.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"
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIEventStateManagerIID, NS_IEVENTSTATEMANAGER_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
1998-11-18 05:25:26 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLAnchorElementIID, NS_IDOMHTMLANCHORELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLTextAreaElementIID, NS_IDOMHTMLTEXTAREAELEMENT_IID);
|
1999-03-02 19:19:24 +00:00
|
|
|
static NS_DEFINE_IID(kIDOMHTMLAreaElementIID, NS_IDOMHTMLAREAELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLObjectElementIID, NS_IDOMHTMLOBJECTELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMHTMLButtonElementIID, NS_IDOMHTMLBUTTONELEMENT_IID);
|
|
|
|
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
|
|
|
|
static NS_DEFINE_IID(kIFocusableContentIID, NS_IFOCUSABLECONTENT_IID);
|
1999-04-30 19:38:39 +00:00
|
|
|
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
1998-06-23 21:53:02 +00:00
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
nsEventStateManager::nsEventStateManager()
|
|
|
|
: mGestureDownPoint(0,0)
|
|
|
|
{
|
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-03-28 22:22:54 +00:00
|
|
|
mLastLeftMouseDownContent = nsnull;
|
|
|
|
mLastMiddleMouseDownContent = nsnull;
|
|
|
|
mLastRightMouseDownContent = nsnull;
|
1998-11-24 07:46:58 +00:00
|
|
|
|
1999-08-19 19:48:45 +00:00
|
|
|
// init d&d gesture state machine variables
|
|
|
|
mIsTrackingDragGesture = PR_FALSE;
|
|
|
|
mGestureDownFrame = nsnull;
|
|
|
|
|
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;
|
1998-06-25 14:51:48 +00:00
|
|
|
NS_INIT_REFCNT();
|
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-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);
|
1998-06-23 21:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsEventStateManager)
|
|
|
|
NS_IMPL_RELEASE(nsEventStateManager)
|
|
|
|
NS_IMPL_QUERY_INTERFACE(nsEventStateManager, kIEventStateManagerIID);
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_IMETHODIMP
|
1998-11-24 07:46:58 +00:00
|
|
|
nsEventStateManager::PreHandleEvent(nsIPresContext& aPresContext,
|
1998-11-18 05:25:26 +00:00
|
|
|
nsGUIEvent *aEvent,
|
|
|
|
nsIFrame* aTargetFrame,
|
1999-06-15 03:14:28 +00:00
|
|
|
nsEventStatus& aStatus,
|
|
|
|
nsIView* aView)
|
1998-06-23 21:53:02 +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);
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
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:
|
|
|
|
BeginTrackingDragGesture ( aEvent, aTargetFrame );
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_MOUSE_MOVE:
|
1999-08-19 19:48:45 +00:00
|
|
|
GenerateDragGesture(aPresContext, aEvent);
|
1998-12-03 03:07:16 +00:00
|
|
|
UpdateCursor(aPresContext, aEvent->point, aTargetFrame, aStatus);
|
1998-12-02 02:14:58 +00:00
|
|
|
GenerateMouseEnterExit(aPresContext, aEvent);
|
1998-11-18 05:25:26 +00:00
|
|
|
break;
|
|
|
|
case NS_MOUSE_EXIT:
|
1999-03-28 22:22:54 +00:00
|
|
|
GenerateMouseEnterExit(aPresContext, aEvent);
|
1998-11-18 05:25:26 +00:00
|
|
|
break;
|
1999-06-22 14:20:14 +00:00
|
|
|
case NS_DRAGDROP_OVER:
|
|
|
|
GenerateDragDropEnterExit(aPresContext, aEvent);
|
|
|
|
break;
|
|
|
|
case NS_DRAGDROP_DROP:
|
|
|
|
case NS_DRAGDROP_EXIT:
|
|
|
|
GenerateDragDropEnterExit(aPresContext, aEvent);
|
|
|
|
break;
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_GOTFOCUS:
|
1999-07-27 20:55:03 +00:00
|
|
|
{
|
|
|
|
nsIContent* newFocus;
|
|
|
|
mCurrentTarget->GetContent(&newFocus);
|
|
|
|
if (newFocus) {
|
|
|
|
nsIFocusableContent *focusChange;
|
|
|
|
if (NS_SUCCEEDED(newFocus->QueryInterface(kIFocusableContentIID,
|
|
|
|
(void **)&focusChange))) {
|
|
|
|
NS_RELEASE(focusChange);
|
|
|
|
NS_RELEASE(newFocus);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(newFocus);
|
|
|
|
}
|
|
|
|
|
|
|
|
//fire focus
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_FOCUS_CONTENT;
|
|
|
|
|
|
|
|
if (!mDocument) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext.GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
presShell->GetDocument(&mDocument);
|
|
|
|
}
|
1999-06-15 03:14:28 +00:00
|
|
|
}
|
1999-07-27 20:55:03 +00:00
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
mDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
1999-06-15 03:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
break;
|
1999-05-18 23:51:04 +00:00
|
|
|
case NS_LOSTFOCUS:
|
1999-07-27 20:55:03 +00:00
|
|
|
{
|
|
|
|
nsIContent* oldFocus;
|
|
|
|
mCurrentTarget->GetContent(&oldFocus);
|
|
|
|
if (oldFocus) {
|
|
|
|
nsIFocusableContent *focusChange;
|
|
|
|
if (NS_SUCCEEDED(oldFocus->QueryInterface(kIFocusableContentIID,
|
|
|
|
(void **)&focusChange))) {
|
|
|
|
NS_RELEASE(focusChange);
|
|
|
|
NS_RELEASE(oldFocus);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_RELEASE(oldFocus);
|
|
|
|
}
|
|
|
|
|
|
|
|
//fire blur
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
|
|
|
|
|
|
|
if (!mDocument) {
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
aPresContext.GetShell(getter_AddRefs(presShell));
|
|
|
|
if (presShell) {
|
|
|
|
presShell->GetDocument(&mDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
mCurrentTarget = nsnull;
|
|
|
|
mDocument->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
|
|
|
}
|
|
|
|
}
|
1999-05-18 23:51:04 +00:00
|
|
|
break;
|
1999-07-27 14:38:07 +00:00
|
|
|
case NS_KEY_PRESS:
|
1999-07-27 20:55:03 +00:00
|
|
|
case NS_KEY_DOWN:
|
|
|
|
case NS_KEY_UP:
|
1999-07-27 14:38:07 +00:00
|
|
|
{
|
1999-07-27 20:55:03 +00:00
|
|
|
if (mCurrentFocus) {
|
|
|
|
mCurrentTargetContent = mCurrentFocus;
|
|
|
|
NS_ADDREF(mCurrentTargetContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->message == NS_KEY_PRESS) {
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
if (keyEvent->isControl) {
|
|
|
|
keyEvent->charCode += 64;
|
|
|
|
}
|
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
|
|
|
|
nsEventStateManager :: GenerateDragGesture ( nsIPresContext& aPresContext, nsGUIEvent *aEvent )
|
|
|
|
{
|
|
|
|
if ( IsTrackingDragGesture() ) {
|
|
|
|
// 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;
|
|
|
|
aPresContext.GetDeviceContext ( getter_AddRefs(devContext) );
|
|
|
|
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;
|
|
|
|
|
|
|
|
// dispatch to the DOM
|
|
|
|
nsCOMPtr<nsIContent> lastContent;
|
|
|
|
mGestureDownFrame->GetContent(getter_AddRefs(lastContent));
|
|
|
|
if ( lastContent )
|
|
|
|
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
|
|
|
|
|
|
|
// dispatch to the frame
|
|
|
|
mGestureDownFrame->HandleEvent(aPresContext, &event, status);
|
|
|
|
|
|
|
|
StopTrackingDragGesture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // GenerateDragGesture
|
|
|
|
|
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::PostHandleEvent(nsIPresContext& aPresContext,
|
1999-09-16 14:54:59 +00:00
|
|
|
nsGUIEvent *aEvent,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsEventStatus& aStatus,
|
|
|
|
nsIView* aView)
|
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;
|
|
|
|
|
|
|
|
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-03-28 22:22:54 +00:00
|
|
|
ret = CheckForAndDispatchClick(aPresContext, (nsMouseEvent*)aEvent, aStatus);
|
1999-04-12 21:24:07 +00:00
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != aStatus) {
|
|
|
|
nsIContent* newFocus;
|
|
|
|
mCurrentTarget->GetContent(&newFocus);
|
1999-08-24 00:42:38 +00:00
|
|
|
nsCOMPtr<nsIFocusableContent> focusable;
|
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
if (newFocus) {
|
1999-08-24 00:42:38 +00:00
|
|
|
// Look for the nearest enclosing focusable content.
|
|
|
|
nsCOMPtr<nsIContent> current = dont_QueryInterface(newFocus);
|
|
|
|
while (current) {
|
|
|
|
focusable = do_QueryInterface(current);
|
|
|
|
if (focusable)
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parent;
|
|
|
|
current->GetParent(*getter_AddRefs(parent));
|
|
|
|
current = parent;
|
|
|
|
}
|
|
|
|
|
1999-08-24 09:37:28 +00:00
|
|
|
PRBool focusChangeFailed = PR_TRUE;
|
1999-08-24 00:42:38 +00:00
|
|
|
if (focusable) {
|
1999-09-20 22:56:32 +00:00
|
|
|
if (current.get() != mCurrentFocus) {
|
1999-09-20 22:18:57 +00:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(focusable);
|
|
|
|
if (ChangeFocus(content, PR_TRUE))
|
|
|
|
focusChangeFailed = PR_FALSE;
|
|
|
|
} else {
|
1999-08-24 09:37:28 +00:00
|
|
|
focusChangeFailed = PR_FALSE;
|
1999-09-20 22:18:57 +00:00
|
|
|
}
|
1999-08-24 09:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (focusChangeFailed) {
|
|
|
|
if (nsnull != aEvent->widget) {
|
|
|
|
aEvent->widget->SetFocus();
|
1999-04-12 21:24:07 +00:00
|
|
|
}
|
1999-08-24 09:37:28 +00:00
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_FOCUS);
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
|
|
|
}
|
1999-04-12 21:24:07 +00:00
|
|
|
|
|
|
|
SetContentState(newFocus, NS_EVENT_STATE_ACTIVE);
|
|
|
|
|
|
|
|
NS_IF_RELEASE(newFocus);
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
1999-04-12 21:24:07 +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);
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_ACTIVE);
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
nsresult rv = aPresContext.GetShell(getter_AddRefs(shell));
|
|
|
|
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;
|
|
|
|
case NS_KEY_DOWN:
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != aStatus) {
|
|
|
|
switch(((nsKeyEvent*)aEvent)->keyCode) {
|
|
|
|
case NS_VK_TAB:
|
1999-03-02 19:19:24 +00:00
|
|
|
//Shift focus forward or back depending on shift key
|
|
|
|
ShiftFocus(!((nsInputEvent*)aEvent)->isShift);
|
1998-11-24 07:46:58 +00:00
|
|
|
aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
1999-01-08 21:13:59 +00:00
|
|
|
case NS_VK_PAGE_DOWN:
|
|
|
|
case NS_VK_PAGE_UP:
|
1999-04-30 19:38:39 +00:00
|
|
|
if (!mCurrentFocus) {
|
|
|
|
nsIScrollableView* sv = GetNearestScrollingView(aView);
|
|
|
|
if (sv) {
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
sv->ScrollByPages((keyEvent->keyCode != NS_VK_PAGE_UP) ? 1 : -1);
|
|
|
|
}
|
|
|
|
}
|
1999-01-08 21:13:59 +00:00
|
|
|
break;
|
1999-09-21 14:18:52 +00:00
|
|
|
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_TRUE : PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-01-08 21:13:59 +00:00
|
|
|
case NS_VK_DOWN:
|
|
|
|
case NS_VK_UP:
|
1999-04-30 19:38:39 +00:00
|
|
|
if (!mCurrentFocus) {
|
|
|
|
nsIScrollableView* sv = GetNearestScrollingView(aView);
|
|
|
|
if (sv) {
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
sv->ScrollByLines((keyEvent->keyCode == NS_VK_DOWN) ? 1 : -1);
|
1999-05-31 01:45:23 +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();
|
|
|
|
nsIView* rootView = nsnull;
|
|
|
|
if (NS_OK == vm->GetRootView(rootView) && nsnull != rootView) {
|
|
|
|
nsIWidget* rootWidget = nsnull;
|
|
|
|
if (NS_OK == rootView->GetWidget(rootWidget) && nsnull != rootWidget) {
|
|
|
|
rootWidget->Update();
|
|
|
|
NS_RELEASE(rootWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
}
|
1999-04-30 19:38:39 +00:00
|
|
|
}
|
|
|
|
}
|
1999-01-08 21:13:59 +00:00
|
|
|
break;
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-07-06 22:55:46 +00:00
|
|
|
case NS_KEY_PRESS:
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != aStatus) {
|
|
|
|
//Handle key commands from keys with char representation here, not on KeyDown
|
|
|
|
nsKeyEvent * keyEvent = (nsKeyEvent *)aEvent;
|
|
|
|
|
|
|
|
//Spacebar
|
|
|
|
if (keyEvent->charCode == 0x20) {
|
|
|
|
if (!mCurrentFocus) {
|
|
|
|
nsIScrollableView* sv = GetNearestScrollingView(aView);
|
|
|
|
if (sv) {
|
|
|
|
sv->ScrollByPages(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
if (aFrame == mLastMouseOverFrame) {
|
|
|
|
mLastMouseOverFrame = 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;
|
|
|
|
if (NS_OK == aView->QueryInterface(kIScrollableViewIID, (void**)&sv)) {
|
|
|
|
return sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* parent;
|
|
|
|
aView->GetParent(parent);
|
|
|
|
|
|
|
|
if (nsnull != parent) {
|
|
|
|
return GetNearestScrollingView(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
void
|
1998-12-03 03:07:16 +00:00
|
|
|
nsEventStateManager::UpdateCursor(nsIPresContext& aPresContext, nsPoint& aPoint, nsIFrame* aTargetFrame,
|
|
|
|
nsEventStatus& aStatus)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
1998-11-18 05:25:26 +00:00
|
|
|
PRInt32 cursor;
|
|
|
|
nsCursor c;
|
|
|
|
|
|
|
|
aTargetFrame->GetCursor(aPresContext, aPoint, cursor);
|
|
|
|
|
|
|
|
switch (cursor) {
|
|
|
|
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;
|
1999-07-07 07:50:03 +00:00
|
|
|
//These aren't in the CSS2 spec. Don't know what to do with them.
|
1998-11-18 05:25:26 +00:00
|
|
|
case NS_STYLE_CURSOR_NE_RESIZE:
|
|
|
|
case NS_STYLE_CURSOR_NW_RESIZE:
|
|
|
|
case NS_STYLE_CURSOR_SE_RESIZE:
|
|
|
|
case NS_STYLE_CURSOR_SW_RESIZE:
|
|
|
|
c = eCursor_select;
|
|
|
|
break;
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
1998-12-03 03:07:16 +00:00
|
|
|
|
|
|
|
if (NS_STYLE_CURSOR_AUTO != cursor) {
|
|
|
|
aStatus = nsEventStatus_eConsumeDoDefault;
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
nsIWidget* window;
|
1999-02-10 05:38:18 +00:00
|
|
|
aTargetFrame->GetWindow(&window);
|
1998-11-18 05:25:26 +00:00
|
|
|
window->SetCursor(c);
|
|
|
|
NS_RELEASE(window);
|
1998-07-17 04:52:12 +00:00
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
void
|
1998-12-02 02:14:58 +00:00
|
|
|
nsEventStateManager::GenerateMouseEnterExit(nsIPresContext& aPresContext, nsGUIEvent* aEvent)
|
1998-07-17 04:52:12 +00:00
|
|
|
{
|
1998-11-18 05:25:26 +00:00
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
{
|
1998-12-02 02:14:58 +00:00
|
|
|
if (mLastMouseOverFrame != mCurrentTarget) {
|
1998-11-18 05:25:26 +00:00
|
|
|
//We'll need the content, too, to check if it changed separately from the frames.
|
|
|
|
nsIContent *lastContent = nsnull;
|
|
|
|
nsIContent *targetContent;
|
|
|
|
|
1999-02-10 00:42:56 +00:00
|
|
|
mCurrentTarget->GetContent(&targetContent);
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
if (nsnull != mLastMouseOverFrame) {
|
|
|
|
//fire mouseout
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
|
|
|
event.message = NS_MOUSE_EXIT;
|
1999-07-01 04:12:42 +00:00
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
//The frame has change but the content may not have. Check before dispatching to content
|
1999-02-10 00:42:56 +00:00
|
|
|
mLastMouseOverFrame->GetContent(&lastContent);
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
if (lastContent != targetContent) {
|
1998-11-19 00:43:36 +00:00
|
|
|
//XXX This event should still go somewhere!!
|
|
|
|
if (nsnull != lastContent) {
|
1999-03-28 22:22:54 +00:00
|
|
|
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
1998-11-19 00:43:36 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Now dispatch to the frame
|
1999-01-28 23:14:36 +00:00
|
|
|
if (nsnull != mLastMouseOverFrame) {
|
|
|
|
//XXX Get the new frame
|
|
|
|
mLastMouseOverFrame->HandleEvent(aPresContext, &event, status);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//fire mouseover
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
|
|
|
event.message = NS_MOUSE_ENTER;
|
1999-07-01 04:12:42 +00:00
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
//The frame has change but the content may not have. Check before dispatching to content
|
|
|
|
if (lastContent != targetContent) {
|
1998-11-19 00:43:36 +00:00
|
|
|
//XXX This event should still go somewhere!!
|
|
|
|
if (nsnull != targetContent) {
|
1999-03-28 22:22:54 +00:00
|
|
|
targetContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
1998-11-19 00:43:36 +00:00
|
|
|
}
|
1999-04-12 21:24:07 +00:00
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
SetContentState(targetContent, NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Now dispatch to the frame
|
1998-12-02 02:14:58 +00:00
|
|
|
if (nsnull != mCurrentTarget) {
|
1999-01-28 23:14:36 +00:00
|
|
|
//XXX Get the new frame
|
1998-12-02 02:14:58 +00:00
|
|
|
mCurrentTarget->HandleEvent(aPresContext, &event, status);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(lastContent);
|
|
|
|
NS_IF_RELEASE(targetContent);
|
|
|
|
|
1998-12-02 02:14:58 +00:00
|
|
|
mLastMouseOverFrame = mCurrentTarget;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_MOUSE_EXIT:
|
|
|
|
{
|
|
|
|
//This is actually the window mouse exit event. Such a think does not
|
|
|
|
// yet exist but it will need to eventually.
|
|
|
|
if (nsnull != mLastMouseOverFrame) {
|
|
|
|
//fire mouseout
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
|
|
|
event.message = NS_MOUSE_EXIT;
|
1999-07-01 04:12:42 +00:00
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
nsIContent *lastContent;
|
1999-02-10 00:42:56 +00:00
|
|
|
mLastMouseOverFrame->GetContent(&lastContent);
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
if (nsnull != lastContent) {
|
1999-03-28 22:22:54 +00:00
|
|
|
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
1999-06-22 14:20:14 +00:00
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_HOVER);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_RELEASE(lastContent);
|
|
|
|
}
|
|
|
|
|
1999-06-22 14:20:14 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
//Now dispatch to the frame
|
1999-01-28 23:14:36 +00:00
|
|
|
if (nsnull != mLastMouseOverFrame) {
|
|
|
|
//XXX Get the new frame
|
|
|
|
mLastMouseOverFrame->HandleEvent(aPresContext, &event, status);
|
1999-06-22 14:20:14 +00:00
|
|
|
mLastMouseOverFrame = nsnull;
|
1999-01-28 23:14:36 +00:00
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-07-17 04:52:12 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
1999-05-04 14:44:51 +00:00
|
|
|
void
|
|
|
|
nsEventStateManager::GenerateDragDropEnterExit(nsIPresContext& aPresContext, nsGUIEvent* aEvent)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
nsIContent *lastContent = nsnull;
|
|
|
|
nsIContent *targetContent;
|
|
|
|
|
|
|
|
mCurrentTarget->GetContent(&targetContent);
|
|
|
|
|
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;
|
|
|
|
event.message = NS_DRAGDROP_EXIT;
|
1999-07-01 04:12:42 +00:00
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
1999-05-04 14:44:51 +00:00
|
|
|
|
|
|
|
//The frame has change but the content may not have. Check before dispatching to content
|
|
|
|
mLastDragOverFrame->GetContent(&lastContent);
|
|
|
|
|
|
|
|
if (lastContent != targetContent) {
|
|
|
|
//XXX This event should still go somewhere!!
|
1999-09-09 00:28:23 +00:00
|
|
|
if (lastContent)
|
1999-05-04 14:44:51 +00:00
|
|
|
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
|
|
|
}
|
|
|
|
|
1999-09-09 00:28:23 +00:00
|
|
|
#if 0
|
1999-05-04 14:44:51 +00:00
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_DRAGOVER);
|
|
|
|
}
|
1999-09-09 00:28:23 +00:00
|
|
|
#endif
|
|
|
|
//Now dispatch to the frame
|
|
|
|
mLastDragOverFrame->HandleEvent(aPresContext, &event, status);
|
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-05-04 14:44:51 +00:00
|
|
|
|
|
|
|
//The frame has change but the content may not have. Check before dispatching to content
|
|
|
|
if (lastContent != targetContent) {
|
|
|
|
//XXX This event should still go somewhere!!
|
1999-09-09 00:28:23 +00:00
|
|
|
if ( targetContent )
|
1999-05-04 14:44:51 +00:00
|
|
|
targetContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
|
|
|
|
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
SetContentState(targetContent, NS_EVENT_STATE_DRAGOVER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-22 14:20:14 +00:00
|
|
|
//Now 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
|
|
|
|
mCurrentTarget->HandleEvent(aPresContext, &event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IF_RELEASE(lastContent);
|
|
|
|
NS_IF_RELEASE(targetContent);
|
|
|
|
|
|
|
|
mLastDragOverFrame = mCurrentTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-06-22 14:20:14 +00:00
|
|
|
case NS_DRAGDROP_DROP:
|
|
|
|
case NS_DRAGDROP_EXIT:
|
1999-05-04 14:44:51 +00:00
|
|
|
{
|
|
|
|
//This is actually the window mouse exit event. Such a think does not
|
|
|
|
// yet exist but it will need to eventually.
|
|
|
|
if (nsnull != mLastDragOverFrame) {
|
|
|
|
//fire mouseout
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsMouseEvent event;
|
|
|
|
event.eventStructType = NS_DRAGDROP_EVENT;
|
|
|
|
event.message = NS_DRAGDROP_EXIT;
|
1999-07-01 04:12:42 +00:00
|
|
|
event.widget = aEvent->widget;
|
|
|
|
event.clickCount = 0;
|
|
|
|
event.point = aEvent->point;
|
|
|
|
event.refPoint = aEvent->refPoint;
|
1999-05-04 14:44:51 +00:00
|
|
|
|
|
|
|
nsIContent *lastContent;
|
|
|
|
mLastDragOverFrame->GetContent(&lastContent);
|
|
|
|
|
|
|
|
if (nsnull != lastContent) {
|
|
|
|
lastContent->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
1999-06-22 14:20:14 +00:00
|
|
|
if (nsEventStatus_eConsumeNoDefault != status) {
|
|
|
|
SetContentState(nsnull, NS_EVENT_STATE_DRAGOVER);
|
|
|
|
}
|
1999-05-04 14:44:51 +00:00
|
|
|
NS_RELEASE(lastContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now dispatch to the frame
|
|
|
|
if (nsnull != mLastDragOverFrame) {
|
|
|
|
//XXX Get the new frame
|
|
|
|
mLastDragOverFrame->HandleEvent(aPresContext, &event, status);
|
1999-06-22 14:20:14 +00:00
|
|
|
mLastDragOverFrame = nsnull;
|
1999-05-04 14:44:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-11-24 07:46:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::CheckForAndDispatchClick(nsIPresContext& aPresContext,
|
|
|
|
nsMouseEvent *aEvent,
|
|
|
|
nsEventStatus& aStatus)
|
|
|
|
{
|
1999-03-11 05:56:11 +00:00
|
|
|
nsresult ret = NS_OK;
|
1998-11-24 07:46:58 +00:00
|
|
|
nsMouseEvent event;
|
1999-09-16 14:54:59 +00:00
|
|
|
nsCOMPtr<nsIContent> mouseContent;
|
1998-11-24 07:46:58 +00:00
|
|
|
PRBool fireClick = PR_FALSE;
|
|
|
|
|
1999-09-16 14:54:59 +00:00
|
|
|
mCurrentTarget->GetContent(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()) {
|
1998-11-24 07:46:58 +00:00
|
|
|
fireClick = PR_TRUE;
|
|
|
|
event.message = NS_MOUSE_LEFT_CLICK;
|
|
|
|
}
|
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()) {
|
1998-11-24 07:46:58 +00:00
|
|
|
fireClick = PR_TRUE;
|
|
|
|
event.message = NS_MOUSE_MIDDLE_CLICK;
|
|
|
|
}
|
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()) {
|
1998-11-24 07:46:58 +00:00
|
|
|
fireClick = PR_TRUE;
|
|
|
|
event.message = NS_MOUSE_RIGHT_CLICK;
|
|
|
|
}
|
1999-03-28 22:22:54 +00:00
|
|
|
NS_IF_RELEASE(mLastRightMouseDownContent);
|
1998-11-24 07:46:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fireClick) {
|
|
|
|
//fire click
|
|
|
|
event.eventStructType = NS_MOUSE_EVENT;
|
1999-06-09 07:38:26 +00:00
|
|
|
event.widget = aEvent->widget;
|
1999-06-08 19:28:52 +00:00
|
|
|
event.point.x = aEvent->point.x;
|
|
|
|
event.point.y = aEvent->point.y;
|
1999-06-09 07:38:26 +00:00
|
|
|
event.refPoint.x = aEvent->refPoint.x;
|
|
|
|
event.refPoint.y = aEvent->refPoint.y;
|
1998-11-24 07:46:58 +00:00
|
|
|
|
1999-09-16 14:54:59 +00:00
|
|
|
if (mouseContent) {
|
|
|
|
ret = mouseContent->HandleDOMEvent(aPresContext, &event, nsnull,
|
|
|
|
NS_EVENT_FLAG_INIT, aStatus);
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
1999-04-13 00:27:58 +00:00
|
|
|
|
|
|
|
if (nsnull != mCurrentTarget) {
|
|
|
|
ret = mCurrentTarget->HandleEvent(aPresContext, &event, aStatus);
|
|
|
|
}
|
1998-11-24 07:46:58 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::DispatchKeyPressEvent(nsIPresContext& aPresContext,
|
|
|
|
nsKeyEvent *aEvent,
|
|
|
|
nsEventStatus& aStatus)
|
|
|
|
{
|
1999-04-27 22:14:17 +00:00
|
|
|
nsresult ret = NS_OK;
|
1998-11-24 07:46:58 +00:00
|
|
|
|
|
|
|
//fire keypress
|
|
|
|
nsKeyEvent event;
|
|
|
|
event.eventStructType = NS_KEY_EVENT;
|
|
|
|
event.message = NS_KEY_PRESS;
|
|
|
|
event.widget = nsnull;
|
|
|
|
event.keyCode = aEvent->keyCode;
|
|
|
|
|
|
|
|
nsIContent *content;
|
1999-02-10 00:42:56 +00:00
|
|
|
mCurrentTarget->GetContent(&content);
|
1998-11-24 07:46:58 +00:00
|
|
|
|
|
|
|
if (nsnull != content) {
|
1999-03-28 22:22:54 +00:00
|
|
|
ret = content->HandleDOMEvent(aPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, aStatus);
|
1998-11-24 07:46:58 +00:00
|
|
|
NS_RELEASE(content);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now dispatch to the frame
|
|
|
|
if (nsnull != mCurrentTarget) {
|
|
|
|
mCurrentTarget->HandleEvent(aPresContext, &event, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
PRBool
|
|
|
|
nsEventStateManager::ChangeFocus(nsIContent* aFocus, PRBool aSetFocus)
|
|
|
|
{
|
1999-08-24 00:42:38 +00:00
|
|
|
nsCOMPtr<nsIFocusableContent> focusChange = do_QueryInterface(aFocus);
|
|
|
|
|
|
|
|
if (focusChange) {
|
1999-03-02 19:19:24 +00:00
|
|
|
if (aSetFocus) {
|
|
|
|
focusChange->SetFocus(mPresContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
focusChange->RemoveFocus(mPresContext);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
//XXX Need to deal with Object tag
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull == mCurrentFocus) {
|
|
|
|
if (nsnull == mDocument) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
mPresContext->GetShell(getter_AddRefs(presShell));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (presShell) {
|
1999-02-12 17:45:58 +00:00
|
|
|
presShell->GetDocument(&mDocument);
|
1998-11-18 05:25:26 +00:00
|
|
|
if (nsnull == mDocument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
nsIContent* next = GetNextTabbableContent(mCurrentFocus, nsnull, mCurrentFocus, forward);
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
if (nsnull == 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
|
|
|
|
|
|
|
//Pass focus up to nsIWebShellContainer FocusAvailable
|
|
|
|
nsISupports* container;
|
|
|
|
mPresContext->GetContainer(&container);
|
|
|
|
if (nsnull != container) {
|
|
|
|
nsIWebShell* webShell;
|
|
|
|
if (NS_OK == container->QueryInterface(kIWebShellIID, (void**)&webShell)) {
|
|
|
|
nsIWebShellContainer* webShellContainer;
|
|
|
|
webShell->GetContainer(webShellContainer);
|
|
|
|
if (nsnull != webShellContainer) {
|
1999-04-12 21:24:07 +00:00
|
|
|
webShellContainer->FocusAvailable(webShell, focusTaken);
|
1999-03-02 19:19:24 +00:00
|
|
|
NS_RELEASE(webShellContainer);
|
|
|
|
}
|
|
|
|
NS_RELEASE(webShell);
|
|
|
|
}
|
|
|
|
NS_RELEASE(container);
|
|
|
|
}
|
1999-04-12 21:24:07 +00:00
|
|
|
if (!focusTaken && !topOfDoc) {
|
|
|
|
ShiftFocus(forward);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
ChangeFocus(next, PR_TRUE);
|
1998-11-18 05:25:26 +00:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mCurrentFocus);
|
|
|
|
mCurrentFocus = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At some point this will need to be linked into HTML 4.0 tabindex
|
|
|
|
*/
|
|
|
|
nsIContent*
|
1999-03-02 19:19:24 +00:00
|
|
|
nsEventStateManager::GetNextTabbableContent(nsIContent* aParent, nsIContent* aChild, nsIContent* aTop, PRBool forward)
|
1998-11-18 05:25:26 +00:00
|
|
|
{
|
|
|
|
PRInt32 count, index;
|
|
|
|
aParent->ChildCount(count);
|
|
|
|
|
|
|
|
if (nsnull != aChild) {
|
|
|
|
aParent->IndexOf(aChild, index);
|
1999-03-02 19:19:24 +00:00
|
|
|
index += forward ? 1 : -1;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-07-19 21:23:57 +00:00
|
|
|
index = forward ? 0 : count-1;
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
for (;index < count && index >= 0;index += forward ? 1 : -1) {
|
1998-11-18 05:25:26 +00:00
|
|
|
nsIContent* child;
|
1999-03-02 19:19:24 +00:00
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
aParent->ChildAt(index, child);
|
1999-03-02 19:19:24 +00:00
|
|
|
nsIContent* content = GetNextTabbableContent(child, nsnull, aTop, forward);
|
1998-11-18 05:25:26 +00:00
|
|
|
if (content != nsnull) {
|
|
|
|
NS_IF_RELEASE(child);
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
if (nsnull != child) {
|
|
|
|
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
|
|
|
|
|
|
|
child->GetTag(tag);
|
|
|
|
if (nsHTMLAtoms::input==tag) {
|
|
|
|
nsIDOMHTMLInputElement *nextInput;
|
|
|
|
if (NS_OK == child->QueryInterface(kIDOMHTMLInputElementIID,(void **)&nextInput)) {
|
|
|
|
nextInput->GetDisabled(&disabled);
|
1999-03-02 19:19:24 +00:00
|
|
|
nextInput->GetTabIndex(&tabIndex);
|
1999-01-28 23:14:36 +00:00
|
|
|
|
|
|
|
nsAutoString type;
|
|
|
|
nextInput->GetType(type);
|
|
|
|
if (type.EqualsIgnoreCase("hidden")) {
|
|
|
|
hidden = PR_TRUE;
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_RELEASE(nextInput);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::select==tag) {
|
|
|
|
nsIDOMHTMLSelectElement *nextSelect;
|
|
|
|
if (NS_OK == child->QueryInterface(kIDOMHTMLSelectElementIID,(void **)&nextSelect)) {
|
|
|
|
nextSelect->GetDisabled(&disabled);
|
1999-03-02 19:19:24 +00:00
|
|
|
nextSelect->GetTabIndex(&tabIndex);
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_RELEASE(nextSelect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::textarea==tag) {
|
|
|
|
nsIDOMHTMLTextAreaElement *nextTextArea;
|
|
|
|
if (NS_OK == child->QueryInterface(kIDOMHTMLTextAreaElementIID,(void **)&nextTextArea)) {
|
|
|
|
nextTextArea->GetDisabled(&disabled);
|
1999-03-02 19:19:24 +00:00
|
|
|
nextTextArea->GetTabIndex(&tabIndex);
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_RELEASE(nextTextArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
else if(nsHTMLAtoms::a==tag) {
|
|
|
|
nsIDOMHTMLAnchorElement *nextAnchor;
|
|
|
|
if (NS_OK == child->QueryInterface(kIDOMHTMLAnchorElementIID,(void **)&nextAnchor)) {
|
|
|
|
nextAnchor->GetTabIndex(&tabIndex);
|
|
|
|
NS_RELEASE(nextAnchor);
|
|
|
|
}
|
|
|
|
disabled = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if(nsHTMLAtoms::button==tag) {
|
|
|
|
nsIDOMHTMLButtonElement *nextButton;
|
|
|
|
if (NS_OK == child->QueryInterface(kIDOMHTMLButtonElementIID,(void **)&nextButton)) {
|
|
|
|
nextButton->GetTabIndex(&tabIndex);
|
|
|
|
nextButton->GetDisabled(&disabled);
|
|
|
|
NS_RELEASE(nextButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(nsHTMLAtoms::area==tag) {
|
|
|
|
nsIDOMHTMLAreaElement *nextArea;
|
|
|
|
if (NS_OK == child->QueryInterface(kIDOMHTMLAreaElementIID,(void **)&nextArea)) {
|
|
|
|
nextArea->GetTabIndex(&tabIndex);
|
|
|
|
NS_RELEASE(nextArea);
|
|
|
|
}
|
|
|
|
disabled = PR_FALSE;
|
|
|
|
}
|
|
|
|
else if(nsHTMLAtoms::object==tag) {
|
|
|
|
nsIDOMHTMLObjectElement *nextObject;
|
|
|
|
if (NS_OK == child->QueryInterface(kIDOMHTMLObjectElementIID,(void **)&nextObject)) {
|
|
|
|
nextObject->GetTabIndex(&tabIndex);
|
|
|
|
NS_RELEASE(nextObject);
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
disabled = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
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) {
|
1998-11-18 05:25:26 +00:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aParent == aTop) {
|
|
|
|
nsIContent* nextParent;
|
|
|
|
aParent->GetParent(nextParent);
|
|
|
|
if (nsnull != nextParent) {
|
1999-03-02 19:19:24 +00:00
|
|
|
nsIContent* content = GetNextTabbableContent(nextParent, aParent, nextParent, forward);
|
1998-11-18 05:25:26 +00:00
|
|
|
NS_RELEASE(nextParent);
|
|
|
|
return content;
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
//Reached end of document
|
|
|
|
else {
|
|
|
|
//If already at lowest priority tab (0), end
|
1999-07-19 21:23:57 +00:00
|
|
|
if (((forward) && (0 == mCurrentTabIndex)) ||
|
|
|
|
((!forward) && (1 == mCurrentTabIndex))) {
|
1999-03-02 19:19:24 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
//else continue looking for next highest priority tab
|
|
|
|
mCurrentTabIndex = GetNextTabIndex(aParent, forward);
|
|
|
|
nsIContent* content = GetNextTabbableContent(aParent, nsnull, aParent, forward);
|
|
|
|
return content;
|
|
|
|
}
|
1998-11-18 05:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
nsIContent* child;
|
|
|
|
|
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++) {
|
|
|
|
aParent->ChildAt(index, child);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
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++) {
|
|
|
|
aParent->ChildAt(index, child);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-18 05:25:26 +00:00
|
|
|
*aFrame = mCurrentTarget;
|
1999-07-27 20:55:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEventStateManager::GetEventTargetContent(nsIContent** aContent)
|
|
|
|
{
|
|
|
|
if (mCurrentTargetContent) {
|
|
|
|
*aContent = mCurrentTargetContent;
|
|
|
|
NS_IF_ADDREF(*aContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCurrentTarget) {
|
|
|
|
mCurrentTarget->GetContent(aContent);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-04-20 00:03:30 +00:00
|
|
|
if ((aState & NS_EVENT_STATE_FOCUS) && (aContent != mCurrentFocus)) {
|
|
|
|
SendFocusBlur(aContent);
|
1999-01-28 23:14:36 +00:00
|
|
|
|
1999-04-20 00:03:30 +00:00
|
|
|
//transferring ref to notifyContent from mCurrentFocus
|
|
|
|
notifyContent[3] = mCurrentFocus;
|
|
|
|
mCurrentFocus = aContent;
|
|
|
|
NS_IF_ADDREF(mCurrentFocus);
|
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) {
|
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
|
|
|
}
|
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-04-12 21:24:07 +00:00
|
|
|
nsEventStateManager::SendFocusBlur(nsIContent *aContent)
|
1999-03-02 19:19:24 +00:00
|
|
|
{
|
|
|
|
if (mCurrentFocus == aContent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-07 23:18:35 +00:00
|
|
|
nsIContent* targetBeforeEvent = mCurrentTargetContent;
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
if (mCurrentFocus) {
|
|
|
|
ChangeFocus(mCurrentFocus, PR_FALSE);
|
|
|
|
|
|
|
|
//fire blur
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
nsEvent event;
|
|
|
|
event.eventStructType = NS_EVENT;
|
|
|
|
event.message = NS_BLUR_CONTENT;
|
|
|
|
|
1999-08-07 23:18:35 +00:00
|
|
|
mCurrentTargetContent = mCurrentFocus;
|
|
|
|
NS_ADDREF(mCurrentTargetContent);
|
|
|
|
|
1999-03-02 19:19:24 +00:00
|
|
|
if (nsnull != mPresContext) {
|
1999-03-28 22:22:54 +00:00
|
|
|
mCurrentFocus->HandleDOMEvent(*mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
1999-08-07 23:18:35 +00:00
|
|
|
|
|
|
|
NS_RELEASE(mCurrentTargetContent);
|
1999-03-02 19:19:24 +00:00
|
|
|
}
|
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
if (nsnull != aContent) {
|
|
|
|
//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-08-07 23:18:35 +00:00
|
|
|
mCurrentTargetContent = aContent;
|
|
|
|
NS_ADDREF(mCurrentTargetContent);
|
|
|
|
|
1999-04-12 21:24:07 +00:00
|
|
|
if (nsnull != mPresContext) {
|
|
|
|
aContent->HandleDOMEvent(*mPresContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
|
|
|
}
|
1999-03-02 19:19:24 +00:00
|
|
|
|
1999-08-07 23:18:35 +00:00
|
|
|
NS_RELEASE(mCurrentTargetContent);
|
|
|
|
|
|
|
|
//reset mCurretTargetContent to what it was
|
|
|
|
mCurrentTargetContent = targetBeforeEvent;
|
|
|
|
|
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;
|
|
|
|
}
|
1999-09-20 22:18:57 +00:00
|
|
|
|
|
|
|
// Check to see if the mCurrentTarget has a view with a widget
|
|
|
|
// i.e TextField or TextArea, if so, don't set the focus on their window
|
|
|
|
PRBool shouldSetFocusOnWindow = PR_TRUE;
|
|
|
|
if (nsnull != mCurrentTarget) {
|
|
|
|
nsIView * view = nsnull;
|
|
|
|
mCurrentTarget->GetView(&view);
|
|
|
|
if (view != nsnull) {
|
|
|
|
nsIWidget *window = nsnull;
|
|
|
|
view->GetWidget(window);
|
|
|
|
if (window != nsnull) { // addrefs
|
|
|
|
shouldSetFocusOnWindow = PR_FALSE;
|
|
|
|
NS_RELEASE(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the window that this frame is in and
|
|
|
|
// make sure it has focus
|
|
|
|
// XXX Note: mLastWindowToHaveFocus this does not track when ANY focus
|
|
|
|
// event comes through, the only place this gets set is here
|
|
|
|
// so some windows may get multiple focus events
|
|
|
|
// For example, if you clicked in the window (generates focus event)
|
|
|
|
// then click on a gfx control (generates another focus event)
|
|
|
|
if (shouldSetFocusOnWindow && nsnull != mCurrentTarget) {
|
|
|
|
nsIFrame * parentFrame;
|
|
|
|
mCurrentTarget->GetParentWithView(&parentFrame);
|
|
|
|
if (nsnull != parentFrame) {
|
|
|
|
nsIView * pView;
|
|
|
|
parentFrame->GetView(&pView);
|
|
|
|
if (nsnull != pView) {
|
|
|
|
nsIWidget *window = nsnull;
|
|
|
|
|
|
|
|
nsIView *ancestor = pView;
|
|
|
|
while (nsnull != ancestor) {
|
|
|
|
ancestor->GetWidget(window); // addrefs
|
|
|
|
if (nsnull != window) {
|
|
|
|
if (window != mLastWindowToHaveFocus) {
|
|
|
|
window->SetFocus();
|
|
|
|
NS_IF_RELEASE(mLastWindowToHaveFocus);
|
|
|
|
mLastWindowToHaveFocus = window;
|
|
|
|
} else {
|
|
|
|
NS_IF_RELEASE(window);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ancestor->GetParent(ancestor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-06-23 21:53:02 +00:00
|
|
|
nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return manager->QueryInterface(kIEventStateManagerIID, (void **) aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|