dom/plugins/base/android/ANPWindow.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:6bc188a17aa7
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 "AndroidBridge.h"
11 #include "nsNPAPIPluginInstance.h"
12 #include "nsPluginInstanceOwner.h"
13 #include "nsWindow.h"
14 #include "mozilla/dom/ScreenOrientation.h"
15
16 #undef LOG
17 #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
18 #define ASSIGN(obj, name) (obj)->name = anp_window_##name
19
20 using namespace mozilla;
21 using namespace mozilla::widget;
22 using namespace mozilla::dom;
23
24 void
25 anp_window_setVisibleRects(NPP instance, const ANPRectI rects[], int32_t count)
26 {
27 NOT_IMPLEMENTED();
28 }
29
30 void
31 anp_window_clearVisibleRects(NPP instance)
32 {
33 NOT_IMPLEMENTED();
34 }
35
36 void
37 anp_window_showKeyboard(NPP instance, bool value)
38 {
39 InputContext context;
40 context.mIMEState.mEnabled = value ? IMEState::PLUGIN : IMEState::DISABLED;
41 context.mIMEState.mOpen = value ? IMEState::OPEN : IMEState::CLOSED;
42 context.mActionHint.Assign(EmptyString());
43
44 InputContextAction action;
45 action.mCause = InputContextAction::CAUSE_UNKNOWN;
46 action.mFocusChange = InputContextAction::FOCUS_NOT_CHANGED;
47
48 nsWindow* window = nsWindow::TopWindow();
49 if (!window) {
50 LOG("Couldn't get top window?");
51 return;
52 }
53
54 window->SetInputContext(context, action);
55 }
56
57 void
58 anp_window_requestFullScreen(NPP instance)
59 {
60 nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
61
62 nsRefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
63 if (!owner) {
64 return;
65 }
66
67 owner->RequestFullScreen();
68 }
69
70 void
71 anp_window_exitFullScreen(NPP instance)
72 {
73 nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
74
75 nsRefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
76 if (!owner) {
77 return;
78 }
79
80 owner->ExitFullScreen();
81 }
82
83 void
84 anp_window_requestCenterFitZoom(NPP instance)
85 {
86 NOT_IMPLEMENTED();
87 }
88
89 ANPRectI
90 anp_window_visibleRect(NPP instance)
91 {
92 ANPRectI rect = { 0, 0, 0, 0 };
93
94 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
95
96 nsIntSize currentSize = pinst->CurrentSize();
97 rect.left = rect.top = 0;
98 rect.right = currentSize.width;
99 rect.bottom = currentSize.height;
100
101 return rect;
102 }
103
104 void anp_window_requestFullScreenOrientation(NPP instance, ANPScreenOrientation orientation)
105 {
106 short newOrientation;
107
108 // Convert to the ActivityInfo equivalent
109 switch (orientation) {
110 case kFixedLandscape_ANPScreenOrientation:
111 newOrientation = eScreenOrientation_LandscapePrimary;
112 break;
113 case kFixedPortrait_ANPScreenOrientation:
114 newOrientation = eScreenOrientation_PortraitPrimary;
115 break;
116 case kLandscape_ANPScreenOrientation:
117 newOrientation = eScreenOrientation_LandscapePrimary |
118 eScreenOrientation_LandscapeSecondary;
119 break;
120 case kPortrait_ANPScreenOrientation:
121 newOrientation = eScreenOrientation_PortraitPrimary |
122 eScreenOrientation_PortraitSecondary;
123 break;
124 default:
125 newOrientation = eScreenOrientation_None;
126 break;
127 }
128
129 nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
130 pinst->SetFullScreenOrientation(newOrientation);
131 }
132
133 void InitWindowInterface(ANPWindowInterfaceV0 *i) {
134 _assert(i->inSize == sizeof(*i));
135 ASSIGN(i, setVisibleRects);
136 ASSIGN(i, clearVisibleRects);
137 ASSIGN(i, showKeyboard);
138 ASSIGN(i, requestFullScreen);
139 ASSIGN(i, exitFullScreen);
140 ASSIGN(i, requestCenterFitZoom);
141 }
142
143 void InitWindowInterfaceV1(ANPWindowInterfaceV1 *i) {
144 _assert(i->inSize == sizeof(*i));
145 ASSIGN(i, setVisibleRects);
146 ASSIGN(i, clearVisibleRects);
147 ASSIGN(i, showKeyboard);
148 ASSIGN(i, requestFullScreen);
149 ASSIGN(i, exitFullScreen);
150 ASSIGN(i, requestCenterFitZoom);
151 ASSIGN(i, visibleRect);
152 }
153
154 void InitWindowInterfaceV2(ANPWindowInterfaceV2 *i) {
155 _assert(i->inSize == sizeof(*i));
156 ASSIGN(i, setVisibleRects);
157 ASSIGN(i, clearVisibleRects);
158 ASSIGN(i, showKeyboard);
159 ASSIGN(i, requestFullScreen);
160 ASSIGN(i, exitFullScreen);
161 ASSIGN(i, requestCenterFitZoom);
162 ASSIGN(i, visibleRect);
163 ASSIGN(i, requestFullScreenOrientation);
164 }
165

mercurial