2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsIRegion.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
|
|
|
|
|
|
|
//mmptemp
|
|
|
|
|
2008-10-10 08:04:34 -07:00
|
|
|
static nsEventStatus HandleEvent(nsGUIEvent *aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
//#define SHOW_VIEW_BORDERS
|
|
|
|
|
|
|
|
#define VIEW_WRAPPER_IID \
|
2010-01-11 13:45:19 -08:00
|
|
|
{ 0xbf4e1841, 0xe9ec, 0x47f2, \
|
|
|
|
{ 0xb4, 0x77, 0x0f, 0xf6, 0x0f, 0x5a, 0xac, 0xbd } }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* nsISupports-derived helper class that allows to store and get a view
|
|
|
|
*/
|
|
|
|
class ViewWrapper : public nsIInterfaceRequestor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(VIEW_WRAPPER_IID)
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
|
|
|
|
ViewWrapper(nsView* aView) : mView(aView) {}
|
|
|
|
|
|
|
|
nsView* GetView() { return mView; }
|
|
|
|
private:
|
|
|
|
nsView* mView;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(ViewWrapper, VIEW_WRAPPER_IID)
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(ViewWrapper)
|
|
|
|
NS_IMPL_RELEASE(ViewWrapper)
|
|
|
|
#ifndef DEBUG
|
|
|
|
NS_IMPL_QUERY_INTERFACE2(ViewWrapper, ViewWrapper, nsIInterfaceRequestor)
|
|
|
|
|
|
|
|
#else
|
|
|
|
NS_IMETHODIMP ViewWrapper::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
|
|
|
|
2010-01-11 13:45:19 -08:00
|
|
|
NS_ASSERTION(!aIID.Equals(NS_GET_IID(nsIView)),
|
2007-03-22 10:30:00 -07:00
|
|
|
"Someone expects a viewwrapper to be a view!");
|
|
|
|
|
|
|
|
*aInstancePtr = nsnull;
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
2007-07-08 00:08:04 -07:00
|
|
|
*aInstancePtr = static_cast<nsISupports*>(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(ViewWrapper))) {
|
|
|
|
*aInstancePtr = this;
|
|
|
|
}
|
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIInterfaceRequestor))) {
|
|
|
|
*aInstancePtr = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (*aInstancePtr) {
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP ViewWrapper::GetInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIView))) {
|
|
|
|
*aInstancePtr = mView;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a widget, returns the stored ViewWrapper on it, or NULL if no
|
|
|
|
* ViewWrapper is there.
|
|
|
|
*/
|
|
|
|
static ViewWrapper* GetWrapperFor(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
// The widget's client data points back to the owning view
|
|
|
|
if (aWidget) {
|
|
|
|
void* clientData;
|
|
|
|
aWidget->GetClientData(clientData);
|
|
|
|
nsISupports* data = (nsISupports*)clientData;
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
ViewWrapper* wrapper;
|
|
|
|
CallQueryInterface(data, &wrapper);
|
|
|
|
// Give a weak reference to the caller. There will still be at least one
|
|
|
|
// reference left, since the wrapper was addrefed when set on the widget.
|
|
|
|
if (wrapper)
|
|
|
|
wrapper->Release();
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Main events handler
|
2010-06-24 19:01:06 -07:00
|
|
|
static nsEventStatus HandleEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
printf(" %d %d %d (%d,%d) \n", aEvent->widget, aEvent->widgetSupports,
|
|
|
|
aEvent->message, aEvent->point.x, aEvent->point.y);
|
|
|
|
#endif
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
|
|
|
nsView *view = nsView::GetViewFor(aEvent->widget);
|
|
|
|
|
|
|
|
if (view)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIViewManager> vm = view->GetViewManager();
|
|
|
|
vm->DispatchEvent(aEvent, view, &result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attached widget event helpers
|
|
|
|
static ViewWrapper* GetAttachedWrapperFor(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aWidget, "null widget ptr");
|
|
|
|
return aWidget->GetAttachedViewPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsView* GetAttachedViewFor(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aWidget, "null widget ptr");
|
|
|
|
|
|
|
|
ViewWrapper* wrapper = GetAttachedWrapperFor(aWidget);
|
|
|
|
if (!wrapper)
|
|
|
|
return nsnull;
|
|
|
|
return wrapper->GetView();
|
|
|
|
}
|
|
|
|
|
|
|
|
// event handler
|
|
|
|
static nsEventStatus AttachedHandleEvent(nsGUIEvent *aEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
2010-06-24 19:01:06 -07:00
|
|
|
nsView *view = GetAttachedViewFor(aEvent->widget);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (view)
|
|
|
|
{
|
2009-05-14 07:04:45 -07:00
|
|
|
nsCOMPtr<nsIViewManager> vm = view->GetViewManager();
|
2009-07-21 17:44:59 -07:00
|
|
|
vm->DispatchEvent(aEvent, view, &result);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
mDirtyRegion = nsnull;
|
2007-11-22 07:08:13 -08:00
|
|
|
mDeletionObserver = nsnull;
|
2010-06-24 19:01:06 -07:00
|
|
|
mWidgetIsTopLevel = PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-13 06:13:16 -07:00
|
|
|
void nsView::DropMouseGrabbing()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIViewObserver> viewObserver = mViewManager->GetViewObserver();
|
|
|
|
if (viewObserver) {
|
|
|
|
viewObserver->ClearMouseCapture(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();
|
|
|
|
|
|
|
|
nsView *rootView = mViewManager->GetRootView();
|
|
|
|
|
|
|
|
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...
|
|
|
|
mViewManager->SetRootView(nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mParent)
|
|
|
|
{
|
|
|
|
mParent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
mViewManager = nsnull;
|
|
|
|
}
|
|
|
|
else if (mParent)
|
|
|
|
{
|
|
|
|
mParent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy and release the widget
|
|
|
|
if (mWindow)
|
|
|
|
{
|
|
|
|
// Release memory for the view wrapper
|
|
|
|
ViewWrapper* wrapper = GetWrapperFor(mWindow);
|
|
|
|
NS_IF_RELEASE(wrapper);
|
|
|
|
|
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) {
|
|
|
|
ViewWrapper* wrapper = GetAttachedWrapperFor(mWindow);
|
|
|
|
NS_IF_RELEASE(wrapper);
|
|
|
|
|
|
|
|
mWindow->SetAttachedViewPtr(nsnull);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mWindow->SetClientData(nsnull);
|
|
|
|
mWindow->Destroy();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_RELEASE(mWindow);
|
|
|
|
}
|
|
|
|
delete mDirtyRegion;
|
2007-11-22 07:08:13 -08:00
|
|
|
|
|
|
|
if (mDeletionObserver) {
|
|
|
|
mDeletionObserver->Clear();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsView::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!aIID.Equals(NS_GET_IID(nsISupports)),
|
|
|
|
"Someone expects views to be ISupports-derived!");
|
|
|
|
|
|
|
|
*aInstancePtr = nsnull;
|
|
|
|
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIView))) {
|
|
|
|
*aInstancePtr = (void*)(nsIView*)this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView* nsIView::GetViewFor(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aWidget, "null widget ptr");
|
|
|
|
|
|
|
|
ViewWrapper* wrapper = GetWrapperFor(aWidget);
|
2010-06-24 19:01:06 -07:00
|
|
|
|
|
|
|
if (!wrapper)
|
|
|
|
wrapper = GetAttachedWrapperFor(aWidget);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (wrapper)
|
2010-06-24 19:01:06 -07:00
|
|
|
return wrapper->GetView();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
ResetWidgetBounds(PR_TRUE, PR_TRUE, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::SetPositionIgnoringChildWidgets(nscoord aX, nscoord aY)
|
|
|
|
{
|
|
|
|
mDimBounds.x += aX - mPosX;
|
|
|
|
mDimBounds.y += aY - mPosY;
|
|
|
|
mPosX = aX;
|
|
|
|
mPosY = aY;
|
|
|
|
|
|
|
|
ResetWidgetBounds(PR_FALSE, PR_TRUE, PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::ResetWidgetBounds(PRBool aRecurse, PRBool aMoveOnly,
|
|
|
|
PRBool aInvalidateChangedSize) {
|
|
|
|
if (mWindow) {
|
|
|
|
// If our view manager has refresh disabled, then do nothing; the view
|
|
|
|
// manager will set our position when refresh is reenabled. Just let it
|
|
|
|
// know that it has pending updates.
|
|
|
|
if (!mViewManager->IsRefreshEnabled()) {
|
|
|
|
mViewManager->PostPendingUpdate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DoResetWidgetBounds(aMoveOnly, aInvalidateChangedSize);
|
|
|
|
} else if (aRecurse) {
|
|
|
|
// reposition any widgets under this view
|
|
|
|
for (nsView* v = GetFirstChild(); v; v = v->GetNextSibling()) {
|
|
|
|
v->ResetWidgetBounds(PR_TRUE, aMoveOnly, aInvalidateChangedSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-24 00:33:41 -08:00
|
|
|
PRBool 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)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-02-24 00:33:41 -08:00
|
|
|
nsIntRect nsIView::CalcWidgetBounds(nsWindowType aType)
|
2007-05-25 20:45:00 -07:00
|
|
|
{
|
2010-07-18 19:23:47 -07:00
|
|
|
PRInt32 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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void nsView::DoResetWidgetBounds(PRBool aMoveOnly,
|
|
|
|
PRBool aInvalidateChangedSize) {
|
|
|
|
// The geometry of a root view's widget is controlled externally,
|
|
|
|
// NOT by sizing or positioning the view
|
|
|
|
if (mViewManager->GetRootView() == this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-14 19:27:09 -08:00
|
|
|
nsIntRect curBounds;
|
2007-03-22 10:30:00 -07:00
|
|
|
mWindow->GetBounds(curBounds);
|
2010-06-24 19:01:06 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsWindowType type;
|
|
|
|
mWindow->GetWindowType(type);
|
|
|
|
|
|
|
|
if (curBounds.IsEmpty() && mDimBounds.IsEmpty() && type == eWindowType_popup) {
|
|
|
|
// Don't manipulate empty popup widgets. For example there's no point
|
|
|
|
// moving hidden comboboxes around, or doing X server roundtrips
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2007-05-25 20:45:00 -07:00
|
|
|
PRBool changedPos = curBounds.TopLeft() != newBounds.TopLeft();
|
|
|
|
PRBool 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.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (changedPos) {
|
|
|
|
if (changedSize && !aMoveOnly) {
|
|
|
|
mWindow->Resize(newBounds.x, newBounds.y, newBounds.width, newBounds.height,
|
|
|
|
aInvalidateChangedSize);
|
|
|
|
} else {
|
|
|
|
mWindow->Move(newBounds.x, newBounds.y);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (changedSize && !aMoveOnly) {
|
|
|
|
mWindow->Resize(newBounds.width, newBounds.height, aInvalidateChangedSize);
|
|
|
|
} // else do nothing!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::SetDimensions(const nsRect& aRect, PRBool aPaint, PRBool aResizeWidget)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
ResetWidgetBounds(PR_FALSE, PR_FALSE, aPaint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-29 19:54:42 -07:00
|
|
|
void nsView::NotifyEffectiveVisibilityChanged(PRBool 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mWindow)
|
|
|
|
{
|
2009-07-29 19:54:42 -07:00
|
|
|
if (aEffectivelyVisible)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
DoResetWidgetBounds(PR_FALSE, PR_TRUE);
|
|
|
|
mWindow->Show(PR_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mWindow->Show(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsView::SetFloating(PRBool aFloatingView)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (mViewManager->GetRootView() == this)
|
|
|
|
mViewManager->InvalidateHierarchy();
|
|
|
|
|
|
|
|
for (nsView *child = mFirstChild; child; child = child->GetNextSibling())
|
|
|
|
child->InvalidateHierarchy(aViewManagerParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::InsertChild(nsView *aChild, nsView *aSibling)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aChild, "null ptr");
|
|
|
|
|
|
|
|
if (nsnull != aChild)
|
|
|
|
{
|
|
|
|
if (nsnull != aSibling)
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
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();
|
|
|
|
if (vm->GetRootView() == aChild)
|
|
|
|
{
|
|
|
|
aChild->InvalidateHierarchy(nsnull); // don't care about releasing grabs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::RemoveChild(nsView *child)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != child, "null ptr");
|
|
|
|
|
|
|
|
if (nsnull != child)
|
|
|
|
{
|
|
|
|
nsView* prevKid = nsnull;
|
|
|
|
nsView* kid = mFirstChild;
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
while (nsnull != kid) {
|
|
|
|
if (kid == child) {
|
|
|
|
if (nsnull != prevKid) {
|
|
|
|
prevKid->SetNextSibling(kid->GetNextSibling());
|
|
|
|
} else {
|
|
|
|
mFirstChild = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
child->SetParent(nsnull);
|
|
|
|
found = PR_TRUE;
|
|
|
|
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();
|
|
|
|
if (vm->GetRootView() == child)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
static void UpdateNativeWidgetZIndexes(nsView* aView, PRInt32 aZIndex)
|
|
|
|
{
|
|
|
|
if (aView->HasWidget()) {
|
|
|
|
nsIWidget* widget = aView->GetWidget();
|
|
|
|
PRInt32 curZ;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRInt32 FindNonAutoZIndex(nsView* aView)
|
|
|
|
{
|
|
|
|
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,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool aEnableDragDrop,
|
|
|
|
PRBool aResetVisibility,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsContentType aContentType)
|
2010-08-20 12:29:01 -07:00
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
return Impl()->CreateWidget(aWidgetInitData,
|
2010-08-20 12:29:01 -07:00
|
|
|
aEnableDragDrop, aResetVisibility,
|
2010-08-20 12:29:02 -07:00
|
|
|
aContentType);
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsIView::CreateWidgetForParent(nsIWidget* aParentWidget,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsWidgetInitData *aWidgetInitData,
|
|
|
|
PRBool aEnableDragDrop,
|
|
|
|
PRBool aResetVisibility,
|
|
|
|
nsContentType aContentType)
|
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
return Impl()->CreateWidgetForParent(aParentWidget, aWidgetInitData,
|
2010-08-20 12:29:02 -07:00
|
|
|
aEnableDragDrop, aResetVisibility,
|
|
|
|
aContentType);
|
|
|
|
}
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsIView::CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsIWidget* aParentWidget,
|
|
|
|
PRBool aEnableDragDrop,
|
|
|
|
PRBool aResetVisibility,
|
|
|
|
nsContentType aContentType)
|
|
|
|
{
|
2010-08-20 12:29:02 -07:00
|
|
|
return Impl()->CreateWidgetForPopup(aWidgetInitData, aParentWidget,
|
2010-08-20 12:29:02 -07:00
|
|
|
aEnableDragDrop, aResetVisibility,
|
|
|
|
aContentType);
|
2010-08-20 12:29:01 -07:00
|
|
|
}
|
|
|
|
|
2010-08-23 23:28:16 -07:00
|
|
|
struct DefaultWidgetInitData : public nsWidgetInitData {
|
|
|
|
DefaultWidgetInitData() : nsWidgetInitData()
|
|
|
|
{
|
|
|
|
mWindowType = eWindowType_child;
|
|
|
|
clipChildren = PR_TRUE;
|
|
|
|
clipSiblings = PR_TRUE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsresult nsView::CreateWidget(nsWidgetInitData *aWidgetInitData,
|
2010-08-20 12:29:01 -07:00
|
|
|
PRBool aEnableDragDrop,
|
|
|
|
PRBool aResetVisibility,
|
2010-08-20 12:29:02 -07:00
|
|
|
nsContentType aContentType)
|
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;
|
|
|
|
aWidgetInitData = aWidgetInitData ? aWidgetInitData : &defaultInitData;
|
2010-08-20 12:29:01 -07:00
|
|
|
aWidgetInitData->mContentType = aContentType;
|
|
|
|
|
|
|
|
nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
nsCOMPtr<nsIDeviceContext> dx;
|
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
nsIWidget* parentWidget =
|
|
|
|
GetParent() ? GetParent()->GetNearestWidget(nsnull) : nsnull;
|
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.
|
|
|
|
mWindow = parentWidget->CreateChild(trect, ::HandleEvent,
|
|
|
|
dx, nsnull, nsnull, aWidgetInitData,
|
|
|
|
PR_TRUE).get();
|
|
|
|
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,
|
|
|
|
PRBool aEnableDragDrop,
|
|
|
|
PRBool aResetVisibility,
|
2010-08-23 23:28:16 -07:00
|
|
|
nsContentType aContentType)
|
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;
|
|
|
|
aWidgetInitData->mContentType = aContentType;
|
|
|
|
|
|
|
|
nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
2010-08-20 12:29:02 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDeviceContext> dx;
|
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
mWindow =
|
|
|
|
aParentWidget->CreateChild(trect, ::HandleEvent,
|
|
|
|
dx, nsnull, nsnull, aWidgetInitData).get();
|
|
|
|
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,
|
|
|
|
PRBool aEnableDragDrop,
|
|
|
|
PRBool aResetVisibility,
|
|
|
|
nsContentType aWindowType)
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDeviceContext> dx;
|
|
|
|
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.
|
|
|
|
mWindow = aParentWidget->CreateChild(trect, ::HandleEvent,
|
|
|
|
dx, nsnull, nsnull, aWidgetInitData,
|
|
|
|
PR_TRUE).get();
|
2010-08-20 12:29:01 -07:00
|
|
|
}
|
|
|
|
else {
|
2010-08-20 12:29:02 -07:00
|
|
|
nsIWidget* nearestParent = GetParent() ? GetParent()->GetNearestWidget(nsnull)
|
|
|
|
: nsnull;
|
|
|
|
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 =
|
|
|
|
nearestParent->CreateChild(trect, ::HandleEvent,
|
|
|
|
dx, nsnull, nsnull, aWidgetInitData).get();
|
|
|
|
}
|
|
|
|
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
|
2010-08-20 12:29:02 -07:00
|
|
|
nsView::InitializeWindow(PRBool aEnableDragDrop, PRBool aResetVisibility)
|
2010-08-20 12:29:01 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mWindow, "Must have a window to initialize");
|
|
|
|
|
2010-08-20 12:29:02 -07:00
|
|
|
ViewWrapper* wrapper = new ViewWrapper(this);
|
|
|
|
NS_ADDREF(wrapper); // Will be released in ~nsView
|
|
|
|
mWindow->SetClientData(wrapper);
|
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
if (aEnableDragDrop) {
|
|
|
|
mWindow->EnableDragDrop(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aWidget, "null widget ptr");
|
|
|
|
/// XXXjimm This is a temporary workaround to an issue w/document
|
|
|
|
// viewer (bug 513162).
|
|
|
|
nsIView *oldView = GetAttachedViewFor(aWidget);
|
|
|
|
if (oldView) {
|
|
|
|
oldView->DetachFromTopLevelWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDeviceContext> dx;
|
|
|
|
mViewManager->GetDeviceContext(*getter_AddRefs(dx));
|
|
|
|
|
|
|
|
// Note, the previous device context will be released. Detaching
|
|
|
|
// will not restore the old one.
|
|
|
|
nsresult rv = aWidget->AttachViewToTopLevel(::AttachedHandleEvent, dx);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mWindow = aWidget;
|
|
|
|
NS_ADDREF(mWindow);
|
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
ViewWrapper* wrapper = new ViewWrapper(Impl());
|
2010-06-24 19:01:06 -07:00
|
|
|
NS_ADDREF(wrapper);
|
|
|
|
mWindow->SetAttachedViewPtr(wrapper);
|
|
|
|
mWindow->EnableDragDrop(PR_TRUE);
|
|
|
|
mWidgetIsTopLevel = PR_TRUE;
|
|
|
|
|
|
|
|
// 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!");
|
|
|
|
|
|
|
|
// Release memory for the view wrapper
|
|
|
|
ViewWrapper* wrapper = GetAttachedWrapperFor(mWindow);
|
|
|
|
NS_IF_RELEASE(wrapper);
|
|
|
|
|
|
|
|
mWindow->SetAttachedViewPtr(nsnull);
|
|
|
|
NS_RELEASE(mWindow);
|
|
|
|
|
|
|
|
mWidgetIsTopLevel = PR_FALSE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void nsView::SetZIndex(PRBool aAuto, PRInt32 aZIndex, PRBool aTopMost)
|
|
|
|
{
|
|
|
|
PRBool oldIsAuto = GetZIndexIsAuto();
|
|
|
|
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
|
2010-08-20 12:29:02 -07:00
|
|
|
if (NS_UNLIKELY(mWindow)) {
|
|
|
|
NS_ERROR("We already have a window for this view? BAD");
|
|
|
|
ViewWrapper* wrapper = GetWrapperFor(mWindow);
|
|
|
|
NS_IF_RELEASE(wrapper);
|
|
|
|
mWindow->SetClientData(nsnull);
|
|
|
|
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
|
|
|
|
//
|
2009-07-21 17:45:00 -07:00
|
|
|
EVENT_CALLBACK nsIView::AttachWidgetEventHandler(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
void* data = nsnull;
|
|
|
|
aWidget->GetClientData(data);
|
|
|
|
NS_ASSERTION(!data, "Already got client data");
|
|
|
|
#endif
|
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
ViewWrapper* wrapper = new ViewWrapper(Impl());
|
2009-07-21 17:45:00 -07:00
|
|
|
if (!wrapper)
|
|
|
|
return nsnull;
|
|
|
|
NS_ADDREF(wrapper); // Will be released in DetachWidgetEventHandler
|
|
|
|
aWidget->SetClientData(wrapper);
|
|
|
|
return ::HandleEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsIView::DetachWidgetEventHandler(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
ViewWrapper* wrapper = GetWrapperFor(aWidget);
|
|
|
|
NS_ASSERTION(!wrapper || wrapper->GetView() == this, "Wrong view");
|
|
|
|
NS_IF_RELEASE(wrapper);
|
|
|
|
aWidget->SetClientData(nsnull);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void nsIView::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
|
|
|
fprintf(out, "%p ", (void*)this);
|
|
|
|
if (nsnull != 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();
|
|
|
|
PRInt32 Z;
|
|
|
|
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);
|
|
|
|
fprintf(out, " z=%d vis=%d clientData=%p <\n",
|
|
|
|
mZIndex, mVis, mClientData);
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint nsView::GetOffsetTo(const nsView* aOther, const PRInt32 aAPD) const
|
|
|
|
{
|
|
|
|
// 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();
|
|
|
|
PRInt32 currAPD = currVM->AppUnitsPerDevPixel();
|
|
|
|
const nsView* root = nsnull;
|
|
|
|
for ( ; v != aOther && v; root = v, v = v->GetParent()) {
|
|
|
|
nsViewManager* newVM = v->GetViewManager();
|
|
|
|
if (newVM != currVM) {
|
|
|
|
PRInt32 newAPD = newVM->AppUnitsPerDevPixel();
|
|
|
|
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.
|
|
|
|
PRInt32 widgetAPD = widgetView->GetViewManager()->AppUnitsPerDevPixel();
|
|
|
|
PRInt32 ourAPD = static_cast<const nsView*>(this)->
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset, const PRInt32 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();
|
|
|
|
PRInt32 currAPD = currVM->AppUnitsPerDevPixel();
|
|
|
|
for ( ; v && !v->HasWidget(); v = v->GetParent()) {
|
|
|
|
nsViewManager* newVM = v->GetViewManager();
|
|
|
|
if (newVM != currVM) {
|
|
|
|
PRInt32 newAPD = newVM->AppUnitsPerDevPixel();
|
|
|
|
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;
|
|
|
|
}
|
2009-07-21 17:45:09 -07:00
|
|
|
return nsnull;
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsIView::IsRoot() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mViewManager != nsnull," View manager is null in nsView::IsRoot()");
|
|
|
|
return mViewManager->GetRootView() == this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsIView::ExternalIsRoot() const
|
|
|
|
{
|
|
|
|
return nsIView::IsRoot();
|
|
|
|
}
|
2007-11-22 07:08:13 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
nsIView::SetDeletionObserver(nsWeakView* aDeletionObserver)
|
|
|
|
{
|
|
|
|
if (mDeletionObserver && aDeletionObserver) {
|
|
|
|
aDeletionObserver->SetPrevious(mDeletionObserver);
|
|
|
|
}
|
|
|
|
mDeletionObserver = aDeletionObserver;
|
|
|
|
}
|
2010-07-18 19:23:47 -07: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();
|
|
|
|
if (this != VM->GetRootView() || !parent) {
|
|
|
|
return mDimBounds;
|
|
|
|
}
|
|
|
|
PRInt32 ourAPD = VM->AppUnitsPerDevPixel();
|
|
|
|
PRInt32 parentAPD = parent->GetViewManager()->AppUnitsPerDevPixel();
|
|
|
|
return mDimBounds.ConvertAppUnitsRoundOut(ourAPD, parentAPD);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
|
|
|
nsView::ConvertFromParentCoords(nsPoint aPt) const
|
|
|
|
{
|
|
|
|
nsView* parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
aPt = aPt.ConvertAppUnits(parent->GetViewManager()->AppUnitsPerDevPixel(),
|
|
|
|
GetViewManager()->AppUnitsPerDevPixel());
|
|
|
|
}
|
|
|
|
aPt -= GetPosition();
|
|
|
|
return aPt;
|
|
|
|
}
|