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
|
|
|
|
2012-12-14 15:58:45 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "mozilla/Likely.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsView.h"
|
|
|
|
#include "nsIWidget.h"
|
2010-08-20 12:29:02 -07:00
|
|
|
#include "nsWidgetsCID.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsViewManager.h"
|
2012-08-15 11:52:42 -07:00
|
|
|
#include "nsIFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2012-08-15 11:52:42 -07:00
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
#include "nsIWidgetListener.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-02 00:56:54 -08:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsView::nsView(nsViewManager* aViewManager, nsViewVisibility aVisibility)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsView);
|
|
|
|
|
|
|
|
mVis = aVisibility;
|
|
|
|
// Views should be transparent by default. Not being transparent is
|
|
|
|
// a promise that the view will paint all its pixels opaquely. Views
|
|
|
|
// should make this promise explicitly by calling
|
|
|
|
// SetViewContentTransparency.
|
|
|
|
mVFlags = 0;
|
|
|
|
mViewManager = aViewManager;
|
2012-07-30 07:20:58 -07:00
|
|
|
mDirtyRegion = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
mWidgetIsTopLevel = false;
|
2012-10-14 21:53:37 -07:00
|
|
|
mInAlternatePaint = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-13 06:13:16 -07:00
|
|
|
void nsView::DropMouseGrabbing()
|
|
|
|
{
|
2011-11-21 09:53:20 -08:00
|
|
|
nsIPresShell* presShell = mViewManager->GetPresShell();
|
|
|
|
if (presShell)
|
|
|
|
presShell->ClearMouseCaptureOnView(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsView::~nsView()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsView);
|
|
|
|
|
|
|
|
while (GetFirstChild())
|
|
|
|
{
|
|
|
|
nsView* child = GetFirstChild();
|
|
|
|
if (child->GetViewManager() == mViewManager) {
|
|
|
|
child->Destroy();
|
|
|
|
} else {
|
|
|
|
// just unhook it. Someone else will want to destroy this.
|
|
|
|
RemoveChild(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mViewManager)
|
|
|
|
{
|
|
|
|
DropMouseGrabbing();
|
|
|
|
|
2011-03-29 19:24:54 -07:00
|
|
|
nsView *rootView = mViewManager->GetRootViewImpl();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (rootView)
|
|
|
|
{
|
|
|
|
// Root views can have parents!
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
mViewManager->RemoveChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rootView == this)
|
|
|
|
{
|
|
|
|
// Inform the view manager that the root view has gone away...
|
2012-07-30 07:20:58 -07:00
|
|
|
mViewManager->SetRootView(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mParent)
|
|
|
|
{
|
|
|
|
mParent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mViewManager = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mParent)
|
|
|
|
{
|
|
|
|
mParent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy and release the widget
|
2011-03-21 11:28:10 -07:00
|
|
|
DestroyWidget();
|
|
|
|
|
|
|
|
delete mDirtyRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::DestroyWidget()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mWindow)
|
|
|
|
{
|
2010-06-24 19:01:06 -07:00
|
|
|
// If we are not attached to a base window, we're going to tear down our
|
|
|
|
// widget here. However, if we're attached to somebody elses widget, we
|
|
|
|
// want to leave the widget alone: don't reset the client data or call
|
|
|
|
// Destroy. Just clear our event view ptr and free our reference to it.
|
|
|
|
if (mWidgetIsTopLevel) {
|
2012-08-15 11:53:14 -07:00
|
|
|
mWindow->SetAttachedWidgetListener(nullptr);
|
2010-06-24 19:01:06 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-08-15 11:52:42 -07:00
|
|
|
mWindow->SetWidgetListener(nullptr);
|
2010-06-24 19:01:06 -07:00
|
|
|
mWindow->Destroy();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_RELEASE(mWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsView::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr == aInstancePtr) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!aIID.Equals(NS_GET_IID(nsISupports)),
|
|
|
|
"Someone expects views to be ISupports-derived!");
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
*aInstancePtr = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIView))) {
|
|
|
|
*aInstancePtr = (void*)(nsIView*)this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* nsIView::GetViewFor(nsIWidget* aWidget)
|
2012-08-15 11:53:14 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != aWidget, "null widget ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-15 11:53:14 -07:00
|
|
|
nsIWidgetListener* listener = aWidget->GetWidgetListener();
|
|
|
|
if (listener) {
|
|
|
|
nsIView* view = listener->GetView();
|
|
|
|
if (view)
|
|
|
|
return view;
|
2011-12-16 16:24:11 -08:00
|
|
|
}
|
2010-06-24 19:01:06 -07:00
|
|
|
|
2012-08-15 11:53:14 -07:00
|
|
|
listener = aWidget->GetAttachedWidgetListener();
|
|
|
|
return listener ? listener->GetView() : nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsIView::Destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::SetPosition(nscoord aX, nscoord aY)
|
|
|
|
{
|
|
|
|
mDimBounds.x += aX - mPosX;
|
|
|
|
mDimBounds.y += aY - mPosY;
|
|
|
|
mPosX = aX;
|
|
|
|
mPosY = aY;
|
|
|
|
|
|
|
|
NS_ASSERTION(GetParent() || (aX == 0 && aY == 0),
|
|
|
|
"Don't try to move the root widget to something non-zero");
|
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
ResetWidgetBounds(true, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
void nsView::ResetWidgetBounds(bool aRecurse, bool aForceSync)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mWindow) {
|
2011-12-23 19:52:23 -08:00
|
|
|
if (!aForceSync) {
|
|
|
|
// Don't change widget geometry synchronously, since that can
|
|
|
|
// cause synchronous painting.
|
2007-03-22 10:30:00 -07:00
|
|
|
mViewManager->PostPendingUpdate();
|
2011-12-23 19:52:23 -08:00
|
|
|
} else {
|
|
|
|
DoResetWidgetBounds(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-12-23 19:52:23 -08:00
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
if (aRecurse) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// reposition any widgets under this view
|
|
|
|
for (nsView* v = GetFirstChild(); v; v = v->GetNextSibling()) {
|
2011-12-23 19:52:23 -08:00
|
|
|
v->ResetWidgetBounds(true, aForceSync);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsIView::IsEffectivelyVisible()
|
2009-07-29 19:54:42 -07:00
|
|
|
{
|
2010-02-24 00:33:41 -08:00
|
|
|
for (nsIView* v = this; v; v = v->mParent) {
|
2009-07-29 19:54:42 -07:00
|
|
|
if (v->GetVisibility() == nsViewVisibility_kHide)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-07-29 19:54:42 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2009-07-29 19:54:42 -07:00
|
|
|
}
|
|
|
|
|
2010-02-24 00:33:41 -08:00
|
|
|
nsIntRect nsIView::CalcWidgetBounds(nsWindowType aType)
|
2007-05-25 20:45:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t p2a = mViewManager->AppUnitsPerDevPixel();
|
2007-05-25 20:45:00 -07:00
|
|
|
|
|
|
|
nsRect viewBounds(mDimBounds);
|
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
nsView* parent = GetParent()->Impl();
|
2010-07-18 19:23:47 -07:00
|
|
|
if (parent) {
|
2007-05-25 20:45:00 -07:00
|
|
|
nsPoint offset;
|
2010-07-18 19:23:47 -07:00
|
|
|
nsIWidget* parentWidget = parent->GetNearestWidget(&offset, p2a);
|
2010-04-22 17:21:54 -07:00
|
|
|
// make viewBounds be relative to the parent widget, in appunits
|
2007-05-25 20:45:00 -07:00
|
|
|
viewBounds += offset;
|
|
|
|
|
2007-05-31 16:23:32 -07:00
|
|
|
if (parentWidget && aType == eWindowType_popup &&
|
2009-07-29 19:54:42 -07:00
|
|
|
IsEffectivelyVisible()) {
|
2010-06-24 19:01:06 -07:00
|
|
|
// put offset into screen coordinates. (based on client area origin)
|
2009-02-18 16:11:49 -08:00
|
|
|
nsIntPoint screenPoint = parentWidget->WidgetToScreenOffset();
|
|
|
|
viewBounds += nsPoint(NSIntPixelsToAppUnits(screenPoint.x, p2a),
|
|
|
|
NSIntPixelsToAppUnits(screenPoint.y, p2a));
|
2007-05-25 20:45:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-22 17:21:54 -07:00
|
|
|
// Compute widget bounds in device pixels
|
2009-05-07 19:31:04 -07:00
|
|
|
nsIntRect newBounds = viewBounds.ToNearestPixels(p2a);
|
2007-05-25 20:45:00 -07:00
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
// Compute where the top-left of our widget ended up relative to the parent
|
|
|
|
// widget, in appunits.
|
2007-05-25 20:45:00 -07:00
|
|
|
nsPoint roundedOffset(NSIntPixelsToAppUnits(newBounds.x, p2a),
|
|
|
|
NSIntPixelsToAppUnits(newBounds.y, p2a));
|
2010-04-22 17:21:54 -07:00
|
|
|
|
|
|
|
// mViewToWidgetOffset is added to coordinates relative to the view origin
|
|
|
|
// to get coordinates relative to the widget.
|
|
|
|
// The view origin, relative to the parent widget, is at
|
|
|
|
// (mPosX,mPosY) - mDimBounds.TopLeft() + viewBounds.TopLeft().
|
|
|
|
// Our widget, relative to the parent widget, is roundedOffset.
|
|
|
|
mViewToWidgetOffset = nsPoint(mPosX, mPosY)
|
|
|
|
- mDimBounds.TopLeft() + viewBounds.TopLeft() - roundedOffset;
|
2007-05-25 20:45:00 -07:00
|
|
|
|
|
|
|
return newBounds;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsView::DoResetWidgetBounds(bool aMoveOnly,
|
|
|
|
bool aInvalidateChangedSize) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The geometry of a root view's widget is controlled externally,
|
|
|
|
// NOT by sizing or positioning the view
|
2011-03-29 19:24:54 -07:00
|
|
|
if (mViewManager->GetRootViewImpl() == this) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect curBounds;
|
2011-12-01 13:35:42 -08:00
|
|
|
mWindow->GetClientBounds(curBounds);
|
2010-06-24 19:01:06 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowType type;
|
|
|
|
mWindow->GetWindowType(type);
|
|
|
|
|
2012-09-19 20:12:36 -07:00
|
|
|
if (type == eWindowType_popup &&
|
|
|
|
((curBounds.IsEmpty() && mDimBounds.IsEmpty()) ||
|
|
|
|
mVis == nsViewVisibility_kHide)) {
|
|
|
|
// Don't manipulate empty or hidden popup widgets. For example there's no
|
|
|
|
// point moving hidden comboboxes around, or doing X server roundtrips
|
2007-03-22 10:30:00 -07:00
|
|
|
// to compute their true screen position. This could mean that WidgetToScreen
|
|
|
|
// operations on these widgets don't return up-to-date values, but popup
|
|
|
|
// positions aren't reliable anyway because of correction to be on or off-screen.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-26 22:56:22 -08:00
|
|
|
NS_PRECONDITION(mWindow, "Why was this called??");
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect newBounds = CalcWidgetBounds(type);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool changedPos = curBounds.TopLeft() != newBounds.TopLeft();
|
|
|
|
bool changedSize = curBounds.Size() != newBounds.Size();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-24 19:01:06 -07:00
|
|
|
// Child views are never attached to top level widgets, this is safe.
|
2012-12-06 09:31:34 -08:00
|
|
|
|
|
|
|
// Coordinates are converted to display pixels for window Move/Resize APIs,
|
|
|
|
// because of the potential for device-pixel coordinate spaces for mixed
|
|
|
|
// hidpi/lodpi screens to overlap each other and result in bad placement
|
|
|
|
// (bug 814434).
|
|
|
|
nsRefPtr<nsDeviceContext> dx;
|
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
|
|
|
|
double invScale = dx->UnscaledAppUnitsPerDevPixel() / 60.0;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (changedPos) {
|
|
|
|
if (changedSize && !aMoveOnly) {
|
2012-12-12 01:57:48 -08:00
|
|
|
mWindow->ResizeClient(newBounds.x * invScale,
|
|
|
|
newBounds.y * invScale,
|
|
|
|
newBounds.width * invScale,
|
|
|
|
newBounds.height * invScale,
|
2011-12-01 13:35:42 -08:00
|
|
|
aInvalidateChangedSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-12-12 01:57:48 -08:00
|
|
|
mWindow->MoveClient(newBounds.x * invScale,
|
|
|
|
newBounds.y * invScale);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (changedSize && !aMoveOnly) {
|
2012-12-12 01:57:48 -08:00
|
|
|
mWindow->ResizeClient(newBounds.width * invScale,
|
|
|
|
newBounds.height * invScale,
|
2011-12-01 13:35:42 -08:00
|
|
|
aInvalidateChangedSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
} // else do nothing!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsView::SetDimensions(const nsRect& aRect, bool aPaint, bool aResizeWidget)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsRect dims = aRect;
|
|
|
|
dims.MoveBy(mPosX, mPosY);
|
|
|
|
|
|
|
|
// Don't use nsRect's operator== here, since it returns true when
|
|
|
|
// both rects are empty even if they have different widths and we
|
|
|
|
// have cases where that sort of thing matters to us.
|
|
|
|
if (mDimBounds.TopLeft() == dims.TopLeft() &&
|
|
|
|
mDimBounds.Size() == dims.Size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDimBounds = dims;
|
|
|
|
|
|
|
|
if (aResizeWidget) {
|
2011-12-23 19:52:23 -08:00
|
|
|
ResetWidgetBounds(false, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void nsView::NotifyEffectiveVisibilityChanged(bool aEffectivelyVisible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-29 19:54:42 -07:00
|
|
|
if (!aEffectivelyVisible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
DropMouseGrabbing();
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != mWindow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-01-26 22:56:22 -08:00
|
|
|
if (aEffectivelyVisible)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
DoResetWidgetBounds(false, true);
|
|
|
|
mWindow->Show(true);
|
2011-01-26 22:56:22 -08:00
|
|
|
}
|
|
|
|
else
|
2011-10-17 07:59:28 -07:00
|
|
|
mWindow->Show(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-29 19:54:42 -07:00
|
|
|
for (nsView* child = mFirstChild; child; child = child->mNextSibling) {
|
|
|
|
if (child->mVis == nsViewVisibility_kHide) {
|
|
|
|
// It was effectively hidden and still is
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Our child is visible if we are
|
|
|
|
child->NotifyEffectiveVisibilityChanged(aEffectivelyVisible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsView::SetVisibility(nsViewVisibility aVisibility)
|
|
|
|
{
|
|
|
|
mVis = aVisibility;
|
|
|
|
NotifyEffectiveVisibilityChanged(IsEffectivelyVisible());
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsView::SetFloating(bool aFloatingView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aFloatingView)
|
|
|
|
mVFlags |= NS_VIEW_FLAG_FLOATING;
|
|
|
|
else
|
|
|
|
mVFlags &= ~NS_VIEW_FLAG_FLOATING;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// recursively make all sub-views "floating" grr.
|
|
|
|
for (nsView* child = mFirstChild; chlid; child = child->GetNextSibling()) {
|
|
|
|
child->SetFloating(aFloatingView);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::InvalidateHierarchy(nsViewManager *aViewManagerParent)
|
|
|
|
{
|
2011-03-29 19:24:54 -07:00
|
|
|
if (mViewManager->GetRootViewImpl() == this)
|
2007-03-22 10:30:00 -07:00
|
|
|
mViewManager->InvalidateHierarchy();
|
|
|
|
|
|
|
|
for (nsView *child = mFirstChild; child; child = child->GetNextSibling())
|
|
|
|
child->InvalidateHierarchy(aViewManagerParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::InsertChild(nsView *aChild, nsView *aSibling)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != aChild, "null ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != aChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != aSibling)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(aSibling->GetParent() == this, "tried to insert view with invalid sibling");
|
|
|
|
#endif
|
|
|
|
//insert after sibling
|
|
|
|
aChild->SetNextSibling(aSibling->GetNextSibling());
|
|
|
|
aSibling->SetNextSibling(aChild);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aChild->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = aChild;
|
|
|
|
}
|
|
|
|
aChild->SetParent(this);
|
|
|
|
|
|
|
|
// If we just inserted a root view, then update the RootViewManager
|
|
|
|
// on all view managers in the new subtree.
|
|
|
|
|
|
|
|
nsViewManager *vm = aChild->GetViewManager();
|
2011-03-29 19:24:54 -07:00
|
|
|
if (vm->GetRootViewImpl() == aChild)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
aChild->InvalidateHierarchy(nullptr); // don't care about releasing grabs
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::RemoveChild(nsView *child)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != child, "null ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != child)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
nsView* prevKid = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsView* kid = mFirstChild;
|
2012-12-02 00:56:54 -08:00
|
|
|
DebugOnly<bool> found = false;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != kid) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (kid == child) {
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != prevKid) {
|
2007-03-22 10:30:00 -07:00
|
|
|
prevKid->SetNextSibling(kid->GetNextSibling());
|
|
|
|
} else {
|
|
|
|
mFirstChild = kid->GetNextSibling();
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
child->SetParent(nullptr);
|
2011-10-17 07:59:28 -07:00
|
|
|
found = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevKid = kid;
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
NS_ASSERTION(found, "tried to remove non child");
|
|
|
|
|
|
|
|
// If we just removed a root view, then update the RootViewManager
|
|
|
|
// on all view managers in the removed subtree.
|
|
|
|
|
|
|
|
nsViewManager *vm = child->GetViewManager();
|
2011-03-29 19:24:54 -07:00
|
|
|
if (vm->GetRootViewImpl() == child)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
child->InvalidateHierarchy(GetViewManager());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Native widgets ultimately just can't deal with the awesome power of
|
|
|
|
// CSS2 z-index. However, we set the z-index on the widget anyway
|
|
|
|
// because in many simple common cases the widgets do end up in the
|
|
|
|
// right order. We set each widget's z-index to the z-index of the
|
|
|
|
// nearest ancestor that has non-auto z-index.
|
2012-08-22 08:56:38 -07:00
|
|
|
static void UpdateNativeWidgetZIndexes(nsView* aView, int32_t aZIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aView->HasWidget()) {
|
|
|
|
nsIWidget* widget = aView->GetWidget();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t curZ;
|
2007-03-22 10:30:00 -07:00
|
|
|
widget->GetZIndex(&curZ);
|
|
|
|
if (curZ != aZIndex) {
|
|
|
|
widget->SetZIndex(aZIndex);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (nsView* v = aView->GetFirstChild(); v; v = v->GetNextSibling()) {
|
|
|
|
if (v->GetZIndexIsAuto()) {
|
|
|
|
UpdateNativeWidgetZIndexes(v, aZIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t FindNonAutoZIndex(nsView* aView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
while (aView) {
|
|
|
|
if (!aView->GetZIndexIsAuto()) {
|
|
|
|
return aView->GetZIndex();
|
|
|
|
}
|
|
|
|
aView = aView->GetParent();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsIView::CreateWidget(nsWidgetInitData *aWidgetInitData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aEnableDragDrop,
|
|
|
|
bool aResetVisibility)
|
2010-08-20 12:29:01 -07:00
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
return Impl()->CreateWidget(aWidgetInitData,
|
2010-09-20 06:40:13 -07:00
|
|
|
aEnableDragDrop, aResetVisibility);
|
2010-08-20 12:29:02 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsIView::CreateWidgetForParent(nsIWidget* aParentWidget,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsWidgetInitData *aWidgetInitData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aEnableDragDrop,
|
|
|
|
bool aResetVisibility)
|
2010-08-20 12:29:02 -07:00
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
return Impl()->CreateWidgetForParent(aParentWidget, aWidgetInitData,
|
2010-09-20 06:40:13 -07:00
|
|
|
aEnableDragDrop, aResetVisibility);
|
2010-08-20 12:29:02 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsIView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsIWidget* aParentWidget,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aEnableDragDrop,
|
|
|
|
bool aResetVisibility)
|
2010-08-20 12:29:02 -07:00
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
return Impl()->CreateWidgetForPopup(aWidgetInitData, aParentWidget,
|
2010-09-20 06:40:13 -07:00
|
|
|
aEnableDragDrop, aResetVisibility);
|
2010-08-20 12:29:01 -07:00
|
|
|
}
|
|
|
|
|
2011-03-21 11:28:10 -07:00
|
|
|
void nsIView::DestroyWidget()
|
|
|
|
{
|
|
|
|
Impl()->DestroyWidget();
|
|
|
|
}
|
|
|
|
|
2010-08-23 23:28:16 -07:00
|
|
|
struct DefaultWidgetInitData : public nsWidgetInitData {
|
|
|
|
DefaultWidgetInitData() : nsWidgetInitData()
|
|
|
|
{
|
|
|
|
mWindowType = eWindowType_child;
|
2011-10-17 07:59:28 -07:00
|
|
|
clipChildren = true;
|
|
|
|
clipSiblings = true;
|
2010-08-23 23:28:16 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsView::CreateWidget(nsWidgetInitData *aWidgetInitData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aEnableDragDrop,
|
|
|
|
bool aResetVisibility)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
AssertNoWindow();
|
2010-08-20 12:29:02 -07:00
|
|
|
NS_ABORT_IF_FALSE(!aWidgetInitData ||
|
|
|
|
aWidgetInitData->mWindowType != eWindowType_popup,
|
|
|
|
"Use CreateWidgetForPopup");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-23 23:28:16 -07:00
|
|
|
DefaultWidgetInitData defaultInitData;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool initDataPassedIn = !!aWidgetInitData;
|
2010-08-23 23:28:16 -07:00
|
|
|
aWidgetInitData = aWidgetInitData ? aWidgetInitData : &defaultInitData;
|
2010-08-24 00:48:46 -07:00
|
|
|
defaultInitData.mListenForResizes =
|
|
|
|
(!initDataPassedIn && GetParent() &&
|
|
|
|
GetParent()->GetViewManager() != mViewManager);
|
2010-08-20 12:29:01 -07:00
|
|
|
|
|
|
|
nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nsRefPtr<nsDeviceContext> dx;
|
2010-08-20 12:29:01 -07:00
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsIWidget* parentWidget =
|
2012-07-30 07:20:58 -07:00
|
|
|
GetParent() ? GetParent()->GetNearestWidget(nullptr) : nullptr;
|
2010-08-20 12:29:02 -07:00
|
|
|
if (!parentWidget) {
|
|
|
|
NS_ERROR("nsView::CreateWidget without suitable parent widget??");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-08-20 12:29:02 -07:00
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
// XXX: using aForceUseIWidgetParent=true to preserve previous
|
|
|
|
// semantics. It's not clear that it's actually needed.
|
2012-08-15 11:53:09 -07:00
|
|
|
mWindow = parentWidget->CreateChild(trect, dx, aWidgetInitData,
|
2011-10-17 07:59:28 -07:00
|
|
|
true).get();
|
2010-08-20 12:29:02 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
InitializeWindow(aEnableDragDrop, aResetVisibility);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsView::CreateWidgetForParent(nsIWidget* aParentWidget,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsWidgetInitData *aWidgetInitData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aEnableDragDrop,
|
|
|
|
bool aResetVisibility)
|
2010-08-20 12:29:02 -07:00
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
AssertNoWindow();
|
2010-08-20 12:29:02 -07:00
|
|
|
NS_ABORT_IF_FALSE(!aWidgetInitData ||
|
|
|
|
aWidgetInitData->mWindowType != eWindowType_popup,
|
|
|
|
"Use CreateWidgetForPopup");
|
|
|
|
NS_ABORT_IF_FALSE(aParentWidget, "Parent widget required");
|
|
|
|
|
2010-08-23 23:28:16 -07:00
|
|
|
DefaultWidgetInitData defaultInitData;
|
|
|
|
aWidgetInitData = aWidgetInitData ? aWidgetInitData : &defaultInitData;
|
|
|
|
|
|
|
|
nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
2010-08-20 12:29:02 -07:00
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nsRefPtr<nsDeviceContext> dx;
|
2010-08-20 12:29:02 -07:00
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
mWindow =
|
2012-08-15 11:53:09 -07:00
|
|
|
aParentWidget->CreateChild(trect, dx, aWidgetInitData).get();
|
2010-08-20 12:29:02 -07:00
|
|
|
if (!mWindow) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-08-20 12:29:02 -07:00
|
|
|
|
|
|
|
InitializeWindow(aEnableDragDrop, aResetVisibility);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsIWidget* aParentWidget,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aEnableDragDrop,
|
|
|
|
bool aResetVisibility)
|
2010-08-20 12:29:02 -07:00
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
AssertNoWindow();
|
2010-08-20 12:29:02 -07:00
|
|
|
NS_ABORT_IF_FALSE(aWidgetInitData, "Widget init data required");
|
|
|
|
NS_ABORT_IF_FALSE(aWidgetInitData->mWindowType == eWindowType_popup,
|
|
|
|
"Use one of the other CreateWidget methods");
|
|
|
|
|
|
|
|
nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nsRefPtr<nsDeviceContext> dx;
|
2010-08-20 12:29:02 -07:00
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
|
|
|
|
|
|
|
|
// XXX/cjones: having these two separate creation cases seems ... um
|
|
|
|
// ... unnecessary, but it's the way the old code did it. Please
|
|
|
|
// unify them by first finding a suitable parent nsIWidget, then
|
2010-08-20 12:29:02 -07:00
|
|
|
// getting rid of aForceUseIWidgetParent.
|
2010-08-20 12:29:02 -07:00
|
|
|
if (aParentWidget) {
|
2010-08-20 12:29:02 -07:00
|
|
|
// XXX: using aForceUseIWidgetParent=true to preserve previous
|
|
|
|
// semantics. It's not clear that it's actually needed.
|
2012-08-15 11:53:09 -07:00
|
|
|
mWindow = aParentWidget->CreateChild(trect, dx, aWidgetInitData,
|
2011-10-17 07:59:28 -07:00
|
|
|
true).get();
|
2010-08-20 12:29:01 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIWidget* nearestParent = GetParent() ? GetParent()->GetNearestWidget(nullptr)
|
|
|
|
: nullptr;
|
2010-08-20 12:29:02 -07:00
|
|
|
if (!nearestParent) {
|
|
|
|
// Without a parent, we can't make a popup. This can happen
|
|
|
|
// when printing
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
mWindow =
|
2012-08-15 11:53:09 -07:00
|
|
|
nearestParent->CreateChild(trect, dx, aWidgetInitData).get();
|
2010-08-20 12:29:02 -07:00
|
|
|
}
|
|
|
|
if (!mWindow) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-08-20 12:29:01 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
InitializeWindow(aEnableDragDrop, aResetVisibility);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsView::InitializeWindow(bool aEnableDragDrop, bool aResetVisibility)
|
2010-08-20 12:29:01 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mWindow, "Must have a window to initialize");
|
|
|
|
|
2012-08-15 11:53:14 -07:00
|
|
|
mWindow->SetWidgetListener(this);
|
2010-08-20 12:29:02 -07:00
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
if (aEnableDragDrop) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mWindow->EnableDragDrop(true);
|
2010-08-20 12:29:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// propagate the z-index to the widget.
|
|
|
|
UpdateNativeWidgetZIndexes(this, FindNonAutoZIndex(this));
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//make sure visibility state is accurate
|
2007-05-25 20:45:00 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aResetVisibility) {
|
2010-08-20 12:29:01 -07:00
|
|
|
SetVisibility(GetVisibility());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:01:06 -07:00
|
|
|
// Attach to a top level widget and start receiving mirrored events.
|
|
|
|
nsresult nsIView::AttachToTopLevelWidget(nsIWidget* aWidget)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(nullptr != aWidget, "null widget ptr");
|
2010-06-24 19:01:06 -07:00
|
|
|
/// XXXjimm This is a temporary workaround to an issue w/document
|
|
|
|
// viewer (bug 513162).
|
2012-08-15 11:53:14 -07:00
|
|
|
nsIWidgetListener* listener = aWidget->GetAttachedWidgetListener();
|
|
|
|
if (listener) {
|
|
|
|
nsIView *oldView = listener->GetView();
|
|
|
|
if (oldView) {
|
|
|
|
oldView->DetachFromTopLevelWidget();
|
|
|
|
}
|
2010-06-24 19:01:06 -07:00
|
|
|
}
|
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
nsRefPtr<nsDeviceContext> dx;
|
2010-06-24 19:01:06 -07:00
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
|
|
|
|
|
|
|
|
// Note, the previous device context will be released. Detaching
|
|
|
|
// will not restore the old one.
|
2012-08-15 11:53:09 -07:00
|
|
|
nsresult rv = aWidget->AttachViewToTopLevel(!nsIWidget::UsePuppetWidgets(), dx);
|
2010-06-24 19:01:06 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mWindow = aWidget;
|
|
|
|
NS_ADDREF(mWindow);
|
|
|
|
|
2012-08-15 11:53:14 -07:00
|
|
|
mWindow->SetAttachedWidgetListener(Impl());
|
2011-10-17 07:59:28 -07:00
|
|
|
mWindow->EnableDragDrop(true);
|
|
|
|
mWidgetIsTopLevel = true;
|
2010-06-24 19:01:06 -07:00
|
|
|
|
|
|
|
// Refresh the view bounds
|
|
|
|
nsWindowType type;
|
|
|
|
mWindow->GetWindowType(type);
|
|
|
|
CalcWidgetBounds(type);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Detach this view from an attached widget.
|
|
|
|
nsresult nsIView::DetachFromTopLevelWidget()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mWidgetIsTopLevel, "Not attached currently!");
|
|
|
|
NS_PRECONDITION(mWindow, "null mWindow for DetachFromTopLevelWidget!");
|
|
|
|
|
2012-08-15 11:53:14 -07:00
|
|
|
mWindow->SetAttachedWidgetListener(nullptr);
|
2010-06-24 19:01:06 -07:00
|
|
|
NS_RELEASE(mWindow);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mWidgetIsTopLevel = false;
|
2010-06-24 19:01:06 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void nsView::SetZIndex(bool aAuto, int32_t aZIndex, bool aTopMost)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool oldIsAuto = GetZIndexIsAuto();
|
2007-03-22 10:30:00 -07:00
|
|
|
mVFlags = (mVFlags & ~NS_VIEW_FLAG_AUTO_ZINDEX) | (aAuto ? NS_VIEW_FLAG_AUTO_ZINDEX : 0);
|
|
|
|
mZIndex = aZIndex;
|
|
|
|
SetTopMost(aTopMost);
|
|
|
|
|
|
|
|
if (HasWidget() || !oldIsAuto || !aAuto) {
|
|
|
|
UpdateNativeWidgetZIndexes(this, FindNonAutoZIndex(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
void nsView::AssertNoWindow()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
// XXX: it would be nice to make this a strong assert
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(mWindow)) {
|
2010-08-20 12:29:02 -07:00
|
|
|
NS_ERROR("We already have a window for this view? BAD");
|
2012-08-15 11:52:42 -07:00
|
|
|
mWindow->SetWidgetListener(nullptr);
|
2010-08-20 12:29:02 -07:00
|
|
|
mWindow->Destroy();
|
|
|
|
NS_RELEASE(mWindow);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
//
|
|
|
|
// internal window creation functions
|
|
|
|
//
|
2012-08-15 11:53:09 -07:00
|
|
|
void nsIView::AttachWidgetEventHandler(nsIWidget* aWidget)
|
2009-07-21 17:45:00 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2012-08-15 11:52:42 -07:00
|
|
|
NS_ASSERTION(!aWidget->GetWidgetListener(), "Already have a widget listener");
|
2009-07-21 17:45:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-08-15 11:53:14 -07:00
|
|
|
aWidget->SetWidgetListener(Impl());
|
2009-07-21 17:45:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsIView::DetachWidgetEventHandler(nsIWidget* aWidget)
|
|
|
|
{
|
2012-08-15 11:53:14 -07:00
|
|
|
NS_ASSERTION(!aWidget->GetWidgetListener() ||
|
|
|
|
aWidget->GetWidgetListener()->GetView() == this, "Wrong view");
|
2012-08-15 11:52:42 -07:00
|
|
|
aWidget->SetWidgetListener(nullptr);
|
2009-07-21 17:45:00 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
void nsIView::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
|
|
|
fprintf(out, "%p ", (void*)this);
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != mWindow) {
|
2010-07-18 19:23:47 -07:00
|
|
|
nscoord p2a = mViewManager->AppUnitsPerDevPixel();
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect rect;
|
|
|
|
mWindow->GetClientBounds(rect);
|
2009-05-07 19:31:04 -07:00
|
|
|
nsRect windowBounds = rect.ToAppUnits(p2a);
|
2009-01-14 19:27:09 -08:00
|
|
|
mWindow->GetBounds(rect);
|
2009-05-07 19:31:04 -07:00
|
|
|
nsRect nonclientBounds = rect.ToAppUnits(p2a);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsrefcnt widgetRefCnt = mWindow->AddRef() - 1;
|
|
|
|
mWindow->Release();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t Z;
|
2007-03-22 10:30:00 -07:00
|
|
|
mWindow->GetZIndex(&Z);
|
|
|
|
fprintf(out, "(widget=%p[%d] z=%d pos={%d,%d,%d,%d}) ",
|
|
|
|
(void*)mWindow, widgetRefCnt, Z,
|
|
|
|
nonclientBounds.x, nonclientBounds.y,
|
|
|
|
windowBounds.width, windowBounds.height);
|
|
|
|
}
|
|
|
|
nsRect brect = GetBounds();
|
|
|
|
fprintf(out, "{%d,%d,%d,%d}",
|
|
|
|
brect.x, brect.y, brect.width, brect.height);
|
2011-11-21 09:53:20 -08:00
|
|
|
fprintf(out, " z=%d vis=%d frame=%p <\n",
|
2012-03-30 13:36:43 -07:00
|
|
|
mZIndex, mVis, static_cast<void*>(mFrame));
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsView* kid = mFirstChild; kid; kid = kid->GetNextSibling()) {
|
|
|
|
NS_ASSERTION(kid->GetParent() == this, "incorrect parent");
|
|
|
|
kid->List(out, aIndent + 1);
|
|
|
|
}
|
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
nsPoint nsIView::GetOffsetTo(const nsIView* aOther) const
|
|
|
|
{
|
2010-08-20 12:29:01 -07:00
|
|
|
return Impl()->GetOffsetTo(static_cast<const nsView*>(aOther),
|
|
|
|
Impl()->GetViewManager()->AppUnitsPerDevPixel());
|
2010-07-18 19:23:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint nsView::GetOffsetTo(const nsView* aOther) const
|
|
|
|
{
|
|
|
|
return GetOffsetTo(aOther, GetViewManager()->AppUnitsPerDevPixel());
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsPoint nsView::GetOffsetTo(const nsView* aOther, const int32_t aAPD) const
|
2010-07-18 19:23:47 -07:00
|
|
|
{
|
2010-10-21 20:37:49 -07:00
|
|
|
NS_ABORT_IF_FALSE(GetParent() || !aOther || aOther->GetParent() ||
|
|
|
|
this == aOther, "caller of (outer) GetOffsetTo must not "
|
|
|
|
"pass unrelated views");
|
2010-07-18 19:23:47 -07:00
|
|
|
// We accumulate the final result in offset
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPoint offset(0, 0);
|
2010-07-18 19:23:47 -07:00
|
|
|
// The offset currently accumulated at the current APD
|
|
|
|
nsPoint docOffset(0, 0);
|
|
|
|
const nsView* v = this;
|
|
|
|
nsViewManager* currVM = v->GetViewManager();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t currAPD = currVM->AppUnitsPerDevPixel();
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsView* root = nullptr;
|
2010-07-18 19:23:47 -07:00
|
|
|
for ( ; v != aOther && v; root = v, v = v->GetParent()) {
|
|
|
|
nsViewManager* newVM = v->GetViewManager();
|
|
|
|
if (newVM != currVM) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t newAPD = newVM->AppUnitsPerDevPixel();
|
2010-07-18 19:23:47 -07:00
|
|
|
if (newAPD != currAPD) {
|
|
|
|
offset += docOffset.ConvertAppUnits(currAPD, aAPD);
|
|
|
|
docOffset.x = docOffset.y = 0;
|
|
|
|
currAPD = newAPD;
|
|
|
|
}
|
|
|
|
currVM = newVM;
|
|
|
|
}
|
|
|
|
docOffset += v->GetPosition();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-07-18 19:23:47 -07:00
|
|
|
offset += docOffset.ConvertAppUnits(currAPD, aAPD);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (v != aOther) {
|
|
|
|
// Looks like aOther wasn't an ancestor of |this|. So now we have
|
2010-07-18 19:23:47 -07:00
|
|
|
// the root-VM-relative position of |this| in |offset|. Get the
|
|
|
|
// root-VM-relative position of aOther and subtract it.
|
|
|
|
nsPoint negOffset = aOther->GetOffsetTo(root, aAPD);
|
|
|
|
offset -= negOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
nsPoint nsIView::GetOffsetToWidget(nsIWidget* aWidget) const
|
|
|
|
{
|
|
|
|
nsPoint pt;
|
|
|
|
// Get the view for widget
|
2010-08-20 12:29:01 -07:00
|
|
|
nsIView* widgetIView = GetViewFor(aWidget);
|
|
|
|
if (!widgetIView) {
|
2010-07-18 19:23:47 -07:00
|
|
|
return pt;
|
|
|
|
}
|
2010-08-20 12:29:01 -07:00
|
|
|
nsView* widgetView = widgetIView->Impl();
|
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
// Get the offset to the widget view in the widget view's APD
|
|
|
|
// We get the offset in the widget view's APD first and then convert to our
|
|
|
|
// APD afterwards so that we can include the widget view's ViewToWidgetOffset
|
|
|
|
// in the sum in its native APD, and then convert the whole thing to our APD
|
|
|
|
// so that we don't have to convert the APD of the relatively small
|
|
|
|
// ViewToWidgetOffset by itself with a potentially large relative rounding
|
|
|
|
// error.
|
|
|
|
pt = -widgetView->GetOffsetTo(static_cast<const nsView*>(this));
|
|
|
|
// Add in the offset to the widget.
|
|
|
|
pt += widgetView->ViewToWidgetOffset();
|
|
|
|
|
|
|
|
// Convert to our appunits.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t widgetAPD = widgetView->GetViewManager()->AppUnitsPerDevPixel();
|
|
|
|
int32_t ourAPD = static_cast<const nsView*>(this)->
|
2010-07-18 19:23:47 -07:00
|
|
|
GetViewManager()->AppUnitsPerDevPixel();
|
|
|
|
pt = pt.ConvertAppUnits(widgetAPD, ourAPD);
|
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIWidget* nsIView::GetNearestWidget(nsPoint* aOffset) const
|
2010-07-18 19:23:47 -07:00
|
|
|
{
|
2010-08-20 12:29:01 -07:00
|
|
|
return Impl()->GetNearestWidget(aOffset,
|
|
|
|
Impl()->GetViewManager()->AppUnitsPerDevPixel());
|
2010-07-18 19:23:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset) const
|
|
|
|
{
|
|
|
|
return GetNearestWidget(aOffset, GetViewManager()->AppUnitsPerDevPixel());
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset, const int32_t aAPD) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-24 19:01:06 -07:00
|
|
|
// aOffset is based on the view's position, which ignores any chrome on
|
|
|
|
// attached parent widgets.
|
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
// We accumulate the final result in pt
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPoint pt(0, 0);
|
2010-07-18 19:23:47 -07:00
|
|
|
// The offset currently accumulated at the current APD
|
|
|
|
nsPoint docPt(0,0);
|
|
|
|
const nsView* v = this;
|
|
|
|
nsViewManager* currVM = v->GetViewManager();
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t currAPD = currVM->AppUnitsPerDevPixel();
|
2010-07-18 19:23:47 -07:00
|
|
|
for ( ; v && !v->HasWidget(); v = v->GetParent()) {
|
|
|
|
nsViewManager* newVM = v->GetViewManager();
|
|
|
|
if (newVM != currVM) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t newAPD = newVM->AppUnitsPerDevPixel();
|
2010-07-18 19:23:47 -07:00
|
|
|
if (newAPD != currAPD) {
|
|
|
|
pt += docPt.ConvertAppUnits(currAPD, aAPD);
|
|
|
|
docPt.x = docPt.y = 0;
|
|
|
|
currAPD = newAPD;
|
|
|
|
}
|
|
|
|
currVM = newVM;
|
|
|
|
}
|
|
|
|
docPt += v->GetPosition();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (!v) {
|
|
|
|
if (aOffset) {
|
2010-07-18 19:23:47 -07:00
|
|
|
pt += docPt.ConvertAppUnits(currAPD, aAPD);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aOffset = pt;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
// pt is now the offset from v's origin to this view's origin.
|
|
|
|
// We add the ViewToWidgetOffset to get the offset to the widget.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aOffset) {
|
2010-07-18 19:23:47 -07:00
|
|
|
docPt += v->ViewToWidgetOffset();
|
|
|
|
pt += docPt.ConvertAppUnits(currAPD, aAPD);
|
|
|
|
*aOffset = pt;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return v->GetWidget();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsIView::IsRoot() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(mViewManager != nullptr," View manager is null in nsView::IsRoot()");
|
2011-03-29 19:24:54 -07:00
|
|
|
return mViewManager->GetRootViewImpl() == this;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsIView::ExternalIsRoot() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return nsIView::IsRoot();
|
|
|
|
}
|
2007-11-22 07:08:13 -08:00
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
nsView*
|
|
|
|
nsIView::Impl()
|
|
|
|
{
|
|
|
|
return static_cast<nsView*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsView*
|
|
|
|
nsIView::Impl() const
|
|
|
|
{
|
|
|
|
return static_cast<const nsView*>(this);
|
|
|
|
}
|
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
nsRect
|
|
|
|
nsView::GetBoundsInParentUnits() const
|
|
|
|
{
|
|
|
|
nsView* parent = GetParent();
|
|
|
|
nsViewManager* VM = GetViewManager();
|
2011-03-29 19:24:54 -07:00
|
|
|
if (this != VM->GetRootViewImpl() || !parent) {
|
2010-07-18 19:23:47 -07:00
|
|
|
return mDimBounds;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t ourAPD = VM->AppUnitsPerDevPixel();
|
|
|
|
int32_t parentAPD = parent->GetViewManager()->AppUnitsPerDevPixel();
|
2010-07-18 19:23:47 -07:00
|
|
|
return mDimBounds.ConvertAppUnitsRoundOut(ourAPD, parentAPD);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
2011-05-11 08:49:16 -07:00
|
|
|
nsIView::ConvertFromParentCoords(nsPoint aPt) const
|
2010-07-18 19:23:47 -07:00
|
|
|
{
|
2011-05-11 08:49:16 -07:00
|
|
|
const nsView* view = static_cast<const nsView*>(this);
|
|
|
|
const nsView* parent = view->GetParent();
|
2010-07-18 19:23:47 -07:00
|
|
|
if (parent) {
|
|
|
|
aPt = aPt.ConvertAppUnits(parent->GetViewManager()->AppUnitsPerDevPixel(),
|
2011-05-11 08:49:16 -07:00
|
|
|
view->GetViewManager()->AppUnitsPerDevPixel());
|
2010-07-18 19:23:47 -07:00
|
|
|
}
|
|
|
|
aPt -= GetPosition();
|
|
|
|
return aPt;
|
|
|
|
}
|
2012-08-15 11:53:14 -07:00
|
|
|
|
|
|
|
static bool
|
|
|
|
IsPopupWidget(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
nsWindowType type;
|
|
|
|
aWidget->GetWindowType(type);
|
|
|
|
return (type == eWindowType_popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell*
|
|
|
|
nsView::GetPresShell()
|
|
|
|
{
|
|
|
|
return GetViewManager()->GetPresShell();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsView::WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y)
|
2012-08-15 11:53:14 -07:00
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm && IsPopupWidget(aWidget)) {
|
|
|
|
pm->PopupMoved(mFrame, nsIntPoint(x, y));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight)
|
2012-08-15 11:53:14 -07:00
|
|
|
{
|
|
|
|
// The root view may not be set if this is the resize associated with
|
|
|
|
// window creation
|
2012-08-20 19:40:45 -07:00
|
|
|
SetForcedRepaint(true);
|
2012-08-15 11:53:14 -07:00
|
|
|
if (this == mViewManager->GetRootView()) {
|
|
|
|
nsRefPtr<nsDeviceContext> devContext;
|
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(devContext));
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t p2a = devContext->AppUnitsPerDevPixel();
|
2012-08-15 11:53:14 -07:00
|
|
|
mViewManager->SetWindowDimensions(NSIntPixelsToAppUnits(aWidth, p2a),
|
|
|
|
NSIntPixelsToAppUnits(aHeight, p2a));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (IsPopupWidget(aWidget)) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
pm->PopupResized(mFrame, nsIntSize(aWidth, aHeight));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsView::RequestWindowClose(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
if (mFrame && IsPopupWidget(aWidget) &&
|
|
|
|
mFrame->GetType() == nsGkAtoms::menuPopupFrame) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
pm->HidePopup(mFrame->GetContent(), false, true, false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsView::WillPaintWindow(nsIWidget* aWidget, bool aWillSendDidPaint)
|
|
|
|
{
|
2012-10-22 06:53:31 -07:00
|
|
|
nsCOMPtr<nsViewManager> vm = mViewManager;
|
|
|
|
vm->WillPaintWindow(aWidget, aWillSendDidPaint);
|
2012-08-15 11:53:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-10-14 21:53:37 -07:00
|
|
|
nsView::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion, uint32_t aFlags)
|
2012-08-15 11:53:14 -07:00
|
|
|
{
|
2012-12-12 13:57:08 -08:00
|
|
|
NS_ASSERTION(this == nsView::GetViewFor(aWidget), "wrong view for widget?");
|
|
|
|
|
2012-10-14 21:53:37 -07:00
|
|
|
mInAlternatePaint = aFlags & PAINT_IS_ALTERNATE;
|
2012-08-15 11:53:14 -07:00
|
|
|
nsCOMPtr<nsViewManager> vm = mViewManager;
|
2012-10-14 21:53:37 -07:00
|
|
|
bool result = vm->PaintWindow(aWidget, aRegion, aFlags);
|
2012-12-12 13:57:08 -08:00
|
|
|
// PaintWindow can destroy this via WillPaintWindow notification, so we have
|
|
|
|
// to re-get the view from the widget.
|
|
|
|
nsView* view = nsView::GetViewFor(aWidget);
|
|
|
|
if (view) {
|
|
|
|
view->mInAlternatePaint = false;
|
|
|
|
}
|
2012-10-14 21:53:37 -07:00
|
|
|
return result;
|
2012-08-15 11:53:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsView::DidPaintWindow()
|
|
|
|
{
|
2012-10-22 06:53:31 -07:00
|
|
|
nsCOMPtr<nsViewManager> vm = mViewManager;
|
|
|
|
vm->DidPaintWindow();
|
2012-08-15 11:53:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
nsView::HandleEvent(nsGUIEvent* aEvent, bool aUseAttachedEvents)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nullptr != aEvent->widget, "null widget ptr");
|
|
|
|
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
nsIView* view;
|
|
|
|
if (aUseAttachedEvents) {
|
|
|
|
nsIWidgetListener* listener = aEvent->widget->GetAttachedWidgetListener();
|
|
|
|
view = listener ? listener->GetView() : nullptr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
view = GetViewFor(aEvent->widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view) {
|
|
|
|
nsCOMPtr<nsIViewManager> vm = view->GetViewManager();
|
|
|
|
vm->DispatchEvent(aEvent, view, &result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|