Bug 1239589 - Change nsBaseWidget::mBounds to a LayoutDeviceIntRect. r=kats.

This patch removes dozens of ToUnknown/FromUnknown conversions and doesn't add
any new ones, which is nice. It also removes UntypedDevPixelsToCocoaPoints(),
which is no longer needed.
This commit is contained in:
Nicholas Nethercote
2015-11-22 20:32:29 -08:00
parent 630c0e6ebc
commit da19ce6e70
18 changed files with 68 additions and 95 deletions

View File

@@ -64,7 +64,7 @@ PluginWidgetProxy::Create(nsIWidget* aParent,
BaseCreate(aParent, aInitData);
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
mEnabled = true;
mVisible = true;

View File

@@ -30,11 +30,11 @@ using namespace mozilla::layers;
using namespace mozilla::widget;
static void
InvalidateRegion(nsIWidget* aWidget, const nsIntRegion& aRegion)
InvalidateRegion(nsIWidget* aWidget, const LayoutDeviceIntRegion& aRegion)
{
nsIntRegionRectIterator it(aRegion);
while(const nsIntRect* r = it.Next()) {
aWidget->Invalidate(LayoutDeviceIntRect::FromUnknownRect(*r));
LayoutDeviceIntRegion::RectIterator it(aRegion);
while(const LayoutDeviceIntRect* r = it.Next()) {
aWidget->Invalidate(*r);
}
}
@@ -107,7 +107,7 @@ PuppetWidget::Create(nsIWidget* aParent,
BaseCreate(nullptr, aInitData);
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
mEnabled = true;
mVisible = true;
@@ -197,7 +197,7 @@ PuppetWidget::Show(bool aState)
if (!wasVisible && mVisible) {
Resize(mBounds.width, mBounds.height, false);
Invalidate(LayoutDeviceIntRect::FromUnknownRect(mBounds));
Invalidate(mBounds);
}
return NS_OK;
@@ -208,8 +208,9 @@ PuppetWidget::Resize(double aWidth,
double aHeight,
bool aRepaint)
{
nsIntRect oldBounds = mBounds;
mBounds.SizeTo(nsIntSize(NSToIntRound(aWidth), NSToIntRound(aHeight)));
LayoutDeviceIntRect oldBounds = mBounds;
mBounds.SizeTo(LayoutDeviceIntSize(NSToIntRound(aWidth),
NSToIntRound(aHeight)));
if (mChild) {
return mChild->Resize(aWidth, aHeight, aRepaint);
@@ -218,7 +219,7 @@ PuppetWidget::Resize(double aWidth,
// XXX: roc says that |aRepaint| dictates whether or not to
// invalidate the expanded area
if (oldBounds.Size() < mBounds.Size() && aRepaint) {
nsIntRegion dirty(mBounds);
LayoutDeviceIntRegion dirty(mBounds);
dirty.Sub(dirty, oldBounds);
InvalidateRegion(this, dirty);
}
@@ -1240,7 +1241,7 @@ PuppetWidget::GetWindowPosition()
NS_METHOD
PuppetWidget::GetScreenBounds(LayoutDeviceIntRect& aRect) {
aRect.MoveTo(WidgetToScreenOffset());
aRect.SizeTo(LayoutDeviceIntSize::FromUnknownSize(mBounds.Size()));
aRect.SizeTo(mBounds.Size());
return NS_OK;
}

View File

@@ -1075,7 +1075,7 @@ nsWindow::Create(nsIWidget* aParent,
}
}
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
// for toplevel windows, bounds are fixed to full screen size
if (!parent) {

View File

@@ -535,11 +535,6 @@ public:
CGFloat DevPixelsToCocoaPoints(int32_t aPixels) const {
return nsCocoaUtils::DevPixelsToCocoaPoints(aPixels, BackingScaleFactor());
}
// XXX: all calls to this function should eventually be replaced with calls
// to DevPixelsToCocoaPoints().
NSRect UntypedDevPixelsToCocoaPoints(const nsIntRect& aRect) const {
return nsCocoaUtils::UntypedDevPixelsToCocoaPoints(aRect, BackingScaleFactor());
}
NSRect DevPixelsToCocoaPoints(const LayoutDeviceIntRect& aRect) const {
return nsCocoaUtils::DevPixelsToCocoaPoints(aRect, BackingScaleFactor());
}

View File

@@ -496,7 +496,7 @@ nsresult nsChildView::Create(nsIWidget* aParent,
gChildViewMethodsSwizzled = true;
}
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
// Ensure that the toolkit is created.
nsToolkit::GetToolkit();
@@ -522,8 +522,7 @@ nsresult nsChildView::Create(nsIWidget* aParent,
// create our parallel NSView and hook it up to our parent. Recall
// that NS_NATIVE_WIDGET is the NSView.
CGFloat scaleFactor = nsCocoaUtils::GetBackingScaleFactor(mParentView);
NSRect r = nsCocoaUtils::DevPixelsToCocoaPoints(
LayoutDeviceIntRect::FromUnknownRect(mBounds), scaleFactor);
NSRect r = nsCocoaUtils::DevPixelsToCocoaPoints(mBounds, scaleFactor);
mView = [(NSView<mozView>*)CreateCocoaView(r) retain];
if (!mView) {
return NS_ERROR_FAILURE;
@@ -929,9 +928,7 @@ NS_IMETHODIMP nsChildView::SetCursor(imgIContainer* aCursor,
// Get this component dimension
NS_IMETHODIMP nsChildView::GetBounds(LayoutDeviceIntRect& aRect)
{
aRect = !mView
? LayoutDeviceIntRect::FromUnknownRect(mBounds)
: CocoaPointsToDevPixels([mView frame]);
aRect = !mView ? mBounds : CocoaPointsToDevPixels([mView frame]);
return NS_OK;
}
@@ -1023,7 +1020,7 @@ NS_IMETHODIMP nsChildView::Move(double aX, double aY)
mBounds.y = y;
ManipulateViewWithoutNeedingDisplay(mView, ^{
[mView setFrame:UntypedDevPixelsToCocoaPoints(mBounds)];
[mView setFrame:DevPixelsToCocoaPoints(mBounds)];
});
NotifyRollupGeometryChange();
@@ -1048,7 +1045,7 @@ NS_IMETHODIMP nsChildView::Resize(double aWidth, double aHeight, bool aRepaint)
mBounds.height = height;
ManipulateViewWithoutNeedingDisplay(mView, ^{
[mView setFrame:UntypedDevPixelsToCocoaPoints(mBounds)];
[mView setFrame:DevPixelsToCocoaPoints(mBounds)];
});
if (mVisible && aRepaint)
@@ -1087,7 +1084,7 @@ NS_IMETHODIMP nsChildView::Resize(double aX, double aY,
}
ManipulateViewWithoutNeedingDisplay(mView, ^{
[mView setFrame:UntypedDevPixelsToCocoaPoints(mBounds)];
[mView setFrame:DevPixelsToCocoaPoints(mBounds)];
});
if (mVisible && aRepaint)
@@ -2650,8 +2647,7 @@ nsChildView::StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion)
}
LayoutDeviceIntRegion dirtyRegion(aInvalidRegion);
LayoutDeviceIntSize renderSize =
LayoutDeviceIntSize::FromUnknownSize(mBounds.Size());
LayoutDeviceIntSize renderSize = mBounds.Size();
if (!mBasicCompositorImage) {
mBasicCompositorImage = new RectTextureImage(mGLPresenter->gl());
@@ -2662,7 +2658,7 @@ nsChildView::StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion)
if (!drawTarget) {
// Composite unchanged textures.
DoRemoteComposition(LayoutDeviceIntRect::FromUnknownRect(mBounds));
DoRemoteComposition(mBounds);
return nullptr;
}
@@ -2675,7 +2671,7 @@ void
nsChildView::EndRemoteDrawing()
{
mBasicCompositorImage->EndUpdate(true);
DoRemoteComposition(LayoutDeviceIntRect::FromUnknownRect(mBounds));
DoRemoteComposition(mBounds);
}
void

View File

@@ -184,17 +184,6 @@ public:
(CGFloat)aPt.y / aBackingScale);
}
// XXX: all calls to this function should eventually be replaced with calls
// to DevPixelsToCocoaPoints().
static NSRect
UntypedDevPixelsToCocoaPoints(const nsIntRect& aRect, CGFloat aBackingScale)
{
return NSMakeRect((CGFloat)aRect.x / aBackingScale,
(CGFloat)aRect.y / aBackingScale,
(CGFloat)aRect.width / aBackingScale,
(CGFloat)aRect.height / aBackingScale);
}
static NSRect
DevPixelsToCocoaPoints(const LayoutDeviceIntRect& aRect,
CGFloat aBackingScale)

View File

@@ -1621,8 +1621,8 @@ nsCocoaWindow::UpdateBounds()
if (mWindow) {
frame = [mWindow frame];
}
mBounds = nsCocoaUtils::CocoaRectToGeckoRectDevPix(
frame, BackingScaleFactor()).ToUnknownRect();
mBounds =
nsCocoaUtils::CocoaRectToGeckoRectDevPix(frame, BackingScaleFactor());
}
NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(LayoutDeviceIntRect &aRect)
@@ -1631,10 +1631,10 @@ NS_IMETHODIMP nsCocoaWindow::GetScreenBounds(LayoutDeviceIntRect &aRect)
#ifdef DEBUG
LayoutDeviceIntRect r = nsCocoaUtils::CocoaRectToGeckoRectDevPix([mWindow frame], BackingScaleFactor());
NS_ASSERTION(mWindow && mBounds == r.ToUnknownRect(), "mBounds out of sync!");
NS_ASSERTION(mWindow && mBounds == r, "mBounds out of sync!");
#endif
aRect = LayoutDeviceIntRect::FromUnknownRect(mBounds);
aRect = mBounds;
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
@@ -2025,8 +2025,7 @@ LayoutDeviceIntPoint nsCocoaWindow::GetClientOffset()
LayoutDeviceIntRect clientRect;
GetClientBounds(clientRect);
return clientRect.TopLeft() -
LayoutDeviceIntPoint::FromUnknownPoint(mBounds.TopLeft());
return clientRect.TopLeft() - mBounds.TopLeft();
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(LayoutDeviceIntPoint(0, 0));
}

View File

@@ -344,13 +344,13 @@ nsWindow::Create(nsIWidget* aParent,
mScreen = static_cast<nsScreenGonk*>(screen.get());
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
mParent = (nsWindow *)aParent;
mVisible = false;
if (!aParent) {
mBounds = mScreen->GetRect().ToUnknownRect();
mBounds = mScreen->GetRect();
}
mComposer2D = HwcComposer2D::GetInstance();
@@ -448,14 +448,14 @@ nsWindow::Resize(double aX,
double aHeight,
bool aRepaint)
{
mBounds = nsIntRect(NSToIntRound(aX), NSToIntRound(aY),
mBounds = LayoutDeviceIntRect(NSToIntRound(aX), NSToIntRound(aY),
NSToIntRound(aWidth), NSToIntRound(aHeight));
if (mWidgetListener) {
mWidgetListener->WindowResized(this, mBounds.width, mBounds.height);
}
if (aRepaint) {
Invalidate(LayoutDeviceIntRect::FromUnknownRect(mBounds));
Invalidate(mBounds);
}
return NS_OK;
@@ -726,7 +726,7 @@ nsWindow::BringToTop()
mWidgetListener->WindowActivated();
}
Invalidate(LayoutDeviceIntRect::FromUnknownRect(mBounds));
Invalidate(mBounds);
}
void

View File

@@ -1497,7 +1497,7 @@ nsWindow::GetScreenBounds(LayoutDeviceIntRect& aRect)
// bounds (bug 581863). gdk_window_get_frame_extents would give the
// frame bounds, but mBounds.Size() is returned here for consistency
// with Resize.
aRect.SizeTo(LayoutDeviceIntSize::FromUnknownSize(mBounds.Size()));
aRect.SizeTo(mBounds.Size());
LOG(("GetScreenBounds %d,%d | %dx%d\n",
aRect.x, aRect.y, aRect.width, aRect.height));
return NS_OK;
@@ -2419,7 +2419,7 @@ nsWindow::OnConfigureEvent(GtkWidget *aWidget, GdkEventConfigure *aEvent)
return FALSE;
}
mBounds.MoveTo(screenBounds.TopLeft().ToUnknownPoint());
mBounds.MoveTo(screenBounds.TopLeft());
// XXX mozilla will invalidate the entire window after this move
// complete. wtf?
@@ -2450,7 +2450,7 @@ nsWindow::OnSizeAllocate(GtkAllocation *aAllocation)
(void *)this, aAllocation->x, aAllocation->y,
aAllocation->width, aAllocation->height));
nsIntSize size = GdkRectToDevicePixels(*aAllocation).Size();
LayoutDeviceIntSize size = GdkRectToDevicePixels(*aAllocation).Size();
if (mBounds.Size() == size)
return;
@@ -3542,7 +3542,7 @@ nsWindow::Create(nsIWidget* aParent,
CommonCreate(aParent, listenForResizes);
// save our bounds
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
ConstrainSize(&mBounds.width, &mBounds.height);
// figure out our parent window
@@ -4301,14 +4301,12 @@ nsWindow::ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
nsWindow* w = static_cast<nsWindow*>(configuration.mChild.get());
NS_ASSERTION(w->GetParent() == this,
"Configured widget is not a child");
LayoutDeviceIntRect wBounds =
LayoutDeviceIntRect::FromUnknownRect(w->mBounds);
w->SetWindowClipRegion(configuration.mClipRegion, true);
if (wBounds.Size() != configuration.mBounds.Size()) {
if (w->mBounds.Size() != configuration.mBounds.Size()) {
w->Resize(configuration.mBounds.x, configuration.mBounds.y,
configuration.mBounds.width, configuration.mBounds.height,
true);
} else if (wBounds.TopLeft() != configuration.mBounds.TopLeft()) {
} else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) {
w->Move(configuration.mBounds.x, configuration.mBounds.y);
}
w->SetWindowClipRegion(configuration.mClipRegion, false);
@@ -6702,7 +6700,7 @@ nsWindow::DevicePixelsToGdkCoordRoundDown(int pixels) {
}
GdkPoint
nsWindow::DevicePixelsToGdkPointRoundDown(nsIntPoint point) {
nsWindow::DevicePixelsToGdkPointRoundDown(LayoutDeviceIntPoint point) {
gint scale = GdkScaleFactor();
return { point.x / scale, point.y / scale };
}
@@ -6718,7 +6716,7 @@ nsWindow::DevicePixelsToGdkRectRoundOut(LayoutDeviceIntRect rect) {
}
GdkRectangle
nsWindow::DevicePixelsToGdkSizeRoundUp(nsIntSize pixelSize) {
nsWindow::DevicePixelsToGdkSizeRoundUp(LayoutDeviceIntSize pixelSize) {
gint scale = GdkScaleFactor();
gint width = (pixelSize.width + scale - 1) / scale;
gint height = (pixelSize.height + scale - 1) / scale;
@@ -6744,10 +6742,10 @@ nsWindow::GdkPointToDevicePixels(GdkPoint point) {
point.y * scale);
}
nsIntRect
LayoutDeviceIntRect
nsWindow::GdkRectToDevicePixels(GdkRectangle rect) {
gint scale = GdkScaleFactor();
return nsIntRect(rect.x * scale,
return LayoutDeviceIntRect(rect.x * scale,
rect.y * scale,
rect.width * scale,
rect.height * scale);

View File

@@ -340,14 +340,14 @@ public:
// To GDK
gint DevicePixelsToGdkCoordRoundUp(int pixels);
gint DevicePixelsToGdkCoordRoundDown(int pixels);
GdkPoint DevicePixelsToGdkPointRoundDown(nsIntPoint point);
GdkRectangle DevicePixelsToGdkSizeRoundUp(nsIntSize pixelSize);
GdkPoint DevicePixelsToGdkPointRoundDown(LayoutDeviceIntPoint point);
GdkRectangle DevicePixelsToGdkSizeRoundUp(LayoutDeviceIntSize pixelSize);
// From GDK
int GdkCoordToDevicePixels(gint coord);
LayoutDeviceIntPoint GdkPointToDevicePixels(GdkPoint point);
LayoutDeviceIntPoint GdkEventCoordsToDevicePixels(gdouble x, gdouble y);
nsIntRect GdkRectToDevicePixels(GdkRectangle rect);
LayoutDeviceIntRect GdkRectToDevicePixels(GdkRectangle rect);
protected:
virtual ~nsWindow();

View File

@@ -1443,7 +1443,7 @@ NS_METHOD nsBaseWidget::GetClientBounds(LayoutDeviceIntRect &aRect)
**/
NS_METHOD nsBaseWidget::GetBounds(LayoutDeviceIntRect &aRect)
{
aRect = LayoutDeviceIntRect::FromUnknownRect(mBounds);
aRect = mBounds;
return NS_OK;
}

View File

@@ -515,7 +515,7 @@ protected:
RefPtr<TextEventDispatcher> mTextEventDispatcher;
nsCursor mCursor;
nsBorderStyle mBorderStyle;
nsIntRect mBounds;
LayoutDeviceIntRect mBounds;
LayoutDeviceIntRect* mOriginalBounds;
// When this pointer is null, the widget is not clipped
mozilla::UniquePtr<LayoutDeviceIntRect[]> mClipRects;

View File

@@ -151,7 +151,7 @@ nsWindow::Create(nsIWidget* aParent,
mParent = (nsWindow *)aParent;
// save our bounds
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
// find native parent
MozQWidget *parent = nullptr;
@@ -466,8 +466,7 @@ nsWindow::Resize(double aWidth, double aHeight, bool aRepaint)
// synthesize a resize event if this isn't a toplevel
if (mIsTopLevel || mListenForResizes) {
nsEventStatus status;
DispatchResizeEvent(LayoutDeviceIntRect::FromUnknownRect(mBounds),
status);
DispatchResizeEvent(mBounds, status);
}
NotifyRollupGeometryChange();
@@ -530,8 +529,7 @@ nsWindow::Resize(double aX, double aY, double aWidth, double aHeight,
if (mIsTopLevel || mListenForResizes) {
// synthesize a resize event
nsEventStatus status;
DispatchResizeEvent(LayoutDeviceIntRect::FromUnknownRect(mBounds),
status);
DispatchResizeEvent(mBounds, status);
}
if (aRepaint) {
@@ -603,13 +601,11 @@ nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>& aConfigura
NS_ASSERTION(w->GetParent() == this,
"Configured widget is not a child");
LayoutDeviceIntRect wBounds =
LayoutDeviceIntRect::FromUnknownRect(w->mBounds);
if (wBounds.Size() != configuration.mBounds.Size()) {
if (w->mBounds.Size() != configuration.mBounds.Size()) {
w->Resize(configuration.mBounds.x, configuration.mBounds.y,
configuration.mBounds.width, configuration.mBounds.height,
true);
} else if (wBounds.TopLeft() != configuration.mBounds.TopLeft()) {
} else if (w->mBounds.TopLeft() != configuration.mBounds.TopLeft()) {
w->Move(configuration.mBounds.x, configuration.mBounds.y);
}
}
@@ -1503,8 +1499,7 @@ void find_first_visible_parent(QWindow* aItem, QWindow*& aVisibleItem)
NS_IMETHODIMP
nsWindow::GetScreenBounds(LayoutDeviceIntRect& aRect)
{
aRect = LayoutDeviceIntRect(LayoutDeviceIntPoint(0, 0),
LayoutDeviceIntSize::FromUnknownSize(mBounds.Size()));
aRect = LayoutDeviceIntRect(LayoutDeviceIntPoint(0, 0), mBounds.Size());
if (mIsTopLevel) {
QPoint pos = mWidget->position();
aRect.MoveTo(pos.x(), pos.y());

View File

@@ -45,7 +45,7 @@ public:
NS_DECL_NSISCREENMANAGER
static nsIntRect GetBounds();
static LayoutDeviceIntRect GetBounds();
private:
virtual ~UIKitScreenManager () {}

View File

@@ -9,7 +9,7 @@
#include "nsScreenManager.h"
#include "nsAppShell.h"
static nsIntRect gScreenBounds;
static LayoutDeviceIntRect gScreenBounds;
static bool gScreenBoundsSet = false;
UIKitScreen::UIKitScreen(UIScreen* aScreen)
@@ -83,7 +83,7 @@ UIKitScreenManager::UIKitScreenManager()
{
}
nsIntRect
LayoutDeviceIntRect
UIKitScreenManager::GetBounds()
{
if (!gScreenBoundsSet) {

View File

@@ -51,7 +51,7 @@ UIKitPointsToDevPixels(CGPoint aPoint, CGFloat aBackingScale)
}
static CGRect
DevPixelsToUIKitPoints(const nsIntRect& aRect, CGFloat aBackingScale)
DevPixelsToUIKitPoints(const LayoutDeviceIntRect& aRect, CGFloat aBackingScale)
{
return CGRectMake((CGFloat)aRect.x / aBackingScale,
(CGFloat)aRect.y / aBackingScale,
@@ -493,7 +493,7 @@ nsWindow::Create(nsIWidget* aParent,
mBounds.height = cgRect.size.height;
}
} else {
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
}
ALOG("nsWindow[%p]::Create bounds: %d %d %d %d", (void*)this,

View File

@@ -548,7 +548,7 @@ nsWindow::Create(nsIWidget* aParent,
nullptr : aParent;
mIsTopWidgetWindow = (nullptr == baseParent);
mBounds = aRect.ToUnknownRect();
mBounds = aRect;
// Ensure that the toolkit is created.
nsToolkit::GetToolkit();
@@ -2030,7 +2030,7 @@ NS_METHOD nsWindow::GetBounds(LayoutDeviceIntRect& aRect)
aRect.x = r.left;
aRect.y = r.top;
} else {
aRect = LayoutDeviceIntRect::FromUnknownRect(mBounds);
aRect = mBounds;
}
return NS_OK;
}
@@ -2066,7 +2066,7 @@ NS_METHOD nsWindow::GetScreenBounds(LayoutDeviceIntRect& aRect)
aRect.x = r.left;
aRect.y = r.top;
} else {
aRect = LayoutDeviceIntRect::FromUnknownRect(mBounds);
aRect = mBounds;
}
return NS_OK;
}

View File

@@ -585,7 +585,7 @@ protected:
HDC mPaintDC; // only set during painting
HDC mCompositeDC; // only set during StartRemoteDrawing
nsIntRect mLastPaintBounds;
LayoutDeviceIntRect mLastPaintBounds;
// Used for displayport suppression during window resize
enum ResizeState {