Skip to content

Commit

Permalink
Bug 890156 - patch 0.3 - Create a version of nsIWidget::Create that t…
Browse files Browse the repository at this point in the history
…akes Desktop pixels, because that's what we actually need to pass in some cases. r=mstange
  • Loading branch information
jfkthame committed Jan 13, 2016
1 parent 09ac818 commit c4aa6ac
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 21 deletions.
4 changes: 4 additions & 0 deletions gfx/tests/gtest/TestCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class MockWidget : public nsBaseWidget
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override { return NS_OK; }
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override { return NS_OK; }
NS_IMETHOD Show(bool aState) override { return NS_OK; }
virtual bool IsVisible() const override { return true; }
NS_IMETHOD ConstrainPosition(bool aAllowSlop,
Expand Down
1 change: 1 addition & 0 deletions widget/PluginWidgetProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PluginWidgetProxy final : public PuppetWidget
NS_DECL_ISUPPORTS_INHERITED

// nsIWidget
using PuppetWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
Expand Down
1 change: 1 addition & 0 deletions widget/PuppetWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class PuppetWidget : public nsBaseWidget
public:
NS_DECL_ISUPPORTS_INHERITED

using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
1 change: 1 addition & 0 deletions widget/android/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class nsWindow :
// nsIWidget
//

using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
5 changes: 5 additions & 0 deletions widget/cocoa/nsCocoaWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ class nsCocoaWindow : public nsBaseWidget, public nsPIWidgetCocoa
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSPIWIDGETCOCOA

NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;

NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
38 changes: 22 additions & 16 deletions widget/cocoa/nsCocoaWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ static void RollUpPopups()
// Find the screen that overlaps aRect the most,
// if none are found default to the mainScreen.
static NSScreen*
FindTargetScreenForRect(const LayoutDeviceIntRect& aRect)
FindTargetScreenForRect(const DesktopIntRect& aRect)
{
NSScreen *targetScreen = [NSScreen mainScreen];
NSEnumerator *screenEnum = [[NSScreen screens] objectEnumerator];
int largestIntersectArea = 0;
while (NSScreen *screen = [screenEnum nextObject]) {
LayoutDeviceIntRect screenRect =
LayoutDeviceIntRect::FromUnknownRect(
DesktopIntRect screenRect =
DesktopIntRect::FromUnknownRect(
nsCocoaUtils::CocoaRectToGeckoRect([screen visibleFrame]));
screenRect = screenRect.Intersect(aRect);
int area = screenRect.width * screenRect.height;
Expand All @@ -206,7 +206,7 @@ static void RollUpPopups()
// or to aScreen if a screen is passed in
// NB: this operates with aRect in desktop pixels
static void
FitRectToVisibleAreaForScreen(LayoutDeviceIntRect& aRect, NSScreen* aScreen)
FitRectToVisibleAreaForScreen(DesktopIntRect& aRect, NSScreen* aScreen)
{
if (!aScreen) {
aScreen = FindTargetScreenForRect(aRect);
Expand Down Expand Up @@ -252,7 +252,7 @@ static bool UseNativePopupWindows()
// aRect here is specified in desktop pixels
nsresult nsCocoaWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
Expand All @@ -261,7 +261,7 @@ static bool UseNativePopupWindows()
// we have to provide an autorelease pool (see bug 559075).
nsAutoreleasePool localPool;

LayoutDeviceIntRect newBounds = aRect;
DesktopIntRect newBounds = aRect;
FitRectToVisibleAreaForScreen(newBounds, nullptr);

// Set defaults which can be overriden from aInitData in BaseCreate
Expand Down Expand Up @@ -291,12 +291,8 @@ static bool UseNativePopupWindows()
}
// now we can convert newBounds to device pixels for the window we created,
// as the child view expects a rect expressed in the dev pix of its parent
double scale = BackingScaleFactor();
newBounds.x *= scale;
newBounds.y *= scale;
newBounds.width *= scale;
newBounds.height *= scale;
return CreatePopupContentView(newBounds);
DesktopToLayoutDeviceScale scale(BackingScaleFactor());
return CreatePopupContentView(RoundedToInt(newBounds * scale));
}

mIsAnimationSuppressed = aInitData->mIsAnimationSuppressed;
Expand All @@ -306,6 +302,16 @@ static bool UseNativePopupWindows()
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}

nsresult nsCocoaWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
{
DesktopToLayoutDeviceScale scale(GetDefaultScaleInternal());
DesktopIntRect desktopRect = RoundedToInt(aRect / scale);
return Create(aParent, aNativeParent, desktopRect, aInitData);
}

static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle)
{
bool allOrDefault = (aBorderStyle == eBorderStyle_all ||
Expand Down Expand Up @@ -1535,9 +1541,9 @@ - (void)animationDidStop:(NSAnimation *)animation
int32_t height = NSToIntRound(aHeight * scale);
ConstrainSize(&width, &height);

LayoutDeviceIntRect newBounds(NSToIntRound(aX), NSToIntRound(aY),
NSToIntRound(width / scale),
NSToIntRound(height / scale));
DesktopIntRect newBounds(NSToIntRound(aX), NSToIntRound(aY),
NSToIntRound(width / scale),
NSToIntRound(height / scale));

// constrain to the screen that contains the largest area of the new rect
FitRectToVisibleAreaForScreen(newBounds, aConstrainToCurrentScreen ?
Expand Down Expand Up @@ -1682,7 +1688,7 @@ LayoutDeviceIntRect newBounds(NSToIntRound(aX), NSToIntRound(aY),
// Then identify the screen it belongs to, and return its scale factor.
NSScreen *screen =
FindTargetScreenForRect(
LayoutDeviceIntRect::FromUnknownRect(nsCocoaUtils::CocoaRectToGeckoRect(frame)));
DesktopIntRect::FromUnknownRect(nsCocoaUtils::CocoaRectToGeckoRect(frame)));
return nsCocoaUtils::GetBackingScaleFactor(screen);
}

Expand Down
3 changes: 2 additions & 1 deletion widget/gonk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ class nsWindow : public nsBaseWidget
static nsEventStatus DispatchKeyInput(mozilla::WidgetKeyboardEvent& aEvent);
static void DispatchTouchInput(mozilla::MultiTouchInput& aInput);

using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
void* aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData);
nsWidgetInitData* aInitData) override;
NS_IMETHOD Destroy(void);

NS_IMETHOD Show(bool aState);
Expand Down
1 change: 1 addition & 0 deletions widget/gtk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class nsWindow : public nsBaseWidget
bool AreBoundsSane(void);

// nsIWidget
using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
27 changes: 25 additions & 2 deletions widget/nsIWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class nsIWidget : public nsISupports {
typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize;
typedef mozilla::ScreenIntPoint ScreenIntPoint;
typedef mozilla::DesktopIntRect DesktopIntRect;

// Used in UpdateThemeGeometries.
struct ThemeGeometry {
Expand Down Expand Up @@ -399,8 +400,10 @@ class nsIWidget : public nsISupports {
* independent top level windows).
*
* The dimensions given in aRect are specified in the parent's
* coordinate system, or for parentless widgets such as top-level
* windows, in global CSS pixels.
* device coordinate system.
* This must not be called for parentless widgets such as top-level
* windows, which use the desktop pixel coordinate system; a separate
* method is provided for these.
*
* @param aParent parent nsIWidget
* @param aNativeParent native parent widget
Expand All @@ -413,6 +416,26 @@ class nsIWidget : public nsISupports {
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) = 0;

/*
* As above, but with aRect specified in DesktopPixel units (for top-level
* widgets).
* Default implementation just converts aRect to device pixels and calls
* through to device-pixel Create, but platforms may override this if the
* mapping is not straightforward or the native platform needs to use the
* desktop pixel values directly.
*/
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr)
{
// GetDefaultScaleInternal() here is a placeholder, to be replaced by
// GetDesktopToDeviceScale in a later patch
mozilla::DesktopToLayoutDeviceScale scale(GetDefaultScaleInternal());
LayoutDeviceIntRect devPixRect = RoundedToInt(aRect * scale);
return Create(aParent, aNativeParent, devPixRect, aInitData);
}

/**
* Allocate, initialize, and return a widget that is a child of
* |this|. The returned widget (if nonnull) has gone through the
Expand Down
1 change: 1 addition & 0 deletions widget/windows/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class nsWindow : public nsWindowBase
using nsWindowBase::DispatchPluginEvent;

// nsIWidget interface
using nsWindowBase::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
Expand Down
6 changes: 4 additions & 2 deletions xpfe/appshell/nsWebShellWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,

// XXX: need to get the default window size from prefs...
// Doesn't come from prefs... will come from CSS/XUL/RDF
LayoutDeviceIntRect r(initialX, initialY, aInitialWidth, aInitialHeight);
DesktopIntRect deskRect(initialX, initialY, aInitialWidth, aInitialHeight);

// Create top level window
mWindow = do_CreateInstance(kWindowCID, &rv);
Expand Down Expand Up @@ -173,8 +173,10 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
mWindow->SetWidgetListener(this);
mWindow->Create((nsIWidget *)parentWidget, // Parent nsIWidget
nullptr, // Native parent widget
r, // Widget dimensions
deskRect, // Widget dimensions
&widgetInitData); // Widget initialization data

LayoutDeviceIntRect r;
mWindow->GetClientBounds(r);
// Match the default background color of content. Important on windows
// since we no longer use content child widgets.
Expand Down

0 comments on commit c4aa6ac

Please sign in to comment.