Bug 890156 - patch 0.3 - Create a version of nsIWidget::Create that takes Desktop pixels, because that's what we actually need to pass in some cases. r=mstange

This commit is contained in:
Jonathan Kew 2016-01-13 07:32:55 +00:00
parent 28d5952fc4
commit c2c031081e
11 changed files with 67 additions and 21 deletions

View File

@ -59,6 +59,10 @@ public:
nsNativeWidget aNativeParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override { return NS_OK; } 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; } NS_IMETHOD Show(bool aState) override { return NS_OK; }
virtual bool IsVisible() const override { return true; } virtual bool IsVisible() const override { return true; }
NS_IMETHOD ConstrainPosition(bool aAllowSlop, NS_IMETHOD ConstrainPosition(bool aAllowSlop,

View File

@ -34,6 +34,7 @@ public:
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
// nsIWidget // nsIWidget
using PuppetWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent, nsNativeWidget aNativeParent, NS_IMETHOD Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override; nsWidgetInitData* aInitData = nullptr) override;

View File

@ -53,6 +53,7 @@ protected:
public: public:
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent, NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,

View File

@ -77,6 +77,7 @@ public:
// nsIWidget // nsIWidget
// //
using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent, NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,

View File

@ -255,6 +255,11 @@ public:
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSPIWIDGETCOCOA NS_DECL_NSPIWIDGETCOCOA
NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const DesktopIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) override;
NS_IMETHOD Create(nsIWidget* aParent, NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,

View File

@ -183,14 +183,14 @@ nsCocoaWindow::~nsCocoaWindow()
// Find the screen that overlaps aRect the most, // Find the screen that overlaps aRect the most,
// if none are found default to the mainScreen. // if none are found default to the mainScreen.
static NSScreen* static NSScreen*
FindTargetScreenForRect(const LayoutDeviceIntRect& aRect) FindTargetScreenForRect(const DesktopIntRect& aRect)
{ {
NSScreen *targetScreen = [NSScreen mainScreen]; NSScreen *targetScreen = [NSScreen mainScreen];
NSEnumerator *screenEnum = [[NSScreen screens] objectEnumerator]; NSEnumerator *screenEnum = [[NSScreen screens] objectEnumerator];
int largestIntersectArea = 0; int largestIntersectArea = 0;
while (NSScreen *screen = [screenEnum nextObject]) { while (NSScreen *screen = [screenEnum nextObject]) {
LayoutDeviceIntRect screenRect = DesktopIntRect screenRect =
LayoutDeviceIntRect::FromUnknownRect( DesktopIntRect::FromUnknownRect(
nsCocoaUtils::CocoaRectToGeckoRect([screen visibleFrame])); nsCocoaUtils::CocoaRectToGeckoRect([screen visibleFrame]));
screenRect = screenRect.Intersect(aRect); screenRect = screenRect.Intersect(aRect);
int area = screenRect.width * screenRect.height; int area = screenRect.width * screenRect.height;
@ -206,7 +206,7 @@ FindTargetScreenForRect(const LayoutDeviceIntRect& aRect)
// or to aScreen if a screen is passed in // or to aScreen if a screen is passed in
// NB: this operates with aRect in desktop pixels // NB: this operates with aRect in desktop pixels
static void static void
FitRectToVisibleAreaForScreen(LayoutDeviceIntRect& aRect, NSScreen* aScreen) FitRectToVisibleAreaForScreen(DesktopIntRect& aRect, NSScreen* aScreen)
{ {
if (!aScreen) { if (!aScreen) {
aScreen = FindTargetScreenForRect(aRect); aScreen = FindTargetScreenForRect(aRect);
@ -252,7 +252,7 @@ static bool UseNativePopupWindows()
// aRect here is specified in desktop pixels // aRect here is specified in desktop pixels
nsresult nsCocoaWindow::Create(nsIWidget* aParent, nsresult nsCocoaWindow::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect, const DesktopIntRect& aRect,
nsWidgetInitData* aInitData) nsWidgetInitData* aInitData)
{ {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
@ -261,7 +261,7 @@ nsresult nsCocoaWindow::Create(nsIWidget* aParent,
// we have to provide an autorelease pool (see bug 559075). // we have to provide an autorelease pool (see bug 559075).
nsAutoreleasePool localPool; nsAutoreleasePool localPool;
LayoutDeviceIntRect newBounds = aRect; DesktopIntRect newBounds = aRect;
FitRectToVisibleAreaForScreen(newBounds, nullptr); FitRectToVisibleAreaForScreen(newBounds, nullptr);
// Set defaults which can be overriden from aInitData in BaseCreate // Set defaults which can be overriden from aInitData in BaseCreate
@ -291,12 +291,8 @@ nsresult nsCocoaWindow::Create(nsIWidget* aParent,
} }
// now we can convert newBounds to device pixels for the window we created, // 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 // as the child view expects a rect expressed in the dev pix of its parent
double scale = BackingScaleFactor(); DesktopToLayoutDeviceScale scale(BackingScaleFactor());
newBounds.x *= scale; return CreatePopupContentView(RoundedToInt(newBounds * scale));
newBounds.y *= scale;
newBounds.width *= scale;
newBounds.height *= scale;
return CreatePopupContentView(newBounds);
} }
mIsAnimationSuppressed = aInitData->mIsAnimationSuppressed; mIsAnimationSuppressed = aInitData->mIsAnimationSuppressed;
@ -306,6 +302,16 @@ nsresult nsCocoaWindow::Create(nsIWidget* aParent,
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; 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) static unsigned int WindowMaskForBorderStyle(nsBorderStyle aBorderStyle)
{ {
bool allOrDefault = (aBorderStyle == eBorderStyle_all || bool allOrDefault = (aBorderStyle == eBorderStyle_all ||
@ -1535,9 +1541,9 @@ nsresult nsCocoaWindow::DoResize(double aX, double aY,
int32_t height = NSToIntRound(aHeight * scale); int32_t height = NSToIntRound(aHeight * scale);
ConstrainSize(&width, &height); ConstrainSize(&width, &height);
LayoutDeviceIntRect newBounds(NSToIntRound(aX), NSToIntRound(aY), DesktopIntRect newBounds(NSToIntRound(aX), NSToIntRound(aY),
NSToIntRound(width / scale), NSToIntRound(width / scale),
NSToIntRound(height / scale)); NSToIntRound(height / scale));
// constrain to the screen that contains the largest area of the new rect // constrain to the screen that contains the largest area of the new rect
FitRectToVisibleAreaForScreen(newBounds, aConstrainToCurrentScreen ? FitRectToVisibleAreaForScreen(newBounds, aConstrainToCurrentScreen ?
@ -1682,7 +1688,7 @@ GetBackingScaleFactor(NSWindow* aWindow)
// Then identify the screen it belongs to, and return its scale factor. // Then identify the screen it belongs to, and return its scale factor.
NSScreen *screen = NSScreen *screen =
FindTargetScreenForRect( FindTargetScreenForRect(
LayoutDeviceIntRect::FromUnknownRect(nsCocoaUtils::CocoaRectToGeckoRect(frame))); DesktopIntRect::FromUnknownRect(nsCocoaUtils::CocoaRectToGeckoRect(frame)));
return nsCocoaUtils::GetBackingScaleFactor(screen); return nsCocoaUtils::GetBackingScaleFactor(screen);
} }

View File

@ -46,10 +46,11 @@ public:
static nsEventStatus DispatchKeyInput(mozilla::WidgetKeyboardEvent& aEvent); static nsEventStatus DispatchKeyInput(mozilla::WidgetKeyboardEvent& aEvent);
static void DispatchTouchInput(mozilla::MultiTouchInput& aInput); static void DispatchTouchInput(mozilla::MultiTouchInput& aInput);
using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent, NS_IMETHOD Create(nsIWidget* aParent,
void* aNativeParent, void* aNativeParent,
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData); nsWidgetInitData* aInitData) override;
NS_IMETHOD Destroy(void); NS_IMETHOD Destroy(void);
NS_IMETHOD Show(bool aState); NS_IMETHOD Show(bool aState);

View File

@ -95,6 +95,7 @@ public:
bool AreBoundsSane(void); bool AreBoundsSane(void);
// nsIWidget // nsIWidget
using nsBaseWidget::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent, NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,

View File

@ -349,6 +349,7 @@ class nsIWidget : public nsISupports {
typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion; typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize; typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize;
typedef mozilla::ScreenIntPoint ScreenIntPoint; typedef mozilla::ScreenIntPoint ScreenIntPoint;
typedef mozilla::DesktopIntRect DesktopIntRect;
// Used in UpdateThemeGeometries. // Used in UpdateThemeGeometries.
struct ThemeGeometry { struct ThemeGeometry {
@ -399,8 +400,10 @@ class nsIWidget : public nsISupports {
* independent top level windows). * independent top level windows).
* *
* The dimensions given in aRect are specified in the parent's * The dimensions given in aRect are specified in the parent's
* coordinate system, or for parentless widgets such as top-level * device coordinate system.
* windows, in global CSS pixels. * 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 aParent parent nsIWidget
* @param aNativeParent native parent widget * @param aNativeParent native parent widget
@ -413,6 +416,26 @@ class nsIWidget : public nsISupports {
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData = nullptr) = 0; 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 * Allocate, initialize, and return a widget that is a child of
* |this|. The returned widget (if nonnull) has gone through the * |this|. The returned widget (if nonnull) has gone through the

View File

@ -95,6 +95,7 @@ public:
using nsWindowBase::DispatchPluginEvent; using nsWindowBase::DispatchPluginEvent;
// nsIWidget interface // nsIWidget interface
using nsWindowBase::Create; // for Create signature not overridden here
NS_IMETHOD Create(nsIWidget* aParent, NS_IMETHOD Create(nsIWidget* aParent,
nsNativeWidget aNativeParent, nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect, const LayoutDeviceIntRect& aRect,

View File

@ -145,7 +145,7 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
// XXX: need to get the default window size from prefs... // XXX: need to get the default window size from prefs...
// Doesn't come from prefs... will come from CSS/XUL/RDF // 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 // Create top level window
mWindow = do_CreateInstance(kWindowCID, &rv); mWindow = do_CreateInstance(kWindowCID, &rv);
@ -173,8 +173,10 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent,
mWindow->SetWidgetListener(this); mWindow->SetWidgetListener(this);
mWindow->Create((nsIWidget *)parentWidget, // Parent nsIWidget mWindow->Create((nsIWidget *)parentWidget, // Parent nsIWidget
nullptr, // Native parent widget nullptr, // Native parent widget
r, // Widget dimensions deskRect, // Widget dimensions
&widgetInitData); // Widget initialization data &widgetInitData); // Widget initialization data
LayoutDeviceIntRect r;
mWindow->GetClientBounds(r); mWindow->GetClientBounds(r);
// Match the default background color of content. Important on windows // Match the default background color of content. Important on windows
// since we no longer use content child widgets. // since we no longer use content child widgets.