Bug 1160250 - Extract a helper function from the triplicated composition-bounds-updating code. r=botond,tn

This commit is contained in:
Kartikaya Gupta 2015-05-07 14:39:20 -04:00
Родитель aa18869ddf
Коммит 76561c0f08
1 изменённых файлов: 67 добавлений и 78 удалений

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

@ -7596,6 +7596,65 @@ nsLayoutUtils::GetContentViewerSize(nsPresContext* aPresContext,
return true; return true;
} }
static bool
UpdateCompositionBoundsForRCDRSF(ParentLayerRect& aCompBounds,
nsPresContext* aPresContext,
const nsRect& aFrameBounds,
bool aScaleContentViewerSize,
const LayoutDeviceToLayerScale2D& aCumulativeResolution)
{
nsIFrame* rootFrame = aPresContext->PresShell()->GetRootFrame();
if (!rootFrame) {
return false;
}
// On Android, we need to do things a bit differently to get things
// right (see bug 983208, bug 988882). We use the bounds of the nearest
// widget, but clamp the height to the frame bounds height. This clamping
// is done to get correct results for a page where the page is sized to
// the screen and thus the dynamic toolbar never disappears. In such a
// case, we want the composition bounds to exclude the toolbar height,
// but the widget bounds includes it. We don't currently have a good way
// of knowing about the toolbar height, but clamping to the frame bounds
// height gives the correct answer in the cases we care about.
#ifdef MOZ_WIDGET_ANDROID
nsIWidget* widget = rootFrame->GetNearestWidget();
#else
nsView* view = rootFrame->GetView();
nsIWidget* widget = view ? view->GetWidget() : nullptr;
#endif
if (widget) {
nsIntRect widgetBounds;
widget->GetBounds(widgetBounds);
widgetBounds.MoveTo(0, 0);
aCompBounds = ParentLayerRect(ViewAs<ParentLayerPixel>(widgetBounds));
#ifdef MOZ_WIDGET_ANDROID
ParentLayerRect frameBounds =
LayoutDeviceRect::FromAppUnits(aFrameBounds, aPresContext->AppUnitsPerDevPixel())
* aCumulativeResolution
* LayerToParentLayerScale(1.0);
if (frameBounds.height < aCompBounds.height) {
aCompBounds.height = frameBounds.height;
}
#endif
return true;
}
LayoutDeviceIntSize contentSize;
if (nsLayoutUtils::GetContentViewerSize(aPresContext, contentSize)) {
LayoutDeviceToParentLayerScale scale;
if (aScaleContentViewerSize && aPresContext->GetParentPresContext()) {
scale = LayoutDeviceToParentLayerScale(
aPresContext->GetParentPresContext()->PresShell()->GetCumulativeResolution());
}
aCompBounds.SizeTo(contentSize * scale);
return true;
}
return false;
}
static bool static bool
DeflateScrollbarAreaFromCompositionBoundsFor(nsIFrame* aScrollFrame) DeflateScrollbarAreaFromCompositionBoundsFor(nsIFrame* aScrollFrame)
{ {
@ -7629,50 +7688,16 @@ nsLayoutUtils::CalculateCompositionSizeForFrame(nsIFrame* aFrame, bool aSubtract
nsPresContext* presContext = aFrame->PresContext(); nsPresContext* presContext = aFrame->PresContext();
nsIPresShell* presShell = presContext->PresShell(); nsIPresShell* presShell = presContext->PresShell();
// See the comments in the code that calculates the root
// composition bounds in ComputeFrameMetrics.
// TODO: Reuse that code here.
bool isRootContentDocRootScrollFrame = presContext->IsRootContentDocument() bool isRootContentDocRootScrollFrame = presContext->IsRootContentDocument()
&& aFrame == presShell->GetRootScrollFrame(); && aFrame == presShell->GetRootScrollFrame();
if (isRootContentDocRootScrollFrame) { if (isRootContentDocRootScrollFrame) {
if (nsIFrame* rootFrame = presShell->GetRootFrame()) { ParentLayerRect compBounds;
#ifdef MOZ_WIDGET_ANDROID // TODO: The UpdateCompositionBoundsForRCDRSF below doesn't take into
nsIWidget* widget = rootFrame->GetNearestWidget(); // account the mTransformScale as part of the LayerToParentLayerScale.
#else if (UpdateCompositionBoundsForRCDRSF(compBounds, presContext, aFrame->GetRect(),
nsView* view = rootFrame->GetView(); false, LayoutDeviceToParentLayerScale2D(presShell->GetCumulativeResolution()))) {
nsIWidget* widget = view ? view->GetWidget() : nullptr;
#endif
int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel(); int32_t auPerDevPixel = presContext->AppUnitsPerDevPixel();
if (widget) { size = nsSize(compBounds.width * auPerDevPixel, compBounds.height * auPerDevPixel);
nsIntRect widgetBounds;
widget->GetBounds(widgetBounds);
size = nsSize(widgetBounds.width * auPerDevPixel,
widgetBounds.height * auPerDevPixel);
#ifdef MOZ_WIDGET_ANDROID
nsRect frameRect = aFrame->GetRect();
float cumulativeResolution = presShell->GetCumulativeResolution();
LayoutDeviceToParentLayerScale layoutToParentLayerScale =
// The ScreenToParentLayerScale should be mTransformScale which is
// not calculated yet, but we don't yet handle CSS transforms, so we
// assume it's 1 here.
LayoutDeviceToLayerScale(cumulativeResolution) *
LayerToScreenScale(1.0) * ScreenToParentLayerScale(1.0);
ParentLayerRect frameRectPixels =
LayoutDeviceRect::FromAppUnits(frameRect, auPerDevPixel)
* layoutToParentLayerScale;
if (frameRectPixels.height < ParentLayerRect(ViewAs<ParentLayerPixel>(widgetBounds)).height) {
// Our return value is in appunits of the parent, so we need to
// include the resolution.
size.height =
NSToCoordRound(frameRect.height * cumulativeResolution);
}
#endif
} else {
LayoutDeviceIntSize contentSize;
if (nsLayoutUtils::GetContentViewerSize(presContext, contentSize)) {
size = LayoutDevicePixel::ToAppUnits(contentSize, auPerDevPixel);
}
}
} }
} }
@ -8280,44 +8305,8 @@ nsLayoutUtils::ComputeFrameMetrics(nsIFrame* aForFrame,
bool isRootContentDocRootScrollFrame = isRootScrollFrame bool isRootContentDocRootScrollFrame = isRootScrollFrame
&& presContext->IsRootContentDocument(); && presContext->IsRootContentDocument();
if (isRootContentDocRootScrollFrame) { if (isRootContentDocRootScrollFrame) {
if (nsIFrame* rootFrame = presShell->GetRootFrame()) { UpdateCompositionBoundsForRCDRSF(metrics.mCompositionBounds, presContext,
// On Android, we need to do things a bit differently to get things compositionBounds, true, metrics.GetCumulativeResolution());
// right (see bug 983208, bug 988882). We use the bounds of the nearest
// widget, but clamp the height to the frame bounds height. This clamping
// is done to get correct results for a page where the page is sized to
// the screen and thus the dynamic toolbar never disappears. In such a
// case, we want the composition bounds to exclude the toolbar height,
// but the widget bounds includes it. We don't currently have a good way
// of knowing about the toolbar height, but clamping to the frame bounds
// height gives the correct answer in the cases we care about.
#ifdef MOZ_WIDGET_ANDROID
nsIWidget* widget = rootFrame->GetNearestWidget();
#else
nsView* view = rootFrame->GetView();
nsIWidget* widget = view ? view->GetWidget() : nullptr;
#endif
if (widget) {
nsIntRect widgetBounds;
widget->GetBounds(widgetBounds);
widgetBounds.MoveTo(0,0);
metrics.mCompositionBounds = ParentLayerRect(ViewAs<ParentLayerPixel>(widgetBounds));
#ifdef MOZ_WIDGET_ANDROID
if (frameBounds.height < metrics.mCompositionBounds.height) {
metrics.mCompositionBounds.height = frameBounds.height;
}
#endif
} else {
LayoutDeviceIntSize contentSize;
if (nsLayoutUtils::GetContentViewerSize(presContext, contentSize)) {
LayoutDeviceToParentLayerScale scale;
if (presContext->GetParentPresContext()) {
float res = presContext->GetParentPresContext()->PresShell()->GetCumulativeResolution();
scale = LayoutDeviceToParentLayerScale(res);
}
metrics.mCompositionBounds.SizeTo(contentSize * scale);
}
}
}
} }
if (DeflateScrollbarAreaFromCompositionBoundsFor(aScrollFrame)) { if (DeflateScrollbarAreaFromCompositionBoundsFor(aScrollFrame)) {