Bug 503877 - Remove nsSwitchToUIThread r=vlad

This commit is contained in:
Rob Arnold 2009-08-04 15:15:19 -07:00
Родитель 1c601ecdaa
Коммит 4c50b117bb
6 изменённых файлов: 1 добавлений и 244 удалений

Просмотреть файл

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef SWITCHTOUITHREAD_H
#define SWITCHTOUITHREAD_H
// foreward declaration
struct MethodInfo;
/**
* Switch thread to match the thread the widget was created in so messages will be dispatched.
*/
class nsSwitchToUIThread {
public:
virtual BOOL CallMethod(MethodInfo *info) = 0;
};
//
// Structure used for passing the information necessary for synchronously
// invoking a method on the GUI thread...
//
struct MethodInfo {
nsSwitchToUIThread* target;
UINT methodId;
int nArgs;
DWORD_PTR* args;
MethodInfo(nsSwitchToUIThread *obj, UINT id, int numArgs=0, DWORD_PTR *arguments = 0) {
target = obj;
methodId = id;
nArgs = numArgs;
args = arguments;
}
BOOL Invoke() { return target->CallMethod(this); }
};
#endif // TOUITHRD_H

Просмотреть файл

@ -333,11 +333,6 @@ LRESULT CALLBACK nsToolkit::WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam)
{
switch (msg) {
case WM_CALLMETHOD:
{
MethodInfo *info = (MethodInfo *)lParam;
return info->Invoke();
}
#ifndef WINCE
case WM_SYSCOLORCHANGE:
{

Просмотреть файл

@ -55,7 +55,6 @@
#define GET_Y_LPARAM(pt) (short(HIWORD(pt)))
#endif
struct MethodInfo;
class nsIEventQueue;
class MouseTrailer;
@ -83,11 +82,6 @@ class nsToolkit : public nsIToolkit
nsToolkit();
NS_IMETHOD Init(PRThread *aThread);
void CallMethod(MethodInfo *info);
// Return whether the current thread is the application's Gui thread.
PRBool IsGuiThread(void) { return (PRBool)(mGuiThread == PR_GetCurrentThread());}
PRThread* GetGuiThread(void) { return mGuiThread; }
HWND GetDispatchWindow(void) { return mDispatchWnd; }
void CreateInternalWindow(PRThread *aThread);
private:
@ -119,14 +113,6 @@ public:
static MouseTrailer *gMouseTrailer;
};
#define WM_CALLMETHOD (WM_USER+1)
inline void nsToolkit::CallMethod(MethodInfo *info)
{
NS_PRECONDITION(::IsWindow(mDispatchWnd), "Invalid window handle");
::SendMessage(mDispatchWnd, WM_CALLMETHOD, (WPARAM)0, (LPARAM)info);
}
class nsWindow;
/**

Просмотреть файл

@ -614,34 +614,6 @@ nsWindow::StandardWindowCreate(nsIWidget *aParent,
BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
aAppShell, aToolkit, aInitData);
// Switch to the "main gui thread" if necessary... This method must
// be executed on the "gui thread"...
nsToolkit* toolkit = (nsToolkit *)mToolkit;
if (toolkit && !toolkit->IsGuiThread()) {
DWORD_PTR args[7];
args[0] = (DWORD_PTR)aParent;
args[1] = (DWORD_PTR)&aRect;
args[2] = (DWORD_PTR)aHandleEventFunction;
args[3] = (DWORD_PTR)aContext;
args[4] = (DWORD_PTR)aAppShell;
args[5] = (DWORD_PTR)aToolkit;
args[6] = (DWORD_PTR)aInitData;
if (nsnull != aParent) {
// nsIWidget parent dispatch
MethodInfo info(this, nsWindow::CREATE, 7, args);
toolkit->CallMethod(&info);
return NS_OK;
}
else {
// Native parent dispatch
MethodInfo info(this, nsWindow::CREATE_NATIVE, 5, args);
toolkit->CallMethod(&info);
return NS_OK;
}
}
HWND parent;
if (nsnull != aParent) { // has a nsIWidget parent
parent = ((aParent) ? (HWND)aParent->GetNativeData(NS_NATIVE_WINDOW) : nsnull);
@ -766,15 +738,6 @@ NS_METHOD nsWindow::Destroy()
if (nsnull == mWnd)
return NS_OK;
// Switch to the "main gui thread" if necessary. Destroy() must be executed on the
// "gui thread".
nsToolkit* toolkit = (nsToolkit *)mToolkit;
if (toolkit != nsnull && !toolkit->IsGuiThread()) {
MethodInfo info(this, nsWindow::DESTROY);
toolkit->CallMethod(&info);
return NS_ERROR_FAILURE;
}
// During the destruction of all of our children, make sure we don't get deleted.
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
@ -1669,16 +1632,6 @@ NS_METHOD nsWindow::IsEnabled(PRBool *aState)
NS_METHOD nsWindow::SetFocus(PRBool aRaise)
{
// Switch to the "main gui thread" if necessary... This method must
// be executed on the "gui thread"...
nsToolkit* toolkit = (nsToolkit *)mToolkit;
NS_ASSERTION(toolkit != nsnull, "This should never be null!"); // Bug 57044
if (toolkit != nsnull && !toolkit->IsGuiThread()) {
MethodInfo info(this, nsWindow::SET_FOCUS);
toolkit->CallMethod(&info);
return NS_ERROR_FAILURE;
}
if (mWnd) {
// Uniconify, if necessary
HWND toplevelWnd = GetTopLevelHWND(mWnd);
@ -2731,71 +2684,6 @@ nsWindow::OnDefaultButtonLoaded(const nsIntRect &aButtonRect)
#endif
}
/**************************************************************
**************************************************************
**
** BLOCK: nsSwitchToUIThread impl.
**
** Switch thread to match the thread the widget was created
** in so messages will be dispatched.
**
**************************************************************
**************************************************************/
/**************************************************************
*
* SECTION: nsSwitchToUIThread::CallMethod
*
* Every function that needs a thread switch goes through this function
* by calling SendMessage (..WM_CALLMETHOD..) in nsToolkit::CallMethod.
*
**************************************************************/
BOOL nsWindow::CallMethod(MethodInfo *info)
{
BOOL bRet = TRUE;
switch (info->methodId) {
case nsWindow::CREATE:
NS_ASSERTION(info->nArgs == 7, "Wrong number of arguments to CallMethod");
Create((nsIWidget*)(info->args[0]),
(nsIntRect&)*(nsIntRect*)(info->args[1]),
(EVENT_CALLBACK)(info->args[2]),
(nsIDeviceContext*)(info->args[3]),
(nsIAppShell *)(info->args[4]),
(nsIToolkit*)(info->args[5]),
(nsWidgetInitData*)(info->args[6]));
break;
case nsWindow::CREATE_NATIVE:
NS_ASSERTION(info->nArgs == 7, "Wrong number of arguments to CallMethod");
Create((nsNativeWidget)(info->args[0]),
(nsIntRect&)*(nsIntRect*)(info->args[1]),
(EVENT_CALLBACK)(info->args[2]),
(nsIDeviceContext*)(info->args[3]),
(nsIAppShell *)(info->args[4]),
(nsIToolkit*)(info->args[5]),
(nsWidgetInitData*)(info->args[6]));
return TRUE;
case nsWindow::DESTROY:
NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod");
Destroy();
break;
case nsWindow::SET_FOCUS:
NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod");
SetFocus(PR_FALSE);
break;
default:
bRet = FALSE;
break;
}
return bRet;
}
/**************************************************************
**************************************************************
**

Просмотреть файл

@ -51,7 +51,6 @@
#include "nsBaseWidget.h"
#include "nsdefs.h"
#include "nsSwitchToUIThread.h"
#include "nsToolkit.h"
#include "nsIEventListener.h"
#include "nsString.h"
@ -91,8 +90,7 @@ class imgIContainer;
* Native WIN32 window wrapper.
*/
class nsWindow : public nsSwitchToUIThread,
public nsBaseWidget
class nsWindow : public nsBaseWidget
{
public:
nsWindow();
@ -184,11 +182,6 @@ public:
NS_IMETHOD OnIMESelectionChange(void);
#endif // NS_ENABLE_TSF
/**
* nsSwitchToUIThread interface
*/
virtual BOOL CallMethod(MethodInfo *info);
/**
* Statics used in other classes
*/
@ -393,22 +386,6 @@ protected:
static STDMETHODIMP_(LRESULT) LresultFromObject(REFIID riid, WPARAM wParam, LPUNKNOWN pAcc);
#endif // ACCESSIBILITY
protected:
/**
* nsSwitchToUIThread
*/
enum {
// Enumeration of the methods which are accessible on the "main GUI thread"
// via the CallMethod(...) mechanism. (see nsSwitchToUIThread)
CREATE = 0x0101,
CREATE_NATIVE,
DESTROY,
SET_FOCUS,
SET_CURSOR,
CREATE_HACK
};
protected:
nsIntSize mLastSize;
nsIntPoint mLastPoint;

Просмотреть файл

@ -199,18 +199,6 @@ protected:
// so it can be cleared automatically.
static nsIContent* mLastRollup;
// Enumeration of the methods which are accessible on the "main GUI thread"
// via the CallMethod(...) mechanism...
// see nsSwitchToUIThread
enum {
CREATE = 0x0101,
CREATE_NATIVE,
DESTROY,
SET_FOCUS,
SET_CURSOR,
CREATE_HACK
};
#ifdef DEBUG
protected:
static nsAutoString debug_GuiEventToString(nsGUIEvent * aGuiEvent);