1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "base/basictypes.h"
7 #include "assert.h"
8 #include "ANPBase.h"
9 #include <android/log.h>
10 #include "nsNPAPIPluginInstance.h"
11 #include "nsPluginInstanceOwner.h"
12 #include "nsWindow.h"
13 #include "mozilla/dom/ScreenOrientation.h"
14
15 #undef LOG
16 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
17 #define ASSIGN(obj, name) (obj)->name = anp_window_##name
18
19 using namespace mozilla;
20 using namespace mozilla::widget;
21 using namespace mozilla::dom;
22
23 void
anp_window_setVisibleRects(NPP instance,const ANPRectI rects[],int32_t count)24 anp_window_setVisibleRects(NPP instance, const ANPRectI rects[], int32_t count)
25 {
26 NOT_IMPLEMENTED();
27 }
28
29 void
anp_window_clearVisibleRects(NPP instance)30 anp_window_clearVisibleRects(NPP instance)
31 {
32 NOT_IMPLEMENTED();
33 }
34
35 void
anp_window_showKeyboard(NPP instance,bool value)36 anp_window_showKeyboard(NPP instance, bool value)
37 {
38 InputContext context;
39 context.mIMEState.mEnabled = value ? IMEState::PLUGIN : IMEState::DISABLED;
40 context.mIMEState.mOpen = value ? IMEState::OPEN : IMEState::CLOSED;
41 context.mActionHint.Assign(EmptyString());
42
43 InputContextAction action;
44 action.mCause = InputContextAction::CAUSE_UNKNOWN;
45 action.mFocusChange = InputContextAction::FOCUS_NOT_CHANGED;
46
47 nsWindow* window = nsWindow::TopWindow();
48 if (!window) {
49 LOG("Couldn't get top window?");
50 return;
51 }
52
53 window->SetInputContext(context, action);
54 }
55
56 void
anp_window_requestFullScreen(NPP instance)57 anp_window_requestFullScreen(NPP instance)
58 {
59 nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
60
61 RefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
62 if (!owner) {
63 return;
64 }
65
66 owner->RequestFullScreen();
67 }
68
69 void
anp_window_exitFullScreen(NPP instance)70 anp_window_exitFullScreen(NPP instance)
71 {
72 nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
73
74 RefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
75 if (!owner) {
76 return;
77 }
78
79 owner->ExitFullScreen();
80 }
81
82 void
anp_window_requestCenterFitZoom(NPP instance)83 anp_window_requestCenterFitZoom(NPP instance)
84 {
85 NOT_IMPLEMENTED();
86 }
87
88 ANPRectI
anp_window_visibleRect(NPP instance)89 anp_window_visibleRect(NPP instance)
90 {
91 ANPRectI rect = { 0, 0, 0, 0 };
92
93 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
94
95 nsIntSize currentSize = pinst->CurrentSize();
96 rect.left = rect.top = 0;
97 rect.right = currentSize.width;
98 rect.bottom = currentSize.height;
99
100 return rect;
101 }
102
anp_window_requestFullScreenOrientation(NPP instance,ANPScreenOrientation orientation)103 void anp_window_requestFullScreenOrientation(NPP instance, ANPScreenOrientation orientation)
104 {
105 short newOrientation;
106
107 // Convert to the ActivityInfo equivalent
108 switch (orientation) {
109 case kFixedLandscape_ANPScreenOrientation:
110 newOrientation = eScreenOrientation_LandscapePrimary;
111 break;
112 case kFixedPortrait_ANPScreenOrientation:
113 newOrientation = eScreenOrientation_PortraitPrimary;
114 break;
115 case kLandscape_ANPScreenOrientation:
116 newOrientation = eScreenOrientation_LandscapePrimary |
117 eScreenOrientation_LandscapeSecondary;
118 break;
119 case kPortrait_ANPScreenOrientation:
120 newOrientation = eScreenOrientation_PortraitPrimary |
121 eScreenOrientation_PortraitSecondary;
122 break;
123 default:
124 newOrientation = eScreenOrientation_None;
125 break;
126 }
127
128 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
129 pinst->SetFullScreenOrientation(newOrientation);
130 }
131
InitWindowInterface(ANPWindowInterfaceV0 * i)132 void InitWindowInterface(ANPWindowInterfaceV0 *i) {
133 _assert(i->inSize == sizeof(*i));
134 ASSIGN(i, setVisibleRects);
135 ASSIGN(i, clearVisibleRects);
136 ASSIGN(i, showKeyboard);
137 ASSIGN(i, requestFullScreen);
138 ASSIGN(i, exitFullScreen);
139 ASSIGN(i, requestCenterFitZoom);
140 }
141
InitWindowInterfaceV2(ANPWindowInterfaceV2 * i)142 void InitWindowInterfaceV2(ANPWindowInterfaceV2 *i) {
143 _assert(i->inSize == sizeof(*i));
144 ASSIGN(i, setVisibleRects);
145 ASSIGN(i, clearVisibleRects);
146 ASSIGN(i, showKeyboard);
147 ASSIGN(i, requestFullScreen);
148 ASSIGN(i, exitFullScreen);
149 ASSIGN(i, requestCenterFitZoom);
150 ASSIGN(i, visibleRect);
151 ASSIGN(i, requestFullScreenOrientation);
152 }
153