Bug 1304692 - Make puppet widget get coordinate rounding from parent. r=smaug

MozReview-Commit-ID: A3ornUMDmt8
This commit is contained in:
Xidorn Quan
2016-09-27 16:37:07 +10:00
parent 7664022ea0
commit c3c6afa175
8 changed files with 77 additions and 9 deletions

View File

@@ -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

View File

@@ -101,6 +101,7 @@ struct ShowInfo
bool fakeShowInfo;
bool isTransparent;
float dpi;
int32_t widgetRounding;
double defaultScale;
};
@@ -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.
*/
@@ -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

View File

@@ -541,6 +541,7 @@ TabChild::TabChild(nsIContentChild* aManager,
, mDestroyed(false)
, mUniqueId(aTabId)
, mDPI(0)
, mRounding(0)
, mDefaultScale(0)
, mIsTransparent(false)
, mIPCOpen(false)
@@ -1549,6 +1550,7 @@ TabChild::ApplyShowInfo(const ShowInfo& aInfo)
}
}
mDPI = aInfo.dpi();
mRounding = aInfo.widgetRounding();
mDefaultScale = aInfo.defaultScale();
mIsTransparent = aInfo.isTransparent();
}
@@ -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)
{
@@ -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) {

View File

@@ -484,6 +484,8 @@ public:
void GetDefaultScale(double *aScale);
void GetWidgetRounding(int32_t* aRounding);
bool IsTransparent() const { return mIsTransparent; }
void GetMaxTouchPoints(uint32_t* aTouchPoints);
@@ -572,6 +574,7 @@ public:
}
virtual bool RecvUIResolutionChanged(const float& aDpi,
const int32_t& aRounding,
const double& aScale) override;
virtual bool
@@ -777,6 +780,7 @@ private:
friend class ContentChild;
float mDPI;
int32_t mRounding;
double mDefaultScale;
bool mIsTransparent;

View File

@@ -277,6 +277,7 @@ TabParent::TabParent(nsIContentParent* aManager,
, mDimensions(0, 0)
, mOrientation(0)
, mDPI(0)
, mRounding(0)
, mDefaultScale(0)
, mUpdatedDimensions(false)
, mSizeMode(nsSizeMode_Normal)
@@ -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);
}
}
@@ -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)
{
@@ -2766,6 +2779,7 @@ TabParent::TryCacheDPIAndScale()
if (widget) {
mDPI = widget->GetDPI();
mRounding = widget->RoundsWidgetCoordinatesTo();
mDefaultScale = widget->GetDefaultScale();
}
}
@@ -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

View File

@@ -321,6 +321,8 @@ public:
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;
@@ -635,6 +637,7 @@ protected:
ScreenIntSize mDimensions;
ScreenOrientationInternal mOrientation;
float mDPI;
int32_t mRounding;
CSSToLayoutDeviceScale mDefaultScale;
bool mUpdatedDimensions;
nsSizeMode mSizeMode;

View File

@@ -79,6 +79,7 @@ PuppetWidget::PuppetWidget(TabChild* aTabChild)
: mTabChild(aTabChild)
, mMemoryPressureObserver(nullptr)
, mDPI(-1)
, mRounding(-1)
, mDefaultScale(-1)
, mCursorHotspotX(0)
, mCursorHotspotY(0)
@@ -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)
{

View File

@@ -135,6 +135,8 @@ public:
virtual LayoutDeviceIntPoint WidgetToScreenOffset() override
{ return LayoutDeviceIntPoint::FromUnknownPoint(GetWindowPosition() + GetChromeDimensions()); }
int32_t RoundsWidgetCoordinatesTo() override;
void InitEvent(WidgetGUIEvent& aEvent,
LayoutDeviceIntPoint* aPoint = nullptr);
@@ -202,9 +204,10 @@ public:
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;
}
@@ -358,6 +361,7 @@ private:
// The DPI of the screen corresponding to this widget
float mDPI;
int32_t mRounding;
double mDefaultScale;
// Precomputed answers for ExecuteNativeKeyBinding