forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PuppetWidget.cpp
799 lines (682 loc) · 19.4 KB
/
PuppetWidget.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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 "base/basictypes.h"
#include "ClientLayerManager.h"
#include "gfxPlatform.h"
#if defined(MOZ_ENABLE_D3D10_LAYER)
# include "LayerManagerD3D10.h"
#endif
#include "mozilla/dom/TabChild.h"
#include "mozilla/Hal.h"
#include "mozilla/layers/CompositorChild.h"
#include "mozilla/layers/PLayerTransactionChild.h"
#include "mozilla/TextEvents.h"
#include "PuppetWidget.h"
#include "nsIWidgetListener.h"
using namespace mozilla::dom;
using namespace mozilla::hal;
using namespace mozilla::layers;
using namespace mozilla::widget;
static void
InvalidateRegion(nsIWidget* aWidget, const nsIntRegion& aRegion)
{
nsIntRegionRectIterator it(aRegion);
while(const nsIntRect* r = it.Next()) {
aWidget->Invalidate(*r);
}
}
/*static*/ already_AddRefed<nsIWidget>
nsIWidget::CreatePuppetWidget(TabChild* aTabChild)
{
NS_ABORT_IF_FALSE(!aTabChild || nsIWidget::UsePuppetWidgets(),
"PuppetWidgets not allowed in this configuration");
nsCOMPtr<nsIWidget> widget = new PuppetWidget(aTabChild);
return widget.forget();
}
namespace mozilla {
namespace widget {
static bool
IsPopup(const nsWidgetInitData* aInitData)
{
return aInitData && aInitData->mWindowType == eWindowType_popup;
}
static bool
MightNeedIMEFocus(const nsWidgetInitData* aInitData)
{
// In the puppet-widget world, popup widgets are just dummies and
// shouldn't try to mess with IME state.
#ifdef MOZ_CROSS_PROCESS_IME
return !IsPopup(aInitData);
#else
return false;
#endif
}
// Arbitrary, fungible.
const size_t PuppetWidget::kMaxDimension = 4000;
NS_IMPL_ISUPPORTS_INHERITED1(PuppetWidget, nsBaseWidget,
nsISupportsWeakReference)
PuppetWidget::PuppetWidget(TabChild* aTabChild)
: mTabChild(aTabChild)
, mDPI(-1)
, mDefaultScale(-1)
{
MOZ_COUNT_CTOR(PuppetWidget);
}
PuppetWidget::~PuppetWidget()
{
MOZ_COUNT_DTOR(PuppetWidget);
}
NS_IMETHODIMP
PuppetWidget::Create(nsIWidget *aParent,
nsNativeWidget aNativeParent,
const nsIntRect &aRect,
nsDeviceContext *aContext,
nsWidgetInitData *aInitData)
{
NS_ABORT_IF_FALSE(!aNativeParent, "got a non-Puppet native parent");
BaseCreate(nullptr, aRect, aContext, aInitData);
mBounds = aRect;
mEnabled = true;
mVisible = true;
mSurface = gfxPlatform::GetPlatform()
->CreateOffscreenSurface(gfxIntSize(1, 1),
gfxASurface::ContentFromFormat(gfxImageFormatARGB32));
mIMEComposing = false;
mNeedIMEStateInit = MightNeedIMEFocus(aInitData);
PuppetWidget* parent = static_cast<PuppetWidget*>(aParent);
if (parent) {
parent->SetChild(this);
mLayerManager = parent->GetLayerManager();
}
else {
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false);
}
return NS_OK;
}
void
PuppetWidget::InitIMEState()
{
MOZ_ASSERT(mTabChild);
if (mNeedIMEStateInit) {
uint32_t chromeSeqno;
mTabChild->SendNotifyIMEFocus(false, &mIMEPreference, &chromeSeqno);
mIMELastBlurSeqno = mIMELastReceivedSeqno = chromeSeqno;
mNeedIMEStateInit = false;
}
}
already_AddRefed<nsIWidget>
PuppetWidget::CreateChild(const nsIntRect &aRect,
nsDeviceContext *aContext,
nsWidgetInitData *aInitData,
bool aForceUseIWidgetParent)
{
bool isPopup = IsPopup(aInitData);
nsCOMPtr<nsIWidget> widget = nsIWidget::CreatePuppetWidget(mTabChild);
return ((widget &&
NS_SUCCEEDED(widget->Create(isPopup ? nullptr: this, nullptr, aRect,
aContext, aInitData))) ?
widget.forget() : nullptr);
}
NS_IMETHODIMP
PuppetWidget::Destroy()
{
Base::OnDestroy();
Base::Destroy();
mPaintTask.Revoke();
mChild = nullptr;
if (mLayerManager) {
mLayerManager->Destroy();
}
mLayerManager = nullptr;
mTabChild = nullptr;
return NS_OK;
}
NS_IMETHODIMP
PuppetWidget::Show(bool aState)
{
NS_ASSERTION(mEnabled,
"does it make sense to Show()/Hide() a disabled widget?");
bool wasVisible = mVisible;
mVisible = aState;
if (mChild) {
mChild->mVisible = aState;
}
if (!mVisible && mLayerManager) {
mLayerManager->ClearCachedResources();
}
if (!wasVisible && mVisible) {
Resize(mBounds.width, mBounds.height, false);
Invalidate(mBounds);
}
return NS_OK;
}
NS_IMETHODIMP
PuppetWidget::Resize(double aWidth,
double aHeight,
bool aRepaint)
{
nsIntRect oldBounds = mBounds;
mBounds.SizeTo(nsIntSize(NSToIntRound(aWidth), NSToIntRound(aHeight)));
if (mChild) {
return mChild->Resize(aWidth, aHeight, aRepaint);
}
// XXX: roc says that |aRepaint| dictates whether or not to
// invalidate the expanded area
if (oldBounds.Size() < mBounds.Size() && aRepaint) {
nsIntRegion dirty(mBounds);
dirty.Sub(dirty, oldBounds);
InvalidateRegion(this, dirty);
}
if (!oldBounds.IsEqualEdges(mBounds) && mAttachedWidgetListener) {
mAttachedWidgetListener->WindowResized(this, mBounds.width, mBounds.height);
}
return NS_OK;
}
NS_IMETHODIMP
PuppetWidget::SetFocus(bool aRaise)
{
// XXX/cjones: someone who knows about event handling needs to
// decide how this should work.
return NS_OK;
}
NS_IMETHODIMP
PuppetWidget::Invalidate(const nsIntRect& aRect)
{
#ifdef DEBUG
debug_DumpInvalidate(stderr, this, &aRect,
nsAutoCString("PuppetWidget"), 0);
#endif
if (mChild) {
return mChild->Invalidate(aRect);
}
mDirtyRegion.Or(mDirtyRegion, aRect);
if (!mDirtyRegion.IsEmpty() && !mPaintTask.IsPending()) {
mPaintTask = new PaintTask(this);
return NS_DispatchToCurrentThread(mPaintTask.get());
}
return NS_OK;
}
void
PuppetWidget::InitEvent(WidgetGUIEvent& event, nsIntPoint* aPoint)
{
if (nullptr == aPoint) {
event.refPoint.x = 0;
event.refPoint.y = 0;
}
else {
// use the point override if provided
event.refPoint.x = aPoint->x;
event.refPoint.y = aPoint->y;
}
event.time = PR_Now() / 1000;
}
NS_IMETHODIMP
PuppetWidget::DispatchEvent(WidgetGUIEvent* event, nsEventStatus& aStatus)
{
#ifdef DEBUG
debug_DumpEvent(stdout, event->widget, event,
nsAutoCString("PuppetWidget"), 0);
#endif
NS_ABORT_IF_FALSE(!mChild || mChild->mWindowType == eWindowType_popup,
"Unexpected event dispatch!");
aStatus = nsEventStatus_eIgnore;
if (event->message == NS_COMPOSITION_START) {
mIMEComposing = true;
}
switch (event->eventStructType) {
case NS_COMPOSITION_EVENT:
mIMELastReceivedSeqno = event->AsCompositionEvent()->seqno;
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
return NS_OK;
break;
case NS_TEXT_EVENT:
mIMELastReceivedSeqno = event->AsTextEvent()->seqno;
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
return NS_OK;
break;
case NS_SELECTION_EVENT:
mIMELastReceivedSeqno = event->AsSelectionEvent()->seqno;
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
return NS_OK;
break;
default:
break;
}
if (mAttachedWidgetListener) {
aStatus = mAttachedWidgetListener->HandleEvent(event, mUseAttachedEvents);
}
if (event->message == NS_COMPOSITION_END) {
mIMEComposing = false;
}
return NS_OK;
}
LayerManager*
PuppetWidget::GetLayerManager(PLayerTransactionChild* aShadowManager,
LayersBackend aBackendHint,
LayerManagerPersistence aPersistence,
bool* aAllowRetaining)
{
if (!mLayerManager) {
// The backend hint is a temporary placeholder until Azure, when
// all content-process layer managers will be BasicLayerManagers.
#if defined(MOZ_ENABLE_D3D10_LAYER)
if (mozilla::layers::LAYERS_D3D10 == aBackendHint) {
nsRefPtr<LayerManagerD3D10> m = new LayerManagerD3D10(this);
m->AsShadowForwarder()->SetShadowManager(aShadowManager);
if (m->Initialize()) {
mLayerManager = m;
}
}
#endif
if (!mLayerManager) {
mLayerManager = new ClientLayerManager(this);
}
}
ShadowLayerForwarder* lf = mLayerManager->AsShadowForwarder();
if (!lf->HasShadowManager() && aShadowManager) {
lf->SetShadowManager(aShadowManager);
}
if (aAllowRetaining) {
*aAllowRetaining = true;
}
return mLayerManager;
}
gfxASurface*
PuppetWidget::GetThebesSurface()
{
return mSurface;
}
nsresult
PuppetWidget::IMEEndComposition(bool aCancel)
{
#ifndef MOZ_CROSS_PROCESS_IME
return NS_OK;
#endif
nsEventStatus status;
WidgetTextEvent textEvent(true, NS_TEXT_TEXT, this);
InitEvent(textEvent, nullptr);
textEvent.seqno = mIMELastReceivedSeqno;
// SendEndIMEComposition is always called since ResetInputState
// should always be called even if we aren't composing something.
if (!mTabChild ||
!mTabChild->SendEndIMEComposition(aCancel, &textEvent.theText)) {
return NS_ERROR_FAILURE;
}
if (!mIMEComposing)
return NS_OK;
DispatchEvent(&textEvent, status);
WidgetCompositionEvent compEvent(true, NS_COMPOSITION_END, this);
InitEvent(compEvent, nullptr);
compEvent.seqno = mIMELastReceivedSeqno;
DispatchEvent(&compEvent, status);
return NS_OK;
}
NS_IMETHODIMP
PuppetWidget::NotifyIME(NotificationToIME aNotification)
{
switch (aNotification) {
case NOTIFY_IME_OF_CURSOR_POS_CHANGED:
case REQUEST_TO_COMMIT_COMPOSITION:
return IMEEndComposition(false);
case REQUEST_TO_CANCEL_COMPOSITION:
return IMEEndComposition(true);
case NOTIFY_IME_OF_FOCUS:
return NotifyIMEOfFocusChange(true);
case NOTIFY_IME_OF_BLUR:
return NotifyIMEOfFocusChange(false);
case NOTIFY_IME_OF_SELECTION_CHANGE:
return NotifyIMEOfSelectionChange();
default:
return NS_ERROR_NOT_IMPLEMENTED;
}
}
NS_IMETHODIMP_(void)
PuppetWidget::SetInputContext(const InputContext& aContext,
const InputContextAction& aAction)
{
#ifndef MOZ_CROSS_PROCESS_IME
return;
#endif
if (!mTabChild) {
return;
}
mTabChild->SendSetInputContext(
static_cast<int32_t>(aContext.mIMEState.mEnabled),
static_cast<int32_t>(aContext.mIMEState.mOpen),
aContext.mHTMLInputType,
aContext.mHTMLInputInputmode,
aContext.mActionHint,
static_cast<int32_t>(aAction.mCause),
static_cast<int32_t>(aAction.mFocusChange));
}
NS_IMETHODIMP_(InputContext)
PuppetWidget::GetInputContext()
{
#ifndef MOZ_CROSS_PROCESS_IME
return InputContext();
#endif
InputContext context;
if (mTabChild) {
int32_t enabled, open;
intptr_t nativeIMEContext;
mTabChild->SendGetInputContext(&enabled, &open, &nativeIMEContext);
context.mIMEState.mEnabled = static_cast<IMEState::Enabled>(enabled);
context.mIMEState.mOpen = static_cast<IMEState::Open>(open);
context.mNativeIMEContext = reinterpret_cast<void*>(nativeIMEContext);
}
return context;
}
nsresult
PuppetWidget::NotifyIMEOfFocusChange(bool aFocus)
{
#ifndef MOZ_CROSS_PROCESS_IME
return NS_OK;
#endif
if (!mTabChild)
return NS_ERROR_FAILURE;
if (aFocus) {
nsEventStatus status;
WidgetQueryContentEvent queryEvent(true, NS_QUERY_TEXT_CONTENT, this);
InitEvent(queryEvent, nullptr);
// Query entire content
queryEvent.InitForQueryTextContent(0, UINT32_MAX);
DispatchEvent(&queryEvent, status);
if (queryEvent.mSucceeded) {
mTabChild->SendNotifyIMETextHint(queryEvent.mReply.mString);
}
} else {
// Might not have been committed composition yet
IMEEndComposition(false);
}
uint32_t chromeSeqno;
mIMEPreference.mWantUpdates = nsIMEUpdatePreference::NOTIFY_NOTHING;
mIMEPreference.mWantHints = false;
if (!mTabChild->SendNotifyIMEFocus(aFocus, &mIMEPreference, &chromeSeqno))
return NS_ERROR_FAILURE;
if (aFocus) {
if ((mIMEPreference.mWantUpdates &
nsIMEUpdatePreference::NOTIFY_SELECTION_CHANGE) &&
mIMEPreference.mWantHints) {
NotifyIMEOfSelectionChange(); // Update selection
}
} else {
mIMELastBlurSeqno = chromeSeqno;
}
return NS_OK;
}
nsIMEUpdatePreference
PuppetWidget::GetIMEUpdatePreference()
{
return mIMEPreference;
}
NS_IMETHODIMP
PuppetWidget::NotifyIMEOfTextChange(uint32_t aStart,
uint32_t aEnd,
uint32_t aNewEnd)
{
#ifndef MOZ_CROSS_PROCESS_IME
return NS_OK;
#endif
if (!mTabChild)
return NS_ERROR_FAILURE;
if (mIMEPreference.mWantHints) {
nsEventStatus status;
WidgetQueryContentEvent queryEvent(true, NS_QUERY_TEXT_CONTENT, this);
InitEvent(queryEvent, nullptr);
queryEvent.InitForQueryTextContent(0, UINT32_MAX);
DispatchEvent(&queryEvent, status);
if (queryEvent.mSucceeded) {
mTabChild->SendNotifyIMETextHint(queryEvent.mReply.mString);
}
}
if (mIMEPreference.mWantUpdates & nsIMEUpdatePreference::NOTIFY_TEXT_CHANGE) {
mTabChild->SendNotifyIMETextChange(aStart, aEnd, aNewEnd);
}
return NS_OK;
}
nsresult
PuppetWidget::NotifyIMEOfSelectionChange()
{
#ifndef MOZ_CROSS_PROCESS_IME
return NS_OK;
#endif
if (!mTabChild)
return NS_ERROR_FAILURE;
if (mIMEPreference.mWantUpdates &
nsIMEUpdatePreference::NOTIFY_SELECTION_CHANGE) {
nsEventStatus status;
WidgetQueryContentEvent queryEvent(true, NS_QUERY_SELECTED_TEXT, this);
InitEvent(queryEvent, nullptr);
DispatchEvent(&queryEvent, status);
if (queryEvent.mSucceeded) {
mTabChild->SendNotifyIMESelection(mIMELastReceivedSeqno,
queryEvent.GetSelectionStart(),
queryEvent.GetSelectionEnd());
}
}
return NS_OK;
}
NS_IMETHODIMP
PuppetWidget::SetCursor(nsCursor aCursor)
{
if (mCursor == aCursor) {
return NS_OK;
}
if (mTabChild && !mTabChild->SendSetCursor(aCursor)) {
return NS_ERROR_FAILURE;
}
mCursor = aCursor;
return NS_OK;
}
nsresult
PuppetWidget::Paint()
{
NS_ABORT_IF_FALSE(!mDirtyRegion.IsEmpty(), "paint event logic messed up");
if (!mAttachedWidgetListener)
return NS_OK;
nsIntRegion region = mDirtyRegion;
// reset repaint tracking
mDirtyRegion.SetEmpty();
mPaintTask.Revoke();
mAttachedWidgetListener->WillPaintWindow(this);
if (mAttachedWidgetListener) {
#ifdef DEBUG
debug_DumpPaintEvent(stderr, this, region,
nsAutoCString("PuppetWidget"), 0);
#endif
if (mozilla::layers::LAYERS_D3D10 == mLayerManager->GetBackendType()) {
mAttachedWidgetListener->PaintWindow(this, region);
} else if (mozilla::layers::LAYERS_CLIENT == mLayerManager->GetBackendType()) {
// Do nothing, the compositor will handle drawing
if (mTabChild) {
mTabChild->NotifyPainted();
}
} else {
nsRefPtr<gfxContext> ctx = new gfxContext(mSurface);
ctx->Rectangle(gfxRect(0,0,0,0));
ctx->Clip();
AutoLayerManagerSetup setupLayerManager(this, ctx,
BUFFER_NONE);
mAttachedWidgetListener->PaintWindow(this, region);
if (mTabChild) {
mTabChild->NotifyPainted();
}
}
}
if (mAttachedWidgetListener) {
mAttachedWidgetListener->DidPaintWindow();
}
return NS_OK;
}
void
PuppetWidget::SetChild(PuppetWidget* aChild)
{
NS_ABORT_IF_FALSE(this != aChild, "can't parent a widget to itself");
NS_ABORT_IF_FALSE(!aChild->mChild,
"fake widget 'hierarchy' only expected to have one level");
mChild = aChild;
}
NS_IMETHODIMP
PuppetWidget::PaintTask::Run()
{
if (mWidget) {
mWidget->Paint();
}
return NS_OK;
}
bool
PuppetWidget::NeedsPaint()
{
return mVisible;
}
float
PuppetWidget::GetDPI()
{
if (mDPI < 0) {
if (mTabChild) {
mTabChild->GetDPI(&mDPI);
} else {
mDPI = 96.0;
}
}
return mDPI;
}
double
PuppetWidget::GetDefaultScaleInternal()
{
if (mDefaultScale < 0) {
if (mTabChild) {
mTabChild->GetDefaultScale(&mDefaultScale);
} else {
mDefaultScale = 1;
}
}
return mDefaultScale;
}
void*
PuppetWidget::GetNativeData(uint32_t aDataType)
{
switch (aDataType) {
case NS_NATIVE_SHAREABLE_WINDOW: {
NS_ABORT_IF_FALSE(mTabChild, "Need TabChild to get the nativeWindow from!");
mozilla::WindowsHandle nativeData = 0;
if (mTabChild) {
mTabChild->SendGetWidgetNativeData(&nativeData);
}
return (void*)nativeData;
}
case NS_NATIVE_WINDOW:
case NS_NATIVE_DISPLAY:
case NS_NATIVE_PLUGIN_PORT:
case NS_NATIVE_GRAPHIC:
case NS_NATIVE_SHELLWIDGET:
case NS_NATIVE_WIDGET:
NS_WARNING("nsWindow::GetNativeData not implemented for this type");
break;
default:
NS_WARNING("nsWindow::GetNativeData called with bad value");
break;
}
return nullptr;
}
PuppetScreen::PuppetScreen(void *nativeScreen)
{
}
PuppetScreen::~PuppetScreen()
{
}
static ScreenConfiguration
ScreenConfig()
{
ScreenConfiguration config;
hal::GetCurrentScreenConfiguration(&config);
return config;
}
NS_IMETHODIMP
PuppetScreen::GetRect(int32_t *outLeft, int32_t *outTop,
int32_t *outWidth, int32_t *outHeight)
{
nsIntRect r = ScreenConfig().rect();
*outLeft = r.x;
*outTop = r.y;
*outWidth = r.width;
*outHeight = r.height;
return NS_OK;
}
NS_IMETHODIMP
PuppetScreen::GetAvailRect(int32_t *outLeft, int32_t *outTop,
int32_t *outWidth, int32_t *outHeight)
{
return GetRect(outLeft, outTop, outWidth, outHeight);
}
NS_IMETHODIMP
PuppetScreen::GetPixelDepth(int32_t *aPixelDepth)
{
*aPixelDepth = ScreenConfig().pixelDepth();
return NS_OK;
}
NS_IMETHODIMP
PuppetScreen::GetColorDepth(int32_t *aColorDepth)
{
*aColorDepth = ScreenConfig().colorDepth();
return NS_OK;
}
NS_IMETHODIMP
PuppetScreen::GetRotation(uint32_t* aRotation)
{
NS_WARNING("Attempt to get screen rotation through nsIScreen::GetRotation(). Nothing should know or care this in sandboxed contexts. If you want *orientation*, use hal.");
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP
PuppetScreen::SetRotation(uint32_t aRotation)
{
NS_WARNING("Attempt to set screen rotation through nsIScreen::GetRotation(). Nothing should know or care this in sandboxed contexts. If you want *orientation*, use hal.");
return NS_ERROR_NOT_AVAILABLE;
}
NS_IMPL_ISUPPORTS1(PuppetScreenManager, nsIScreenManager)
PuppetScreenManager::PuppetScreenManager()
{
mOneScreen = new PuppetScreen(nullptr);
}
PuppetScreenManager::~PuppetScreenManager()
{
}
NS_IMETHODIMP
PuppetScreenManager::GetPrimaryScreen(nsIScreen** outScreen)
{
NS_IF_ADDREF(*outScreen = mOneScreen.get());
return NS_OK;
}
NS_IMETHODIMP
PuppetScreenManager::ScreenForRect(int32_t inLeft,
int32_t inTop,
int32_t inWidth,
int32_t inHeight,
nsIScreen** outScreen)
{
return GetPrimaryScreen(outScreen);
}
NS_IMETHODIMP
PuppetScreenManager::ScreenForNativeWidget(void* aWidget,
nsIScreen** outScreen)
{
return GetPrimaryScreen(outScreen);
}
NS_IMETHODIMP
PuppetScreenManager::GetNumberOfScreens(uint32_t* aNumberOfScreens)
{
*aNumberOfScreens = 1;
return NS_OK;
}
NS_IMETHODIMP
PuppetScreenManager::GetSystemDefaultScale(float *aDefaultScale)
{
*aDefaultScale = 1.0f;
return NS_OK;
}
} // namespace widget
} // namespace mozilla