2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2015-01-27 22:27:30 -08:00
|
|
|
#include "mozilla/TextEventDispatcher.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2012-01-19 06:45:37 -08:00
|
|
|
#include "mozilla/layers/CompositorChild.h"
|
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2013-06-23 22:28:22 -07:00
|
|
|
#include "mozilla/layers/ImageBridgeChild.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBaseWidget.h"
|
2011-04-16 18:22:44 -07:00
|
|
|
#include "nsDeviceContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsIScreenManager.h"
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
2007-12-03 08:33:42 -08:00
|
|
|
#include "nsIContent.h"
|
2013-10-24 00:18:07 -07:00
|
|
|
#include "nsIDocument.h"
|
2014-04-01 17:21:23 -07:00
|
|
|
#include "nsIPresShell.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIServiceManager.h"
|
2011-05-23 07:54:03 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2010-03-01 00:03:49 -08:00
|
|
|
#include "BasicLayers.h"
|
2013-04-30 22:03:25 -07:00
|
|
|
#include "ClientLayerManager.h"
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
#include "mozilla/layers/Compositor.h"
|
2010-08-27 19:44:37 -07:00
|
|
|
#include "nsIXULRuntime.h"
|
2012-08-15 11:52:37 -07:00
|
|
|
#include "nsIXULWindow.h"
|
2012-08-15 11:52:41 -07:00
|
|
|
#include "nsIBaseWindow.h"
|
2012-10-26 06:15:22 -07:00
|
|
|
#include "nsXULPopupManager.h"
|
2012-08-15 11:52:42 -07:00
|
|
|
#include "nsIWidgetListener.h"
|
2011-01-18 12:11:19 -08:00
|
|
|
#include "nsIGfxInfo.h"
|
2011-01-20 20:01:25 -08:00
|
|
|
#include "npapi.h"
|
2012-01-19 06:45:37 -08:00
|
|
|
#include "base/thread.h"
|
2013-02-26 01:01:10 -08:00
|
|
|
#include "prdtoa.h"
|
2012-05-22 08:34:34 -07:00
|
|
|
#include "prenv.h"
|
2012-06-18 18:28:00 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-15 12:00:16 -07:00
|
|
|
#include "mozilla/unused.h"
|
2013-01-31 15:11:49 -08:00
|
|
|
#include "nsContentUtils.h"
|
2014-02-26 18:53:27 -08:00
|
|
|
#include "gfxPrefs.h"
|
2013-07-08 21:21:05 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-09-25 04:21:18 -07:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-11-26 14:15:17 -08:00
|
|
|
#include "GLConsts.h"
|
2014-03-15 12:00:16 -07:00
|
|
|
#include "mozilla/unused.h"
|
2014-12-18 08:30:05 -08:00
|
|
|
#include "mozilla/VsyncDispatcher.h"
|
2014-12-15 01:47:15 -08:00
|
|
|
#include "mozilla/layers/APZCTreeManager.h"
|
2014-12-15 01:49:48 -08:00
|
|
|
#include "mozilla/layers/ChromeProcessController.h"
|
2014-12-18 15:25:03 -08:00
|
|
|
#include "mozilla/layers/InputAPZContext.h"
|
|
|
|
#include "mozilla/dom/TabParent.h"
|
2009-09-24 03:58:04 -07:00
|
|
|
|
2012-08-15 11:52:37 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2009-09-24 03:58:04 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
|
|
|
|
static void debug_RegisterPrefCallbacks();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t gNumWidgets;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2013-12-19 08:42:19 -08:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "nsCocoaFeatures.h"
|
|
|
|
#endif
|
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
nsIRollupListener* nsBaseWidget::gRollupListener = nullptr;
|
|
|
|
|
2010-03-01 00:03:49 -08:00
|
|
|
using namespace mozilla::layers;
|
2013-09-27 18:42:08 -07:00
|
|
|
using namespace mozilla::ipc;
|
2011-05-23 07:54:03 -07:00
|
|
|
using namespace mozilla;
|
2012-01-19 06:45:37 -08:00
|
|
|
using base::Thread;
|
2010-03-01 00:03:49 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIContent* nsBaseWidget::mLastRollup = nullptr;
|
2012-05-15 06:01:48 -07:00
|
|
|
// Global user preference for disabling native theme. Used
|
|
|
|
// in NativeWindowTheme.
|
|
|
|
bool gDisableNativeTheme = false;
|
2007-12-03 08:33:42 -08:00
|
|
|
|
2013-12-14 12:40:56 -08:00
|
|
|
// Async pump timer during injected long touch taps
|
|
|
|
#define TOUCH_INJECT_PUMP_TIMER_MSEC 50
|
|
|
|
#define TOUCH_INJECT_LONG_TAP_DEFAULT_MSEC 1500
|
|
|
|
int32_t nsIWidget::sPointerIdCounter = 0;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsBaseWidget
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsBaseWidget, nsIWidget)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2007-12-03 08:33:42 -08: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsBaseWidget constructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsBaseWidget::nsBaseWidget()
|
2012-08-15 11:52:42 -07:00
|
|
|
: mWidgetListener(nullptr)
|
2012-08-15 11:53:14 -07:00
|
|
|
, mAttachedWidgetListener(nullptr)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mContext(nullptr)
|
2014-12-19 12:52:42 -08:00
|
|
|
, mCompositorVsyncDispatcher(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mCursor(eCursor_standard)
|
2014-05-27 18:12:29 -07:00
|
|
|
, mUpdateCursor(true)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mBorderStyle(eBorderStyle_none)
|
2012-11-15 10:55:15 -08:00
|
|
|
, mUseLayersAcceleration(false)
|
2012-02-27 13:33:19 -08:00
|
|
|
, mForceLayersAcceleration(false)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mTemporarilyUseBasicLayerManager(false)
|
2012-08-15 11:53:09 -07:00
|
|
|
, mUseAttachedEvents(false)
|
2012-09-29 04:36:09 -07:00
|
|
|
, mContextInitialized(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mBounds(0,0,0,0)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mOriginalBounds(nullptr)
|
2009-07-21 17:44:55 -07:00
|
|
|
, mClipRectCount(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mSizeMode(nsSizeMode_Normal)
|
2010-07-27 06:38:03 -07:00
|
|
|
, mPopupLevel(ePopupLevelTop)
|
2012-05-31 10:52:09 -07:00
|
|
|
, mPopupType(ePopupTypeAny)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
|
|
|
gNumWidgets++;
|
|
|
|
printf("WIDGETS+ = %d\n", gNumWidgets);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-05-22 08:34:34 -07:00
|
|
|
debug_RegisterPrefCallbacks();
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2013-06-16 19:50:32 -07:00
|
|
|
|
|
|
|
mShutdownObserver = new WidgetShutdownObserver(this);
|
|
|
|
nsContentUtils::RegisterShutdownObserver(mShutdownObserver);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(WidgetShutdownObserver, nsIObserver)
|
2013-06-16 19:50:32 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
WidgetShutdownObserver::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *aData)
|
2013-06-16 19:50:32 -07:00
|
|
|
{
|
2013-06-18 19:21:01 -07:00
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0 &&
|
|
|
|
mWidget) {
|
2013-06-16 19:50:32 -07:00
|
|
|
mWidget->Shutdown();
|
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBaseWidget::Shutdown()
|
|
|
|
{
|
|
|
|
DestroyCompositor();
|
|
|
|
mShutdownObserver = nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-23 07:17:44 -07:00
|
|
|
static void DeferredDestroyCompositor(CompositorParent* aCompositorParent,
|
2012-07-13 08:25:29 -07:00
|
|
|
CompositorChild* aCompositorChild)
|
2012-03-30 12:43:11 -07:00
|
|
|
{
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
// Bug 848949 needs to be fixed before
|
|
|
|
// we can close the channel properly
|
|
|
|
//aCompositorChild->Close();
|
2012-03-30 12:43:11 -07:00
|
|
|
aCompositorParent->Release();
|
|
|
|
aCompositorChild->Release();
|
|
|
|
}
|
|
|
|
|
2013-01-01 14:38:48 -08:00
|
|
|
void nsBaseWidget::DestroyCompositor()
|
2012-05-23 07:17:44 -07:00
|
|
|
{
|
|
|
|
if (mCompositorChild) {
|
|
|
|
mCompositorChild->SendWillStop();
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
mCompositorChild->Destroy();
|
2012-05-23 07:17:44 -07:00
|
|
|
|
|
|
|
// The call just made to SendWillStop can result in IPC from the
|
|
|
|
// CompositorParent to the CompositorChild (e.g. caused by the destruction
|
|
|
|
// of shared memory). We need to ensure this gets processed by the
|
|
|
|
// CompositorChild before it gets destroyed. It suffices to ensure that
|
|
|
|
// events already in the MessageLoop get processed before the
|
|
|
|
// CompositorChild is destroyed, so we add a task to the MessageLoop to
|
|
|
|
// handle compositor desctruction.
|
|
|
|
MessageLoop::current()->PostTask(FROM_HERE,
|
|
|
|
NewRunnableFunction(DeferredDestroyCompositor, mCompositorParent,
|
2012-07-13 08:25:29 -07:00
|
|
|
mCompositorChild));
|
2012-05-23 07:17:44 -07:00
|
|
|
// The DestroyCompositor task we just added to the MessageLoop will handle
|
|
|
|
// releasing mCompositorParent and mCompositorChild.
|
2014-03-15 12:00:16 -07:00
|
|
|
unused << mCompositorParent.forget();
|
|
|
|
unused << mCompositorChild.forget();
|
2012-05-23 07:17:44 -07:00
|
|
|
}
|
|
|
|
}
|
2012-03-30 12:43:11 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsBaseWidget destructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsBaseWidget::~nsBaseWidget()
|
|
|
|
{
|
2010-07-15 14:08:10 -07:00
|
|
|
if (mLayerManager &&
|
2014-01-23 10:26:41 -08:00
|
|
|
mLayerManager->GetBackendType() == LayersBackend::LAYERS_BASIC) {
|
2010-07-15 14:08:10 -07:00
|
|
|
static_cast<BasicLayerManager*>(mLayerManager.get())->ClearRetainerWidget();
|
|
|
|
}
|
|
|
|
|
2010-12-06 18:05:25 -08:00
|
|
|
if (mLayerManager) {
|
|
|
|
mLayerManager->Destroy();
|
2012-07-30 07:20:58 -07:00
|
|
|
mLayerManager = nullptr;
|
2012-01-19 06:45:37 -08:00
|
|
|
}
|
|
|
|
|
2013-06-16 19:50:32 -07:00
|
|
|
if (mShutdownObserver) {
|
2013-06-18 19:21:01 -07:00
|
|
|
// If the shutdown observer is currently processing observers,
|
|
|
|
// then UnregisterShutdownObserver won't stop our Observer
|
|
|
|
// function from being called. Make sure we don't try
|
|
|
|
// to reference the dead widget.
|
|
|
|
mShutdownObserver->mWidget = nullptr;
|
2013-06-16 19:50:32 -07:00
|
|
|
nsContentUtils::UnregisterShutdownObserver(mShutdownObserver);
|
|
|
|
}
|
|
|
|
|
2012-05-23 07:17:44 -07:00
|
|
|
DestroyCompositor();
|
2010-12-06 18:05:25 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
|
|
|
gNumWidgets--;
|
|
|
|
printf("WIDGETS- = %d\n", gNumWidgets);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IF_RELEASE(mContext);
|
2011-05-17 07:01:36 -07:00
|
|
|
delete mOriginalBounds;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-12-19 12:52:42 -08:00
|
|
|
// Can have base widgets that are things like tooltips which don't have CompositorVsyncDispatchers
|
|
|
|
if (mCompositorVsyncDispatcher) {
|
|
|
|
mCompositorVsyncDispatcher->Shutdown();
|
2014-12-18 08:30:05 -08:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Basic create.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::BaseCreate(nsIWidget *aParent,
|
2009-01-14 19:27:09 -08:00
|
|
|
const nsIntRect &aRect,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWidgetInitData *aInitData)
|
|
|
|
{
|
2012-05-15 06:01:48 -07:00
|
|
|
static bool gDisableNativeThemeCached = false;
|
|
|
|
if (!gDisableNativeThemeCached) {
|
2012-07-17 16:59:45 -07:00
|
|
|
Preferences::AddBoolVarCache(&gDisableNativeTheme,
|
|
|
|
"mozilla.widget.disable-native-theme",
|
|
|
|
gDisableNativeTheme);
|
2012-05-15 06:01:48 -07:00
|
|
|
gDisableNativeThemeCached = true;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// keep a reference to the device context
|
|
|
|
if (aContext) {
|
|
|
|
mContext = aContext;
|
|
|
|
NS_ADDREF(mContext);
|
|
|
|
}
|
|
|
|
else {
|
2011-04-16 18:22:42 -07:00
|
|
|
mContext = new nsDeviceContext();
|
|
|
|
NS_ADDREF(mContext);
|
2012-07-30 07:20:58 -07:00
|
|
|
mContext->Init(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != aInitData) {
|
2009-09-24 02:32:20 -07:00
|
|
|
mWindowType = aInitData->mWindowType;
|
|
|
|
mBorderStyle = aInitData->mBorderStyle;
|
2010-07-27 06:38:03 -07:00
|
|
|
mPopupLevel = aInitData->mPopupLevel;
|
2012-05-31 10:52:09 -07:00
|
|
|
mPopupType = aInitData->mPopupHint;
|
2014-02-20 17:26:41 -08:00
|
|
|
mRequireOffMainThreadCompositing = aInitData->mRequireOffMainThreadCompositing;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aParent) {
|
|
|
|
aParent->AddChild(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsBaseWidget::CaptureMouse(bool aCapture)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Accessor functions to get/set the client data
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIWidgetListener* nsBaseWidget::GetWidgetListener()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
return mWidgetListener;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
void nsBaseWidget::SetWidgetListener(nsIWidgetListener* aWidgetListener)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
mWidgetListener = aWidgetListener;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
already_AddRefed<nsIWidget>
|
|
|
|
nsBaseWidget::CreateChild(const nsIntRect &aRect,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsWidgetInitData *aInitData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aForceUseIWidgetParent)
|
2010-08-20 12:29:02 -07:00
|
|
|
{
|
|
|
|
nsIWidget* parent = this;
|
2012-07-30 07:20:58 -07:00
|
|
|
nsNativeWidget nativeParent = nullptr;
|
2010-08-20 12:29:02 -07:00
|
|
|
|
|
|
|
if (!aForceUseIWidgetParent) {
|
|
|
|
// Use only either parent or nativeParent, not both, to match
|
|
|
|
// existing code. Eventually Create() should be divested of its
|
|
|
|
// nativeWidget parameter.
|
2012-07-30 07:20:58 -07:00
|
|
|
nativeParent = parent ? parent->GetNativeData(NS_NATIVE_WIDGET) : nullptr;
|
|
|
|
parent = nativeParent ? nullptr : parent;
|
2010-08-20 12:29:02 -07:00
|
|
|
NS_ABORT_IF_FALSE(!parent || !nativeParent, "messed up logic");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
if (aInitData && aInitData->mWindowType == eWindowType_popup) {
|
|
|
|
widget = AllocateChildPopupWidget();
|
|
|
|
} else {
|
|
|
|
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
|
|
|
|
widget = do_CreateInstance(kCChildCID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widget &&
|
|
|
|
NS_SUCCEEDED(widget->Create(parent, nativeParent, aRect,
|
2011-10-25 08:05:32 -07:00
|
|
|
aContext, aInitData))) {
|
2010-08-20 12:29:02 -07:00
|
|
|
return widget.forget();
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-08-20 12:29:02 -07:00
|
|
|
}
|
|
|
|
|
2013-01-01 14:38:48 -08:00
|
|
|
// Attach a view to our widget which we'll send events to.
|
2010-06-24 19:01:06 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-15 11:53:09 -07:00
|
|
|
nsBaseWidget::AttachViewToTopLevel(bool aUseAttachedEvents,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext)
|
2010-06-24 19:01:06 -07:00
|
|
|
{
|
2010-09-08 08:52:58 -07:00
|
|
|
NS_ASSERTION((mWindowType == eWindowType_toplevel ||
|
|
|
|
mWindowType == eWindowType_dialog ||
|
2011-02-09 12:13:18 -08:00
|
|
|
mWindowType == eWindowType_invisible ||
|
|
|
|
mWindowType == eWindowType_child),
|
|
|
|
"Can't attach to window of that type");
|
2010-06-24 19:01:06 -07:00
|
|
|
|
2012-08-15 11:53:09 -07:00
|
|
|
mUseAttachedEvents = aUseAttachedEvents;
|
2010-06-24 19:01:06 -07:00
|
|
|
|
|
|
|
if (aContext) {
|
|
|
|
if (mContext) {
|
|
|
|
NS_IF_RELEASE(mContext);
|
|
|
|
}
|
|
|
|
mContext = aContext;
|
|
|
|
NS_ADDREF(mContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:53:14 -07:00
|
|
|
nsIWidgetListener* nsBaseWidget::GetAttachedWidgetListener()
|
2010-06-24 19:01:06 -07:00
|
|
|
{
|
2012-08-15 11:53:14 -07:00
|
|
|
return mAttachedWidgetListener;
|
2010-06-24 19:01:06 -07:00
|
|
|
}
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2012-08-15 11:53:14 -07:00
|
|
|
void nsBaseWidget::SetAttachedWidgetListener(nsIWidgetListener* aListener)
|
2010-06-24 19:01:06 -07:00
|
|
|
{
|
2012-08-15 11:53:14 -07:00
|
|
|
mAttachedWidgetListener = aListener;
|
2010-06-24 19:01:06 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Close this nsBaseWidget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_METHOD nsBaseWidget::Destroy()
|
|
|
|
{
|
|
|
|
// Just in case our parent is the only ref to us
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
// disconnect from the parent
|
|
|
|
nsIWidget *parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Set this nsBaseWidget's parent
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetParent(nsIWidget* aNewParent)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this nsBaseWidget parent
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIWidget* nsBaseWidget::GetParent(void)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-16 01:21:06 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this nsBaseWidget top level widget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2009-08-03 15:25:20 -07:00
|
|
|
nsIWidget* nsBaseWidget::GetTopLevelWidget()
|
2008-09-16 01:21:06 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIWidget *topLevelWidget = nullptr, *widget = this;
|
2008-09-16 01:21:06 -07:00
|
|
|
while (widget) {
|
|
|
|
topLevelWidget = widget;
|
|
|
|
widget = widget->GetParent();
|
|
|
|
}
|
|
|
|
return topLevelWidget;
|
|
|
|
}
|
|
|
|
|
2008-05-02 04:32:50 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this nsBaseWidget's top (non-sheet) parent (if it's a sheet)
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIWidget* nsBaseWidget::GetSheetWindowParent(void)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-05-02 04:32:50 -07:00
|
|
|
}
|
|
|
|
|
2010-08-13 02:57:48 -07:00
|
|
|
float nsBaseWidget::GetDPI()
|
|
|
|
{
|
|
|
|
return 96.0f;
|
|
|
|
}
|
|
|
|
|
2013-09-17 17:45:19 -07:00
|
|
|
CSSToLayoutDeviceScale nsIWidget::GetDefaultScale()
|
2013-04-09 01:39:47 -07:00
|
|
|
{
|
|
|
|
double devPixelsPerCSSPixel = DefaultScaleOverride();
|
|
|
|
|
|
|
|
if (devPixelsPerCSSPixel <= 0.0) {
|
|
|
|
devPixelsPerCSSPixel = GetDefaultScaleInternal();
|
|
|
|
}
|
|
|
|
|
2013-09-17 17:45:19 -07:00
|
|
|
return CSSToLayoutDeviceScale(devPixelsPerCSSPixel);
|
2013-04-09 01:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
double nsIWidget::DefaultScaleOverride()
|
2010-08-13 02:57:48 -07:00
|
|
|
{
|
2012-10-30 17:31:35 -07:00
|
|
|
// The number of device pixels per CSS pixel. A value <= 0 means choose
|
|
|
|
// automatically based on the DPI. A positive value is used as-is. This effectively
|
|
|
|
// controls the size of a CSS "px".
|
2013-02-26 01:01:10 -08:00
|
|
|
double devPixelsPerCSSPixel = -1.0;
|
2012-10-30 17:31:35 -07:00
|
|
|
|
|
|
|
nsAdoptingCString prefString = Preferences::GetCString("layout.css.devPixelsPerPx");
|
|
|
|
if (!prefString.IsEmpty()) {
|
2013-02-26 01:01:10 -08:00
|
|
|
devPixelsPerCSSPixel = PR_strtod(prefString, nullptr);
|
2012-10-30 17:31:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return devPixelsPerCSSPixel;
|
2010-08-13 02:57:48 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Add a child to the list of children
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::AddChild(nsIWidget* aChild)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!aChild->GetNextSibling() && !aChild->GetPrevSibling(),
|
|
|
|
"aChild not properly removed from its old child list");
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Remove a child from the list of children
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::RemoveChild(nsIWidget* aChild)
|
|
|
|
{
|
2013-07-09 20:52:19 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// nsCocoaWindow doesn't implement GetParent, so in that case parent will be
|
|
|
|
// null and we'll just have to do without this assertion.
|
|
|
|
nsIWidget* parent = aChild->GetParent();
|
|
|
|
NS_ASSERTION(!parent || parent == this, "Not one of our kids!");
|
|
|
|
#else
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(aChild->GetParent() == this, "Not one of our kids!");
|
2013-07-09 20:52:19 -07:00
|
|
|
#endif
|
|
|
|
#endif
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07: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);
|
|
|
|
}
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
aChild->SetNextSibling(nullptr);
|
|
|
|
aChild->SetPrevSibling(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Sets widget's position within its parent's child list.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2014-03-19 09:48:08 -07:00
|
|
|
void nsBaseWidget::SetZIndex(int32_t aZIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Hold a ref to ourselves just in case, since we're going to remove
|
|
|
|
// from our parent.
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mZIndex = aZIndex;
|
|
|
|
|
|
|
|
// reorder this child in its parent's list.
|
2007-07-08 00:08:04 -07:00
|
|
|
nsBaseWidget* parent = static_cast<nsBaseWidget*>(GetParent());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
// Scope sib outside the for loop so we can check it afterward
|
|
|
|
nsIWidget* sib = parent->GetFirstChild();
|
|
|
|
for ( ; sib; sib = sib->GetNextSibling()) {
|
2014-03-19 09:48:08 -07:00
|
|
|
int32_t childZIndex = GetZIndex();
|
|
|
|
if (aZIndex < childZIndex) {
|
|
|
|
// 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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-19 09:48:08 -07:00
|
|
|
PlaceBehind(eZPlacementBelow, sib, false);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// were we added to the list?
|
|
|
|
if (!sib) {
|
|
|
|
parent->AddChild(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Places widget behind the given widget (platforms must override)
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIWidget *aWidget, bool aActivate)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Maximize, minimize or restore the window. The BaseWidget implementation
|
|
|
|
// merely stores the state.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsBaseWidget::SetSizeMode(int32_t aMode)
|
2010-08-26 21:44:01 -07:00
|
|
|
{
|
2009-07-08 09:13:13 -07:00
|
|
|
if (aMode == nsSizeMode_Normal ||
|
|
|
|
aMode == nsSizeMode_Minimized ||
|
|
|
|
aMode == nsSizeMode_Maximized ||
|
|
|
|
aMode == nsSizeMode_Fullscreen) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mSizeMode = (nsSizeMode) aMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this component cursor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsCursor nsBaseWidget::GetCursor()
|
|
|
|
{
|
|
|
|
return mCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsBaseWidget::SetCursor(nsCursor aCursor)
|
|
|
|
{
|
2013-01-01 14:38:48 -08:00
|
|
|
mCursor = aCursor;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetCursor(imgIContainer* aCursor,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aHotspotX, uint32_t aHotspotY)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Window transparency methods
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
void nsBaseWidget::SetTransparencyMode(nsTransparencyMode aMode) {
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-08-12 17:44:14 -07:00
|
|
|
nsTransparencyMode nsBaseWidget::GetTransparencyMode() {
|
|
|
|
return eTransparencyOpaque;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-07-21 17:44:55 -07:00
|
|
|
nsBaseWidget::StoreWindowClipRegion(const nsTArray<nsIntRect>& aRects)
|
|
|
|
{
|
2009-07-26 14:19:15 -07:00
|
|
|
if (mClipRects && mClipRectCount == aRects.Length() &&
|
|
|
|
memcmp(mClipRects, aRects.Elements(), sizeof(nsIntRect)*mClipRectCount) == 0)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-07-26 14:19:15 -07:00
|
|
|
|
2009-07-21 17:44:55 -07:00
|
|
|
mClipRectCount = aRects.Length();
|
|
|
|
mClipRects = new nsIntRect[mClipRectCount];
|
|
|
|
if (mClipRects) {
|
|
|
|
memcpy(mClipRects, aRects.Elements(), sizeof(nsIntRect)*mClipRectCount);
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-07-21 17:44:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBaseWidget::GetWindowClipRegion(nsTArray<nsIntRect>* aRects)
|
|
|
|
{
|
|
|
|
if (mClipRects) {
|
|
|
|
aRects->AppendElements(mClipRects.get(), mClipRectCount);
|
|
|
|
} else {
|
|
|
|
aRects->AppendElement(nsIntRect(0, 0, mBounds.width, mBounds.height));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 12:59:19 -08:00
|
|
|
const nsIntRegion
|
|
|
|
nsBaseWidget::RegionFromArray(const nsTArray<nsIntRect>& aRects)
|
|
|
|
{
|
|
|
|
nsIntRegion region;
|
|
|
|
for (uint32_t i = 0; i < aRects.Length(); ++i) {
|
|
|
|
region.Or(region, aRects[i]);
|
|
|
|
}
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBaseWidget::ArrayFromRegion(const nsIntRegion& aRegion, nsTArray<nsIntRect>& aRects)
|
|
|
|
{
|
|
|
|
const nsIntRect* r;
|
|
|
|
for (nsIntRegionRectIterator iter(aRegion); (r = iter.Next());) {
|
|
|
|
aRects.AppendElement(*r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBaseWidget::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
|
|
|
|
bool aIntersectWithExisting)
|
|
|
|
{
|
|
|
|
if (!aIntersectWithExisting) {
|
|
|
|
nsBaseWidget::StoreWindowClipRegion(aRects);
|
|
|
|
} else {
|
|
|
|
// In this case still early return if nothing changed.
|
|
|
|
if (mClipRects && mClipRectCount == aRects.Length() &&
|
|
|
|
memcmp(mClipRects,
|
|
|
|
aRects.Elements(),
|
|
|
|
sizeof(nsIntRect)*mClipRectCount) == 0) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get current rects
|
|
|
|
nsTArray<nsIntRect> currentRects;
|
|
|
|
GetWindowClipRegion(¤tRects);
|
|
|
|
// create region from them
|
|
|
|
nsIntRegion currentRegion = RegionFromArray(currentRects);
|
|
|
|
// create region from new rects
|
|
|
|
nsIntRegion newRegion = RegionFromArray(aRects);
|
|
|
|
// intersect regions
|
|
|
|
nsIntRegion intersection;
|
|
|
|
intersection.And(currentRegion, newRegion);
|
|
|
|
// create int rect array from intersection
|
|
|
|
nsTArray<nsIntRect> rects;
|
|
|
|
ArrayFromRegion(intersection, rects);
|
|
|
|
// store
|
|
|
|
nsBaseWidget::StoreWindowClipRegion(rects);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-14 08:33:40 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Set window shadow style
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsBaseWidget::SetWindowShadowStyle(int32_t aMode)
|
2008-10-14 08:33:40 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Hide window borders/decorations for this widget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsBaseWidget::HideWindowChrome(bool aShouldHide)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Put the window into full-screen mode
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2014-07-09 12:29:28 -07:00
|
|
|
NS_IMETHODIMP nsBaseWidget::MakeFullScreen(bool aFullScreen, nsIScreen* aScreen)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-01 12:01:11 -07:00
|
|
|
HideWindowChrome(aFullScreen);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aFullScreen) {
|
|
|
|
if (!mOriginalBounds)
|
2009-01-14 19:27:09 -08:00
|
|
|
mOriginalBounds = new nsIntRect();
|
2007-03-22 10:30:00 -07:00
|
|
|
GetScreenBounds(*mOriginalBounds);
|
2013-11-28 20:11:49 -08:00
|
|
|
// convert dev pix to display pix for window manipulation
|
2013-09-17 17:45:19 -07:00
|
|
|
CSSToLayoutDeviceScale scale = GetDefaultScale();
|
|
|
|
mOriginalBounds->x = NSToIntRound(mOriginalBounds->x / scale.scale);
|
|
|
|
mOriginalBounds->y = NSToIntRound(mOriginalBounds->y / scale.scale);
|
|
|
|
mOriginalBounds->width = NSToIntRound(mOriginalBounds->width / scale.scale);
|
|
|
|
mOriginalBounds->height = NSToIntRound(mOriginalBounds->height / scale.scale);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Move to top-left corner of screen and size to the screen dimensions
|
|
|
|
nsCOMPtr<nsIScreenManager> screenManager;
|
2013-01-01 14:38:48 -08:00
|
|
|
screenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(screenManager, "Unable to grab screenManager.");
|
|
|
|
if (screenManager) {
|
2014-07-09 12:29:28 -07:00
|
|
|
nsCOMPtr<nsIScreen> screen = aScreen;
|
|
|
|
if (!screen) {
|
|
|
|
// no screen was passed in, use the one that the window is on
|
|
|
|
screenManager->ScreenForRect(mOriginalBounds->x,
|
|
|
|
mOriginalBounds->y,
|
|
|
|
mOriginalBounds->width,
|
|
|
|
mOriginalBounds->height,
|
|
|
|
getter_AddRefs(screen));
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (screen) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t left, top, width, height;
|
2013-03-19 10:24:25 -07:00
|
|
|
if (NS_SUCCEEDED(screen->GetRectDisplayPix(&left, &top, &width, &height))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Resize(left, top, width, height, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (mOriginalBounds) {
|
|
|
|
Resize(mOriginalBounds->x, mOriginalBounds->y, mOriginalBounds->width,
|
2011-10-17 07:59:28 -07:00
|
|
|
mOriginalBounds->height, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-03-01 00:03:49 -08:00
|
|
|
nsBaseWidget::AutoLayerManagerSetup::AutoLayerManagerSetup(
|
2010-07-15 14:08:04 -07:00
|
|
|
nsBaseWidget* aWidget, gfxContext* aTarget,
|
2012-07-30 17:42:26 -07:00
|
|
|
BufferMode aDoubleBuffering, ScreenRotation aRotation)
|
2010-03-01 00:03:49 -08:00
|
|
|
: mWidget(aWidget)
|
|
|
|
{
|
2012-12-26 21:55:41 -08:00
|
|
|
mLayerManager = static_cast<BasicLayerManager*>(mWidget->GetLayerManager());
|
|
|
|
if (mLayerManager) {
|
2014-01-23 10:26:41 -08:00
|
|
|
NS_ASSERTION(mLayerManager->GetBackendType() == LayersBackend::LAYERS_BASIC,
|
2010-03-30 20:02:58 -07:00
|
|
|
"AutoLayerManagerSetup instantiated for non-basic layer backend!");
|
2012-12-26 21:55:41 -08:00
|
|
|
mLayerManager->SetDefaultTarget(aTarget);
|
|
|
|
mLayerManager->SetDefaultTargetConfiguration(aDoubleBuffering, aRotation);
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBaseWidget::AutoLayerManagerSetup::~AutoLayerManagerSetup()
|
|
|
|
{
|
2012-12-26 21:55:41 -08:00
|
|
|
if (mLayerManager) {
|
2014-01-23 10:26:41 -08:00
|
|
|
NS_ASSERTION(mLayerManager->GetBackendType() == LayersBackend::LAYERS_BASIC,
|
2010-03-30 20:02:58 -07:00
|
|
|
"AutoLayerManagerSetup instantiated for non-basic layer backend!");
|
2012-12-26 21:55:41 -08:00
|
|
|
mLayerManager->SetDefaultTarget(nullptr);
|
2014-01-23 10:26:41 -08:00
|
|
|
mLayerManager->SetDefaultTargetConfiguration(mozilla::layers::BufferMode::BUFFER_NONE, ROTATION_0);
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-15 03:34:29 -07:00
|
|
|
nsBaseWidget::AutoUseBasicLayerManager::AutoUseBasicLayerManager(nsBaseWidget* aWidget)
|
|
|
|
: mWidget(aWidget)
|
|
|
|
{
|
2012-12-16 22:35:39 -08:00
|
|
|
mPreviousTemporarilyUseBasicLayerManager =
|
|
|
|
mWidget->mTemporarilyUseBasicLayerManager;
|
2011-10-17 07:59:28 -07:00
|
|
|
mWidget->mTemporarilyUseBasicLayerManager = true;
|
2010-10-15 03:34:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBaseWidget::AutoUseBasicLayerManager::~AutoUseBasicLayerManager()
|
|
|
|
{
|
2012-12-16 22:35:39 -08:00
|
|
|
mWidget->mTemporarilyUseBasicLayerManager =
|
|
|
|
mPreviousTemporarilyUseBasicLayerManager;
|
2010-10-15 03:34:29 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-11-15 10:55:15 -08:00
|
|
|
nsBaseWidget::ComputeShouldAccelerate(bool aDefault)
|
2010-03-01 00:03:49 -08:00
|
|
|
{
|
2013-08-25 16:56:53 -07:00
|
|
|
#if defined(XP_WIN) || defined(ANDROID) || \
|
2014-02-20 18:08:53 -08:00
|
|
|
defined(MOZ_GL_PROVIDER) || defined(XP_MACOSX) || defined(MOZ_WIDGET_QT)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool accelerateByDefault = true;
|
2011-01-11 14:01:37 -08:00
|
|
|
#else
|
2011-09-28 23:19:26 -07:00
|
|
|
bool accelerateByDefault = false;
|
2011-01-11 14:01:37 -08:00
|
|
|
#endif
|
2010-08-27 19:44:37 -07:00
|
|
|
|
2013-01-11 19:59:48 -08:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// 10.6.2 and lower have a bug involving textures and pixel buffer objects
|
|
|
|
// that caused bug 629016, so we don't allow OpenGL-accelerated layers on
|
|
|
|
// those versions of the OS.
|
|
|
|
// This will still let full-screen video be accelerated on OpenGL, because
|
|
|
|
// that XUL widget opts in to acceleration, but that's probably OK.
|
2014-09-17 14:48:07 -07:00
|
|
|
accelerateByDefault = nsCocoaFeatures::AccelerateByDefault();
|
2013-01-11 19:59:48 -08:00
|
|
|
#endif
|
|
|
|
|
2011-05-23 07:54:03 -07:00
|
|
|
// we should use AddBoolPrefVarCache
|
2014-02-26 18:53:27 -08:00
|
|
|
bool disableAcceleration = gfxPrefs::LayersAccelerationDisabled();
|
|
|
|
mForceLayersAcceleration = gfxPrefs::LayersAccelerationForceEnabled();
|
2010-09-08 15:19:11 -07:00
|
|
|
|
|
|
|
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
|
2011-08-31 15:58:19 -07:00
|
|
|
accelerateByDefault = accelerateByDefault ||
|
2010-09-08 15:19:11 -07:00
|
|
|
(acceleratedEnv && (*acceleratedEnv != '0'));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
|
2011-09-28 23:19:26 -07:00
|
|
|
bool safeMode = false;
|
2010-09-08 15:19:11 -07:00
|
|
|
if (xr)
|
|
|
|
xr->GetInSafeMode(&safeMode);
|
2010-05-12 11:56:31 -07:00
|
|
|
|
2011-08-19 08:39:00 -07:00
|
|
|
bool whitelisted = false;
|
2011-01-18 12:11:19 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
if (gfxInfo) {
|
2011-09-07 14:17:44 -07:00
|
|
|
// bug 655578: on X11 at least, we must always call GetData (even if we don't need that information)
|
|
|
|
// as that's what causes GfxInfo initialization which kills the zombie 'glxtest' process.
|
|
|
|
// initially we relied on the fact that GetFeatureStatus calls GetData for us, but bug 681026 showed
|
|
|
|
// that assumption to be unsafe.
|
|
|
|
gfxInfo->GetData();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t status;
|
2011-01-18 12:11:19 -08:00
|
|
|
if (NS_SUCCEEDED(gfxInfo->GetFeatureStatus(nsIGfxInfo::FEATURE_OPENGL_LAYERS, &status))) {
|
2014-07-01 14:44:09 -07:00
|
|
|
if (status == nsIGfxInfo::FEATURE_STATUS_OK) {
|
2011-08-19 08:39:00 -07:00
|
|
|
whitelisted = true;
|
2011-01-18 12:11:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-19 08:39:00 -07:00
|
|
|
if (disableAcceleration || safeMode)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-08-19 08:39:00 -07:00
|
|
|
|
2012-02-27 13:33:19 -08:00
|
|
|
if (mForceLayersAcceleration)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2011-08-19 08:39:00 -07:00
|
|
|
if (!whitelisted) {
|
2014-01-27 12:40:50 -08:00
|
|
|
static int tell_me_once = 0;
|
|
|
|
if (!tell_me_once) {
|
|
|
|
NS_WARNING("OpenGL-accelerated layers are not supported on this system");
|
|
|
|
tell_me_once = 1;
|
|
|
|
}
|
2014-08-22 12:26:56 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2012-07-05 07:12:43 -07:00
|
|
|
NS_RUNTIMEABORT("OpenGL-accelerated layers are a hard requirement on this platform. "
|
2013-04-02 10:49:04 -07:00
|
|
|
"Cannot continue without support for them");
|
2012-07-05 07:12:43 -07:00
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-08-19 08:39:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-18 12:11:19 -08:00
|
|
|
if (accelerateByDefault)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-09-08 15:19:11 -07:00
|
|
|
|
2011-01-11 14:01:37 -08:00
|
|
|
/* use the window acceleration flag */
|
2012-11-15 10:55:15 -08:00
|
|
|
return aDefault;
|
2010-09-08 15:19:11 -07:00
|
|
|
}
|
2010-09-03 11:08:23 -07:00
|
|
|
|
2013-04-17 14:39:13 -07:00
|
|
|
CompositorParent* nsBaseWidget::NewCompositorParent(int aSurfaceWidth,
|
|
|
|
int aSurfaceHeight)
|
|
|
|
{
|
2013-04-29 20:16:04 -07:00
|
|
|
return new CompositorParent(this, false, aSurfaceWidth, aSurfaceHeight);
|
2013-04-17 14:39:13 -07:00
|
|
|
}
|
|
|
|
|
2012-01-19 06:45:37 -08:00
|
|
|
void nsBaseWidget::CreateCompositor()
|
2013-03-20 15:45:07 -07:00
|
|
|
{
|
|
|
|
nsIntRect rect;
|
|
|
|
GetBounds(rect);
|
|
|
|
CreateCompositor(rect.width, rect.height);
|
|
|
|
}
|
|
|
|
|
2014-12-15 01:47:15 -08:00
|
|
|
already_AddRefed<GeckoContentController>
|
|
|
|
nsBaseWidget::CreateRootContentController()
|
|
|
|
{
|
2014-12-15 01:49:48 -08:00
|
|
|
nsRefPtr<GeckoContentController> controller = new ChromeProcessController();
|
|
|
|
return controller.forget();
|
2014-12-15 01:47:15 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBaseWidget::ConfigureAPZCTreeManager()
|
|
|
|
{
|
|
|
|
uint64_t rootLayerTreeId = mCompositorParent->RootLayerTreeId();
|
|
|
|
mAPZC = CompositorParent::GetAPZCTreeManager(rootLayerTreeId);
|
|
|
|
MOZ_ASSERT(mAPZC);
|
|
|
|
|
|
|
|
mAPZC->SetDPI(GetDPI());
|
|
|
|
|
|
|
|
nsRefPtr<GeckoContentController> controller = CreateRootContentController();
|
|
|
|
if (controller) {
|
|
|
|
CompositorParent::SetControllerForLayerTree(rootLayerTreeId, controller);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 15:25:03 -08:00
|
|
|
nsEventStatus
|
|
|
|
nsBaseWidget::DispatchEventForAPZ(WidgetGUIEvent* aEvent,
|
|
|
|
const ScrollableLayerGuid& aGuid,
|
|
|
|
uint64_t aInputBlockId)
|
|
|
|
{
|
|
|
|
InputAPZContext context(aGuid, aInputBlockId);
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
DispatchEvent(aEvent, status);
|
|
|
|
|
|
|
|
if (mAPZC && !context.WasRoutedToChildProcess()) {
|
|
|
|
// APZ did not find a dispatch-to-content region in the child process,
|
|
|
|
// and EventStateManager did not route the event into the child process.
|
|
|
|
// It's safe to communicate to APZ that the event has been processed.
|
|
|
|
mAPZC->SetTargetAPZC(aInputBlockId, aGuid);
|
|
|
|
mAPZC->ContentReceivedInputBlock(aInputBlockId, aEvent->mFlags.mDefaultPrevented);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-08-17 23:46:16 -07:00
|
|
|
void
|
|
|
|
nsBaseWidget::GetPreferredCompositorBackends(nsTArray<LayersBackend>& aHints)
|
2013-05-09 14:02:50 -07:00
|
|
|
{
|
2013-06-23 22:27:29 -07:00
|
|
|
if (mUseLayersAcceleration) {
|
2014-01-23 10:26:41 -08:00
|
|
|
aHints.AppendElement(LayersBackend::LAYERS_OPENGL);
|
2013-05-09 14:02:50 -07:00
|
|
|
}
|
|
|
|
|
2014-01-23 10:26:41 -08:00
|
|
|
aHints.AppendElement(LayersBackend::LAYERS_BASIC);
|
2013-08-17 23:46:16 -07:00
|
|
|
}
|
|
|
|
|
2014-12-19 12:52:42 -08:00
|
|
|
void nsBaseWidget::CreateCompositorVsyncDispatcher()
|
2014-12-18 08:30:05 -08:00
|
|
|
{
|
|
|
|
if (gfxPrefs::HardwareVsyncEnabled()) {
|
|
|
|
// Parent directly listens to the vsync source whereas
|
|
|
|
// child process communicate via IPC
|
|
|
|
// Should be called AFTER gfxPlatform is initialized
|
|
|
|
if (XRE_IsParentProcess()) {
|
2014-12-19 12:52:42 -08:00
|
|
|
mCompositorVsyncDispatcher = new CompositorVsyncDispatcher();
|
2014-12-18 08:30:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 12:52:42 -08:00
|
|
|
CompositorVsyncDispatcher*
|
|
|
|
nsBaseWidget::GetCompositorVsyncDispatcher()
|
2014-12-18 08:30:05 -08:00
|
|
|
{
|
2014-12-19 12:52:42 -08:00
|
|
|
return mCompositorVsyncDispatcher;
|
2014-12-18 08:30:05 -08:00
|
|
|
}
|
|
|
|
|
2013-03-20 15:45:07 -07:00
|
|
|
void nsBaseWidget::CreateCompositor(int aWidth, int aHeight)
|
2012-01-19 06:45:37 -08:00
|
|
|
{
|
2014-10-10 01:53:30 -07:00
|
|
|
// This makes sure that gfxPlatforms gets initialized if it hasn't by now.
|
|
|
|
gfxPlatform::GetPlatform();
|
|
|
|
|
2014-06-06 06:51:24 -07:00
|
|
|
MOZ_ASSERT(gfxPlatform::UsesOffMainThreadCompositing(),
|
|
|
|
"This function assumes OMTC");
|
|
|
|
|
2013-05-03 10:34:33 -07:00
|
|
|
// Recreating this is tricky, as we may still have an old and we need
|
|
|
|
// to make sure it's properly destroyed by calling DestroyCompositor!
|
|
|
|
|
2013-06-16 19:50:32 -07:00
|
|
|
// If we've already received a shutdown notification, don't try
|
|
|
|
// create a new compositor.
|
|
|
|
if (!mShutdownObserver) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-19 12:52:42 -08:00
|
|
|
CreateCompositorVsyncDispatcher();
|
2013-04-17 14:39:13 -07:00
|
|
|
mCompositorParent = NewCompositorParent(aWidth, aHeight);
|
2013-09-27 18:42:08 -07:00
|
|
|
MessageChannel *parentChannel = mCompositorParent->GetIPCChannel();
|
2014-07-15 08:37:45 -07:00
|
|
|
nsRefPtr<ClientLayerManager> lm = new ClientLayerManager(this);
|
2012-07-13 08:25:29 -07:00
|
|
|
MessageLoop *childMessageLoop = CompositorParent::CompositorLoop();
|
|
|
|
mCompositorChild = new CompositorChild(lm);
|
2013-09-27 18:42:08 -07:00
|
|
|
mCompositorChild->Open(parentChannel, childMessageLoop, ipc::ChildSide);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
|
2014-12-15 01:47:15 -08:00
|
|
|
if (gfxPrefs::AsyncPanZoomEnabled()) {
|
|
|
|
ConfigureAPZCTreeManager();
|
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
TextureFactoryIdentifier textureFactoryIdentifier;
|
2014-03-04 00:45:51 -08:00
|
|
|
PLayerTransactionChild* shadowManager = nullptr;
|
2013-08-17 23:46:16 -07:00
|
|
|
nsTArray<LayersBackend> backendHints;
|
|
|
|
GetPreferredCompositorBackends(backendHints);
|
2013-05-03 10:34:33 -07:00
|
|
|
|
2014-09-03 05:59:36 -07:00
|
|
|
#if !defined(MOZ_X11) && !defined(XP_WIN)
|
|
|
|
if (!mRequireOffMainThreadCompositing &&
|
|
|
|
!Preferences::GetBool("layers.offmainthreadcomposition.force-basic", false)) {
|
|
|
|
for (size_t i = 0; i < backendHints.Length(); ++i) {
|
|
|
|
if (backendHints[i] == LayersBackend::LAYERS_BASIC) {
|
|
|
|
backendHints[i] = LayersBackend::LAYERS_NONE;
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 04:52:14 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-08 16:32:26 -07:00
|
|
|
bool success = false;
|
2013-08-17 23:46:16 -07:00
|
|
|
if (!backendHints.IsEmpty()) {
|
2013-08-08 16:32:26 -07:00
|
|
|
shadowManager = mCompositorChild->SendPLayerTransactionConstructor(
|
2013-08-17 23:46:16 -07:00
|
|
|
backendHints, 0, &textureFactoryIdentifier, &success);
|
2013-08-08 16:32:26 -07:00
|
|
|
}
|
2012-01-19 06:45:37 -08:00
|
|
|
|
2013-08-04 00:46:17 -07:00
|
|
|
if (success) {
|
2012-07-13 08:25:29 -07:00
|
|
|
ShadowLayerForwarder* lf = lm->AsShadowForwarder();
|
|
|
|
if (!lf) {
|
2014-07-15 08:37:45 -07:00
|
|
|
lm = nullptr;
|
2012-07-30 07:20:58 -07:00
|
|
|
mCompositorChild = nullptr;
|
2012-07-13 08:25:29 -07:00
|
|
|
return;
|
2012-01-19 06:45:37 -08:00
|
|
|
}
|
2012-07-13 08:25:29 -07:00
|
|
|
lf->SetShadowManager(shadowManager);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
lf->IdentifyTextureHost(textureFactoryIdentifier);
|
2013-06-23 22:28:22 -07:00
|
|
|
ImageBridgeChild::IdentifyCompositorTextureHost(textureFactoryIdentifier);
|
2013-08-08 16:32:26 -07:00
|
|
|
WindowUsesOMTC();
|
2012-07-13 08:25:29 -07:00
|
|
|
|
2014-07-15 08:37:45 -07:00
|
|
|
mLayerManager = lm.forget();
|
2013-05-03 10:34:33 -07:00
|
|
|
return;
|
2012-01-19 06:45:37 -08:00
|
|
|
}
|
2013-05-03 10:34:33 -07:00
|
|
|
|
2013-08-04 16:20:02 -07:00
|
|
|
NS_WARNING("Failed to create an OMT compositor.");
|
2013-05-03 10:34:33 -07:00
|
|
|
DestroyCompositor();
|
|
|
|
// Compositor child had the only reference to LayerManager and will have
|
|
|
|
// deallocated it when being freed.
|
2012-01-19 06:45:37 -08:00
|
|
|
}
|
|
|
|
|
2013-03-04 10:32:20 -08:00
|
|
|
bool nsBaseWidget::ShouldUseOffMainThreadCompositing()
|
2012-05-22 08:34:34 -07:00
|
|
|
{
|
2014-06-06 06:51:24 -07:00
|
|
|
return gfxPlatform::UsesOffMainThreadCompositing();
|
2012-05-22 08:34:34 -07:00
|
|
|
}
|
|
|
|
|
2013-04-24 11:42:40 -07:00
|
|
|
LayerManager* nsBaseWidget::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
2011-08-09 12:38:26 -07:00
|
|
|
LayersBackend aBackendHint,
|
|
|
|
LayerManagerPersistence aPersistence,
|
2010-12-06 18:05:52 -08:00
|
|
|
bool* aAllowRetaining)
|
2010-09-08 15:19:11 -07:00
|
|
|
{
|
|
|
|
if (!mLayerManager) {
|
2010-08-27 19:44:37 -07:00
|
|
|
|
2012-11-15 10:55:15 -08:00
|
|
|
mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration);
|
2010-08-27 19:44:37 -07:00
|
|
|
|
2012-05-15 12:56:56 -07:00
|
|
|
// Try to use an async compositor first, if possible
|
2013-03-04 10:32:20 -08:00
|
|
|
if (ShouldUseOffMainThreadCompositing()) {
|
2012-05-15 12:56:56 -07:00
|
|
|
// e10s uses the parameter to pass in the shadow manager from the TabChild
|
|
|
|
// so we don't expect to see it there since this doesn't support e10s.
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(aShadowManager == nullptr, "Async Compositor not supported with e10s");
|
2012-05-15 12:56:56 -07:00
|
|
|
CreateCompositor();
|
|
|
|
}
|
2012-05-15 20:19:37 -07:00
|
|
|
|
2010-03-30 20:02:58 -07:00
|
|
|
if (!mLayerManager) {
|
2013-01-18 17:07:32 -08:00
|
|
|
mLayerManager = CreateBasicLayerManager();
|
2010-03-30 20:02:58 -07:00
|
|
|
}
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
2010-10-15 03:34:29 -07:00
|
|
|
if (mTemporarilyUseBasicLayerManager && !mBasicLayerManager) {
|
|
|
|
mBasicLayerManager = CreateBasicLayerManager();
|
|
|
|
}
|
|
|
|
LayerManager* usedLayerManager = mTemporarilyUseBasicLayerManager ?
|
|
|
|
mBasicLayerManager : mLayerManager;
|
|
|
|
if (aAllowRetaining) {
|
|
|
|
*aAllowRetaining = (usedLayerManager == mLayerManager);
|
|
|
|
}
|
|
|
|
return usedLayerManager;
|
2010-03-01 00:03:49 -08:00
|
|
|
}
|
|
|
|
|
2013-09-01 15:20:45 -07:00
|
|
|
LayerManager* nsBaseWidget::CreateBasicLayerManager()
|
2010-09-14 16:40:23 -07:00
|
|
|
{
|
2013-04-30 22:03:25 -07:00
|
|
|
return new BasicLayerManager(this);
|
2010-09-14 16:40:23 -07:00
|
|
|
}
|
|
|
|
|
2012-10-04 00:05:24 -07:00
|
|
|
CompositorChild* nsBaseWidget::GetRemoteRenderer()
|
|
|
|
{
|
|
|
|
return mCompositorChild;
|
|
|
|
}
|
|
|
|
|
2013-07-08 21:21:05 -07:00
|
|
|
TemporaryRef<mozilla::gfx::DrawTarget> nsBaseWidget::StartRemoteDrawing()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Return the used device context
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
2013-01-01 14:38:48 -08:00
|
|
|
nsDeviceContext* nsBaseWidget::GetDeviceContext()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-29 04:36:09 -07:00
|
|
|
if (!mContextInitialized) {
|
|
|
|
mContext->Init(this);
|
|
|
|
mContextInitialized = true;
|
|
|
|
}
|
2013-01-01 14:38:48 -08:00
|
|
|
return mContext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Destroy the window
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::OnDestroy()
|
|
|
|
{
|
2011-10-25 08:05:32 -07:00
|
|
|
// release references to device context and app shell
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IF_RELEASE(mContext);
|
2015-01-27 22:27:30 -08:00
|
|
|
|
|
|
|
if (mTextEventDispatcher) {
|
|
|
|
mTextEventDispatcher->OnDestroyWidget();
|
|
|
|
// Don't release it until this widget actually released because after this
|
|
|
|
// is called, TextEventDispatcher() may create it again.
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsBaseWidget::SetWindowClass(const nsAString& xulWinType)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_METHOD nsBaseWidget::MoveClient(double aX, double aY)
|
2011-12-01 13:35:42 -08:00
|
|
|
{
|
|
|
|
nsIntPoint clientOffset(GetClientOffset());
|
2013-04-15 05:17:22 -07:00
|
|
|
|
|
|
|
// GetClientOffset returns device pixels; scale back to display pixels
|
|
|
|
// if that's what this widget uses for the Move/Resize APIs
|
2013-09-17 17:45:19 -07:00
|
|
|
CSSToLayoutDeviceScale scale = BoundsUseDisplayPixels()
|
|
|
|
? GetDefaultScale()
|
|
|
|
: CSSToLayoutDeviceScale(1.0);
|
|
|
|
aX -= clientOffset.x * 1.0 / scale.scale;
|
|
|
|
aY -= clientOffset.y * 1.0 / scale.scale;
|
2013-04-15 05:17:22 -07:00
|
|
|
|
2011-12-01 13:35:42 -08:00
|
|
|
return Move(aX, aY);
|
|
|
|
}
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_METHOD nsBaseWidget::ResizeClient(double aWidth,
|
|
|
|
double aHeight,
|
2011-12-01 13:35:42 -08:00
|
|
|
bool aRepaint)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((aWidth >=0) , "Negative width passed to ResizeClient");
|
|
|
|
NS_ASSERTION((aHeight >=0), "Negative height passed to ResizeClient");
|
|
|
|
|
|
|
|
nsIntRect clientBounds;
|
|
|
|
GetClientBounds(clientBounds);
|
2013-04-15 05:17:22 -07:00
|
|
|
|
|
|
|
// GetClientBounds and mBounds are device pixels; scale back to display pixels
|
|
|
|
// if that's what this widget uses for the Move/Resize APIs
|
2013-09-17 17:45:19 -07:00
|
|
|
CSSToLayoutDeviceScale scale = BoundsUseDisplayPixels()
|
|
|
|
? GetDefaultScale()
|
|
|
|
: CSSToLayoutDeviceScale(1.0);
|
|
|
|
double invScale = 1.0 / scale.scale;
|
|
|
|
aWidth = mBounds.width * invScale + (aWidth - clientBounds.width * invScale);
|
|
|
|
aHeight = mBounds.height * invScale + (aHeight - clientBounds.height * invScale);
|
2011-12-01 13:35:42 -08:00
|
|
|
|
|
|
|
return Resize(aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
|
2012-12-12 01:57:38 -08:00
|
|
|
NS_METHOD nsBaseWidget::ResizeClient(double aX,
|
|
|
|
double aY,
|
|
|
|
double aWidth,
|
|
|
|
double aHeight,
|
2011-12-01 13:35:42 -08:00
|
|
|
bool aRepaint)
|
|
|
|
{
|
|
|
|
NS_ASSERTION((aWidth >=0) , "Negative width passed to ResizeClient");
|
|
|
|
NS_ASSERTION((aHeight >=0), "Negative height passed to ResizeClient");
|
|
|
|
|
|
|
|
nsIntRect clientBounds;
|
|
|
|
GetClientBounds(clientBounds);
|
2013-04-15 05:17:22 -07:00
|
|
|
|
2013-09-17 17:45:19 -07:00
|
|
|
double scale = BoundsUseDisplayPixels() ? 1.0 / GetDefaultScale().scale : 1.0;
|
2013-04-15 05:17:22 -07:00
|
|
|
aWidth = mBounds.width * scale + (aWidth - clientBounds.width * scale);
|
|
|
|
aHeight = mBounds.height * scale + (aHeight - clientBounds.height * scale);
|
2011-12-01 13:35:42 -08:00
|
|
|
|
|
|
|
nsIntPoint clientOffset(GetClientOffset());
|
2013-04-15 05:17:22 -07:00
|
|
|
aX -= clientOffset.x * scale;
|
|
|
|
aY -= clientOffset.y * scale;
|
2011-12-01 13:35:42 -08:00
|
|
|
|
|
|
|
return Resize(aX, aY, aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:01:07 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Bounds
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* If the implementation of nsWindow supports borders this method MUST be overridden
|
|
|
|
*
|
|
|
|
**/
|
2009-01-14 19:27:09 -08:00
|
|
|
NS_METHOD nsBaseWidget::GetClientBounds(nsIntRect &aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return GetBounds(aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the implementation of nsWindow supports borders this method MUST be overridden
|
|
|
|
*
|
|
|
|
**/
|
2009-01-14 19:27:09 -08:00
|
|
|
NS_METHOD nsBaseWidget::GetBounds(nsIntRect &aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aRect = mBounds;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the implementation of nsWindow uses a local coordinate system within the window,
|
|
|
|
* this method must be overridden
|
|
|
|
*
|
|
|
|
**/
|
2009-01-14 19:27:09 -08:00
|
|
|
NS_METHOD nsBaseWidget::GetScreenBounds(nsIntRect &aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return GetBounds(aRect);
|
|
|
|
}
|
|
|
|
|
2014-05-20 00:32:17 -07:00
|
|
|
NS_METHOD nsBaseWidget::GetRestoredBounds(nsIntRect &aRect)
|
|
|
|
{
|
|
|
|
if (SizeMode() != nsSizeMode_Normal) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return GetScreenBounds(aRect);
|
|
|
|
}
|
|
|
|
|
2010-07-27 06:38:03 -07:00
|
|
|
nsIntPoint nsBaseWidget::GetClientOffset()
|
2010-06-24 19:01:06 -07:00
|
|
|
{
|
2010-07-27 06:38:03 -07:00
|
|
|
return nsIntPoint(0, 0);
|
2010-06-24 19:01:06 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 19:01:07 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::GetNonClientMargins(nsIntMargin &margins)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2010-06-24 19:01:07 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::SetNonClientMargins(nsIntMargin &margins)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_METHOD nsBaseWidget::EnableDragDrop(bool aEnable)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-01-28 08:09:34 -08:00
|
|
|
uint32_t nsBaseWidget::GetMaxTouchPoints() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_METHOD nsBaseWidget::SetModal(bool aModal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsBaseWidget::GetAttention(int32_t aCycleCount) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2009-04-21 16:53:52 -07:00
|
|
|
nsBaseWidget::HasPendingInputEvent()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-04-21 16:53:52 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::SetIcon(const nsAString&)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsBaseWidget::SetWindowTitlebarColor(nscolor aColor, bool aActive)
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-08-08 09:11:54 -07:00
|
|
|
nsBaseWidget::ShowsResizeIndicator(nsIntRect* aResizerRect)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-08-08 09:11:54 -07:00
|
|
|
}
|
|
|
|
|
2010-03-30 20:02:58 -07:00
|
|
|
NS_IMETHODIMP
|
2012-11-15 10:55:15 -08:00
|
|
|
nsBaseWidget::SetLayersAcceleration(bool aEnabled)
|
2010-03-30 20:02:58 -07:00
|
|
|
{
|
2012-11-15 10:55:15 -08:00
|
|
|
if (mUseLayersAcceleration == aEnabled) {
|
2010-03-30 20:02:58 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-11-15 10:55:15 -08:00
|
|
|
|
|
|
|
bool usedAcceleration = mUseLayersAcceleration;
|
|
|
|
|
|
|
|
mUseLayersAcceleration = ComputeShouldAccelerate(aEnabled);
|
|
|
|
// ComputeShouldAccelerate may have set mUseLayersAcceleration to a value
|
|
|
|
// different from aEnabled.
|
|
|
|
if (usedAcceleration == mUseLayersAcceleration) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-12-06 18:05:25 -08:00
|
|
|
if (mLayerManager) {
|
|
|
|
mLayerManager->Destroy();
|
|
|
|
}
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
mLayerManager = nullptr;
|
2010-03-30 20:02:58 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-02 06:34:54 -07:00
|
|
|
NS_METHOD nsBaseWidget::RegisterTouchWindow()
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsBaseWidget::UnregisterTouchWindow()
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2009-09-24 03:58:04 -07:00
|
|
|
NS_IMETHODIMP
|
2013-03-15 02:03:16 -07:00
|
|
|
nsBaseWidget::OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
|
|
|
|
double aOriginalDeltaY,
|
|
|
|
double& aOverriddenDeltaX,
|
|
|
|
double& aOverriddenDeltaY)
|
|
|
|
{
|
|
|
|
aOverriddenDeltaX = aOriginalDeltaX;
|
|
|
|
aOverriddenDeltaY = aOriginalDeltaY;
|
|
|
|
|
|
|
|
static bool sInitialized = false;
|
|
|
|
static bool sIsOverrideEnabled = false;
|
|
|
|
static int32_t sIntFactorX = 0;
|
|
|
|
static int32_t sIntFactorY = 0;
|
|
|
|
|
|
|
|
if (!sInitialized) {
|
|
|
|
Preferences::AddBoolVarCache(&sIsOverrideEnabled,
|
|
|
|
"mousewheel.system_scroll_override_on_root_content.enabled", false);
|
|
|
|
Preferences::AddIntVarCache(&sIntFactorX,
|
|
|
|
"mousewheel.system_scroll_override_on_root_content.horizontal.factor", 0);
|
|
|
|
Preferences::AddIntVarCache(&sIntFactorY,
|
|
|
|
"mousewheel.system_scroll_override_on_root_content.vertical.factor", 0);
|
|
|
|
sIntFactorX = std::max(sIntFactorX, 0);
|
|
|
|
sIntFactorY = std::max(sIntFactorY, 0);
|
|
|
|
sInitialized = true;
|
|
|
|
}
|
2009-09-24 03:58:04 -07:00
|
|
|
|
2013-03-15 02:03:16 -07:00
|
|
|
if (!sIsOverrideEnabled) {
|
2009-09-24 03:58:04 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The pref value must be larger than 100, otherwise, we don't override the
|
|
|
|
// delta value.
|
2013-03-15 02:03:16 -07:00
|
|
|
if (sIntFactorX > 100) {
|
|
|
|
double factor = static_cast<double>(sIntFactorX) / 100;
|
|
|
|
aOverriddenDeltaX *= factor;
|
|
|
|
}
|
|
|
|
if (sIntFactorY > 100) {
|
|
|
|
double factor = static_cast<double>(sIntFactorY) / 100;
|
|
|
|
aOverriddenDeltaY *= factor;
|
2009-09-24 03:58:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-29 21:03:42 -07:00
|
|
|
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2012-06-05 19:08:30 -07:00
|
|
|
ResolveIconNameHelper(nsIFile *aFile,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAString &aIconName,
|
|
|
|
const nsAString &aIconSuffix)
|
|
|
|
{
|
|
|
|
aFile->Append(NS_LITERAL_STRING("icons"));
|
|
|
|
aFile->Append(NS_LITERAL_STRING("default"));
|
|
|
|
aFile->Append(aIconName + aIconSuffix);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool readable;
|
2007-03-22 10:30:00 -07:00
|
|
|
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,
|
2012-06-05 19:08:30 -07:00
|
|
|
nsIFile **aResult)
|
2013-01-01 14:38:48 -08:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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));
|
|
|
|
if (dirs) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasMore;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (NS_SUCCEEDED(dirs->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> element;
|
|
|
|
dirs->GetNext(getter_AddRefs(element));
|
|
|
|
if (!element)
|
|
|
|
continue;
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(element);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!file)
|
|
|
|
continue;
|
|
|
|
if (ResolveIconNameHelper(file, aIconName, aIconSuffix)) {
|
|
|
|
NS_ADDREF(*aResult = file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// then check the main app chrome directory
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
dirSvc->Get(NS_APP_CHROME_DIR, NS_GET_IID(nsIFile),
|
2007-03-22 10:30:00 -07:00
|
|
|
getter_AddRefs(file));
|
|
|
|
if (file && ResolveIconNameHelper(file, aIconName, aIconSuffix))
|
|
|
|
NS_ADDREF(*aResult = file);
|
|
|
|
}
|
|
|
|
|
2013-01-01 14:38:48 -08:00
|
|
|
NS_IMETHODIMP
|
2013-10-01 20:46:03 -07:00
|
|
|
nsBaseWidget::BeginResizeDrag(WidgetGUIEvent* aEvent,
|
|
|
|
int32_t aHorizontal,
|
|
|
|
int32_t aVertical)
|
2007-12-11 02:08:35 -08:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2010-07-17 01:11:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-10-01 23:38:27 -07:00
|
|
|
nsBaseWidget::BeginMoveDrag(WidgetMouseEvent* aEvent)
|
2010-07-17 01:11:54 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2007-12-11 02:08:35 -08:00
|
|
|
}
|
2010-11-22 22:48:03 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-01-25 18:05:34 -08:00
|
|
|
nsBaseWidget::GetGLFrameBufferFormat()
|
|
|
|
{
|
2013-11-26 14:15:17 -08:00
|
|
|
return LOCAL_GL_RGBA;
|
2012-01-25 18:05:34 -08:00
|
|
|
}
|
|
|
|
|
2012-07-30 17:43:29 -07:00
|
|
|
void nsBaseWidget::SetSizeConstraints(const SizeConstraints& aConstraints)
|
|
|
|
{
|
|
|
|
mSizeConstraints = aConstraints;
|
|
|
|
// We can't ensure that the size is honored at this point because we're
|
|
|
|
// probably in the middle of a reflow.
|
|
|
|
}
|
|
|
|
|
|
|
|
const widget::SizeConstraints& nsBaseWidget::GetSizeConstraints() const
|
|
|
|
{
|
|
|
|
return mSizeConstraints;
|
|
|
|
}
|
|
|
|
|
2012-10-26 06:15:22 -07:00
|
|
|
// static
|
|
|
|
nsIRollupListener*
|
|
|
|
nsBaseWidget::GetActiveRollupListener()
|
|
|
|
{
|
|
|
|
// If set, then this is likely an <html:select> dropdown.
|
|
|
|
if (gRollupListener)
|
|
|
|
return gRollupListener;
|
|
|
|
|
|
|
|
return nsXULPopupManager::GetInstance();
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:41 -07:00
|
|
|
void
|
|
|
|
nsBaseWidget::NotifyWindowDestroyed()
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!mWidgetListener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXULWindow> window = mWidgetListener->GetXULWindow();
|
|
|
|
nsCOMPtr<nsIBaseWindow> xulWindow(do_QueryInterface(window));
|
|
|
|
if (xulWindow) {
|
|
|
|
xulWindow->Destroy();
|
2012-08-15 11:52:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:35 -07:00
|
|
|
void
|
|
|
|
nsBaseWidget::NotifySizeMoveDone()
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!mWidgetListener || mWidgetListener->GetXULWindow())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIPresShell* presShell = mWidgetListener->GetPresShell();
|
2012-08-15 11:52:35 -07:00
|
|
|
if (presShell) {
|
|
|
|
presShell->WindowSizeMoveDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-27 23:45:08 -08:00
|
|
|
void
|
|
|
|
nsBaseWidget::NotifyWindowMoved(int32_t aX, int32_t aY)
|
|
|
|
{
|
|
|
|
if (mWidgetListener) {
|
|
|
|
mWidgetListener->WindowMoved(this, aX, aY);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetIMEUpdatePreference().WantPositionChanged()) {
|
|
|
|
NotifyIME(IMENotification(IMEMessage::NOTIFY_IME_OF_POSITION_CHANGE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:35 -07:00
|
|
|
void
|
|
|
|
nsBaseWidget::NotifySysColorChanged()
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!mWidgetListener || mWidgetListener->GetXULWindow())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIPresShell* presShell = mWidgetListener->GetPresShell();
|
2012-08-15 11:52:35 -07:00
|
|
|
if (presShell) {
|
|
|
|
presShell->SysColorChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsBaseWidget::NotifyThemeChanged()
|
|
|
|
{
|
2012-08-15 11:52:42 -07:00
|
|
|
if (!mWidgetListener || mWidgetListener->GetXULWindow())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIPresShell* presShell = mWidgetListener->GetPresShell();
|
2012-08-15 11:52:35 -07:00
|
|
|
if (presShell) {
|
|
|
|
presShell->ThemeChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:40 -07:00
|
|
|
void
|
|
|
|
nsBaseWidget::NotifyUIStateChanged(UIStateChangeType aShowAccelerators,
|
|
|
|
UIStateChangeType aShowFocusRings)
|
|
|
|
{
|
2012-08-17 08:36:34 -07:00
|
|
|
if (!mWidgetListener)
|
|
|
|
return;
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIPresShell* presShell = mWidgetListener->GetPresShell();
|
2013-04-18 06:24:30 -07:00
|
|
|
if (!presShell)
|
|
|
|
return;
|
|
|
|
|
2012-08-15 11:52:40 -07:00
|
|
|
nsIDocument* doc = presShell->GetDocument();
|
|
|
|
if (doc) {
|
|
|
|
nsPIDOMWindow* win = doc->GetWindow();
|
|
|
|
if (win) {
|
|
|
|
win->SetKeyboardIndicators(aShowAccelerators, aShowFocusRings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 22:27:30 -08:00
|
|
|
NS_IMETHODIMP_(nsIWidget::TextEventDispatcher*)
|
|
|
|
nsBaseWidget::GetTextEventDispatcher()
|
|
|
|
{
|
|
|
|
if (!mTextEventDispatcher) {
|
|
|
|
mTextEventDispatcher = new TextEventDispatcher(this);
|
|
|
|
}
|
|
|
|
return mTextEventDispatcher;
|
|
|
|
}
|
|
|
|
|
2012-08-15 11:52:37 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
|
2012-11-17 18:01:44 -08:00
|
|
|
a11y::Accessible*
|
2013-06-27 08:03:58 -07:00
|
|
|
nsBaseWidget::GetRootAccessible()
|
2012-08-15 11:52:37 -07:00
|
|
|
{
|
2012-08-17 08:36:34 -07:00
|
|
|
NS_ENSURE_TRUE(mWidgetListener, nullptr);
|
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIPresShell* presShell = mWidgetListener->GetPresShell();
|
2012-08-15 11:52:37 -07:00
|
|
|
NS_ENSURE_TRUE(presShell, nullptr);
|
|
|
|
|
|
|
|
// If container is null then the presshell is not active. This often happens
|
|
|
|
// when a preshell is being held onto for fastback.
|
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
2013-11-20 11:18:25 -08:00
|
|
|
NS_ENSURE_TRUE(presContext->GetContainerWeak(), nullptr);
|
2012-08-15 11:52:37 -07:00
|
|
|
|
|
|
|
// Accessible creation might be not safe so use IsSafeToRunScript to
|
|
|
|
// make sure it's not created at unsafe times.
|
2013-06-27 08:03:58 -07:00
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
services::GetAccessibilityService();
|
2012-08-15 11:52:37 -07:00
|
|
|
if (accService) {
|
|
|
|
return accService->GetRootDocumentAccessible(presShell, nsContentUtils::IsSafeToRunScript());
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-12-14 12:40:56 -08:00
|
|
|
#endif // ACCESSIBILITY
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIWidget::SynthesizeNativeTouchTap(nsIntPoint aPointerScreenPoint, bool aLongTap)
|
|
|
|
{
|
|
|
|
if (sPointerIdCounter > TOUCH_INJECT_MAX_POINTS) {
|
|
|
|
sPointerIdCounter = 0;
|
|
|
|
}
|
|
|
|
int pointerId = sPointerIdCounter;
|
|
|
|
sPointerIdCounter++;
|
|
|
|
nsresult rv = SynthesizeNativeTouchPoint(pointerId, TOUCH_CONTACT,
|
|
|
|
aPointerScreenPoint, 1.0, 90);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aLongTap) {
|
|
|
|
nsresult rv = SynthesizeNativeTouchPoint(pointerId, TOUCH_REMOVE,
|
|
|
|
aPointerScreenPoint, 0, 0);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initiate a long tap
|
|
|
|
int elapse = Preferences::GetInt("ui.click_hold_context_menus.delay",
|
|
|
|
TOUCH_INJECT_LONG_TAP_DEFAULT_MSEC);
|
|
|
|
if (!mLongTapTimer) {
|
|
|
|
mLongTapTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
SynthesizeNativeTouchPoint(pointerId, TOUCH_CANCEL,
|
|
|
|
aPointerScreenPoint, 0, 0);
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
// Windows requires recuring events, so we set this to a smaller window
|
|
|
|
// than the pref value.
|
|
|
|
int timeout = elapse;
|
|
|
|
if (timeout > TOUCH_INJECT_PUMP_TIMER_MSEC) {
|
|
|
|
timeout = TOUCH_INJECT_PUMP_TIMER_MSEC;
|
|
|
|
}
|
|
|
|
mLongTapTimer->InitWithFuncCallback(OnLongTapTimerCallback, this,
|
|
|
|
timeout,
|
|
|
|
nsITimer::TYPE_REPEATING_SLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we already have a long tap pending, cancel it. We only allow one long
|
|
|
|
// tap to be active at a time.
|
|
|
|
if (mLongTapTouchPoint) {
|
|
|
|
SynthesizeNativeTouchPoint(mLongTapTouchPoint->mPointerId, TOUCH_CANCEL,
|
|
|
|
mLongTapTouchPoint->mPosition, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
mLongTapTouchPoint = new LongTapInfo(pointerId, aPointerScreenPoint,
|
|
|
|
TimeDuration::FromMilliseconds(elapse));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsIWidget::OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure)
|
|
|
|
{
|
2014-03-15 12:00:15 -07:00
|
|
|
nsIWidget *self = static_cast<nsIWidget *>(aClosure);
|
2013-12-14 12:40:56 -08:00
|
|
|
|
|
|
|
if ((self->mLongTapTouchPoint->mStamp + self->mLongTapTouchPoint->mDuration) >
|
|
|
|
TimeStamp::Now()) {
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// Windows needs us to keep pumping feedback to the digitizer, so update
|
|
|
|
// the pointer id with the same position.
|
|
|
|
self->SynthesizeNativeTouchPoint(self->mLongTapTouchPoint->mPointerId,
|
|
|
|
TOUCH_CONTACT,
|
|
|
|
self->mLongTapTouchPoint->mPosition,
|
|
|
|
1.0, 90);
|
2012-08-15 11:52:37 -07:00
|
|
|
#endif
|
2013-12-14 12:40:56 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// finished, remove the touch point
|
|
|
|
self->mLongTapTimer->Cancel();
|
|
|
|
self->mLongTapTimer = nullptr;
|
|
|
|
self->SynthesizeNativeTouchPoint(self->mLongTapTouchPoint->mPointerId,
|
|
|
|
TOUCH_REMOVE,
|
|
|
|
self->mLongTapTouchPoint->mPosition,
|
|
|
|
0, 0);
|
|
|
|
self->mLongTapTouchPoint = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsIWidget::ClearNativeTouchSequence()
|
|
|
|
{
|
|
|
|
if (!mLongTapTimer) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mLongTapTimer->Cancel();
|
|
|
|
mLongTapTimer = nullptr;
|
|
|
|
SynthesizeNativeTouchPoint(mLongTapTouchPoint->mPointerId, TOUCH_CANCEL,
|
|
|
|
mLongTapTouchPoint->mPosition, 0, 0);
|
|
|
|
mLongTapTouchPoint = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-15 11:52:37 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ nsAutoString
|
2013-10-01 20:46:03 -07:00
|
|
|
nsBaseWidget::debug_GuiEventToString(WidgetGUIEvent* aGuiEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != aGuiEvent,"cmon, null gui event.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString eventName(NS_LITERAL_STRING("UNKNOWN"));
|
|
|
|
|
|
|
|
#define _ASSIGN_eventName(_value,_name)\
|
2011-12-05 01:10:27 -08:00
|
|
|
case _value: eventName.AssignLiteral(_name) ; break
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch(aGuiEvent->message)
|
|
|
|
{
|
|
|
|
_ASSIGN_eventName(NS_BLUR_CONTENT,"NS_BLUR_CONTENT");
|
|
|
|
_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");
|
2014-04-10 00:11:37 -07:00
|
|
|
_ASSIGN_eventName(NS_EDITOR_INPUT,"NS_EDITOR_INPUT");
|
2007-03-22 10:30:00 -07:00
|
|
|
_ASSIGN_eventName(NS_FOCUS_CONTENT,"NS_FOCUS_CONTENT");
|
|
|
|
_ASSIGN_eventName(NS_FORM_SELECTED,"NS_FORM_SELECTED");
|
|
|
|
_ASSIGN_eventName(NS_FORM_CHANGE,"NS_FORM_CHANGE");
|
|
|
|
_ASSIGN_eventName(NS_FORM_RESET,"NS_FORM_RESET");
|
|
|
|
_ASSIGN_eventName(NS_FORM_SUBMIT,"NS_FORM_SUBMIT");
|
|
|
|
_ASSIGN_eventName(NS_IMAGE_ABORT,"NS_IMAGE_ABORT");
|
|
|
|
_ASSIGN_eventName(NS_LOAD_ERROR,"NS_LOAD_ERROR");
|
|
|
|
_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");
|
|
|
|
_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");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_MOVE,"NS_MOUSE_MOVE");
|
|
|
|
_ASSIGN_eventName(NS_LOAD,"NS_LOAD");
|
2009-09-01 09:45:05 -07:00
|
|
|
_ASSIGN_eventName(NS_POPSTATE,"NS_POPSTATE");
|
2010-09-16 01:48:47 -07:00
|
|
|
_ASSIGN_eventName(NS_BEFORE_SCRIPT_EXECUTE,"NS_BEFORE_SCRIPT_EXECUTE");
|
|
|
|
_ASSIGN_eventName(NS_AFTER_SCRIPT_EXECUTE,"NS_AFTER_SCRIPT_EXECUTE");
|
2007-03-22 10:30:00 -07:00
|
|
|
_ASSIGN_eventName(NS_PAGE_UNLOAD,"NS_PAGE_UNLOAD");
|
2009-06-26 10:16:50 -07:00
|
|
|
_ASSIGN_eventName(NS_HASHCHANGE,"NS_HASHCHANGE");
|
2010-06-23 18:12:07 -07:00
|
|
|
_ASSIGN_eventName(NS_READYSTATECHANGE,"NS_READYSTATECHANGE");
|
2007-03-22 10:30:00 -07:00
|
|
|
_ASSIGN_eventName(NS_XUL_BROADCAST, "NS_XUL_BROADCAST");
|
|
|
|
_ASSIGN_eventName(NS_XUL_COMMAND_UPDATE, "NS_XUL_COMMAND_UPDATE");
|
|
|
|
|
|
|
|
#undef _ASSIGN_eventName
|
|
|
|
|
2013-01-01 14:38:48 -08:00
|
|
|
default:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
char buf[32];
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
sprintf(buf,"UNKNOWN: %d",aGuiEvent->message);
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2011-12-05 01:10:27 -08:00
|
|
|
CopyASCIItoUTF16(buf, eventName);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsAutoString(eventName);
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Code to deal with paint and event debug prefs.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
struct PrefPair
|
|
|
|
{
|
|
|
|
const char * name;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool value;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static PrefPair debug_PrefValues[] =
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
{ "nglayout.debug.crossing_event_dumping", false },
|
|
|
|
{ "nglayout.debug.event_dumping", false },
|
|
|
|
{ "nglayout.debug.invalidate_dumping", false },
|
|
|
|
{ "nglayout.debug.motion_event_dumping", false },
|
|
|
|
{ "nglayout.debug.paint_dumping", false },
|
|
|
|
{ "nglayout.debug.paint_flashing", false }
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBaseWidget::debug_GetCachedBoolPref(const char * aPrefName)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != aPrefName,"cmon, pref name is null.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(debug_PrefValues); i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (strcmp(debug_PrefValues[i].name, aPrefName) == 0)
|
|
|
|
{
|
|
|
|
return debug_PrefValues[i].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
2011-09-28 23:19:26 -07:00
|
|
|
static void debug_SetCachedBoolPref(const char * aPrefName,bool aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != aPrefName,"cmon, pref name is null.");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(debug_PrefValues); i++)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (strcmp(debug_PrefValues[i].name, aPrefName) == 0)
|
|
|
|
{
|
|
|
|
debug_PrefValues[i].value = aValue;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ASSERTION(false, "cmon, this code is not reached dude.");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
2012-06-18 18:28:00 -07:00
|
|
|
class Debug_PrefObserver MOZ_FINAL : public nsIObserver {
|
2014-06-24 09:36:44 -07:00
|
|
|
~Debug_PrefObserver() {}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(Debug_PrefObserver, nsIObserver)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Debug_PrefObserver::Observe(nsISupports* subject, const char* topic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* data)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ConvertUTF16toUTF8 prefName(data);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool value = Preferences::GetBool(prefName.get(), false);
|
2007-03-22 10:30:00 -07:00
|
|
|
debug_SetCachedBoolPref(prefName.get(), value);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
debug_RegisterPrefCallbacks()
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool once = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-23 07:54:03 -07:00
|
|
|
if (!once) {
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
once = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-23 07:54:03 -07:00
|
|
|
nsCOMPtr<nsIObserver> obs(new Debug_PrefObserver());
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(debug_PrefValues); i++) {
|
2011-05-23 07:54:03 -07:00
|
|
|
// Initialize the pref values
|
|
|
|
debug_PrefValues[i].value =
|
2011-09-28 23:19:26 -07:00
|
|
|
Preferences::GetBool(debug_PrefValues[i].name, false);
|
2011-05-23 07:54:03 -07:00
|
|
|
|
|
|
|
if (obs) {
|
|
|
|
// Register callbacks for when these change
|
|
|
|
Preferences::AddStrongObserver(obs, debug_PrefValues[i].name);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
_GetPrintCount()
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t sCount = 0;
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return ++sCount;
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBaseWidget::debug_WantPaintFlashing()
|
|
|
|
{
|
|
|
|
return debug_GetCachedBoolPref("nglayout.debug.paint_flashing");
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpEvent(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* aGuiEvent,
|
2012-09-01 19:35:17 -07:00
|
|
|
const nsAutoCString & aWidgetName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aWindowID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aGuiEvent->message == NS_MOUSE_MOVE)
|
|
|
|
{
|
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.motion_event_dumping"))
|
|
|
|
return;
|
|
|
|
}
|
2013-01-01 14:38:48 -08:00
|
|
|
|
|
|
|
if (aGuiEvent->message == NS_MOUSE_ENTER ||
|
2007-03-22 10:30:00 -07:00
|
|
|
aGuiEvent->message == NS_MOUSE_EXIT)
|
|
|
|
{
|
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.crossing_event_dumping"))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.event_dumping"))
|
|
|
|
return;
|
|
|
|
|
2011-12-05 01:10:27 -08:00
|
|
|
NS_LossyConvertUTF16toASCII tempString(debug_GuiEventToString(aGuiEvent).get());
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
fprintf(aFileOut,
|
2013-01-01 14:38:48 -08:00
|
|
|
"%4d %-26s widget=%-8p name=%-12s id=0x%-6x refpt=%d,%d\n",
|
2007-03-22 10:30:00 -07:00
|
|
|
_GetPrintCount(),
|
|
|
|
tempString.get(),
|
|
|
|
(void *) aWidget,
|
|
|
|
aWidgetName.get(),
|
2013-01-01 14:38:48 -08:00
|
|
|
aWindowID,
|
2014-08-28 09:45:48 -07:00
|
|
|
aGuiEvent->refPoint.x,
|
|
|
|
aGuiEvent->refPoint.y);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpPaintEvent(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
2012-08-15 11:52:42 -07:00
|
|
|
const nsIntRegion & aRegion,
|
2012-09-01 19:35:17 -07:00
|
|
|
const nsAutoCString & aWidgetName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aWindowID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != aFileOut,"cmon, null output FILE");
|
|
|
|
NS_ASSERTION(nullptr != aWidget,"cmon, the widget is null");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.paint_dumping"))
|
|
|
|
return;
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2012-08-15 11:52:42 -07:00
|
|
|
nsIntRect rect = aRegion.GetBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
fprintf(aFileOut,
|
2013-01-01 14:38:48 -08:00
|
|
|
"%4d PAINT widget=%p name=%-12s id=0x%-6x bounds-rect=%3d,%-3d %3d,%-3d",
|
2007-03-22 10:30:00 -07:00
|
|
|
_GetPrintCount(),
|
|
|
|
(void *) aWidget,
|
|
|
|
aWidgetName.get(),
|
2013-01-01 14:38:48 -08:00
|
|
|
aWindowID,
|
2010-08-20 12:29:01 -07:00
|
|
|
rect.x, rect.y, rect.width, rect.height
|
|
|
|
);
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
fprintf(aFileOut,"\n");
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpInvalidate(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
2009-01-14 19:27:09 -08:00
|
|
|
const nsIntRect * aRect,
|
2012-09-01 19:35:17 -07:00
|
|
|
const nsAutoCString & aWidgetName,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aWindowID)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.invalidate_dumping"))
|
|
|
|
return;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr != aFileOut,"cmon, null output FILE");
|
|
|
|
NS_ASSERTION(nullptr != aWidget,"cmon, the widget is null");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
fprintf(aFileOut,
|
2013-01-01 14:38:48 -08:00
|
|
|
"%4d Invalidate widget=%p name=%-12s id=0x%-6x",
|
2007-03-22 10:30:00 -07:00
|
|
|
_GetPrintCount(),
|
|
|
|
(void *) aWidget,
|
|
|
|
aWidgetName.get(),
|
2013-01-01 14:38:48 -08:00
|
|
|
aWindowID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-01 14:38:48 -08:00
|
|
|
if (aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
fprintf(aFileOut,
|
|
|
|
" rect=%3d,%-3d %3d,%-3d",
|
2013-01-01 14:38:48 -08:00
|
|
|
aRect->x,
|
2007-03-22 10:30:00 -07:00
|
|
|
aRect->y,
|
2013-01-01 14:38:48 -08:00
|
|
|
aRect->width,
|
2007-03-22 10:30:00 -07:00
|
|
|
aRect->height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(aFileOut,
|
|
|
|
" rect=%-15s",
|
|
|
|
"none");
|
|
|
|
}
|
2013-01-01 14:38:48 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
fprintf(aFileOut,"\n");
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|