-
Notifications
You must be signed in to change notification settings - Fork 16
/
EmbedLiteWindowBaseChild.cpp
165 lines (137 loc) · 4.2 KB
/
EmbedLiteWindowBaseChild.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
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 "EmbedLitePuppetWidget.h"
#include "EmbedLiteWindowBaseChild.h"
#include "mozilla/unused.h"
#include "Hal.h"
#include "ScreenOrientation.h"
#include "nsIScreen.h"
#include "nsIScreenManager.h"
#include "gfxPlatform.h"
using namespace mozilla::dom;
namespace mozilla {
namespace layers {
void ShutdownTileCache();
}
namespace embedlite {
static int sWindowCount = 0;
EmbedLiteWindowBaseChild::EmbedLiteWindowBaseChild(const uint32_t& aId)
: mId(aId)
, mWidget(nullptr)
, mSize(0, 0)
, mRotation(ROTATION_0)
{
MOZ_COUNT_CTOR(EmbedLiteWindowBaseChild);
mCreateWidgetTask = NewRunnableMethod(this, &EmbedLiteWindowBaseChild::CreateWidget);
MessageLoop::current()->PostTask(FROM_HERE, mCreateWidgetTask);
sWindowCount++;
// Make sure gfx platform is initialized and ready to go.
gfxPlatform::GetPlatform();
}
EmbedLiteWindowBaseChild::~EmbedLiteWindowBaseChild()
{
MOZ_COUNT_DTOR(EmbedLiteWindowBaseChild);
if (mCreateWidgetTask) {
mCreateWidgetTask->Cancel();
mCreateWidgetTask = nullptr;
}
sWindowCount--;
if (sWindowCount == 0) {
mozilla::layers::ShutdownTileCache();
}
}
EmbedLitePuppetWidget* EmbedLiteWindowBaseChild::GetWidget() const
{
return static_cast<EmbedLitePuppetWidget*>(mWidget.get());
}
void EmbedLiteWindowBaseChild::ActorDestroy(ActorDestroyReason aWhy)
{
LOGT("reason:%i", aWhy);
}
bool EmbedLiteWindowBaseChild::RecvDestroy()
{
LOGT("destroy");
mWidget = nullptr;
unused << SendDestroyed();
PEmbedLiteWindowChild::Send__delete__(this);
return true;
}
bool EmbedLiteWindowBaseChild::RecvSetSize(const gfxSize& aSize)
{
LOGT("this:%p", this);
mSize = aSize;
if (mWidget) {
mWidget->Resize(aSize.width, aSize.height, true);
}
return true;
}
bool EmbedLiteWindowBaseChild::RecvSetContentOrientation(const mozilla::ScreenRotation& aRotation)
{
LOGT("this:%p", this);
mRotation = aRotation;
if (mWidget) {
EmbedLitePuppetWidget* widget = static_cast<EmbedLitePuppetWidget*>(mWidget.get());
widget->SetRotation(aRotation);
widget->UpdateSize();
}
nsresult rv;
nsCOMPtr<nsIScreenManager> screenMgr =
do_GetService("@mozilla.org/gfx/screenmanager;1", &rv);
if (NS_FAILED(rv)) {
NS_ERROR("Can't find nsIScreenManager!");
return true;
}
nsIntRect rect;
int32_t colorDepth, pixelDepth;
nsCOMPtr<nsIScreen> screen;
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height);
screen->GetColorDepth(&colorDepth);
screen->GetPixelDepth(&pixelDepth);
ScreenOrientation orientation = eScreenOrientation_Default;
switch (aRotation) {
case ROTATION_0:
orientation = eScreenOrientation_PortraitPrimary;
break;
case ROTATION_90:
orientation = eScreenOrientation_LandscapePrimary;
break;
case ROTATION_180:
orientation = eScreenOrientation_PortraitSecondary;
break;
case ROTATION_270:
orientation = eScreenOrientation_LandscapeSecondary;
break;
default:
break;
}
hal::NotifyScreenConfigurationChange(hal::ScreenConfiguration(
rect, orientation, colorDepth, pixelDepth));
return true;
}
void EmbedLiteWindowBaseChild::CreateWidget()
{
LOGT("this:%p", this);
if (mCreateWidgetTask) {
mCreateWidgetTask->Cancel();
mCreateWidgetTask = nullptr;
}
mWidget = new EmbedLitePuppetWidget(this);
static_cast<EmbedLitePuppetWidget*>(mWidget.get())->SetRotation(mRotation);
nsWidgetInitData widgetInit;
widgetInit.clipChildren = true;
widgetInit.mWindowType = eWindowType_toplevel;
widgetInit.mRequireOffMainThreadCompositing = true;
mWidget->Create(
nullptr, 0, // no parents
nsIntRect(nsIntPoint(0, 0), nsIntSize(mSize.width, mSize.height)),
&widgetInit // HandleWidgetEvent
);
static_cast<EmbedLitePuppetWidget*>(mWidget.get())->UpdateSize();
unused << SendInitialized();
}
} // namespace embedlite
} // namespace mozilla