Bug 1073336 part 5 - Add AnimationPlayerCollection::PlayerUpdated; r=dbaron
[gecko.git] / widget / PluginWidgetProxy.cpp
blob0d31f491815ec59f2474fa5d1a4df3e4bc8b2459
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"
8 #include "nsDebug.h"
10 #define PWLOG(...)
11 // #define PWLOG(...) printf_stderr(__VA_ARGS__)
13 /* static */
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();
23 namespace mozilla {
24 namespace widget {
26 NS_IMPL_ISUPPORTS_INHERITED(PluginWidgetProxy, PuppetWidget, nsIWidget)
28 #define ENSURE_CHANNEL do { \
29 if (!mActor) { \
30 NS_WARNING("called on an invalid channel."); \
31 return NS_ERROR_FAILURE; \
32 } \
33 } while (0)
35 PluginWidgetProxy::PluginWidgetProxy(dom::TabChild* aTabChild,
36 mozilla::plugins::PluginWidgetChild* aActor) :
37 PuppetWidget(aTabChild),
38 mActor(aActor)
40 // See ChannelDestroyed() in the header
41 mActor->mWidget = this;
44 PluginWidgetProxy::~PluginWidgetProxy()
46 PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
49 NS_IMETHODIMP
50 PluginWidgetProxy::Create(nsIWidget* aParent,
51 nsNativeWidget aNativeParent,
52 const nsIntRect& aRect,
53 nsDeviceContext* aContext,
54 nsWidgetInitData* aInitData)
56 ENSURE_CHANNEL;
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);
65 mBounds = aRect;
66 mEnabled = true;
67 mVisible = true;
69 mActor->SendResize(mBounds);
71 return NS_OK;
74 NS_IMETHODIMP
75 PluginWidgetProxy::SetParent(nsIWidget* aNewParent)
77 mParent = aNewParent;
79 nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
80 nsIWidget* parent = GetParent();
81 if (parent) {
82 parent->RemoveChild(this);
84 if (aNewParent) {
85 aNewParent->AddChild(this);
87 return NS_OK;
90 nsIWidget*
91 PluginWidgetProxy::GetParent(void)
93 return mParent.get();
96 NS_IMETHODIMP
97 PluginWidgetProxy::Destroy()
99 PWLOG("PluginWidgetProxy::Destroy()\n");
101 if (mActor) {
102 mActor->SendShow(false);
103 mActor->SendDestroy();
104 mActor->mWidget = nullptr;
105 mActor->Send__delete__(mActor);
106 mActor = nullptr;
109 return PuppetWidget::Destroy();
112 NS_IMETHODIMP
113 PluginWidgetProxy::Show(bool aState)
115 ENSURE_CHANNEL;
116 mActor->SendShow(aState);
117 mVisible = aState;
118 return NS_OK;
121 NS_IMETHODIMP
122 PluginWidgetProxy::Invalidate(const nsIntRect& aRect)
124 ENSURE_CHANNEL;
125 mActor->SendInvalidate(aRect);
126 return NS_OK;
129 void*
130 PluginWidgetProxy::GetNativeData(uint32_t aDataType)
132 if (!mActor) {
133 return nullptr;
135 switch (aDataType) {
136 case NS_NATIVE_PLUGIN_PORT:
137 case NS_NATIVE_WINDOW:
138 case NS_NATIVE_SHAREABLE_WINDOW:
139 break;
140 default:
141 NS_WARNING("PluginWidgetProxy::GetNativeData received request for unsupported data type.");
142 return nullptr;
144 uintptr_t value = 0;
145 mActor->SendGetNativePluginPort(&value);
146 PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)value);
147 return (void*)value;
150 NS_IMETHODIMP
151 PluginWidgetProxy::Resize(double aWidth, double aHeight, bool aRepaint)
153 ENSURE_CHANNEL;
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);
161 return NS_OK;
164 NS_IMETHODIMP
165 PluginWidgetProxy::Resize(double aX, double aY, double aWidth,
166 double aHeight, bool aRepaint)
168 nsresult rv = Move(aX, aY);
169 if (NS_FAILED(rv)) {
170 return rv;
172 return Resize(aWidth, aHeight, aRepaint);
175 NS_IMETHODIMP
176 PluginWidgetProxy::Move(double aX, double aY)
178 ENSURE_CHANNEL;
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);
184 return NS_OK;
187 NS_IMETHODIMP
188 PluginWidgetProxy::SetFocus(bool aRaise)
190 ENSURE_CHANNEL;
191 PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise);
192 mActor->SendSetFocus(aRaise);
193 return NS_OK;
196 nsresult
197 PluginWidgetProxy::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
198 bool aIntersectWithExisting)
200 ENSURE_CHANNEL;
201 mActor->SendSetWindowClipRegion(aRects, aIntersectWithExisting);
202 nsBaseWidget::SetWindowClipRegion(aRects, aIntersectWithExisting);
203 return NS_OK;
206 } // namespace widget
207 } // namespace mozilla