Bug 1043644 - Use the content viewer bounds instead of the view bounds if available. r=tn

This commit is contained in:
Kartikaya Gupta 2014-07-29 14:50:48 -04:00
Родитель ca74ecaa11
Коммит 917e8cd729
4 изменённых файлов: 67 добавлений и 4 удалений

Просмотреть файл

@ -187,6 +187,11 @@ struct LayoutDevicePixel {
static LayoutDeviceIntRect FromAppUnitsToNearest(const nsRect& aRect, nscoord aAppUnitsPerDevPixel) {
return FromUntyped(aRect.ToNearestPixels(aAppUnitsPerDevPixel));
}
static nsSize ToAppUnits(const LayoutDeviceIntSize& aSize, nscoord aAppUnitsPerDevPixel) {
return nsSize(aSize.width * aAppUnitsPerDevPixel,
aSize.height * aAppUnitsPerDevPixel);
}
};
/*

Просмотреть файл

@ -787,7 +787,17 @@ static void RecordFrameMetrics(nsIFrame* aForFrame,
}
#endif
} else {
metrics.mCompositionBounds = viewBounds;
LayoutDeviceIntRect contentBounds;
if (nsLayoutUtils::GetContentViewerBounds(presContext, contentBounds)) {
LayoutDeviceToParentLayerScale scale(1.0f);
if (presContext->GetParentPresContext()) {
gfxSize res = presContext->GetParentPresContext()->PresShell()->GetCumulativeResolution();
scale = LayoutDeviceToParentLayerScale(res.width, res.height);
}
metrics.mCompositionBounds = LayoutDeviceRect(contentBounds) * scale;
} else {
metrics.mCompositionBounds = viewBounds;
}
}
}
}

Просмотреть файл

@ -80,6 +80,7 @@
#include "TiledLayerBuffer.h" // For TILEDLAYERBUFFER_TILE_SIZE
#include "ClientLayerManager.h"
#include "nsRefreshDriver.h"
#include "nsIContentViewer.h"
#include "mozilla/Preferences.h"
@ -6615,6 +6616,27 @@ nsLayoutUtils::UpdateImageVisibilityForFrame(nsIFrame* aImageFrame)
}
}
/* static */ bool
nsLayoutUtils::GetContentViewerBounds(nsPresContext* aPresContext,
LayoutDeviceIntRect& aOutRect)
{
nsCOMPtr<nsIDocShell> docShell = aPresContext->GetDocShell();
if (!docShell) {
return false;
}
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
if (!cv) {
return false;
}
nsIntRect bounds;
cv->GetBounds(bounds);
aOutRect = LayoutDeviceIntRect::FromUntyped(bounds);
return true;
}
/* static */ nsSize
nsLayoutUtils::CalculateCompositionSizeForFrame(nsIFrame* aFrame)
{
@ -6638,10 +6660,10 @@ nsLayoutUtils::CalculateCompositionSizeForFrame(nsIFrame* aFrame)
#else
view->GetWidget();
#endif
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
if (widget) {
nsIntRect widgetBounds;
widget->GetBounds(widgetBounds);
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
size = nsSize(widgetBounds.width * auPerDevPixel,
widgetBounds.height * auPerDevPixel);
#ifdef MOZ_WIDGET_ANDROID
@ -6650,7 +6672,12 @@ nsLayoutUtils::CalculateCompositionSizeForFrame(nsIFrame* aFrame)
}
#endif
} else {
size = viewSize;
LayoutDeviceIntRect contentBounds;
if (nsLayoutUtils::GetContentViewerBounds(presContext, contentBounds)) {
size = LayoutDevicePixel::ToAppUnits(contentBounds.Size(), auPerDevPixel);
} else {
size = viewSize;
}
}
}
}
@ -6666,6 +6693,7 @@ nsLayoutUtils::CalculateCompositionSizeForFrame(nsIFrame* aFrame)
return size;
}
/* static */ CSSSize
nsLayoutUtils::CalculateRootCompositionSize(nsIFrame* aFrame,
bool aIsRootContentDocRootScrollFrame,
@ -6716,7 +6744,17 @@ nsLayoutUtils::CalculateRootCompositionSize(nsIFrame* aFrame,
}
#endif
} else {
rootCompositionSize = viewSize;
LayoutDeviceIntRect contentBounds;
if (nsLayoutUtils::GetContentViewerBounds(rootPresContext, contentBounds)) {
LayoutDeviceToLayerScale scale(1.0f);
if (rootPresContext->GetParentPresContext()) {
gfxSize res = rootPresContext->GetParentPresContext()->PresShell()->GetCumulativeResolution();
scale = LayoutDeviceToLayerScale(res.width, res.height);
}
rootCompositionSize = contentBounds.Size() * scale;
} else {
rootCompositionSize = viewSize;
}
}
}
}

Просмотреть файл

@ -128,6 +128,7 @@ public:
typedef mozilla::CSSPoint CSSPoint;
typedef mozilla::CSSSize CSSSize;
typedef mozilla::LayerMargin LayerMargin;
typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
/**
* Finds previously assigned ViewID for the given content element, if any.
@ -2152,6 +2153,15 @@ public:
static void
UpdateImageVisibilityForFrame(nsIFrame* aImageFrame);
/**
* Populate aOutRect with the bounds of the content viewer corresponding
* to the given prescontext. Return true if the bounds were set, false
* otherwise.
*/
static bool
GetContentViewerBounds(nsPresContext* aPresContext,
LayoutDeviceIntRect& aOutRect);
/**
* Calculate the compostion size for a frame. See FrameMetrics.h for
* defintion of composition size (or bounds).