Bug 1171182 - Browser Zoom Query for NPAPI; r=bsmedberg r=jaas

This commit is contained in:
Kyle Machulis 2016-03-17 12:00:59 -07:00
parent 1acf9bbc23
commit 869a7a0a24
11 changed files with 122 additions and 15 deletions

View File

@ -412,6 +412,8 @@ typedef enum {
NPNVdocumentOrigin = 22,
NPNVCSSZoomFactor = 23,
NPNVpluginDrawingModel = 1000 /* Get the current drawing model (NPDrawingModel) */
#if defined(XP_MACOSX)
, NPNVcontentsScaleFactor = 1001

View File

@ -2031,6 +2031,14 @@ _getvalue(NPP npp, NPNVariable variable, void *result)
}
#endif
case NPNVCSSZoomFactor: {
nsNPAPIPluginInstance *inst =
(nsNPAPIPluginInstance *) (npp ? npp->ndata : nullptr);
double scaleFactor = inst ? inst->GetCSSZoomFactor() : 1.0;
*(double*)result = scaleFactor;
return NPERR_NO_ERROR;
}
#ifdef MOZ_WIDGET_ANDROID
case kLogInterfaceV0_ANPGetValue: {
LOG("get log interface");

View File

@ -1001,7 +1001,8 @@ nsresult nsNPAPIPluginInstance::IsRemoteDrawingCoreAnimation(bool* aDrawing)
#endif
}
nsresult nsNPAPIPluginInstance::ContentsScaleFactorChanged(double aContentsScaleFactor)
nsresult
nsNPAPIPluginInstance::ContentsScaleFactorChanged(double aContentsScaleFactor)
{
#ifdef XP_MACOSX
if (!mPlugin)
@ -1021,6 +1022,31 @@ nsresult nsNPAPIPluginInstance::ContentsScaleFactorChanged(double aContentsScale
#endif
}
nsresult
nsNPAPIPluginInstance::CSSZoomFactorChanged(float aCSSZoomFactor)
{
if (RUNNING != mRunning)
return NS_OK;
PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("nsNPAPIPluginInstance informing plugin of CSS Zoom Factor change this=%p\n",this));
if (!mPlugin || !mPlugin->GetLibrary())
return NS_ERROR_FAILURE;
NPPluginFuncs* pluginFunctions = mPlugin->PluginFuncs();
if (!pluginFunctions->setvalue)
return NS_ERROR_FAILURE;
PluginDestructionGuard guard(this);
NPError error;
double value = static_cast<double>(aCSSZoomFactor);
NS_TRY_SAFE_CALL_RETURN(error, (*pluginFunctions->setvalue)(&mNPP, NPNVCSSZoomFactor, &value), this,
NS_PLUGIN_CALL_UNSAFE_TO_REENTER_GECKO);
return (error == NPERR_NO_ERROR) ? NS_OK : NS_ERROR_FAILURE;
}
nsresult
nsNPAPIPluginInstance::GetJSObject(JSContext *cx, JSObject** outObject)
{
@ -1739,6 +1765,16 @@ nsNPAPIPluginInstance::GetContentsScaleFactor()
return scaleFactor;
}
float
nsNPAPIPluginInstance::GetCSSZoomFactor()
{
float zoomFactor = 1.0;
if (mOwner) {
mOwner->GetCSSZoomFactor(&zoomFactor);
}
return zoomFactor;
}
nsresult
nsNPAPIPluginInstance::GetRunID(uint32_t* aRunID)
{

View File

@ -100,6 +100,7 @@ public:
nsresult GetDrawingModel(int32_t* aModel);
nsresult IsRemoteDrawingCoreAnimation(bool* aDrawing);
nsresult ContentsScaleFactorChanged(double aContentsScaleFactor);
nsresult CSSZoomFactorChanged(float aCSSZoomFactor);
nsresult GetJSObject(JSContext *cx, JSObject** outObject);
bool ShouldCache();
nsresult IsWindowless(bool* isWindowless);
@ -306,6 +307,9 @@ public:
// Returns the contents scale factor of the screen the plugin is drawn on.
double GetContentsScaleFactor();
// Returns the css zoom factor of the document the plugin is drawn on.
float GetCSSZoomFactor();
nsresult GetRunID(uint32_t *aRunID);
static bool InPluginCallUnsafeForReentry() { return gInUnsafePluginCalls > 0; }

View File

@ -361,6 +361,7 @@ nsPluginInstanceOwner::nsPluginInstanceOwner()
mLastScaleFactor = 1.0;
mShouldBlurOnActivate = false;
#endif
mLastCSSZoomFactor = 1.0;
mContentFocused = false;
mWidgetVisible = true;
mPluginWindowVisible = false;
@ -3535,17 +3536,6 @@ nsPluginInstanceOwner::SendWindowFocusChanged(bool aIsActive)
NS_PLUGIN_CALL_SAFE_TO_REENTER_GECKO);
}
void
nsPluginInstanceOwner::ResolutionMayHaveChanged()
{
double scaleFactor = 1.0;
GetContentsScaleFactor(&scaleFactor);
if (scaleFactor != mLastScaleFactor) {
ContentsScaleFactorChanged(scaleFactor);
mLastScaleFactor = scaleFactor;
}
}
void
nsPluginInstanceOwner::HidePluginWindow()
{
@ -3616,6 +3606,28 @@ nsPluginInstanceOwner::UpdateWindowVisibility(bool aVisible)
}
#endif // XP_MACOSX
void
nsPluginInstanceOwner::ResolutionMayHaveChanged()
{
#ifdef XP_MACOSX
double scaleFactor = 1.0;
GetContentsScaleFactor(&scaleFactor);
if (scaleFactor != mLastScaleFactor) {
ContentsScaleFactorChanged(scaleFactor);
mLastScaleFactor = scaleFactor;
}
#endif
float zoomFactor = 1.0;
GetCSSZoomFactor(&zoomFactor);
if (zoomFactor != mLastCSSZoomFactor) {
if (mInstance) {
mInstance->CSSZoomFactorChanged(zoomFactor);
}
mLastCSSZoomFactor = zoomFactor;
}
}
void
nsPluginInstanceOwner::UpdateDocumentActiveState(bool aIsActive)
{
@ -3695,6 +3707,18 @@ nsPluginInstanceOwner::GetContentsScaleFactor(double *result)
return NS_OK;
}
void
nsPluginInstanceOwner::GetCSSZoomFactor(float *result)
{
nsCOMPtr<nsIContent> content = do_QueryReferent(mContent);
nsIPresShell* presShell = nsContentUtils::FindPresShellForDocument(content->OwnerDoc());
if (presShell) {
*result = presShell->GetPresContext()->DeviceContext()->GetFullZoom();
} else {
*result = 1.0;
}
}
void nsPluginInstanceOwner::SetFrame(nsPluginFrame *aFrame)
{
// Don't do anything if the frame situation hasn't changed.

View File

@ -138,7 +138,6 @@ public:
enum { ePluginPaintEnable, ePluginPaintDisable };
void WindowFocusMayHaveChanged();
void ResolutionMayHaveChanged();
bool WindowIsActive();
void SendWindowFocusChanged(bool aIsActive);
@ -160,6 +159,7 @@ public:
void UpdateWindowVisibility(bool aVisible);
#endif // XP_MACOSX
void ResolutionMayHaveChanged();
void UpdateDocumentActiveState(bool aIsActive);
void SetFrame(nsPluginFrame *aFrame);
@ -278,6 +278,7 @@ public:
const mozilla::widget::CandidateWindowPosition& aPosition);
bool RequestCommitOrCancel(bool aCommitted);
void GetCSSZoomFactor(float *result);
private:
virtual ~nsPluginInstanceOwner();
@ -328,7 +329,7 @@ private:
// True if, the next time the window is activated, we should blur ourselves.
bool mShouldBlurOnActivate;
#endif
double mLastCSSZoomFactor;
// Initially, the event loop nesting level we were created on, it's updated
// if we detect the appshell is on a lower level as long as we're not stopped.
// We delay DoStopPlugin() until the appshell reaches this level or lower.

View File

@ -97,6 +97,8 @@ child:
intr NPP_GetValue_NPPVpluginNativeAccessibleAtkPlugId()
returns (nsCString plug_id, NPError result);
intr NPP_SetValue_NPNVCSSZoomFactor(double value) returns (NPError result);
intr NPP_SetValue_NPNVmuteAudioBool(bool muted) returns (NPError result);
intr NPP_HandleEvent(NPRemoteEvent event)

View File

@ -543,6 +543,10 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar,
}
#endif /* XP_MACOSX */
case NPNVCSSZoomFactor: {
*static_cast<double*>(aValue) = mCSSZoomFactor;
return NPERR_NO_ERROR;
}
#ifdef DEBUG
case NPNVjavascriptEnabledBool:
case NPNVasdEnabledBool:
@ -817,6 +821,21 @@ PluginInstanceChild::AnswerNPP_SetValue_NPNVprivateModeBool(const bool& value,
return true;
}
bool
PluginInstanceChild::AnswerNPP_SetValue_NPNVCSSZoomFactor(const double& value,
NPError* result)
{
if (!mPluginIface->setvalue) {
*result = NPERR_GENERIC_ERROR;
return true;
}
mCSSZoomFactor = value;
double v = value;
*result = mPluginIface->setvalue(GetNPP(), NPNVCSSZoomFactor, &v);
return true;
}
bool
PluginInstanceChild::AnswerNPP_SetValue_NPNVmuteAudioBool(const bool& value,
NPError* result)

View File

@ -89,6 +89,8 @@ protected:
AnswerNPP_SetValue_NPNVprivateModeBool(const bool& value, NPError* result) override;
virtual bool
AnswerNPP_SetValue_NPNVmuteAudioBool(const bool& value, NPError* result) override;
virtual bool
AnswerNPP_SetValue_NPNVCSSZoomFactor(const double& value, NPError* result) override;
virtual bool
AnswerNPP_HandleEvent(const NPRemoteEvent& event, int16_t* handled) override;
@ -403,6 +405,7 @@ private:
#if defined(XP_DARWIN)
double mContentsScaleFactor;
#endif
double mCSSZoomFactor;
int16_t mDrawingModel;
NPAsyncSurface* mCurrentDirectSurface;

View File

@ -1735,6 +1735,13 @@ PluginInstanceParent::NPP_SetValue(NPNVariable variable, void* value)
return result;
case NPNVCSSZoomFactor:
if (!CallNPP_SetValue_NPNVCSSZoomFactor(*static_cast<double*>(value),
&result))
return NPERR_GENERIC_ERROR;
return result;
default:
NS_ERROR("Unhandled NPNVariable in NPP_SetValue");
MOZ_LOG(GetPluginLog(), LogLevel::Warning,

View File

@ -1218,8 +1218,9 @@ nsPluginFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
#endif
if (aBuilder->IsForPainting() && mInstanceOwner) {
#ifdef XP_MACOSX
// Update plugin frame for both content scaling and full zoom changes.
mInstanceOwner->ResolutionMayHaveChanged();
#ifdef XP_MACOSX
mInstanceOwner->WindowFocusMayHaveChanged();
#endif
if (mInstanceOwner->UseAsyncRendering()) {