From 5e167b12ea6ac16ca235c1a2dbcf5b32afd22f58 Mon Sep 17 00:00:00 2001 From: "Jerry.Kirk%Nexwarecorp.com" Date: Fri, 3 Sep 1999 12:55:19 +0000 Subject: [PATCH] Just the beginnings of a Photon Event Loop, still work in progress git-svn-id: svn://10.0.0.236/trunk@45882 18797224-902f-48f8-a5cc-f745e15eee43 --- .../appshell/eventloop/photon/nsCEvent.cpp | 100 ++++++++++++++ .../appshell/eventloop/photon/nsCEvent.h | 47 +++++++ .../eventloop/photon/nsCEventFilter.cpp | 78 +++++++++++ .../eventloop/photon/nsCEventFilter.h | 47 +++++++ .../appshell/eventloop/photon/nsCPhFilter.h | 38 ++++++ .../eventloop/photon/nsCPlatformBaseLoop.cpp | 122 ++++++++++++++++++ .../eventloop/photon/nsCPlatformBaseLoop.h | 57 ++++++++ .../appshell/eventloop/photon/nsIPhEvent.idl | 12 ++ .../eventloop/photon/nsIPhEventFilter.idl | 14 ++ 9 files changed, 515 insertions(+) create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCEvent.cpp create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCEvent.h create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.cpp create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.h create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCPhFilter.h create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.cpp create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.h create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsIPhEvent.idl create mode 100644 mozilla/xpcom/appshell/eventloop/photon/nsIPhEventFilter.idl diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.cpp b/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.cpp new file mode 100644 index 00000000000..186677c94cb --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.cpp @@ -0,0 +1,100 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + * Jerry Kirk + */ + +#include "nsCRT.h" + +#include "nsCEvent.h" + +//***************************************************************************** +//*** nsCEvent: Object Management +//***************************************************************************** + +nsCEvent::nsCEvent(void* platformEventData) +{ + NS_INIT_REFCNT(); + + if (platformEventData) + { + mEventBufferSz = PhGetMsgSize ( (PhEvent_t *) platformEventData ); + m_msg = (PhEvent_t *) malloc( mEventBufferSz ); + NS_ENSURE_ARG_POINTER(m_msg); + nsCRT::memcpy(m_msg, platformEventData, mEventBufferSz); + } + else + { + mEventBufferSz = sizeof(PhEvent_t); + m_msg = (PhEvent_t *) malloc( mEventBufferSz ); + NS_ENSURE_ARG_POINTER(m_msg); + nsCRT::memset(m_msg, 0, mEventBufferSz); + } +} + +nsCEvent::~nsCEvent() +{ +} + +//***************************************************************************** +// nsCEvent::nsISupports +//***************************************************************************** + +NS_IMPL_ISUPPORTS1(nsCEvent, nsIEvent) + +//***************************************************************************** +// nsCEvent::nsIEvent +//***************************************************************************** + +NS_IMETHODIMP nsCEvent::GetNativeData(nsNativeEventDataType dataType, + void** data) +{ + NS_ENSURE_ARG(nsNativeEventDataTypes::PhotonMsgStruct == dataType); + NS_ENSURE_ARG_POINTER(data); + + *data = m_msg; + + return NS_OK; +} + +NS_IMETHODIMP nsCEvent::SetNativeData(nsNativeEventDataType dataType, + void* data) +{ + NS_ENSURE_ARG(nsNativeEventDataTypes::PhotonMsgStruct == dataType); + + if(!data) + { + /* Get rid of the Event */ + nsCRT::memset(m_msg, 0, mEventBufferSz); + } + else + { + unsigned long locEventBufferSz = PhGetMsgSize ( (PhEvent_t *) data ); + if (locEventBufferSz > mEventBufferSz) + { + mEventBufferSz = locEventBufferSz; + m_msg = (PhEvent_t *) realloc( mEventBufferSz ); + NS_ENSURE_ARG_POINTER(m_msg); + } + nsCRT::memcpy(m_msg, data, mEventBufferSz); + } + + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.h b/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.h new file mode 100644 index 00000000000..57b6d651b21 --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCEvent.h @@ -0,0 +1,47 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + * Jerry Kirk + */ + +#ifndef nsCEvent_h__ +#define nsCEvent_h__ + +#include "PhT.h" +#include "nsIEvent.h" + +class nsCEvent : public nsIEvent +{ +public: + nsCEvent(void* platformEventData=nsnull); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIEVENT + +protected: + virtual ~nsCEvent(); + +protected: + PhEvent_t *m_msg; + unsigned long mEventBufferSz; +}; + +#endif /* nsCEvent_h__ */ diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.cpp b/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.cpp new file mode 100644 index 00000000000..2eed2f731a6 --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.cpp @@ -0,0 +1,78 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + * Jerry Kirk + */ + +#include "nsCRT.h" + +#include "nsCEventFilter.h" + +//***************************************************************************** +//*** nsCEventFilter: Object Management +//***************************************************************************** + +nsCEventFilter::nsCEventFilter(void* platformFilterData) +{ + NS_INIT_REFCNT(); + + if(platformFilterData) + nsCRT::memcpy(&m_filter, platformFilterData, sizeof(m_filter)); + else + nsCRT::memset(&m_filter, 0, sizeof(m_filter)); +} + +nsCEventFilter::~nsCEventFilter() +{ +} + +//***************************************************************************** +// nsCEventFilter::nsISupports +//***************************************************************************** + +NS_IMPL_ISUPPORTS1(nsCEventFilter, nsIEventFilter) + +//***************************************************************************** +// nsCEventFilter::nsIEventFilter +//***************************************************************************** + +NS_IMETHODIMP nsCEventFilter::GetNativeData(nsNativeFilterDataType dataType, + void** data) +{ + NS_ENSURE_ARG(nsNativeFilterDataTypes::PhotonFilter == dataType); + NS_ENSURE_ARG_POINTER(data); + + *data = &m_filter; + + return NS_OK; +} + +NS_IMETHODIMP nsCEventFilter::SetNativeData(nsNativeFilterDataType dataType, + void* data) +{ + NS_ENSURE_ARG(nsNativeFilterDataTypes::PhotonFilter == dataType); + + if(!data) + nsCRT::memset(&m_filter, 0, sizeof(m_filter)); + else + nsCRT::memcpy(&m_filter, data, sizeof(m_filter)); + + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.h b/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.h new file mode 100644 index 00000000000..617932172fa --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCEventFilter.h @@ -0,0 +1,47 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + * Jerry Kirk + */ + +#ifndef nsCEventFilter_h__ +#define nsCEventFilter_h__ + +#include "PhT.h" +#include "nsIEventFilter.h" +#include "nsCPhFilter.h" + +class nsCEventFilter : public nsIEventFilter +{ +public: + nsCEventFilter(void* platformFilterData=nsnull); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIEVENTFILTER + +protected: + virtual ~nsCEventFilter(); + +protected: + nsCPhFilter m_filter; +}; + +#endif /* nsCEventFilter_h__ */ diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCPhFilter.h b/mozilla/xpcom/appshell/eventloop/photon/nsCPhFilter.h new file mode 100644 index 00000000000..e54799c373b --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCPhFilter.h @@ -0,0 +1,38 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + * Jerry Kirk + */ + +#ifndef nsCPhFilter_h__ +#define nsCPhFilter_h__ + +#include "Pht.h" + +class nsCPhFilter +{ +public: +// HWND hWnd; +// UINT wMsgFilterMin; +// UINT wMsgFilterMax; +// UINT wRemoveFlags; // fRemoveEvent flag passed to PeekEvent takes precedent +}; // over PM_NOREMOVE and PM_REMOVE. + +#endif /* nsPhFilter_h__ */ diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.cpp b/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.cpp new file mode 100644 index 00000000000..d2df1abd55d --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.cpp @@ -0,0 +1,122 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + * Jerry Kirk + */ + +#include "nsCPlatformBaseLoop.h" +#include "nsCPhFilter.h" + +//***************************************************************************** +//*** nsCPlatformBaseLoop: Object Management +//***************************************************************************** + +nsCPlatformBaseLoop::nsCPlatformBaseLoop(nsEventLoopType type) : + nsCBaseLoop(type) +{ + m_PhThreadId = pthread_self(); +} + +nsCPlatformBaseLoop::~nsCPlatformBaseLoop() +{ +} + +//***************************************************************************** +// nsCPlatformBaseLoop:: Internal Platform Implementations of nsIEventLoop +// (Error checking is ensured above) +//***************************************************************************** + +nsresult nsCPlatformBaseLoop::PlatformGetNextEvent(void* platformFilterData, + void* platformEventData) +{ + nsCPhFilter* filter=(nsCPhFilter*)platformFilterData; + PhEvent_t* pEvent = (PhEvent_t*) platformEventData; + if(::GetMessage(pMsg, filter->hWnd, filter->wMsgFilterMin, + filter->wMsgFilterMax)) + return NS_OK; + return NS_COMFALSE; +} + +nsresult nsCPlatformBaseLoop::PlatformPeekNextEvent(void* platformFilterData, + void* platformEventData, PRBool fRemoveEvent) +{ + nsCWinFilter* filter=(nsCWinFilter*)platformFilterData; + MSG* pMsg=(MSG*)platformEventData; + + if(fRemoveEvent) + filter->wRemoveFlags|= PM_REMOVE; + else + filter->wRemoveFlags&= ~PM_REMOVE; + if(::PeekMessage(pMsg, filter->hWnd, filter->wMsgFilterMin, + filter->wMsgFilterMax, filter->wRemoveFlags)) + return NS_OK; + return NS_COMFALSE; +} + +nsresult nsCPlatformBaseLoop::PlatformTranslateEvent(void* platformEventData) +{ + MSG* pMsg=(MSG*)platformEventData; + ::TranslateMessage(pMsg); + return NS_OK; +} + +nsresult nsCPlatformBaseLoop::PlatformDispatchEvent(void* platformEventData) +{ + MSG* pMsg=(MSG*)platformEventData; + ::DispatchMessage(pMsg); + return NS_OK; +} + +nsresult nsCPlatformBaseLoop::PlatformSendLoopEvent(void* platformEventData, PRInt32* result) +{ + MSG* pMsg=(MSG*)platformEventData; + *result = ::SendMessage(pMsg->hwnd, pMsg->message, pMsg->wParam,pMsg->lParam); + return NS_OK; +} + +nsresult nsCPlatformBaseLoop::PlatformPostLoopEvent(void* platformEventData) +{ + MSG* pMsg=(MSG*)platformEventData; + if(!pMsg->hwnd) + { + if(!::PostThreadMessage(m_WinThreadId, pMsg->message, pMsg->wParam, + pMsg->lParam)) + return NS_ERROR_FAILURE; + } + else if(!::PostMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam)) + return NS_ERROR_FAILURE; + return NS_OK; +} + +nsNativeEventDataType nsCPlatformBaseLoop::PlatformGetEventType() +{ + return nsNativeEventDataTypes::WinMsgStruct; +} + +nsNativeEventDataType nsCPlatformBaseLoop::PlatformGetFilterType() +{ + return nsNativeFilterDataTypes::WinFilter; +} + +PRInt32 nsCPlatformBaseLoop::PlatformGetReturnCode(void* platformEventData) +{ + MSG* pMsg=(MSG*)platformEventData; + return pMsg->wParam; +} \ No newline at end of file diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.h b/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.h new file mode 100644 index 00000000000..3aa0395fae5 --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsCPlatformBaseLoop.h @@ -0,0 +1,57 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * The Original Code is the Mozilla browser. + * + * The Initial Developer of the Original Code is Netscape + * Communications, Inc. Portions created by Netscape are + * Copyright (C) 1999, Mozilla. All Rights Reserved. + * + * Contributor(s): + * Travis Bogard + * Jerry Kirk + */ + +#ifndef nsCPlatformBaseLoop_h__ +#define nsCPlatformBaseLoop_h__ + +#include "PhT.h" + +#include "nsCBaseLoop.h" + +class nsCPlatformBaseLoop : public nsCBaseLoop +{ +protected: + nsCPlatformBaseLoop(nsEventLoopType type); + virtual ~nsCPlatformBaseLoop(); + + // Internal Platform Implementations of nsIEventLoop + // (Error checking is ensured above) + // We can over-ride these at a high level because they are the same + // across all types of event loops. + nsresult PlatformGetNextEvent(void* platformFilterData, void* platformEventData); + nsresult PlatformPeekNextEvent(void* FilterData, void* platformEventData, + PRBool fRemoveElement); + nsresult PlatformTranslateEvent(void* platformEventData); + nsresult PlatformDispatchEvent(void* platformEventData); + nsresult PlatformSendLoopEvent(void* platformEventData, PRInt32* result); + nsresult PlatformPostLoopEvent(void* platformEventData); + + nsNativeEventDataType PlatformGetEventType(); + nsNativeFilterDataType PlatformGetFilterType(); + PRInt32 PlatformGetReturnCode(void* platformEventData); + +protected: + pthread_t m_PhThreadId; +}; + +#endif /* nsCAppLoop_h__ */ diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsIPhEvent.idl b/mozilla/xpcom/appshell/eventloop/photon/nsIPhEvent.idl new file mode 100644 index 00000000000..ab902c6a1d9 --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsIPhEvent.idl @@ -0,0 +1,12 @@ +#include "nsISupports.idl" +#include "nsIEvent.idl" + +/** + * The nsIPhEvent defines what a message looks like on the Photon Platform. + */ + +[scriptable, uuid(2EFB5005-4508-11d3-AEDA-00A024FFC08C)] +interface nsIPhEvent : nsIEvent +{ + //XXX Place the contents of a Photon PhEvent_t struct here. +}; \ No newline at end of file diff --git a/mozilla/xpcom/appshell/eventloop/photon/nsIPhEventFilter.idl b/mozilla/xpcom/appshell/eventloop/photon/nsIPhEventFilter.idl new file mode 100644 index 00000000000..f4482b8c35b --- /dev/null +++ b/mozilla/xpcom/appshell/eventloop/photon/nsIPhEventFilter.idl @@ -0,0 +1,14 @@ +#include "nsISupports.idl" +#include "nsIEventFilter.idl" + +/** + * The nsIPhEventFilter defines what a message filter looks like on the Photon + * Platform. + */ + +[scriptable, uuid(2EFB5006-4508-11d3-AEDA-00A024FFC08C)] +interface nsIPhEventFilter : nsIEventFilter +{ + //XXX Place the contents of a Photon PhEvent_t struct here. + //As well as other needed filtering criteria. +}; \ No newline at end of file