diff --git a/dom/plugins/base/npapi.h b/dom/plugins/base/npapi.h index 1b256163c184..798ee20aad6b 100644 --- a/dom/plugins/base/npapi.h +++ b/dom/plugins/base/npapi.h @@ -412,6 +412,8 @@ typedef enum { NPNVdocumentOrigin = 22, + NPNVCSSZoomFactor = 23, + NPNVpluginDrawingModel = 1000 /* Get the current drawing model (NPDrawingModel) */ #if defined(XP_MACOSX) , NPNVcontentsScaleFactor = 1001 diff --git a/dom/plugins/base/nsNPAPIPlugin.cpp b/dom/plugins/base/nsNPAPIPlugin.cpp index 8eff00273d77..a25731178bbd 100644 --- a/dom/plugins/base/nsNPAPIPlugin.cpp +++ b/dom/plugins/base/nsNPAPIPlugin.cpp @@ -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"); diff --git a/dom/plugins/base/nsNPAPIPluginInstance.cpp b/dom/plugins/base/nsNPAPIPluginInstance.cpp index 9aec762ce270..33945ad1e1ce 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.cpp +++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp @@ -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(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) { diff --git a/dom/plugins/base/nsNPAPIPluginInstance.h b/dom/plugins/base/nsNPAPIPluginInstance.h index 7aed6051bb2d..8e26a547ea4e 100644 --- a/dom/plugins/base/nsNPAPIPluginInstance.h +++ b/dom/plugins/base/nsNPAPIPluginInstance.h @@ -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; } diff --git a/dom/plugins/base/nsPluginInstanceOwner.cpp b/dom/plugins/base/nsPluginInstanceOwner.cpp index d449ecc79eb7..7dc2175a1b82 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.cpp +++ b/dom/plugins/base/nsPluginInstanceOwner.cpp @@ -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 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. diff --git a/dom/plugins/base/nsPluginInstanceOwner.h b/dom/plugins/base/nsPluginInstanceOwner.h index 7fafa09de5be..1b8d9c8ca43b 100644 --- a/dom/plugins/base/nsPluginInstanceOwner.h +++ b/dom/plugins/base/nsPluginInstanceOwner.h @@ -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. diff --git a/dom/plugins/ipc/PPluginInstance.ipdl b/dom/plugins/ipc/PPluginInstance.ipdl index ff09c7f8822e..a5381f58fbbe 100644 --- a/dom/plugins/ipc/PPluginInstance.ipdl +++ b/dom/plugins/ipc/PPluginInstance.ipdl @@ -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) diff --git a/dom/plugins/ipc/PluginInstanceChild.cpp b/dom/plugins/ipc/PluginInstanceChild.cpp index 27b66340402c..63a74fee74cb 100644 --- a/dom/plugins/ipc/PluginInstanceChild.cpp +++ b/dom/plugins/ipc/PluginInstanceChild.cpp @@ -543,6 +543,10 @@ PluginInstanceChild::NPN_GetValue(NPNVariable aVar, } #endif /* XP_MACOSX */ + case NPNVCSSZoomFactor: { + *static_cast(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) diff --git a/dom/plugins/ipc/PluginInstanceChild.h b/dom/plugins/ipc/PluginInstanceChild.h index 6ddd751219d7..d04954439ec3 100644 --- a/dom/plugins/ipc/PluginInstanceChild.h +++ b/dom/plugins/ipc/PluginInstanceChild.h @@ -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; diff --git a/dom/plugins/ipc/PluginInstanceParent.cpp b/dom/plugins/ipc/PluginInstanceParent.cpp index f4ea848541c2..8bbd952c8277 100644 --- a/dom/plugins/ipc/PluginInstanceParent.cpp +++ b/dom/plugins/ipc/PluginInstanceParent.cpp @@ -1735,6 +1735,13 @@ PluginInstanceParent::NPP_SetValue(NPNVariable variable, void* value) return result; + case NPNVCSSZoomFactor: + if (!CallNPP_SetValue_NPNVCSSZoomFactor(*static_cast(value), + &result)) + return NPERR_GENERIC_ERROR; + + return result; + default: NS_ERROR("Unhandled NPNVariable in NPP_SetValue"); MOZ_LOG(GetPluginLog(), LogLevel::Warning, diff --git a/layout/generic/nsPluginFrame.cpp b/layout/generic/nsPluginFrame.cpp index f536a6367e7c..8ed1ab65dbb1 100644 --- a/layout/generic/nsPluginFrame.cpp +++ b/layout/generic/nsPluginFrame.cpp @@ -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()) {