mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 12:50:09 +00:00
Bug 1294442: Part 1 - Allow calculating content size with constraints. r=smaug
MozReview-Commit-ID: 4AyootQ5icK --HG-- extra : rebase_source : 8d2421263e7636c99cecd1f7cf9dda2da20be6f3
This commit is contained in:
parent
b4c8518aff
commit
a6c6580702
@ -234,6 +234,16 @@ interface nsIContentViewer : nsISupports
|
||||
*/
|
||||
void getContentSize(out long width, out long height);
|
||||
|
||||
/**
|
||||
* Returns the preferred width and height of the content, constrained to the
|
||||
* given maximum values. If either maxWidth or maxHeight is less than zero,
|
||||
* that dimension is not constrained.
|
||||
*
|
||||
* All input and output values are in device pixels, rather than CSS pixels.
|
||||
*/
|
||||
void getContentSizeConstrained(in long maxWidth, in long maxHeight,
|
||||
out long width, out long height);
|
||||
|
||||
/** The minimum font size */
|
||||
attribute long minFontSize;
|
||||
|
||||
|
@ -300,6 +300,9 @@ private:
|
||||
nsresult GetPopupLinkNode(nsIDOMNode** aNode);
|
||||
nsresult GetPopupImageNode(nsIImageLoadingContent** aNode);
|
||||
|
||||
nsresult GetContentSizeInternal(int32_t* aWidth, int32_t* aHeight,
|
||||
nscoord aMaxWidth, nscoord aMaxHeight);
|
||||
|
||||
void PrepareToStartLoad(void);
|
||||
|
||||
nsresult SyncParentSubDocMap();
|
||||
@ -3358,22 +3361,12 @@ nsDocumentViewer::ResumePainting()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocumentViewer::GetContentSize(int32_t* aWidth, int32_t* aHeight)
|
||||
nsresult
|
||||
nsDocumentViewer::GetContentSizeInternal(int32_t* aWidth, int32_t* aHeight,
|
||||
nscoord aMaxWidth, nscoord aMaxHeight)
|
||||
{
|
||||
NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
// Skip doing this on docshell-less documents for now
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(mContainer);
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellParent;
|
||||
docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent));
|
||||
|
||||
// It's only valid to access this from a top frame. Doesn't work from
|
||||
// sub-frames.
|
||||
NS_ENSURE_TRUE(!docShellParent, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
GetPresShell(getter_AddRefs(presShell));
|
||||
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
|
||||
@ -3390,6 +3383,9 @@ nsDocumentViewer::GetContentSize(int32_t* aWidth, int32_t* aHeight)
|
||||
nsRenderingContext rcx(presShell->CreateReferenceRenderingContext());
|
||||
prefWidth = root->GetPrefISize(&rcx);
|
||||
}
|
||||
if (prefWidth > aMaxWidth) {
|
||||
prefWidth = aMaxWidth;
|
||||
}
|
||||
|
||||
nsresult rv = presShell->ResizeReflow(prefWidth, NS_UNCONSTRAINEDSIZE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -3400,6 +3396,14 @@ nsDocumentViewer::GetContentSize(int32_t* aWidth, int32_t* aHeight)
|
||||
|
||||
// so how big is it?
|
||||
nsRect shellArea = presContext->GetVisibleArea();
|
||||
if (shellArea.height > aMaxHeight) {
|
||||
// Reflow to max height if we would up too tall.
|
||||
rv = presShell->ResizeReflow(prefWidth, aMaxHeight);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
shellArea = presContext->GetVisibleArea();
|
||||
}
|
||||
|
||||
// Protect against bogus returns here
|
||||
NS_ENSURE_TRUE(shellArea.width != NS_UNCONSTRAINEDSIZE &&
|
||||
shellArea.height != NS_UNCONSTRAINEDSIZE,
|
||||
@ -3411,6 +3415,43 @@ nsDocumentViewer::GetContentSize(int32_t* aWidth, int32_t* aHeight)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocumentViewer::GetContentSize(int32_t* aWidth, int32_t* aHeight)
|
||||
{
|
||||
// Skip doing this on docshell-less documents for now
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(mContainer);
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellParent;
|
||||
docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent));
|
||||
|
||||
// It's only valid to access this from a top frame. Doesn't work from
|
||||
// sub-frames.
|
||||
NS_ENSURE_TRUE(!docShellParent, NS_ERROR_FAILURE);
|
||||
|
||||
return GetContentSizeInternal(aWidth, aHeight, NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocumentViewer::GetContentSizeConstrained(int32_t aMaxWidth, int32_t aMaxHeight,
|
||||
int32_t* aWidth, int32_t* aHeight)
|
||||
{
|
||||
RefPtr<nsPresContext> presContext;
|
||||
GetPresContext(getter_AddRefs(presContext));
|
||||
NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE);
|
||||
|
||||
nscoord maxWidth = NS_UNCONSTRAINEDSIZE;
|
||||
nscoord maxHeight = NS_UNCONSTRAINEDSIZE;
|
||||
if (aMaxWidth > 0) {
|
||||
maxWidth = presContext->DevPixelsToAppUnits(aMaxWidth);
|
||||
}
|
||||
if (aMaxHeight > 0) {
|
||||
maxHeight = presContext->DevPixelsToAppUnits(aMaxHeight);
|
||||
}
|
||||
|
||||
return GetContentSizeInternal(aWidth, aHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsDocViewerSelectionListener, nsISelectionListener)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user