2010-11-08 17:48:02 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:set ts=2 sts=2 sw=2 et cin:
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
/* rendering objects for replaced elements implemented by a plugin */
|
|
|
|
|
2014-09-24 08:33:00 +04:00
|
|
|
#include "nsPluginFrame.h"
|
2013-09-25 05:43:43 +04:00
|
|
|
|
2013-12-31 13:06:12 +04:00
|
|
|
#include "gfx2DGlue.h"
|
2014-09-11 10:48:09 +04:00
|
|
|
#include "gfxMatrix.h"
|
2014-10-24 11:26:27 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-09-25 15:21:22 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2015-10-16 07:19:27 +03:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-08-22 22:32:52 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// This is needed for DoublePassRenderingEvent.
|
2010-11-08 17:48:02 +03:00
|
|
|
#include "mozilla/plugins/PluginMessageUtils.h"
|
2013-08-22 22:32:52 +04:00
|
|
|
#endif
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2013-01-03 17:23:11 +04:00
|
|
|
#include "nsView.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIPluginInstanceOwner.h"
|
2011-04-08 23:58:04 +04:00
|
|
|
#include "nsNPAPIPluginInstance.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
#include "nsIDOMElement.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
#include "npapi.h"
|
|
|
|
#include "nsIObjectLoadingContent.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsFocusManager.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsIObserverService.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
#include "nsIObjectFrame.h"
|
|
|
|
#include "nsPluginNativeWindow.h"
|
2011-02-16 08:48:01 +03:00
|
|
|
#include "FrameLayerBuilder.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2012-08-19 23:33:25 +04:00
|
|
|
#include "ImageLayers.h"
|
2013-08-22 22:32:52 +04:00
|
|
|
#include "nsPluginInstanceOwner.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "gfxWindowsNativeDrawing.h"
|
|
|
|
#include "gfxWindowsSurface.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Layers.h"
|
2011-02-17 01:43:30 +03:00
|
|
|
#include "ReadbackLayer.h"
|
2013-08-22 22:32:52 +04:00
|
|
|
#include "ImageContainer.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// accessibility support
|
|
|
|
#ifdef ACCESSIBILITY
|
2011-01-28 07:38:14 +03:00
|
|
|
#include "nsAccessibilityService.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG 1 /* Allow logging in the release build */
|
|
|
|
#endif /* MOZ_LOGGING */
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "gfxQuartzNativeDrawing.h"
|
2012-07-31 19:11:57 +04:00
|
|
|
#include "mozilla/gfx/QuartzSupport.h"
|
2010-11-08 17:48:02 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "mozilla/X11Util.h"
|
|
|
|
using mozilla::DefaultXDisplay;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <wtypes.h>
|
|
|
|
#include <winuser.h>
|
|
|
|
#endif
|
|
|
|
|
2012-07-20 23:20:51 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#endif
|
|
|
|
|
2015-01-29 22:41:55 +03:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
#ifdef CreateEvent // Thank you MS.
|
|
|
|
#undef CreateEvent
|
|
|
|
#endif
|
|
|
|
|
2015-11-06 01:35:03 +03:00
|
|
|
static mozilla::LazyLogModule sPluginFrameLog("nsPluginFrame");
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
using namespace mozilla;
|
2013-12-31 13:06:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2010-11-08 17:48:02 +03:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
class PluginBackgroundSink : public ReadbackSink {
|
|
|
|
public:
|
2014-09-24 08:34:00 +04:00
|
|
|
PluginBackgroundSink(nsPluginFrame* aFrame, uint64_t aStartSequenceNumber)
|
2011-02-17 01:43:30 +03:00
|
|
|
: mLastSequenceNumber(aStartSequenceNumber), mFrame(aFrame) {}
|
2016-11-09 16:37:59 +03:00
|
|
|
~PluginBackgroundSink() override
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
|
|
|
if (mFrame) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mFrame->mBackgroundSink = nullptr;
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void SetUnknown(uint64_t aSequenceNumber) override
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
|
|
|
if (!AcceptUpdate(aSequenceNumber))
|
|
|
|
return;
|
|
|
|
mFrame->mInstanceOwner->SetBackgroundUnknown();
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
already_AddRefed<DrawTarget>
|
|
|
|
BeginUpdate(const nsIntRect& aRect, uint64_t aSequenceNumber) override
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
|
|
|
if (!AcceptUpdate(aSequenceNumber))
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-02-17 01:43:30 +03:00
|
|
|
return mFrame->mInstanceOwner->BeginUpdateBackground(aRect);
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void EndUpdate(const nsIntRect& aRect) override
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
2015-12-18 06:39:09 +03:00
|
|
|
return mFrame->mInstanceOwner->EndUpdateBackground(aRect);
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
void Destroy() { mFrame = nullptr; }
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
protected:
|
2012-08-22 19:56:38 +04:00
|
|
|
bool AcceptUpdate(uint64_t aSequenceNumber) {
|
2011-02-17 01:43:30 +03:00
|
|
|
if (aSequenceNumber > mLastSequenceNumber && mFrame &&
|
|
|
|
mFrame->mInstanceOwner) {
|
|
|
|
mLastSequenceNumber = aSequenceNumber;
|
2011-10-01 19:43:07 +04:00
|
|
|
return true;
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
2011-10-01 19:43:07 +04:00
|
|
|
return false;
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t mLastSequenceNumber;
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame* mFrame;
|
2011-02-17 01:43:30 +03:00
|
|
|
};
|
|
|
|
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::nsPluginFrame(nsStyleContext* aContext)
|
2016-04-18 09:01:57 +03:00
|
|
|
: nsFrame(aContext)
|
2015-05-29 18:59:08 +03:00
|
|
|
, mInstanceOwner(nullptr)
|
2016-12-01 11:06:50 +03:00
|
|
|
, mInnerView(nullptr)
|
|
|
|
, mBackgroundSink(nullptr)
|
2011-10-01 19:43:07 +04:00
|
|
|
, mReflowCallbackPosted(false)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2015-11-06 01:35:03 +03:00
|
|
|
MOZ_LOG(sPluginFrameLog, LogLevel::Debug,
|
2014-09-24 08:34:00 +04:00
|
|
|
("Created new nsPluginFrame %p\n", this));
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::~nsPluginFrame()
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2015-11-06 01:35:03 +03:00
|
|
|
MOZ_LOG(sPluginFrameLog, LogLevel::Debug,
|
2014-09-24 08:34:00 +04:00
|
|
|
("nsPluginFrame %p deleted\n", this));
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2014-09-24 08:34:00 +04:00
|
|
|
NS_QUERYFRAME_HEAD(nsPluginFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsPluginFrame)
|
2010-11-08 17:48:02 +03:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIObjectFrame)
|
2016-04-18 09:01:57 +03:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsFrame)
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-29 01:53:44 +04:00
|
|
|
a11y::AccType
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::AccessibleType()
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2012-12-18 09:22:26 +04:00
|
|
|
return a11y::ePluginType;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2014-09-24 08:34:00 +04:00
|
|
|
NS_IMETHODIMP nsPluginFrame::GetPluginPort(HWND *aPort)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2014-12-11 17:44:07 +03:00
|
|
|
*aPort = (HWND) mInstanceOwner->GetPluginPort();
|
2010-11-08 17:48:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::Init(nsIContent* aContent,
|
2014-05-25 02:20:40 +04:00
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2015-11-06 01:35:03 +03:00
|
|
|
MOZ_LOG(sPluginFrameLog, LogLevel::Debug,
|
2014-09-24 08:34:00 +04:00
|
|
|
("Initializing nsPluginFrame %p for content %p\n", this, aContent));
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2016-04-18 09:01:57 +03:00
|
|
|
nsFrame::Init(aContent, aParent, aPrevInFlow);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2012-02-06 15:47:11 +04:00
|
|
|
if (mReflowCallbackPosted) {
|
|
|
|
PresContext()->PresShell()->CancelReflowCallback(this);
|
|
|
|
}
|
|
|
|
|
2015-12-02 22:31:17 +03:00
|
|
|
// Ensure our DidComposite observer is gone.
|
|
|
|
mDidCompositeObserver = nullptr;
|
|
|
|
|
2012-02-01 01:55:54 +04:00
|
|
|
// Tell content owner of the instance to disconnect its frame.
|
|
|
|
nsCOMPtr<nsIObjectLoadingContent> objContent(do_QueryInterface(mContent));
|
|
|
|
NS_ASSERTION(objContent, "Why not an object loading content?");
|
2013-04-18 01:13:09 +04:00
|
|
|
|
2013-04-18 02:11:21 +04:00
|
|
|
// The content might not have a reference to the instance owner any longer in
|
|
|
|
// the case of re-entry during instantiation or teardown, so make sure we're
|
|
|
|
// dissociated.
|
2013-04-18 01:13:09 +04:00
|
|
|
if (mInstanceOwner) {
|
|
|
|
mInstanceOwner->SetFrame(nullptr);
|
|
|
|
}
|
2012-09-07 04:16:02 +04:00
|
|
|
objContent->HasNewFrame(nullptr);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
if (mBackgroundSink) {
|
|
|
|
mBackgroundSink->Destroy();
|
|
|
|
}
|
|
|
|
|
2016-04-18 09:01:57 +03:00
|
|
|
nsFrame::DestroyFrom(aDestructRoot);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
if (HasView()) {
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* view = GetView();
|
2013-01-05 07:12:24 +04:00
|
|
|
nsViewManager* vm = view->GetViewManager();
|
2010-11-08 17:48:02 +03:00
|
|
|
if (vm) {
|
|
|
|
nsViewVisibility visibility =
|
|
|
|
IsHidden() ? nsViewVisibility_kHide : nsViewVisibility_kShow;
|
|
|
|
vm->SetViewVisibility(view, visibility);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-18 09:01:57 +03:00
|
|
|
nsFrame::DidSetStyleContext(aOldStyleContext);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetType() const
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
return nsGkAtoms::objectFrame;
|
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetFrameName(nsAString& aResult) const
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2014-09-24 08:35:00 +04:00
|
|
|
return MakeFrameName(NS_LITERAL_STRING("PluginFrame"), aResult);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::PrepForDrawing(nsIWidget *aWidget)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2012-02-01 01:55:54 +04:00
|
|
|
mWidget = aWidget;
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* view = GetView();
|
2010-11-08 17:48:02 +03:00
|
|
|
NS_ASSERTION(view, "Object frames must have views");
|
|
|
|
if (!view) {
|
2012-02-01 01:55:54 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2011-02-16 00:45:02 +03:00
|
|
|
}
|
|
|
|
|
2013-01-05 07:12:24 +04:00
|
|
|
nsViewManager* viewMan = view->GetViewManager();
|
2010-11-08 17:48:02 +03:00
|
|
|
// mark the view as hidden since we don't know the (x,y) until Paint
|
|
|
|
// XXX is the above comment correct?
|
|
|
|
viewMan->SetViewVisibility(view, nsViewVisibility_kHide);
|
|
|
|
|
|
|
|
//this is ugly. it was ripped off from didreflow(). MMP
|
|
|
|
// Position and size view relative to its parent, not relative to our
|
|
|
|
// parent frame (our parent frame may not have a view).
|
|
|
|
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* parentWithView;
|
2010-11-08 17:48:02 +03:00
|
|
|
nsPoint origin;
|
|
|
|
nsRect r(0, 0, mRect.width, mRect.height);
|
|
|
|
|
|
|
|
GetOffsetFromView(origin, &parentWithView);
|
|
|
|
viewMan->ResizeView(view, r);
|
|
|
|
viewMan->MoveViewTo(view, origin.x, origin.y);
|
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
nsRootPresContext* rpc = presContext->GetRootPresContext();
|
2010-11-08 17:48:02 +03:00
|
|
|
if (!rpc) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-02-01 01:55:54 +04:00
|
|
|
if (mWidget) {
|
2012-10-06 17:03:23 +04:00
|
|
|
// Disallow windowed plugins in popups
|
2012-07-06 04:45:23 +04:00
|
|
|
nsIFrame* rootFrame = rpc->PresShell()->FrameManager()->GetRootFrame();
|
|
|
|
nsIWidget* parentWidget = rootFrame->GetNearestWidget();
|
|
|
|
if (!parentWidget || nsLayoutUtils::GetDisplayRootFrame(this) != rootFrame) {
|
2010-12-24 23:37:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-02-01 01:55:54 +04:00
|
|
|
}
|
2010-12-24 23:37:03 +03:00
|
|
|
|
2011-04-19 07:07:22 +04:00
|
|
|
mInnerView = viewMan->CreateView(GetContentRectRelativeToSelf(), view);
|
2010-11-08 17:48:02 +03:00
|
|
|
if (!mInnerView) {
|
|
|
|
NS_ERROR("Could not create inner view");
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
viewMan->InsertChild(view, mInnerView, nullptr, true);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2012-02-01 01:55:54 +04:00
|
|
|
mWidget->SetParent(parentWidget);
|
|
|
|
mWidget->Enable(true);
|
2015-09-01 18:39:30 +03:00
|
|
|
mWidget->Show(true);
|
2012-02-01 01:55:54 +04:00
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
// Set the plugin window to have an empty clip region until we know
|
|
|
|
// what our true position, size and clip region are. These
|
|
|
|
// will be reset when nsRootPresContext computes our true
|
|
|
|
// geometry. The plugin window does need to have a good size here, so
|
|
|
|
// set the size explicitly to a reasonable guess.
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsIWidget::Configuration,1> configurations;
|
2012-10-06 17:03:23 +04:00
|
|
|
nsIWidget::Configuration* configuration = configurations.AppendElement();
|
|
|
|
nscoord appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
configuration->mChild = mWidget;
|
|
|
|
configuration->mBounds.width = NSAppUnitsToIntPixels(mRect.width, appUnitsPerDevPixel);
|
|
|
|
configuration->mBounds.height = NSAppUnitsToIntPixels(mRect.height, appUnitsPerDevPixel);
|
|
|
|
parentWidget->ConfigureChildren(configurations);
|
2012-02-01 01:55:54 +04:00
|
|
|
|
2012-08-15 22:53:09 +04:00
|
|
|
mInnerView->AttachWidgetEventHandler(mWidget);
|
2011-08-30 10:09:56 +04:00
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
#ifdef XP_MACOSX
|
2012-02-01 01:55:54 +04:00
|
|
|
// On Mac, we need to invalidate ourselves since even windowed
|
|
|
|
// plugins are painted through Thebes and we need to ensure
|
2014-09-26 21:07:06 +04:00
|
|
|
// the PaintedLayer containing the plugin is updated.
|
2012-02-01 01:55:54 +04:00
|
|
|
if (parentWidget == GetNearestWidget()) {
|
2012-08-29 09:39:31 +04:00
|
|
|
InvalidateFrame();
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
2012-02-01 01:55:54 +04:00
|
|
|
#endif
|
2011-08-30 10:09:56 +04:00
|
|
|
|
2012-08-17 08:25:19 +04:00
|
|
|
RegisterPluginForGeometryUpdates();
|
2011-08-30 10:09:56 +04:00
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
// Here we set the background color for this widget because some plugins will use
|
|
|
|
// the child window background color when painting. If it's not set, it may default to gray
|
|
|
|
// Sometimes, a frame doesn't have a background color or is transparent. In this
|
|
|
|
// case, walk up the frame tree until we do find a frame with a background color
|
|
|
|
for (nsIFrame* frame = this; frame; frame = frame->GetParent()) {
|
2016-12-30 16:57:37 +03:00
|
|
|
nscolor bgcolor = frame->
|
|
|
|
GetVisitedDependentColor(&nsStyleBackground::mBackgroundColor);
|
2010-11-08 17:48:02 +03:00
|
|
|
if (NS_GET_A(bgcolor) > 0) { // make sure we got an actual color
|
|
|
|
mWidget->SetBackgroundColor(bgcolor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-02-01 01:55:54 +04:00
|
|
|
// Changing to windowless mode changes the NPWindow geometry.
|
|
|
|
FixupWindow(GetContentRectRelativeToSelf().Size());
|
2012-08-17 08:25:19 +04:00
|
|
|
RegisterPluginForGeometryUpdates();
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsHidden()) {
|
|
|
|
viewMan->SetViewVisibility(view, nsViewVisibility_kShow);
|
|
|
|
}
|
|
|
|
|
2012-02-01 01:55:54 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
|
|
|
if (accService) {
|
|
|
|
accService->RecreateAccessible(PresContext()->PresShell(), mContent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define EMBED_DEF_WIDTH 240
|
|
|
|
#define EMBED_DEF_HEIGHT 200
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetMinISize(nsRenderingContext *aRenderingContext)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
|
2011-10-01 19:43:07 +04:00
|
|
|
if (!IsHidden(false)) {
|
2015-03-03 14:09:00 +03:00
|
|
|
if (mContent->IsAnyOfHTMLElements(nsGkAtoms::applet,
|
|
|
|
nsGkAtoms::embed)) {
|
2014-12-09 17:00:51 +03:00
|
|
|
bool vertical = GetWritingMode().IsVertical();
|
|
|
|
result = nsPresContext::CSSPixelsToAppUnits(
|
|
|
|
vertical ? EMBED_DEF_HEIGHT : EMBED_DEF_WIDTH);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2014-09-24 08:34:00 +04:00
|
|
|
return nsPluginFrame::GetMinISize(aRenderingContext);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2015-01-29 22:41:55 +03:00
|
|
|
void
|
|
|
|
nsPluginFrame::GetWidgetConfiguration(nsTArray<nsIWidget::Configuration>* aConfigurations)
|
|
|
|
{
|
|
|
|
if (!mWidget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mWidget->GetParent()) {
|
|
|
|
// Plugin widgets should not be toplevel except when they're out of the
|
|
|
|
// document, in which case the plugin should not be registered for
|
|
|
|
// geometry updates and this should not be called. But apparently we
|
|
|
|
// have bugs where mWidget sometimes is toplevel here. Bail out.
|
|
|
|
NS_ERROR("Plugin widgets registered for geometry updates should not be toplevel");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget::Configuration* configuration = aConfigurations->AppendElement();
|
|
|
|
configuration->mChild = mWidget;
|
2015-12-03 01:32:55 +03:00
|
|
|
configuration->mBounds = mNextConfigurationBounds;
|
2015-01-29 22:41:55 +03:00
|
|
|
configuration->mClipRegion = mNextConfigurationClipRegion;
|
|
|
|
#if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2015-01-29 22:41:55 +03:00
|
|
|
configuration->mWindowID = (uintptr_t)mWidget->GetNativeData(NS_NATIVE_PLUGIN_PORT);
|
2016-07-18 11:54:02 +03:00
|
|
|
configuration->mVisible = mWidget->IsVisible();
|
2016-03-01 21:48:26 +03:00
|
|
|
|
2015-01-29 22:41:55 +03:00
|
|
|
}
|
|
|
|
#endif // defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
|
|
|
|
}
|
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetDesiredSize(nsPresContext* aPresContext,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aMetrics)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
// By default, we have no area
|
2014-07-24 12:30:07 +04:00
|
|
|
aMetrics.ClearSize();
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2011-10-01 19:43:07 +04:00
|
|
|
if (IsHidden(false)) {
|
2010-11-08 17:48:02 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-07-24 12:30:07 +04:00
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
aMetrics.Width() = aReflowInput.ComputedWidth();
|
|
|
|
aMetrics.Height() = aReflowInput.ComputedHeight();
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// for EMBED and APPLET, default to 240x200 for compatibility
|
2015-03-03 14:09:00 +03:00
|
|
|
if (mContent->IsAnyOfHTMLElements(nsGkAtoms::applet,
|
|
|
|
nsGkAtoms::embed)) {
|
2013-12-27 21:59:52 +04:00
|
|
|
if (aMetrics.Width() == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aMetrics.Width() = clamped(nsPresContext::CSSPixelsToAppUnits(EMBED_DEF_WIDTH),
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.ComputedMinWidth(),
|
|
|
|
aReflowInput.ComputedMaxWidth());
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
2013-12-27 21:59:52 +04:00
|
|
|
if (aMetrics.Height() == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aMetrics.Height() = clamped(nsPresContext::CSSPixelsToAppUnits(EMBED_DEF_HEIGHT),
|
2016-07-21 13:36:39 +03:00
|
|
|
aReflowInput.ComputedMinHeight(),
|
|
|
|
aReflowInput.ComputedMaxHeight());
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2013-06-12 16:04:28 +04:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2010-11-08 17:48:02 +03:00
|
|
|
// We need to make sure that the size of the object frame does not
|
|
|
|
// exceed the maximum size of X coordinates. See bug #225357 for
|
|
|
|
// more information. In theory Gtk2 can handle large coordinates,
|
|
|
|
// but underlying plugins can't.
|
2013-12-27 21:59:52 +04:00
|
|
|
aMetrics.Height() = std::min(aPresContext->DevPixelsToAppUnits(INT16_MAX), aMetrics.Height());
|
|
|
|
aMetrics.Width() = std::min(aPresContext->DevPixelsToAppUnits(INT16_MAX), aMetrics.Width());
|
2010-11-08 17:48:02 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point, the width has an unconstrained value only if we have
|
|
|
|
// nothing to go on (no width set, no information from the plugin, nothing).
|
|
|
|
// Make up a number.
|
2013-12-27 21:59:52 +04:00
|
|
|
if (aMetrics.Width() == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aMetrics.Width() =
|
2016-07-21 13:36:39 +03:00
|
|
|
(aReflowInput.ComputedMinWidth() != NS_UNCONSTRAINEDSIZE) ?
|
|
|
|
aReflowInput.ComputedMinWidth() : 0;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// At this point, the height has an unconstrained value only in two cases:
|
|
|
|
// a) We are in standards mode with percent heights and parent is auto-height
|
|
|
|
// b) We have no height information at all.
|
|
|
|
// In either case, we have to make up a number.
|
2013-12-27 21:59:52 +04:00
|
|
|
if (aMetrics.Height() == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aMetrics.Height() =
|
2016-07-21 13:36:39 +03:00
|
|
|
(aReflowInput.ComputedMinHeight() != NS_UNCONSTRAINEDSIZE) ?
|
|
|
|
aReflowInput.ComputedMinHeight() : 0;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXXbz don't add in the border and padding, because we screw up our
|
|
|
|
// plugin's size and positioning if we do... Eventually we _do_ want to
|
|
|
|
// paint borders, though! At that point, we will need to adjust the desired
|
|
|
|
// size either here or in Reflow.... Further, we will need to fix Paint() to
|
|
|
|
// call the superclass in all cases.
|
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aMetrics,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2010-11-08 17:48:02 +03:00
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
2014-09-24 08:34:00 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsPluginFrame");
|
2016-07-21 13:36:39 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aMetrics, aStatus);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// Get our desired size
|
2016-07-21 13:36:39 +03:00
|
|
|
GetDesiredSize(aPresContext, aReflowInput, aMetrics);
|
2010-11-08 17:48:02 +03:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
|
|
|
FinishAndStoreOverflow(&aMetrics);
|
|
|
|
|
|
|
|
// delay plugin instantiation until all children have
|
|
|
|
// arrived. Otherwise there may be PARAMs or other stuff that the
|
|
|
|
// plugin needs to see that haven't arrived yet.
|
|
|
|
if (!GetContent()->IsDoneAddingChildren()) {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2014-05-13 04:47:52 +04:00
|
|
|
return;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// if we are printing or print previewing, bail for now
|
|
|
|
if (aPresContext->Medium() == nsGkAtoms::print) {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2014-05-13 04:47:52 +04:00
|
|
|
return;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2013-12-27 21:59:52 +04:00
|
|
|
nsRect r(0, 0, aMetrics.Width(), aMetrics.Height());
|
2016-07-21 13:36:39 +03:00
|
|
|
r.Deflate(aReflowInput.ComputedPhysicalBorderPadding());
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
if (mInnerView) {
|
2013-01-05 07:12:24 +04:00
|
|
|
nsViewManager* vm = mInnerView->GetViewManager();
|
2010-11-08 17:48:02 +03:00
|
|
|
vm->MoveViewTo(mInnerView, r.x, r.y);
|
2011-10-01 19:43:07 +04:00
|
|
|
vm->ResizeView(mInnerView, nsRect(nsPoint(0, 0), r.Size()), true);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FixupWindow(r.Size());
|
|
|
|
if (!mReflowCallbackPosted) {
|
2011-10-01 19:43:07 +04:00
|
|
|
mReflowCallbackPosted = true;
|
2010-11-08 17:48:02 +03:00
|
|
|
aPresContext->PresShell()->PostReflowCallback(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aMetrics);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////// nsIReflowCallback ///////////////
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::ReflowFinished()
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2011-10-01 19:43:07 +04:00
|
|
|
mReflowCallbackPosted = false;
|
2010-11-08 17:48:02 +03:00
|
|
|
CallSetWindow();
|
2011-10-01 19:43:07 +04:00
|
|
|
return true;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::ReflowCallbackCanceled()
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2011-10-01 19:43:07 +04:00
|
|
|
mReflowCallbackPosted = false;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::FixupWindow(const nsSize& aSize)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
|
|
|
|
if (!mInstanceOwner)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NPWindow *window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
|
2012-12-24 08:45:57 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(window);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool windowless = (window->type == NPWindowTypeDrawable);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
nsIntPoint origin = GetWindowOriginInPixels(windowless);
|
|
|
|
|
2012-10-02 23:48:05 +04:00
|
|
|
// window must be in "display pixels"
|
2015-09-17 23:31:34 +03:00
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// window must be in "display pixels"
|
2012-10-02 23:48:05 +04:00
|
|
|
double scaleFactor = 1.0;
|
|
|
|
if (NS_FAILED(mInstanceOwner->GetContentsScaleFactor(&scaleFactor))) {
|
|
|
|
scaleFactor = 1.0;
|
|
|
|
}
|
|
|
|
int intScaleFactor = ceil(scaleFactor);
|
|
|
|
window->x = origin.x / intScaleFactor;
|
|
|
|
window->y = origin.y / intScaleFactor;
|
|
|
|
window->width = presContext->AppUnitsToDevPixels(aSize.width) / intScaleFactor;
|
|
|
|
window->height = presContext->AppUnitsToDevPixels(aSize.height) / intScaleFactor;
|
2015-09-17 23:31:34 +03:00
|
|
|
#else
|
|
|
|
window->x = origin.x;
|
|
|
|
window->y = origin.y;
|
|
|
|
window->width = presContext->AppUnitsToDevPixels(aSize.width);
|
|
|
|
window->height = presContext->AppUnitsToDevPixels(aSize.height);
|
|
|
|
#endif
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2014-12-11 17:44:07 +03:00
|
|
|
#ifndef XP_MACOSX
|
2011-10-01 19:43:07 +04:00
|
|
|
mInstanceOwner->UpdateWindowPositionAndClipRect(false);
|
2010-11-08 17:48:02 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
NotifyPluginReflowObservers();
|
|
|
|
}
|
|
|
|
|
2010-12-08 00:18:50 +03:00
|
|
|
nsresult
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::CallSetWindow(bool aCheckIsHidden)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NPWindow *win = nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2010-12-08 00:18:50 +03:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsNPAPIPluginInstance> pi;
|
2010-11-08 17:48:02 +03:00
|
|
|
if (!mInstanceOwner ||
|
2011-05-18 05:48:34 +04:00
|
|
|
NS_FAILED(rv = mInstanceOwner->GetInstance(getter_AddRefs(pi))) ||
|
2010-11-08 17:48:02 +03:00
|
|
|
!pi ||
|
|
|
|
NS_FAILED(rv = mInstanceOwner->GetWindow(win)) ||
|
|
|
|
!win)
|
2010-12-08 00:18:50 +03:00
|
|
|
return rv;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
nsPluginNativeWindow *window = (nsPluginNativeWindow *)win;
|
|
|
|
|
2010-12-20 22:49:37 +03:00
|
|
|
if (aCheckIsHidden && IsHidden())
|
2010-12-08 00:18:50 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2015-06-17 20:59:34 +03:00
|
|
|
// Calling either nsPluginInstanceOwner::FixUpPluginWindow() (here,
|
|
|
|
// on OS X) or SetWindow() (below, on all platforms) can destroy this
|
|
|
|
// frame. (FixUpPluginWindow() calls SetWindow()). So grab a safe
|
|
|
|
// reference to mInstanceOwner which we can use below, if needed.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPluginInstanceOwner> instanceOwnerRef(mInstanceOwner);
|
2015-06-17 20:59:34 +03:00
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
// refresh the plugin port as well
|
2014-12-11 17:44:07 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mInstanceOwner->FixUpPluginWindow(nsPluginInstanceOwner::ePluginPaintEnable);
|
2015-06-17 20:59:34 +03:00
|
|
|
// Bail now if our frame has been destroyed.
|
|
|
|
if (!instanceOwnerRef->GetFrame()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-12-11 17:44:07 +03:00
|
|
|
#endif
|
|
|
|
window->window = mInstanceOwner->GetPluginPort();
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// Adjust plugin dimensions according to pixel snap results
|
|
|
|
// and reduce amount of SetWindow calls
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
nsRootPresContext* rootPC = presContext->GetRootPresContext();
|
|
|
|
if (!rootPC)
|
2010-12-08 00:18:50 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2010-11-08 17:48:02 +03:00
|
|
|
nsIFrame* rootFrame = rootPC->PresShell()->FrameManager()->GetRootFrame();
|
2011-04-19 07:07:22 +04:00
|
|
|
nsRect bounds = GetContentRectRelativeToSelf() + GetOffsetToCrossDoc(rootFrame);
|
2010-11-08 17:48:02 +03:00
|
|
|
nsIntRect intBounds = bounds.ToNearestPixels(appUnitsPerDevPixel);
|
2012-10-02 23:48:05 +04:00
|
|
|
|
2015-04-08 19:51:49 +03:00
|
|
|
// In e10s, this returns the offset to the top level window, in non-e10s
|
|
|
|
// it return 0,0.
|
|
|
|
LayoutDeviceIntPoint intOffset = GetRemoteTabChromeOffset();
|
|
|
|
intBounds.x += intOffset.x;
|
|
|
|
intBounds.y += intOffset.y;
|
|
|
|
|
2015-09-17 23:31:34 +03:00
|
|
|
#if defined(XP_MACOSX)
|
2012-10-02 23:48:05 +04:00
|
|
|
// window must be in "display pixels"
|
|
|
|
double scaleFactor = 1.0;
|
2016-08-10 23:21:01 +03:00
|
|
|
if (NS_FAILED(instanceOwnerRef->GetContentsScaleFactor(&scaleFactor))) {
|
2012-10-02 23:48:05 +04:00
|
|
|
scaleFactor = 1.0;
|
|
|
|
}
|
2015-09-17 23:31:34 +03:00
|
|
|
|
2012-10-02 23:48:05 +04:00
|
|
|
size_t intScaleFactor = ceil(scaleFactor);
|
|
|
|
window->x = intBounds.x / intScaleFactor;
|
|
|
|
window->y = intBounds.y / intScaleFactor;
|
|
|
|
window->width = intBounds.width / intScaleFactor;
|
|
|
|
window->height = intBounds.height / intScaleFactor;
|
2015-09-17 23:31:34 +03:00
|
|
|
#else
|
|
|
|
window->x = intBounds.x;
|
|
|
|
window->y = intBounds.y;
|
|
|
|
window->width = intBounds.width;
|
|
|
|
window->height = intBounds.height;
|
|
|
|
#endif
|
2016-08-10 23:21:01 +03:00
|
|
|
// BE CAREFUL: By the time we get here the PluginFrame is sometimes destroyed
|
|
|
|
// and poisoned. If we reference local fields (implicit this deref),
|
|
|
|
// we will crash.
|
|
|
|
instanceOwnerRef->ResolutionMayHaveChanged();
|
2016-05-20 23:32:10 +03:00
|
|
|
|
2011-11-01 22:52:20 +04:00
|
|
|
// This will call pi->SetWindow and take care of window subclassing
|
|
|
|
// if needed, see bug 132759. Calling SetWindow can destroy this frame
|
|
|
|
// so check for that before doing anything else with this frame's memory.
|
2016-08-10 23:21:01 +03:00
|
|
|
if (instanceOwnerRef->UseAsyncRendering()) {
|
2010-12-08 00:18:50 +03:00
|
|
|
rv = pi->AsyncSetWindow(window);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
else {
|
2010-12-08 00:18:50 +03:00
|
|
|
rv = window->CallSetWindow(pi);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2011-11-01 22:52:20 +04:00
|
|
|
instanceOwnerRef->ReleasePluginPort(window->window);
|
|
|
|
|
2010-12-08 00:18:50 +03:00
|
|
|
return rv;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2012-08-17 08:25:19 +04:00
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::RegisterPluginForGeometryUpdates()
|
2012-08-17 08:25:19 +04:00
|
|
|
{
|
|
|
|
nsRootPresContext* rpc = PresContext()->GetRootPresContext();
|
|
|
|
NS_ASSERTION(rpc, "We should have a root pres context!");
|
|
|
|
if (mRootPresContextRegisteredWith == rpc || !rpc) {
|
|
|
|
// Already registered with current root pres context,
|
|
|
|
// or null root pres context...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mRootPresContextRegisteredWith && mRootPresContextRegisteredWith != rpc) {
|
|
|
|
// Registered to some other root pres context. Unregister, and
|
|
|
|
// re-register with our current one...
|
|
|
|
UnregisterPluginForGeometryUpdates();
|
|
|
|
}
|
|
|
|
mRootPresContextRegisteredWith = rpc;
|
|
|
|
mRootPresContextRegisteredWith->RegisterPluginForGeometryUpdates(mContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::UnregisterPluginForGeometryUpdates()
|
2012-08-17 08:25:19 +04:00
|
|
|
{
|
|
|
|
if (!mRootPresContextRegisteredWith) {
|
|
|
|
// Not registered...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRootPresContextRegisteredWith->UnregisterPluginForGeometryUpdates(mContent);
|
|
|
|
mRootPresContextRegisteredWith = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-02-01 01:55:54 +04:00
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::SetInstanceOwner(nsPluginInstanceOwner* aOwner)
|
2012-02-01 01:55:54 +04:00
|
|
|
{
|
2013-04-18 02:11:21 +04:00
|
|
|
// The ownership model here is historically fuzzy. This should only be called
|
|
|
|
// by nsPluginInstanceOwner when it is given a new frame, and
|
|
|
|
// nsObjectLoadingContent should be arbitrating frame-ownership via its
|
|
|
|
// HasNewFrame callback.
|
2012-02-01 01:55:54 +04:00
|
|
|
mInstanceOwner = aOwner;
|
2015-12-02 22:31:17 +03:00
|
|
|
|
|
|
|
// Reset the DidCompositeObserver since the owner changed.
|
|
|
|
mDidCompositeObserver = nullptr;
|
|
|
|
|
2012-08-14 08:06:44 +04:00
|
|
|
if (mInstanceOwner) {
|
|
|
|
return;
|
|
|
|
}
|
2015-12-02 22:31:17 +03:00
|
|
|
|
2012-08-17 08:25:19 +04:00
|
|
|
UnregisterPluginForGeometryUpdates();
|
2012-08-14 08:06:44 +04:00
|
|
|
if (mWidget && mInnerView) {
|
|
|
|
mInnerView->DetachWidgetEventHandler(mWidget);
|
|
|
|
// Make sure the plugin is hidden in case an update of plugin geometry
|
|
|
|
// hasn't happened since this plugin became hidden.
|
|
|
|
nsIWidget* parent = mWidget->GetParent();
|
|
|
|
if (parent) {
|
|
|
|
nsTArray<nsIWidget::Configuration> configurations;
|
2012-10-06 17:03:23 +04:00
|
|
|
nsIWidget::Configuration* configuration = configurations.AppendElement();
|
|
|
|
configuration->mChild = mWidget;
|
2012-08-14 08:06:44 +04:00
|
|
|
parent->ConfigureChildren(configurations);
|
|
|
|
|
|
|
|
mWidget->Show(false);
|
|
|
|
mWidget->Enable(false);
|
|
|
|
mWidget->SetParent(nullptr);
|
2012-02-01 01:55:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::IsFocusable(int32_t *aTabIndex, bool aWithMouse)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
if (aTabIndex)
|
|
|
|
*aTabIndex = -1;
|
2016-04-18 09:01:57 +03:00
|
|
|
return nsFrame::IsFocusable(aTabIndex, aWithMouse);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::IsHidden(bool aCheckVisibilityStyle) const
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
if (aCheckVisibilityStyle) {
|
2013-02-17 01:51:02 +04:00
|
|
|
if (!StyleVisibility()->IsVisibleOrCollapsed())
|
2011-10-01 19:43:07 +04:00
|
|
|
return true;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// only <embed> tags support the HIDDEN attribute
|
2015-03-03 14:09:00 +03:00
|
|
|
if (mContent->IsHTMLElement(nsGkAtoms::embed)) {
|
2010-11-08 17:48:02 +03:00
|
|
|
// Yes, these are really the kooky ways that you could tell 4.x
|
|
|
|
// not to hide the <embed> once you'd put the 'hidden' attribute
|
|
|
|
// on the tag...
|
|
|
|
|
|
|
|
// HIDDEN w/ no attributes gets translated as we are hidden for
|
|
|
|
// compatibility w/ 4.x and IE so we don't create a non-painting
|
|
|
|
// widget in layout. See bug 188959.
|
|
|
|
nsAutoString hidden;
|
|
|
|
if (mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::hidden, hidden) &&
|
|
|
|
(hidden.IsEmpty() ||
|
|
|
|
(!hidden.LowerCaseEqualsLiteral("false") &&
|
|
|
|
!hidden.LowerCaseEqualsLiteral("no") &&
|
|
|
|
!hidden.LowerCaseEqualsLiteral("off")))) {
|
2011-10-01 19:43:07 +04:00
|
|
|
return true;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-01 19:43:07 +04:00
|
|
|
return false;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 19:51:49 +03:00
|
|
|
mozilla::LayoutDeviceIntPoint
|
|
|
|
nsPluginFrame::GetRemoteTabChromeOffset()
|
|
|
|
{
|
|
|
|
LayoutDeviceIntPoint offset;
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowOuter* window = GetContent()->OwnerDoc()->GetWindow()) {
|
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> topWindow = window->GetTop()) {
|
2015-04-08 19:51:49 +03:00
|
|
|
dom::TabChild* tc = dom::TabChild::GetFrom(topWindow);
|
|
|
|
if (tc) {
|
2015-09-28 13:35:00 +03:00
|
|
|
offset += tc->GetChromeDisplacement();
|
2015-04-08 19:51:49 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint
|
|
|
|
nsPluginFrame::GetWindowOriginInPixels(bool aWindowless)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView * parentWithView;
|
2010-11-08 17:48:02 +03:00
|
|
|
nsPoint origin(0,0);
|
|
|
|
|
|
|
|
GetOffsetFromView(origin, &parentWithView);
|
|
|
|
|
|
|
|
// if it's windowless, let's make sure we have our origin set right
|
|
|
|
// it may need to be corrected, like after scrolling
|
|
|
|
if (aWindowless && parentWithView) {
|
|
|
|
nsPoint offsetToWidget;
|
|
|
|
parentWithView->GetNearestWidget(&offsetToWidget);
|
|
|
|
origin += offsetToWidget;
|
|
|
|
}
|
2011-04-19 07:07:22 +04:00
|
|
|
origin += GetContentRectRelativeToSelf().TopLeft();
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2015-04-08 19:51:49 +03:00
|
|
|
nsIntPoint pt(PresContext()->AppUnitsToDevPixels(origin.x),
|
|
|
|
PresContext()->AppUnitsToDevPixels(origin.y));
|
|
|
|
|
|
|
|
// If we're in the content process offsetToWidget is tied to the top level
|
|
|
|
// widget we can access in the child process, which is the tab. We need the
|
|
|
|
// offset all the way up to the top level native window here. (If this is
|
|
|
|
// non-e10s this routine will return 0,0.)
|
|
|
|
if (aWindowless) {
|
|
|
|
mozilla::LayoutDeviceIntPoint lpt = GetRemoteTabChromeOffset();
|
|
|
|
pt += nsIntPoint(lpt.x, lpt.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pt;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:53 +04:00
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::DidReflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput* aReflowInput,
|
2010-11-08 17:48:02 +03:00
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
|
|
|
// Do this check before calling the superclass, as that clears
|
|
|
|
// NS_FRAME_FIRST_REFLOW
|
2012-11-14 10:47:33 +04:00
|
|
|
if (aStatus == nsDidReflowStatus::FINISHED &&
|
2010-11-08 17:48:02 +03:00
|
|
|
(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
nsCOMPtr<nsIObjectLoadingContent> objContent(do_QueryInterface(mContent));
|
|
|
|
NS_ASSERTION(objContent, "Why not an object loading content?");
|
|
|
|
objContent->HasNewFrame(this);
|
|
|
|
}
|
|
|
|
|
2016-07-21 13:36:39 +03:00
|
|
|
nsFrame::DidReflow(aPresContext, aReflowInput, aStatus);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// The view is created hidden; once we have reflowed it and it has been
|
|
|
|
// positioned then we show it.
|
2013-04-18 02:11:21 +04:00
|
|
|
if (aStatus != nsDidReflowStatus::FINISHED)
|
2014-05-13 04:47:53 +04:00
|
|
|
return;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
if (HasView()) {
|
2013-01-03 17:23:11 +04:00
|
|
|
nsView* view = GetView();
|
2013-01-05 07:12:24 +04:00
|
|
|
nsViewManager* vm = view->GetViewManager();
|
2010-11-08 17:48:02 +03:00
|
|
|
if (vm)
|
|
|
|
vm->SetViewVisibility(view, IsHidden() ? nsViewVisibility_kHide : nsViewVisibility_kShow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::PaintPrintPlugin(nsIFrame* aFrame, nsRenderingContext* aCtx,
|
2010-11-08 17:48:02 +03:00
|
|
|
const nsRect& aDirtyRect, nsPoint aPt)
|
|
|
|
{
|
2014-09-11 10:48:09 +04:00
|
|
|
gfxContext* ctx = aCtx->ThebesContext();
|
|
|
|
|
|
|
|
// Translate the context:
|
2011-04-19 07:07:22 +04:00
|
|
|
nsPoint pt = aPt + aFrame->GetContentRectRelativeToSelf().TopLeft();
|
2014-09-11 10:48:09 +04:00
|
|
|
gfxPoint devPixelPt =
|
|
|
|
nsLayoutUtils::PointToGfxPoint(pt, aFrame->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
|
|
|
|
gfxContextMatrixAutoSaveRestore autoSR(ctx);
|
|
|
|
ctx->SetMatrix(ctx->CurrentMatrix().Translate(devPixelPt));
|
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
// FIXME - Bug 385435: Doesn't aDirtyRect need translating too?
|
2014-09-11 10:48:09 +04:00
|
|
|
|
2014-09-24 08:34:00 +04:00
|
|
|
static_cast<nsPluginFrame*>(aFrame)->PrintPlugin(*aCtx, aDirtyRect);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2014-06-23 08:24:14 +04:00
|
|
|
/**
|
|
|
|
* nsDisplayPluginReadback creates an active ReadbackLayer. The ReadbackLayer
|
|
|
|
* obtains from the compositor the contents of the window underneath
|
|
|
|
* the ReadbackLayer, which we then use as an opaque buffer for plugins to
|
|
|
|
* asynchronously draw onto.
|
|
|
|
*/
|
2011-02-17 01:43:30 +03:00
|
|
|
class nsDisplayPluginReadback : public nsDisplayItem {
|
|
|
|
public:
|
|
|
|
nsDisplayPluginReadback(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayPluginReadback);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2016-11-09 16:37:59 +03:00
|
|
|
~nsDisplayPluginReadback() override {
|
2011-02-17 01:43:30 +03:00
|
|
|
MOZ_COUNT_DTOR(nsDisplayPluginReadback);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool* aSnap) override;
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("PluginReadback", TYPE_PLUGIN_READBACK)
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager* aManager,
|
2015-03-21 19:28:04 +03:00
|
|
|
const ContainerLayerParameters& aContainerParameters) override
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
2014-09-24 08:34:00 +04:00
|
|
|
return static_cast<nsPluginFrame*>(mFrame)->BuildLayer(aBuilder, aManager, this, aContainerParameters);
|
2010-12-20 04:37:43 +03:00
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 18:05:55 +04:00
|
|
|
LayerManager* aManager,
|
2015-03-21 19:28:04 +03:00
|
|
|
const ContainerLayerParameters& aParameters) override
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static nsRect
|
2011-02-23 08:38:09 +03:00
|
|
|
GetDisplayItemBounds(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem, nsIFrame* aFrame)
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
2011-02-23 08:38:09 +03:00
|
|
|
// XXX For slightly more accurate region computations we should pixel-snap this
|
2011-04-19 07:07:22 +04:00
|
|
|
return aFrame->GetContentRectRelativeToSelf() + aItem->ToReferenceFrame();
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplayPluginReadback::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2011-02-23 08:38:09 +03:00
|
|
|
return GetDisplayItemBounds(aBuilder, this, mFrame);
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
|
2012-07-20 23:20:51 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
class nsDisplayPluginVideo : public nsDisplayItem {
|
|
|
|
public:
|
|
|
|
nsDisplayPluginVideo(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame, nsNPAPIPluginInstance::VideoInfo* aVideoInfo)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame), mVideoInfo(aVideoInfo)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayPluginVideo);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayPluginVideo() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayPluginVideo);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool* aSnap) override;
|
2012-07-20 23:20:51 +04:00
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("PluginVideo", TYPE_PLUGIN_VIDEO)
|
|
|
|
|
|
|
|
virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2015-03-21 19:28:04 +03:00
|
|
|
const ContainerLayerParameters& aContainerParameters) override
|
2012-07-20 23:20:51 +04:00
|
|
|
{
|
2014-09-24 08:34:00 +04:00
|
|
|
return static_cast<nsPluginFrame*>(mFrame)->BuildLayer(aBuilder, aManager, this, aContainerParameters);
|
2012-07-20 23:20:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2015-03-21 19:28:04 +03:00
|
|
|
const ContainerLayerParameters& aParameters) override
|
2012-07-20 23:20:51 +04:00
|
|
|
{
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNPAPIPluginInstance::VideoInfo* VideoInfo() { return mVideoInfo; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsNPAPIPluginInstance::VideoInfo* mVideoInfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
nsDisplayPluginVideo::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
|
|
|
{
|
|
|
|
*aSnap = false;
|
|
|
|
return GetDisplayItemBounds(aBuilder, this, mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
nsRect
|
2012-04-10 15:24:18 +04:00
|
|
|
nsDisplayPlugin::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
2012-11-13 23:56:47 +04:00
|
|
|
*aSnap = true;
|
2011-02-23 08:38:09 +03:00
|
|
|
return GetDisplayItemBounds(aBuilder, this, mFrame);
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
void
|
|
|
|
nsDisplayPlugin::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame* f = static_cast<nsPluginFrame*>(mFrame);
|
2012-04-10 15:24:18 +04:00
|
|
|
bool snap;
|
|
|
|
f->PaintPlugin(aBuilder, *aCtx, mVisibleRect, GetBounds(aBuilder, &snap));
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2016-02-22 18:17:16 +03:00
|
|
|
static nsRect
|
|
|
|
GetClippedBoundsIncludingAllScrollClips(nsDisplayItem* aItem,
|
|
|
|
nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
nsRect r = aItem->GetClippedBounds(aBuilder);
|
2017-02-01 01:07:35 +03:00
|
|
|
for (auto* sc = aItem->GetClipChain(); sc; sc = sc->mParent) {
|
|
|
|
r = sc->mClip.ApplyNonRoundedIntersection(r);
|
2016-02-22 18:17:16 +03:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-11-08 17:48:02 +03:00
|
|
|
nsDisplayPlugin::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2014-06-23 08:24:51 +04:00
|
|
|
nsRegion* aVisibleRegion)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2012-10-06 17:03:23 +04:00
|
|
|
if (aBuilder->IsForPluginGeometry()) {
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame* f = static_cast<nsPluginFrame*>(mFrame);
|
2012-10-06 17:03:23 +04:00
|
|
|
if (!aBuilder->IsInTransform() || f->IsPaintedByGecko()) {
|
|
|
|
// Since transforms induce reference frames, we don't need to worry
|
|
|
|
// about this method fluffing out due to non-rectilinear transforms.
|
|
|
|
nsRect rAncestor = nsLayoutUtils::TransformFrameRectToAncestor(f,
|
|
|
|
f->GetContentRectRelativeToSelf(), ReferenceFrame());
|
|
|
|
nscoord appUnitsPerDevPixel =
|
|
|
|
ReferenceFrame()->PresContext()->AppUnitsPerDevPixel();
|
2015-12-03 01:32:55 +03:00
|
|
|
f->mNextConfigurationBounds = LayoutDeviceIntRect::FromUnknownRect(
|
|
|
|
rAncestor.ToNearestPixels(appUnitsPerDevPixel));
|
2012-10-06 17:03:23 +04:00
|
|
|
|
|
|
|
nsRegion visibleRegion;
|
2015-12-24 14:02:05 +03:00
|
|
|
// Apply all scroll clips when computing the clipped bounds of this item.
|
|
|
|
// We hide windowed plugins during APZ scrolling, so there never is an
|
|
|
|
// async transform that we need to take into account when clipping.
|
2016-02-22 18:17:16 +03:00
|
|
|
visibleRegion.And(*aVisibleRegion, GetClippedBoundsIncludingAllScrollClips(this, aBuilder));
|
2012-10-06 17:03:23 +04:00
|
|
|
// Make visibleRegion relative to f
|
|
|
|
visibleRegion.MoveBy(-ToReferenceFrame());
|
|
|
|
|
|
|
|
f->mNextConfigurationClipRegion.Clear();
|
2016-01-19 04:20:59 +03:00
|
|
|
for (auto iter = visibleRegion.RectIter(); !iter.Done(); iter.Next()) {
|
2012-10-06 17:03:23 +04:00
|
|
|
nsRect rAncestor =
|
2016-01-19 04:20:59 +03:00
|
|
|
nsLayoutUtils::TransformFrameRectToAncestor(f, iter.Get(), ReferenceFrame());
|
2015-12-03 01:32:55 +03:00
|
|
|
LayoutDeviceIntRect rPixels =
|
|
|
|
LayoutDeviceIntRect::FromUnknownRect(rAncestor.ToNearestPixels(appUnitsPerDevPixel)) -
|
|
|
|
f->mNextConfigurationBounds.TopLeft();
|
2012-10-06 17:03:23 +04:00
|
|
|
if (!rPixels.IsEmpty()) {
|
|
|
|
f->mNextConfigurationClipRegion.AppendElement(rPixels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f->mInnerView) {
|
|
|
|
// This should produce basically the same rectangle (but not relative
|
|
|
|
// to the root frame). We only call this here for the side-effect of
|
|
|
|
// setting mViewToWidgetOffset on the view.
|
|
|
|
f->mInnerView->CalcWidgetBounds(eWindowType_plugin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 08:24:51 +04:00
|
|
|
return nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion
|
|
|
|
nsDisplayPlugin::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-03 08:29:05 +04:00
|
|
|
bool* aSnap)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame* f = static_cast<nsPluginFrame*>(mFrame);
|
2010-11-08 12:06:14 +03:00
|
|
|
if (!aBuilder->IsForPluginGeometry()) {
|
|
|
|
nsIWidget* widget = f->GetWidget();
|
|
|
|
if (widget) {
|
2012-10-06 17:03:23 +04:00
|
|
|
// Be conservative and treat plugins with widgets as not opaque,
|
|
|
|
// because that's simple and we might need the content under the widget
|
|
|
|
// if the widget is unexpectedly clipped away. (As can happen when
|
|
|
|
// chrome content over a plugin forces us to clip out the plugin for
|
|
|
|
// security reasons.)
|
|
|
|
// We shouldn't be repainting the content under plugins much anyway
|
|
|
|
// since there generally shouldn't be anything to invalidate or paint
|
2014-09-26 21:06:08 +04:00
|
|
|
// in PaintedLayers there.
|
2012-10-06 17:03:23 +04:00
|
|
|
return result;
|
2010-11-08 12:06:14 +03:00
|
|
|
}
|
|
|
|
}
|
2012-10-06 17:03:23 +04:00
|
|
|
|
2012-04-10 15:24:18 +04:00
|
|
|
if (f->IsOpaque()) {
|
|
|
|
nsRect bounds = GetBounds(aBuilder, aSnap);
|
|
|
|
if (aBuilder->IsForPluginGeometry() ||
|
|
|
|
(f->GetPaintedRect(this) + ToReferenceFrame()).Contains(bounds)) {
|
|
|
|
// We can treat this as opaque
|
|
|
|
result = bounds;
|
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2012-10-06 17:03:23 +04:00
|
|
|
return result;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::PluginEventNotifier::Run() {
|
2010-11-08 17:48:02 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
mozilla::services::GetObserverService();
|
2012-07-30 18:20:58 +04:00
|
|
|
obsSvc->NotifyObservers(nullptr, "plugin-changed-event", mEventType.get());
|
2010-11-08 17:48:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::NotifyPluginReflowObservers()
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
nsContentUtils::AddScriptRunner(new PluginEventNotifier(NS_LITERAL_STRING("reflow")));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::DidSetWidgetGeometry()
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2015-01-21 22:02:32 +03:00
|
|
|
#if defined(XP_MACOSX)
|
2015-04-25 00:44:00 +03:00
|
|
|
if (mInstanceOwner && !IsHidden()) {
|
2015-01-21 22:02:32 +03:00
|
|
|
mInstanceOwner->FixUpPluginWindow(nsPluginInstanceOwner::ePluginPaintEnable);
|
|
|
|
}
|
|
|
|
#else
|
2012-10-06 17:03:23 +04:00
|
|
|
if (!mWidget && mInstanceOwner) {
|
|
|
|
// UpdateWindowVisibility will notify the plugin of position changes
|
|
|
|
// by updating the NPWindow and calling NPP_SetWindow/AsyncSetWindow.
|
2012-11-27 17:18:39 +04:00
|
|
|
// We treat windowless plugins inside popups as always visible, since
|
|
|
|
// plugins inside popups don't get valid mNextConfigurationBounds
|
|
|
|
// set up.
|
|
|
|
mInstanceOwner->UpdateWindowVisibility(
|
|
|
|
nsLayoutUtils::IsPopup(nsLayoutUtils::GetDisplayRootFrame(this)) ||
|
|
|
|
!mNextConfigurationBounds.IsEmpty());
|
2012-10-06 17:03:23 +04:00
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::IsOpaque() const
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
#if defined(XP_MACOSX)
|
2011-10-01 19:43:07 +04:00
|
|
|
return false;
|
2012-07-20 23:20:51 +04:00
|
|
|
#elif defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// We don't know, so just assume transparent
|
|
|
|
return false;
|
2011-02-17 01:43:30 +03:00
|
|
|
#else
|
2016-06-07 05:21:30 +03:00
|
|
|
|
|
|
|
if (mInstanceOwner && mInstanceOwner->UseAsyncRendering()) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-17 01:43:30 +03:00
|
|
|
return !IsTransparentMode();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::IsTransparentMode() const
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
|
|
|
#if defined(XP_MACOSX)
|
2011-10-01 19:43:07 +04:00
|
|
|
return false;
|
2010-11-08 17:48:02 +03:00
|
|
|
#else
|
|
|
|
if (!mInstanceOwner)
|
2011-10-01 19:43:07 +04:00
|
|
|
return false;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NPWindow *window = nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
mInstanceOwner->GetWindow(window);
|
2012-02-03 02:55:25 +04:00
|
|
|
if (!window) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
if (window->type != NPWindowTypeDrawable)
|
2011-10-01 19:43:07 +04:00
|
|
|
return false;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsNPAPIPluginInstance> pi;
|
2011-05-18 05:48:34 +04:00
|
|
|
rv = mInstanceOwner->GetInstance(getter_AddRefs(pi));
|
2010-11-08 17:48:02 +03:00
|
|
|
if (NS_FAILED(rv) || !pi)
|
2011-10-01 19:43:07 +04:00
|
|
|
return false;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool transparent = false;
|
2010-11-08 17:48:02 +03:00
|
|
|
pi->IsTransparent(&transparent);
|
2011-02-17 01:43:30 +03:00
|
|
|
return transparent;
|
2010-11-08 17:48:02 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2010-11-08 17:48:02 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// XXX why are we painting collapsed object frames?
|
|
|
|
if (!IsVisibleOrCollapsedForPainting(aBuilder))
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
nsPresContext::nsPresContextType type = PresContext()->Type();
|
|
|
|
|
|
|
|
// If we are painting in Print Preview do nothing....
|
|
|
|
if (type == nsPresContext::eContext_PrintPreview)
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2014-09-24 08:34:00 +04:00
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsPluginFrame");
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
if (mWidget && aBuilder->IsInTransform()) {
|
|
|
|
// Windowed plugins should not be rendered inside a transform.
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-11 17:44:07 +03:00
|
|
|
if (aBuilder->IsForPainting() && mInstanceOwner) {
|
2016-03-17 22:00:59 +03:00
|
|
|
// Update plugin frame for both content scaling and full zoom changes.
|
2014-12-11 17:44:07 +03:00
|
|
|
mInstanceOwner->ResolutionMayHaveChanged();
|
2016-03-17 22:00:59 +03:00
|
|
|
#ifdef XP_MACOSX
|
2014-12-11 17:44:07 +03:00
|
|
|
mInstanceOwner->WindowFocusMayHaveChanged();
|
|
|
|
#endif
|
|
|
|
if (mInstanceOwner->UseAsyncRendering()) {
|
|
|
|
NPWindow* window = nullptr;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
bool isVisible = window && window->width > 0 && window->height > 0;
|
|
|
|
if (isVisible && aBuilder->ShouldSyncDecodeImages()) {
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
mInstanceOwner->UpdateWindowVisibility(true);
|
|
|
|
#endif
|
|
|
|
}
|
2010-12-20 04:37:43 +03:00
|
|
|
|
2014-12-11 17:44:07 +03:00
|
|
|
mInstanceOwner->NotifyPaintWaiter(aBuilder);
|
|
|
|
}
|
2010-12-20 04:37:43 +03:00
|
|
|
}
|
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox
|
2014-05-14 08:10:01 +04:00
|
|
|
clip(aBuilder, this);
|
2013-03-04 13:56:02 +04:00
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
// determine if we are printing
|
|
|
|
if (type == nsPresContext::eContext_Print) {
|
2013-03-04 13:56:02 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 15:08:08 +04:00
|
|
|
nsDisplayGeneric(aBuilder, this, PaintPrintPlugin, "PrintPlugin",
|
|
|
|
nsDisplayItem::TYPE_PRINT_PLUGIN));
|
2010-11-08 17:48:02 +03:00
|
|
|
} else {
|
2012-11-23 03:29:05 +04:00
|
|
|
LayerState state = GetLayerState(aBuilder, nullptr);
|
|
|
|
if (state == LAYER_INACTIVE &&
|
|
|
|
nsDisplayItem::ForceActiveLayers()) {
|
|
|
|
state = LAYER_ACTIVE;
|
|
|
|
}
|
2012-07-20 23:20:51 +04:00
|
|
|
// We don't need this on Android, and it just confuses things
|
|
|
|
#if !MOZ_WIDGET_ANDROID
|
2011-02-17 01:43:30 +03:00
|
|
|
if (aBuilder->IsPaintingToWindow() &&
|
2012-11-23 03:29:05 +04:00
|
|
|
state == LAYER_ACTIVE &&
|
2011-02-17 01:43:30 +03:00
|
|
|
IsTransparentMode()) {
|
2013-03-04 13:56:02 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 15:08:08 +04:00
|
|
|
nsDisplayPluginReadback(aBuilder, this));
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
2012-07-20 23:20:51 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MOZ_WIDGET_ANDROID
|
|
|
|
if (aBuilder->IsPaintingToWindow() &&
|
2012-11-23 03:29:05 +04:00
|
|
|
state == LAYER_ACTIVE) {
|
2012-07-20 23:20:51 +04:00
|
|
|
|
|
|
|
nsTArray<nsNPAPIPluginInstance::VideoInfo*> videos;
|
|
|
|
mInstanceOwner->GetVideos(videos);
|
2012-10-15 00:56:03 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < videos.Length(); i++) {
|
2013-03-04 13:56:02 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2012-07-20 23:20:51 +04:00
|
|
|
nsDisplayPluginVideo(aBuilder, this, videos[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 15:08:08 +04:00
|
|
|
nsDisplayPlugin(aBuilder, this));
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::PrintPlugin(nsRenderingContext& aRenderingContext,
|
2010-11-08 17:48:02 +03:00
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObjectLoadingContent> obj(do_QueryInterface(mContent));
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* frame = nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
obj->GetPrintFrame(&frame);
|
|
|
|
if (!frame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
// make sure this is REALLY an nsIObjectFrame
|
|
|
|
// we may need to go through the children to get it
|
|
|
|
nsIObjectFrame* objectFrame = do_QueryFrame(frame);
|
|
|
|
if (!objectFrame)
|
|
|
|
objectFrame = GetNextObjectFrame(presContext,frame);
|
|
|
|
if (!objectFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// finally we can get our plugin instance
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsNPAPIPluginInstance> pi;
|
2011-05-18 05:48:34 +04:00
|
|
|
if (NS_FAILED(objectFrame->GetPluginInstance(getter_AddRefs(pi))) || !pi)
|
2010-11-08 17:48:02 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
// now we need to setup the correct location for printing
|
|
|
|
NPWindow window;
|
2012-07-30 18:20:58 +04:00
|
|
|
window.window = nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// prepare embedded mode printing struct
|
|
|
|
NPPrint npprint;
|
|
|
|
npprint.mode = NP_EMBED;
|
|
|
|
|
|
|
|
// we need to find out if we are windowless or not
|
2011-09-29 10:19:26 +04:00
|
|
|
bool windowless = false;
|
2010-11-08 17:48:02 +03:00
|
|
|
pi->IsWindowless(&windowless);
|
|
|
|
window.type = windowless ? NPWindowTypeDrawable : NPWindowTypeWindow;
|
|
|
|
|
|
|
|
window.clipRect.bottom = 0; window.clipRect.top = 0;
|
|
|
|
window.clipRect.left = 0; window.clipRect.right = 0;
|
2012-10-15 05:28:23 +04:00
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
// platform specific printing code
|
2014-12-11 17:44:07 +03:00
|
|
|
#if defined(XP_UNIX) || defined(XP_MACOSX)
|
|
|
|
// Doesn't work in a thebes world, or on OS X.
|
2011-12-20 07:46:39 +04:00
|
|
|
(void)window;
|
|
|
|
(void)npprint;
|
2010-11-08 17:48:02 +03:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
|
|
|
|
/* On Windows, we use the win32 printing surface to print. This, in
|
|
|
|
* turn, uses the Cairo paginated surface, which in turn uses the
|
|
|
|
* meta surface to record all operations and then play them back.
|
|
|
|
* This doesn't work too well for plugins, because if plugins render
|
|
|
|
* directly into the DC, the meta surface won't have any knowledge
|
|
|
|
* of them, and so at the end when it actually does the replay step,
|
|
|
|
* it'll fill the background with white and draw over whatever was
|
|
|
|
* rendered before.
|
|
|
|
*
|
|
|
|
* So, to avoid this, we use PushGroup, which creates a new windows
|
|
|
|
* surface, the plugin renders to that, and then we use normal
|
|
|
|
* cairo methods to composite that in such that it's recorded using the
|
|
|
|
* meta surface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* we'll already be translated into the right spot by gfxWindowsNativeDrawing */
|
2011-04-19 07:07:22 +04:00
|
|
|
nsSize contentSize = GetContentRectRelativeToSelf().Size();
|
2010-11-08 17:48:02 +03:00
|
|
|
window.x = 0;
|
|
|
|
window.y = 0;
|
|
|
|
window.width = presContext->AppUnitsToDevPixels(contentSize.width);
|
|
|
|
window.height = presContext->AppUnitsToDevPixels(contentSize.height);
|
|
|
|
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
|
|
|
|
|
|
|
ctx->Save();
|
|
|
|
|
|
|
|
/* Make sure plugins don't do any damage outside of where they're supposed to */
|
|
|
|
ctx->NewPath();
|
|
|
|
gfxRect r(window.x, window.y, window.width, window.height);
|
|
|
|
ctx->Rectangle(r);
|
|
|
|
ctx->Clip();
|
|
|
|
|
|
|
|
gfxWindowsNativeDrawing nativeDraw(ctx, r);
|
|
|
|
do {
|
|
|
|
HDC dc = nativeDraw.BeginNativeDrawing();
|
|
|
|
if (!dc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// XXX don't we need to call nativeDraw.TransformToNativeRect here?
|
|
|
|
npprint.print.embedPrint.platformPrint = dc;
|
|
|
|
npprint.print.embedPrint.window = window;
|
|
|
|
// send off print info to plugin
|
|
|
|
pi->Print(&npprint);
|
|
|
|
|
|
|
|
nativeDraw.EndNativeDrawing();
|
|
|
|
} while (nativeDraw.ShouldRenderAgain());
|
|
|
|
nativeDraw.PaintToContext();
|
|
|
|
|
|
|
|
ctx->Restore();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// XXX Nav 4.x always sent a SetWindow call after print. Should we do the same?
|
|
|
|
// XXX Calling DidReflow here makes no sense!!!
|
2012-11-14 10:47:33 +04:00
|
|
|
nsDidReflowStatus status = nsDidReflowStatus::FINISHED; // should we use a special status?
|
2010-11-08 17:48:02 +03:00
|
|
|
frame->DidReflow(presContext,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, status); // DidReflow will take care of it
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2011-02-23 08:38:09 +03:00
|
|
|
nsRect
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetPaintedRect(nsDisplayPlugin* aItem)
|
2011-02-23 08:38:09 +03:00
|
|
|
{
|
|
|
|
if (!mInstanceOwner)
|
|
|
|
return nsRect();
|
2011-04-19 07:07:22 +04:00
|
|
|
nsRect r = GetContentRectRelativeToSelf();
|
2011-02-23 08:38:09 +03:00
|
|
|
if (!mInstanceOwner->UseAsyncRendering())
|
|
|
|
return r;
|
|
|
|
|
|
|
|
nsIntSize size = mInstanceOwner->GetCurrentImageSize();
|
|
|
|
nsPresContext* pc = PresContext();
|
|
|
|
r.IntersectRect(r, nsRect(0, 0, pc->DevPixelsToAppUnits(size.width),
|
|
|
|
pc->DevPixelsToAppUnits(size.height)));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerState
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetLayerState(nsDisplayListBuilder* aBuilder,
|
2010-11-08 17:48:02 +03:00
|
|
|
LayerManager* aManager)
|
|
|
|
{
|
2011-02-12 19:09:03 +03:00
|
|
|
if (!mInstanceOwner)
|
2011-02-23 08:38:09 +03:00
|
|
|
return LAYER_NONE;
|
2011-02-12 19:09:03 +03:00
|
|
|
|
2012-07-20 23:20:51 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// We always want a layer on Honeycomb and later
|
2016-08-30 08:11:55 +03:00
|
|
|
return LAYER_ACTIVE;
|
|
|
|
#else
|
2016-03-01 21:48:26 +03:00
|
|
|
if (mInstanceOwner->NeedsScrollImageLayer()) {
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
|
2011-06-30 20:46:26 +04:00
|
|
|
if (!mInstanceOwner->UseAsyncRendering()) {
|
2011-02-23 08:38:09 +03:00
|
|
|
return LAYER_NONE;
|
2011-06-30 20:46:26 +04:00
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2016-01-14 02:42:27 +03:00
|
|
|
return LAYER_ACTIVE_FORCE;
|
2016-08-30 08:11:55 +03:00
|
|
|
#endif
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 07:36:41 +03:00
|
|
|
class PluginFrameDidCompositeObserver final : public DidCompositeObserver
|
2015-12-02 22:31:17 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-12-01 07:36:41 +03:00
|
|
|
PluginFrameDidCompositeObserver(nsPluginInstanceOwner* aOwner, LayerManager* aLayerManager)
|
2015-12-02 22:31:17 +03:00
|
|
|
: mInstanceOwner(aOwner),
|
|
|
|
mLayerManager(aLayerManager)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
~PluginFrameDidCompositeObserver() {
|
|
|
|
mLayerManager->RemoveDidCompositeObserver(this);
|
|
|
|
}
|
|
|
|
void DidComposite() override {
|
|
|
|
mInstanceOwner->DidComposite();
|
|
|
|
}
|
2016-12-01 07:36:41 +03:00
|
|
|
bool IsValid(LayerManager* aLayerManager) {
|
2015-12-02 22:31:17 +03:00
|
|
|
return aLayerManager == mLayerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsPluginInstanceOwner* mInstanceOwner;
|
2016-12-01 07:36:41 +03:00
|
|
|
RefPtr<LayerManager> mLayerManager;
|
2015-12-02 22:31:17 +03:00
|
|
|
};
|
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
already_AddRefed<Layer>
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2010-11-08 17:48:02 +03:00
|
|
|
LayerManager* aManager,
|
2012-09-17 02:25:33 +04:00
|
|
|
nsDisplayItem* aItem,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
if (!mInstanceOwner)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NPWindow* window = nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
if (!window)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
if (window->width <= 0 || window->height <= 0)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2015-09-17 23:31:34 +03:00
|
|
|
#if defined(XP_MACOSX)
|
2012-10-02 23:48:05 +04:00
|
|
|
// window is in "display pixels", but size needs to be in device pixels
|
2015-09-17 23:31:34 +03:00
|
|
|
// window must be in "display pixels"
|
2012-10-02 23:48:05 +04:00
|
|
|
double scaleFactor = 1.0;
|
|
|
|
if (NS_FAILED(mInstanceOwner->GetContentsScaleFactor(&scaleFactor))) {
|
|
|
|
scaleFactor = 1.0;
|
|
|
|
}
|
2015-09-17 23:31:34 +03:00
|
|
|
|
|
|
|
size_t intScaleFactor = ceil(scaleFactor);
|
|
|
|
#else
|
|
|
|
size_t intScaleFactor = 1;
|
|
|
|
#endif
|
|
|
|
|
2013-12-31 13:06:12 +04:00
|
|
|
IntSize size(window->width * intScaleFactor, window->height * intScaleFactor);
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2011-04-19 07:07:22 +04:00
|
|
|
nsRect area = GetContentRectRelativeToSelf() + aItem->ToReferenceFrame();
|
2010-11-08 17:48:02 +03:00
|
|
|
gfxRect r = nsLayoutUtils::RectToGfxRect(area, PresContext()->AppUnitsPerDevPixel());
|
|
|
|
// to provide crisper and faster drawing.
|
|
|
|
r.Round();
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Layer> layer =
|
2012-08-29 09:47:15 +04:00
|
|
|
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, aItem));
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
if (aItem->GetType() == nsDisplayItem::TYPE_PLUGIN) {
|
2016-03-01 21:48:26 +03:00
|
|
|
RefPtr<ImageContainer> container;
|
|
|
|
// Image for Windowed plugins that support window capturing for scroll
|
|
|
|
// operations or async windowless rendering.
|
|
|
|
container = mInstanceOwner->GetImageContainer();
|
2012-11-08 01:15:27 +04:00
|
|
|
if (!container) {
|
2016-03-01 21:48:26 +03:00
|
|
|
// This can occur if our instance is gone or if the current plugin
|
|
|
|
// configuration does not require a backing image layer.
|
2012-11-08 01:15:27 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
if (!layer) {
|
2011-02-12 19:09:03 +03:00
|
|
|
mInstanceOwner->NotifyPaintWaiter(aBuilder);
|
2011-02-17 01:43:30 +03:00
|
|
|
// Initialize ImageLayer
|
|
|
|
layer = aManager->CreateImageLayer();
|
|
|
|
if (!layer)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-02-12 19:09:03 +03:00
|
|
|
}
|
|
|
|
|
2012-10-31 06:54:06 +04:00
|
|
|
NS_ASSERTION(layer->GetType() == Layer::TYPE_IMAGE, "Bad layer type");
|
2011-02-17 01:43:30 +03:00
|
|
|
ImageLayer* imglayer = static_cast<ImageLayer*>(layer.get());
|
2013-04-17 06:21:06 +04:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (!mInstanceOwner->UseAsyncRendering()) {
|
|
|
|
mInstanceOwner->DoCocoaEventDrawRect(r, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
2011-02-17 06:56:06 +03:00
|
|
|
|
2014-01-23 22:26:41 +04:00
|
|
|
imglayer->SetScaleToSize(size, ScaleMode::STRETCH);
|
2011-02-17 01:43:30 +03:00
|
|
|
imglayer->SetContainer(container);
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter samplingFilter = nsLayoutUtils::GetSamplingFilterForFrame(this);
|
2011-09-19 15:12:16 +04:00
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
if (!aManager->IsCompositingCheap()) {
|
|
|
|
// Pixman just horrible with bilinear filter scaling
|
2016-05-25 19:01:18 +03:00
|
|
|
samplingFilter = SamplingFilter::POINT;
|
2011-09-19 15:12:16 +04:00
|
|
|
}
|
|
|
|
#endif
|
2016-05-25 19:01:18 +03:00
|
|
|
imglayer->SetSamplingFilter(samplingFilter);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
layer->SetContentFlags(IsOpaque() ? Layer::CONTENT_OPAQUE : 0);
|
2015-12-02 22:31:17 +03:00
|
|
|
|
|
|
|
if (aBuilder->IsPaintingToWindow() &&
|
|
|
|
aBuilder->GetWidgetLayerManager() &&
|
2016-12-01 07:36:41 +03:00
|
|
|
(aBuilder->GetWidgetLayerManager()->GetBackendType() == LayersBackend::LAYERS_CLIENT ||
|
|
|
|
aBuilder->GetWidgetLayerManager()->GetBackendType() == LayersBackend::LAYERS_WR) &&
|
2015-12-02 22:31:17 +03:00
|
|
|
mInstanceOwner->UseAsyncRendering())
|
|
|
|
{
|
2016-12-01 07:36:41 +03:00
|
|
|
RefPtr<LayerManager> lm = aBuilder->GetWidgetLayerManager();
|
2015-12-02 22:31:17 +03:00
|
|
|
if (!mDidCompositeObserver || !mDidCompositeObserver->IsValid(lm)) {
|
2016-07-08 09:08:00 +03:00
|
|
|
mDidCompositeObserver = MakeUnique<PluginFrameDidCompositeObserver>(mInstanceOwner, lm);
|
2015-12-02 22:31:17 +03:00
|
|
|
}
|
2016-07-08 09:08:00 +03:00
|
|
|
lm->AddDidCompositeObserver(mDidCompositeObserver.get());
|
2015-12-02 22:31:17 +03:00
|
|
|
}
|
2012-07-20 23:20:51 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
} else if (aItem->GetType() == nsDisplayItem::TYPE_PLUGIN_VIDEO) {
|
|
|
|
nsDisplayPluginVideo* videoItem = reinterpret_cast<nsDisplayPluginVideo*>(aItem);
|
|
|
|
nsNPAPIPluginInstance::VideoInfo* videoInfo = videoItem->VideoInfo();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageContainer> container = mInstanceOwner->GetImageContainerForVideo(videoInfo);
|
2012-07-20 23:20:51 +04:00
|
|
|
if (!container)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-07-20 23:20:51 +04:00
|
|
|
|
|
|
|
if (!layer) {
|
|
|
|
// Initialize ImageLayer
|
|
|
|
layer = aManager->CreateImageLayer();
|
|
|
|
if (!layer)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-07-20 23:20:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageLayer* imglayer = static_cast<ImageLayer*>(layer.get());
|
|
|
|
imglayer->SetContainer(container);
|
|
|
|
|
|
|
|
layer->SetContentFlags(IsOpaque() ? Layer::CONTENT_OPAQUE : 0);
|
|
|
|
|
|
|
|
// Set the offset and size according to the video dimensions
|
|
|
|
r.MoveBy(videoInfo->mDimensions.TopLeft());
|
|
|
|
size.width = videoInfo->mDimensions.width;
|
|
|
|
size.height = videoInfo->mDimensions.height;
|
|
|
|
#endif
|
2011-02-17 01:43:30 +03:00
|
|
|
} else {
|
|
|
|
NS_ASSERTION(aItem->GetType() == nsDisplayItem::TYPE_PLUGIN_READBACK,
|
|
|
|
"Unknown item type");
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!IsOpaque(), "Opaque plugins don't use backgrounds");
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
if (!layer) {
|
|
|
|
layer = aManager->CreateReadbackLayer();
|
|
|
|
if (!layer)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-02-17 01:43:30 +03:00
|
|
|
}
|
|
|
|
NS_ASSERTION(layer->GetType() == Layer::TYPE_READBACK, "Bad layer type");
|
|
|
|
|
|
|
|
ReadbackLayer* readback = static_cast<ReadbackLayer*>(layer.get());
|
2015-03-29 17:59:15 +03:00
|
|
|
if (readback->GetSize() != size) {
|
2011-02-17 01:43:30 +03:00
|
|
|
// This will destroy any old background sink and notify us that the
|
|
|
|
// background is now unknown
|
2012-07-30 18:20:58 +04:00
|
|
|
readback->SetSink(nullptr);
|
2015-03-29 17:59:15 +03:00
|
|
|
readback->SetSize(size);
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2011-03-01 15:54:37 +03:00
|
|
|
if (mBackgroundSink) {
|
|
|
|
// Maybe we still have a background sink associated with another
|
|
|
|
// readback layer that wasn't recycled for some reason? Unhook it
|
|
|
|
// now so that if this frame goes away, it doesn't have a dangling
|
|
|
|
// reference to us.
|
|
|
|
mBackgroundSink->Destroy();
|
|
|
|
}
|
2011-02-17 01:43:30 +03:00
|
|
|
mBackgroundSink =
|
|
|
|
new PluginBackgroundSink(this,
|
|
|
|
readback->AllocateSequenceNumber());
|
|
|
|
readback->SetSink(mBackgroundSink);
|
|
|
|
// The layer has taken ownership of our sink. When either the sink dies
|
|
|
|
// or the frame dies, the connection from the surviving object is nulled out.
|
|
|
|
}
|
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// Set a transform on the layer to draw the plugin in the right place
|
2014-01-27 19:28:33 +04:00
|
|
|
gfxPoint p = r.TopLeft() + aContainerParameters.mOffset;
|
2014-09-10 17:26:12 +04:00
|
|
|
Matrix transform = Matrix::Translation(p.x, p.y);
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2014-01-27 19:28:33 +04:00
|
|
|
layer->SetBaseTransform(Matrix4x4::From2D(transform));
|
2011-02-17 01:43:30 +03:00
|
|
|
return layer.forget();
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::PaintPlugin(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2010-11-08 17:48:02 +03:00
|
|
|
const nsRect& aDirtyRect, const nsRect& aPluginRect)
|
|
|
|
{
|
2011-11-11 04:17:46 +04:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2011-09-17 01:34:31 +04:00
|
|
|
if (mInstanceOwner) {
|
|
|
|
gfxRect frameGfxRect =
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aPluginRect);
|
|
|
|
gfxRect dirtyGfxRect =
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aDirtyRect);
|
2012-01-18 19:41:35 +04:00
|
|
|
|
2012-03-12 21:03:54 +04:00
|
|
|
gfxContext* ctx = aRenderingContext.ThebesContext();
|
2012-01-18 19:41:35 +04:00
|
|
|
|
2012-03-12 21:03:54 +04:00
|
|
|
mInstanceOwner->Paint(ctx, frameGfxRect, dirtyGfxRect);
|
2011-09-17 01:34:31 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-10-28 20:50:53 +03:00
|
|
|
#else
|
|
|
|
# if defined(DEBUG)
|
|
|
|
// On Desktop, we should have built a layer as we no longer support in-process
|
|
|
|
// plugins or synchronous painting. We can only get here for windowed plugins
|
|
|
|
// (which draw themselves), or via some error/unload state.
|
|
|
|
if (mInstanceOwner) {
|
|
|
|
NPWindow *window = nullptr;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
MOZ_ASSERT(!window || window->type == NPWindowTypeWindow);
|
|
|
|
}
|
|
|
|
# endif
|
2011-09-17 01:34:31 +04:00
|
|
|
#endif
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::HandleEvent(nsPresContext* aPresContext,
|
2013-10-02 07:46:03 +04:00
|
|
|
WidgetGUIEvent* anEvent,
|
|
|
|
nsEventStatus* anEventStatus)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(anEvent);
|
|
|
|
NS_ENSURE_ARG_POINTER(anEventStatus);
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mInstanceOwner)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
mInstanceOwner->ConsiderNewEventloopNestingLevel();
|
|
|
|
|
2015-08-29 02:58:28 +03:00
|
|
|
if (anEvent->mMessage == ePluginActivate) {
|
2010-11-08 17:48:02 +03:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(GetContent());
|
|
|
|
if (fm && elem)
|
|
|
|
return fm->SetFocus(elem, 0);
|
|
|
|
}
|
2015-08-29 02:58:28 +03:00
|
|
|
else if (anEvent->mMessage == ePluginFocus) {
|
2011-03-25 18:03:33 +03:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2010-11-16 00:12:50 +03:00
|
|
|
if (fm)
|
|
|
|
return fm->FocusPlugin(GetContent());
|
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
if (mInstanceOwner->SendNativeEvents() &&
|
2013-09-24 14:04:16 +04:00
|
|
|
anEvent->IsNativeEventDelivererForPlugin()) {
|
2010-11-08 17:48:02 +03:00
|
|
|
*anEventStatus = mInstanceOwner->ProcessEvent(*anEvent);
|
2013-02-27 15:50:27 +04:00
|
|
|
// Due to plugin code reentering Gecko, this frame may be dead at this
|
|
|
|
// point.
|
2010-11-08 17:48:02 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2016-04-18 09:01:57 +03:00
|
|
|
rv = nsFrame::HandleEvent(aPresContext, anEvent, anEventStatus);
|
2010-11-08 17:48:02 +03:00
|
|
|
return rv;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// we want to process some native mouse events in the cocoa event model
|
2015-08-29 02:58:31 +03:00
|
|
|
if ((anEvent->mMessage == eMouseEnterIntoWidget ||
|
2015-09-10 19:59:54 +03:00
|
|
|
anEvent->mMessage == eWheel) &&
|
2010-11-08 17:48:02 +03:00
|
|
|
mInstanceOwner->GetEventModel() == NPEventModelCocoa) {
|
|
|
|
*anEventStatus = mInstanceOwner->ProcessEvent(*anEvent);
|
2013-02-27 15:50:27 +04:00
|
|
|
// Due to plugin code reentering Gecko, this frame may be dead at this
|
|
|
|
// point.
|
2010-11-08 17:48:02 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2013-09-18 03:36:03 +04:00
|
|
|
|
|
|
|
// These two calls to nsIPresShell::SetCapturingContext() (on mouse-down
|
|
|
|
// and mouse-up) are needed to make the routing of mouse events while
|
|
|
|
// dragging conform to standard OS X practice, and to the Cocoa NPAPI spec.
|
|
|
|
// See bug 525078 and bug 909678.
|
2015-08-29 02:58:30 +03:00
|
|
|
if (anEvent->mMessage == eMouseDown) {
|
2013-09-18 03:36:03 +04:00
|
|
|
nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
|
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
#endif
|
|
|
|
|
2016-04-18 09:01:57 +03:00
|
|
|
rv = nsFrame::HandleEvent(aPresContext, anEvent, anEventStatus);
|
2013-09-18 03:36:03 +04:00
|
|
|
|
|
|
|
// We need to be careful from this point because the call to
|
2016-04-18 09:01:57 +03:00
|
|
|
// nsFrame::HandleEvent() might have killed us.
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2015-08-29 02:58:30 +03:00
|
|
|
if (anEvent->mMessage == eMouseUp) {
|
2013-09-18 03:36:03 +04:00
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
#endif
|
|
|
|
|
2013-09-18 03:36:03 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-10-16 07:19:27 +03:00
|
|
|
void
|
|
|
|
nsPluginFrame::HandleWheelEventAsDefaultAction(WidgetWheelEvent* aWheelEvent)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(WantsToHandleWheelEventAsDefaultAction());
|
2016-03-22 10:47:52 +03:00
|
|
|
MOZ_ASSERT(!aWheelEvent->DefaultPrevented());
|
2015-10-16 07:19:27 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(!mInstanceOwner) ||
|
|
|
|
NS_WARN_IF(aWheelEvent->mMessage != eWheel)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the wheel event has native message, it should may be handled by
|
|
|
|
// HandleEvent() in the future. In such case, we should do nothing here.
|
|
|
|
if (NS_WARN_IF(!!aWheelEvent->mPluginEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInstanceOwner->ProcessEvent(*aWheelEvent);
|
|
|
|
// We need to assume that the event is always consumed/handled by the
|
|
|
|
// plugin. There is no way to know if it's actually consumed/handled.
|
|
|
|
aWheelEvent->mViewPortIsOverscrolled = false;
|
2016-03-31 18:27:45 +03:00
|
|
|
aWheelEvent->mOverflowDeltaX = 0;
|
2016-03-31 18:36:55 +03:00
|
|
|
aWheelEvent->mOverflowDeltaY = 0;
|
2015-10-17 09:50:09 +03:00
|
|
|
// Consume the event explicitly.
|
|
|
|
aWheelEvent->PreventDefault();
|
2015-10-16 07:19:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsPluginFrame::WantsToHandleWheelEventAsDefaultAction() const
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (!mInstanceOwner) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
NPWindow* window = nullptr;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
// On Windows, only when the plugin is windowless, we need to send wheel
|
|
|
|
// events as default action.
|
|
|
|
return window->type == NPWindowTypeDrawable;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
nsresult
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aPluginInstance = nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2011-08-30 10:09:56 +04:00
|
|
|
if (!mInstanceOwner) {
|
2012-02-01 01:55:54 +04:00
|
|
|
return NS_OK;
|
2011-08-30 10:09:56 +04:00
|
|
|
}
|
|
|
|
|
2012-02-01 01:55:54 +04:00
|
|
|
return mInstanceOwner->GetInstance(aPluginInstance);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetCursor(const nsPoint& aPoint, nsIFrame::Cursor& aCursor)
|
2011-04-08 23:58:04 +04:00
|
|
|
{
|
|
|
|
if (!mInstanceOwner) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsNPAPIPluginInstance> inst;
|
2011-05-18 05:48:34 +04:00
|
|
|
mInstanceOwner->GetInstance(getter_AddRefs(inst));
|
2011-04-08 23:58:04 +04:00
|
|
|
if (!inst) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool useDOMCursor = static_cast<nsNPAPIPluginInstance*>(inst.get())->UsesDOMForCursor();
|
2011-04-08 23:58:04 +04:00
|
|
|
if (!useDOMCursor) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-04-18 09:01:57 +03:00
|
|
|
return nsFrame::GetCursor(aPoint, aCursor);
|
2011-04-08 23:58:04 +04:00
|
|
|
}
|
|
|
|
|
2011-08-19 00:08:38 +04:00
|
|
|
void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::SetIsDocumentActive(bool aIsActive)
|
2011-08-19 00:08:38 +04:00
|
|
|
{
|
|
|
|
if (mInstanceOwner) {
|
|
|
|
mInstanceOwner->UpdateDocumentActiveState(aIsActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 17:48:02 +03:00
|
|
|
// static
|
|
|
|
nsIObjectFrame *
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::GetNextObjectFrame(nsPresContext* aPresContext, nsIFrame* aRoot)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* child : aRoot->PrincipalChildList()) {
|
2010-11-08 17:48:02 +03:00
|
|
|
nsIObjectFrame* outFrame = do_QueryFrame(child);
|
|
|
|
if (outFrame) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsNPAPIPluginInstance> pi;
|
2011-05-18 05:48:34 +04:00
|
|
|
outFrame->GetPluginInstance(getter_AddRefs(pi)); // make sure we have a REAL plugin
|
2010-11-08 17:48:02 +03:00
|
|
|
if (pi)
|
|
|
|
return outFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
outFrame = GetNextObjectFrame(aPresContext, child);
|
|
|
|
if (outFrame)
|
|
|
|
return outFrame;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::BeginSwapDocShells(nsISupports* aSupports, void*)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2014-06-19 06:09:35 +04:00
|
|
|
NS_PRECONDITION(aSupports, "");
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aSupports));
|
|
|
|
if (!content) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// This function is called from a document content enumerator so we need
|
2014-09-24 08:34:00 +04:00
|
|
|
// to filter out the nsPluginFrames and ignore the rest.
|
2014-06-19 06:09:35 +04:00
|
|
|
nsIObjectFrame* obj = do_QueryFrame(content->GetPrimaryFrame());
|
2010-11-08 17:48:02 +03:00
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame* objectFrame = static_cast<nsPluginFrame*>(obj);
|
2010-11-08 17:48:02 +03:00
|
|
|
NS_ASSERTION(!objectFrame->mWidget || objectFrame->mWidget->GetParent(),
|
|
|
|
"Plugin windows must not be toplevel");
|
2012-08-17 08:25:19 +04:00
|
|
|
objectFrame->UnregisterPluginForGeometryUpdates();
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::EndSwapDocShells(nsISupports* aSupports, void*)
|
2010-11-08 17:48:02 +03:00
|
|
|
{
|
2014-06-19 06:09:35 +04:00
|
|
|
NS_PRECONDITION(aSupports, "");
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aSupports));
|
|
|
|
if (!content) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
|
|
|
|
// This function is called from a document content enumerator so we need
|
2014-09-24 08:34:00 +04:00
|
|
|
// to filter out the nsPluginFrames and ignore the rest.
|
2014-06-19 06:09:35 +04:00
|
|
|
nsIObjectFrame* obj = do_QueryFrame(content->GetPrimaryFrame());
|
2010-11-08 17:48:02 +03:00
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame* objectFrame = static_cast<nsPluginFrame*>(obj);
|
2010-11-08 17:48:02 +03:00
|
|
|
nsRootPresContext* rootPC = objectFrame->PresContext()->GetRootPresContext();
|
|
|
|
NS_ASSERTION(rootPC, "unable to register the plugin frame");
|
2012-07-06 04:45:23 +04:00
|
|
|
nsIWidget* widget = objectFrame->mWidget;
|
2010-11-08 17:48:02 +03:00
|
|
|
if (widget) {
|
|
|
|
// Reparent the widget.
|
|
|
|
nsIWidget* parent =
|
|
|
|
rootPC->PresShell()->GetRootFrame()->GetNearestWidget();
|
|
|
|
widget->SetParent(parent);
|
2013-02-28 23:16:03 +04:00
|
|
|
nsWeakFrame weakFrame(objectFrame);
|
2010-11-08 17:48:02 +03:00
|
|
|
objectFrame->CallSetWindow();
|
2013-02-28 23:16:03 +04:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
|
2016-03-18 03:57:53 +03:00
|
|
|
if (objectFrame->mInstanceOwner) {
|
|
|
|
objectFrame->RegisterPluginForGeometryUpdates();
|
|
|
|
}
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewObjectFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
2014-09-24 08:34:00 +04:00
|
|
|
return new (aPresShell) nsPluginFrame(aContext);
|
2010-11-08 17:48:02 +03:00
|
|
|
}
|
|
|
|
|
2012-03-23 22:21:57 +04:00
|
|
|
bool
|
2014-09-24 08:34:00 +04:00
|
|
|
nsPluginFrame::IsPaintedByGecko() const
|
2012-03-23 22:21:57 +04:00
|
|
|
{
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return !mWidget;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-24 08:34:00 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsPluginFrame)
|