2010-11-08 06:48:02 -08: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 04:12:37 -07: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 06:48:02 -08:00
|
|
|
|
|
|
|
/* rendering objects for replaced elements implemented by a plugin */
|
|
|
|
|
2013-09-24 18:43:43 -07:00
|
|
|
#include "nsObjectFrame.h"
|
|
|
|
|
2013-09-25 04:21:22 -07:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2013-08-22 11:32:52 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// This is needed for DoublePassRenderingEvent.
|
2010-11-08 06:48:02 -08:00
|
|
|
#include "mozilla/plugins/PluginMessageUtils.h"
|
2013-08-22 11:32:52 -07:00
|
|
|
#endif
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2013-01-03 05:23:11 -08:00
|
|
|
#include "nsView.h"
|
2013-01-04 19:12:24 -08:00
|
|
|
#include "nsViewManager.h"
|
2010-11-08 06:48:02 -08:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIPluginInstanceOwner.h"
|
2011-04-08 12:58:04 -07:00
|
|
|
#include "nsNPAPIPluginInstance.h"
|
2010-11-08 06:48:02 -08:00
|
|
|
#include "nsIDOMElement.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2010-11-08 06:48:02 -08: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 07:25:50 -07:00
|
|
|
#include "GeckoProfiler.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
#include "nsIObjectFrame.h"
|
|
|
|
#include "nsPluginNativeWindow.h"
|
2011-02-15 21:48:01 -08:00
|
|
|
#include "FrameLayerBuilder.h"
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
#include "ImageLayers.h"
|
2013-08-22 11:32:52 -07:00
|
|
|
#include "nsPluginInstanceOwner.h"
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "gfxWindowsNativeDrawing.h"
|
|
|
|
#include "gfxWindowsSurface.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Layers.h"
|
2011-02-16 14:43:30 -08:00
|
|
|
#include "ReadbackLayer.h"
|
2013-08-22 11:32:52 -07:00
|
|
|
#include "ImageContainer.h"
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
// accessibility support
|
|
|
|
#ifdef ACCESSIBILITY
|
2011-01-27 20:38:14 -08:00
|
|
|
#include "nsAccessibilityService.h"
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG 1 /* Allow logging in the release build */
|
|
|
|
#endif /* MOZ_LOGGING */
|
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "gfxQuartzNativeDrawing.h"
|
|
|
|
#include "nsPluginUtilsOSX.h"
|
2012-07-31 08:11:57 -07:00
|
|
|
#include "mozilla/gfx/QuartzSupport.h"
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "mozilla/X11Util.h"
|
|
|
|
using mozilla::DefaultXDisplay;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <wtypes.h>
|
|
|
|
#include <winuser.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_OS2
|
|
|
|
#define INCL_PM
|
|
|
|
#define INCL_GPI
|
|
|
|
#include <os2.h>
|
2011-04-25 10:59:07 -07:00
|
|
|
#include "gfxOS2Surface.h"
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
#include "AndroidBridge.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#endif
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
#ifdef CreateEvent // Thank you MS.
|
|
|
|
#undef CreateEvent
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
2012-10-29 16:32:10 -07:00
|
|
|
static PRLogModuleInfo *
|
|
|
|
GetObjectFrameLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sLog;
|
|
|
|
if (!sLog)
|
|
|
|
sLog = PR_NewLogModule("nsObjectFrame");
|
|
|
|
return sLog;
|
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif /* PR_LOGGING */
|
|
|
|
|
2012-10-15 05:38:34 -07:00
|
|
|
#if defined(XP_MACOSX) && !defined(__LP64__)
|
2011-06-11 00:12:58 -07:00
|
|
|
|
|
|
|
// The header files QuickdrawAPI.h and QDOffscreen.h are missing on OS X 10.7
|
|
|
|
// and up (though the QuickDraw APIs defined in them are still present) -- so
|
|
|
|
// we need to supply the relevant parts of their contents here. It's likely
|
|
|
|
// that Apple will eventually remove the APIs themselves (probably in OS X
|
|
|
|
// 10.8), so we need to make them weak imports, and test for their presence
|
|
|
|
// before using them.
|
|
|
|
extern "C" {
|
|
|
|
#if !defined(__QUICKDRAWAPI__)
|
|
|
|
extern void SetRect(
|
|
|
|
Rect * r,
|
|
|
|
short left,
|
|
|
|
short top,
|
|
|
|
short right,
|
|
|
|
short bottom)
|
|
|
|
__attribute__((weak_import));
|
|
|
|
#endif /* __QUICKDRAWAPI__ */
|
|
|
|
|
|
|
|
#if !defined(__QDOFFSCREEN__)
|
|
|
|
extern QDErr NewGWorldFromPtr(
|
|
|
|
GWorldPtr * offscreenGWorld,
|
|
|
|
UInt32 PixelFormat,
|
|
|
|
const Rect * boundsRect,
|
2013-10-08 11:47:21 -07:00
|
|
|
CTabHandle cTable, /* can be nullptr */
|
|
|
|
GDHandle aGDevice, /* can be nullptr */
|
2011-06-11 00:12:58 -07:00
|
|
|
GWorldFlags flags,
|
|
|
|
Ptr newBuffer,
|
|
|
|
SInt32 rowBytes)
|
|
|
|
__attribute__((weak_import));
|
|
|
|
extern void DisposeGWorld(GWorldPtr offscreenGWorld)
|
|
|
|
__attribute__((weak_import));
|
|
|
|
#endif /* __QDOFFSCREEN__ */
|
|
|
|
}
|
|
|
|
|
2012-10-15 05:38:34 -07:00
|
|
|
#endif /* #if defined(XP_MACOSX) && !defined(__LP64__) */
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
using namespace mozilla;
|
2010-11-08 06:48:02 -08:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
class PluginBackgroundSink : public ReadbackSink {
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
PluginBackgroundSink(nsObjectFrame* aFrame, uint64_t aStartSequenceNumber)
|
2011-02-16 14:43:30 -08:00
|
|
|
: mLastSequenceNumber(aStartSequenceNumber), mFrame(aFrame) {}
|
|
|
|
~PluginBackgroundSink()
|
|
|
|
{
|
|
|
|
if (mFrame) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrame->mBackgroundSink = nullptr;
|
2011-02-16 14:43:30 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual void SetUnknown(uint64_t aSequenceNumber)
|
2011-02-16 14:43:30 -08:00
|
|
|
{
|
|
|
|
if (!AcceptUpdate(aSequenceNumber))
|
|
|
|
return;
|
|
|
|
mFrame->mInstanceOwner->SetBackgroundUnknown();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual already_AddRefed<gfxContext>
|
2012-08-22 08:56:38 -07:00
|
|
|
BeginUpdate(const nsIntRect& aRect, uint64_t aSequenceNumber)
|
2011-02-16 14:43:30 -08:00
|
|
|
{
|
|
|
|
if (!AcceptUpdate(aSequenceNumber))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-02-16 14:43:30 -08:00
|
|
|
return mFrame->mInstanceOwner->BeginUpdateBackground(aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void EndUpdate(gfxContext* aContext, const nsIntRect& aRect)
|
|
|
|
{
|
|
|
|
return mFrame->mInstanceOwner->EndUpdateBackground(aContext, aRect);
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
void Destroy() { mFrame = nullptr; }
|
2011-02-16 14:43:30 -08:00
|
|
|
|
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
bool AcceptUpdate(uint64_t aSequenceNumber) {
|
2011-02-16 14:43:30 -08:00
|
|
|
if (aSequenceNumber > mLastSequenceNumber && mFrame &&
|
|
|
|
mFrame->mInstanceOwner) {
|
|
|
|
mLastSequenceNumber = aSequenceNumber;
|
2011-10-01 08:43:07 -07:00
|
|
|
return true;
|
2011-02-16 14:43:30 -08:00
|
|
|
}
|
2011-10-01 08:43:07 -07:00
|
|
|
return false;
|
2011-02-16 14:43:30 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mLastSequenceNumber;
|
2011-02-16 14:43:30 -08:00
|
|
|
nsObjectFrame* mFrame;
|
|
|
|
};
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
nsObjectFrame::nsObjectFrame(nsStyleContext* aContext)
|
|
|
|
: nsObjectFrameSuper(aContext)
|
2011-10-01 08:43:07 -07:00
|
|
|
, mReflowCallbackPosted(false)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetObjectFrameLog(), PR_LOG_DEBUG,
|
2010-11-08 06:48:02 -08:00
|
|
|
("Created new nsObjectFrame %p\n", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsObjectFrame::~nsObjectFrame()
|
|
|
|
{
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetObjectFrameLog(), PR_LOG_DEBUG,
|
2010-11-08 06:48:02 -08:00
|
|
|
("nsObjectFrame %p deleted\n", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_QUERYFRAME_HEAD(nsObjectFrame)
|
2012-09-28 14:53:44 -07:00
|
|
|
NS_QUERYFRAME_ENTRY(nsObjectFrame)
|
2010-11-08 06:48:02 -08:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIObjectFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsObjectFrameSuper)
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 14:53:44 -07:00
|
|
|
a11y::AccType
|
|
|
|
nsObjectFrame::AccessibleType()
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
2012-12-17 21:22:26 -08:00
|
|
|
return a11y::ePluginType;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
NS_IMETHODIMP nsObjectFrame::GetPluginPort(HWND *aPort)
|
|
|
|
{
|
|
|
|
*aPort = (HWND) mInstanceOwner->GetPluginPortFromWidget();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2010-11-08 06:48:02 -08:00
|
|
|
nsObjectFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetObjectFrameLog(), PR_LOG_DEBUG,
|
2010-11-08 06:48:02 -08:00
|
|
|
("Initializing nsObjectFrame %p for content %p\n", this, aContent));
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
nsObjectFrameSuper::Init(aContent, aParent, aPrevInFlow);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
|
|
{
|
2012-02-06 03:47:11 -08:00
|
|
|
if (mReflowCallbackPosted) {
|
|
|
|
PresContext()->PresShell()->CancelReflowCallback(this);
|
|
|
|
}
|
|
|
|
|
2012-01-31 13:55:54 -08: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-17 14:13:09 -07:00
|
|
|
|
2013-04-17 15:11:21 -07: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-17 14:13:09 -07:00
|
|
|
if (mInstanceOwner) {
|
|
|
|
mInstanceOwner->SetFrame(nullptr);
|
|
|
|
}
|
2012-09-06 17:16:02 -07:00
|
|
|
objContent->HasNewFrame(nullptr);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
if (mBackgroundSink) {
|
|
|
|
mBackgroundSink->Destroy();
|
|
|
|
}
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
nsObjectFrameSuper::DestroyFrom(aDestructRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsObjectFrame::DidSetStyleContext(nsStyleContext* aOldStyleContext)
|
|
|
|
{
|
|
|
|
if (HasView()) {
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = GetView();
|
2013-01-04 19:12:24 -08:00
|
|
|
nsViewManager* vm = view->GetViewManager();
|
2010-11-08 06:48:02 -08:00
|
|
|
if (vm) {
|
|
|
|
nsViewVisibility visibility =
|
|
|
|
IsHidden() ? nsViewVisibility_kHide : nsViewVisibility_kShow;
|
|
|
|
vm->SetViewVisibility(view, visibility);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsObjectFrameSuper::DidSetStyleContext(aOldStyleContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsObjectFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::objectFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("ObjectFrame"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
2012-01-31 13:55:54 -08:00
|
|
|
nsObjectFrame::PrepForDrawing(nsIWidget *aWidget)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
2012-01-31 13:55:54 -08:00
|
|
|
mWidget = aWidget;
|
|
|
|
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = GetView();
|
2010-11-08 06:48:02 -08:00
|
|
|
NS_ASSERTION(view, "Object frames must have views");
|
|
|
|
if (!view) {
|
2012-01-31 13:55:54 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2011-02-15 13:45:02 -08:00
|
|
|
}
|
|
|
|
|
2013-01-04 19:12:24 -08:00
|
|
|
nsViewManager* viewMan = view->GetViewManager();
|
2010-11-08 06:48:02 -08: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 05:23:11 -08:00
|
|
|
nsView* parentWithView;
|
2010-11-08 06:48:02 -08: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 06:03:23 -07:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
nsRootPresContext* rpc = presContext->GetRootPresContext();
|
2010-11-08 06:48:02 -08:00
|
|
|
if (!rpc) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-01-31 13:55:54 -08:00
|
|
|
if (mWidget) {
|
2012-10-06 06:03:23 -07:00
|
|
|
// Disallow windowed plugins in popups
|
2012-07-05 17:45:23 -07:00
|
|
|
nsIFrame* rootFrame = rpc->PresShell()->FrameManager()->GetRootFrame();
|
|
|
|
nsIWidget* parentWidget = rootFrame->GetNearestWidget();
|
|
|
|
if (!parentWidget || nsLayoutUtils::GetDisplayRootFrame(this) != rootFrame) {
|
2010-12-24 12:37:03 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-01-31 13:55:54 -08:00
|
|
|
}
|
2010-12-24 12:37:03 -08:00
|
|
|
|
2011-04-18 20:07:22 -07:00
|
|
|
mInnerView = viewMan->CreateView(GetContentRectRelativeToSelf(), view);
|
2010-11-08 06:48:02 -08:00
|
|
|
if (!mInnerView) {
|
|
|
|
NS_ERROR("Could not create inner view");
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
viewMan->InsertChild(view, mInnerView, nullptr, true);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2012-01-31 13:55:54 -08:00
|
|
|
mWidget->SetParent(parentWidget);
|
|
|
|
mWidget->Show(true);
|
|
|
|
mWidget->Enable(true);
|
|
|
|
|
2012-10-06 06:03:23 -07: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.
|
|
|
|
nsAutoTArray<nsIWidget::Configuration,1> configurations;
|
|
|
|
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-01-31 13:55:54 -08:00
|
|
|
|
2013-05-10 00:13:49 -07:00
|
|
|
nsRefPtr<nsDeviceContext> dx = viewMan->GetDeviceContext();
|
2012-08-15 11:53:09 -07:00
|
|
|
mInnerView->AttachWidgetEventHandler(mWidget);
|
2011-08-29 23:09:56 -07:00
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
#ifdef XP_MACOSX
|
2012-01-31 13:55:54 -08:00
|
|
|
// On Mac, we need to invalidate ourselves since even windowed
|
|
|
|
// plugins are painted through Thebes and we need to ensure
|
|
|
|
// the Thebes layer containing the plugin is updated.
|
|
|
|
if (parentWidget == GetNearestWidget()) {
|
2012-08-28 22:39:31 -07:00
|
|
|
InvalidateFrame();
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
2012-01-31 13:55:54 -08:00
|
|
|
#endif
|
2011-08-29 23:09:56 -07:00
|
|
|
|
2012-08-16 21:25:19 -07:00
|
|
|
RegisterPluginForGeometryUpdates();
|
2011-08-29 23:09:56 -07:00
|
|
|
|
2010-11-08 06:48:02 -08: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()) {
|
|
|
|
nscolor bgcolor =
|
2011-08-29 23:09:56 -07:00
|
|
|
frame->GetVisitedDependentColor(eCSSProperty_background_color);
|
2010-11-08 06:48:02 -08:00
|
|
|
if (NS_GET_A(bgcolor) > 0) { // make sure we got an actual color
|
|
|
|
mWidget->SetBackgroundColor(bgcolor);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-01-31 13:55:54 -08:00
|
|
|
// Changing to windowless mode changes the NPWindow geometry.
|
|
|
|
FixupWindow(GetContentRectRelativeToSelf().Size());
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
#ifndef XP_MACOSX
|
2012-08-16 21:25:19 -07:00
|
|
|
RegisterPluginForGeometryUpdates();
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsHidden()) {
|
|
|
|
viewMan->SetViewVisibility(view, nsViewVisibility_kShow);
|
|
|
|
}
|
|
|
|
|
2012-01-31 13:55:54 -08:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
|
|
|
if (accService) {
|
|
|
|
accService->RecreateAccessible(PresContext()->PresShell(), mContent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define EMBED_DEF_WIDTH 240
|
|
|
|
#define EMBED_DEF_HEIGHT 200
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsObjectFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
|
2011-10-01 08:43:07 -07:00
|
|
|
if (!IsHidden(false)) {
|
2010-11-08 06:48:02 -08:00
|
|
|
nsIAtom *atom = mContent->Tag();
|
|
|
|
if (atom == nsGkAtoms::applet || atom == nsGkAtoms::embed) {
|
|
|
|
result = nsPresContext::CSSPixelsToAppUnits(EMBED_DEF_WIDTH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsObjectFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
|
|
|
return nsObjectFrame::GetMinWidth(aRenderingContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::GetDesiredSize(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsHTMLReflowMetrics& aMetrics)
|
|
|
|
{
|
|
|
|
// By default, we have no area
|
|
|
|
aMetrics.width = 0;
|
|
|
|
aMetrics.height = 0;
|
|
|
|
|
2011-10-01 08:43:07 -07:00
|
|
|
if (IsHidden(false)) {
|
2010-11-08 06:48:02 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMetrics.width = aReflowState.ComputedWidth();
|
|
|
|
aMetrics.height = aReflowState.ComputedHeight();
|
|
|
|
|
|
|
|
// for EMBED and APPLET, default to 240x200 for compatibility
|
|
|
|
nsIAtom *atom = mContent->Tag();
|
|
|
|
if (atom == nsGkAtoms::applet || atom == nsGkAtoms::embed) {
|
|
|
|
if (aMetrics.width == NS_UNCONSTRAINEDSIZE) {
|
2011-10-28 11:33:28 -07:00
|
|
|
aMetrics.width = clamped(nsPresContext::CSSPixelsToAppUnits(EMBED_DEF_WIDTH),
|
|
|
|
aReflowState.mComputedMinWidth,
|
|
|
|
aReflowState.mComputedMaxWidth);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
if (aMetrics.height == NS_UNCONSTRAINEDSIZE) {
|
2011-10-28 11:33:28 -07:00
|
|
|
aMetrics.height = clamped(nsPresContext::CSSPixelsToAppUnits(EMBED_DEF_HEIGHT),
|
|
|
|
aReflowState.mComputedMinHeight,
|
|
|
|
aReflowState.mComputedMaxHeight);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2013-06-12 05:04:28 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2010-11-08 06:48:02 -08: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-01-15 04:22:03 -08:00
|
|
|
aMetrics.height = std::min(aPresContext->DevPixelsToAppUnits(INT16_MAX), aMetrics.height);
|
|
|
|
aMetrics.width = std::min(aPresContext->DevPixelsToAppUnits(INT16_MAX), aMetrics.width);
|
2010-11-08 06:48:02 -08: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.
|
|
|
|
if (aMetrics.width == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aMetrics.width =
|
|
|
|
(aReflowState.mComputedMinWidth != NS_UNCONSTRAINEDSIZE) ?
|
|
|
|
aReflowState.mComputedMinWidth : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (aMetrics.height == NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aMetrics.height =
|
|
|
|
(aReflowState.mComputedMinHeight != NS_UNCONSTRAINEDSIZE) ?
|
|
|
|
aReflowState.mComputedMinHeight : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsObjectFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
|
|
|
|
|
|
|
// Get our desired size
|
|
|
|
GetDesiredSize(aPresContext, aReflowState, aMetrics);
|
|
|
|
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;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we are printing or print previewing, bail for now
|
|
|
|
if (aPresContext->Medium() == nsGkAtoms::print) {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect r(0, 0, aMetrics.width, aMetrics.height);
|
|
|
|
r.Deflate(aReflowState.mComputedBorderPadding);
|
|
|
|
|
|
|
|
if (mInnerView) {
|
2013-01-04 19:12:24 -08:00
|
|
|
nsViewManager* vm = mInnerView->GetViewManager();
|
2010-11-08 06:48:02 -08:00
|
|
|
vm->MoveViewTo(mInnerView, r.x, r.y);
|
2011-10-01 08:43:07 -07:00
|
|
|
vm->ResizeView(mInnerView, nsRect(nsPoint(0, 0), r.Size()), true);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
FixupWindow(r.Size());
|
|
|
|
if (!mReflowCallbackPosted) {
|
2011-10-01 08:43:07 -07:00
|
|
|
mReflowCallbackPosted = true;
|
2010-11-08 06:48:02 -08:00
|
|
|
aPresContext->PresShell()->PostReflowCallback(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////// nsIReflowCallback ///////////////
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-11-08 06:48:02 -08:00
|
|
|
nsObjectFrame::ReflowFinished()
|
|
|
|
{
|
2011-10-01 08:43:07 -07:00
|
|
|
mReflowCallbackPosted = false;
|
2010-11-08 06:48:02 -08:00
|
|
|
CallSetWindow();
|
2011-10-01 08:43:07 -07:00
|
|
|
return true;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::ReflowCallbackCanceled()
|
|
|
|
{
|
2011-10-01 08:43:07 -07:00
|
|
|
mReflowCallbackPosted = false;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::FixupWindow(const nsSize& aSize)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
|
|
|
|
if (!mInstanceOwner)
|
|
|
|
return;
|
|
|
|
|
|
|
|
NPWindow *window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
|
2012-12-23 20:45:57 -08:00
|
|
|
NS_ENSURE_TRUE_VOID(window);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2011-10-27 13:00:49 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2011-05-31 21:37:54 -07:00
|
|
|
mInstanceOwner->FixUpPluginWindow(nsPluginInstanceOwner::ePluginPaintDisable);
|
2011-10-27 13:00:49 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool windowless = (window->type == NPWindowTypeDrawable);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
nsIntPoint origin = GetWindowOriginInPixels(windowless);
|
|
|
|
|
2012-10-02 12:48:05 -07:00
|
|
|
// window must be in "display pixels"
|
|
|
|
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;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
// on the Mac we need to set the clipRect to { 0, 0, 0, 0 } for now. This will keep
|
|
|
|
// us from drawing on screen until the widget is properly positioned, which will not
|
|
|
|
// happen until we have finished the reflow process.
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
window->clipRect.top = 0;
|
|
|
|
window->clipRect.left = 0;
|
|
|
|
window->clipRect.bottom = 0;
|
|
|
|
window->clipRect.right = 0;
|
|
|
|
#else
|
2011-10-01 08:43:07 -07:00
|
|
|
mInstanceOwner->UpdateWindowPositionAndClipRect(false);
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
NotifyPluginReflowObservers();
|
|
|
|
}
|
|
|
|
|
2010-12-07 13:18:50 -08:00
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsObjectFrame::CallSetWindow(bool aCheckIsHidden)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NPWindow *win = nullptr;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2010-12-07 13:18:50 -08:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2011-05-17 18:48:34 -07:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> pi;
|
2010-11-08 06:48:02 -08:00
|
|
|
if (!mInstanceOwner ||
|
2011-05-17 18:48:34 -07:00
|
|
|
NS_FAILED(rv = mInstanceOwner->GetInstance(getter_AddRefs(pi))) ||
|
2010-11-08 06:48:02 -08:00
|
|
|
!pi ||
|
|
|
|
NS_FAILED(rv = mInstanceOwner->GetWindow(win)) ||
|
|
|
|
!win)
|
2010-12-07 13:18:50 -08:00
|
|
|
return rv;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
nsPluginNativeWindow *window = (nsPluginNativeWindow *)win;
|
|
|
|
#ifdef XP_MACOSX
|
2011-10-27 13:00:49 -07:00
|
|
|
nsWeakFrame weakFrame(this);
|
2011-05-31 21:37:54 -07:00
|
|
|
mInstanceOwner->FixUpPluginWindow(nsPluginInstanceOwner::ePluginPaintDisable);
|
2011-10-27 13:00:49 -07:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
|
2010-12-20 11:49:37 -08:00
|
|
|
if (aCheckIsHidden && IsHidden())
|
2010-12-07 13:18:50 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
// refresh the plugin port as well
|
|
|
|
window->window = mInstanceOwner->GetPluginPortFromWidget();
|
|
|
|
|
|
|
|
// 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-07 13:18:50 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2010-11-08 06:48:02 -08:00
|
|
|
nsIFrame* rootFrame = rootPC->PresShell()->FrameManager()->GetRootFrame();
|
2011-04-18 20:07:22 -07:00
|
|
|
nsRect bounds = GetContentRectRelativeToSelf() + GetOffsetToCrossDoc(rootFrame);
|
2010-11-08 06:48:02 -08:00
|
|
|
nsIntRect intBounds = bounds.ToNearestPixels(appUnitsPerDevPixel);
|
2012-10-02 12:48:05 -07:00
|
|
|
|
|
|
|
// window must be in "display pixels"
|
|
|
|
double scaleFactor = 1.0;
|
|
|
|
if (NS_FAILED(mInstanceOwner->GetContentsScaleFactor(&scaleFactor))) {
|
|
|
|
scaleFactor = 1.0;
|
|
|
|
}
|
|
|
|
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;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2011-11-01 11:52:20 -07:00
|
|
|
// Calling SetWindow might destroy this frame. We need to use the instance
|
|
|
|
// owner to clean up so hold a ref.
|
|
|
|
nsRefPtr<nsPluginInstanceOwner> instanceOwnerRef(mInstanceOwner);
|
|
|
|
|
|
|
|
// 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.
|
2011-02-12 08:09:03 -08:00
|
|
|
if (mInstanceOwner->UseAsyncRendering()) {
|
2010-12-07 13:18:50 -08:00
|
|
|
rv = pi->AsyncSetWindow(window);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
else {
|
2010-12-07 13:18:50 -08:00
|
|
|
rv = window->CallSetWindow(pi);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2011-11-01 11:52:20 -07:00
|
|
|
instanceOwnerRef->ReleasePluginPort(window->window);
|
|
|
|
|
2010-12-07 13:18:50 -08:00
|
|
|
return rv;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2012-08-16 21:25:19 -07:00
|
|
|
void
|
|
|
|
nsObjectFrame::RegisterPluginForGeometryUpdates()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
nsObjectFrame::UnregisterPluginForGeometryUpdates()
|
|
|
|
{
|
|
|
|
if (!mRootPresContextRegisteredWith) {
|
|
|
|
// Not registered...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRootPresContextRegisteredWith->UnregisterPluginForGeometryUpdates(mContent);
|
|
|
|
mRootPresContextRegisteredWith = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-01-31 13:55:54 -08:00
|
|
|
void
|
|
|
|
nsObjectFrame::SetInstanceOwner(nsPluginInstanceOwner* aOwner)
|
|
|
|
{
|
2013-04-17 15:11:21 -07: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-01-31 13:55:54 -08:00
|
|
|
mInstanceOwner = aOwner;
|
2012-08-13 21:06:44 -07:00
|
|
|
if (mInstanceOwner) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-16 21:25:19 -07:00
|
|
|
UnregisterPluginForGeometryUpdates();
|
2012-08-13 21:06:44 -07: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 06:03:23 -07:00
|
|
|
nsIWidget::Configuration* configuration = configurations.AppendElement();
|
|
|
|
configuration->mChild = mWidget;
|
2012-08-13 21:06:44 -07:00
|
|
|
parent->ConfigureChildren(configurations);
|
|
|
|
|
|
|
|
mWidget->Show(false);
|
|
|
|
mWidget->Enable(false);
|
|
|
|
mWidget->SetParent(nullptr);
|
2012-01-31 13:55:54 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsObjectFrame::IsFocusable(int32_t *aTabIndex, bool aWithMouse)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
|
|
|
if (aTabIndex)
|
|
|
|
*aTabIndex = -1;
|
|
|
|
return nsObjectFrameSuper::IsFocusable(aTabIndex, aWithMouse);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsObjectFrame::IsHidden(bool aCheckVisibilityStyle) const
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
|
|
|
if (aCheckVisibilityStyle) {
|
2013-02-16 13:51:02 -08:00
|
|
|
if (!StyleVisibility()->IsVisibleOrCollapsed())
|
2011-10-01 08:43:07 -07:00
|
|
|
return true;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// only <embed> tags support the HIDDEN attribute
|
|
|
|
if (mContent->Tag() == nsGkAtoms::embed) {
|
|
|
|
// 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 08:43:07 -07:00
|
|
|
return true;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-01 08:43:07 -07:00
|
|
|
return false;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsIntPoint nsObjectFrame::GetWindowOriginInPixels(bool aWindowless)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView * parentWithView;
|
2010-11-08 06:48:02 -08: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-18 20:07:22 -07:00
|
|
|
origin += GetContentRectRelativeToSelf().TopLeft();
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
return nsIntPoint(PresContext()->AppUnitsToDevPixels(origin.x),
|
|
|
|
PresContext()->AppUnitsToDevPixels(origin.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::DidReflow(nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState* aReflowState,
|
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
|
|
|
// Do this check before calling the superclass, as that clears
|
|
|
|
// NS_FRAME_FIRST_REFLOW
|
2012-11-13 22:47:33 -08:00
|
|
|
if (aStatus == nsDidReflowStatus::FINISHED &&
|
2010-11-08 06:48:02 -08:00
|
|
|
(GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
nsCOMPtr<nsIObjectLoadingContent> objContent(do_QueryInterface(mContent));
|
|
|
|
NS_ASSERTION(objContent, "Why not an object loading content?");
|
|
|
|
objContent->HasNewFrame(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = nsObjectFrameSuper::DidReflow(aPresContext, aReflowState, aStatus);
|
|
|
|
|
|
|
|
// The view is created hidden; once we have reflowed it and it has been
|
|
|
|
// positioned then we show it.
|
2013-04-17 15:11:21 -07:00
|
|
|
if (aStatus != nsDidReflowStatus::FINISHED)
|
2010-11-08 06:48:02 -08:00
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (HasView()) {
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = GetView();
|
2013-01-04 19:12:24 -08:00
|
|
|
nsViewManager* vm = view->GetViewManager();
|
2010-11-08 06:48:02 -08:00
|
|
|
if (vm)
|
|
|
|
vm->SetViewVisibility(view, IsHidden() ? nsViewVisibility_kHide : nsViewVisibility_kShow);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsObjectFrame::PaintPrintPlugin(nsIFrame* aFrame, nsRenderingContext* aCtx,
|
2010-11-08 06:48:02 -08:00
|
|
|
const nsRect& aDirtyRect, nsPoint aPt)
|
|
|
|
{
|
2011-04-18 20:07:22 -07:00
|
|
|
nsPoint pt = aPt + aFrame->GetContentRectRelativeToSelf().TopLeft();
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext::AutoPushTranslation translate(aCtx, pt);
|
2010-11-08 06:48:02 -08:00
|
|
|
// FIXME - Bug 385435: Doesn't aDirtyRect need translating too?
|
|
|
|
static_cast<nsObjectFrame*>(aFrame)->PrintPlugin(*aCtx, aDirtyRect);
|
|
|
|
}
|
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
class nsDisplayPluginReadback : public nsDisplayItem {
|
|
|
|
public:
|
|
|
|
nsDisplayPluginReadback(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsDisplayPluginReadback);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayPluginReadback() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayPluginReadback);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-10 04:24:18 -07:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap);
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-02-16 14:43:30 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion);
|
2011-02-16 14:43:30 -08:00
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("PluginReadback", TYPE_PLUGIN_READBACK)
|
|
|
|
|
|
|
|
virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 05:11:27 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters)
|
2011-02-16 14:43:30 -08:00
|
|
|
{
|
2012-09-16 15:25:33 -07:00
|
|
|
return static_cast<nsObjectFrame*>(mFrame)->BuildLayer(aBuilder, aManager, this, aContainerParameters);
|
2010-12-19 17:37:43 -08:00
|
|
|
}
|
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 07:05:55 -07:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters)
|
2011-02-16 14:43:30 -08:00
|
|
|
{
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static nsRect
|
2011-02-22 21:38:09 -08:00
|
|
|
GetDisplayItemBounds(nsDisplayListBuilder* aBuilder, nsDisplayItem* aItem, nsIFrame* aFrame)
|
2011-02-16 14:43:30 -08:00
|
|
|
{
|
2011-02-22 21:38:09 -08:00
|
|
|
// XXX For slightly more accurate region computations we should pixel-snap this
|
2011-04-18 20:07:22 -07:00
|
|
|
return aFrame->GetContentRectRelativeToSelf() + aItem->ToReferenceFrame();
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
nsRect
|
2012-04-10 04:24:18 -07:00
|
|
|
nsDisplayPluginReadback::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2011-02-16 14:43:30 -08:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2011-02-22 21:38:09 -08:00
|
|
|
return GetDisplayItemBounds(aBuilder, this, mFrame);
|
2011-02-16 14:43:30 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-02-16 14:43:30 -08:00
|
|
|
nsDisplayPluginReadback::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2011-02-16 14:43:30 -08:00
|
|
|
{
|
2011-02-16 14:43:30 -08:00
|
|
|
if (!nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion))
|
2011-10-01 08:43:07 -07:00
|
|
|
return false;
|
2011-02-16 14:43:30 -08:00
|
|
|
|
|
|
|
nsRect expand;
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
|
|
|
expand.IntersectRect(aAllowVisibleRegionExpansion, GetBounds(aBuilder, &snap));
|
2011-02-16 14:43:30 -08:00
|
|
|
// *Add* our bounds to the visible region so that stuff underneath us is
|
|
|
|
// likely to be made visible, so we can use it for a background! This is
|
|
|
|
// a bit crazy since we normally only subtract from the visible region.
|
2011-02-16 14:43:30 -08:00
|
|
|
aVisibleRegion->Or(*aVisibleRegion, expand);
|
2011-10-01 08:43:07 -07:00
|
|
|
return true;
|
2011-02-16 14:43:30 -08:00
|
|
|
}
|
|
|
|
|
2012-07-20 12:20:51 -07: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
|
|
|
|
|
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap);
|
|
|
|
virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion);
|
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("PluginVideo", TYPE_PLUGIN_VIDEO)
|
|
|
|
|
|
|
|
virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters)
|
|
|
|
{
|
2012-09-16 15:25:33 -07:00
|
|
|
return static_cast<nsObjectFrame*>(mFrame)->BuildLayer(aBuilder, aManager, this, aContainerParameters);
|
2012-07-20 12:20:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aParameters)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDisplayPluginVideo::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
|
|
|
{
|
|
|
|
return nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
|
|
|
aAllowVisibleRegionExpansion);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
nsRect
|
2012-04-10 04:24:18 -07:00
|
|
|
nsDisplayPlugin::GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2011-02-16 14:43:30 -08:00
|
|
|
{
|
2012-11-13 11:56:47 -08:00
|
|
|
*aSnap = true;
|
2011-02-22 21:38:09 -08:00
|
|
|
return GetDisplayItemBounds(aBuilder, this, mFrame);
|
2011-02-16 14:43:30 -08:00
|
|
|
}
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
void
|
|
|
|
nsDisplayPlugin::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
|
|
|
nsObjectFrame* f = static_cast<nsObjectFrame*>(mFrame);
|
2012-04-10 04:24:18 -07:00
|
|
|
bool snap;
|
|
|
|
f->PaintPlugin(aBuilder, *aCtx, mVisibleRect, GetBounds(aBuilder, &snap));
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-11-08 06:48:02 -08:00
|
|
|
nsDisplayPlugin::ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2011-01-27 14:58:50 -08:00
|
|
|
nsRegion* aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
2012-10-06 06:03:23 -07:00
|
|
|
if (aBuilder->IsForPluginGeometry()) {
|
|
|
|
nsObjectFrame* f = static_cast<nsObjectFrame*>(mFrame);
|
|
|
|
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();
|
|
|
|
f->mNextConfigurationBounds = rAncestor.ToNearestPixels(appUnitsPerDevPixel);
|
|
|
|
|
|
|
|
nsRegion visibleRegion;
|
2013-04-05 01:30:34 -07:00
|
|
|
visibleRegion.And(*aVisibleRegion, GetClippedBounds(aBuilder));
|
2012-10-06 06:03:23 -07:00
|
|
|
// Make visibleRegion relative to f
|
|
|
|
visibleRegion.MoveBy(-ToReferenceFrame());
|
|
|
|
|
|
|
|
f->mNextConfigurationClipRegion.Clear();
|
|
|
|
nsRegionRectIterator iter(visibleRegion);
|
|
|
|
for (const nsRect* r = iter.Next(); r; r = iter.Next()) {
|
|
|
|
nsRect rAncestor =
|
|
|
|
nsLayoutUtils::TransformFrameRectToAncestor(f, *r, ReferenceFrame());
|
|
|
|
nsIntRect rPixels = rAncestor.ToNearestPixels(appUnitsPerDevPixel)
|
|
|
|
- f->mNextConfigurationBounds.TopLeft();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 14:58:50 -08:00
|
|
|
return nsDisplayItem::ComputeVisibility(aBuilder, aVisibleRegion,
|
2011-05-13 09:40:46 -07:00
|
|
|
aAllowVisibleRegionExpansion);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion
|
|
|
|
nsDisplayPlugin::GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-02 21:29:05 -07:00
|
|
|
bool* aSnap)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = false;
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion result;
|
2010-11-08 06:48:02 -08:00
|
|
|
nsObjectFrame* f = static_cast<nsObjectFrame*>(mFrame);
|
2010-11-08 01:06:14 -08:00
|
|
|
if (!aBuilder->IsForPluginGeometry()) {
|
|
|
|
nsIWidget* widget = f->GetWidget();
|
|
|
|
if (widget) {
|
2012-10-06 06:03:23 -07: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
|
|
|
|
// in ThebesLayers there.
|
|
|
|
return result;
|
2010-11-08 01:06:14 -08:00
|
|
|
}
|
|
|
|
}
|
2012-10-06 06:03:23 -07:00
|
|
|
|
2012-04-10 04:24:18 -07: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-02 17:48:09 -08:00
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2012-10-06 06:03:23 -07:00
|
|
|
return result;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsObjectFrame::PluginEventNotifier::Run() {
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
mozilla::services::GetObserverService();
|
2012-07-30 07:20:58 -07:00
|
|
|
obsSvc->NotifyObservers(nullptr, "plugin-changed-event", mEventType.get());
|
2010-11-08 06:48:02 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::NotifyPluginReflowObservers()
|
|
|
|
{
|
|
|
|
nsContentUtils::AddScriptRunner(new PluginEventNotifier(NS_LITERAL_STRING("reflow")));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::DidSetWidgetGeometry()
|
|
|
|
{
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
if (mInstanceOwner) {
|
2011-05-31 21:37:54 -07:00
|
|
|
mInstanceOwner->FixUpPluginWindow(nsPluginInstanceOwner::ePluginPaintEnable);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
2012-10-06 06:03:23 -07:00
|
|
|
#else
|
|
|
|
if (!mWidget && mInstanceOwner) {
|
|
|
|
// UpdateWindowVisibility will notify the plugin of position changes
|
|
|
|
// by updating the NPWindow and calling NPP_SetWindow/AsyncSetWindow.
|
2012-11-27 05:18:39 -08: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 06:03:23 -07:00
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-11-08 06:48:02 -08:00
|
|
|
nsObjectFrame::IsOpaque() const
|
|
|
|
{
|
|
|
|
#if defined(XP_MACOSX)
|
2011-02-16 14:43:30 -08:00
|
|
|
// ???
|
2011-10-01 08:43:07 -07:00
|
|
|
return false;
|
2012-07-20 12:20:51 -07:00
|
|
|
#elif defined(MOZ_WIDGET_ANDROID)
|
|
|
|
// We don't know, so just assume transparent
|
|
|
|
return false;
|
2011-02-16 14:43:30 -08:00
|
|
|
#else
|
|
|
|
return !IsTransparentMode();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-02-16 14:43:30 -08:00
|
|
|
nsObjectFrame::IsTransparentMode() const
|
|
|
|
{
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// ???
|
2011-10-01 08:43:07 -07:00
|
|
|
return false;
|
2010-11-08 06:48:02 -08:00
|
|
|
#else
|
|
|
|
if (!mInstanceOwner)
|
2011-10-01 08:43:07 -07:00
|
|
|
return false;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NPWindow *window = nullptr;
|
2010-11-08 06:48:02 -08:00
|
|
|
mInstanceOwner->GetWindow(window);
|
2012-02-02 14:55:25 -08:00
|
|
|
if (!window) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
if (window->type != NPWindowTypeDrawable)
|
2011-10-01 08:43:07 -07:00
|
|
|
return false;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
nsresult rv;
|
2011-05-17 18:48:34 -07:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> pi;
|
|
|
|
rv = mInstanceOwner->GetInstance(getter_AddRefs(pi));
|
2010-11-08 06:48:02 -08:00
|
|
|
if (NS_FAILED(rv) || !pi)
|
2011-10-01 08:43:07 -07:00
|
|
|
return false;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool transparent = false;
|
2010-11-08 06:48:02 -08:00
|
|
|
pi->IsTransparent(&transparent);
|
2011-02-16 14:43:30 -08:00
|
|
|
return transparent;
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2010-11-08 06:48:02 -08:00
|
|
|
nsObjectFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// XXX why are we painting collapsed object frames?
|
|
|
|
if (!IsVisibleOrCollapsedForPainting(aBuilder))
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2011-02-16 14:43:30 -08:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
nsPresContext::nsPresContextType type = PresContext()->Type();
|
|
|
|
|
|
|
|
// If we are painting in Print Preview do nothing....
|
|
|
|
if (type == nsPresContext::eContext_PrintPreview)
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsObjectFrame");
|
|
|
|
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
if (mWidget && aBuilder->IsInTransform()) {
|
|
|
|
// Windowed plugins should not be rendered inside a transform.
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-02-12 08:09:03 -08:00
|
|
|
if (aBuilder->IsForPainting() && mInstanceOwner && mInstanceOwner->UseAsyncRendering()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
NPWindow* window = nullptr;
|
2010-12-19 17:37:43 -08:00
|
|
|
mInstanceOwner->GetWindow(window);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isVisible = window && window->width > 0 && window->height > 0;
|
2011-01-13 05:20:53 -08:00
|
|
|
if (isVisible && aBuilder->ShouldSyncDecodeImages()) {
|
2010-12-19 17:37:43 -08:00
|
|
|
#ifndef XP_MACOSX
|
2011-10-01 08:43:07 -07:00
|
|
|
mInstanceOwner->UpdateWindowVisibility(true);
|
2010-12-19 17:37:43 -08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-10-30 19:53:37 -07:00
|
|
|
mInstanceOwner->NotifyPaintWaiter(aBuilder);
|
2010-12-19 17:37:43 -08:00
|
|
|
}
|
|
|
|
|
2013-03-04 01:56:02 -08:00
|
|
|
DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox
|
|
|
|
clip(aBuilder, this, DisplayListClipState::ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT);
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
// determine if we are printing
|
|
|
|
if (type == nsPresContext::eContext_Print) {
|
2013-03-04 01:56:02 -08:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 03:08:08 -08:00
|
|
|
nsDisplayGeneric(aBuilder, this, PaintPrintPlugin, "PrintPlugin",
|
|
|
|
nsDisplayItem::TYPE_PRINT_PLUGIN));
|
2010-11-08 06:48:02 -08:00
|
|
|
} else {
|
2012-11-22 15:29:05 -08:00
|
|
|
LayerState state = GetLayerState(aBuilder, nullptr);
|
|
|
|
if (state == LAYER_INACTIVE &&
|
|
|
|
nsDisplayItem::ForceActiveLayers()) {
|
|
|
|
state = LAYER_ACTIVE;
|
|
|
|
}
|
2012-07-20 12:20:51 -07:00
|
|
|
// We don't need this on Android, and it just confuses things
|
|
|
|
#if !MOZ_WIDGET_ANDROID
|
2011-02-16 14:43:30 -08:00
|
|
|
if (aBuilder->IsPaintingToWindow() &&
|
2012-11-22 15:29:05 -08:00
|
|
|
state == LAYER_ACTIVE &&
|
2011-02-16 14:43:30 -08:00
|
|
|
IsTransparentMode()) {
|
2013-03-04 01:56:02 -08:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 03:08:08 -08:00
|
|
|
nsDisplayPluginReadback(aBuilder, this));
|
2011-02-16 14:43:30 -08:00
|
|
|
}
|
2012-07-20 12:20:51 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MOZ_WIDGET_ANDROID
|
|
|
|
if (aBuilder->IsPaintingToWindow() &&
|
2012-11-22 15:29:05 -08:00
|
|
|
state == LAYER_ACTIVE) {
|
2012-07-20 12:20:51 -07:00
|
|
|
|
|
|
|
nsTArray<nsNPAPIPluginInstance::VideoInfo*> videos;
|
|
|
|
mInstanceOwner->GetVideos(videos);
|
2012-10-14 13:56:03 -07:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < videos.Length(); i++) {
|
2013-03-04 01:56:02 -08:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2012-07-20 12:20:51 -07:00
|
|
|
nsDisplayPluginVideo(aBuilder, this, videos[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2011-02-16 14:43:30 -08:00
|
|
|
|
2013-03-04 01:56:02 -08:00
|
|
|
aLists.Content()->AppendNewToTop(new (aBuilder)
|
2013-02-14 03:08:08 -08:00
|
|
|
nsDisplayPlugin(aBuilder, this));
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
#ifdef XP_OS2
|
|
|
|
static void *
|
2011-04-25 10:59:07 -07:00
|
|
|
GetPSFromRC(nsRenderingContext& aRenderingContext)
|
2011-04-07 18:04:40 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<gfxASurface>
|
|
|
|
surf = aRenderingContext.ThebesContext()->CurrentSurface();
|
|
|
|
if (!surf || surf->CairoStatus())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-04-07 18:04:40 -07:00
|
|
|
return (void *)(static_cast<gfxOS2Surface*>
|
|
|
|
(static_cast<gfxASurface*>(surf.get()))->GetPS());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsObjectFrame::PrintPlugin(nsRenderingContext& aRenderingContext,
|
2010-11-08 06:48:02 -08:00
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObjectLoadingContent> obj(do_QueryInterface(mContent));
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsIFrame* frame = nullptr;
|
2010-11-08 06:48:02 -08: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
|
2011-05-17 18:48:34 -07:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> pi;
|
|
|
|
if (NS_FAILED(objectFrame->GetPluginInstance(getter_AddRefs(pi))) || !pi)
|
2010-11-08 06:48:02 -08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// now we need to setup the correct location for printing
|
|
|
|
NPWindow window;
|
2012-07-30 07:20:58 -07:00
|
|
|
window.window = nullptr;
|
2010-11-08 06:48:02 -08: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-28 23:19:26 -07:00
|
|
|
bool windowless = false;
|
2010-11-08 06:48:02 -08: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-14 18:28:23 -07:00
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
// platform specific printing code
|
2012-10-15 05:38:34 -07:00
|
|
|
#if defined(XP_MACOSX) && !defined(__LP64__)
|
2012-10-14 18:28:23 -07:00
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
2011-06-11 00:12:58 -07:00
|
|
|
// Don't use this code if any of the QuickDraw APIs it currently requires
|
|
|
|
// are missing (as they probably will be on OS X 10.8 and up).
|
2012-10-14 18:28:23 -07:00
|
|
|
if (!&::SetRect || !&::NewGWorldFromPtr || !&::DisposeGWorld) {
|
2011-06-11 00:12:58 -07:00
|
|
|
NS_WARNING("Cannot print plugin -- required QuickDraw APIs are missing!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-18 20:07:22 -07:00
|
|
|
nsSize contentSize = GetContentRectRelativeToSelf().Size();
|
2010-11-08 06:48:02 -08:00
|
|
|
window.x = 0;
|
|
|
|
window.y = 0;
|
|
|
|
window.width = presContext->AppUnitsToDevPixels(contentSize.width);
|
|
|
|
window.height = presContext->AppUnitsToDevPixels(contentSize.height);
|
|
|
|
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
gfxContextAutoSaveRestore save(ctx);
|
|
|
|
|
|
|
|
ctx->NewPath();
|
|
|
|
|
|
|
|
gfxRect rect(window.x, window.y, window.width, window.height);
|
|
|
|
|
|
|
|
ctx->Rectangle(rect);
|
|
|
|
ctx->Clip();
|
|
|
|
|
|
|
|
gfxQuartzNativeDrawing nativeDraw(ctx, rect);
|
|
|
|
CGContextRef cgContext = nativeDraw.BeginNativeDrawing();
|
|
|
|
if (!cgContext) {
|
|
|
|
nativeDraw.EndNativeDrawing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.clipRect.right = window.width;
|
|
|
|
window.clipRect.bottom = window.height;
|
|
|
|
window.type = NPWindowTypeDrawable;
|
|
|
|
|
2011-04-18 20:07:48 -07:00
|
|
|
::Rect gwBounds;
|
2010-11-08 06:48:02 -08:00
|
|
|
::SetRect(&gwBounds, 0, 0, window.width, window.height);
|
|
|
|
|
|
|
|
nsTArray<char> buffer(window.width * window.height * 4);
|
|
|
|
CGColorSpaceRef cspace = ::CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
|
|
|
|
if (!cspace) {
|
|
|
|
nativeDraw.EndNativeDrawing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
CGContextRef cgBuffer =
|
|
|
|
::CGBitmapContextCreate(buffer.Elements(),
|
|
|
|
window.width, window.height, 8, window.width * 4,
|
|
|
|
cspace, kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedFirst);
|
|
|
|
::CGColorSpaceRelease(cspace);
|
|
|
|
if (!cgBuffer) {
|
|
|
|
nativeDraw.EndNativeDrawing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GWorldPtr gWorld;
|
2013-10-08 11:47:21 -07:00
|
|
|
if (::NewGWorldFromPtr(&gWorld, k32ARGBPixelFormat, &gwBounds,
|
|
|
|
nullptr, nullptr, 0,
|
2010-11-08 06:48:02 -08:00
|
|
|
buffer.Elements(), window.width * 4) != noErr) {
|
|
|
|
::CGContextRelease(cgBuffer);
|
|
|
|
nativeDraw.EndNativeDrawing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.clipRect.right = window.width;
|
|
|
|
window.clipRect.bottom = window.height;
|
|
|
|
window.type = NPWindowTypeDrawable;
|
|
|
|
// Setting nsPluginPrint/NPPrint.print.embedPrint.window.window to
|
|
|
|
// &GWorldPtr and nsPluginPrint/NPPrint.print.embedPrint.platformPrint to
|
|
|
|
// GWorldPtr isn't any kind of standard (it's not documented anywhere).
|
|
|
|
// But that's what WebKit does. And it's what the Flash plugin (apparently
|
|
|
|
// the only NPAPI plugin on OS X to support printing) seems to expect. So
|
|
|
|
// we do the same. The Flash plugin uses the CoreGraphics drawing mode.
|
|
|
|
// But a GWorldPtr should be usable in either CoreGraphics or QuickDraw
|
|
|
|
// drawing mode. See bug 191046.
|
|
|
|
window.window = &gWorld;
|
|
|
|
npprint.print.embedPrint.platformPrint = gWorld;
|
|
|
|
npprint.print.embedPrint.window = window;
|
2011-06-21 08:37:47 -07:00
|
|
|
pi->Print(&npprint);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
::CGContextTranslateCTM(cgContext, 0.0f, float(window.height));
|
|
|
|
::CGContextScaleCTM(cgContext, 1.0f, -1.0f);
|
|
|
|
CGImageRef image = ::CGBitmapContextCreateImage(cgBuffer);
|
|
|
|
if (!image) {
|
|
|
|
::CGContextRestoreGState(cgContext);
|
|
|
|
::CGContextRelease(cgBuffer);
|
|
|
|
::DisposeGWorld(gWorld);
|
|
|
|
nativeDraw.EndNativeDrawing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
::CGContextDrawImage(cgContext,
|
|
|
|
::CGRectMake(0, 0, window.width, window.height),
|
|
|
|
image);
|
|
|
|
::CGImageRelease(image);
|
|
|
|
::CGContextRelease(cgBuffer);
|
|
|
|
|
|
|
|
::DisposeGWorld(gWorld);
|
|
|
|
|
|
|
|
nativeDraw.EndNativeDrawing();
|
2012-10-14 18:28:23 -07:00
|
|
|
#pragma clang diagnostic warning "-Wdeprecated-declarations"
|
2010-11-08 06:48:02 -08:00
|
|
|
#elif defined(XP_UNIX)
|
|
|
|
|
|
|
|
/* XXX this just flat-out doesn't work in a thebes world --
|
|
|
|
* RenderEPS is a no-op. So don't bother to do any work here.
|
|
|
|
*/
|
2011-12-19 19:46:39 -08:00
|
|
|
(void)window;
|
|
|
|
(void)npprint;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
#elif defined(XP_OS2)
|
2011-04-07 18:04:40 -07:00
|
|
|
void *hps = GetPSFromRC(aRenderingContext);
|
2010-11-08 06:48:02 -08:00
|
|
|
if (!hps)
|
|
|
|
return;
|
|
|
|
|
|
|
|
npprint.print.embedPrint.platformPrint = hps;
|
|
|
|
npprint.print.embedPrint.window = window;
|
|
|
|
// send off print info to plugin
|
|
|
|
pi->Print(&npprint);
|
|
|
|
#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-18 20:07:22 -07:00
|
|
|
nsSize contentSize = GetContentRectRelativeToSelf().Size();
|
2010-11-08 06:48:02 -08: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-13 22:47:33 -08:00
|
|
|
nsDidReflowStatus status = nsDidReflowStatus::FINISHED; // should we use a special status?
|
2010-11-08 06:48:02 -08:00
|
|
|
frame->DidReflow(presContext,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, status); // DidReflow will take care of it
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2011-02-22 21:38:09 -08:00
|
|
|
nsRect
|
|
|
|
nsObjectFrame::GetPaintedRect(nsDisplayPlugin* aItem)
|
|
|
|
{
|
|
|
|
if (!mInstanceOwner)
|
|
|
|
return nsRect();
|
2011-04-18 20:07:22 -07:00
|
|
|
nsRect r = GetContentRectRelativeToSelf();
|
2011-02-22 21:38:09 -08: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
|
2010-11-08 06:48:02 -08:00
|
|
|
nsObjectFrame::GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager)
|
|
|
|
{
|
2011-02-12 08:09:03 -08:00
|
|
|
if (!mInstanceOwner)
|
2011-02-22 21:38:09 -08:00
|
|
|
return LAYER_NONE;
|
2011-02-12 08:09:03 -08:00
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// We always want a layer on Honeycomb and later
|
|
|
|
if (AndroidBridge::Bridge()->GetAPIVersion() >= 11)
|
|
|
|
return LAYER_ACTIVE;
|
|
|
|
#endif
|
|
|
|
|
2011-06-30 09:46:26 -07:00
|
|
|
if (!mInstanceOwner->UseAsyncRendering()) {
|
2011-02-22 21:38:09 -08:00
|
|
|
return LAYER_NONE;
|
2011-06-30 09:46:26 -07:00
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2011-02-22 21:38:09 -08:00
|
|
|
return LAYER_ACTIVE;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsObjectFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
2012-09-16 15:25:33 -07:00
|
|
|
nsDisplayItem* aItem,
|
|
|
|
const ContainerParameters& aContainerParameters)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
|
|
|
if (!mInstanceOwner)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NPWindow* window = nullptr;
|
2010-11-08 06:48:02 -08:00
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
if (!window)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
if (window->width <= 0 || window->height <= 0)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2012-10-02 12:48:05 -07:00
|
|
|
// window is in "display pixels", but size needs to be in device pixels
|
|
|
|
double scaleFactor = 1.0;
|
|
|
|
if (NS_FAILED(mInstanceOwner->GetContentsScaleFactor(&scaleFactor))) {
|
|
|
|
scaleFactor = 1.0;
|
|
|
|
}
|
|
|
|
int intScaleFactor = ceil(scaleFactor);
|
|
|
|
gfxIntSize size(window->width * intScaleFactor, window->height * intScaleFactor);
|
2011-02-16 14:43:30 -08:00
|
|
|
|
2011-04-18 20:07:22 -07:00
|
|
|
nsRect area = GetContentRectRelativeToSelf() + aItem->ToReferenceFrame();
|
2010-11-08 06:48:02 -08:00
|
|
|
gfxRect r = nsLayoutUtils::RectToGfxRect(area, PresContext()->AppUnitsPerDevPixel());
|
|
|
|
// to provide crisper and faster drawing.
|
|
|
|
r.Round();
|
|
|
|
nsRefPtr<Layer> layer =
|
2012-08-28 22:47:15 -07:00
|
|
|
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, aItem));
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
if (aItem->GetType() == nsDisplayItem::TYPE_PLUGIN) {
|
2012-11-07 13:15:27 -08:00
|
|
|
// Create image
|
|
|
|
nsRefPtr<ImageContainer> container = mInstanceOwner->GetImageContainer();
|
|
|
|
if (!container) {
|
|
|
|
// This can occur if our instance is gone.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
if (!layer) {
|
2011-02-12 08:09:03 -08:00
|
|
|
mInstanceOwner->NotifyPaintWaiter(aBuilder);
|
2011-02-16 14:43:30 -08:00
|
|
|
// Initialize ImageLayer
|
|
|
|
layer = aManager->CreateImageLayer();
|
|
|
|
if (!layer)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-02-12 08:09:03 -08:00
|
|
|
}
|
|
|
|
|
2012-10-30 19:54:06 -07:00
|
|
|
NS_ASSERTION(layer->GetType() == Layer::TYPE_IMAGE, "Bad layer type");
|
2011-02-16 14:43:30 -08:00
|
|
|
ImageLayer* imglayer = static_cast<ImageLayer*>(layer.get());
|
2013-04-16 19:21:06 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (!mInstanceOwner->UseAsyncRendering()) {
|
|
|
|
mInstanceOwner->DoCocoaEventDrawRect(r, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
2011-02-16 19:56:06 -08:00
|
|
|
|
2013-08-20 12:45:30 -07:00
|
|
|
imglayer->SetScaleToSize(size, SCALE_STRETCH);
|
2011-02-16 14:43:30 -08:00
|
|
|
imglayer->SetContainer(container);
|
2013-10-01 14:01:19 -07:00
|
|
|
GraphicsFilter filter =
|
2011-09-19 04:12:16 -07:00
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this);
|
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
if (!aManager->IsCompositingCheap()) {
|
|
|
|
// Pixman just horrible with bilinear filter scaling
|
2013-10-01 14:01:19 -07:00
|
|
|
filter = GraphicsFilter::FILTER_NEAREST;
|
2011-09-19 04:12:16 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
imglayer->SetFilter(filter);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
layer->SetContentFlags(IsOpaque() ? Layer::CONTENT_OPAQUE : 0);
|
2012-07-20 12:20:51 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
} else if (aItem->GetType() == nsDisplayItem::TYPE_PLUGIN_VIDEO) {
|
|
|
|
nsDisplayPluginVideo* videoItem = reinterpret_cast<nsDisplayPluginVideo*>(aItem);
|
|
|
|
nsNPAPIPluginInstance::VideoInfo* videoInfo = videoItem->VideoInfo();
|
|
|
|
|
|
|
|
nsRefPtr<ImageContainer> container = mInstanceOwner->GetImageContainerForVideo(videoInfo);
|
|
|
|
if (!container)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-07-20 12:20:51 -07:00
|
|
|
|
|
|
|
if (!layer) {
|
|
|
|
// Initialize ImageLayer
|
|
|
|
layer = aManager->CreateImageLayer();
|
|
|
|
if (!layer)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-07-20 12:20:51 -07: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-16 14:43:30 -08:00
|
|
|
} else {
|
|
|
|
NS_ASSERTION(aItem->GetType() == nsDisplayItem::TYPE_PLUGIN_READBACK,
|
|
|
|
"Unknown item type");
|
|
|
|
NS_ABORT_IF_FALSE(!IsOpaque(), "Opaque plugins don't use backgrounds");
|
|
|
|
|
|
|
|
if (!layer) {
|
|
|
|
layer = aManager->CreateReadbackLayer();
|
|
|
|
if (!layer)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-02-16 14:43:30 -08:00
|
|
|
}
|
|
|
|
NS_ASSERTION(layer->GetType() == Layer::TYPE_READBACK, "Bad layer type");
|
|
|
|
|
|
|
|
ReadbackLayer* readback = static_cast<ReadbackLayer*>(layer.get());
|
|
|
|
if (readback->GetSize() != nsIntSize(size.width, size.height)) {
|
|
|
|
// This will destroy any old background sink and notify us that the
|
|
|
|
// background is now unknown
|
2012-07-30 07:20:58 -07:00
|
|
|
readback->SetSink(nullptr);
|
2011-02-16 14:43:30 -08:00
|
|
|
readback->SetSize(nsIntSize(size.width, size.height));
|
|
|
|
|
2011-03-01 04:54:37 -08: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-16 14:43:30 -08: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 06:48:02 -08:00
|
|
|
|
|
|
|
// Set a transform on the layer to draw the plugin in the right place
|
|
|
|
gfxMatrix transform;
|
2012-09-16 15:25:33 -07:00
|
|
|
transform.Translate(r.TopLeft() + aContainerParameters.mOffset);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2012-07-30 19:20:00 -07:00
|
|
|
layer->SetBaseTransform(gfx3DMatrix::From2D(transform));
|
2011-02-22 21:38:09 -08:00
|
|
|
layer->SetVisibleRegion(nsIntRect(0, 0, size.width, size.height));
|
2011-02-16 14:43:30 -08:00
|
|
|
return layer.forget();
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsObjectFrame::PaintPlugin(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext& aRenderingContext,
|
2010-11-08 06:48:02 -08:00
|
|
|
const nsRect& aDirtyRect, const nsRect& aPluginRect)
|
|
|
|
{
|
2011-11-10 16:17:46 -08:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2011-09-16 14:34:31 -07:00
|
|
|
if (mInstanceOwner) {
|
|
|
|
gfxRect frameGfxRect =
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aPluginRect);
|
|
|
|
gfxRect dirtyGfxRect =
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aDirtyRect);
|
2012-01-18 07:41:35 -08:00
|
|
|
|
2012-03-12 10:03:54 -07:00
|
|
|
gfxContext* ctx = aRenderingContext.ThebesContext();
|
2012-01-18 07:41:35 -08:00
|
|
|
|
2012-03-12 10:03:54 -07:00
|
|
|
mInstanceOwner->Paint(ctx, frameGfxRect, dirtyGfxRect);
|
2011-09-16 14:34:31 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
// Screen painting code
|
|
|
|
#if defined(XP_MACOSX)
|
|
|
|
// delegate all painting to the plugin instance.
|
|
|
|
if (mInstanceOwner) {
|
|
|
|
if (mInstanceOwner->GetDrawingModel() == NPDrawingModelCoreGraphics ||
|
|
|
|
mInstanceOwner->GetDrawingModel() == NPDrawingModelCoreAnimation ||
|
|
|
|
mInstanceOwner->GetDrawingModel() ==
|
|
|
|
NPDrawingModelInvalidatingCoreAnimation) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
|
2010-11-08 06:48:02 -08:00
|
|
|
// Clip to the content area where the plugin should be drawn. If
|
|
|
|
// we don't do this, the plugin can draw outside its bounds.
|
|
|
|
nsIntRect contentPixels = aPluginRect.ToNearestPixels(appUnitsPerDevPixel);
|
|
|
|
nsIntRect dirtyPixels = aDirtyRect.ToOutsidePixels(appUnitsPerDevPixel);
|
|
|
|
nsIntRect clipPixels;
|
|
|
|
clipPixels.IntersectRect(contentPixels, dirtyPixels);
|
|
|
|
|
|
|
|
// Don't invoke the drawing code if the clip is empty.
|
|
|
|
if (clipPixels.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
gfxRect nativeClipRect(clipPixels.x, clipPixels.y,
|
|
|
|
clipPixels.width, clipPixels.height);
|
|
|
|
gfxContext* ctx = aRenderingContext.ThebesContext();
|
|
|
|
|
|
|
|
gfxContextAutoSaveRestore save(ctx);
|
|
|
|
ctx->NewPath();
|
|
|
|
ctx->Rectangle(nativeClipRect);
|
|
|
|
ctx->Clip();
|
|
|
|
gfxPoint offset(contentPixels.x, contentPixels.y);
|
|
|
|
ctx->Translate(offset);
|
|
|
|
|
|
|
|
gfxQuartzNativeDrawing nativeDrawing(ctx, nativeClipRect - offset);
|
|
|
|
|
|
|
|
CGContextRef cgContext = nativeDrawing.BeginNativeDrawing();
|
|
|
|
if (!cgContext) {
|
|
|
|
NS_WARNING("null CGContextRef during PaintPlugin");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-17 18:48:34 -07:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> inst;
|
|
|
|
GetPluginInstance(getter_AddRefs(inst));
|
2010-11-08 06:48:02 -08:00
|
|
|
if (!inst) {
|
|
|
|
NS_WARNING("null plugin instance during PaintPlugin");
|
|
|
|
nativeDrawing.EndNativeDrawing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NPWindow* window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
if (!window) {
|
|
|
|
NS_WARNING("null plugin window during PaintPlugin");
|
|
|
|
nativeDrawing.EndNativeDrawing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NP_CGContext* cgPluginPortCopy =
|
|
|
|
static_cast<NP_CGContext*>(mInstanceOwner->GetPluginPortCopy());
|
|
|
|
if (!cgPluginPortCopy) {
|
|
|
|
NS_WARNING("null plugin port copy during PaintPlugin");
|
|
|
|
nativeDrawing.EndNativeDrawing();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInstanceOwner->BeginCGPaint();
|
|
|
|
if (mInstanceOwner->GetDrawingModel() == NPDrawingModelCoreAnimation ||
|
|
|
|
mInstanceOwner->GetDrawingModel() ==
|
|
|
|
NPDrawingModelInvalidatingCoreAnimation) {
|
|
|
|
// CoreAnimation is updated, render the layer and perform a readback.
|
|
|
|
mInstanceOwner->RenderCoreAnimation(cgContext, window->width, window->height);
|
|
|
|
} else {
|
|
|
|
mInstanceOwner->Paint(nativeClipRect - offset, cgContext);
|
|
|
|
}
|
|
|
|
mInstanceOwner->EndCGPaint();
|
|
|
|
|
|
|
|
nativeDrawing.EndNativeDrawing();
|
|
|
|
} else {
|
|
|
|
// FIXME - Bug 385435: Doesn't aDirtyRect need translating too?
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext::AutoPushTranslation
|
2011-04-07 18:04:39 -07:00
|
|
|
translate(&aRenderingContext, aPluginRect.TopLeft());
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
// this rect is used only in the CoreGraphics drawing model
|
|
|
|
gfxRect tmpRect(0, 0, 0, 0);
|
2013-10-08 11:47:21 -07:00
|
|
|
mInstanceOwner->Paint(tmpRect, nullptr);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(MOZ_X11)
|
|
|
|
if (mInstanceOwner) {
|
|
|
|
NPWindow *window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
if (window->type == NPWindowTypeDrawable) {
|
|
|
|
gfxRect frameGfxRect =
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aPluginRect);
|
|
|
|
gfxRect dirtyGfxRect =
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aDirtyRect);
|
|
|
|
gfxContext* ctx = aRenderingContext.ThebesContext();
|
|
|
|
|
|
|
|
mInstanceOwner->Paint(ctx, frameGfxRect, dirtyGfxRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(XP_WIN)
|
2011-05-17 18:48:34 -07:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> inst;
|
|
|
|
GetPluginInstance(getter_AddRefs(inst));
|
2010-11-08 06:48:02 -08:00
|
|
|
if (inst) {
|
|
|
|
gfxRect frameGfxRect =
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aPluginRect);
|
|
|
|
gfxRect dirtyGfxRect =
|
|
|
|
PresContext()->AppUnitsToGfxUnits(aDirtyRect);
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
|
|
|
gfxMatrix currentMatrix = ctx->CurrentMatrix();
|
|
|
|
|
2011-10-01 08:43:07 -07:00
|
|
|
if (ctx->UserToDevicePixelSnapped(frameGfxRect, false)) {
|
2010-11-08 06:48:02 -08:00
|
|
|
dirtyGfxRect = ctx->UserToDevice(dirtyGfxRect);
|
|
|
|
ctx->IdentityMatrix();
|
|
|
|
}
|
|
|
|
dirtyGfxRect.RoundOut();
|
|
|
|
|
|
|
|
// Look if it's windowless
|
|
|
|
NPWindow *window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
|
|
|
|
if (window->type == NPWindowTypeDrawable) {
|
|
|
|
// the offset of the DC
|
|
|
|
nsPoint origin;
|
|
|
|
|
|
|
|
gfxWindowsNativeDrawing nativeDraw(ctx, frameGfxRect);
|
|
|
|
if (nativeDraw.IsDoublePass()) {
|
|
|
|
// OOP plugin specific: let the shim know before we paint if we are doing a
|
|
|
|
// double pass render. If this plugin isn't oop, the register window message
|
|
|
|
// will be ignored.
|
|
|
|
NPEvent pluginEvent;
|
2013-10-22 06:27:36 -07:00
|
|
|
pluginEvent.event = plugins::DoublePassRenderingEvent();
|
2010-11-08 06:48:02 -08:00
|
|
|
pluginEvent.wParam = 0;
|
|
|
|
pluginEvent.lParam = 0;
|
|
|
|
if (pluginEvent.event)
|
2012-07-30 07:20:58 -07:00
|
|
|
inst->HandleEvent(&pluginEvent, nullptr);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
do {
|
|
|
|
HDC hdc = nativeDraw.BeginNativeDrawing();
|
|
|
|
if (!hdc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RECT dest;
|
|
|
|
nativeDraw.TransformToNativeRect(frameGfxRect, dest);
|
|
|
|
RECT dirty;
|
|
|
|
nativeDraw.TransformToNativeRect(dirtyGfxRect, dirty);
|
|
|
|
|
2010-11-10 05:19:53 -08:00
|
|
|
window->window = hdc;
|
|
|
|
window->x = dest.left;
|
|
|
|
window->y = dest.top;
|
|
|
|
window->clipRect.left = 0;
|
|
|
|
window->clipRect.top = 0;
|
|
|
|
// if we're painting, we're visible.
|
|
|
|
window->clipRect.right = window->width;
|
|
|
|
window->clipRect.bottom = window->height;
|
|
|
|
|
|
|
|
// Windowless plugins on windows need a special event to update their location,
|
|
|
|
// see bug 135737.
|
|
|
|
//
|
|
|
|
// bug 271442: note, the rectangle we send is now purely the bounds of the plugin
|
|
|
|
// relative to the window it is contained in, which is useful for the plugin to
|
|
|
|
// correctly translate mouse coordinates.
|
|
|
|
//
|
|
|
|
// this does not mesh with the comments for bug 135737 which imply that the rectangle
|
|
|
|
// must be clipped in some way to prevent the plugin attempting to paint over areas
|
|
|
|
// it shouldn't.
|
|
|
|
//
|
|
|
|
// since the two uses of the rectangle are mutually exclusive in some cases, and
|
|
|
|
// since I don't see any incorrect painting (at least with Flash and ViewPoint -
|
|
|
|
// the originator of bug 135737), it seems that windowless plugins are not relying
|
|
|
|
// on information here for clipping their drawing, and we can safely use this message
|
|
|
|
// to tell the plugin exactly where it is in all cases.
|
|
|
|
|
2011-10-01 08:43:07 -07:00
|
|
|
nsIntPoint origin = GetWindowOriginInPixels(true);
|
2010-11-10 05:19:53 -08:00
|
|
|
nsIntRect winlessRect = nsIntRect(origin, nsIntSize(window->width, window->height));
|
|
|
|
|
2011-04-18 20:07:23 -07:00
|
|
|
if (!mWindowlessRect.IsEqualEdges(winlessRect)) {
|
2010-11-09 06:36:33 -08:00
|
|
|
mWindowlessRect = winlessRect;
|
|
|
|
|
|
|
|
WINDOWPOS winpos;
|
|
|
|
memset(&winpos, 0, sizeof(winpos));
|
|
|
|
winpos.x = mWindowlessRect.x;
|
|
|
|
winpos.y = mWindowlessRect.y;
|
|
|
|
winpos.cx = mWindowlessRect.width;
|
|
|
|
winpos.cy = mWindowlessRect.height;
|
|
|
|
|
|
|
|
// finally, update the plugin by sending it a WM_WINDOWPOSCHANGED event
|
|
|
|
NPEvent pluginEvent;
|
|
|
|
pluginEvent.event = WM_WINDOWPOSCHANGED;
|
|
|
|
pluginEvent.wParam = 0;
|
|
|
|
pluginEvent.lParam = (LPARAM)&winpos;
|
2012-07-30 07:20:58 -07:00
|
|
|
inst->HandleEvent(&pluginEvent, nullptr);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
2010-11-10 05:19:53 -08:00
|
|
|
|
|
|
|
inst->SetWindow(window);
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
mInstanceOwner->Paint(dirty, hdc);
|
|
|
|
nativeDraw.EndNativeDrawing();
|
|
|
|
} while (nativeDraw.ShouldRenderAgain());
|
|
|
|
nativeDraw.PaintToContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->SetMatrix(currentMatrix);
|
|
|
|
}
|
|
|
|
#elif defined(XP_OS2)
|
2011-05-17 18:48:34 -07:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> inst;
|
|
|
|
GetPluginInstance(getter_AddRefs(inst));
|
2010-11-08 06:48:02 -08:00
|
|
|
if (inst) {
|
|
|
|
// Look if it's windowless
|
|
|
|
NPWindow *window;
|
|
|
|
mInstanceOwner->GetWindow(window);
|
|
|
|
|
|
|
|
if (window->type == NPWindowTypeDrawable) {
|
|
|
|
// FIXME - Bug 385435: Doesn't aDirtyRect need translating too?
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext::AutoPushTranslation
|
2011-04-07 18:04:39 -07:00
|
|
|
translate(&aRenderingContext, aPluginRect.TopLeft());
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
// check if we need to call SetWindow with updated parameters
|
2011-09-28 23:19:26 -07:00
|
|
|
bool doupdatewindow = false;
|
2010-11-08 06:48:02 -08:00
|
|
|
// the offset of the DC
|
|
|
|
nsIntPoint origin;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Layout now has an optimized way of painting. Now we always get
|
|
|
|
* a new drawing surface, sized to be just what's needed. Windowless
|
|
|
|
* plugins need a transform applied to their origin so they paint
|
|
|
|
* in the right place. Since |SetWindow| is no longer being used
|
|
|
|
* to tell the plugin where it is, we dispatch a NPWindow through
|
|
|
|
* |HandleEvent| to tell the plugin when its window moved
|
|
|
|
*/
|
|
|
|
gfxContext *ctx = aRenderingContext.ThebesContext();
|
|
|
|
|
|
|
|
gfxMatrix ctxMatrix = ctx->CurrentMatrix();
|
|
|
|
if (ctxMatrix.HasNonTranslation()) {
|
|
|
|
// soo; in the future, we should be able to render
|
|
|
|
// the object content to an offscreen DC, and then
|
|
|
|
// composite it in with the right transforms.
|
|
|
|
|
|
|
|
// But, we don't bother doing that, because we don't
|
|
|
|
// have the event handling story figured out yet.
|
|
|
|
// Instead, let's just bail.
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-11 03:37:52 -08:00
|
|
|
origin.x = NSToIntRound(ctxMatrix.GetTranslation().x);
|
|
|
|
origin.y = NSToIntRound(ctxMatrix.GetTranslation().y);
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
/* Need to force the clip to be set */
|
|
|
|
ctx->UpdateSurfaceClip();
|
|
|
|
|
|
|
|
/* Set the device offsets as appropriate, for whatever our current group offsets might be */
|
|
|
|
gfxFloat xoff, yoff;
|
|
|
|
nsRefPtr<gfxASurface> surf = ctx->CurrentSurface(&xoff, &yoff);
|
|
|
|
|
|
|
|
if (surf->CairoStatus() != 0) {
|
|
|
|
NS_WARNING("Plugin is being asked to render to a surface that's in error!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we need to update the PS
|
2011-04-07 18:04:40 -07:00
|
|
|
HPS hps = (HPS)GetPSFromRC(aRenderingContext);
|
2010-11-08 06:48:02 -08:00
|
|
|
if (reinterpret_cast<HPS>(window->window) != hps) {
|
|
|
|
window->window = reinterpret_cast<void*>(hps);
|
2011-10-01 08:43:07 -07:00
|
|
|
doupdatewindow = true;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
LONG lPSid = GpiSavePS(hps);
|
|
|
|
RECTL rclViewport;
|
|
|
|
if (GpiQueryDevice(hps) != NULLHANDLE) { // ensure that we have an associated HDC
|
|
|
|
if (GpiQueryPageViewport(hps, &rclViewport)) {
|
|
|
|
rclViewport.xLeft += (LONG)xoff;
|
|
|
|
rclViewport.xRight += (LONG)xoff;
|
|
|
|
rclViewport.yBottom += (LONG)yoff;
|
|
|
|
rclViewport.yTop += (LONG)yoff;
|
|
|
|
GpiSetPageViewport(hps, &rclViewport);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((window->x != origin.x) || (window->y != origin.y)) {
|
|
|
|
window->x = origin.x;
|
|
|
|
window->y = origin.y;
|
2011-10-01 08:43:07 -07:00
|
|
|
doupdatewindow = true;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// if our location or visible area has changed, we need to tell the plugin
|
|
|
|
if (doupdatewindow) {
|
|
|
|
inst->SetWindow(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
mInstanceOwner->Paint(aDirtyRect, hps);
|
|
|
|
if (lPSid >= 1) {
|
|
|
|
GpiRestorePS(hps, lPSid);
|
|
|
|
}
|
|
|
|
surf->MarkDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::HandleEvent(nsPresContext* aPresContext,
|
2013-10-01 20:46:03 -07:00
|
|
|
WidgetGUIEvent* anEvent,
|
|
|
|
nsEventStatus* anEventStatus)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(anEvent);
|
|
|
|
NS_ENSURE_ARG_POINTER(anEventStatus);
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mInstanceOwner)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
mInstanceOwner->ConsiderNewEventloopNestingLevel();
|
|
|
|
|
|
|
|
if (anEvent->message == NS_PLUGIN_ACTIVATE) {
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(GetContent());
|
|
|
|
if (fm && elem)
|
|
|
|
return fm->SetFocus(elem, 0);
|
|
|
|
}
|
2010-11-15 13:12:50 -08:00
|
|
|
else if (anEvent->message == NS_PLUGIN_FOCUS) {
|
2011-03-25 08:03:33 -07:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2010-11-15 13:12:50 -08:00
|
|
|
if (fm)
|
|
|
|
return fm->FocusPlugin(GetContent());
|
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2012-10-16 12:41:21 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (anEvent->message == NS_PLUGIN_RESOLUTION_CHANGED) {
|
|
|
|
double scaleFactor = 1.0;
|
|
|
|
mInstanceOwner->GetContentsScaleFactor(&scaleFactor);
|
|
|
|
mInstanceOwner->ContentsScaleFactorChanged(scaleFactor);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
if (mInstanceOwner->SendNativeEvents() &&
|
2013-09-24 03:04:16 -07:00
|
|
|
anEvent->IsNativeEventDelivererForPlugin()) {
|
2010-11-08 06:48:02 -08:00
|
|
|
*anEventStatus = mInstanceOwner->ProcessEvent(*anEvent);
|
2013-02-27 03:50:27 -08:00
|
|
|
// Due to plugin code reentering Gecko, this frame may be dead at this
|
|
|
|
// point.
|
2010-11-08 06:48:02 -08:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
rv = nsObjectFrameSuper::HandleEvent(aPresContext, anEvent, anEventStatus);
|
|
|
|
return rv;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// we want to process some native mouse events in the cocoa event model
|
2012-08-11 18:42:36 -07:00
|
|
|
if ((anEvent->message == NS_MOUSE_ENTER ||
|
|
|
|
anEvent->message == NS_WHEEL_WHEEL) &&
|
2010-11-08 06:48:02 -08:00
|
|
|
mInstanceOwner->GetEventModel() == NPEventModelCocoa) {
|
|
|
|
*anEventStatus = mInstanceOwner->ProcessEvent(*anEvent);
|
2013-02-27 03:50:27 -08:00
|
|
|
// Due to plugin code reentering Gecko, this frame may be dead at this
|
|
|
|
// point.
|
2010-11-08 06:48:02 -08:00
|
|
|
return rv;
|
|
|
|
}
|
2013-09-17 16:36:03 -07: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.
|
|
|
|
if (anEvent->message == NS_MOUSE_BUTTON_DOWN) {
|
|
|
|
nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
|
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
|
2013-09-17 16:36:03 -07:00
|
|
|
rv = nsObjectFrameSuper::HandleEvent(aPresContext, anEvent, anEventStatus);
|
|
|
|
|
|
|
|
// We need to be careful from this point because the call to
|
|
|
|
// nsObjectFrameSuper::HandleEvent() might have killed us.
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
2013-09-17 16:36:03 -07:00
|
|
|
if (anEvent->message == NS_MOUSE_BUTTON_UP) {
|
|
|
|
nsIPresShell::SetCapturingContent(nullptr, 0);
|
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
#endif
|
|
|
|
|
2013-09-17 16:36:03 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
nsresult
|
2011-05-17 18:48:34 -07:00
|
|
|
nsObjectFrame::GetPluginInstance(nsNPAPIPluginInstance** aPluginInstance)
|
2010-11-08 06:48:02 -08:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aPluginInstance = nullptr;
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2011-08-29 23:09:56 -07:00
|
|
|
if (!mInstanceOwner) {
|
2012-01-31 13:55:54 -08:00
|
|
|
return NS_OK;
|
2011-08-29 23:09:56 -07:00
|
|
|
}
|
|
|
|
|
2012-01-31 13:55:54 -08:00
|
|
|
return mInstanceOwner->GetInstance(aPluginInstance);
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
2011-04-08 12:58:04 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsObjectFrame::GetCursor(const nsPoint& aPoint, nsIFrame::Cursor& aCursor)
|
|
|
|
{
|
|
|
|
if (!mInstanceOwner) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-05-17 18:48:34 -07:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> inst;
|
|
|
|
mInstanceOwner->GetInstance(getter_AddRefs(inst));
|
2011-04-08 12:58:04 -07:00
|
|
|
if (!inst) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool useDOMCursor = static_cast<nsNPAPIPluginInstance*>(inst.get())->UsesDOMForCursor();
|
2011-04-08 12:58:04 -07:00
|
|
|
if (!useDOMCursor) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsObjectFrameSuper::GetCursor(aPoint, aCursor);
|
|
|
|
}
|
|
|
|
|
2011-08-18 13:08:38 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsObjectFrame::SetIsDocumentActive(bool aIsActive)
|
2011-08-18 13:08:38 -07:00
|
|
|
{
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
if (mInstanceOwner) {
|
|
|
|
mInstanceOwner->UpdateDocumentActiveState(aIsActive);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
// static
|
|
|
|
nsIObjectFrame *
|
|
|
|
nsObjectFrame::GetNextObjectFrame(nsPresContext* aPresContext, nsIFrame* aRoot)
|
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* child = aRoot->GetFirstPrincipalChild();
|
2010-11-08 06:48:02 -08:00
|
|
|
|
|
|
|
while (child) {
|
|
|
|
nsIObjectFrame* outFrame = do_QueryFrame(child);
|
|
|
|
if (outFrame) {
|
2011-05-17 18:48:34 -07:00
|
|
|
nsRefPtr<nsNPAPIPluginInstance> pi;
|
|
|
|
outFrame->GetPluginInstance(getter_AddRefs(pi)); // make sure we have a REAL plugin
|
2010-11-08 06:48:02 -08:00
|
|
|
if (pi)
|
|
|
|
return outFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
outFrame = GetNextObjectFrame(aPresContext, child);
|
|
|
|
if (outFrame)
|
|
|
|
return outFrame;
|
|
|
|
child = child->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
nsObjectFrame::BeginSwapDocShells(nsIContent* aContent, void*)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aContent, "");
|
|
|
|
|
|
|
|
// This function is called from a document content enumerator so we need
|
|
|
|
// to filter out the nsObjectFrames and ignore the rest.
|
|
|
|
nsIObjectFrame* obj = do_QueryFrame(aContent->GetPrimaryFrame());
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsObjectFrame* objectFrame = static_cast<nsObjectFrame*>(obj);
|
|
|
|
NS_ASSERTION(!objectFrame->mWidget || objectFrame->mWidget->GetParent(),
|
|
|
|
"Plugin windows must not be toplevel");
|
2012-08-16 21:25:19 -07:00
|
|
|
objectFrame->UnregisterPluginForGeometryUpdates();
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
nsObjectFrame::EndSwapDocShells(nsIContent* aContent, void*)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aContent, "");
|
|
|
|
|
|
|
|
// This function is called from a document content enumerator so we need
|
|
|
|
// to filter out the nsObjectFrames and ignore the rest.
|
|
|
|
nsIObjectFrame* obj = do_QueryFrame(aContent->GetPrimaryFrame());
|
|
|
|
if (!obj)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsObjectFrame* objectFrame = static_cast<nsObjectFrame*>(obj);
|
|
|
|
nsRootPresContext* rootPC = objectFrame->PresContext()->GetRootPresContext();
|
|
|
|
NS_ASSERTION(rootPC, "unable to register the plugin frame");
|
2012-07-05 17:45:23 -07:00
|
|
|
nsIWidget* widget = objectFrame->mWidget;
|
2010-11-08 06:48:02 -08:00
|
|
|
if (widget) {
|
|
|
|
// Reparent the widget.
|
|
|
|
nsIWidget* parent =
|
|
|
|
rootPC->PresShell()->GetRootFrame()->GetNearestWidget();
|
|
|
|
widget->SetParent(parent);
|
2013-02-28 11:16:03 -08:00
|
|
|
nsWeakFrame weakFrame(objectFrame);
|
2010-11-08 06:48:02 -08:00
|
|
|
objectFrame->CallSetWindow();
|
2013-02-28 11:16:03 -08:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-11-08 06:48:02 -08:00
|
|
|
|
2013-02-28 11:16:03 -08:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (objectFrame->mWidget) {
|
2012-08-16 21:25:19 -07:00
|
|
|
objectFrame->RegisterPluginForGeometryUpdates();
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
2013-02-28 11:16:03 -08:00
|
|
|
#else
|
|
|
|
objectFrame->RegisterPluginForGeometryUpdates();
|
|
|
|
#endif
|
2010-11-08 06:48:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewObjectFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsObjectFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2012-03-23 11:21:57 -07:00
|
|
|
bool
|
2012-10-06 06:03:23 -07:00
|
|
|
nsObjectFrame::IsPaintedByGecko() const
|
2012-03-23 11:21:57 -07:00
|
|
|
{
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return !mWidget;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-11-08 06:48:02 -08:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsObjectFrame)
|