Skip to content

Commit

Permalink
Merge HandleViewportChange and share between TabChildHepers
Browse files Browse the repository at this point in the history
  • Loading branch information
tmeshkova committed Mar 12, 2014
1 parent f6aad0d commit 5be78bb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 256 deletions.
50 changes: 34 additions & 16 deletions dom/ipc/TabChild.cpp
Expand Up @@ -534,19 +534,19 @@ TabChildBase::GetPageSize(nsCOMPtr<nsIDocument> aDocument, const CSSSize& aViewp
std::max(htmlHeight, bodyHeight));
}

void
TabChild::HandlePossibleViewportChange()
bool
TabChildBase::HandlePossibleViewportChange()
{
if (!IsAsyncPanZoomEnabled()) {
return;
return false;
}

nsCOMPtr<nsIDocument> document(GetDocument());
nsCOMPtr<nsIDOMWindowUtils> utils(GetDOMWindowUtils());

nsViewportInfo viewportInfo = nsContentUtils::GetViewportInfo(document, mInnerSize);
uint32_t presShellId;
ViewID viewId;
mozilla::layers::FrameMetrics::ViewID viewId;
bool scrollIdentifiersValid = APZCCallbackHelper::GetScrollIdentifiers(
document->GetDocumentElement(), &presShellId, &viewId);
if (scrollIdentifiersValid) {
Expand All @@ -555,10 +555,10 @@ TabChild::HandlePossibleViewportChange()
viewportInfo.IsDoubleTapZoomAllowed(),
viewportInfo.GetMinZoom(),
viewportInfo.GetMaxZoom());
SendUpdateZoomConstraints(presShellId,
viewId,
/* isRoot = */ true,
constraints);
DoUpdateZoomConstraints(presShellId,
viewId,
/* isRoot = */ true,
constraints);
}

float screenW = mInnerSize.width;
Expand All @@ -568,7 +568,7 @@ TabChild::HandlePossibleViewportChange()
// We're not being displayed in any way; don't bother doing anything because
// that will just confuse future adjustments.
if (!screenW || !screenH) {
return;
return false;
}

float oldBrowserWidth = mOldViewportWidth;
Expand All @@ -588,7 +588,7 @@ TabChild::HandlePossibleViewportChange()
// window.innerWidth before they are painted have a correct value (bug
// 771575).
if (!mContentDocumentIsDisplayed) {
return;
return false;
}

float oldScreenWidth = mLastRootMetrics.mCompositionBounds.width;
Expand Down Expand Up @@ -651,7 +651,7 @@ TabChild::HandlePossibleViewportChange()
CSSSize pageSize = GetPageSize(document, viewport);
if (!pageSize.width) {
// Return early rather than divide by 0.
return;
return false;
}
metrics.mScrollableRect = CSSRect(CSSPoint(), pageSize);

Expand Down Expand Up @@ -679,12 +679,26 @@ TabChild::HandlePossibleViewportChange()
viewportInfo.IsDoubleTapZoomAllowed(),
viewportInfo.GetMinZoom(),
viewportInfo.GetMaxZoom());
SendUpdateZoomConstraints(presShellId,
viewId,
/* isRoot = */ true,
constraints);
DoUpdateZoomConstraints(presShellId,
viewId,
/* isRoot = */ true,
constraints);
}
}

return true;
}

bool
TabChild::DoUpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const bool& aIsRoot,
const ZoomConstraints& aConstraints)
{
return SendUpdateZoomConstraints(aPresShellId,
aViewId,
aIsRoot,
aConstraints);
}

nsresult
Expand Down Expand Up @@ -1589,7 +1603,7 @@ TabChild::RecvAcknowledgeScrollUpdate(const ViewID& aScrollId,
}

bool
TabChild::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
TabChildBase::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
{
if (!mGlobal || !mTabChildGlobal) {
return true;
Expand Down Expand Up @@ -1639,6 +1653,10 @@ TabChild::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
data.AppendLiteral(", \"height\" : ");
data.AppendFloat(newMetrics.mScrollableRect.height);
data.AppendLiteral(" }");
data.AppendPrintf(", \"resolution\" : "); // TODO: check if it's actually used?
data.AppendPrintf("{ \"width\" : ");
data.AppendFloat(aFrameMetrics.mZoom.scale);
data.AppendPrintf(" }");
data.AppendLiteral(", \"cssCompositedRect\" : ");
data.AppendLiteral("{ \"width\" : ");
data.AppendFloat(cssCompositedRect.width);
Expand Down
26 changes: 17 additions & 9 deletions dom/ipc/TabChild.h
Expand Up @@ -155,6 +155,16 @@ class TabChildBase : public nsFrameScriptExecutor,
virtual nsIWidget* WebWidget() = 0;
nsIPrincipal* GetPrincipal() { return mPrincipal; }
bool IsAsyncPanZoomEnabled();
// Recalculates the display state, including the CSS
// viewport. This should be called whenever we believe the
// viewport data on a document may have changed. If it didn't
// change, this function doesn't do anything. However, it should
// not be called all the time as it is fairly expensive.
bool HandlePossibleViewportChange();
virtual bool DoUpdateZoomConstraints(const uint32_t& aPresShellId,
const mozilla::layers::FrameMetrics::ViewID& aViewId,
const bool& aIsRoot,
const mozilla::layers::ZoomConstraints& aConstraints) = 0;

protected:
CSSSize GetPageSize(nsCOMPtr<nsIDocument> aDocument, const CSSSize& aViewport);
Expand Down Expand Up @@ -185,6 +195,8 @@ class TabChildBase : public nsFrameScriptExecutor,
bool HasValidInnerSize();
void InitializeRootMetrics();

bool ProcessUpdateFrame(const mozilla::layers::FrameMetrics& aFrameMetrics);

protected:
float mOldViewportWidth;
bool mContentDocumentIsDisplayed;
Expand Down Expand Up @@ -259,7 +271,10 @@ class TabChild : public PBrowserChild,
const mozilla::dom::StructuredCloneData& aData,
JS::Handle<JSObject *> aCpows,
nsIPrincipal* aPrincipal) MOZ_OVERRIDE;

virtual bool DoUpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const bool& aIsRoot,
const ZoomConstraints& aConstraints) MOZ_OVERRIDE;
virtual bool RecvLoadURL(const nsCString& uri) MOZ_OVERRIDE;
virtual bool RecvCacheFileDescriptor(const nsString& aPath,
const FileDescriptor& aFileDescriptor)
Expand Down Expand Up @@ -480,18 +495,11 @@ class TabChild : public PBrowserChild,
bool InitRenderingState();
void DestroyWindow();
void SetProcessNameToAppName();
bool ProcessUpdateFrame(const mozilla::layers::FrameMetrics& aFrameMetrics);


// Call RecvShow(nsIntSize(0, 0)) and block future calls to RecvShow().
void DoFakeShow();

// Recalculates the display state, including the CSS
// viewport. This should be called whenever we believe the
// viewport data on a document may have changed. If it didn't
// change, this function doesn't do anything. However, it should
// not be called all the time as it is fairly expensive.
void HandlePossibleViewportChange();

// These methods are used for tracking synthetic mouse events
// dispatched for compatibility. On each touch event, we
// UpdateTapState(). If we've detected that the current gesture
Expand Down

0 comments on commit 5be78bb

Please sign in to comment.