-
Notifications
You must be signed in to change notification settings - Fork 16
/
EmbedLiteView.cpp
293 lines (246 loc) · 6.4 KB
/
EmbedLiteView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
#include "EmbedLog.h"
#include "EmbedLiteView.h"
#include "EmbedLiteApp.h"
#include "mozilla/unused.h"
#include "nsServiceManagerUtils.h"
#include "EmbedLiteViewThreadParent.h"
// Image as URL includes
#include "gfxImageSurface.h"
#include "mozilla/Base64.h"
#include "imgIEncoder.h"
#include "InputData.h"
namespace mozilla {
namespace embedlite {
class FakeListener : public EmbedLiteViewListener {};
static FakeListener sFakeListener;
EmbedLiteView::EmbedLiteView(EmbedLiteApp* aApp, EmbedLiteWindow* aWindow, PEmbedLiteViewParent* aViewImpl, uint32_t aViewId)
: mApp(aApp)
, mWindow(aWindow)
, mListener(NULL)
, mViewImpl(dynamic_cast<EmbedLiteViewIface*>(aViewImpl))
, mViewParent(aViewImpl)
, mUniqueID(aViewId)
{
LOGT();
dynamic_cast<EmbedLiteViewIface*>(aViewImpl)->SetEmbedAPIView(this);
}
EmbedLiteView::~EmbedLiteView()
{
LOGT("impl:%p", mViewImpl);
if (mViewImpl) {
mViewImpl->ViewAPIDestroyed();
}
}
void
EmbedLiteView::Destroy()
{
MOZ_ASSERT(mViewParent);
unused << mViewParent->SendDestroy();
}
void
EmbedLiteView::Destroyed()
{
if (mListener) {
mListener->ViewDestroyed();
}
EmbedLiteApp::GetInstance()->ViewDestroyed(mUniqueID);
}
void
EmbedLiteView::SetListener(EmbedLiteViewListener* aListener)
{
mListener = aListener;
}
EmbedLiteViewListener* const
EmbedLiteView::GetListener() const
{
return mListener ? mListener : &sFakeListener;
}
EmbedLiteViewIface*
EmbedLiteView::GetImpl()
{
return mViewImpl;
}
void
EmbedLiteView::LoadURL(const char* aUrl)
{
LOGT("url:%s", aUrl);
unused << mViewParent->SendLoadURL(NS_ConvertUTF8toUTF16(nsDependentCString(aUrl)));
}
void
EmbedLiteView::SetIsActive(bool aIsActive)
{
LOGT();
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendSetIsActive(aIsActive);
// Make sure active view content controller is always registered with
// APZCTreeManager for the window.
if (aIsActive) {
static_cast<EmbedLiteViewBaseParent*>(mViewParent)->UpdateScrollController();
}
}
void
EmbedLiteView::SetIsFocused(bool aIsFocused)
{
LOGT();
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendSetIsFocused(aIsFocused);
}
void
EmbedLiteView::SetThrottlePainting(bool aThrottle)
{
LOGT();
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendSetThrottlePainting(aThrottle);
}
void
EmbedLiteView::SuspendTimeouts()
{
LOGT();
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendSuspendTimeouts();
}
void
EmbedLiteView::ResumeTimeouts()
{
LOGT();
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendResumeTimeouts();
}
void EmbedLiteView::GoBack()
{
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendGoBack();
}
void EmbedLiteView::GoForward()
{
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendGoForward();
}
void EmbedLiteView::StopLoad()
{
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendStopLoad();
}
void EmbedLiteView::Reload(bool hard)
{
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendReload(hard);
}
void
EmbedLiteView::LoadFrameScript(const char* aURI)
{
LOGT("uri:%s, mViewImpl:%p", aURI, mViewImpl);
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendLoadFrameScript(NS_ConvertUTF8toUTF16(nsDependentCString(aURI)));
}
void
EmbedLiteView::AddMessageListener(const char* aName)
{
LOGT("name:%s", aName);
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendAddMessageListener(nsDependentCString(aName));
}
void
EmbedLiteView::RemoveMessageListener(const char* aName)
{
LOGT("name:%s", aName);
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendRemoveMessageListener(nsDependentCString(aName));
}
void EmbedLiteView::AddMessageListeners(const nsTArray<nsString>& aMessageNames)
{
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendAddMessageListeners(aMessageNames);
}
void EmbedLiteView::RemoveMessageListeners(const nsTArray<nsString>& aMessageNames)
{
NS_ENSURE_TRUE(mViewParent, );
unused << mViewParent->SendRemoveMessageListeners(aMessageNames);
}
void
EmbedLiteView::SendAsyncMessage(const char16_t* aMessageName, const char16_t* aMessage)
{
NS_ENSURE_TRUE(mViewParent, );
const nsDependentString msgname(aMessageName);
const nsDependentString msg(aMessage);
unused << mViewParent->SendAsyncMessage(msgname, msg);
}
// Render interface
void
EmbedLiteView::SetMargins(int top, int right, int bottom, int left)
{
unused << mViewParent->SendSetMargins(top, right, bottom, left);
}
void
EmbedLiteView::ReceiveInputEvent(const InputData& aEvent)
{
NS_ENSURE_TRUE(mViewImpl,);
mViewImpl->ReceiveInputEvent(aEvent);
}
void
EmbedLiteView::SendTextEvent(const char* composite, const char* preEdit)
{
NS_ENSURE_TRUE(mViewImpl,);
mViewImpl->TextEvent(composite, preEdit);
}
void EmbedLiteView::SendKeyPress(int domKeyCode, int gmodifiers, int charCode)
{
NS_ENSURE_TRUE(mViewImpl,);
mViewImpl->SendKeyPress(domKeyCode, gmodifiers, charCode);
}
void EmbedLiteView::SendKeyRelease(int domKeyCode, int gmodifiers, int charCode)
{
NS_ENSURE_TRUE(mViewImpl,);
mViewImpl->SendKeyRelease(domKeyCode, gmodifiers, charCode);
}
void
EmbedLiteView::MousePress(int x, int y, int mstime, unsigned int buttons, unsigned int modifiers)
{
NS_ENSURE_TRUE(mViewImpl, );
mViewImpl->MousePress(x, y, mstime, buttons, modifiers);
}
void
EmbedLiteView::MouseRelease(int x, int y, int mstime, unsigned int buttons, unsigned int modifiers)
{
NS_ENSURE_TRUE(mViewImpl, );
mViewImpl->MouseRelease(x, y, mstime, buttons, modifiers);
}
void
EmbedLiteView::MouseMove(int x, int y, int mstime, unsigned int buttons, unsigned int modifiers)
{
NS_ENSURE_TRUE(mViewImpl, );
mViewImpl->MouseMove(x, y, mstime, buttons, modifiers);
}
void
EmbedLiteView::PinchStart(int x, int y)
{
NS_ENSURE_TRUE(mViewImpl, );
LOGT();
}
void
EmbedLiteView::PinchUpdate(int x, int y, float scale)
{
NS_ENSURE_TRUE(mViewImpl, );
LOGT();
}
void
EmbedLiteView::PinchEnd(int x, int y, float scale)
{
NS_ENSURE_TRUE(mViewImpl, );
LOGT();
}
uint32_t
EmbedLiteView::GetUniqueID()
{
NS_ENSURE_TRUE(mViewImpl, 0);
uint32_t id;
mViewImpl->GetUniqueID(&id);
MOZ_ASSERT(id == mUniqueID);
return mUniqueID;
}
} // namespace embedlite
} // namespace mozilla