2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
#include "nsView.h"
|
2013-01-03 17:23:08 +04:00
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-03-28 00:38:33 +04:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2013-05-07 22:48:59 +04:00
|
|
|
#include "mozilla/Poison.h"
|
2019-04-06 09:02:28 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIWidget.h"
|
2001-11-07 07:05:38 +03:00
|
|
|
#include "nsViewManager.h"
|
2012-08-15 22:52:42 +04:00
|
|
|
#include "nsIFrame.h"
|
2013-04-29 16:11:04 +04:00
|
|
|
#include "nsPresArena.h"
|
2012-08-15 22:52:42 +04:00
|
|
|
#include "nsXULPopupManager.h"
|
|
|
|
#include "nsIWidgetListener.h"
|
2014-03-07 07:24:32 +04:00
|
|
|
#include "nsContentUtils.h" // for nsAutoScriptBlocker
|
2015-08-25 08:51:58 +03:00
|
|
|
#include "mozilla/TimelineConsumers.h"
|
2015-10-28 13:00:52 +03:00
|
|
|
#include "mozilla/CompositeTimelineMarker.h"
|
1998-11-24 02:50:17 +03:00
|
|
|
|
2012-12-02 12:56:54 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2016-12-20 02:34:00 +03:00
|
|
|
static bool sShowPreviousPage = true;
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::nsView(nsViewManager* aViewManager, nsViewVisibility aVisibility)
|
2017-01-24 19:10:01 +03:00
|
|
|
: mViewManager(aViewManager),
|
|
|
|
mParent(nullptr),
|
|
|
|
mNextSibling(nullptr),
|
|
|
|
mFirstChild(nullptr),
|
|
|
|
mFrame(nullptr),
|
|
|
|
mDirtyRegion(nullptr),
|
|
|
|
mZIndex(0),
|
|
|
|
mVis(aVisibility),
|
|
|
|
mPosX(0),
|
|
|
|
mPosY(0),
|
|
|
|
mVFlags(0),
|
|
|
|
mWidgetIsTopLevel(false),
|
|
|
|
mForcedRepaint(false),
|
|
|
|
mNeedsWindowPropertiesSync(false) {
|
2013-01-03 17:23:11 +04:00
|
|
|
MOZ_COUNT_CTOR(nsView);
|
1999-10-05 18:52:53 +04:00
|
|
|
|
2002-10-11 05:23:13 +04:00
|
|
|
// 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.
|
2016-12-20 02:34:00 +03:00
|
|
|
|
|
|
|
static bool sShowPreviousPageInitialized = false;
|
|
|
|
if (!sShowPreviousPageInitialized) {
|
|
|
|
Preferences::AddBoolVarCache(&sShowPreviousPage,
|
|
|
|
"layout.show_previous_page", true);
|
|
|
|
sShowPreviousPageInitialized = true;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::DropMouseGrabbing() {
|
2011-11-21 21:53:20 +04:00
|
|
|
nsIPresShell* presShell = mViewManager->GetPresShell();
|
|
|
|
if (presShell) presShell->ClearMouseCaptureOnView(this);
|
2003-02-23 05:53:15 +03:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::~nsView() {
|
|
|
|
MOZ_COUNT_DTOR(nsView);
|
1999-10-05 18:52:53 +04:00
|
|
|
|
2003-02-23 05:53:15 +03:00
|
|
|
while (GetFirstChild()) {
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* child = GetFirstChild();
|
2002-02-20 00:33:26 +03:00
|
|
|
if (child->GetViewManager() == mViewManager) {
|
|
|
|
child->Destroy();
|
|
|
|
} else {
|
|
|
|
// just unhook it. Someone else will want to destroy this.
|
|
|
|
RemoveChild(child);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2003-02-23 05:53:15 +03:00
|
|
|
if (mViewManager) {
|
2004-12-01 06:04:17 +03:00
|
|
|
DropMouseGrabbing();
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2013-01-05 07:13:05 +04:00
|
|
|
nsView* rootView = mViewManager->GetRootView();
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2004-05-17 20:29:13 +04:00
|
|
|
if (rootView) {
|
2002-02-20 00:33:26 +03:00
|
|
|
// Root views can have parents!
|
2003-02-23 05:53:15 +03:00
|
|
|
if (mParent) {
|
2002-02-20 00:33:26 +03:00
|
|
|
mViewManager->RemoveChild(this);
|
|
|
|
}
|
|
|
|
|
2004-05-17 20:29:13 +04:00
|
|
|
if (rootView == this) {
|
|
|
|
// Inform the view manager that the root view has gone away...
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewManager->SetRootView(nullptr);
|
2004-05-17 20:29:13 +04:00
|
|
|
}
|
|
|
|
} else if (mParent) {
|
|
|
|
mParent->RemoveChild(this);
|
|
|
|
}
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewManager = nullptr;
|
2003-02-23 05:53:15 +03:00
|
|
|
} else if (mParent) {
|
1998-05-01 07:13:34 +04:00
|
|
|
mParent->RemoveChild(this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-08-08 08:23:33 +04:00
|
|
|
|
2015-07-22 04:09:02 +03:00
|
|
|
if (mPreviousWindow) {
|
|
|
|
mPreviousWindow->SetPreviouslyAttachedWidgetListener(nullptr);
|
|
|
|
}
|
|
|
|
|
2000-08-12 23:05:52 +04:00
|
|
|
// Destroy and release the widget
|
2011-03-21 21:28:10 +03:00
|
|
|
DestroyWidget();
|
|
|
|
|
2019-02-15 08:07:21 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mFrame);
|
|
|
|
|
2011-03-21 21:28:10 +03:00
|
|
|
delete mDirtyRegion;
|
|
|
|
}
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class DestroyWidgetRunnable : public Runnable {
|
2013-05-28 12:11:11 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit DestroyWidgetRunnable(nsIWidget* aWidget)
|
|
|
|
: mozilla::Runnable("DestroyWidgetRunnable"), mWidget(aWidget) {}
|
2013-05-28 12:11:11 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMETHODIMP DestroyWidgetRunnable::Run() {
|
|
|
|
mWidget->Destroy();
|
|
|
|
mWidget = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::DestroyWidget() {
|
2003-02-23 05:53:15 +03:00
|
|
|
if (mWindow) {
|
2010-06-25 06:01:06 +04: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
|
2015-10-22 00:10:05 +03:00
|
|
|
// Destroy. Just clear our event view ptr and free our reference to it.
|
2010-06-25 06:01:06 +04:00
|
|
|
if (mWidgetIsTopLevel) {
|
2012-08-15 22:53:14 +04:00
|
|
|
mWindow->SetAttachedWidgetListener(nullptr);
|
2010-06-25 06:01:06 +04:00
|
|
|
} else {
|
2012-08-15 22:52:42 +04:00
|
|
|
mWindow->SetWidgetListener(nullptr);
|
2013-05-28 12:11:11 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> widgetDestroyer =
|
|
|
|
new DestroyWidgetRunnable(mWindow);
|
|
|
|
|
2015-10-13 04:41:35 +03:00
|
|
|
// Don't leak if we happen to arrive here after the main thread
|
|
|
|
// has disappeared.
|
|
|
|
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
|
|
|
|
if (mainThread) {
|
|
|
|
mainThread->Dispatch(widgetDestroyer.forget(), NS_DISPATCH_NORMAL);
|
|
|
|
}
|
2010-06-25 06:01:06 +04:00
|
|
|
}
|
|
|
|
|
2015-04-19 21:59:51 +03:00
|
|
|
mWindow = nullptr;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* nsView::GetViewFor(nsIWidget* aWidget) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(nullptr != aWidget, "null widget ptr");
|
2004-09-04 19:49:20 +04:00
|
|
|
|
2012-08-15 22:53:14 +04:00
|
|
|
nsIWidgetListener* listener = aWidget->GetWidgetListener();
|
|
|
|
if (listener) {
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* view = listener->GetView();
|
2012-08-15 22:53:14 +04:00
|
|
|
if (view) return view;
|
2011-12-17 04:24:11 +04:00
|
|
|
}
|
2010-06-25 06:01:06 +04:00
|
|
|
|
2012-08-15 22:53:14 +04:00
|
|
|
listener = aWidget->GetAttachedWidgetListener();
|
|
|
|
return listener ? listener->GetView() : nullptr;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::Destroy() {
|
2013-04-29 16:11:04 +04:00
|
|
|
this->~nsView();
|
2013-05-07 22:48:59 +04:00
|
|
|
mozWritePoison(this, sizeof(*this));
|
2013-04-29 16:11:04 +04:00
|
|
|
nsView::operator delete(this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::SetPosition(nscoord aX, nscoord aY) {
|
2018-01-10 19:16:22 +03:00
|
|
|
mDimBounds.MoveBy(aX - mPosX, aY - mPosY);
|
2002-01-27 10:56:23 +03:00
|
|
|
mPosX = aX;
|
|
|
|
mPosY = aY;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-01-30 06:20:41 +03:00
|
|
|
NS_ASSERTION(GetParent() || (aX == 0 && aY == 0),
|
|
|
|
"Don't try to move the root widget to something non-zero");
|
2004-01-10 08:36:32 +03:00
|
|
|
|
2011-12-24 07:52:23 +04:00
|
|
|
ResetWidgetBounds(true, false);
|
2004-01-10 08:36:32 +03:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::ResetWidgetBounds(bool aRecurse, bool aForceSync) {
|
2004-10-12 00:35:51 +04:00
|
|
|
if (mWindow) {
|
2011-12-24 07:52:23 +04:00
|
|
|
if (!aForceSync) {
|
|
|
|
// Don't change widget geometry synchronously, since that can
|
|
|
|
// cause synchronous painting.
|
2005-01-20 06:39:09 +03:00
|
|
|
mViewManager->PostPendingUpdate();
|
2011-12-24 07:52:23 +04:00
|
|
|
} else {
|
|
|
|
DoResetWidgetBounds(false, true);
|
2004-10-12 00:35:51 +04:00
|
|
|
}
|
2011-12-24 07:52:23 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-10-12 00:35:51 +04:00
|
|
|
|
2011-12-24 07:52:23 +04:00
|
|
|
if (aRecurse) {
|
2005-10-21 06:40:04 +04:00
|
|
|
// reposition any widgets under this view
|
2013-01-03 17:23:11 +04:00
|
|
|
for (nsView* v = GetFirstChild(); v; v = v->GetNextSibling()) {
|
2011-12-24 07:52:23 +04:00
|
|
|
v->ResetWidgetBounds(true, aForceSync);
|
2000-04-03 07:55:38 +04:00
|
|
|
}
|
2005-10-21 06:40:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
bool nsView::IsEffectivelyVisible() {
|
|
|
|
for (nsView* v = this; v; v = v->mParent) {
|
2009-07-30 06:54:42 +04:00
|
|
|
if (v->GetVisibility() == nsViewVisibility_kHide) return false;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-07-30 06:54:42 +04:00
|
|
|
}
|
|
|
|
|
2015-11-16 11:35:18 +03:00
|
|
|
LayoutDeviceIntRect nsView::CalcWidgetBounds(nsWindowType aType) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t p2a = mViewManager->AppUnitsPerDevPixel();
|
2007-05-26 07:45:00 +04:00
|
|
|
|
|
|
|
nsRect viewBounds(mDimBounds);
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* parent = GetParent();
|
2013-07-30 20:22:41 +04:00
|
|
|
nsIWidget* parentWidget = nullptr;
|
2010-07-19 06:23:47 +04:00
|
|
|
if (parent) {
|
2007-05-26 07:45:00 +04:00
|
|
|
nsPoint offset;
|
2013-07-30 20:22:41 +04:00
|
|
|
parentWidget = parent->GetNearestWidget(&offset, p2a);
|
2010-04-23 04:21:54 +04:00
|
|
|
// make viewBounds be relative to the parent widget, in appunits
|
2007-05-26 07:45:00 +04:00
|
|
|
viewBounds += offset;
|
|
|
|
|
2007-06-01 03:23:32 +04:00
|
|
|
if (parentWidget && aType == eWindowType_popup && IsEffectivelyVisible()) {
|
2010-06-25 06:01:06 +04:00
|
|
|
// put offset into screen coordinates. (based on client area origin)
|
2015-02-04 23:21:03 +03:00
|
|
|
LayoutDeviceIntPoint screenPoint = parentWidget->WidgetToScreenOffset();
|
2009-02-19 03:11:49 +03:00
|
|
|
viewBounds += nsPoint(NSIntPixelsToAppUnits(screenPoint.x, p2a),
|
|
|
|
NSIntPixelsToAppUnits(screenPoint.y, p2a));
|
2007-05-26 07:45:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-23 04:21:54 +04:00
|
|
|
// Compute widget bounds in device pixels
|
2015-11-16 11:35:18 +03:00
|
|
|
LayoutDeviceIntRect newBounds =
|
|
|
|
LayoutDeviceIntRect::FromUnknownRect(viewBounds.ToNearestPixels(p2a));
|
2007-05-26 07:45:00 +04:00
|
|
|
|
2018-01-09 13:51:07 +03:00
|
|
|
#if defined(XP_MACOSX) || defined(MOZ_WIDGET_GTK)
|
2015-06-29 18:50:00 +03:00
|
|
|
// cocoa and GTK round widget coordinates to the nearest global "display
|
|
|
|
// pixel" integer value. So we avoid fractional display pixel values by
|
|
|
|
// rounding to the nearest value that won't yield a fractional display pixel.
|
2015-04-19 21:59:51 +03:00
|
|
|
nsIWidget* widget = parentWidget ? parentWidget : mWindow.get();
|
2013-07-30 20:22:41 +04:00
|
|
|
uint32_t round;
|
|
|
|
if (aType == eWindowType_popup && widget &&
|
|
|
|
((round = widget->RoundsWidgetCoordinatesTo()) > 1)) {
|
2015-11-16 11:35:18 +03:00
|
|
|
LayoutDeviceIntSize pixelRoundedSize = newBounds.Size();
|
2013-07-30 20:22:41 +04:00
|
|
|
// round the top left and bottom right to the nearest round pixel
|
|
|
|
newBounds.x =
|
|
|
|
NSToIntRoundUp(NSAppUnitsToDoublePixels(viewBounds.x, p2a) / round) *
|
|
|
|
round;
|
|
|
|
newBounds.y =
|
|
|
|
NSToIntRoundUp(NSAppUnitsToDoublePixels(viewBounds.y, p2a) / round) *
|
|
|
|
round;
|
|
|
|
newBounds.width =
|
|
|
|
NSToIntRoundUp(NSAppUnitsToDoublePixels(viewBounds.XMost(), p2a) /
|
|
|
|
round) *
|
|
|
|
round -
|
|
|
|
newBounds.x;
|
|
|
|
newBounds.height =
|
|
|
|
NSToIntRoundUp(NSAppUnitsToDoublePixels(viewBounds.YMost(), p2a) /
|
|
|
|
round) *
|
|
|
|
round -
|
|
|
|
newBounds.y;
|
|
|
|
// but if that makes the widget larger then our frame may not paint the
|
|
|
|
// extra pixels, so reduce the size to the nearest round value
|
|
|
|
if (newBounds.width > pixelRoundedSize.width) {
|
|
|
|
newBounds.width -= round;
|
|
|
|
}
|
|
|
|
if (newBounds.height > pixelRoundedSize.height) {
|
|
|
|
newBounds.height -= round;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-19 06:23:47 +04:00
|
|
|
// Compute where the top-left of our widget ended up relative to the parent
|
|
|
|
// widget, in appunits.
|
2018-01-10 19:16:22 +03:00
|
|
|
nsPoint roundedOffset(NSIntPixelsToAppUnits(newBounds.X(), p2a),
|
|
|
|
NSIntPixelsToAppUnits(newBounds.Y(), p2a));
|
2010-04-23 04:21:54 +04: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-26 07:45:00 +04:00
|
|
|
|
|
|
|
return newBounds;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::DoResetWidgetBounds(bool aMoveOnly, bool aInvalidateChangedSize) {
|
2005-10-21 06:40:04 +04:00
|
|
|
// The geometry of a root view's widget is controlled externally,
|
|
|
|
// NOT by sizing or positioning the view
|
2013-01-05 07:13:05 +04:00
|
|
|
if (mViewManager->GetRootView() == this) {
|
2005-10-21 06:40:04 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-05-02 01:21:32 +04:00
|
|
|
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(mWindow, "Why was this called??");
|
2013-05-02 01:21:32 +04:00
|
|
|
|
2013-05-02 01:21:33 +04:00
|
|
|
// Hold this ref to make sure it stays alive.
|
|
|
|
nsCOMPtr<nsIWidget> widget = mWindow;
|
|
|
|
|
|
|
|
// Stash a copy of these and use them so we can handle this being deleted (say
|
|
|
|
// from sync painting/flushing from Show/Move/Resize on the widget).
|
2015-11-26 07:55:36 +03:00
|
|
|
LayoutDeviceIntRect newBounds;
|
2013-05-02 01:21:33 +04:00
|
|
|
|
2014-03-19 20:48:08 +04:00
|
|
|
nsWindowType type = widget->WindowType();
|
2013-05-02 01:21:32 +04:00
|
|
|
|
2016-08-19 02:03:04 +03:00
|
|
|
LayoutDeviceIntRect curBounds = widget->GetClientBounds();
|
2013-05-02 01:21:33 +04:00
|
|
|
bool invisiblePopup = type == eWindowType_popup &&
|
|
|
|
((curBounds.IsEmpty() && mDimBounds.IsEmpty()) ||
|
|
|
|
mVis == nsViewVisibility_kHide);
|
2010-06-25 06:01:06 +04:00
|
|
|
|
2013-05-02 01:21:33 +04:00
|
|
|
if (invisiblePopup) {
|
2013-05-02 01:21:33 +04:00
|
|
|
// We're going to hit the early exit below, avoid calling CalcWidgetBounds.
|
|
|
|
} else {
|
2015-11-16 11:35:18 +03:00
|
|
|
newBounds = CalcWidgetBounds(type);
|
2018-04-03 22:27:02 +03:00
|
|
|
invisiblePopup = newBounds.IsEmpty();
|
2013-05-02 01:21:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool curVisibility = widget->IsVisible();
|
2019-02-04 09:51:50 +03:00
|
|
|
bool newVisibility = !invisiblePopup && IsEffectivelyVisible();
|
2013-05-02 01:21:33 +04:00
|
|
|
if (curVisibility && !newVisibility) {
|
|
|
|
widget->Show(false);
|
|
|
|
}
|
2006-08-16 05:54:30 +04:00
|
|
|
|
2013-05-02 01:21:33 +04:00
|
|
|
if (invisiblePopup) {
|
2012-09-20 07:12:36 +04:00
|
|
|
// Don't manipulate empty or hidden popup widgets. For example there's no
|
|
|
|
// point moving hidden comboboxes around, or doing X server roundtrips
|
2006-08-16 05:54:30 +04:00
|
|
|
// to compute their true screen position. This could mean that
|
|
|
|
// WidgetToScreen operations on these widgets don't return up-to-date
|
|
|
|
// values, but popup positions aren't reliable anyway because of correction
|
|
|
|
// to be on or off-screen.
|
|
|
|
return;
|
|
|
|
}
|
2000-04-03 07:55:38 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changedPos = curBounds.TopLeft() != newBounds.TopLeft();
|
|
|
|
bool changedSize = curBounds.Size() != newBounds.Size();
|
2004-10-12 00:35:51 +04:00
|
|
|
|
2010-06-25 06:01:06 +04:00
|
|
|
// Child views are never attached to top level widgets, this is safe.
|
2012-12-06 21:31:34 +04:00
|
|
|
|
2015-12-03 16:19:50 +03:00
|
|
|
// Coordinates are converted to desktop pixels for window Move/Resize APIs,
|
2012-12-06 21:31:34 +04:00
|
|
|
// because of the potential for device-pixel coordinate spaces for mixed
|
|
|
|
// hidpi/lodpi screens to overlap each other and result in bad placement
|
|
|
|
// (bug 814434).
|
2018-10-23 15:49:21 +03:00
|
|
|
|
|
|
|
DesktopToLayoutDeviceScale scale = widget->GetDesktopToDeviceScaleByScreen();
|
2012-12-06 21:31:34 +04:00
|
|
|
|
2015-12-03 16:19:50 +03:00
|
|
|
DesktopRect deskRect = newBounds / scale;
|
2005-10-21 06:40:04 +04:00
|
|
|
if (changedPos) {
|
|
|
|
if (changedSize && !aMoveOnly) {
|
2018-01-10 19:16:22 +03:00
|
|
|
widget->ResizeClient(deskRect.X(), deskRect.Y(), deskRect.Width(),
|
2013-05-02 01:21:33 +04:00
|
|
|
deskRect.Height(), aInvalidateChangedSize);
|
2004-10-12 00:35:51 +04:00
|
|
|
} else {
|
2018-01-10 19:16:22 +03:00
|
|
|
widget->MoveClient(deskRect.X(), deskRect.Y());
|
2004-01-10 08:36:32 +03:00
|
|
|
}
|
2005-10-21 06:40:04 +04:00
|
|
|
} else {
|
|
|
|
if (changedSize && !aMoveOnly) {
|
2018-01-10 19:16:22 +03:00
|
|
|
widget->ResizeClient(deskRect.Width(), deskRect.Height(),
|
2013-05-02 01:21:33 +04:00
|
|
|
aInvalidateChangedSize);
|
2005-10-21 06:40:04 +04:00
|
|
|
} // else do nothing!
|
2002-01-27 10:56:23 +03:00
|
|
|
}
|
2013-05-02 01:21:32 +04:00
|
|
|
|
|
|
|
if (!curVisibility && newVisibility) {
|
2013-05-02 01:21:33 +04:00
|
|
|
widget->Show(true);
|
2013-05-02 01:21:32 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::SetDimensions(const nsRect& aRect, bool aPaint,
|
|
|
|
bool aResizeWidget) {
|
2002-01-27 10:56:23 +03:00
|
|
|
nsRect dims = aRect;
|
|
|
|
dims.MoveBy(mPosX, mPosY);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2005-09-30 06:29:43 +04:00
|
|
|
// 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()) {
|
2002-01-27 10:56:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-12 00:35:51 +04:00
|
|
|
mDimBounds = dims;
|
2002-01-27 10:56:23 +03:00
|
|
|
|
2004-10-12 00:35:51 +04:00
|
|
|
if (aResizeWidget) {
|
2011-12-24 07:52:23 +04:00
|
|
|
ResetWidgetBounds(false, false);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::NotifyEffectiveVisibilityChanged(bool aEffectivelyVisible) {
|
2009-07-30 06:54:42 +04:00
|
|
|
if (!aEffectivelyVisible) {
|
2003-02-23 05:53:15 +03:00
|
|
|
DropMouseGrabbing();
|
2001-05-04 07:02:55 +04:00
|
|
|
}
|
|
|
|
|
2013-02-26 01:18:48 +04:00
|
|
|
SetForcedRepaint(true);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != mWindow) {
|
2013-05-02 01:21:32 +04:00
|
|
|
ResetWidgetBounds(false, false);
|
2005-09-30 23:25:42 +04:00
|
|
|
}
|
1998-08-30 23:16:11 +04:00
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
for (nsView* child = mFirstChild; child; child = child->mNextSibling) {
|
2009-07-30 06:54:42 +04:00
|
|
|
if (child->mVis == nsViewVisibility_kHide) {
|
|
|
|
// It was effectively hidden and still is
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Our child is visible if we are
|
|
|
|
child->NotifyEffectiveVisibilityChanged(aEffectivelyVisible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::SetVisibility(nsViewVisibility aVisibility) {
|
2009-07-30 06:54:42 +04:00
|
|
|
mVis = aVisibility;
|
|
|
|
NotifyEffectiveVisibilityChanged(IsEffectivelyVisible());
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::SetFloating(bool aFloatingView) {
|
2000-01-25 04:53:34 +03:00
|
|
|
if (aFloatingView)
|
2001-12-01 17:31:45 +03:00
|
|
|
mVFlags |= NS_VIEW_FLAG_FLOATING;
|
2000-01-25 04:53:34 +03:00
|
|
|
else
|
2001-12-01 17:31:45 +03:00
|
|
|
mVFlags &= ~NS_VIEW_FLAG_FLOATING;
|
2000-01-25 04:53:34 +03:00
|
|
|
}
|
|
|
|
|
2016-04-22 08:17:15 +03:00
|
|
|
void nsView::InvalidateHierarchy() {
|
2013-01-05 07:13:05 +04:00
|
|
|
if (mViewManager->GetRootView() == this) mViewManager->InvalidateHierarchy();
|
2005-05-05 00:22:32 +04:00
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
for (nsView* child = mFirstChild; child; child = child->GetNextSibling())
|
2016-04-22 08:17:15 +03:00
|
|
|
child->InvalidateHierarchy();
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::InsertChild(nsView* aChild, nsView* aSibling) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(nullptr != aChild, "null ptr");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != aChild) {
|
|
|
|
if (nullptr != aSibling) {
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2003-07-03 17:05:57 +04:00
|
|
|
NS_ASSERTION(aSibling->GetParent() == this,
|
|
|
|
"tried to insert view with invalid sibling");
|
1998-08-30 23:16:11 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
// insert after sibling
|
2003-07-03 17:05:57 +04:00
|
|
|
aChild->SetNextSibling(aSibling->GetNextSibling());
|
2001-11-07 07:05:38 +03:00
|
|
|
aSibling->SetNextSibling(aChild);
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
2001-11-07 07:05:38 +03:00
|
|
|
aChild->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = aChild;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-11-07 07:05:38 +03:00
|
|
|
aChild->SetParent(this);
|
2005-05-05 00:22:32 +04:00
|
|
|
|
|
|
|
// If we just inserted a root view, then update the RootViewManager
|
|
|
|
// on all view managers in the new subtree.
|
|
|
|
|
2013-01-05 07:13:23 +04:00
|
|
|
nsViewManager* vm = aChild->GetViewManager();
|
2013-01-05 07:13:05 +04:00
|
|
|
if (vm->GetRootView() == aChild) {
|
2016-04-22 08:17:15 +03:00
|
|
|
aChild->InvalidateHierarchy();
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::RemoveChild(nsView* child) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(nullptr != child, "null ptr");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != child) {
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* prevKid = nullptr;
|
|
|
|
nsView* kid = mFirstChild;
|
2012-12-02 12:56:54 +04:00
|
|
|
DebugOnly<bool> found = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
while (nullptr != kid) {
|
1998-04-14 00:24:54 +04:00
|
|
|
if (kid == child) {
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != prevKid) {
|
2003-07-03 17:05:57 +04:00
|
|
|
prevKid->SetNextSibling(kid->GetNextSibling());
|
1998-04-14 00:24:54 +04:00
|
|
|
} else {
|
2001-11-07 07:05:38 +03:00
|
|
|
mFirstChild = kid->GetNextSibling();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
child->SetParent(nullptr);
|
2011-10-17 18:59:28 +04:00
|
|
|
found = true;
|
1998-04-14 00:24:54 +04:00
|
|
|
break;
|
|
|
|
}
|
1998-05-01 07:13:34 +04:00
|
|
|
prevKid = kid;
|
2001-11-07 07:05:38 +03:00
|
|
|
kid = kid->GetNextSibling();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
NS_ASSERTION(found, "tried to remove non child");
|
2005-05-05 00:22:32 +04:00
|
|
|
|
|
|
|
// If we just removed a root view, then update the RootViewManager
|
|
|
|
// on all view managers in the removed subtree.
|
|
|
|
|
2013-01-05 07:13:23 +04:00
|
|
|
nsViewManager* vm = child->GetViewManager();
|
2013-01-05 07:13:05 +04:00
|
|
|
if (vm->GetRootView() == child) {
|
2016-04-22 08:17:15 +03:00
|
|
|
child->InvalidateHierarchy();
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-27 23:49:47 +03:00
|
|
|
// 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.
|
2013-01-03 17:23:11 +04:00
|
|
|
static void UpdateNativeWidgetZIndexes(nsView* aView, int32_t aZIndex) {
|
2005-01-27 23:49:47 +03:00
|
|
|
if (aView->HasWidget()) {
|
|
|
|
nsIWidget* widget = aView->GetWidget();
|
2014-03-19 20:48:08 +04:00
|
|
|
if (widget->GetZIndex() != aZIndex) {
|
2005-01-27 23:49:47 +03:00
|
|
|
widget->SetZIndex(aZIndex);
|
|
|
|
}
|
|
|
|
} else {
|
2013-01-03 17:23:11 +04:00
|
|
|
for (nsView* v = aView->GetFirstChild(); v; v = v->GetNextSibling()) {
|
2005-01-27 23:49:47 +03:00
|
|
|
if (v->GetZIndexIsAuto()) {
|
|
|
|
UpdateNativeWidgetZIndexes(v, aZIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
static int32_t FindNonAutoZIndex(nsView* aView) {
|
2005-01-27 23:49:47 +03:00
|
|
|
while (aView) {
|
|
|
|
if (!aView->GetZIndexIsAuto()) {
|
|
|
|
return aView->GetZIndex();
|
|
|
|
}
|
|
|
|
aView = aView->GetParent();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-24 10:28:16 +04:00
|
|
|
struct DefaultWidgetInitData : public nsWidgetInitData {
|
|
|
|
DefaultWidgetInitData() : nsWidgetInitData() {
|
|
|
|
mWindowType = eWindowType_child;
|
2011-10-17 18:59:28 +04:00
|
|
|
clipChildren = true;
|
|
|
|
clipSiblings = true;
|
2010-08-24 10:28:16 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsresult nsView::CreateWidget(nsWidgetInitData* aWidgetInitData,
|
2013-01-03 17:23:08 +04:00
|
|
|
bool aEnableDragDrop, bool aResetVisibility) {
|
2010-08-20 23:29:02 +04:00
|
|
|
AssertNoWindow();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
!aWidgetInitData || aWidgetInitData->mWindowType != eWindowType_popup,
|
|
|
|
"Use CreateWidgetForPopup");
|
1998-11-04 07:14:10 +03:00
|
|
|
|
2010-08-24 10:28:16 +04:00
|
|
|
DefaultWidgetInitData defaultInitData;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool initDataPassedIn = !!aWidgetInitData;
|
2010-08-24 10:28:16 +04:00
|
|
|
aWidgetInitData = aWidgetInitData ? aWidgetInitData : &defaultInitData;
|
2010-08-24 11:48:46 +04:00
|
|
|
defaultInitData.mListenForResizes =
|
|
|
|
(!initDataPassedIn && GetParent() &&
|
|
|
|
GetParent()->GetViewManager() != mViewManager);
|
2010-08-20 23:29:01 +04:00
|
|
|
|
2015-11-16 11:35:18 +03:00
|
|
|
LayoutDeviceIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
1998-11-04 07:14:10 +03:00
|
|
|
|
2010-08-20 23:29:02 +04:00
|
|
|
nsIWidget* parentWidget =
|
2012-07-30 18:20:58 +04:00
|
|
|
GetParent() ? GetParent()->GetNearestWidget(nullptr) : nullptr;
|
2010-08-20 23:29:02 +04:00
|
|
|
if (!parentWidget) {
|
2013-01-03 17:23:11 +04:00
|
|
|
NS_ERROR("nsView::CreateWidget without suitable parent widget??");
|
2010-08-20 23:29:02 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-08-20 23:29:02 +04:00
|
|
|
|
2010-08-20 23:29:02 +04:00
|
|
|
// XXX: using aForceUseIWidgetParent=true to preserve previous
|
|
|
|
// semantics. It's not clear that it's actually needed.
|
2015-04-19 21:59:51 +03:00
|
|
|
mWindow = parentWidget->CreateChild(trect, aWidgetInitData, true);
|
2010-08-20 23:29:02 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2010-08-20 23:29:02 +04:00
|
|
|
InitializeWindow(aEnableDragDrop, aResetVisibility);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsresult nsView::CreateWidgetForParent(nsIWidget* aParentWidget,
|
2013-01-03 17:23:08 +04:00
|
|
|
nsWidgetInitData* aWidgetInitData,
|
|
|
|
bool aEnableDragDrop,
|
|
|
|
bool aResetVisibility) {
|
2010-08-20 23:29:02 +04:00
|
|
|
AssertNoWindow();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(
|
|
|
|
!aWidgetInitData || aWidgetInitData->mWindowType != eWindowType_popup,
|
|
|
|
"Use CreateWidgetForPopup");
|
|
|
|
MOZ_ASSERT(aParentWidget, "Parent widget required");
|
2010-08-20 23:29:02 +04:00
|
|
|
|
2010-08-24 10:28:16 +04:00
|
|
|
DefaultWidgetInitData defaultInitData;
|
|
|
|
aWidgetInitData = aWidgetInitData ? aWidgetInitData : &defaultInitData;
|
|
|
|
|
2015-11-16 11:35:18 +03:00
|
|
|
LayoutDeviceIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
2010-08-20 23:29:02 +04:00
|
|
|
|
2015-04-19 21:59:51 +03:00
|
|
|
mWindow = aParentWidget->CreateChild(trect, aWidgetInitData);
|
2010-08-20 23:29:02 +04:00
|
|
|
if (!mWindow) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-08-20 23:29:02 +04:00
|
|
|
|
|
|
|
InitializeWindow(aEnableDragDrop, aResetVisibility);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsresult nsView::CreateWidgetForPopup(nsWidgetInitData* aWidgetInitData,
|
2013-01-03 17:23:08 +04:00
|
|
|
nsIWidget* aParentWidget,
|
|
|
|
bool aEnableDragDrop,
|
|
|
|
bool aResetVisibility) {
|
2010-08-20 23:29:02 +04:00
|
|
|
AssertNoWindow();
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aWidgetInitData, "Widget init data required");
|
|
|
|
MOZ_ASSERT(aWidgetInitData->mWindowType == eWindowType_popup,
|
|
|
|
"Use one of the other CreateWidget methods");
|
2010-08-20 23:29:02 +04:00
|
|
|
|
2015-11-16 11:35:18 +03:00
|
|
|
LayoutDeviceIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
2010-08-20 23:29:02 +04:00
|
|
|
|
|
|
|
// 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 23:29:02 +04:00
|
|
|
// getting rid of aForceUseIWidgetParent.
|
2010-08-20 23:29:02 +04:00
|
|
|
if (aParentWidget) {
|
2010-08-20 23:29:02 +04:00
|
|
|
// XXX: using aForceUseIWidgetParent=true to preserve previous
|
|
|
|
// semantics. It's not clear that it's actually needed.
|
2015-04-19 21:59:51 +03:00
|
|
|
mWindow = aParentWidget->CreateChild(trect, aWidgetInitData, true);
|
2010-08-20 23:29:01 +04:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIWidget* nearestParent =
|
|
|
|
GetParent() ? GetParent()->GetNearestWidget(nullptr) : nullptr;
|
2010-08-20 23:29:02 +04:00
|
|
|
if (!nearestParent) {
|
|
|
|
// Without a parent, we can't make a popup. This can happen
|
|
|
|
// when printing
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-04-19 21:59:51 +03:00
|
|
|
mWindow = nearestParent->CreateChild(trect, aWidgetInitData);
|
2010-08-20 23:29:02 +04:00
|
|
|
}
|
|
|
|
if (!mWindow) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2010-08-20 23:29:01 +04:00
|
|
|
}
|
1998-11-04 07:14:10 +03:00
|
|
|
|
2010-08-20 23:29:01 +04:00
|
|
|
InitializeWindow(aEnableDragDrop, aResetVisibility);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::InitializeWindow(bool aEnableDragDrop, bool aResetVisibility) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mWindow, "Must have a window to initialize");
|
2010-08-20 23:29:01 +04:00
|
|
|
|
2012-08-15 22:53:14 +04:00
|
|
|
mWindow->SetWidgetListener(this);
|
2010-08-20 23:29:02 +04:00
|
|
|
|
2010-08-20 23:29:01 +04:00
|
|
|
if (aEnableDragDrop) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mWindow->EnableDragDrop(true);
|
2010-08-20 23:29:01 +04:00
|
|
|
}
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2010-08-20 23:29:01 +04:00
|
|
|
// propagate the z-index to the widget.
|
|
|
|
UpdateNativeWidgetZIndexes(this, FindNonAutoZIndex(this));
|
|
|
|
|
1998-11-04 07:14:10 +03:00
|
|
|
// make sure visibility state is accurate
|
2007-05-26 07:45:00 +04:00
|
|
|
|
2001-10-31 08:06:31 +03:00
|
|
|
if (aResetVisibility) {
|
2010-08-20 23:29:01 +04:00
|
|
|
SetVisibility(GetVisibility());
|
2003-03-05 17:32:07 +03:00
|
|
|
}
|
1998-11-04 07:14:10 +03:00
|
|
|
}
|
|
|
|
|
2015-05-04 22:29:19 +03:00
|
|
|
void nsView::SetNeedsWindowPropertiesSync() {
|
|
|
|
mNeedsWindowPropertiesSync = true;
|
|
|
|
if (mViewManager) {
|
|
|
|
mViewManager->PostPendingUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-25 06:01:06 +04:00
|
|
|
// Attach to a top level widget and start receiving mirrored events.
|
2013-01-03 17:23:11 +04:00
|
|
|
nsresult nsView::AttachToTopLevelWidget(nsIWidget* aWidget) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(nullptr != aWidget, "null widget ptr");
|
|
|
|
|
2010-06-25 06:01:06 +04:00
|
|
|
/// XXXjimm This is a temporary workaround to an issue w/document
|
|
|
|
// viewer (bug 513162).
|
2012-08-15 22:53:14 +04:00
|
|
|
nsIWidgetListener* listener = aWidget->GetAttachedWidgetListener();
|
|
|
|
if (listener) {
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* oldView = listener->GetView();
|
2012-08-15 22:53:14 +04:00
|
|
|
if (oldView) {
|
|
|
|
oldView->DetachFromTopLevelWidget();
|
|
|
|
}
|
2010-06-25 06:01:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note, the previous device context will be released. Detaching
|
|
|
|
// will not restore the old one.
|
2016-08-10 03:04:08 +03:00
|
|
|
aWidget->AttachViewToTopLevel(!nsIWidget::UsePuppetWidgets());
|
2010-06-25 06:01:06 +04:00
|
|
|
|
|
|
|
mWindow = aWidget;
|
|
|
|
|
2013-01-03 17:23:08 +04:00
|
|
|
mWindow->SetAttachedWidgetListener(this);
|
2017-08-30 21:18:25 +03:00
|
|
|
if (mWindow->WindowType() != eWindowType_invisible) {
|
|
|
|
nsresult rv = mWindow->AsyncEnableDragDrop(true);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mWidgetIsTopLevel = true;
|
2010-06-25 06:01:06 +04:00
|
|
|
|
|
|
|
// Refresh the view bounds
|
2014-03-19 20:48:08 +04:00
|
|
|
CalcWidgetBounds(mWindow->WindowType());
|
2010-06-25 06:01:06 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-22 00:10:05 +03:00
|
|
|
// Detach this view from an attached widget.
|
2013-01-03 17:23:11 +04:00
|
|
|
nsresult nsView::DetachFromTopLevelWidget() {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(mWidgetIsTopLevel, "Not attached currently!");
|
|
|
|
MOZ_ASSERT(mWindow, "null mWindow for DetachFromTopLevelWidget!");
|
2010-06-25 06:01:06 +04:00
|
|
|
|
2012-08-15 22:53:14 +04:00
|
|
|
mWindow->SetAttachedWidgetListener(nullptr);
|
2015-07-22 04:09:02 +03:00
|
|
|
nsIWidgetListener* listener = mWindow->GetPreviouslyAttachedWidgetListener();
|
|
|
|
|
|
|
|
if (listener && listener->GetView()) {
|
|
|
|
// Ensure the listener doesn't think it's being used anymore
|
|
|
|
listener->GetView()->SetPreviousWidget(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the new view's frame is paint suppressed then the window
|
|
|
|
// will want to use us instead until that's done
|
|
|
|
mWindow->SetPreviouslyAttachedWidgetListener(this);
|
|
|
|
|
|
|
|
mPreviousWindow = mWindow;
|
2015-04-19 21:59:51 +03:00
|
|
|
mWindow = nullptr;
|
2010-06-25 06:01:06 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mWidgetIsTopLevel = false;
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2010-06-25 06:01:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-31 01:10:28 +04:00
|
|
|
void nsView::SetZIndex(bool aAuto, int32_t aZIndex) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool oldIsAuto = GetZIndexIsAuto();
|
2001-12-01 17:31:45 +03:00
|
|
|
mVFlags = (mVFlags & ~NS_VIEW_FLAG_AUTO_ZINDEX) |
|
|
|
|
(aAuto ? NS_VIEW_FLAG_AUTO_ZINDEX : 0);
|
|
|
|
mZIndex = aZIndex;
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2005-01-27 23:49:47 +03:00
|
|
|
if (HasWidget() || !oldIsAuto || !aAuto) {
|
|
|
|
UpdateNativeWidgetZIndexes(this, FindNonAutoZIndex(this));
|
2001-12-01 17:31:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::AssertNoWindow() {
|
2010-08-20 23:29:02 +04:00
|
|
|
// XXX: it would be nice to make this a strong assert
|
2012-10-26 17:32:10 +04:00
|
|
|
if (MOZ_UNLIKELY(mWindow)) {
|
2010-08-20 23:29:02 +04:00
|
|
|
NS_ERROR("We already have a window for this view? BAD");
|
2012-08-15 22:52:42 +04:00
|
|
|
mWindow->SetWidgetListener(nullptr);
|
2010-08-20 23:29:02 +04:00
|
|
|
mWindow->Destroy();
|
2015-04-19 21:59:51 +03:00
|
|
|
mWindow = nullptr;
|
2010-08-20 23:29:02 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-08-20 23:29:02 +04:00
|
|
|
//
|
|
|
|
// internal window creation functions
|
|
|
|
//
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::AttachWidgetEventHandler(nsIWidget* aWidget) {
|
2009-07-22 04:45:00 +04:00
|
|
|
#ifdef DEBUG
|
2012-08-15 22:52:42 +04:00
|
|
|
NS_ASSERTION(!aWidget->GetWidgetListener(), "Already have a widget listener");
|
2009-07-22 04:45:00 +04:00
|
|
|
#endif
|
|
|
|
|
2013-01-03 17:23:08 +04:00
|
|
|
aWidget->SetWidgetListener(this);
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::DetachWidgetEventHandler(nsIWidget* aWidget) {
|
2012-08-15 22:53:14 +04:00
|
|
|
NS_ASSERTION(!aWidget->GetWidgetListener() ||
|
|
|
|
aWidget->GetWidgetListener()->GetView() == this,
|
|
|
|
"Wrong view");
|
2012-08-15 22:52:42 +04:00
|
|
|
aWidget->SetWidgetListener(nullptr);
|
2009-07-22 04:45:00 +04:00
|
|
|
}
|
|
|
|
|
2004-01-21 01:15:38 +03:00
|
|
|
#ifdef DEBUG
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::List(FILE* out, int32_t aIndent) const {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i;
|
1998-08-05 13:02:52 +04:00
|
|
|
for (i = aIndent; --i >= 0;) fputs(" ", out);
|
2001-11-07 07:05:38 +03:00
|
|
|
fprintf(out, "%p ", (void*)this);
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != mWindow) {
|
2010-07-19 06:23:47 +04:00
|
|
|
nscoord p2a = mViewManager->AppUnitsPerDevPixel();
|
2016-08-19 02:03:04 +03:00
|
|
|
LayoutDeviceIntRect rect = mWindow->GetClientBounds();
|
2015-11-26 07:32:47 +03:00
|
|
|
nsRect windowBounds = LayoutDeviceIntRect::ToAppUnits(rect, p2a);
|
2016-08-19 02:03:04 +03:00
|
|
|
rect = mWindow->GetBounds();
|
2015-11-26 07:32:47 +03:00
|
|
|
nsRect nonclientBounds = LayoutDeviceIntRect::ToAppUnits(rect, p2a);
|
2015-04-19 21:59:51 +03:00
|
|
|
nsrefcnt widgetRefCnt = mWindow.get()->AddRef() - 1;
|
|
|
|
mWindow.get()->Release();
|
2014-03-19 20:48:08 +04:00
|
|
|
int32_t Z = mWindow->GetZIndex();
|
2014-03-28 00:38:33 +04:00
|
|
|
fprintf(out, "(widget=%p[%" PRIuPTR "] z=%d pos={%d,%d,%d,%d}) ",
|
2005-01-27 23:49:47 +03:00
|
|
|
(void*)mWindow, widgetRefCnt, Z, nonclientBounds.X(),
|
2018-01-10 19:16:22 +03:00
|
|
|
nonclientBounds.Y(), windowBounds.Width(), windowBounds.Height());
|
1998-06-05 00:02:30 +04:00
|
|
|
}
|
2003-07-03 17:05:57 +04:00
|
|
|
nsRect brect = GetBounds();
|
2018-01-10 19:16:22 +03:00
|
|
|
fprintf(out, "{%d,%d,%d,%d}", brect.X(), brect.Y(), brect.Width(),
|
|
|
|
brect.Height());
|
2011-11-21 21:53:20 +04:00
|
|
|
fprintf(out, " z=%d vis=%d frame=%p <\n", mZIndex, mVis,
|
2012-03-31 00:36:43 +04:00
|
|
|
static_cast<void*>(mFrame));
|
2013-01-03 17:23:11 +04:00
|
|
|
for (nsView* kid = mFirstChild; kid; kid = kid->GetNextSibling()) {
|
2004-01-29 03:04:58 +03:00
|
|
|
NS_ASSERTION(kid->GetParent() == this, "incorrect parent");
|
1998-04-14 00:24:54 +04:00
|
|
|
kid->List(out, aIndent + 1);
|
|
|
|
}
|
1998-08-05 13:02:52 +04:00
|
|
|
for (i = aIndent; --i >= 0;) fputs(" ", out);
|
1998-04-14 00:24:54 +04:00
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
2004-01-21 01:15:38 +03:00
|
|
|
#endif // DEBUG
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsPoint nsView::GetOffsetTo(const nsView* aOther) const {
|
2013-01-05 07:13:23 +04:00
|
|
|
return GetOffsetTo(aOther, GetViewManager()->AppUnitsPerDevPixel());
|
2010-07-19 06:23:47 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsPoint nsView::GetOffsetTo(const nsView* aOther, const int32_t aAPD) const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(GetParent() || !aOther || aOther->GetParent() || this == aOther,
|
|
|
|
"caller of (outer) GetOffsetTo must not pass unrelated views");
|
2010-07-19 06:23:47 +04:00
|
|
|
// We accumulate the final result in offset
|
2004-11-03 19:16:57 +03:00
|
|
|
nsPoint offset(0, 0);
|
2010-07-19 06:23:47 +04:00
|
|
|
// The offset currently accumulated at the current APD
|
|
|
|
nsPoint docOffset(0, 0);
|
2013-01-03 17:23:11 +04:00
|
|
|
const nsView* v = this;
|
2013-01-05 07:13:23 +04:00
|
|
|
nsViewManager* currVM = v->GetViewManager();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t currAPD = currVM->AppUnitsPerDevPixel();
|
2013-01-03 17:23:11 +04:00
|
|
|
const nsView* root = nullptr;
|
2010-07-19 06:23:47 +04:00
|
|
|
for (; v != aOther && v; root = v, v = v->GetParent()) {
|
2013-01-05 07:13:23 +04:00
|
|
|
nsViewManager* newVM = v->GetViewManager();
|
2010-07-19 06:23:47 +04:00
|
|
|
if (newVM != currVM) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newAPD = newVM->AppUnitsPerDevPixel();
|
2010-07-19 06:23:47 +04:00
|
|
|
if (newAPD != currAPD) {
|
2015-03-27 00:44:40 +03:00
|
|
|
offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD);
|
2010-07-19 06:23:47 +04:00
|
|
|
docOffset.x = docOffset.y = 0;
|
|
|
|
currAPD = newAPD;
|
|
|
|
}
|
|
|
|
currVM = newVM;
|
|
|
|
}
|
|
|
|
docOffset += v->GetPosition();
|
2004-11-03 19:16:57 +03:00
|
|
|
}
|
2015-03-27 00:44:40 +03:00
|
|
|
offset += docOffset.ScaleToOtherAppUnits(currAPD, aAPD);
|
2004-11-03 19:16:57 +03:00
|
|
|
|
|
|
|
if (v != aOther) {
|
|
|
|
// Looks like aOther wasn't an ancestor of |this|. So now we have
|
2010-07-19 06:23:47 +04: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;
|
2004-11-03 19:16:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsPoint nsView::GetOffsetToWidget(nsIWidget* aWidget) const {
|
2010-07-19 06:23:47 +04:00
|
|
|
nsPoint pt;
|
|
|
|
// Get the view for widget
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* widgetView = GetViewFor(aWidget);
|
2013-01-03 17:23:08 +04:00
|
|
|
if (!widgetView) {
|
2010-07-19 06:23:47 +04:00
|
|
|
return pt;
|
|
|
|
}
|
2010-08-20 23:29:01 +04:00
|
|
|
|
2010-07-19 06:23:47 +04: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.
|
2013-01-03 17:23:08 +04:00
|
|
|
pt = -widgetView->GetOffsetTo(this);
|
2010-07-19 06:23:47 +04:00
|
|
|
// Add in the offset to the widget.
|
|
|
|
pt += widgetView->ViewToWidgetOffset();
|
|
|
|
|
|
|
|
// Convert to our appunits.
|
2013-01-05 07:13:23 +04:00
|
|
|
int32_t widgetAPD = widgetView->GetViewManager()->AppUnitsPerDevPixel();
|
|
|
|
int32_t ourAPD = GetViewManager()->AppUnitsPerDevPixel();
|
2015-03-27 00:44:40 +03:00
|
|
|
pt = pt.ScaleToOtherAppUnits(widgetAPD, ourAPD);
|
2010-07-19 06:23:47 +04:00
|
|
|
return pt;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset) const {
|
2013-01-05 07:13:23 +04:00
|
|
|
return GetNearestWidget(aOffset, GetViewManager()->AppUnitsPerDevPixel());
|
2010-07-19 06:23:47 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsIWidget* nsView::GetNearestWidget(nsPoint* aOffset,
|
|
|
|
const int32_t aAPD) const {
|
2010-06-25 06:01:06 +04:00
|
|
|
// aOffset is based on the view's position, which ignores any chrome on
|
|
|
|
// attached parent widgets.
|
|
|
|
|
2010-07-19 06:23:47 +04:00
|
|
|
// We accumulate the final result in pt
|
2004-01-30 06:20:41 +03:00
|
|
|
nsPoint pt(0, 0);
|
2010-07-19 06:23:47 +04:00
|
|
|
// The offset currently accumulated at the current APD
|
|
|
|
nsPoint docPt(0, 0);
|
2013-01-03 17:23:11 +04:00
|
|
|
const nsView* v = this;
|
2013-01-05 07:13:23 +04:00
|
|
|
nsViewManager* currVM = v->GetViewManager();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t currAPD = currVM->AppUnitsPerDevPixel();
|
2010-07-19 06:23:47 +04:00
|
|
|
for (; v && !v->HasWidget(); v = v->GetParent()) {
|
2013-01-05 07:13:23 +04:00
|
|
|
nsViewManager* newVM = v->GetViewManager();
|
2010-07-19 06:23:47 +04:00
|
|
|
if (newVM != currVM) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newAPD = newVM->AppUnitsPerDevPixel();
|
2010-07-19 06:23:47 +04:00
|
|
|
if (newAPD != currAPD) {
|
2015-03-27 00:44:40 +03:00
|
|
|
pt += docPt.ScaleToOtherAppUnits(currAPD, aAPD);
|
2010-07-19 06:23:47 +04:00
|
|
|
docPt.x = docPt.y = 0;
|
|
|
|
currAPD = newAPD;
|
|
|
|
}
|
|
|
|
currVM = newVM;
|
|
|
|
}
|
|
|
|
docPt += v->GetPosition();
|
2004-01-30 06:20:41 +03:00
|
|
|
}
|
|
|
|
if (!v) {
|
|
|
|
if (aOffset) {
|
2015-03-27 00:44:40 +03:00
|
|
|
pt += docPt.ScaleToOtherAppUnits(currAPD, aAPD);
|
2004-01-30 06:20:41 +03:00
|
|
|
*aOffset = pt;
|
2002-01-27 10:56:23 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1998-06-16 21:05:42 +04:00
|
|
|
}
|
|
|
|
|
2010-07-19 06:23:47 +04: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.
|
2004-01-30 06:20:41 +03:00
|
|
|
if (aOffset) {
|
2010-07-19 06:23:47 +04:00
|
|
|
docPt += v->ViewToWidgetOffset();
|
2015-03-27 00:44:40 +03:00
|
|
|
pt += docPt.ScaleToOtherAppUnits(currAPD, aAPD);
|
2010-07-19 06:23:47 +04:00
|
|
|
*aOffset = pt;
|
2000-01-27 02:04:40 +03:00
|
|
|
}
|
2004-01-30 06:20:41 +03:00
|
|
|
return v->GetWidget();
|
1998-06-16 21:05:42 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
bool nsView::IsRoot() const {
|
|
|
|
NS_ASSERTION(mViewManager != nullptr,
|
|
|
|
" View manager is null in nsView::IsRoot()");
|
2013-01-05 07:13:05 +04:00
|
|
|
return mViewManager->GetRootView() == this;
|
2000-03-24 02:49:18 +03:00
|
|
|
}
|
2000-04-14 01:56:27 +04:00
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsRect nsView::GetBoundsInParentUnits() const {
|
|
|
|
nsView* parent = GetParent();
|
2013-01-05 07:13:23 +04:00
|
|
|
nsViewManager* VM = GetViewManager();
|
2013-01-05 07:13:05 +04:00
|
|
|
if (this != VM->GetRootView() || !parent) {
|
2010-07-19 06:23:47 +04:00
|
|
|
return mDimBounds;
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t ourAPD = VM->AppUnitsPerDevPixel();
|
2013-01-05 07:13:23 +04:00
|
|
|
int32_t parentAPD = parent->GetViewManager()->AppUnitsPerDevPixel();
|
2015-03-27 00:44:40 +03:00
|
|
|
return mDimBounds.ScaleToOtherAppUnitsRoundOut(ourAPD, parentAPD);
|
2010-07-19 06:23:47 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsPoint nsView::ConvertFromParentCoords(nsPoint aPt) const {
|
|
|
|
const nsView* parent = GetParent();
|
2010-07-19 06:23:47 +04:00
|
|
|
if (parent) {
|
2015-03-27 00:44:40 +03:00
|
|
|
aPt = aPt.ScaleToOtherAppUnits(
|
|
|
|
parent->GetViewManager()->AppUnitsPerDevPixel(),
|
|
|
|
GetViewManager()->AppUnitsPerDevPixel());
|
2010-07-19 06:23:47 +04:00
|
|
|
}
|
|
|
|
aPt -= GetPosition();
|
|
|
|
return aPt;
|
|
|
|
}
|
2012-08-15 22:53:14 +04:00
|
|
|
|
|
|
|
static bool IsPopupWidget(nsIWidget* aWidget) {
|
2014-03-19 20:48:08 +04:00
|
|
|
return (aWidget->WindowType() == eWindowType_popup);
|
2012-08-15 22:53:14 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsIPresShell* nsView::GetPresShell() {
|
2012-08-15 22:53:14 +04:00
|
|
|
return GetViewManager()->GetPresShell();
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
bool nsView::WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) {
|
2012-08-15 22:53:14 +04:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm && IsPopupWidget(aWidget)) {
|
|
|
|
pm->PopupMoved(mFrame, nsIntPoint(x, y));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
bool nsView::WindowResized(nsIWidget* aWidget, int32_t aWidth,
|
|
|
|
int32_t aHeight) {
|
2012-08-15 22:53:14 +04:00
|
|
|
// The root view may not be set if this is the resize associated with
|
|
|
|
// window creation
|
2012-08-21 06:40:45 +04:00
|
|
|
SetForcedRepaint(true);
|
2012-08-15 22:53:14 +04:00
|
|
|
if (this == mViewManager->GetRootView()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsDeviceContext> devContext = mViewManager->GetDeviceContext();
|
2013-01-30 16:04:19 +04:00
|
|
|
// ensure DPI is up-to-date, in case of window being opened and sized
|
|
|
|
// on a non-default-dpi display (bug 829963)
|
|
|
|
devContext->CheckDPIChange();
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t p2a = devContext->AppUnitsPerDevPixel();
|
2012-08-15 22:53:14 +04:00
|
|
|
mViewManager->SetWindowDimensions(NSIntPixelsToAppUnits(aWidth, p2a),
|
|
|
|
NSIntPixelsToAppUnits(aHeight, p2a));
|
2014-03-19 20:48:08 +04:00
|
|
|
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
nsIPresShell* presShell = mViewManager->GetPresShell();
|
|
|
|
if (presShell && presShell->GetDocument()) {
|
|
|
|
pm->AdjustPopupsOnWindowChange(presShell);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 22:53:14 +04:00
|
|
|
return true;
|
|
|
|
}
|
2017-02-09 12:42:41 +03:00
|
|
|
if (IsPopupWidget(aWidget)) {
|
2012-08-15 22:53:14 +04:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2015-03-30 18:36:01 +03:00
|
|
|
pm->PopupResized(mFrame, LayoutDeviceIntSize(aWidth, aHeight));
|
2012-08-15 22:53:14 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
bool nsView::RequestWindowClose(nsIWidget* aWidget) {
|
2017-04-30 18:30:08 +03:00
|
|
|
if (mFrame && IsPopupWidget(aWidget) && mFrame->IsMenuPopupFrame()) {
|
2012-08-15 22:53:14 +04:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2014-04-08 16:45:52 +04:00
|
|
|
pm->HidePopup(mFrame->GetContent(), false, true, false, false);
|
2012-08-15 22:53:14 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-28 23:34:08 +04:00
|
|
|
void nsView::WillPaintWindow(nsIWidget* aWidget) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsViewManager> vm = mViewManager;
|
2013-01-28 23:34:08 +04:00
|
|
|
vm->WillPaintWindow(aWidget);
|
2012-08-15 22:53:14 +04:00
|
|
|
}
|
|
|
|
|
2015-12-03 08:45:41 +03:00
|
|
|
bool nsView::PaintWindow(nsIWidget* aWidget, LayoutDeviceIntRegion aRegion) {
|
2013-01-03 17:23:11 +04:00
|
|
|
NS_ASSERTION(this == nsView::GetViewFor(aWidget), "wrong view for widget?");
|
2012-12-13 01:57:08 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsViewManager> vm = mViewManager;
|
2013-05-23 18:49:18 +04:00
|
|
|
bool result = vm->PaintWindow(aWidget, aRegion);
|
2012-10-15 08:53:37 +04:00
|
|
|
return result;
|
2012-08-15 22:53:14 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::DidPaintWindow() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsViewManager> vm = mViewManager;
|
2012-10-22 17:53:31 +04:00
|
|
|
vm->DidPaintWindow();
|
2012-08-15 22:53:14 +04:00
|
|
|
}
|
|
|
|
|
2018-04-20 22:13:06 +03:00
|
|
|
void nsView::DidCompositeWindow(mozilla::layers::TransactionId aTransactionId,
|
2016-04-13 23:59:15 +03:00
|
|
|
const TimeStamp& aCompositeStart,
|
2015-08-25 08:51:58 +03:00
|
|
|
const TimeStamp& aCompositeEnd) {
|
2014-03-07 07:24:32 +04:00
|
|
|
nsIPresShell* presShell = mViewManager->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2015-08-25 08:51:58 +03:00
|
|
|
|
|
|
|
nsPresContext* context = presShell->GetPresContext();
|
2016-01-22 04:09:04 +03:00
|
|
|
nsRootPresContext* rootContext = context->GetRootPresContext();
|
2017-03-24 00:22:26 +03:00
|
|
|
if (rootContext) {
|
|
|
|
rootContext->NotifyDidPaintForSubtree(aTransactionId, aCompositeEnd);
|
|
|
|
}
|
2015-08-25 08:51:58 +03:00
|
|
|
|
|
|
|
// If the two timestamps are identical, this was likely a fake composite
|
|
|
|
// event which wouldn't be terribly useful to display.
|
|
|
|
if (aCompositeStart == aCompositeEnd) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocShell* docShell = context->GetDocShell();
|
2015-10-22 00:10:05 +03:00
|
|
|
RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
|
2015-08-25 08:51:58 +03:00
|
|
|
|
2015-10-22 00:10:05 +03:00
|
|
|
if (timelines && timelines->HasConsumer(docShell)) {
|
|
|
|
timelines->AddMarkerForDocShell(
|
2015-10-28 13:00:52 +03:00
|
|
|
docShell, MakeUnique<CompositeTimelineMarker>(
|
|
|
|
aCompositeStart, MarkerTracingType::START));
|
2015-10-22 00:10:05 +03:00
|
|
|
timelines->AddMarkerForDocShell(
|
2015-10-28 13:00:52 +03:00
|
|
|
docShell, MakeUnique<CompositeTimelineMarker>(
|
|
|
|
aCompositeEnd, MarkerTracingType::END));
|
2015-10-22 00:10:05 +03:00
|
|
|
}
|
2014-03-07 07:24:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::RequestRepaint() {
|
2012-12-18 07:42:02 +04:00
|
|
|
nsIPresShell* presShell = mViewManager->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
presShell->ScheduleViewManagerFlush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-06 21:48:50 +03:00
|
|
|
bool nsView::ShouldNotBeVisible() {
|
|
|
|
if (mFrame && mFrame->IsMenuPopupFrame()) {
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
return !pm || !pm->IsPopupOpen(mFrame->GetContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-02 07:46:03 +04:00
|
|
|
nsEventStatus nsView::HandleEvent(WidgetGUIEvent* aEvent,
|
|
|
|
bool aUseAttachedEvents) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(nullptr != aEvent->mWidget, "null widget ptr");
|
2012-08-15 22:53:14 +04:00
|
|
|
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* view;
|
2012-08-15 22:53:14 +04:00
|
|
|
if (aUseAttachedEvents) {
|
2016-04-14 11:03:14 +03:00
|
|
|
nsIWidgetListener* listener = aEvent->mWidget->GetAttachedWidgetListener();
|
2012-08-15 22:53:14 +04:00
|
|
|
view = listener ? listener->GetView() : nullptr;
|
|
|
|
} else {
|
2016-04-14 11:03:14 +03:00
|
|
|
view = GetViewFor(aEvent->mWidget);
|
2012-08-15 22:53:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (view) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsViewManager> vm = view->GetViewManager();
|
2012-08-15 22:53:14 +04:00
|
|
|
vm->DispatchEvent(aEvent, view, &result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2015-07-22 04:09:02 +03:00
|
|
|
|
|
|
|
bool nsView::IsPrimaryFramePaintSuppressed() {
|
2017-11-09 05:00:48 +03:00
|
|
|
return sShowPreviousPage && mFrame &&
|
|
|
|
mFrame->PresShell()->IsPaintingSuppressed();
|
2015-07-22 04:09:02 +03:00
|
|
|
}
|