Skip to content

Commit

Permalink
Bug 1304692 - Make puppet widget get coordinate rounding from parent.…
Browse files Browse the repository at this point in the history
… r=smaug

MozReview-Commit-ID: A3ornUMDmt8
  • Loading branch information
upsuper committed Sep 27, 2016
1 parent 874d7b7 commit 668d883
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 9 deletions.
5 changes: 3 additions & 2 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,14 +822,15 @@ ContentChild::ProvideWindowCommon(TabChild* aTabOpener,
renderFrame = nullptr;
}

ShowInfo showInfo(EmptyString(), false, false, true, false, 0, 0);
ShowInfo showInfo(EmptyString(), false, false, true, false, 0, 0, 0);
auto* opener = nsPIDOMWindowOuter::From(aParent);
nsIDocShell* openerShell;
if (opener && (openerShell = opener->GetDocShell())) {
nsCOMPtr<nsILoadContext> context = do_QueryInterface(openerShell);
showInfo = ShowInfo(EmptyString(), false,
context->UsePrivateBrowsing(), true, false,
aTabOpener->mDPI, aTabOpener->mDefaultScale);
aTabOpener->mDPI, aTabOpener->mRounding,
aTabOpener->mDefaultScale);
}

// Unfortunately we don't get a window unless we've shown the frame. That's
Expand Down
8 changes: 7 additions & 1 deletion dom/ipc/PBrowser.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct ShowInfo
bool fakeShowInfo;
bool isTransparent;
float dpi;
int32_t widgetRounding;
double defaultScale;
};

Expand Down Expand Up @@ -375,6 +376,11 @@ parent:
*/
sync GetDefaultScale() returns (double value);

/**
* Gets the rounding of coordinates in the widget.
*/
sync GetWidgetRounding() returns (int32_t value);

/**
* Gets maximum of touch points at current device.
*/
Expand Down Expand Up @@ -793,7 +799,7 @@ child:
* value (-1) but in the majority of the cases this saves us from two
* sync requests from the child to the parent.
*/
async UIResolutionChanged(float dpi, double scale);
async UIResolutionChanged(float dpi, int32_t rounding, double scale);

/**
* Tell the child that the system theme has changed, and that a repaint
Expand Down
25 changes: 23 additions & 2 deletions dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ TabChild::TabChild(nsIContentChild* aManager,
, mDestroyed(false)
, mUniqueId(aTabId)
, mDPI(0)
, mRounding(0)
, mDefaultScale(0)
, mIsTransparent(false)
, mIPCOpen(false)
Expand Down Expand Up @@ -1549,6 +1550,7 @@ TabChild::ApplyShowInfo(const ShowInfo& aInfo)
}
}
mDPI = aInfo.dpi();
mRounding = aInfo.widgetRounding();
mDefaultScale = aInfo.defaultScale();
mIsTransparent = aInfo.isTransparent();
}
Expand Down Expand Up @@ -2942,6 +2944,22 @@ TabChild::GetDefaultScale(double* aScale)
SendGetDefaultScale(aScale);
}

void
TabChild::GetWidgetRounding(int32_t* aRounding)
{
*aRounding = 1;
if (!mRemoteFrame) {
return;
}
if (mRounding > 0) {
*aRounding = mRounding;
return;
}

// Fallback to a sync call if needed.
SendGetWidgetRounding(aRounding);
}

void
TabChild::GetMaxTouchPoints(uint32_t* aTouchPoints)
{
Expand Down Expand Up @@ -3285,12 +3303,15 @@ TabChild::RecvRequestNotifyAfterRemotePaint()
}

bool
TabChild::RecvUIResolutionChanged(const float& aDpi, const double& aScale)
TabChild::RecvUIResolutionChanged(const float& aDpi,
const int32_t& aRounding,
const double& aScale)
{
ScreenIntSize oldScreenSize = GetInnerSize();
mDPI = 0;
mRounding = 0;
mDefaultScale = 0;
static_cast<PuppetWidget*>(mPuppetWidget.get())->UpdateBackingScaleCache(aDpi, aScale);
static_cast<PuppetWidget*>(mPuppetWidget.get())->UpdateBackingScaleCache(aDpi, aRounding, aScale);
nsCOMPtr<nsIDocument> document(GetDocument());
nsCOMPtr<nsIPresShell> presShell = document->GetShell();
if (presShell) {
Expand Down
4 changes: 4 additions & 0 deletions dom/ipc/TabChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ class TabChild final : public TabChildBase,

void GetDefaultScale(double *aScale);

void GetWidgetRounding(int32_t* aRounding);

bool IsTransparent() const { return mIsTransparent; }

void GetMaxTouchPoints(uint32_t* aTouchPoints);
Expand Down Expand Up @@ -572,6 +574,7 @@ class TabChild final : public TabChildBase,
}

virtual bool RecvUIResolutionChanged(const float& aDpi,
const int32_t& aRounding,
const double& aScale) override;

virtual bool
Expand Down Expand Up @@ -777,6 +780,7 @@ class TabChild final : public TabChildBase,

friend class ContentChild;
float mDPI;
int32_t mRounding;
double mDefaultScale;

bool mIsTransparent;
Expand Down
20 changes: 17 additions & 3 deletions dom/ipc/TabParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ TabParent::TabParent(nsIContentParent* aManager,
, mDimensions(0, 0)
, mOrientation(0)
, mDPI(0)
, mRounding(0)
, mDefaultScale(0)
, mUpdatedDimensions(false)
, mSizeMode(nsSizeMode_Normal)
Expand Down Expand Up @@ -1030,7 +1031,8 @@ TabParent::UIResolutionChanged()
// fails to cache the values, then mDefaultScale.scale might be invalid.
// We don't want to send that value to content. Just send -1 for it too in
// that case.
Unused << SendUIResolutionChanged(mDPI, mDPI < 0 ? -1.0 : mDefaultScale.scale);
Unused << SendUIResolutionChanged(mDPI, mRounding,
mDPI < 0 ? -1.0 : mDefaultScale.scale);
}
}

Expand Down Expand Up @@ -2499,6 +2501,17 @@ TabParent::RecvGetDefaultScale(double* aValue)
return true;
}

bool
TabParent::RecvGetWidgetRounding(int32_t* aValue)
{
TryCacheDPIAndScale();

MOZ_ASSERT(mRounding > 0,
"Must not ask for rounding before OwnerElement is received!");
*aValue = mRounding;
return true;
}

bool
TabParent::RecvGetMaxTouchPoints(uint32_t* aTouchPoints)
{
Expand Down Expand Up @@ -2766,6 +2779,7 @@ TabParent::TryCacheDPIAndScale()

if (widget) {
mDPI = widget->GetDPI();
mRounding = widget->RoundsWidgetCoordinatesTo();
mDefaultScale = widget->GetDefaultScale();
}
}
Expand Down Expand Up @@ -3374,11 +3388,11 @@ TabParent::GetShowInfo()
nsContentUtils::IsChromeDoc(mFrameElement->OwnerDoc()) &&
mFrameElement->HasAttr(kNameSpaceID_None, nsGkAtoms::transparent);
return ShowInfo(name, allowFullscreen, isPrivate, false,
isTransparent, mDPI, mDefaultScale.scale);
isTransparent, mDPI, mRounding, mDefaultScale.scale);
}

return ShowInfo(EmptyString(), false, false, false,
false, mDPI, mDefaultScale.scale);
false, mDPI, mRounding, mDefaultScale.scale);
}

void
Expand Down
3 changes: 3 additions & 0 deletions dom/ipc/TabParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ class TabParent final : public PBrowserParent

virtual bool RecvGetDefaultScale(double* aValue) override;

virtual bool RecvGetWidgetRounding(int32_t* aValue) override;

virtual bool RecvGetMaxTouchPoints(uint32_t* aTouchPoints) override;

virtual bool RecvGetWidgetNativeData(WindowsHandle* aValue) override;
Expand Down Expand Up @@ -635,6 +637,7 @@ class TabParent final : public PBrowserParent
ScreenIntSize mDimensions;
ScreenOrientationInternal mOrientation;
float mDPI;
int32_t mRounding;
CSSToLayoutDeviceScale mDefaultScale;
bool mUpdatedDimensions;
nsSizeMode mSizeMode;
Expand Down
15 changes: 15 additions & 0 deletions widget/PuppetWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ PuppetWidget::PuppetWidget(TabChild* aTabChild)
: mTabChild(aTabChild)
, mMemoryPressureObserver(nullptr)
, mDPI(-1)
, mRounding(-1)
, mDefaultScale(-1)
, mCursorHotspotX(0)
, mCursorHotspotY(0)
Expand Down Expand Up @@ -1194,6 +1195,20 @@ PuppetWidget::GetDefaultScaleInternal()
return mDefaultScale;
}

int32_t
PuppetWidget::RoundsWidgetCoordinatesTo()
{
if (mRounding < 0) {
if (mTabChild) {
mTabChild->GetWidgetRounding(&mRounding);
} else {
mRounding = 1;
}
}

return mRounding;
}

void*
PuppetWidget::GetNativeData(uint32_t aDataType)
{
Expand Down
6 changes: 5 additions & 1 deletion widget/PuppetWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class PuppetWidget : public nsBaseWidget
virtual LayoutDeviceIntPoint WidgetToScreenOffset() override
{ return LayoutDeviceIntPoint::FromUnknownPoint(GetWindowPosition() + GetChromeDimensions()); }

int32_t RoundsWidgetCoordinatesTo() override;

void InitEvent(WidgetGUIEvent& aEvent,
LayoutDeviceIntPoint* aPoint = nullptr);

Expand Down Expand Up @@ -202,9 +204,10 @@ class PuppetWidget : public nsBaseWidget

virtual TabChild* GetOwningTabChild() override { return mTabChild; }

void UpdateBackingScaleCache(float aDpi, double aScale)
void UpdateBackingScaleCache(float aDpi, int32_t aRounding, double aScale)
{
mDPI = aDpi;
mRounding = aRounding;
mDefaultScale = aScale;
}

Expand Down Expand Up @@ -358,6 +361,7 @@ class PuppetWidget : public nsBaseWidget

// The DPI of the screen corresponding to this widget
float mDPI;
int32_t mRounding;
double mDefaultScale;

// Precomputed answers for ExecuteNativeKeyBinding
Expand Down

0 comments on commit 668d883

Please sign in to comment.