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"
|
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
|
1998-11-24 02:50:17 +03:00
|
|
|
|
2012-12-02 12:56:54 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::nsView(nsViewManager* aViewManager, nsViewVisibility aVisibility)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2013-01-03 17:23:11 +04:00
|
|
|
MOZ_COUNT_CTOR(nsView);
|
1999-10-05 18:52:53 +04:00
|
|
|
|
2004-11-04 18:06:50 +03:00
|
|
|
mVis = aVisibility;
|
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.
|
2007-02-24 03:23:42 +03:00
|
|
|
mVFlags = 0;
|
2004-11-04 18:06:50 +03:00
|
|
|
mViewManager = aViewManager;
|
2012-07-30 18:20:58 +04:00
|
|
|
mDirtyRegion = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mWidgetIsTopLevel = false;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::DropMouseGrabbing()
|
2009-09-13 17:13:16 +04:00
|
|
|
{
|
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()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2013-01-03 17:23:11 +04:00
|
|
|
MOZ_COUNT_DTOR(nsView);
|
1999-10-05 18:52:53 +04:00
|
|
|
|
2003-02-23 05:53:15 +03:00
|
|
|
while (GetFirstChild())
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-12-01 06:04:17 +03:00
|
|
|
DropMouseGrabbing();
|
|
|
|
|
2013-01-05 07:13:05 +04:00
|
|
|
nsView *rootView = mViewManager->GetRootView();
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mViewManager = nullptr;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2003-02-23 05:53:15 +03:00
|
|
|
else if (mParent)
|
1998-08-08 08:23:33 +04:00
|
|
|
{
|
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
|
|
|
|
2000-08-12 23:05:52 +04:00
|
|
|
// Destroy and release the widget
|
2011-03-21 21:28:10 +03:00
|
|
|
DestroyWidget();
|
|
|
|
|
|
|
|
delete mDirtyRegion;
|
|
|
|
}
|
|
|
|
|
2013-05-28 12:11:11 +04:00
|
|
|
class DestroyWidgetRunnable : public nsRunnable {
|
|
|
|
public:
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
explicit DestroyWidgetRunnable(nsIWidget* aWidget) : mWidget(aWidget) {}
|
|
|
|
|
|
|
|
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()
|
2011-03-21 21:28:10 +03:00
|
|
|
{
|
2003-02-23 05:53:15 +03:00
|
|
|
if (mWindow)
|
1998-11-03 09:36:36 +03:00
|
|
|
{
|
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
|
|
|
|
// Destroy. Just clear our event view ptr and free our reference to it.
|
|
|
|
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);
|
|
|
|
|
|
|
|
NS_DispatchToMainThread(widgetDestroyer);
|
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)
|
2012-08-15 22:53:14 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(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()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2002-01-27 10:56:23 +03:00
|
|
|
mDimBounds.x += aX - mPosX;
|
|
|
|
mDimBounds.y += aY - mPosY;
|
|
|
|
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)
|
2011-12-24 07:52:23 +04:00
|
|
|
{
|
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()
|
2009-07-30 06:54:42 +04:00
|
|
|
{
|
2013-01-03 17:23:11 +04:00
|
|
|
for (nsView* v = this; v; v = v->mParent) {
|
2009-07-30 06:54:42 +04:00
|
|
|
if (v->GetVisibility() == nsViewVisibility_kHide)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-07-30 06:54:42 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-07-30 06:54:42 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsIntRect nsView::CalcWidgetBounds(nsWindowType aType)
|
2007-05-26 07:45:00 +04:00
|
|
|
{
|
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 &&
|
2009-07-30 06:54:42 +04:00
|
|
|
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
|
2009-05-08 06:31:04 +04:00
|
|
|
nsIntRect newBounds = viewBounds.ToNearestPixels(p2a);
|
2007-05-26 07:45:00 +04:00
|
|
|
|
2013-07-30 20:22:41 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// cocoa rounds 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)) {
|
|
|
|
nsIntSize pixelRoundedSize = newBounds.Size();
|
|
|
|
// 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.
|
2007-05-26 07:45:00 +04: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,
|
2011-09-29 10:19:26 +04:00
|
|
|
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
|
|
|
|
|
|
|
NS_PRECONDITION(mWindow, "Why was this called??");
|
|
|
|
|
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).
|
|
|
|
nsIntRect newBounds;
|
2013-05-10 11:13:49 +04:00
|
|
|
nsRefPtr<nsDeviceContext> dx = mViewManager->GetDeviceContext();
|
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
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect curBounds;
|
2013-05-02 01:21:33 +04:00
|
|
|
widget->GetClientBounds(curBounds);
|
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 {
|
|
|
|
newBounds = CalcWidgetBounds(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool curVisibility = widget->IsVisible();
|
|
|
|
bool newVisibility = IsEffectivelyVisible();
|
|
|
|
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
|
|
|
|
|
|
|
// Coordinates are converted to display pixels for window Move/Resize APIs,
|
|
|
|
// because of the potential for device-pixel coordinate spaces for mixed
|
|
|
|
// hidpi/lodpi screens to overlap each other and result in bad placement
|
|
|
|
// (bug 814434).
|
2013-04-18 19:35:49 +04:00
|
|
|
double invScale;
|
|
|
|
|
|
|
|
// Bug 861270: for correct widget manipulation at arbitrary scale factors,
|
2013-05-02 01:21:33 +04:00
|
|
|
// prefer to base scaling on widget->GetDefaultScale(). But only do this if
|
2013-04-18 19:35:49 +04:00
|
|
|
// it matches the view manager's device context scale after allowing for the
|
|
|
|
// quantization to app units, because of OS X multiscreen issues (where the
|
|
|
|
// only two scales are 1.0 or 2.0, and so the quantization doesn't actually
|
|
|
|
// cause problems anyhow).
|
|
|
|
// In the case of a mismatch, fall back to scaling based on the dev context's
|
2014-11-13 14:53:02 +03:00
|
|
|
// AppUnitsPerDevPixelAtUnitFullZoom value. On platforms where the device-pixel
|
2013-04-18 19:35:49 +04:00
|
|
|
// scale is uniform across all displays (currently all except OS X), we'll
|
|
|
|
// always use the precise value from mWindow->GetDefaultScale here.
|
2013-09-18 04:45:19 +04:00
|
|
|
CSSToLayoutDeviceScale scale = widget->GetDefaultScale();
|
2014-11-13 14:53:02 +03:00
|
|
|
if (NSToIntRound(60.0 / scale.scale) == dx->AppUnitsPerDevPixelAtUnitFullZoom()) {
|
2013-09-18 04:45:19 +04:00
|
|
|
invScale = 1.0 / scale.scale;
|
2013-04-18 19:35:49 +04:00
|
|
|
} else {
|
2014-11-13 14:53:02 +03:00
|
|
|
invScale = dx->AppUnitsPerDevPixelAtUnitFullZoom() / 60.0;
|
2013-04-18 19:35:49 +04:00
|
|
|
}
|
2012-12-06 21:31:34 +04:00
|
|
|
|
2005-10-21 06:40:04 +04:00
|
|
|
if (changedPos) {
|
|
|
|
if (changedSize && !aMoveOnly) {
|
2013-05-02 01:21:33 +04:00
|
|
|
widget->ResizeClient(newBounds.x * invScale,
|
|
|
|
newBounds.y * invScale,
|
|
|
|
newBounds.width * invScale,
|
|
|
|
newBounds.height * invScale,
|
|
|
|
aInvalidateChangedSize);
|
2004-10-12 00:35:51 +04:00
|
|
|
} else {
|
2013-05-02 01:21:33 +04:00
|
|
|
widget->MoveClient(newBounds.x * invScale,
|
|
|
|
newBounds.y * invScale);
|
2004-01-10 08:36:32 +03:00
|
|
|
}
|
2005-10-21 06:40:04 +04:00
|
|
|
} else {
|
|
|
|
if (changedSize && !aMoveOnly) {
|
2013-05-02 01:21:33 +04:00
|
|
|
widget->ResizeClient(newBounds.width * invScale,
|
|
|
|
newBounds.height * invScale,
|
|
|
|
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)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2009-07-30 06:54:42 +04:00
|
|
|
if (!aEffectivelyVisible)
|
2001-05-04 07:02:55 +04:00
|
|
|
{
|
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)
|
2005-09-30 23:25:42 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::InvalidateHierarchy(nsViewManager *aViewManagerParent)
|
2005-05-05 00:22:32 +04:00
|
|
|
{
|
2013-01-05 07:13:05 +04:00
|
|
|
if (mViewManager->GetRootView() == this)
|
2005-05-05 00:22:32 +04:00
|
|
|
mViewManager->InvalidateHierarchy();
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
for (nsView *child = mFirstChild; child; child = child->GetNextSibling())
|
2005-08-24 01:52:59 +04:00
|
|
|
child->InvalidateHierarchy(aViewManagerParent);
|
2005-05-05 00:22:32 +04:00
|
|
|
}
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
void nsView::InsertChild(nsView *aChild, nsView *aSibling)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aChild, "null ptr");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != aChild)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != aSibling)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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)
|
2005-05-05 00:22:32 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
aChild->InvalidateHierarchy(nullptr); // don't care about releasing grabs
|
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)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != child, "null ptr");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
if (nullptr != child)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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)
|
2005-05-05 00:22:32 +04:00
|
|
|
{
|
2013-01-05 07:13:23 +04:00
|
|
|
child->InvalidateHierarchy(GetViewManager());
|
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)
|
1998-11-04 07:14:10 +03:00
|
|
|
{
|
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
|
|
|
|
|
|
|
nsIntRect 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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
nsIntRect 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
|
|
|
{
|
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
|
|
|
|
|
|
|
nsIntRect trect = CalcWidgetBounds(aWidgetInitData->mWindowType);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::InitializeWindow(bool aEnableDragDrop, bool aResetVisibility)
|
2010-08-20 23:29:01 +04:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
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)
|
2010-06-25 06:01:06 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(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.
|
2015-02-05 08:33:49 +03:00
|
|
|
nsresult rv = aWidget->AttachViewToTopLevel(!nsIWidget::UsePuppetWidgets());
|
2010-06-25 06:01:06 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
mWindow = aWidget;
|
|
|
|
|
2013-01-03 17:23:08 +04:00
|
|
|
mWindow->SetAttachedWidgetListener(this);
|
2011-10-17 18:59:28 +04:00
|
|
|
mWindow->EnableDragDrop(true);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Detach this view from an attached widget.
|
2013-01-03 17:23:11 +04:00
|
|
|
nsresult nsView::DetachFromTopLevelWidget()
|
2010-06-25 06:01:06 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mWidgetIsTopLevel, "Not attached currently!");
|
|
|
|
NS_PRECONDITION(mWindow, "null mWindow for DetachFromTopLevelWidget!");
|
|
|
|
|
2012-08-15 22:53:14 +04:00
|
|
|
mWindow->SetAttachedWidgetListener(nullptr);
|
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;
|
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)
|
2001-12-01 17:31:45 +03:00
|
|
|
{
|
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;
|
2002-07-02 16:50:14 +04: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()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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)
|
2009-07-22 04:45:00 +04:00
|
|
|
{
|
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
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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();
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect rect;
|
|
|
|
mWindow->GetClientBounds(rect);
|
2015-04-21 18:04:57 +03:00
|
|
|
nsRect windowBounds = ToAppUnits(rect, p2a);
|
2009-01-15 06:27:09 +03:00
|
|
|
mWindow->GetBounds(rect);
|
2015-04-21 18:04:57 +03:00
|
|
|
nsRect nonclientBounds = 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,
|
1999-03-19 00:04:00 +03:00
|
|
|
nonclientBounds.x, nonclientBounds.y,
|
1998-06-05 00:02:30 +04:00
|
|
|
windowBounds.width, windowBounds.height);
|
|
|
|
}
|
2003-07-03 17:05:57 +04:00
|
|
|
nsRect brect = GetBounds();
|
1999-03-19 00:04:00 +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",
|
2012-03-31 00:36:43 +04:00
|
|
|
mZIndex, mVis, 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
|
2004-11-03 19:16:57 +03:00
|
|
|
{
|
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
|
2010-07-19 06:23:47 +04:00
|
|
|
{
|
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
|
2010-07-19 06:23:47 +04:00
|
|
|
{
|
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
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
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
|
2000-03-24 02:49:18 +03:00
|
|
|
{
|
2013-01-03 17:23:11 +04:00
|
|
|
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
|
|
|
|
2010-07-19 06:23:47 +04:00
|
|
|
nsRect
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::GetBoundsInParentUnits() const
|
2010-07-19 06:23:47 +04:00
|
|
|
{
|
2013-01-03 17:23:11 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
nsPoint
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::ConvertFromParentCoords(nsPoint aPt) const
|
2010-07-19 06:23:47 +04:00
|
|
|
{
|
2013-01-03 17:23:11 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresShell*
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::GetPresShell()
|
2012-08-15 22:53:14 +04:00
|
|
|
{
|
|
|
|
return GetViewManager()->GetPresShell();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-01-03 17:23:11 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-01-03 17:23:11 +04:00
|
|
|
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()) {
|
2013-05-10 11:13:49 +04:00
|
|
|
nsRefPtr<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;
|
|
|
|
}
|
|
|
|
else if (IsPopupWidget(aWidget)) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::RequestWindowClose(nsIWidget* aWidget)
|
2012-08-15 22:53:14 +04:00
|
|
|
{
|
|
|
|
if (mFrame && IsPopupWidget(aWidget) &&
|
|
|
|
mFrame->GetType() == nsGkAtoms::menuPopupFrame) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-28 23:34:08 +04:00
|
|
|
nsView::WillPaintWindow(nsIWidget* aWidget)
|
2012-08-15 22:53:14 +04:00
|
|
|
{
|
2013-01-05 07:12:42 +04:00
|
|
|
nsRefPtr<nsViewManager> vm = mViewManager;
|
2013-01-28 23:34:08 +04:00
|
|
|
vm->WillPaintWindow(aWidget);
|
2012-08-15 22:53:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-05-23 18:49:18 +04:00
|
|
|
nsView::PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion)
|
2012-08-15 22:53:14 +04:00
|
|
|
{
|
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
|
|
|
|
2013-01-05 07:12:42 +04:00
|
|
|
nsRefPtr<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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::DidPaintWindow()
|
2012-08-15 22:53:14 +04:00
|
|
|
{
|
2013-01-05 07:12:42 +04:00
|
|
|
nsRefPtr<nsViewManager> vm = mViewManager;
|
2012-10-22 17:53:31 +04:00
|
|
|
vm->DidPaintWindow();
|
2012-08-15 22:53:14 +04:00
|
|
|
}
|
|
|
|
|
2014-03-07 07:24:32 +04:00
|
|
|
void
|
|
|
|
nsView::DidCompositeWindow()
|
|
|
|
{
|
|
|
|
nsIPresShell* presShell = mViewManager->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
presShell->GetPresContext()->GetDisplayRootPresContext()->GetRootPresContext()->NotifyDidPaintForSubtree(nsIPresShell::PAINT_COMPOSITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 07:42:02 +04:00
|
|
|
void
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView::RequestRepaint()
|
2012-12-18 07:42:02 +04:00
|
|
|
{
|
|
|
|
nsIPresShell* presShell = mViewManager->GetPresShell();
|
|
|
|
if (presShell) {
|
|
|
|
presShell->ScheduleViewManagerFlush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 22:53:14 +04:00
|
|
|
nsEventStatus
|
2013-10-02 07:46:03 +04:00
|
|
|
nsView::HandleEvent(WidgetGUIEvent* aEvent,
|
|
|
|
bool aUseAttachedEvents)
|
2012-08-15 22:53:14 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nullptr != aEvent->widget, "null widget ptr");
|
|
|
|
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* view;
|
2012-08-15 22:53:14 +04:00
|
|
|
if (aUseAttachedEvents) {
|
|
|
|
nsIWidgetListener* listener = aEvent->widget->GetAttachedWidgetListener();
|
|
|
|
view = listener ? listener->GetView() : nullptr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
view = GetViewFor(aEvent->widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view) {
|
2013-01-05 07:12:42 +04:00
|
|
|
nsRefPtr<nsViewManager> vm = view->GetViewManager();
|
2012-08-15 22:53:14 +04:00
|
|
|
vm->DispatchEvent(aEvent, view, &result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|