2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 22:01:16 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-23 19:19:23 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* 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/
|
1998-09-23 19:19:23 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-09-23 19:19:23 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2003-05-08 18:31:01 +00:00
|
|
|
* Dean Tessman <dean_tessman@hotmail.com>
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 22:01:16 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 22:01:16 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 22:01:16 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-09-23 19:19:23 +00:00
|
|
|
|
|
|
|
#include "nsBaseWidget.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
1999-01-25 19:18:43 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-23 19:19:23 +00:00
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2004-11-24 22:48:45 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2003-05-08 18:31:01 +00:00
|
|
|
#include "nsIScreenManager.h"
|
2004-09-07 18:59:27 +00:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2007-02-07 07:46:44 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2007-12-03 16:33:42 +00:00
|
|
|
#include "nsIContent.h"
|
1999-09-09 02:32:54 +00:00
|
|
|
#include "nsIServiceManager.h"
|
2006-10-23 15:29:09 +00:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch2.h"
|
2010-03-01 08:03:49 +00:00
|
|
|
#include "BasicLayers.h"
|
2010-03-31 03:02:58 +00:00
|
|
|
#include "LayerManagerOGL.h"
|
2009-09-24 10:58:04 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2006-10-23 15:29:09 +00:00
|
|
|
#include "nsIObserver.h"
|
1999-12-03 07:23:22 +00:00
|
|
|
|
|
|
|
static void debug_RegisterPrefCallbacks();
|
|
|
|
|
2007-09-27 16:01:32 +00:00
|
|
|
static PRBool debug_InSecureKeyboardInputMode = PR_FALSE;
|
1999-09-09 02:32:54 +00:00
|
|
|
#endif
|
|
|
|
|
1999-10-05 14:53:40 +00:00
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
|
|
|
static PRInt32 gNumWidgets;
|
|
|
|
#endif
|
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2007-12-03 16:33:42 +00:00
|
|
|
nsIContent* nsBaseWidget::mLastRollup = nsnull;
|
|
|
|
|
1999-09-04 08:13:41 +00:00
|
|
|
// nsBaseWidget
|
|
|
|
NS_IMPL_ISUPPORTS1(nsBaseWidget, nsIWidget)
|
1999-02-23 08:10:24 +00:00
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
|
2007-12-03 16:33:42 +00:00
|
|
|
nsAutoRollup::nsAutoRollup()
|
|
|
|
{
|
|
|
|
// remember if mLastRollup was null, and only clear it upon destruction
|
|
|
|
// if so. This prevents recursive usage of nsAutoRollup from clearing
|
|
|
|
// mLastRollup when it shouldn't.
|
|
|
|
wasClear = !nsBaseWidget::mLastRollup;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoRollup::~nsAutoRollup()
|
|
|
|
{
|
|
|
|
if (nsBaseWidget::mLastRollup && wasClear) {
|
|
|
|
NS_RELEASE(nsBaseWidget::mLastRollup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsBaseWidget constructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1999-10-05 14:53:40 +00:00
|
|
|
|
1999-08-24 01:00:01 +00:00
|
|
|
nsBaseWidget::nsBaseWidget()
|
2002-11-06 09:35:13 +00:00
|
|
|
: mClientData(nsnull)
|
2010-06-25 02:01:06 +00:00
|
|
|
, mViewWrapperPtr(nsnull)
|
2002-11-06 09:35:13 +00:00
|
|
|
, mEventCallback(nsnull)
|
2010-06-25 02:01:06 +00:00
|
|
|
, mViewCallback(nsnull)
|
2002-11-06 09:35:13 +00:00
|
|
|
, mContext(nsnull)
|
|
|
|
, mToolkit(nsnull)
|
|
|
|
, mCursor(eCursor_standard)
|
2003-03-10 01:23:32 +00:00
|
|
|
, mWindowType(eWindowType_child)
|
2002-11-06 09:35:13 +00:00
|
|
|
, mBorderStyle(eBorderStyle_none)
|
|
|
|
, mOnDestroyCalled(PR_FALSE)
|
2010-03-31 03:02:58 +00:00
|
|
|
, mUseAcceleratedRendering(PR_FALSE)
|
2002-11-06 09:35:13 +00:00
|
|
|
, mBounds(0,0,0,0)
|
|
|
|
, mOriginalBounds(nsnull)
|
2009-07-22 00:44:55 +00:00
|
|
|
, mClipRectCount(0)
|
2002-11-06 09:35:13 +00:00
|
|
|
, mZIndex(0)
|
|
|
|
, mSizeMode(nsSizeMode_Normal)
|
2010-07-27 13:38:03 +00:00
|
|
|
, mPopupLevel(ePopupLevelTop)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-10-05 14:53:40 +00:00
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
|
|
|
gNumWidgets++;
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("WIDGETS+ = %d\n", gNumWidgets);
|
1999-10-05 14:53:40 +00:00
|
|
|
#endif
|
|
|
|
|
2002-01-24 01:18:36 +00:00
|
|
|
#ifdef DEBUG
|
1999-12-03 07:23:22 +00:00
|
|
|
debug_RegisterPrefCallbacks();
|
|
|
|
#endif
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsBaseWidget destructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsBaseWidget::~nsBaseWidget()
|
|
|
|
{
|
2010-07-15 21:08:10 +00:00
|
|
|
if (mLayerManager &&
|
|
|
|
mLayerManager->GetBackendType() == LayerManager::LAYERS_BASIC) {
|
|
|
|
static_cast<BasicLayerManager*>(mLayerManager.get())->ClearRetainerWidget();
|
|
|
|
}
|
|
|
|
|
1999-10-05 14:53:40 +00:00
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
|
|
|
gNumWidgets--;
|
2000-10-28 22:17:53 +00:00
|
|
|
printf("WIDGETS- = %d\n", gNumWidgets);
|
1999-10-05 14:53:40 +00:00
|
|
|
#endif
|
|
|
|
|
2004-01-05 23:28:41 +00:00
|
|
|
NS_IF_RELEASE(mToolkit);
|
|
|
|
NS_IF_RELEASE(mContext);
|
2002-11-06 09:35:13 +00:00
|
|
|
if (mOriginalBounds)
|
|
|
|
delete mOriginalBounds;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
1999-10-15 00:49:11 +00:00
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Basic create.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::BaseCreate(nsIWidget *aParent,
|
2009-01-15 03:27:09 +00:00
|
|
|
const nsIntRect &aRect,
|
1999-09-28 01:31:41 +00:00
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell,
|
|
|
|
nsIToolkit *aToolkit,
|
|
|
|
nsWidgetInitData *aInitData)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
if (nsnull == mToolkit) {
|
|
|
|
if (nsnull != aToolkit) {
|
|
|
|
mToolkit = (nsIToolkit*)aToolkit;
|
|
|
|
NS_ADDREF(mToolkit);
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-09-28 01:31:41 +00:00
|
|
|
if (nsnull != aParent) {
|
2007-06-30 03:04:32 +00:00
|
|
|
mToolkit = aParent->GetToolkit();
|
|
|
|
NS_IF_ADDREF(mToolkit);
|
1999-09-28 01:31:41 +00:00
|
|
|
}
|
|
|
|
// it's some top level window with no toolkit passed in.
|
|
|
|
// Create a default toolkit with the current thread
|
1999-10-15 00:49:11 +00:00
|
|
|
#if !defined(USE_TLS_FOR_TOOLKIT)
|
1999-09-28 01:31:41 +00:00
|
|
|
else {
|
|
|
|
static NS_DEFINE_CID(kToolkitCID, NS_TOOLKIT_CID);
|
|
|
|
|
|
|
|
nsresult res;
|
2004-11-01 18:50:36 +00:00
|
|
|
res = CallCreateInstance(kToolkitCID, &mToolkit);
|
2002-01-13 00:28:11 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(res), "Can not create a toolkit in nsBaseWidget::Create");
|
1999-09-28 01:31:41 +00:00
|
|
|
if (mToolkit)
|
|
|
|
mToolkit->Init(PR_GetCurrentThread());
|
|
|
|
}
|
1999-10-15 00:49:11 +00:00
|
|
|
#else /* USE_TLS_FOR_TOOLKIT */
|
|
|
|
else {
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = NS_GetCurrentToolkit(&mToolkit);
|
|
|
|
}
|
|
|
|
#endif /* USE_TLS_FOR_TOOLKIT */
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
1999-09-28 01:31:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// save the event callback function
|
|
|
|
mEventCallback = aHandleEventFunction;
|
|
|
|
|
|
|
|
// keep a reference to the device context
|
|
|
|
if (aContext) {
|
|
|
|
mContext = aContext;
|
|
|
|
NS_ADDREF(mContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
|
|
|
|
|
2004-11-01 18:50:36 +00:00
|
|
|
res = CallCreateInstance(kDeviceContextCID, &mContext);
|
1998-09-23 19:19:23 +00:00
|
|
|
|
2002-01-13 00:28:11 +00:00
|
|
|
if (NS_SUCCEEDED(res))
|
1999-09-28 01:31:41 +00:00
|
|
|
mContext->Init(nsnull);
|
|
|
|
}
|
1998-09-23 19:19:23 +00:00
|
|
|
|
1999-09-28 01:31:41 +00:00
|
|
|
if (nsnull != aInitData) {
|
2009-09-24 09:32:20 +00:00
|
|
|
mWindowType = aInitData->mWindowType;
|
|
|
|
mBorderStyle = aInitData->mBorderStyle;
|
2010-07-27 13:38:03 +00:00
|
|
|
mPopupLevel = aInitData->mPopupLevel;
|
1999-09-28 01:31:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aParent) {
|
|
|
|
aParent->AddChild(this);
|
|
|
|
}
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
1999-06-21 20:37:50 +00:00
|
|
|
NS_IMETHODIMP nsBaseWidget::CaptureMouse(PRBool aCapture)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Accessor functions to get/set the client data
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsBaseWidget::GetClientData(void*& aClientData)
|
|
|
|
{
|
|
|
|
aClientData = mClientData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetClientData(void* aClientData)
|
|
|
|
{
|
|
|
|
mClientData = aClientData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-25 02:01:06 +00:00
|
|
|
// Attach a view to our widget which we'll send events to.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction,
|
|
|
|
nsIDeviceContext *aContext)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((mWindowType == eWindowType_toplevel), "Can't attach to child?");
|
|
|
|
|
|
|
|
mViewCallback = aViewEventFunction;
|
|
|
|
|
|
|
|
if (aContext) {
|
|
|
|
if (mContext) {
|
|
|
|
NS_IF_RELEASE(mContext);
|
|
|
|
}
|
|
|
|
mContext = aContext;
|
|
|
|
NS_ADDREF(mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewWrapper* nsBaseWidget::GetAttachedViewPtr()
|
|
|
|
{
|
|
|
|
return mViewWrapperPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetAttachedViewPtr(ViewWrapper* aViewWrapper)
|
|
|
|
{
|
|
|
|
mViewWrapperPtr = aViewWrapper;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsBaseWidget::ResizeClient(PRInt32 aX,
|
|
|
|
PRInt32 aY,
|
|
|
|
PRInt32 aWidth,
|
|
|
|
PRInt32 aHeight,
|
|
|
|
PRBool aRepaint)
|
|
|
|
{
|
|
|
|
return Resize(aX, aY, aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Close this nsBaseWidget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::Destroy()
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
2004-05-22 20:54:40 +00:00
|
|
|
// Just in case our parent is the only ref to us
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
1998-09-23 19:19:23 +00:00
|
|
|
// disconnect from the parent
|
|
|
|
nsIWidget *parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
1999-04-19 23:24:40 +00:00
|
|
|
|
1998-09-28 22:32:48 +00:00
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-12 03:59:15 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Set this nsBaseWidget's parent
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetParent(nsIWidget* aNewParent)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this nsBaseWidget parent
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIWidget* nsBaseWidget::GetParent(void)
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2008-09-16 08:21:06 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this nsBaseWidget top level widget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2009-08-03 22:25:20 +00:00
|
|
|
nsIWidget* nsBaseWidget::GetTopLevelWidget()
|
2008-09-16 08:21:06 +00:00
|
|
|
{
|
2008-12-15 13:43:48 +00:00
|
|
|
nsIWidget *topLevelWidget = nsnull, *widget = this;
|
2008-09-16 08:21:06 +00:00
|
|
|
while (widget) {
|
|
|
|
topLevelWidget = widget;
|
|
|
|
widget = widget->GetParent();
|
|
|
|
}
|
|
|
|
return topLevelWidget;
|
|
|
|
}
|
|
|
|
|
2008-05-02 11:32:50 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this nsBaseWidget's top (non-sheet) parent (if it's a sheet)
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIWidget* nsBaseWidget::GetSheetWindowParent(void)
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Add a child to the list of children
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::AddChild(nsIWidget* aChild)
|
|
|
|
{
|
2004-05-22 20:54:40 +00:00
|
|
|
NS_PRECONDITION(!aChild->GetNextSibling() && !aChild->GetPrevSibling(),
|
|
|
|
"aChild not properly removed from its old child list");
|
|
|
|
|
|
|
|
if (!mFirstChild) {
|
|
|
|
mFirstChild = mLastChild = aChild;
|
|
|
|
} else {
|
|
|
|
// append to the list
|
|
|
|
NS_ASSERTION(mLastChild, "Bogus state");
|
|
|
|
NS_ASSERTION(!mLastChild->GetNextSibling(), "Bogus state");
|
|
|
|
mLastChild->SetNextSibling(aChild);
|
|
|
|
aChild->SetPrevSibling(mLastChild);
|
|
|
|
mLastChild = aChild;
|
|
|
|
}
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Remove a child from the list of children
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::RemoveChild(nsIWidget* aChild)
|
|
|
|
{
|
2006-03-22 18:00:28 +00:00
|
|
|
NS_ASSERTION(aChild->GetParent() == this, "Not one of our kids!");
|
2004-05-22 20:54:40 +00:00
|
|
|
|
|
|
|
if (mLastChild == aChild) {
|
|
|
|
mLastChild = mLastChild->GetPrevSibling();
|
|
|
|
}
|
|
|
|
if (mFirstChild == aChild) {
|
|
|
|
mFirstChild = mFirstChild->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now remove from the list. Make sure that we pass ownership of the tail
|
|
|
|
// of the list correctly before we have aChild let go of it.
|
|
|
|
nsIWidget* prev = aChild->GetPrevSibling();
|
|
|
|
nsIWidget* next = aChild->GetNextSibling();
|
|
|
|
if (prev) {
|
|
|
|
prev->SetNextSibling(next);
|
|
|
|
}
|
|
|
|
if (next) {
|
|
|
|
next->SetPrevSibling(prev);
|
|
|
|
}
|
|
|
|
|
|
|
|
aChild->SetNextSibling(nsnull);
|
|
|
|
aChild->SetPrevSibling(nsnull);
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
1999-09-23 23:26:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Sets widget's position within its parent's child list.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetZIndex(PRInt32 aZIndex)
|
|
|
|
{
|
2006-03-22 18:00:28 +00:00
|
|
|
// Hold a ref to ourselves just in case, since we're going to remove
|
|
|
|
// from our parent.
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
|
2004-01-05 23:28:41 +00:00
|
|
|
mZIndex = aZIndex;
|
|
|
|
|
|
|
|
// reorder this child in its parent's list.
|
2007-07-08 07:08:04 +00:00
|
|
|
nsBaseWidget* parent = static_cast<nsBaseWidget*>(GetParent());
|
2004-01-05 23:28:41 +00:00
|
|
|
if (parent) {
|
2004-05-22 20:54:40 +00:00
|
|
|
parent->RemoveChild(this);
|
|
|
|
// Scope sib outside the for loop so we can check it afterward
|
|
|
|
nsIWidget* sib = parent->GetFirstChild();
|
|
|
|
for ( ; sib; sib = sib->GetNextSibling()) {
|
2004-01-05 23:28:41 +00:00
|
|
|
PRInt32 childZIndex;
|
2004-05-22 20:54:40 +00:00
|
|
|
if (NS_SUCCEEDED(sib->GetZIndex(&childZIndex))) {
|
2004-01-05 23:28:41 +00:00
|
|
|
if (aZIndex < childZIndex) {
|
2004-05-22 20:54:40 +00:00
|
|
|
// Insert ourselves before sib
|
|
|
|
nsIWidget* prev = sib->GetPrevSibling();
|
|
|
|
mNextSibling = sib;
|
|
|
|
mPrevSibling = prev;
|
|
|
|
sib->SetPrevSibling(this);
|
|
|
|
if (prev) {
|
|
|
|
prev->SetNextSibling(this);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(sib == parent->mFirstChild, "Broken child list");
|
|
|
|
// We've taken ownership of sib, so it's safe to have parent let
|
|
|
|
// go of it
|
|
|
|
parent->mFirstChild = this;
|
|
|
|
}
|
|
|
|
PlaceBehind(eZPlacementBelow, sib, PR_FALSE);
|
2004-01-05 23:28:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// were we added to the list?
|
2004-05-22 20:54:40 +00:00
|
|
|
if (!sib) {
|
|
|
|
parent->AddChild(this);
|
2004-01-05 23:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-09-23 23:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Gets widget's position within its parent's child list.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::GetZIndex(PRInt32* aZIndex)
|
|
|
|
{
|
2004-01-05 23:28:41 +00:00
|
|
|
*aZIndex = mZIndex;
|
|
|
|
return NS_OK;
|
1999-09-23 23:26:25 +00:00
|
|
|
}
|
|
|
|
|
2000-04-01 22:10:22 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Places widget behind the given widget (platforms must override)
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2003-10-07 01:19:51 +00:00
|
|
|
NS_IMETHODIMP nsBaseWidget::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
|
|
|
nsIWidget *aWidget, PRBool aActivate)
|
2000-04-01 22:10:22 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-09 01:55:48 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Maximize, minimize or restore the window. The BaseWidget implementation
|
|
|
|
// merely stores the state.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetSizeMode(PRInt32 aMode) {
|
|
|
|
|
2009-07-08 16:13:13 +00:00
|
|
|
|
|
|
|
if (aMode == nsSizeMode_Normal ||
|
|
|
|
aMode == nsSizeMode_Minimized ||
|
|
|
|
aMode == nsSizeMode_Maximized ||
|
|
|
|
aMode == nsSizeMode_Fullscreen) {
|
2000-03-09 01:55:48 +00:00
|
|
|
|
|
|
|
mSizeMode = (nsSizeMode) aMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get the size mode (minimized, maximized, that sort of thing...)
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::GetSizeMode(PRInt32* aMode) {
|
|
|
|
|
|
|
|
*aMode = mSizeMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get the foreground color
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nscolor nsBaseWidget::GetForegroundColor(void)
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
return mForeground;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Set the foreground color
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetForegroundColor(const nscolor &aColor)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
mForeground = aColor;
|
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get the background color
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nscolor nsBaseWidget::GetBackgroundColor(void)
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
return mBackground;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Set the background color
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetBackgroundColor(const nscolor &aColor)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
mBackground = aColor;
|
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this component cursor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsCursor nsBaseWidget::GetCursor()
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
return mCursor;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetCursor(nsCursor aCursor)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
|
|
|
mCursor = aCursor;
|
1998-09-28 22:32:48 +00:00
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
2004-12-30 21:56:11 +00:00
|
|
|
|
2005-07-01 04:29:42 +00:00
|
|
|
NS_IMETHODIMP nsBaseWidget::SetCursor(imgIContainer* aCursor,
|
|
|
|
PRUint32 aHotspotX, PRUint32 aHotspotY)
|
2004-12-30 21:56:11 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1998-09-23 19:19:23 +00:00
|
|
|
|
2001-06-04 23:03:24 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get the window type for this widget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::GetWindowType(nsWindowType& aWindowType)
|
|
|
|
{
|
|
|
|
aWindowType = mWindowType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-06 02:49:40 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Window transparency methods
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2008-08-13 00:44:14 +00:00
|
|
|
void nsBaseWidget::SetTransparencyMode(nsTransparencyMode aMode) {
|
2003-04-06 02:49:40 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 00:44:14 +00:00
|
|
|
nsTransparencyMode nsBaseWidget::GetTransparencyMode() {
|
|
|
|
return eTransparencyOpaque;
|
2003-04-06 02:49:40 +00:00
|
|
|
}
|
|
|
|
|
2009-07-26 21:19:15 +00:00
|
|
|
PRBool
|
2009-07-22 00:44:55 +00:00
|
|
|
nsBaseWidget::StoreWindowClipRegion(const nsTArray<nsIntRect>& aRects)
|
|
|
|
{
|
2009-07-26 21:19:15 +00:00
|
|
|
if (mClipRects && mClipRectCount == aRects.Length() &&
|
|
|
|
memcmp(mClipRects, aRects.Elements(), sizeof(nsIntRect)*mClipRectCount) == 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-07-22 00:44:55 +00:00
|
|
|
mClipRectCount = aRects.Length();
|
|
|
|
mClipRects = new nsIntRect[mClipRectCount];
|
|
|
|
if (mClipRects) {
|
|
|
|
memcpy(mClipRects, aRects.Elements(), sizeof(nsIntRect)*mClipRectCount);
|
|
|
|
}
|
2009-07-26 21:19:15 +00:00
|
|
|
return PR_TRUE;
|
2009-07-22 00:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBaseWidget::GetWindowClipRegion(nsTArray<nsIntRect>* aRects)
|
|
|
|
{
|
|
|
|
if (mClipRects) {
|
|
|
|
aRects->AppendElements(mClipRects.get(), mClipRectCount);
|
|
|
|
} else {
|
|
|
|
aRects->AppendElement(nsIntRect(0, 0, mBounds.width, mBounds.height));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-14 15:33:40 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Set window shadow style
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetWindowShadowStyle(PRInt32 aMode)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2002-02-20 03:33:52 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Hide window borders/decorations for this widget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::HideWindowChrome(PRBool aShouldHide)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2001-06-04 23:03:24 +00:00
|
|
|
|
2002-11-06 09:35:13 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Put the window into full-screen mode
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::MakeFullScreen(PRBool aFullScreen)
|
|
|
|
{
|
2009-07-01 19:01:11 +00:00
|
|
|
HideWindowChrome(aFullScreen);
|
2002-11-06 09:35:13 +00:00
|
|
|
|
|
|
|
if (aFullScreen) {
|
|
|
|
if (!mOriginalBounds)
|
2009-01-15 03:27:09 +00:00
|
|
|
mOriginalBounds = new nsIntRect();
|
2002-11-06 09:35:13 +00:00
|
|
|
GetScreenBounds(*mOriginalBounds);
|
2003-05-08 18:31:01 +00:00
|
|
|
|
|
|
|
// Move to top-left corner of screen and size to the screen dimensions
|
|
|
|
nsCOMPtr<nsIScreenManager> screenManager;
|
|
|
|
screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
|
|
|
NS_ASSERTION(screenManager, "Unable to grab screenManager.");
|
|
|
|
if (screenManager) {
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
screenManager->ScreenForRect(mOriginalBounds->x, mOriginalBounds->y,
|
|
|
|
mOriginalBounds->width, mOriginalBounds->height,
|
|
|
|
getter_AddRefs(screen));
|
|
|
|
if (screen) {
|
|
|
|
PRInt32 left, top, width, height;
|
|
|
|
if (NS_SUCCEEDED(screen->GetRect(&left, &top, &width, &height))) {
|
|
|
|
Resize(left, top, width, height, PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-06 09:35:13 +00:00
|
|
|
} else if (mOriginalBounds) {
|
|
|
|
Resize(mOriginalBounds->x, mOriginalBounds->y, mOriginalBounds->width,
|
|
|
|
mOriginalBounds->height, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-01 08:03:49 +00:00
|
|
|
nsBaseWidget::AutoLayerManagerSetup::AutoLayerManagerSetup(
|
2010-07-15 21:08:04 +00:00
|
|
|
nsBaseWidget* aWidget, gfxContext* aTarget,
|
|
|
|
BasicLayerManager::BufferMode aDoubleBuffering)
|
2010-03-01 08:03:49 +00:00
|
|
|
: mWidget(aWidget)
|
|
|
|
{
|
|
|
|
BasicLayerManager* manager =
|
|
|
|
static_cast<BasicLayerManager*>(mWidget->GetLayerManager());
|
|
|
|
if (manager) {
|
2010-03-31 03:02:58 +00:00
|
|
|
NS_ASSERTION(manager->GetBackendType() == LayerManager::LAYERS_BASIC,
|
|
|
|
"AutoLayerManagerSetup instantiated for non-basic layer backend!");
|
2010-07-15 21:08:04 +00:00
|
|
|
manager->SetDefaultTarget(aTarget, aDoubleBuffering);
|
2010-03-01 08:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBaseWidget::AutoLayerManagerSetup::~AutoLayerManagerSetup()
|
|
|
|
{
|
|
|
|
BasicLayerManager* manager =
|
|
|
|
static_cast<BasicLayerManager*>(mWidget->GetLayerManager());
|
|
|
|
if (manager) {
|
2010-03-31 03:02:58 +00:00
|
|
|
NS_ASSERTION(manager->GetBackendType() == LayerManager::LAYERS_BASIC,
|
|
|
|
"AutoLayerManagerSetup instantiated for non-basic layer backend!");
|
2010-07-15 21:08:04 +00:00
|
|
|
manager->SetDefaultTarget(nsnull, BasicLayerManager::BUFFER_NONE);
|
2010-03-01 08:03:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerManager* nsBaseWidget::GetLayerManager()
|
|
|
|
{
|
|
|
|
if (!mLayerManager) {
|
2010-05-12 18:56:31 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
PRBool allowAcceleration = PR_TRUE;
|
|
|
|
if (prefs) {
|
|
|
|
prefs->GetBoolPref("mozilla.widget.accelerated-layers",
|
|
|
|
&allowAcceleration);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUseAcceleratedRendering && allowAcceleration) {
|
2010-03-31 03:02:58 +00:00
|
|
|
nsRefPtr<LayerManagerOGL> layerManager =
|
|
|
|
new mozilla::layers::LayerManagerOGL(this);
|
|
|
|
/**
|
|
|
|
* XXX - On several OSes initialization is expected to fail for now.
|
|
|
|
* If we'd get a none-basic layer manager they'd crash. This is ok though
|
|
|
|
* since on those platforms it will fail. Anyone implementing new
|
|
|
|
* platforms on LayerManagerOGL should ensure their widget is able to
|
|
|
|
* deal with it though!
|
|
|
|
*/
|
|
|
|
if (layerManager->Initialize()) {
|
|
|
|
mLayerManager = layerManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!mLayerManager) {
|
2010-07-15 21:08:10 +00:00
|
|
|
mLayerManager = new BasicLayerManager(this);
|
2010-03-31 03:02:58 +00:00
|
|
|
}
|
2010-03-01 08:03:49 +00:00
|
|
|
}
|
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Return the toolkit this widget was created on
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIToolkit* nsBaseWidget::GetToolkit()
|
|
|
|
{
|
|
|
|
return mToolkit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Return the used device context
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIDeviceContext* nsBaseWidget::GetDeviceContext()
|
|
|
|
{
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
2005-11-29 20:12:29 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get the thebes surface
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
gfxASurface *nsBaseWidget::GetThebesSurface()
|
|
|
|
{
|
|
|
|
// in theory we should get our parent's surface,
|
|
|
|
// clone it, and set a device offset before returning
|
|
|
|
return nsnull;
|
|
|
|
}
|
2007-09-02 15:55:28 +00:00
|
|
|
|
2005-11-29 20:12:29 +00:00
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Destroy the window
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::OnDestroy()
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
// release references to device context, toolkit, and app shell
|
|
|
|
NS_IF_RELEASE(mContext);
|
|
|
|
NS_IF_RELEASE(mToolkit);
|
1998-12-01 17:58:27 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 12:56:40 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetWindowClass(const nsAString& xulWinType)
|
2002-08-07 01:59:22 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1998-12-01 17:58:27 +00:00
|
|
|
|
2010-06-25 02:01:07 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Bounds
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
1998-11-04 21:43:47 +00:00
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* If the implementation of nsWindow supports borders this method MUST be overridden
|
|
|
|
*
|
|
|
|
**/
|
2009-01-15 03:27:09 +00:00
|
|
|
NS_METHOD nsBaseWidget::GetClientBounds(nsIntRect &aRect)
|
1998-11-04 21:43:47 +00:00
|
|
|
{
|
|
|
|
return GetBounds(aRect);
|
|
|
|
}
|
|
|
|
|
1998-11-24 14:57:09 +00:00
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* If the implementation of nsWindow supports borders this method MUST be overridden
|
|
|
|
*
|
|
|
|
**/
|
2009-01-15 03:27:09 +00:00
|
|
|
NS_METHOD nsBaseWidget::GetBounds(nsIntRect &aRect)
|
1998-11-24 14:57:09 +00:00
|
|
|
{
|
|
|
|
aRect = mBounds;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-06 01:29:19 +00:00
|
|
|
/**
|
|
|
|
* If the implementation of nsWindow uses a local coordinate system within the window,
|
|
|
|
* this method must be overridden
|
|
|
|
*
|
|
|
|
**/
|
2009-01-15 03:27:09 +00:00
|
|
|
NS_METHOD nsBaseWidget::GetScreenBounds(nsIntRect &aRect)
|
2000-01-06 01:29:19 +00:00
|
|
|
{
|
|
|
|
return GetBounds(aRect);
|
|
|
|
}
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-14 22:00:24 +00:00
|
|
|
|
2010-07-27 13:38:03 +00:00
|
|
|
nsIntPoint nsBaseWidget::GetClientOffset()
|
2010-06-25 02:01:06 +00:00
|
|
|
{
|
2010-07-27 13:38:03 +00:00
|
|
|
return nsIntPoint(0, 0);
|
2010-06-25 02:01:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 03:27:09 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetBounds(const nsIntRect &aRect)
|
1998-11-24 14:57:09 +00:00
|
|
|
{
|
|
|
|
mBounds = aRect;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-25 02:01:07 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::GetNonClientMargins(nsIntMargin &margins)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::SetNonClientMargins(nsIntMargin &margins)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1998-11-04 21:43:47 +00:00
|
|
|
|
1999-08-26 14:41:17 +00:00
|
|
|
NS_METHOD nsBaseWidget::EnableDragDrop(PRBool aEnable)
|
1999-03-09 23:47:47 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 23:46:30 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetModal(PRBool aModal)
|
1999-06-13 20:56:08 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-07-09 12:11:12 +00:00
|
|
|
|
1999-12-10 07:20:51 +00:00
|
|
|
NS_IMETHODIMP
|
2004-02-11 03:46:30 +00:00
|
|
|
nsBaseWidget::GetAttention(PRInt32 aCycleCount) {
|
1999-12-10 07:20:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:53:52 +00:00
|
|
|
PRBool
|
|
|
|
nsBaseWidget::HasPendingInputEvent()
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-14 00:57:30 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 22:26:36 +00:00
|
|
|
nsBaseWidget::SetIcon(const nsAString&)
|
2001-04-14 00:57:30 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-27 16:01:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::BeginSecureKeyboardInput()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(!debug_InSecureKeyboardInputMode, "Attempting to nest call to BeginSecureKeyboardInput!");
|
|
|
|
debug_InSecureKeyboardInputMode = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::EndSecureKeyboardInput()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(debug_InSecureKeyboardInputMode, "Calling EndSecureKeyboardInput when it hasn't been enabled!");
|
|
|
|
debug_InSecureKeyboardInputMode = PR_FALSE;
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-30 04:03:42 +00:00
|
|
|
NS_IMETHODIMP
|
2008-05-02 11:32:50 +00:00
|
|
|
nsBaseWidget::SetWindowTitlebarColor(nscolor aColor, PRBool aActive)
|
2007-10-30 04:03:42 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2008-08-08 16:11:54 +00:00
|
|
|
PRBool
|
|
|
|
nsBaseWidget::ShowsResizeIndicator(nsIntRect* aResizerRect)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-31 03:02:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::SetAcceleratedRendering(PRBool aEnabled)
|
|
|
|
{
|
|
|
|
if (mUseAcceleratedRendering == aEnabled) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mUseAcceleratedRendering = aEnabled;
|
|
|
|
mLayerManager = NULL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsBaseWidget::GetAcceleratedRendering()
|
|
|
|
{
|
|
|
|
return mUseAcceleratedRendering;
|
|
|
|
}
|
|
|
|
|
2009-09-24 10:58:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta,
|
|
|
|
PRBool aIsHorizontal,
|
|
|
|
PRInt32 &aOverriddenDelta)
|
|
|
|
{
|
|
|
|
aOverriddenDelta = aOriginalDelta;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(prefs, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch;
|
|
|
|
nsresult rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(prefBranch, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
PRBool isOverrideEnabled;
|
|
|
|
const char* kPrefNameOverrideEnabled =
|
|
|
|
"mousewheel.system_scroll_override_on_root_content.enabled";
|
|
|
|
rv = prefBranch->GetBoolPref(kPrefNameOverrideEnabled, &isOverrideEnabled);
|
|
|
|
if (NS_FAILED(rv) || !isOverrideEnabled) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 iFactor;
|
|
|
|
nsCAutoString factorPrefName(
|
|
|
|
"mousewheel.system_scroll_override_on_root_content.");
|
|
|
|
if (aIsHorizontal) {
|
|
|
|
factorPrefName.AppendLiteral("horizontal.");
|
|
|
|
} else {
|
|
|
|
factorPrefName.AppendLiteral("vertical.");
|
|
|
|
}
|
|
|
|
factorPrefName.AppendLiteral("factor");
|
|
|
|
rv = prefBranch->GetIntPref(factorPrefName.get(), &iFactor);
|
|
|
|
// The pref value must be larger than 100, otherwise, we don't override the
|
|
|
|
// delta value.
|
|
|
|
if (NS_FAILED(rv) || iFactor <= 100) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
double factor = (double)iFactor / 100;
|
|
|
|
aOverriddenDelta = PRInt32(NS_round((double)aOriginalDelta * factor));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-30 04:03:42 +00:00
|
|
|
|
2004-09-07 18:59:27 +00:00
|
|
|
/**
|
|
|
|
* Modifies aFile to point at an icon file with the given name and suffix. The
|
|
|
|
* suffix may correspond to a file extension with leading '.' if appropriate.
|
|
|
|
* Returns true if the icon file exists and can be read.
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
ResolveIconNameHelper(nsILocalFile *aFile,
|
|
|
|
const nsAString &aIconName,
|
|
|
|
const nsAString &aIconSuffix)
|
|
|
|
{
|
|
|
|
aFile->Append(NS_LITERAL_STRING("icons"));
|
|
|
|
aFile->Append(NS_LITERAL_STRING("default"));
|
|
|
|
aFile->Append(aIconName + aIconSuffix);
|
|
|
|
|
|
|
|
PRBool readable;
|
|
|
|
return NS_SUCCEEDED(aFile->IsReadable(&readable)) && readable;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the given icon name into a local file object. This method is
|
|
|
|
* intended to be called by subclasses of nsBaseWidget. aIconSuffix is a
|
|
|
|
* platform specific icon file suffix (e.g., ".ico" under Win32).
|
|
|
|
*
|
|
|
|
* If no file is found matching the given parameters, then null is returned.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsBaseWidget::ResolveIconName(const nsAString &aIconName,
|
|
|
|
const nsAString &aIconSuffix,
|
|
|
|
nsILocalFile **aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProperties> dirSvc = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
|
|
|
|
if (!dirSvc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// first check auxilary chrome directories
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> dirs;
|
|
|
|
dirSvc->Get(NS_APP_CHROME_DIR_LIST, NS_GET_IID(nsISimpleEnumerator),
|
|
|
|
getter_AddRefs(dirs));
|
2004-09-08 22:06:17 +00:00
|
|
|
if (dirs) {
|
|
|
|
PRBool hasMore;
|
|
|
|
while (NS_SUCCEEDED(dirs->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> element;
|
|
|
|
dirs->GetNext(getter_AddRefs(element));
|
|
|
|
if (!element)
|
|
|
|
continue;
|
|
|
|
nsCOMPtr<nsILocalFile> file = do_QueryInterface(element);
|
|
|
|
if (!file)
|
|
|
|
continue;
|
|
|
|
if (ResolveIconNameHelper(file, aIconName, aIconSuffix)) {
|
|
|
|
NS_ADDREF(*aResult = file);
|
|
|
|
return;
|
|
|
|
}
|
2004-09-07 18:59:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// then check the main app chrome directory
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> file;
|
|
|
|
dirSvc->Get(NS_APP_CHROME_DIR, NS_GET_IID(nsILocalFile),
|
|
|
|
getter_AddRefs(file));
|
2004-09-08 22:06:17 +00:00
|
|
|
if (file && ResolveIconNameHelper(file, aIconName, aIconSuffix))
|
2004-09-07 18:59:27 +00:00
|
|
|
NS_ADDREF(*aResult = file);
|
|
|
|
}
|
|
|
|
|
2007-12-11 10:08:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2010-07-17 08:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::BeginMoveDrag(nsMouseEvent* aEvent)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2007-12-11 10:08:35 +00:00
|
|
|
}
|
|
|
|
|
2009-12-13 21:01:33 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Code to sort rectangles for scrolling.
|
|
|
|
//
|
|
|
|
// The algorithm used here is similar to that described at
|
|
|
|
// http://weblogs.mozillazine.org/roc/archives/2009/08/homework_answer.html
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void
|
|
|
|
ScrollRectIterBase::BaseInit(const nsIntPoint& aDelta, ScrollRect* aHead)
|
|
|
|
{
|
|
|
|
mHead = aHead;
|
|
|
|
// Reflect the coordinate system of the rectangles so that we can assume
|
|
|
|
// that rectangles are moving in the direction of decreasing x and y.
|
|
|
|
Flip(aDelta);
|
|
|
|
|
|
|
|
// Do an initial sort of the rectangles by y and then reverse-x.
|
|
|
|
// nsRegion does not guarantee yx-banded rectangles but still tends to
|
|
|
|
// prefer breaking up rectangles vertically and joining horizontally, so
|
|
|
|
// tends to have fewer rectangles across x than down y, making this
|
|
|
|
// algorithm more efficient for rectangles from nsRegion when y is the
|
|
|
|
// primary sort parameter.
|
|
|
|
ScrollRect* unmovedHead; // chain of unmoved rectangles
|
|
|
|
{
|
|
|
|
nsTArray<ScrollRect*> array;
|
|
|
|
for (ScrollRect* r = mHead; r; r = r->mNext) {
|
|
|
|
array.AppendElement(r);
|
|
|
|
}
|
|
|
|
array.Sort(InitialSortComparator());
|
|
|
|
|
|
|
|
ScrollRect *next = nsnull;
|
|
|
|
for (PRUint32 i = array.Length(); i--; ) {
|
|
|
|
array[i]->mNext = next;
|
|
|
|
next = array[i];
|
|
|
|
}
|
|
|
|
unmovedHead = next;
|
|
|
|
// mHead becomes the start of the moved chain.
|
|
|
|
mHead = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to move each rect from an unmoved chain to the moved chain.
|
|
|
|
mTailLink = &mHead;
|
|
|
|
while (unmovedHead) {
|
|
|
|
// Move() will check for other rectangles that might need to be moved first
|
|
|
|
// and move them also.
|
|
|
|
Move(&unmovedHead);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reflect back to the original coordinate system.
|
|
|
|
Flip(aDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScrollRectIterBase::Move(ScrollRect** aUnmovedLink)
|
|
|
|
{
|
|
|
|
ScrollRect* rect = *aUnmovedLink;
|
|
|
|
// Remove rect from the unmoved chain.
|
|
|
|
*aUnmovedLink = rect->mNext;
|
|
|
|
rect->mNext = nsnull;
|
|
|
|
|
|
|
|
// Check subsequent rectangles that overlap vertically to see whether they
|
|
|
|
// might need to be moved first.
|
|
|
|
//
|
|
|
|
// The overlapping subsequent rectangles that are not moved this time get
|
|
|
|
// checked for each of their preceding unmoved overlapping rectangles,
|
|
|
|
// which adds an O(n^2) cost to this algorithm (where n is the number of
|
|
|
|
// rectangles across x). The reverse-x ordering from InitialSortComparator
|
|
|
|
// avoids this for the case when rectangles are aligned in y.
|
2010-02-02 05:19:44 +00:00
|
|
|
for (ScrollRect** nextLink = aUnmovedLink; *nextLink; ) {
|
|
|
|
ScrollRect* otherRect = *nextLink;
|
2009-12-13 21:01:33 +00:00
|
|
|
NS_ASSERTION(otherRect->y >= rect->y, "Scroll rectangles out of order");
|
|
|
|
if (otherRect->y >= rect->YMost()) // doesn't overlap vertically
|
|
|
|
break;
|
|
|
|
|
|
|
|
// This only moves the other rectangle first if it is entirely to the
|
|
|
|
// left. No promises are made regarding intersecting rectangles. Moving
|
|
|
|
// another intersecting rectangle with merely x < rect->x (but XMost() >
|
|
|
|
// rect->x) can cause more conflicts between rectangles that do not
|
|
|
|
// intersect each other.
|
|
|
|
if (otherRect->XMost() <= rect->x) {
|
|
|
|
Move(nextLink);
|
|
|
|
// *nextLink now points to a subsequent rectangle.
|
|
|
|
} else {
|
|
|
|
// Step over otherRect for now.
|
|
|
|
nextLink = &otherRect->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add rect to the moved chain.
|
|
|
|
*mTailLink = rect;
|
|
|
|
mTailLink = &rect->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlitRectIter::BlitRectIter(const nsIntPoint& aDelta,
|
|
|
|
const nsTArray<nsIntRect>& aRects)
|
|
|
|
: mRects(aRects.Length())
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < aRects.Length(); ++i) {
|
|
|
|
mRects.AppendElement(aRects[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Link rectangles into a chain.
|
|
|
|
ScrollRect *next = nsnull;
|
|
|
|
for (PRUint32 i = mRects.Length(); i--; ) {
|
|
|
|
mRects[i].mNext = next;
|
|
|
|
next = &mRects[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseInit(aDelta, next);
|
|
|
|
}
|
|
|
|
|
2002-01-24 01:18:36 +00:00
|
|
|
#ifdef DEBUG
|
1999-09-09 02:32:54 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
1999-07-09 12:11:12 +00:00
|
|
|
//
|
|
|
|
// Convert a GUI event message code to a string.
|
|
|
|
// Makes it a lot easier to debug events.
|
|
|
|
//
|
|
|
|
// See gtk/nsWidget.cpp and windows/nsWindow.cpp
|
|
|
|
// for a DebugPrintEvent() function that uses
|
|
|
|
// this.
|
|
|
|
//
|
1999-09-09 02:32:54 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ nsAutoString
|
|
|
|
nsBaseWidget::debug_GuiEventToString(nsGUIEvent * aGuiEvent)
|
1999-07-09 12:11:12 +00:00
|
|
|
{
|
1999-09-09 02:32:54 +00:00
|
|
|
NS_ASSERTION(nsnull != aGuiEvent,"cmon, null gui event.");
|
|
|
|
|
2001-12-16 11:58:03 +00:00
|
|
|
nsAutoString eventName(NS_LITERAL_STRING("UNKNOWN"));
|
1999-07-09 12:11:12 +00:00
|
|
|
|
|
|
|
#define _ASSIGN_eventName(_value,_name)\
|
2000-04-17 08:21:30 +00:00
|
|
|
case _value: eventName.AssignWithConversion(_name) ; break
|
1999-07-09 12:11:12 +00:00
|
|
|
|
1999-09-09 02:32:54 +00:00
|
|
|
switch(aGuiEvent->message)
|
1999-07-09 12:11:12 +00:00
|
|
|
{
|
|
|
|
_ASSIGN_eventName(NS_BLUR_CONTENT,"NS_BLUR_CONTENT");
|
|
|
|
_ASSIGN_eventName(NS_CREATE,"NS_CREATE");
|
|
|
|
_ASSIGN_eventName(NS_DESTROY,"NS_DESTROY");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_GESTURE,"NS_DND_GESTURE");
|
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_DROP,"NS_DND_DROP");
|
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_ENTER,"NS_DND_ENTER");
|
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_EXIT,"NS_DND_EXIT");
|
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_OVER,"NS_DND_OVER");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_FOCUS_CONTENT,"NS_FOCUS_CONTENT");
|
1999-08-07 23:18:35 +00:00
|
|
|
_ASSIGN_eventName(NS_FORM_SELECTED,"NS_FORM_SELECTED");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_FORM_CHANGE,"NS_FORM_CHANGE");
|
1999-09-21 23:02:35 +00:00
|
|
|
_ASSIGN_eventName(NS_FORM_INPUT,"NS_FORM_INPUT");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_FORM_RESET,"NS_FORM_RESET");
|
|
|
|
_ASSIGN_eventName(NS_FORM_SUBMIT,"NS_FORM_SUBMIT");
|
|
|
|
_ASSIGN_eventName(NS_IMAGE_ABORT,"NS_IMAGE_ABORT");
|
2006-09-02 10:00:26 +00:00
|
|
|
_ASSIGN_eventName(NS_LOAD_ERROR,"NS_LOAD_ERROR");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_KEY_DOWN,"NS_KEY_DOWN");
|
|
|
|
_ASSIGN_eventName(NS_KEY_PRESS,"NS_KEY_PRESS");
|
|
|
|
_ASSIGN_eventName(NS_KEY_UP,"NS_KEY_UP");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_ENTER,"NS_MOUSE_ENTER");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_EXIT,"NS_MOUSE_EXIT");
|
2006-11-16 21:35:39 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_BUTTON_DOWN,"NS_MOUSE_BUTTON_DOWN");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_BUTTON_UP,"NS_MOUSE_BUTTON_UP");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_CLICK,"NS_MOUSE_CLICK");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_DOUBLECLICK,"NS_MOUSE_DBLCLICK");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_MOVE,"NS_MOUSE_MOVE");
|
|
|
|
_ASSIGN_eventName(NS_MOVE,"NS_MOVE");
|
2006-08-31 19:33:01 +00:00
|
|
|
_ASSIGN_eventName(NS_LOAD,"NS_LOAD");
|
2009-09-01 16:45:05 +00:00
|
|
|
_ASSIGN_eventName(NS_POPSTATE,"NS_POPSTATE");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_PAGE_UNLOAD,"NS_PAGE_UNLOAD");
|
2009-06-26 17:16:50 +00:00
|
|
|
_ASSIGN_eventName(NS_HASHCHANGE,"NS_HASHCHANGE");
|
2010-06-24 01:12:07 +00:00
|
|
|
_ASSIGN_eventName(NS_READYSTATECHANGE,"NS_READYSTATECHANGE");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_PAINT,"NS_PAINT");
|
1999-09-21 23:02:35 +00:00
|
|
|
_ASSIGN_eventName(NS_XUL_BROADCAST, "NS_XUL_BROADCAST");
|
|
|
|
_ASSIGN_eventName(NS_XUL_COMMAND_UPDATE, "NS_XUL_COMMAND_UPDATE");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_LINE_NEXT,"NS_SB_LINE_NEXT");
|
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_LINE_PREV,"NS_SB_LINE_PREV");
|
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_PAGE_NEXT,"NS_SB_PAGE_NEXT");
|
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_PAGE_PREV,"NS_SB_PAGE_PREV");
|
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_POS,"NS_SB_POS");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_SIZE,"NS_SIZE");
|
|
|
|
|
|
|
|
#undef _ASSIGN_eventName
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
1999-09-09 02:32:54 +00:00
|
|
|
sprintf(buf,"UNKNOWN: %d",aGuiEvent->message);
|
1999-07-09 12:11:12 +00:00
|
|
|
|
2000-04-17 08:21:30 +00:00
|
|
|
eventName.AssignWithConversion(buf);
|
1999-07-09 12:11:12 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-07-09 12:11:12 +00:00
|
|
|
return nsAutoString(eventName);
|
|
|
|
}
|
1999-09-09 02:32:54 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
//
|
1999-12-03 07:23:22 +00:00
|
|
|
// Code to deal with paint and event debug prefs.
|
1999-09-09 02:32:54 +00:00
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
1999-12-03 07:23:22 +00:00
|
|
|
struct PrefPair
|
|
|
|
{
|
2004-07-15 19:58:57 +00:00
|
|
|
const char * name;
|
2004-01-05 23:28:41 +00:00
|
|
|
PRBool value;
|
1999-12-03 07:23:22 +00:00
|
|
|
};
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
static PrefPair debug_PrefValues[] =
|
|
|
|
{
|
2004-01-05 23:28:41 +00:00
|
|
|
{ "nglayout.debug.crossing_event_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.event_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.invalidate_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.motion_event_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.paint_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.paint_flashing", PR_FALSE }
|
1999-12-03 07:23:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static PRUint32 debug_NumPrefValues =
|
|
|
|
(sizeof(debug_PrefValues) / sizeof(debug_PrefValues[0]));
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
2006-10-23 15:29:09 +00:00
|
|
|
static PRBool debug_GetBoolPref(nsIPrefBranch * aPrefs,const char * aPrefName)
|
1999-09-09 02:32:54 +00:00
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
|
|
|
NS_ASSERTION(nsnull != aPrefs,"cmon, prefs are null.");
|
|
|
|
|
|
|
|
PRBool value = PR_FALSE;
|
|
|
|
|
|
|
|
if (aPrefs)
|
1999-09-09 02:32:54 +00:00
|
|
|
{
|
2004-01-05 23:28:41 +00:00
|
|
|
aPrefs->GetBoolPref(aPrefName,&value);
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
return value;
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
2002-01-24 01:18:36 +00:00
|
|
|
PRBool
|
|
|
|
nsBaseWidget::debug_GetCachedBoolPref(const char * aPrefName)
|
1999-09-09 02:32:54 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
|
|
|
{
|
2004-06-26 14:32:11 +00:00
|
|
|
if (strcmp(debug_PrefValues[i].name, aPrefName) == 0)
|
2004-01-05 23:28:41 +00:00
|
|
|
{
|
|
|
|
return debug_PrefValues[i].value;
|
|
|
|
}
|
1999-12-03 07:23:22 +00:00
|
|
|
}
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
static void debug_SetCachedBoolPref(const char * aPrefName,PRBool aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
|
|
|
{
|
2004-06-26 14:32:11 +00:00
|
|
|
if (strcmp(debug_PrefValues[i].name, aPrefName) == 0)
|
2004-01-05 23:28:41 +00:00
|
|
|
{
|
|
|
|
debug_PrefValues[i].value = aValue;
|
1999-09-09 02:32:54 +00:00
|
|
|
|
2004-01-05 23:28:41 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-12-03 07:23:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(PR_FALSE, "cmon, this code is not reached dude.");
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
2006-10-23 15:29:09 +00:00
|
|
|
class Debug_PrefObserver : public nsIObserver {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
1999-12-03 07:23:22 +00:00
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(Debug_PrefObserver, nsIObserver)
|
1999-12-03 07:23:22 +00:00
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Debug_PrefObserver::Observe(nsISupports* subject, const char* topic,
|
|
|
|
const PRUnichar* data)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(subject));
|
|
|
|
NS_ASSERTION(branch, "must implement nsIPrefBranch");
|
1999-12-03 07:23:22 +00:00
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
NS_ConvertUTF16toUTF8 prefName(data);
|
1999-12-03 07:23:22 +00:00
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
PRBool value = PR_FALSE;
|
|
|
|
branch->GetBoolPref(prefName.get(), &value);
|
|
|
|
debug_SetCachedBoolPref(prefName.get(), value);
|
|
|
|
return NS_OK;
|
1999-12-03 07:23:22 +00:00
|
|
|
}
|
2006-10-23 15:29:09 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
debug_RegisterPrefCallbacks()
|
|
|
|
{
|
2004-01-05 23:28:41 +00:00
|
|
|
static PRBool once = PR_TRUE;
|
|
|
|
|
|
|
|
if (once)
|
|
|
|
{
|
|
|
|
once = PR_FALSE;
|
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch2> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
2004-01-05 23:28:41 +00:00
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
NS_ASSERTION(prefs, "Prefs services is null.");
|
2004-01-05 23:28:41 +00:00
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
if (prefs)
|
2004-01-05 23:28:41 +00:00
|
|
|
{
|
2006-10-23 15:29:09 +00:00
|
|
|
nsCOMPtr<nsIObserver> obs(new Debug_PrefObserver());
|
2004-01-05 23:28:41 +00:00
|
|
|
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
|
|
|
{
|
|
|
|
// Initialize the pref values
|
|
|
|
debug_PrefValues[i].value =
|
|
|
|
debug_GetBoolPref(prefs,debug_PrefValues[i].name);
|
|
|
|
|
2006-10-23 15:29:09 +00:00
|
|
|
if (obs) {
|
|
|
|
// Register callbacks for when these change
|
|
|
|
prefs->AddObserver(debug_PrefValues[i].name, obs, PR_FALSE);
|
|
|
|
}
|
2004-01-05 23:28:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
static PRInt32
|
|
|
|
_GetPrintCount()
|
|
|
|
{
|
|
|
|
static PRInt32 sCount = 0;
|
|
|
|
|
|
|
|
return ++sCount;
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ PRBool
|
|
|
|
nsBaseWidget::debug_WantPaintFlashing()
|
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
return debug_GetCachedBoolPref("nglayout.debug.paint_flashing");
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpEvent(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
|
|
|
nsGUIEvent * aGuiEvent,
|
|
|
|
const nsCAutoString & aWidgetName,
|
|
|
|
PRInt32 aWindowID)
|
|
|
|
{
|
|
|
|
// NS_PAINT is handled by debug_DumpPaintEvent()
|
|
|
|
if (aGuiEvent->message == NS_PAINT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aGuiEvent->message == NS_MOUSE_MOVE)
|
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.motion_event_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aGuiEvent->message == NS_MOUSE_ENTER ||
|
|
|
|
aGuiEvent->message == NS_MOUSE_EXIT)
|
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.crossing_event_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.event_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
2000-04-17 08:21:30 +00:00
|
|
|
|
2001-06-30 11:02:25 +00:00
|
|
|
nsCAutoString tempString; tempString.AssignWithConversion(debug_GuiEventToString(aGuiEvent).get());
|
1999-09-09 02:32:54 +00:00
|
|
|
|
|
|
|
fprintf(aFileOut,
|
2005-08-23 03:57:07 +00:00
|
|
|
"%4d %-26s widget=%-8p name=%-12s id=%-8p refpt=%d,%d\n",
|
1999-09-09 02:32:54 +00:00
|
|
|
_GetPrintCount(),
|
2001-10-26 04:24:06 +00:00
|
|
|
tempString.get(),
|
1999-09-09 02:32:54 +00:00
|
|
|
(void *) aWidget,
|
2001-10-26 04:24:06 +00:00
|
|
|
aWidgetName.get(),
|
1999-09-09 02:32:54 +00:00
|
|
|
(void *) (aWindowID ? aWindowID : 0x0),
|
2005-08-23 03:57:07 +00:00
|
|
|
aGuiEvent->refPoint.x,
|
|
|
|
aGuiEvent->refPoint.y);
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpPaintEvent(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
|
|
|
nsPaintEvent * aPaintEvent,
|
|
|
|
const nsCAutoString & aWidgetName,
|
|
|
|
PRInt32 aWindowID)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aFileOut,"cmon, null output FILE");
|
|
|
|
NS_ASSERTION(nsnull != aWidget,"cmon, the widget is null");
|
|
|
|
NS_ASSERTION(nsnull != aPaintEvent,"cmon, the paint event is null");
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.paint_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(aFileOut,
|
|
|
|
"%4d PAINT widget=%p name=%-12s id=%-8p rect=",
|
|
|
|
_GetPrintCount(),
|
|
|
|
(void *) aWidget,
|
2001-10-26 04:24:06 +00:00
|
|
|
aWidgetName.get(),
|
1999-09-09 02:32:54 +00:00
|
|
|
(void *) aWindowID);
|
|
|
|
|
|
|
|
fprintf(aFileOut,"\n");
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpInvalidate(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
2009-01-15 03:27:09 +00:00
|
|
|
const nsIntRect * aRect,
|
1999-09-09 02:32:54 +00:00
|
|
|
PRBool aIsSynchronous,
|
|
|
|
const nsCAutoString & aWidgetName,
|
|
|
|
PRInt32 aWindowID)
|
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.invalidate_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
NS_ASSERTION(nsnull != aFileOut,"cmon, null output FILE");
|
|
|
|
NS_ASSERTION(nsnull != aWidget,"cmon, the widget is null");
|
|
|
|
|
|
|
|
fprintf(aFileOut,
|
|
|
|
"%4d Invalidate widget=%p name=%-12s id=%-8p",
|
|
|
|
_GetPrintCount(),
|
|
|
|
(void *) aWidget,
|
2001-10-26 04:24:06 +00:00
|
|
|
aWidgetName.get(),
|
1999-09-09 02:32:54 +00:00
|
|
|
(void *) aWindowID);
|
|
|
|
|
|
|
|
if (aRect)
|
|
|
|
{
|
|
|
|
fprintf(aFileOut,
|
|
|
|
" rect=%3d,%-3d %3d,%-3d",
|
|
|
|
aRect->x,
|
|
|
|
aRect->y,
|
|
|
|
aRect->width,
|
|
|
|
aRect->height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(aFileOut,
|
|
|
|
" rect=%-15s",
|
|
|
|
"none");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(aFileOut,
|
|
|
|
" sync=%s",
|
|
|
|
(const char *) (aIsSynchronous ? "yes" : "no "));
|
|
|
|
|
|
|
|
fprintf(aFileOut,"\n");
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2002-01-24 01:18:36 +00:00
|
|
|
#endif // DEBUG
|
1999-09-09 02:32:54 +00:00
|
|
|
|