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
|
|
|
|
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK (sizeof(void*)-1)
|
|
|
|
#include "plarena.h"
|
|
|
|
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsViewManager.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsView.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsRegion.h"
|
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsCOMArray.h"
|
2009-07-21 17:45:00 -07:00
|
|
|
#include "nsIPluginWidget.h"
|
2010-07-27 06:38:02 -07:00
|
|
|
#include "nsXULPopupManager.h"
|
2010-08-05 11:39:39 -07:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-03-25 16:17:35 -07:00
|
|
|
#include "nsEventStateManager.h"
|
2011-11-17 23:54:27 -08:00
|
|
|
#include "mozilla/StartupTimeline.h"
|
2011-12-02 14:05:33 -08:00
|
|
|
#include "sampler.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
XXX TODO XXX
|
|
|
|
|
|
|
|
DeCOMify newly private methods
|
|
|
|
Optimize view storage
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
A note about platform assumptions:
|
|
|
|
|
|
|
|
We assume that a widget is z-ordered on top of its parent.
|
|
|
|
|
|
|
|
We do NOT assume anything about the relative z-ordering of sibling widgets. Even though
|
|
|
|
we ask for a specific z-order, we don't assume that widget z-ordering actually works.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NSCOORD_NONE PR_INT32_MIN
|
|
|
|
|
|
|
|
#undef DEBUG_MOUSE_LOCATION
|
|
|
|
|
|
|
|
PRInt32 nsViewManager::mVMCount = 0;
|
|
|
|
|
|
|
|
// Weakly held references to all of the view managers
|
|
|
|
nsVoidArray* nsViewManager::gViewManagers = nsnull;
|
|
|
|
PRUint32 nsViewManager::gLastUserEventTime = 0;
|
|
|
|
|
|
|
|
nsViewManager::nsViewManager()
|
2011-05-11 08:49:16 -07:00
|
|
|
: mDelayedResize(NSCOORD_NONE, NSCOORD_NONE)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mRootViewManager(this)
|
|
|
|
{
|
|
|
|
if (gViewManagers == nsnull) {
|
|
|
|
NS_ASSERTION(mVMCount == 0, "View Manager count is incorrect");
|
|
|
|
// Create an array to hold a list of view managers
|
|
|
|
gViewManagers = new nsVoidArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
gViewManagers->AppendElement(this);
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
++mVMCount;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// NOTE: we use a zeroing operator new, so all data members are
|
|
|
|
// assumed to be cleared here.
|
2012-07-03 17:24:55 -07:00
|
|
|
mHasPendingUpdates = false;
|
2011-12-23 19:52:23 -08:00
|
|
|
mHasPendingWidgetGeometryChanges = false;
|
2011-10-17 07:59:28 -07:00
|
|
|
mRecursiveRefreshPending = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsViewManager::~nsViewManager()
|
|
|
|
{
|
|
|
|
if (mRootView) {
|
|
|
|
// Destroy any remaining views
|
|
|
|
mRootView->Destroy();
|
|
|
|
mRootView = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsRootVM()) {
|
|
|
|
// We have a strong ref to mRootViewManager
|
|
|
|
NS_RELEASE(mRootViewManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION((mVMCount > 0), "underflow of viewmanagers");
|
|
|
|
--mVMCount;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool removed =
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
gViewManagers->RemoveElement(this);
|
|
|
|
NS_ASSERTION(removed, "Viewmanager instance not was not in the global list of viewmanagers");
|
|
|
|
|
|
|
|
if (0 == mVMCount) {
|
|
|
|
// There aren't any more view managers so
|
|
|
|
// release the global array of view managers
|
|
|
|
|
|
|
|
NS_ASSERTION(gViewManagers != nsnull, "About to delete null gViewManagers");
|
|
|
|
delete gViewManagers;
|
|
|
|
gViewManagers = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-11-21 09:53:20 -08:00
|
|
|
mPresShell = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsViewManager, nsIViewManager)
|
|
|
|
|
|
|
|
// We don't hold a reference to the presentation context because it
|
|
|
|
// holds a reference to us.
|
2011-04-16 18:22:44 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::Init(nsDeviceContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aContext, "null ptr");
|
|
|
|
|
|
|
|
if (nsnull == aContext) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (nsnull != mContext) {
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
}
|
|
|
|
mContext = aContext;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsIView *)
|
|
|
|
nsViewManager::CreateView(const nsRect& aBounds,
|
|
|
|
const nsIView* aParent,
|
|
|
|
nsViewVisibility aVisibilityFlag)
|
|
|
|
{
|
|
|
|
nsView *v = new nsView(this, aVisibilityFlag);
|
|
|
|
if (v) {
|
2009-09-10 18:44:20 -07:00
|
|
|
v->SetParent(static_cast<nsView*>(const_cast<nsIView*>(aParent)));
|
2007-03-22 10:30:00 -07:00
|
|
|
v->SetPosition(aBounds.x, aBounds.y);
|
|
|
|
nsRect dim(0, 0, aBounds.width, aBounds.height);
|
2011-10-17 07:59:28 -07:00
|
|
|
v->SetDimensions(dim, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:24:54 -07:00
|
|
|
NS_IMETHODIMP_(nsIView*)
|
|
|
|
nsViewManager::GetRootView()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-03-29 19:24:54 -07:00
|
|
|
return mRootView;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsViewManager::SetRootView(nsIView *aView)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_PRECONDITION(!view || view->GetViewManager() == this,
|
|
|
|
"Unexpected viewmanager on root view");
|
|
|
|
|
|
|
|
// Do NOT destroy the current root view. It's the caller's responsibility
|
|
|
|
// to destroy it
|
|
|
|
mRootView = view;
|
|
|
|
|
|
|
|
if (mRootView) {
|
|
|
|
nsView* parent = mRootView->GetParent();
|
|
|
|
if (parent) {
|
|
|
|
// Calling InsertChild on |parent| will InvalidateHierarchy() on us, so
|
|
|
|
// no need to set mRootViewManager ourselves here.
|
|
|
|
parent->InsertChild(mRootView, nsnull);
|
|
|
|
} else {
|
|
|
|
InvalidateHierarchy();
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mRootView->SetZIndex(false, 0, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// Else don't touch mRootViewManager
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsViewManager::GetWindowDimensions(nscoord *aWidth, nscoord *aHeight)
|
|
|
|
{
|
|
|
|
if (nsnull != mRootView) {
|
|
|
|
if (mDelayedResize == nsSize(NSCOORD_NONE, NSCOORD_NONE)) {
|
2011-05-11 08:49:16 -07:00
|
|
|
nsRect dim = mRootView->GetDimensions();
|
2007-03-22 10:30:00 -07:00
|
|
|
*aWidth = dim.width;
|
|
|
|
*aHeight = dim.height;
|
|
|
|
} else {
|
|
|
|
*aWidth = mDelayedResize.width;
|
|
|
|
*aHeight = mDelayedResize.height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*aWidth = 0;
|
|
|
|
*aHeight = 0;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:01:06 -07:00
|
|
|
void nsViewManager::DoSetWindowDimensions(nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
2011-05-11 08:49:16 -07:00
|
|
|
nsRect oldDim = mRootView->GetDimensions();
|
2010-06-24 19:01:06 -07:00
|
|
|
nsRect newDim(0, 0, aWidth, aHeight);
|
|
|
|
// We care about resizes even when one dimension is already zero.
|
2011-04-18 20:07:23 -07:00
|
|
|
if (!oldDim.IsEqualEdges(newDim)) {
|
2010-06-24 19:01:06 -07:00
|
|
|
// Don't resize the widget. It is already being set elsewhere.
|
2011-10-17 07:59:28 -07:00
|
|
|
mRootView->SetDimensions(newDim, true, false);
|
2011-11-21 09:53:20 -08:00
|
|
|
if (mPresShell)
|
|
|
|
mPresShell->ResizeReflow(aWidth, aHeight);
|
2010-06-24 19:01:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::SetWindowDimensions(nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
|
|
|
if (mRootView) {
|
2011-11-21 09:53:20 -08:00
|
|
|
if (mRootView->IsEffectivelyVisible() && mPresShell && mPresShell->IsVisible()) {
|
2011-01-28 16:10:46 -08:00
|
|
|
if (mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE) &&
|
|
|
|
mDelayedResize != nsSize(aWidth, aHeight)) {
|
|
|
|
// We have a delayed resize; that now obsolete size may already have
|
|
|
|
// been flushed to the PresContext so we need to update the PresContext
|
|
|
|
// with the new size because if the new size is exactly the same as the
|
|
|
|
// root view's current size then DoSetWindowDimensions will not
|
|
|
|
// request a resize reflow (which would correct it). See bug 617076.
|
|
|
|
mDelayedResize = nsSize(aWidth, aHeight);
|
2011-10-17 07:59:28 -07:00
|
|
|
FlushDelayedResize(false);
|
2011-01-28 16:10:46 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
mDelayedResize.SizeTo(NSCOORD_NONE, NSCOORD_NONE);
|
|
|
|
DoSetWindowDimensions(aWidth, aHeight);
|
|
|
|
} else {
|
|
|
|
mDelayedResize.SizeTo(aWidth, aHeight);
|
2011-12-14 20:42:15 -08:00
|
|
|
if (mPresShell && mPresShell->GetDocument()) {
|
|
|
|
mPresShell->GetDocument()->SetNeedStyleFlush();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::FlushDelayedResize(bool aDoReflow)
|
2008-09-09 06:43:10 -07:00
|
|
|
{
|
|
|
|
if (mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE)) {
|
2010-08-05 11:39:39 -07:00
|
|
|
if (aDoReflow) {
|
|
|
|
DoSetWindowDimensions(mDelayedResize.width, mDelayedResize.height);
|
|
|
|
mDelayedResize.SizeTo(NSCOORD_NONE, NSCOORD_NONE);
|
2011-11-21 09:53:20 -08:00
|
|
|
} else if (mPresShell) {
|
|
|
|
nsPresContext* presContext = mPresShell->GetPresContext();
|
2010-08-05 11:39:39 -07:00
|
|
|
if (presContext) {
|
|
|
|
presContext->SetVisibleArea(nsRect(nsPoint(0, 0), mDelayedResize));
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 06:43:10 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
// Convert aIn from being relative to and in appunits of aFromView, to being
|
|
|
|
// relative to and in appunits of aToView.
|
|
|
|
static nsRegion ConvertRegionBetweenViews(const nsRegion& aIn,
|
|
|
|
nsView* aFromView,
|
|
|
|
nsView* aToView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-18 19:23:47 -07:00
|
|
|
nsRegion out = aIn;
|
|
|
|
out.MoveBy(aFromView->GetOffsetTo(aToView));
|
|
|
|
out = out.ConvertAppUnitsRoundOut(
|
|
|
|
aFromView->GetViewManager()->AppUnitsPerDevPixel(),
|
|
|
|
aToView->GetViewManager()->AppUnitsPerDevPixel());
|
2010-03-01 00:03:49 -08:00
|
|
|
return out;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-05-29 20:15:00 -07:00
|
|
|
nsIView* nsIViewManager::GetDisplayRootFor(nsIView* aView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-29 20:15:00 -07:00
|
|
|
nsIView *displayRoot = aView;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (;;) {
|
2011-05-29 20:15:00 -07:00
|
|
|
nsIView *displayParent = displayRoot->GetParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!displayParent)
|
|
|
|
return displayRoot;
|
|
|
|
|
|
|
|
if (displayRoot->GetFloating() && !displayParent->GetFloating())
|
|
|
|
return displayRoot;
|
2011-05-29 20:15:00 -07:00
|
|
|
|
|
|
|
// If we have a combobox dropdown popup within a panel popup, both the view
|
|
|
|
// for the dropdown popup and its parent will be floating, so we need to
|
|
|
|
// distinguish this situation. We do this by looking for a widget. Any view
|
|
|
|
// with a widget is a display root, except for plugins.
|
|
|
|
nsIWidget* widget = displayRoot->GetWidget();
|
|
|
|
if (widget) {
|
|
|
|
nsWindowType type;
|
|
|
|
widget->GetWindowType(type);
|
|
|
|
if (type == eWindowType_popup) {
|
|
|
|
NS_ASSERTION(displayRoot->GetFloating() && displayParent->GetFloating(),
|
|
|
|
"this should only happen with floating views that have floating parents");
|
|
|
|
return displayRoot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
displayRoot = displayParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
aRegion is given in device coordinates!!
|
2010-03-01 00:03:49 -08:00
|
|
|
aContext may be null, in which case layers should be used for
|
|
|
|
rendering.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-07-03 17:25:57 -07:00
|
|
|
void nsViewManager::Refresh(nsView *aView, nsIWidget *aWidget,
|
|
|
|
const nsIntRegion& aRegion,
|
2012-01-27 19:36:23 -08:00
|
|
|
bool aWillSendDidPaint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-03 17:25:57 -07:00
|
|
|
NS_ASSERTION(aView == nsView::GetViewFor(aWidget), "view widget mismatch");
|
2010-07-18 19:23:47 -07:00
|
|
|
NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// damageRegion is the damaged area, in twips, relative to the view origin
|
2010-07-18 19:23:47 -07:00
|
|
|
nsRegion damageRegion = aRegion.ToAppUnits(AppUnitsPerDevPixel());
|
2010-03-01 00:03:49 -08:00
|
|
|
// move region from widget coordinates into view coordinates
|
2010-07-18 19:23:47 -07:00
|
|
|
damageRegion.MoveBy(-aView->ViewToWidgetOffset());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (damageRegion.IsEmpty()) {
|
|
|
|
#ifdef DEBUG_roc
|
2011-05-11 08:49:16 -07:00
|
|
|
nsRect viewRect = aView->GetDimensions();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect damageRect = damageRegion.GetBounds();
|
|
|
|
printf("XXX Damage rectangle (%d,%d,%d,%d) does not intersect the widget's view (%d,%d,%d,%d)!\n",
|
|
|
|
damageRect.x, damageRect.y, damageRect.width, damageRect.height,
|
|
|
|
viewRect.x, viewRect.y, viewRect.width, viewRect.height);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!IsPainting(), "recursive painting not permitted");
|
|
|
|
if (IsPainting()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
RootViewManager()->mRecursiveRefreshPending = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-14 16:08:57 -07:00
|
|
|
{
|
2009-11-15 14:48:18 -08:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2011-10-17 07:59:28 -07:00
|
|
|
SetPainting(true);
|
2008-03-14 16:08:57 -07:00
|
|
|
|
2012-01-27 19:36:23 -08:00
|
|
|
NS_ASSERTION(GetDisplayRootFor(aView) == aView,
|
|
|
|
"Widgets that we paint must all be display roots");
|
|
|
|
|
|
|
|
if (mPresShell) {
|
2012-07-03 17:25:57 -07:00
|
|
|
mPresShell->Paint(aView, aWidget, damageRegion, aRegion,
|
2012-07-03 16:36:38 -07:00
|
|
|
aWillSendDidPaint);
|
2012-01-27 19:36:23 -08:00
|
|
|
mozilla::StartupTimeline::RecordOnce(mozilla::StartupTimeline::FIRST_PAINT);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
SetPainting(false);
|
2008-03-14 16:08:57 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (RootViewManager()->mRecursiveRefreshPending) {
|
2011-10-17 07:59:28 -07:00
|
|
|
RootViewManager()->mRecursiveRefreshPending = false;
|
2011-12-23 19:52:25 -08:00
|
|
|
InvalidateAllViews();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-03 17:14:47 -07:00
|
|
|
void nsViewManager::ProcessPendingUpdatesForView(nsView* aView,
|
2011-12-23 19:52:23 -08:00
|
|
|
bool aFlushDirtyRegion)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IsRootVM(), "Updates will be missed");
|
|
|
|
|
|
|
|
// Protect against a null-view.
|
|
|
|
if (!aView) {
|
2012-07-03 17:14:47 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aView->HasWidget()) {
|
2011-12-23 19:52:23 -08:00
|
|
|
aView->ResetWidgetBounds(false, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// process pending updates in child view.
|
|
|
|
for (nsView* childView = aView->GetFirstChild(); childView;
|
|
|
|
childView = childView->GetNextSibling()) {
|
2012-07-03 17:14:47 -07:00
|
|
|
ProcessPendingUpdatesForView(childView, aFlushDirtyRegion);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
// Push out updates after we've processed the children; ensures that
|
|
|
|
// damage is applied based on the final widget geometry
|
2011-12-23 19:52:23 -08:00
|
|
|
if (aFlushDirtyRegion) {
|
|
|
|
FlushDirtyRegionToWidget(aView);
|
|
|
|
}
|
2011-12-23 19:52:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsViewManager::FlushDirtyRegionToWidget(nsView* aView)
|
|
|
|
{
|
|
|
|
if (!aView->HasNonEmptyDirtyRegion())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsRegion* dirtyRegion = aView->GetDirtyRegion();
|
|
|
|
nsView* nearestViewWithWidget = aView;
|
|
|
|
while (!nearestViewWithWidget->HasWidget() &&
|
|
|
|
nearestViewWithWidget->GetParent()) {
|
|
|
|
nearestViewWithWidget = nearestViewWithWidget->GetParent();
|
2011-12-23 19:52:23 -08:00
|
|
|
}
|
2011-12-23 19:52:22 -08:00
|
|
|
nsRegion r =
|
|
|
|
ConvertRegionBetweenViews(*dirtyRegion, aView, nearestViewWithWidget);
|
|
|
|
nsViewManager* widgetVM = nearestViewWithWidget->GetViewManager();
|
2011-12-23 19:52:25 -08:00
|
|
|
widgetVM->InvalidateWidgetArea(nearestViewWithWidget, r);
|
2011-12-23 19:52:22 -08:00
|
|
|
dirtyRegion->SetEmpty();
|
2011-12-23 19:52:22 -08:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:25 -08:00
|
|
|
NS_IMETHODIMP nsViewManager::InvalidateView(nsIView *aView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Mark the entire view as damaged
|
2011-12-23 19:52:25 -08:00
|
|
|
return InvalidateView(aView, aView->GetDimensions());
|
2011-12-23 19:52:23 -08:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:22 -08:00
|
|
|
static void
|
|
|
|
AddDirtyRegion(nsView *aView, const nsRegion &aDamagedRegion)
|
|
|
|
{
|
|
|
|
nsRegion* dirtyRegion = aView->GetDirtyRegion();
|
|
|
|
if (!dirtyRegion)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dirtyRegion->Or(*dirtyRegion, aDamagedRegion);
|
|
|
|
dirtyRegion->SimplifyOutward(8);
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
void
|
|
|
|
nsViewManager::PostPendingUpdate()
|
|
|
|
{
|
|
|
|
nsViewManager* rootVM = RootViewManager();
|
2012-07-03 17:24:55 -07:00
|
|
|
rootVM->mHasPendingUpdates = true;
|
2011-12-23 19:52:23 -08:00
|
|
|
rootVM->mHasPendingWidgetGeometryChanges = true;
|
2012-07-03 17:14:47 -07:00
|
|
|
if (rootVM->mPresShell) {
|
2012-07-03 17:20:24 -07:00
|
|
|
rootVM->mPresShell->ScheduleViewManagerFlush();
|
2011-12-23 19:52:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* @param aDamagedRegion this region, relative to aWidgetView, is invalidated in
|
|
|
|
* every widget child of aWidgetView, plus aWidgetView's own widget
|
|
|
|
*/
|
|
|
|
void
|
2011-12-23 19:52:25 -08:00
|
|
|
nsViewManager::InvalidateWidgetArea(nsView *aWidgetView,
|
|
|
|
const nsRegion &aDamagedRegion)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-18 19:23:47 -07:00
|
|
|
NS_ASSERTION(aWidgetView->GetViewManager() == this,
|
2011-12-23 19:52:25 -08:00
|
|
|
"InvalidateWidgetArea called on view we don't own");
|
2011-12-23 19:52:23 -08:00
|
|
|
nsIWidget* widget = aWidgetView->GetWidget();
|
2010-07-18 19:23:47 -07:00
|
|
|
|
2010-06-24 19:01:06 -07:00
|
|
|
#if 0
|
|
|
|
nsRect dbgBounds = aDamagedRegion.GetBounds();
|
2011-12-23 19:52:25 -08:00
|
|
|
printf("InvalidateWidgetArea view:%X (%d) widget:%X region: %d, %d, %d, %d\n",
|
2010-06-24 19:01:06 -07:00
|
|
|
aWidgetView, aWidgetView->IsAttachedToTopLevel(),
|
2011-12-23 19:52:23 -08:00
|
|
|
widget, dbgBounds.x, dbgBounds.y, dbgBounds.width, dbgBounds.height);
|
2010-06-24 19:01:06 -07:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// If the widget is hidden, it don't cover nothing
|
2012-07-19 01:57:50 -07:00
|
|
|
if (widget && !widget->IsVisible()) {
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
if (!widget) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// The root view or a scrolling view might not have a widget
|
|
|
|
// (for example, during printing). We get here when we scroll
|
|
|
|
// during printing to show selected options in a listbox, for example.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update all child widgets with the damage. In the process,
|
|
|
|
// accumulate the union of all the child widget areas, or at least
|
|
|
|
// some subset of that.
|
|
|
|
nsRegion children;
|
2011-12-23 19:52:23 -08:00
|
|
|
if (widget->GetTransparencyMode() != eTransparencyTransparent) {
|
|
|
|
for (nsIWidget* childWidget = widget->GetFirstChild();
|
2009-02-24 08:53:32 -08:00
|
|
|
childWidget;
|
|
|
|
childWidget = childWidget->GetNextSibling()) {
|
|
|
|
nsView* view = nsView::GetViewFor(childWidget);
|
|
|
|
NS_ASSERTION(view != aWidgetView, "will recur infinitely");
|
2010-09-11 11:24:50 -07:00
|
|
|
nsWindowType type;
|
|
|
|
childWidget->GetWindowType(type);
|
2012-07-19 01:57:50 -07:00
|
|
|
if (view && childWidget->IsVisible() && type != eWindowType_popup) {
|
2010-09-17 11:05:51 -07:00
|
|
|
NS_ASSERTION(type == eWindowType_plugin,
|
|
|
|
"Only plugin or popup widgets can be children!");
|
|
|
|
|
|
|
|
// We do not need to invalidate in plugin widgets, but we should
|
|
|
|
// exclude them from the invalidation region IF we're not on
|
|
|
|
// Mac. On Mac we need to draw under plugin widgets, because
|
|
|
|
// plugin widgets are basically invisible
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
// GetBounds should compensate for chrome on a toplevel widget
|
|
|
|
nsIntRect bounds;
|
|
|
|
childWidget->GetBounds(bounds);
|
|
|
|
|
|
|
|
nsTArray<nsIntRect> clipRects;
|
|
|
|
childWidget->GetWindowClipRegion(&clipRects);
|
|
|
|
for (PRUint32 i = 0; i < clipRects.Length(); ++i) {
|
|
|
|
nsRect rr = (clipRects[i] + bounds.TopLeft()).
|
|
|
|
ToAppUnits(AppUnitsPerDevPixel());
|
|
|
|
children.Or(children, rr - aWidgetView->ViewToWidgetOffset());
|
|
|
|
children.SimplifyInward(20);
|
2009-02-24 08:53:32 -08:00
|
|
|
}
|
2010-09-17 11:05:51 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRegion leftOver;
|
2012-05-03 09:33:51 -07:00
|
|
|
leftOver.Sub(aDamagedRegion, children);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!leftOver.IsEmpty()) {
|
|
|
|
const nsRect* r;
|
|
|
|
for (nsRegionRectIterator iter(leftOver); (r = iter.Next());) {
|
2010-07-02 12:11:04 -07:00
|
|
|
nsIntRect bounds = ViewToWidget(aWidgetView, *r);
|
2011-12-23 19:52:23 -08:00
|
|
|
widget->Invalidate(bounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-08-18 18:16:58 -07:00
|
|
|
ShouldIgnoreInvalidation(nsViewManager* aVM)
|
|
|
|
{
|
|
|
|
while (aVM) {
|
2011-11-21 09:53:20 -08:00
|
|
|
nsIPresShell* shell = aVM->GetPresShell();
|
|
|
|
if (!shell || shell->ShouldIgnoreInvalidation()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-18 18:16:58 -07:00
|
|
|
}
|
2011-03-29 19:24:54 -07:00
|
|
|
nsView* view = aVM->GetRootViewImpl()->GetParent();
|
2010-08-18 18:16:58 -07:00
|
|
|
aVM = view ? view->GetViewManager() : nsnull;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-18 18:16:58 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:25 -08:00
|
|
|
nsresult nsViewManager::InvalidateView(nsIView *aView, const nsRect &aRect)
|
2010-08-18 18:16:58 -07:00
|
|
|
{
|
|
|
|
// If painting is suppressed in the presshell or an ancestor drop all
|
|
|
|
// invalidates, it will invalidate everything when it unsuppresses.
|
|
|
|
if (ShouldIgnoreInvalidation(this)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:25 -08:00
|
|
|
return InvalidateViewNoSuppression(aView, aRect);
|
2010-08-18 18:16:58 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:25 -08:00
|
|
|
NS_IMETHODIMP nsViewManager::InvalidateViewNoSuppression(nsIView *aView,
|
|
|
|
const nsRect &aRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aView, "null view");
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
NS_ASSERTION(view->GetViewManager() == this,
|
2011-12-23 19:52:25 -08:00
|
|
|
"InvalidateViewNoSuppression called on view we don't own");
|
2010-07-18 19:23:47 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsRect damagedRect(aRect);
|
2009-09-08 22:40:02 -07:00
|
|
|
if (damagedRect.IsEmpty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-29 20:15:00 -07:00
|
|
|
nsView* displayRoot = static_cast<nsView*>(GetDisplayRootFor(view));
|
2010-07-02 12:11:04 -07:00
|
|
|
nsViewManager* displayRootVM = displayRoot->GetViewManager();
|
2008-11-25 14:09:37 -08:00
|
|
|
// Propagate the update to the displayRoot, since iframes, for example,
|
|
|
|
// can overlap each other and be translucent. So we have to possibly
|
|
|
|
// invalidate our rect in each of the widgets we have lying about.
|
|
|
|
damagedRect.MoveBy(view->GetOffsetTo(displayRoot));
|
2010-07-18 19:23:47 -07:00
|
|
|
PRInt32 rootAPD = displayRootVM->AppUnitsPerDevPixel();
|
|
|
|
PRInt32 APD = AppUnitsPerDevPixel();
|
|
|
|
damagedRect = damagedRect.ConvertAppUnitsRoundOut(APD, rootAPD);
|
2011-12-23 19:52:23 -08:00
|
|
|
|
|
|
|
// accumulate this rectangle in the view's dirty region, so we can
|
|
|
|
// process it later.
|
|
|
|
AddDirtyRegion(displayRoot, nsRegion(damagedRect));
|
|
|
|
|
2012-07-03 17:24:55 -07:00
|
|
|
// Schedule an invalidation flush with the refresh driver.
|
|
|
|
PostPendingUpdate();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:25 -08:00
|
|
|
NS_IMETHODIMP nsViewManager::InvalidateAllViews()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (RootViewManager() != this) {
|
2011-12-23 19:52:25 -08:00
|
|
|
return RootViewManager()->InvalidateAllViews();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:25 -08:00
|
|
|
InvalidateViews(mRootView);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:25 -08:00
|
|
|
void nsViewManager::InvalidateViews(nsView *aView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-12-23 19:52:25 -08:00
|
|
|
// Invalidate this view.
|
|
|
|
InvalidateView(aView);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-23 19:52:25 -08:00
|
|
|
// Invalidate all children as well.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsView* childView = aView->GetFirstChild();
|
|
|
|
while (nsnull != childView) {
|
2011-12-23 19:52:25 -08:00
|
|
|
childView->GetViewManager()->InvalidateViews(childView);
|
2007-03-22 10:30:00 -07:00
|
|
|
childView = childView->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2010-07-27 06:38:02 -07:00
|
|
|
IsViewForPopup(nsIView* aView)
|
|
|
|
{
|
|
|
|
nsIWidget* widget = aView->GetWidget();
|
|
|
|
if (widget) {
|
|
|
|
nsWindowType type;
|
|
|
|
widget->GetWindowType(type);
|
|
|
|
return (type == eWindowType_popup);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-27 06:38:02 -07:00
|
|
|
}
|
|
|
|
|
2009-07-21 17:44:59 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::DispatchEvent(nsGUIEvent *aEvent,
|
|
|
|
nsIView* aView, nsEventStatus *aStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-18 19:23:47 -07:00
|
|
|
NS_ASSERTION(!aView || static_cast<nsView*>(aView)->GetViewManager() == this,
|
|
|
|
"wrong view manager");
|
|
|
|
|
2012-01-17 12:33:04 -08:00
|
|
|
SAMPLE_LABEL("event", "nsViewManager::DispatchEvent");
|
2011-12-02 14:05:33 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aStatus = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
switch(aEvent->message)
|
|
|
|
{
|
|
|
|
case NS_SIZE:
|
|
|
|
{
|
2009-07-21 17:44:59 -07:00
|
|
|
if (aView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-24 19:01:06 -07:00
|
|
|
// client area dimensions are set on the view
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord width = ((nsSizeEvent*)aEvent)->windowSize->width;
|
|
|
|
nscoord height = ((nsSizeEvent*)aEvent)->windowSize->height;
|
|
|
|
|
|
|
|
// The root view may not be set if this is the resize associated with
|
|
|
|
// window creation
|
|
|
|
|
2009-07-21 17:44:59 -07:00
|
|
|
if (aView == mRootView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-05 13:29:49 -07:00
|
|
|
PRInt32 p2a = AppUnitsPerDevPixel();
|
2007-03-22 10:30:00 -07:00
|
|
|
SetWindowDimensions(NSIntPixelsToAppUnits(width, p2a),
|
|
|
|
NSIntPixelsToAppUnits(height, p2a));
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
2010-07-27 06:38:02 -07:00
|
|
|
else if (IsViewForPopup(aView))
|
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
|
|
|
{
|
2011-11-21 09:53:20 -08:00
|
|
|
pm->PopupResized(aView->GetFrame(), nsIntSize(width, height));
|
2010-07-27 06:38:02 -07:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-07-27 06:38:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-27 06:38:02 -07:00
|
|
|
case NS_MOVE:
|
|
|
|
{
|
|
|
|
// A popup's parent view is the root view for the parent window, so when
|
|
|
|
// a popup moves, the popup's frame and view position must be updated
|
|
|
|
// to match.
|
|
|
|
if (aView && IsViewForPopup(aView))
|
|
|
|
{
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm)
|
|
|
|
{
|
2011-11-21 09:53:20 -08:00
|
|
|
pm->PopupMoved(aView->GetFrame(), aEvent->refPoint);
|
2010-07-27 06:38:02 -07:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-25 16:17:35 -07:00
|
|
|
case NS_DONESIZEMOVE:
|
|
|
|
{
|
2011-11-21 09:53:20 -08:00
|
|
|
if (mPresShell) {
|
|
|
|
nsPresContext* presContext = mPresShell->GetPresContext();
|
2011-03-25 16:17:35 -07:00
|
|
|
if (presContext) {
|
|
|
|
nsEventStateManager::ClearGlobalActiveContent(nsnull);
|
|
|
|
}
|
2011-11-21 09:53:20 -08:00
|
|
|
|
2011-03-25 16:17:35 -07:00
|
|
|
}
|
2011-11-21 09:53:20 -08:00
|
|
|
|
|
|
|
nsIPresShell::ClearMouseCapture(nsnull);
|
2011-03-25 16:17:35 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-07-27 06:38:04 -07:00
|
|
|
case NS_XUL_CLOSE:
|
|
|
|
{
|
|
|
|
// if this is a popup, make a request to hide it. Note that a popuphidden
|
|
|
|
// event listener may cancel the event and the popup will not be hidden.
|
|
|
|
nsIWidget* widget = aView->GetWidget();
|
|
|
|
if (widget) {
|
|
|
|
nsWindowType type;
|
|
|
|
widget->GetWindowType(type);
|
|
|
|
if (type == eWindowType_popup) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2011-11-21 09:53:20 -08:00
|
|
|
pm->HidePopup(aView->GetFrame());
|
2010-07-27 06:38:04 -07:00
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-11-13 15:03:46 -08:00
|
|
|
case NS_WILL_PAINT:
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-07-21 17:44:59 -07:00
|
|
|
if (!aView || !mContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
2012-07-03 16:36:38 -07:00
|
|
|
|
|
|
|
nsPaintEvent *event = static_cast<nsPaintEvent*>(aEvent);
|
|
|
|
|
|
|
|
NS_ASSERTION(static_cast<nsView*>(aView) ==
|
|
|
|
nsView::GetViewFor(event->widget),
|
|
|
|
"view/widget mismatch");
|
|
|
|
|
|
|
|
// If an ancestor widget was hidden and then shown, we could
|
|
|
|
// have a delayed resize to handle.
|
|
|
|
for (nsViewManager *vm = this; vm;
|
|
|
|
vm = vm->mRootView->GetParent()
|
|
|
|
? vm->mRootView->GetParent()->GetViewManager()
|
|
|
|
: nsnull) {
|
|
|
|
if (vm->mDelayedResize != nsSize(NSCOORD_NONE, NSCOORD_NONE) &&
|
|
|
|
vm->mRootView->IsEffectivelyVisible() &&
|
|
|
|
mPresShell && mPresShell->IsVisible()) {
|
|
|
|
vm->FlushDelayedResize(true);
|
|
|
|
vm->InvalidateView(vm->mRootView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flush things like reflows and plugin widget geometry updates by
|
|
|
|
// calling WillPaint on observer presShells.
|
|
|
|
nsRefPtr<nsViewManager> rootVM = RootViewManager();
|
|
|
|
if (mPresShell) {
|
|
|
|
rootVM->CallWillPaintOnObservers(event->willSendDidPaint);
|
|
|
|
}
|
|
|
|
// Flush view widget geometry updates and invalidations.
|
|
|
|
rootVM->ProcessPendingUpdates();
|
2011-12-23 19:52:24 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_PAINT:
|
|
|
|
{
|
|
|
|
if (!aView || !mContext)
|
|
|
|
break;
|
|
|
|
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
nsPaintEvent *event = static_cast<nsPaintEvent*>(aEvent);
|
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
|
|
|
NS_ASSERTION(view == nsView::GetViewFor(event->widget),
|
|
|
|
"view/widget mismatch");
|
|
|
|
NS_ASSERTION(IsPaintingAllowed(),
|
|
|
|
"shouldn't be receiving paint events while painting is "
|
|
|
|
"disallowed!");
|
|
|
|
|
2012-07-03 16:36:38 -07:00
|
|
|
if (!event->didSendWillPaint) {
|
|
|
|
// Send NS_WILL_PAINT event ourselves.
|
|
|
|
nsPaintEvent willPaintEvent(true, NS_WILL_PAINT, event->widget);
|
|
|
|
willPaintEvent.willSendDidPaint = event->willSendDidPaint;
|
|
|
|
DispatchEvent(&willPaintEvent, view, aStatus);
|
|
|
|
|
|
|
|
// Get the view pointer again since NS_WILL_PAINT might have
|
|
|
|
// destroyed it during CallWillPaintOnObservers (bug 378273).
|
|
|
|
view = nsView::GetViewFor(event->widget);
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:24 -08:00
|
|
|
if (!view || event->region.IsEmpty())
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Paint.
|
2012-07-03 17:25:57 -07:00
|
|
|
Refresh(view, event->widget, event->region, event->willSendDidPaint);
|
2011-12-23 19:52:24 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:08 -07:00
|
|
|
case NS_DID_PAINT: {
|
2012-07-03 16:36:38 -07:00
|
|
|
nsRefPtr<nsViewManager> rootVM = RootViewManager();
|
|
|
|
rootVM->CallDidPaintOnObserver();
|
2010-07-15 14:08:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_CREATE:
|
|
|
|
case NS_DESTROY:
|
|
|
|
case NS_SETZLEVEL:
|
|
|
|
/* Don't pass these events through. Passing them through
|
|
|
|
causes performance problems on pages with lots of views/frames
|
|
|
|
@see bug 112861 */
|
|
|
|
*aStatus = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_DISPLAYCHANGED:
|
|
|
|
|
|
|
|
//Destroy the cached backbuffer to force a new backbuffer
|
|
|
|
//be constructed with the appropriate display depth.
|
|
|
|
//@see bugzilla bug 6061
|
|
|
|
*aStatus = nsEventStatus_eConsumeDoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_SYSCOLORCHANGED:
|
|
|
|
{
|
2011-11-21 09:53:20 -08:00
|
|
|
if (mPresShell) {
|
|
|
|
// Hold a refcount to the presshell. The continued existence of the observer will
|
|
|
|
// delay deletion of this view hierarchy should the event want to cause its
|
|
|
|
// destruction in, say, some JavaScript event handler.
|
|
|
|
nsCOMPtr<nsIPresShell> presShell = mPresShell;
|
|
|
|
presShell->HandleEvent(aView->GetFrame(), aEvent, false, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if ((NS_IS_MOUSE_EVENT(aEvent) &&
|
2010-03-23 20:36:27 -07:00
|
|
|
// Ignore mouse events that we synthesize.
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsMouseEvent*>(aEvent)->reason ==
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent::eReal &&
|
|
|
|
// Ignore mouse exit and enter (we'll get moves if the user
|
|
|
|
// is really moving the mouse) since we get them when we
|
|
|
|
// create and destroy widgets.
|
|
|
|
aEvent->message != NS_MOUSE_EXIT &&
|
|
|
|
aEvent->message != NS_MOUSE_ENTER) ||
|
|
|
|
NS_IS_KEY_EVENT(aEvent) ||
|
2008-12-14 19:54:54 -08:00
|
|
|
NS_IS_IME_EVENT(aEvent) ||
|
2011-05-10 21:52:44 -07:00
|
|
|
aEvent->message == NS_PLUGIN_INPUT_EVENT) {
|
2007-03-22 10:30:00 -07:00
|
|
|
gLastUserEventTime = PR_IntervalToMicroseconds(PR_IntervalNow());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aEvent->message == NS_DEACTIVATE) {
|
2009-09-13 06:13:16 -07:00
|
|
|
// if a window is deactivated, clear the mouse capture regardless
|
|
|
|
// of what is capturing
|
2011-11-21 09:53:20 -08:00
|
|
|
nsIPresShell::ClearMouseCapture(nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-11-21 09:53:20 -08:00
|
|
|
// Find the view whose coordinates system we're in.
|
|
|
|
nsIView* view = aView;
|
|
|
|
bool dispatchUsingCoordinates = NS_IsEventUsingCoordinates(aEvent);
|
|
|
|
if (dispatchUsingCoordinates) {
|
|
|
|
// Will dispatch using coordinates. Pretty bogus but it's consistent
|
2007-03-22 10:30:00 -07:00
|
|
|
// with what presshell does.
|
2011-11-21 09:53:20 -08:00
|
|
|
view = GetDisplayRootFor(view);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-11-21 09:53:20 -08:00
|
|
|
|
|
|
|
// If the view has no frame, look for a view that does.
|
|
|
|
nsIFrame* frame = view->GetFrame();
|
|
|
|
if (!frame &&
|
|
|
|
(dispatchUsingCoordinates || NS_IS_KEY_EVENT(aEvent) ||
|
|
|
|
NS_IS_IME_RELATED_EVENT(aEvent) ||
|
|
|
|
NS_IS_NON_RETARGETED_PLUGIN_EVENT(aEvent) ||
|
|
|
|
aEvent->message == NS_PLUGIN_ACTIVATE ||
|
|
|
|
aEvent->message == NS_PLUGIN_FOCUS)) {
|
|
|
|
while (view && !view->GetFrame()) {
|
|
|
|
view = view->GetParent();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-21 09:53:20 -08:00
|
|
|
if (view) {
|
|
|
|
frame = view->GetFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != frame) {
|
|
|
|
// Hold a refcount to the presshell. The continued existence of the
|
|
|
|
// presshell will delay deletion of this view hierarchy should the event
|
|
|
|
// want to cause its destruction in, say, some JavaScript event handler.
|
2011-11-21 09:53:20 -08:00
|
|
|
nsCOMPtr<nsIPresShell> shell = view->GetViewManager()->GetPresShell();
|
|
|
|
if (shell) {
|
|
|
|
shell->HandleEvent(frame, aEvent, false, aStatus);
|
2011-11-21 09:53:20 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursively reparent widgets if necessary
|
|
|
|
|
|
|
|
void nsViewManager::ReparentChildWidgets(nsIView* aView, nsIWidget *aNewWidget)
|
|
|
|
{
|
2010-09-18 04:28:50 -07:00
|
|
|
NS_PRECONDITION(aNewWidget, "");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aView->HasWidget()) {
|
|
|
|
// Check to see if the parent widget is the
|
|
|
|
// same as the new parent. If not then reparent
|
|
|
|
// the widget, otherwise there is nothing more
|
|
|
|
// to do for the view and its descendants
|
|
|
|
nsIWidget* widget = aView->GetWidget();
|
|
|
|
nsIWidget* parentWidget = widget->GetParent();
|
2010-09-18 04:28:50 -07:00
|
|
|
if (parentWidget) {
|
|
|
|
// Child widget
|
|
|
|
if (parentWidget != aNewWidget) {
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2010-09-18 04:28:50 -07:00
|
|
|
nsresult rv =
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2010-09-18 04:28:50 -07:00
|
|
|
widget->SetParent(aNewWidget);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "SetParent failed!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Toplevel widget (popup, dialog, etc)
|
|
|
|
widget->ReparentNativeWidget(aNewWidget);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to check each of the views children to see
|
|
|
|
// if they have a widget and reparent it.
|
|
|
|
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2007-03-22 10:30:00 -07:00
|
|
|
for (nsView *kid = view->GetFirstChild(); kid; kid = kid->GetNextSibling()) {
|
|
|
|
ReparentChildWidgets(kid, aNewWidget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reparent a view and its descendant views widgets if necessary
|
|
|
|
|
|
|
|
void nsViewManager::ReparentWidgets(nsIView* aView, nsIView *aParent)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aParent, "Must have a parent");
|
|
|
|
NS_PRECONDITION(aView, "Must have a view");
|
|
|
|
|
|
|
|
// Quickly determine whether the view has pre-existing children or a
|
|
|
|
// widget. In most cases the view will not have any pre-existing
|
|
|
|
// children when this is called. Only in the case
|
|
|
|
// where a view has been reparented by removing it from
|
|
|
|
// a reinserting it into a new location in the view hierarchy do we
|
|
|
|
// have to consider reparenting the existing widgets for the view and
|
|
|
|
// it's descendants.
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (view->HasWidget() || view->GetFirstChild()) {
|
|
|
|
nsIWidget* parentWidget = aParent->GetNearestWidget(nsnull);
|
|
|
|
if (parentWidget) {
|
|
|
|
ReparentChildWidgets(aView, parentWidget);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_WARNING("Can not find a widget for the parent view");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsViewManager::InsertChild(nsIView *aParent, nsIView *aChild, nsIView *aSibling,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aAfter)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* parent = static_cast<nsView*>(aParent);
|
|
|
|
nsView* child = static_cast<nsView*>(aChild);
|
|
|
|
nsView* sibling = static_cast<nsView*>(aSibling);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_PRECONDITION(nsnull != parent, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != child, "null ptr");
|
|
|
|
NS_ASSERTION(sibling == nsnull || sibling->GetParent() == parent,
|
|
|
|
"tried to insert view with invalid sibling");
|
|
|
|
NS_ASSERTION(!IsViewInserted(child), "tried to insert an already-inserted view");
|
|
|
|
|
|
|
|
if ((nsnull != parent) && (nsnull != child))
|
|
|
|
{
|
|
|
|
// if aAfter is set, we will insert the child after 'prev' (i.e. after 'kid' in document
|
|
|
|
// order, otherwise after 'kid' (i.e. before 'kid' in document order).
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
if (nsnull == aSibling) {
|
|
|
|
if (aAfter) {
|
|
|
|
// insert at end of document order, i.e., before first view
|
|
|
|
// this is the common case, by far
|
|
|
|
parent->InsertChild(child, nsnull);
|
|
|
|
ReparentWidgets(child, parent);
|
|
|
|
} else {
|
|
|
|
// insert at beginning of document order, i.e., after last view
|
|
|
|
nsView *kid = parent->GetFirstChild();
|
|
|
|
nsView *prev = nsnull;
|
|
|
|
while (kid) {
|
|
|
|
prev = kid;
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
// prev is last view or null if there are no children
|
|
|
|
parent->InsertChild(child, prev);
|
|
|
|
ReparentWidgets(child, parent);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nsView *kid = parent->GetFirstChild();
|
|
|
|
nsView *prev = nsnull;
|
|
|
|
while (kid && sibling != kid) {
|
|
|
|
//get the next sibling view
|
|
|
|
prev = kid;
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
NS_ASSERTION(kid != nsnull,
|
|
|
|
"couldn't find sibling in child list");
|
|
|
|
if (aAfter) {
|
|
|
|
// insert after 'kid' in document order, i.e. before in view order
|
|
|
|
parent->InsertChild(child, prev);
|
|
|
|
ReparentWidgets(child, parent);
|
|
|
|
} else {
|
|
|
|
// insert before 'kid' in document order, i.e. after in view order
|
|
|
|
parent->InsertChild(child, kid);
|
|
|
|
ReparentWidgets(child, parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else // don't keep consistent document order, but order things by z-index instead
|
|
|
|
// essentially we're emulating the old InsertChild(parent, child, zindex)
|
|
|
|
PRInt32 zIndex = child->GetZIndex();
|
|
|
|
while (nsnull != kid)
|
|
|
|
{
|
|
|
|
PRInt32 idx = kid->GetZIndex();
|
|
|
|
|
|
|
|
if (CompareZIndex(zIndex, child->IsTopMost(), child->GetZIndexIsAuto(),
|
|
|
|
idx, kid->IsTopMost(), kid->GetZIndexIsAuto()) >= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
prev = kid;
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->InsertChild(child, prev);
|
|
|
|
ReparentWidgets(child, parent);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// if the parent view is marked as "floating", make the newly added view float as well.
|
|
|
|
if (parent->GetFloating())
|
2011-10-17 07:59:28 -07:00
|
|
|
child->SetFloating(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//and mark this area as dirty if the view is visible...
|
|
|
|
|
|
|
|
if (nsViewVisibility_kHide != child->GetVisibility())
|
2011-12-23 19:52:25 -08:00
|
|
|
child->GetViewManager()->InvalidateView(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsViewManager::InsertChild(nsIView *aParent, nsIView *aChild, PRInt32 aZIndex)
|
|
|
|
{
|
|
|
|
// no-one really calls this with anything other than aZIndex == 0 on a fresh view
|
|
|
|
// XXX this method should simply be eliminated and its callers redirected to the real method
|
2011-10-17 07:59:28 -07:00
|
|
|
SetViewZIndex(aChild, false, aZIndex, false);
|
|
|
|
return InsertChild(aParent, aChild, nsnull, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsViewManager::RemoveChild(nsIView *aChild)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* child = static_cast<nsView*>(aChild);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(child);
|
|
|
|
|
|
|
|
nsView* parent = child->GetParent();
|
|
|
|
|
2010-07-18 19:23:47 -07:00
|
|
|
if (nsnull != parent) {
|
|
|
|
NS_ASSERTION(child->GetViewManager() == this ||
|
|
|
|
parent->GetViewManager() == this, "wrong view manager");
|
2011-12-23 19:52:25 -08:00
|
|
|
child->GetViewManager()->InvalidateView(child);
|
2010-07-18 19:23:47 -07:00
|
|
|
parent->RemoveChild(child);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsViewManager::MoveViewTo(nsIView *aView, nscoord aX, nscoord aY)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2010-07-18 19:23:47 -07:00
|
|
|
NS_ASSERTION(view->GetViewManager() == this, "wrong view manager");
|
2007-03-22 10:30:00 -07:00
|
|
|
nsPoint oldPt = view->GetPosition();
|
2010-07-18 19:23:47 -07:00
|
|
|
nsRect oldBounds = view->GetBoundsInParentUnits();
|
2007-03-22 10:30:00 -07:00
|
|
|
view->SetPosition(aX, aY);
|
|
|
|
|
|
|
|
// only do damage control if the view is visible
|
|
|
|
|
|
|
|
if ((aX != oldPt.x) || (aY != oldPt.y)) {
|
|
|
|
if (view->GetVisibility() != nsViewVisibility_kHide) {
|
|
|
|
nsView* parentView = view->GetParent();
|
2010-07-18 19:23:47 -07:00
|
|
|
if (parentView) {
|
|
|
|
nsViewManager* parentVM = parentView->GetViewManager();
|
2011-12-23 19:52:25 -08:00
|
|
|
parentVM->InvalidateView(parentView, oldBounds);
|
|
|
|
parentVM->InvalidateView(parentView, view->GetBoundsInParentUnits());
|
2010-07-18 19:23:47 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsViewManager::InvalidateHorizontalBandDifference(nsView *aView, const nsRect& aRect, const nsRect& aCutOut,
|
2011-12-23 19:52:22 -08:00
|
|
|
nscoord aY1, nscoord aY2, bool aInCutOut) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord height = aY2 - aY1;
|
|
|
|
if (aRect.x < aCutOut.x) {
|
|
|
|
nsRect r(aRect.x, aY1, aCutOut.x - aRect.x, height);
|
2011-12-23 19:52:25 -08:00
|
|
|
InvalidateView(aView, r);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (!aInCutOut && aCutOut.x < aCutOut.XMost()) {
|
|
|
|
nsRect r(aCutOut.x, aY1, aCutOut.width, height);
|
2011-12-23 19:52:25 -08:00
|
|
|
InvalidateView(aView, r);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aCutOut.XMost() < aRect.XMost()) {
|
|
|
|
nsRect r(aCutOut.XMost(), aY1, aRect.XMost() - aCutOut.XMost(), height);
|
2011-12-23 19:52:25 -08:00
|
|
|
InvalidateView(aView, r);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:22 -08:00
|
|
|
void nsViewManager::InvalidateRectDifference(nsView *aView, const nsRect& aRect, const nsRect& aCutOut) {
|
2011-02-10 14:38:37 -08:00
|
|
|
NS_ASSERTION(aView->GetViewManager() == this,
|
|
|
|
"InvalidateRectDifference called on view we don't own");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aRect.y < aCutOut.y) {
|
2011-12-23 19:52:22 -08:00
|
|
|
InvalidateHorizontalBandDifference(aView, aRect, aCutOut, aRect.y, aCutOut.y, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aCutOut.y < aCutOut.YMost()) {
|
2011-12-23 19:52:22 -08:00
|
|
|
InvalidateHorizontalBandDifference(aView, aRect, aCutOut, aCutOut.y, aCutOut.YMost(), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (aCutOut.YMost() < aRect.YMost()) {
|
2011-12-23 19:52:22 -08:00
|
|
|
InvalidateHorizontalBandDifference(aView, aRect, aCutOut, aCutOut.YMost(), aRect.YMost(), false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::ResizeView(nsIView *aView, const nsRect &aRect, bool aRepaintExposedAreaOnly)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2010-07-18 19:23:47 -07:00
|
|
|
NS_ASSERTION(view->GetViewManager() == this, "wrong view manager");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-11 08:49:16 -07:00
|
|
|
nsRect oldDimensions = view->GetDimensions();
|
2011-04-18 20:07:23 -07:00
|
|
|
if (!oldDimensions.IsEqualEdges(aRect)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// resize the view.
|
|
|
|
// Prevent Invalidation of hidden views
|
|
|
|
if (view->GetVisibility() == nsViewVisibility_kHide) {
|
2011-10-17 07:59:28 -07:00
|
|
|
view->SetDimensions(aRect, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2011-02-10 14:38:37 -08:00
|
|
|
nsView* parentView = view->GetParent();
|
|
|
|
if (!parentView) {
|
|
|
|
parentView = view;
|
|
|
|
}
|
2010-07-18 19:23:47 -07:00
|
|
|
nsRect oldBounds = view->GetBoundsInParentUnits();
|
2011-10-17 07:59:28 -07:00
|
|
|
view->SetDimensions(aRect, true);
|
2011-02-10 14:38:37 -08:00
|
|
|
nsViewManager* parentVM = parentView->GetViewManager();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aRepaintExposedAreaOnly) {
|
2011-12-23 19:52:25 -08:00
|
|
|
// Invalidate the union of the old and new size
|
|
|
|
InvalidateView(view, aRect);
|
|
|
|
parentVM->InvalidateView(parentView, oldBounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2011-12-23 19:52:22 -08:00
|
|
|
InvalidateRectDifference(view, aRect, oldDimensions);
|
2010-07-18 19:23:47 -07:00
|
|
|
nsRect newBounds = view->GetBoundsInParentUnits();
|
2011-12-23 19:52:22 -08:00
|
|
|
parentVM->InvalidateRectDifference(parentView, oldBounds, newBounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that if layout resizes the view and the view has a custom clip
|
|
|
|
// region set, then we expect layout to update the clip region too. Thus
|
|
|
|
// in the case where mClipRect has been optimized away to just be a null
|
|
|
|
// pointer, and this resize is implicitly changing the clip rect, it's OK
|
|
|
|
// because layout will change it back again if necessary.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::SetViewFloating(nsIView *aView, bool aFloating)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(!(nsnull == view), "no view");
|
|
|
|
|
|
|
|
view->SetFloating(aFloating);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsViewManager::SetViewVisibility(nsIView *aView, nsViewVisibility aVisible)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2010-07-18 19:23:47 -07:00
|
|
|
NS_ASSERTION(view->GetViewManager() == this, "wrong view manager");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aVisible != view->GetVisibility()) {
|
|
|
|
view->SetVisibility(aVisible);
|
|
|
|
|
|
|
|
if (IsViewInserted(view)) {
|
|
|
|
if (!view->HasWidget()) {
|
|
|
|
if (nsViewVisibility_kHide == aVisible) {
|
|
|
|
nsView* parentView = view->GetParent();
|
|
|
|
if (parentView) {
|
2010-07-18 19:23:47 -07:00
|
|
|
parentView->GetViewManager()->
|
2011-12-23 19:52:25 -08:00
|
|
|
InvalidateView(parentView, view->GetBoundsInParentUnits());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-12-23 19:52:25 -08:00
|
|
|
InvalidateView(view);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsViewManager::IsViewInserted(nsView *aView)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mRootView == aView) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else if (aView->GetParent() == nsnull) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
nsView* view = aView->GetParent()->GetFirstChild();
|
|
|
|
while (view != nsnull) {
|
|
|
|
if (view == aView) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
view = view->GetNextSibling();
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::SetViewZIndex(nsIView *aView, bool aAutoZIndex, PRInt32 aZIndex, bool aTopMost)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsView* view = static_cast<nsView*>(aView);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_ASSERTION((view != nsnull), "no view");
|
|
|
|
|
|
|
|
// don't allow the root view's z-index to be changed. It should always be zero.
|
|
|
|
// This could be removed and replaced with a style rule, or just removed altogether, with interesting consequences
|
|
|
|
if (aView == mRootView) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool oldTopMost = view->IsTopMost();
|
|
|
|
bool oldIsAuto = view->GetZIndexIsAuto();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aAutoZIndex) {
|
|
|
|
aZIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 oldidx = view->GetZIndex();
|
|
|
|
view->SetZIndex(aAutoZIndex, aZIndex, aTopMost);
|
|
|
|
|
|
|
|
if (oldidx != aZIndex || oldTopMost != aTopMost ||
|
|
|
|
oldIsAuto != aAutoZIndex) {
|
2011-12-23 19:52:25 -08:00
|
|
|
InvalidateView(view);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-04-16 18:22:44 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::GetDeviceContext(nsDeviceContext *&aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aContext = mContext;
|
2011-09-16 13:22:44 -07:00
|
|
|
NS_IF_ADDREF(aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
nsIViewManager*
|
|
|
|
nsViewManager::IncrementDisableRefreshCount()
|
2011-12-23 22:21:58 -08:00
|
|
|
{
|
|
|
|
if (!IsRootVM()) {
|
2011-12-23 19:52:23 -08:00
|
|
|
return RootViewManager()->IncrementDisableRefreshCount();
|
2011-12-23 22:21:58 -08:00
|
|
|
}
|
2011-12-23 19:52:23 -08:00
|
|
|
|
|
|
|
++mRefreshDisableCount;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-26 15:59:50 -08:00
|
|
|
return this;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
void
|
|
|
|
nsViewManager::DecrementDisableRefreshCount()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-26 15:59:50 -08:00
|
|
|
NS_ASSERTION(IsRootVM(), "Should only be called on root");
|
2011-12-23 19:52:23 -08:00
|
|
|
--mRefreshDisableCount;
|
|
|
|
NS_ASSERTION(mRefreshDisableCount >= 0, "Invalid refresh disable count!");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-21 17:45:03 -07:00
|
|
|
NS_IMETHODIMP nsViewManager::GetRootWidget(nsIWidget **aWidget)
|
|
|
|
{
|
|
|
|
if (!mRootView) {
|
|
|
|
*aWidget = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (mRootView->HasWidget()) {
|
|
|
|
*aWidget = mRootView->GetWidget();
|
|
|
|
NS_ADDREF(*aWidget);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (mRootView->GetParent())
|
|
|
|
return mRootView->GetParent()->GetViewManager()->GetRootWidget(aWidget);
|
|
|
|
*aWidget = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-02 12:11:04 -07:00
|
|
|
nsIntRect nsViewManager::ViewToWidget(nsView *aView, const nsRect &aRect) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-02 12:11:04 -07:00
|
|
|
NS_ASSERTION(aView->GetViewManager() == this, "wrong view manager");
|
|
|
|
|
|
|
|
// account for the view's origin not lining up with the widget's
|
2012-05-03 09:33:51 -07:00
|
|
|
nsRect rect = aRect + aView->ViewToWidgetOffset();
|
2007-06-27 23:02:05 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// finally, convert to device coordinates.
|
2010-06-05 13:29:49 -07:00
|
|
|
return rect.ToOutsidePixels(AppUnitsPerDevPixel());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsViewManager::IsPainting(bool& aIsPainting)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aIsPainting = IsPainting();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-03 17:14:47 -07:00
|
|
|
void
|
2011-12-23 19:52:22 -08:00
|
|
|
nsViewManager::ProcessPendingUpdates()
|
|
|
|
{
|
2011-12-23 19:52:23 -08:00
|
|
|
if (!IsRootVM()) {
|
2012-07-03 17:14:47 -07:00
|
|
|
RootViewManager()->ProcessPendingUpdates();
|
|
|
|
return;
|
2011-12-23 19:52:23 -08:00
|
|
|
}
|
2010-08-05 11:39:39 -07:00
|
|
|
|
2012-07-03 17:24:55 -07:00
|
|
|
if (mHasPendingUpdates) {
|
|
|
|
ProcessPendingUpdatesForView(mRootView, true);
|
|
|
|
mHasPendingUpdates = false;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-23 19:52:23 -08:00
|
|
|
void
|
|
|
|
nsViewManager::UpdateWidgetGeometry()
|
|
|
|
{
|
|
|
|
if (!IsRootVM()) {
|
|
|
|
RootViewManager()->UpdateWidgetGeometry();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mHasPendingWidgetGeometryChanges) {
|
|
|
|
ProcessPendingUpdatesForView(mRootView, false);
|
|
|
|
mHasPendingWidgetGeometryChanges = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-16 03:55:19 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsViewManager::CallWillPaintOnObservers(bool aWillSendDidPaint)
|
2009-10-16 03:55:19 -07:00
|
|
|
{
|
2010-07-15 14:08:08 -07:00
|
|
|
NS_PRECONDITION(IsRootVM(), "Must be root VM for this to be called!");
|
2009-10-16 03:55:19 -07:00
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = 0; index < mVMCount; index++) {
|
|
|
|
nsViewManager* vm = (nsViewManager*)gViewManagers->ElementAt(index);
|
|
|
|
if (vm->RootViewManager() == this) {
|
|
|
|
// One of our kids.
|
2010-09-11 11:24:50 -07:00
|
|
|
if (vm->mRootView && vm->mRootView->IsEffectivelyVisible()) {
|
2011-11-21 09:53:20 -08:00
|
|
|
nsCOMPtr<nsIPresShell> shell = vm->GetPresShell();
|
|
|
|
if (shell) {
|
|
|
|
shell->WillPaint(aWillSendDidPaint);
|
2010-09-11 11:24:50 -07:00
|
|
|
}
|
2009-10-16 03:55:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:08 -07:00
|
|
|
void
|
2012-01-27 19:36:23 -08:00
|
|
|
nsViewManager::CallDidPaintOnObserver()
|
2010-07-15 14:08:08 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(IsRootVM(), "Must be root VM for this to be called!");
|
|
|
|
|
2012-01-27 19:36:23 -08:00
|
|
|
if (mRootView && mRootView->IsEffectivelyVisible()) {
|
|
|
|
nsCOMPtr<nsIPresShell> shell = GetPresShell();
|
|
|
|
if (shell) {
|
|
|
|
shell->DidPaint();
|
2010-07-15 14:08:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsViewManager::GetLastUserEventTime(PRUint32& aTime)
|
|
|
|
{
|
|
|
|
aTime = gLastUserEventTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsViewManager::InvalidateHierarchy()
|
|
|
|
{
|
|
|
|
if (mRootView) {
|
|
|
|
if (!IsRootVM()) {
|
|
|
|
NS_RELEASE(mRootViewManager);
|
|
|
|
}
|
|
|
|
nsView *parent = mRootView->GetParent();
|
|
|
|
if (parent) {
|
|
|
|
mRootViewManager = parent->GetViewManager()->RootViewManager();
|
|
|
|
NS_ADDREF(mRootViewManager);
|
|
|
|
NS_ASSERTION(mRootViewManager != this,
|
|
|
|
"Root view had a parent, but it has the same view manager");
|
|
|
|
} else {
|
|
|
|
mRootViewManager = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|