Skip to content

Commit

Permalink
Bug 1261842 - Add methods to nsIDocShellTreeOwner for sizing the prim…
Browse files Browse the repository at this point in the history
…ary content. r=smaug

MozReview-Commit-ID: CqiRTVd444n
  • Loading branch information
mikeconley committed Jul 14, 2016
1 parent dbb9b25 commit 8874f90
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 58 deletions.
26 changes: 26 additions & 0 deletions docshell/base/nsIDocShellTreeOwner.idl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ interface nsIDocShellTreeOwner : nsISupports
*/
void sizeShellTo(in nsIDocShellTreeItem shell, in long cx, in long cy);

/*
Gets the size of the primary content area in CSS pixels. This should work
for both in-process and out-of-process content areas.
*/
void getPrimaryContentSize(out long width, out long height);
/*
Sets the size of the primary content area in CSS pixels. This should work
for both in-process and out-of-process content areas.
*/
void setPrimaryContentSize(in long width, in long height);

/*
Gets the size of the root docshell in CSS pixels.
*/
void getRootShellSize(out long width, out long height);
/*
Sets the size of the root docshell in CSS pixels.
*/
void setRootShellSize(in long width, in long height);

/*
Sets the persistence of different attributes of the window.
*/
Expand All @@ -98,4 +118,10 @@ interface nsIDocShellTreeOwner : nsISupports
Gets the number of targettable docshells.
*/
readonly attribute unsigned long targetableShellCount;

/*
Returns true if there is a primary content shell or a primary
tab parent.
*/
readonly attribute bool hasPrimaryContent;
};
4 changes: 1 addition & 3 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5414,8 +5414,6 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
nsCOMPtr<mozIDOMWindowProxy> window;
TabParent::AutoUseNewTab aunt(newTab, aWindowIsNew, aURLToLoad);

const char* features = aFeatures.IsVoid() ? nullptr : aFeatures.get();

nsCOMPtr<nsPIWindowWatcher> pwwatch =
do_GetService(NS_WINDOWWATCHER_CONTRACTID, aResult);

Expand All @@ -5429,7 +5427,7 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab,
// to open a new window that is unrelated to a pre-existing tab.
*aResult = pwwatch->OpenWindowWithoutParent(getter_AddRefs(newRemoteTab));
} else {
*aResult = pwwatch->OpenWindowWithTabParent(thisTabParent, features, aCalledFromJS,
*aResult = pwwatch->OpenWindowWithTabParent(thisTabParent, aFeatures, aCalledFromJS,
aFullZoom, getter_AddRefs(newRemoteTab));
}

Expand Down
35 changes: 35 additions & 0 deletions embedding/browser/nsDocShellTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,34 @@ nsDocShellTreeOwner::GetPrimaryTabParent(nsITabParent** aTab)
return NS_OK;
}

NS_IMETHODIMP
nsDocShellTreeOwner::GetPrimaryContentSize(int32_t* aWidth,
int32_t* aHeight)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsDocShellTreeOwner::SetPrimaryContentSize(int32_t aWidth,
int32_t aHeight)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsDocShellTreeOwner::GetRootShellSize(int32_t* aWidth,
int32_t* aHeight)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsDocShellTreeOwner::SetRootShellSize(int32_t aWidth,
int32_t aHeight)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsDocShellTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
int32_t aCX, int32_t aCY)
Expand Down Expand Up @@ -537,6 +565,13 @@ nsDocShellTreeOwner::GetTargetableShellCount(uint32_t* aResult)
return NS_OK;
}

NS_IMETHODIMP
nsDocShellTreeOwner::GetHasPrimaryContent(bool* aResult)
{
*aResult = mPrimaryTabParent || mPrimaryContentShell;
return NS_OK;
}

//*****************************************************************************
// nsDocShellTreeOwner::nsIBaseWindow
//*****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion embedding/components/windowwatcher/nsPIWindowWatcher.idl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ interface nsPIWindowWatcher : nsISupports
* window.
*/
nsITabParent openWindowWithTabParent(in nsITabParent aOpeningTab,
in string aFeatures,
in ACString aFeatures,
in boolean aCalledFromJS,
in float aOpenerFullZoom);

Expand Down
84 changes: 52 additions & 32 deletions embedding/components/windowwatcher/nsWindowWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ CheckUserContextCompatibility(nsIDocShell* aDocShell)
NS_IMETHODIMP
nsWindowWatcher::OpenWindowWithoutParent(nsITabParent** aResult)
{
return OpenWindowWithTabParent(nullptr, "", true, 1.0f, aResult);
return OpenWindowWithTabParent(nullptr, EmptyCString(), true, 1.0f, aResult);
}

NS_IMETHODIMP
nsWindowWatcher::OpenWindowWithTabParent(nsITabParent* aOpeningTabParent,
const char* aFeatures,
const nsACString& aFeatures,
bool aCalledFromJS,
float aOpenerFullZoom,
nsITabParent** aResult)
Expand Down Expand Up @@ -569,8 +569,7 @@ nsWindowWatcher::OpenWindowWithTabParent(nsITabParent* aOpeningTabParent,
windowCreator2->SetScreenId(retval);
#endif

nsAutoCString features(aFeatures);
uint32_t chromeFlags = CalculateChromeFlagsForChild(features);
uint32_t chromeFlags = CalculateChromeFlagsForChild(aFeatures);

// A content process has asked for a new window, which implies
// that the new window will need to be remote.
Expand Down Expand Up @@ -616,15 +615,15 @@ nsWindowWatcher::OpenWindowWithTabParent(nsITabParent* aOpeningTabParent,
// that will also run with out-of-process tabs.
chromeContext->SetRemoteTabs(true);

if (PL_strcasestr(features.get(), "width=") ||
PL_strcasestr(features.get(), "height=")) {
if (PL_strcasestr(aFeatures.BeginReading(), "width=") ||
PL_strcasestr(aFeatures.BeginReading(), "height=")) {
chromeTreeOwner->SetPersistence(false, false, false);
}

SizeSpec sizeSpec;
CalcSizeSpec(features, sizeSpec);
SizeOpenedDocShellItem(chromeTreeItem, parentWindowOuter, false, sizeSpec,
&aOpenerFullZoom);
CalcSizeSpec(aFeatures, sizeSpec);
SizeOpenedWindow(chromeTreeOwner, parentWindowOuter, false, sizeSpec,
&aOpenerFullZoom);

nsCOMPtr<nsITabParent> newTabParent;
chromeTreeOwner->GetPrimaryTabParent(getter_AddRefs(newTabParent));
Expand Down Expand Up @@ -1228,8 +1227,10 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent,
}

if (isNewToplevelWindow) {
SizeOpenedDocShellItem(newDocShellItem, aParent, isCallerChrome, sizeSpec,
aOpenerFullZoom);
nsCOMPtr<nsIDocShellTreeOwner> newTreeOwner;
newDocShellItem->GetTreeOwner(getter_AddRefs(newTreeOwner));
SizeOpenedWindow(newTreeOwner, aParent, isCallerChrome, sizeSpec,
aOpenerFullZoom);
}

// XXXbz isn't windowIsModal always true when windowIsModalContentDialog?
Expand Down Expand Up @@ -2236,18 +2237,34 @@ nsWindowWatcher::CalcSizeSpec(const nsACString& aFeatures, SizeSpec& aResult)
}
}

/* Size and position the new window according to aSizeSpec. This method
/* Size and position a new window according to aSizeSpec. This method
is assumed to be called after the window has already been given
a default position and size; thus its current position and size are
accurate defaults. The new window is made visible at method end.
@param aTreeOwner
The top-level nsIDocShellTreeOwner of the newly opened window.
@param aParent (optional)
The parent window from which to inherit zoom factors from if
aOpenerFullZoom isn't passed.
@param aIsCallerChrome
True if the code requesting the new window is privileged.
@param aSizeSpec
The size that the new window should be.
@param aOpenerFullZoom
An optional pointer to a zoom factor to scale the content
to.
*/
void
nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
mozIDOMWindowProxy* aParent,
bool aIsCallerChrome,
const SizeSpec& aSizeSpec,
float* aOpenerFullZoom)
nsWindowWatcher::SizeOpenedWindow(nsIDocShellTreeOwner* aTreeOwner,
mozIDOMWindowProxy* aParent,
bool aIsCallerChrome,
const SizeSpec& aSizeSpec,
float* aOpenerFullZoom)
{
// We should only be sizing top-level windows if we're in the parent
// process.
MOZ_ASSERT(XRE_IsParentProcess());

// position and size of window
int32_t left = 0, top = 0, width = 100, height = 100;
// difference between chrome and content size
Expand All @@ -2256,9 +2273,7 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
bool sizeChromeWidth = true, sizeChromeHeight = true;

// get various interfaces for aDocShellItem, used throughout this method
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
aDocShellItem->GetTreeOwner(getter_AddRefs(treeOwner));
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin(do_QueryInterface(treeOwner));
nsCOMPtr<nsIBaseWindow> treeOwnerAsWin(do_QueryInterface(aTreeOwner));
if (!treeOwnerAsWin) { // we'll need this to actually size the docshell
return;
}
Expand All @@ -2275,7 +2290,7 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
}
}

double scale;
double scale = 1.0;
treeOwnerAsWin->GetUnscaledDevicePixelsPerCSSPixel(&scale);

/* The current position and size will be unchanged if not specified
Expand All @@ -2291,16 +2306,16 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
width = NSToIntRound(width / scale);
height = NSToIntRound(height / scale);
{
// scope shellWindow why not
nsCOMPtr<nsIBaseWindow> shellWindow(do_QueryInterface(aDocShellItem));
if (shellWindow) {
int32_t cox, coy;
double shellScale;
shellWindow->GetSize(&cox, &coy);
shellWindow->GetUnscaledDevicePixelsPerCSSPixel(&shellScale);
chromeWidth = width - NSToIntRound(cox / shellScale);
chromeHeight = height - NSToIntRound(coy / shellScale);
int32_t contentWidth, contentHeight;
bool hasPrimaryContent = false;
aTreeOwner->GetHasPrimaryContent(&hasPrimaryContent);
if (hasPrimaryContent) {
aTreeOwner->GetPrimaryContentSize(&contentWidth, &contentHeight);
} else {
aTreeOwner->GetRootShellSize(&contentWidth, &contentHeight);
}
chromeWidth = width - contentWidth;
chromeHeight = height - contentHeight;
}

// Set up left/top
Expand Down Expand Up @@ -2352,7 +2367,6 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
}

if (!enabled) {

// Security check failed. Ensure all args meet minimum reqs.

int32_t oldTop = top, oldLeft = left;
Expand Down Expand Up @@ -2451,7 +2465,13 @@ nsWindowWatcher::SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
chrome or content sizes. If we have a mix, use the chrome size
adjusted by the chrome/content differences calculated earlier. */
if (!sizeChromeWidth && !sizeChromeHeight) {
treeOwner->SizeShellTo(aDocShellItem, width * scale, height * scale);
bool hasPrimaryContent = false;
aTreeOwner->GetHasPrimaryContent(&hasPrimaryContent);
if (hasPrimaryContent) {
aTreeOwner->SetPrimaryContentSize(width * scale, height * scale);
} else {
aTreeOwner->SetRootShellSize(width * scale, height * scale);
}
} else {
if (!sizeChromeWidth) {
width += chromeWidth;
Expand Down
10 changes: 5 additions & 5 deletions embedding/components/windowwatcher/nsWindowWatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ class nsWindowWatcher
nsPIDOMWindowOuter* aParent,
bool aWindowIsNew,
mozIDOMWindowProxy** aOpenedWindow);
static void SizeOpenedDocShellItem(nsIDocShellTreeItem* aDocShellItem,
mozIDOMWindowProxy* aParent,
bool aIsCallerChrome,
const SizeSpec& aSizeSpec,
float* aOpenerFullZoom);
static void SizeOpenedWindow(nsIDocShellTreeOwner* aTreeOwner,
mozIDOMWindowProxy* aParent,
bool aIsCallerChrome,
const SizeSpec& aSizeSpec,
float* aOpenerFullZoom);
static void GetWindowTreeItem(mozIDOMWindowProxy* aWindow,
nsIDocShellTreeItem** aResult);
static void GetWindowTreeOwner(nsPIDOMWindowOuter* aWindow,
Expand Down
2 changes: 2 additions & 0 deletions xpfe/appshell/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ LOCAL_INCLUDES += [
]

FINAL_LIBRARY = 'xul'

include('/ipc/chromium/chromium-config.mozbuild')
39 changes: 39 additions & 0 deletions xpfe/appshell/nsChromeTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,38 @@ nsChromeTreeOwner::GetPrimaryTabParent(nsITabParent** aTab)
return mXULWindow->GetPrimaryTabParent(aTab);
}

NS_IMETHODIMP
nsChromeTreeOwner::GetPrimaryContentSize(int32_t* aWidth,
int32_t* aHeight)
{
NS_ENSURE_STATE(mXULWindow);
return mXULWindow->GetPrimaryContentSize(aWidth, aHeight);
}

NS_IMETHODIMP
nsChromeTreeOwner::SetPrimaryContentSize(int32_t aWidth,
int32_t aHeight)
{
NS_ENSURE_STATE(mXULWindow);
return mXULWindow->SetPrimaryContentSize(aWidth, aHeight);
}

NS_IMETHODIMP
nsChromeTreeOwner::GetRootShellSize(int32_t* aWidth,
int32_t* aHeight)
{
NS_ENSURE_STATE(mXULWindow);
return mXULWindow->GetRootShellSize(aWidth, aHeight);
}

NS_IMETHODIMP
nsChromeTreeOwner::SetRootShellSize(int32_t aWidth,
int32_t aHeight)
{
NS_ENSURE_STATE(mXULWindow);
return mXULWindow->SetRootShellSize(aWidth, aHeight);
}

NS_IMETHODIMP nsChromeTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
int32_t aCX, int32_t aCY)
{
Expand Down Expand Up @@ -349,6 +381,13 @@ nsChromeTreeOwner::GetTargetableShellCount(uint32_t* aResult)
return NS_OK;
}

NS_IMETHODIMP
nsChromeTreeOwner::GetHasPrimaryContent(bool* aResult)
{
NS_ENSURE_STATE(mXULWindow);
return mXULWindow->GetHasPrimaryContent(aResult);
}

//*****************************************************************************
// nsChromeTreeOwner::nsIBaseWindow
//*****************************************************************************
Expand Down
Loading

0 comments on commit 8874f90

Please sign in to comment.