From 4bc897076e2fb5ca1209c2b33b83ab40a0f4bbe0 Mon Sep 17 00:00:00 2001 From: "locka%iol.ie" Date: Wed, 17 Jan 2001 21:10:46 +0000 Subject: [PATCH] New embedding routines to be called by host apps during message processing and idle time. b=44120. NOT PART OF BUILD (yet) --- embedding/base/nsEmbedAPI.h | 59 ++++++++++++++++++++++++++--- embedding/base/nsEmbedWin32.cpp | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 embedding/base/nsEmbedWin32.cpp diff --git a/embedding/base/nsEmbedAPI.h b/embedding/base/nsEmbedAPI.h index 74758771ab50..7570456c85df 100644 --- a/embedding/base/nsEmbedAPI.h +++ b/embedding/base/nsEmbedAPI.h @@ -29,15 +29,64 @@ #include "nsIDirectoryService.h" -/* - aPath -> the mozilla bin directory. If nsnull, the default is used - aProvider -> the application directory service provider. If nsnull, the - default (nsAppFileLocationProvider) is constructed and used. -*/ +/** + * Function to initialise the Gecko embedding APIs. You *must* call this + * method before any others! + * + * aPath -> the mozilla bin directory. If nsnull, the default is used + * aProvider -> the application directory service provider. If nsnull, the + * default (nsAppFileLocationProvider) is constructed and used. + */ extern nsresult NS_InitEmbedding(nsILocalFile *mozBinDirectory, nsIDirectoryServiceProvider *appFileLocProvider); + + +/** + * Function to call to finish the Gecko embedding APIs. + */ extern nsresult NS_TermEmbedding(); +/*---------------------------------------------------------------------------*/ +/* Event processing APIs. The native OS dependencies mean you must be */ +/* building on a supported platform to get the functions below. */ +/*---------------------------------------------------------------------------*/ +#undef MOZ_SUPPORTS_EMBEDDING_EVENT_PROCESSING + +/* Win32 specific stuff */ +#ifdef WIN32 +#include "windows.h" +typedef MSG nsEmbedNativeEvent; +#define MOZ_SUPPORTS_EMBEDDING_EVENT_PROCESSING #endif +/* Mac specific stuff */ +/* TODO implementation left as an exercise for the reader */ + +/* GTK specific stuff */ +/* TODO implementation left as an exercise for the reader */ + + +#ifdef MOZ_SUPPORTS_EMBEDDING_EVENT_PROCESSING + +/** + * Function to call during the idle time in your application and/or as each + * event is processed. This function ensures things such as timers are fired + * correctly. + */ +extern nsresult NS_DoIdleEmbeddingStuff(); + + +/** + * Function to call before handling an event. It gives Gecko the chance to + * handle the event first. + * + * aEvent -> the native UI event + * aWasHandled -> returns with PR_TRUE if the event was handled by Gecko + */ +extern nsresult NS_HandleEmbeddingEvent(nsEmbedNativeEvent &aEvent, PRBool &aWasHandled); + +#endif /* MOZ_SUPPORTS_EMBEDDING_EVENT_PROCESSING */ + +#endif /* NSEMBEDAPI_H */ + diff --git a/embedding/base/nsEmbedWin32.cpp b/embedding/base/nsEmbedWin32.cpp new file mode 100644 index 000000000000..a73fbc5a5255 --- /dev/null +++ b/embedding/base/nsEmbedWin32.cpp @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + * + * Author: + * Adam Lock + * + * Contributor(s): + */ + +#include "nsEmbedAPI.h" + +#ifndef WIN32 +#error This file is for Win32! +#endif + +#ifdef MOZ_SUPPORTS_EMBEDDING_EVENT_PROCESSING + +#include "nsWidgetsCID.h" +#include "nsITimer.h" +#include "nsITimerQueue.h" + +static NS_DEFINE_CID(kTimerManagerCID, NS_TIMERMANAGER_CID); + +nsresult NS_DoIdleEmbeddingStuff() +{ + nsresult rv = NS_ERROR_FAILURE; + NS_WITH_SERVICE(nsITimerQueue, timerQueue, kTimerManagerCID, &rv); + if (NS_FAILED(rv)) + { + return NS_ERROR_FAILURE; + } + + if (timerQueue->HasReadyTimers(NS_PRIORITY_LOWEST)) + { + MSG wmsg; + do + { + timerQueue->FireNextReadyTimer(NS_PRIORITY_LOWEST); + } while (timerQueue->HasReadyTimers(NS_PRIORITY_LOWEST) && + !::PeekMessage(&wmsg, NULL, 0, 0, PM_NOREMOVE)); + } + return NS_OK; +} + +nsresult NS_HandleEmbeddingEvent(nsEmbedNativeEvent &aEvent, PRBool &aWasHandled) +{ + aWasHandled = PR_FALSE; + return NS_OK; +} + +#endif /* MOZ_SUPPORTS_EMBEDDING_EVENT_PROCESSING */