1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "PluginWidgetProxy.h"
6 #include "mozilla/dom/TabChild.h"
7 #include "mozilla/plugins/PluginWidgetChild.h"
11 // #define PWLOG(...) printf_stderr(__VA_ARGS__)
14 already_AddRefed
<nsIWidget
>
15 nsIWidget::CreatePluginProxyWidget(TabChild
* aTabChild
,
16 mozilla::plugins::PluginWidgetChild
* aActor
)
18 nsCOMPtr
<nsIWidget
> widget
=
19 new mozilla::widget::PluginWidgetProxy(aTabChild
, aActor
);
20 return widget
.forget();
26 NS_IMPL_ISUPPORTS_INHERITED(PluginWidgetProxy
, PuppetWidget
, nsIWidget
)
28 #define ENSURE_CHANNEL do { \
30 NS_WARNING("called on an invalid channel."); \
31 return NS_ERROR_FAILURE; \
35 PluginWidgetProxy::PluginWidgetProxy(dom::TabChild
* aTabChild
,
36 mozilla::plugins::PluginWidgetChild
* aActor
) :
37 PuppetWidget(aTabChild
),
40 // See ChannelDestroyed() in the header
41 mActor
->mWidget
= this;
44 PluginWidgetProxy::~PluginWidgetProxy()
46 PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
50 PluginWidgetProxy::Create(nsIWidget
* aParent
,
51 nsNativeWidget aNativeParent
,
52 const nsIntRect
& aRect
,
53 nsDeviceContext
* aContext
,
54 nsWidgetInitData
* aInitData
)
57 PWLOG("PluginWidgetProxy::Create()\n");
59 if (!mActor
->SendCreate()) {
60 NS_WARNING("failed to create chrome widget, plugins won't paint.");
63 BaseCreate(aParent
, aRect
, aContext
, aInitData
);
69 mActor
->SendResize(mBounds
);
75 PluginWidgetProxy::SetParent(nsIWidget
* aNewParent
)
79 nsCOMPtr
<nsIWidget
> kungFuDeathGrip(this);
80 nsIWidget
* parent
= GetParent();
82 parent
->RemoveChild(this);
85 aNewParent
->AddChild(this);
91 PluginWidgetProxy::GetParent(void)
97 PluginWidgetProxy::Destroy()
99 PWLOG("PluginWidgetProxy::Destroy()\n");
102 mActor
->SendShow(false);
103 mActor
->SendDestroy();
104 mActor
->mWidget
= nullptr;
105 mActor
->Send__delete__(mActor
);
109 return PuppetWidget::Destroy();
113 PluginWidgetProxy::Show(bool aState
)
116 mActor
->SendShow(aState
);
122 PluginWidgetProxy::Invalidate(const nsIntRect
& aRect
)
125 mActor
->SendInvalidate(aRect
);
130 PluginWidgetProxy::GetNativeData(uint32_t aDataType
)
136 case NS_NATIVE_PLUGIN_PORT
:
137 case NS_NATIVE_WINDOW
:
138 case NS_NATIVE_SHAREABLE_WINDOW
:
141 NS_WARNING("PluginWidgetProxy::GetNativeData received request for unsupported data type.");
145 mActor
->SendGetNativePluginPort(&value
);
146 PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)value
);
151 PluginWidgetProxy::Resize(double aWidth
, double aHeight
, bool aRepaint
)
154 PWLOG("PluginWidgetProxy::Resize(%0.2f, %0.2f, %d)\n", aWidth
, aHeight
, aRepaint
);
155 nsIntRect oldBounds
= mBounds
;
156 mBounds
.SizeTo(nsIntSize(NSToIntRound(aWidth
), NSToIntRound(aHeight
)));
157 mActor
->SendResize(mBounds
);
158 if (!oldBounds
.IsEqualEdges(mBounds
) && mAttachedWidgetListener
) {
159 mAttachedWidgetListener
->WindowResized(this, mBounds
.width
, mBounds
.height
);
165 PluginWidgetProxy::Resize(double aX
, double aY
, double aWidth
,
166 double aHeight
, bool aRepaint
)
168 nsresult rv
= Move(aX
, aY
);
172 return Resize(aWidth
, aHeight
, aRepaint
);
176 PluginWidgetProxy::Move(double aX
, double aY
)
179 PWLOG("PluginWidgetProxy::Move(%0.2f, %0.2f)\n", aX
, aY
);
180 mActor
->SendMove(aX
, aY
);
181 if (mAttachedWidgetListener
) {
182 mAttachedWidgetListener
->WindowMoved(this, aX
, aY
);
188 PluginWidgetProxy::SetFocus(bool aRaise
)
191 PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise
);
192 mActor
->SendSetFocus(aRaise
);
197 PluginWidgetProxy::SetWindowClipRegion(const nsTArray
<nsIntRect
>& aRects
,
198 bool aIntersectWithExisting
)
201 mActor
->SendSetWindowClipRegion(aRects
, aIntersectWithExisting
);
202 nsBaseWidget::SetWindowClipRegion(aRects
, aIntersectWithExisting
);
206 } // namespace widget
207 } // namespace mozilla