michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "base/basictypes.h" michael@0: #include "assert.h" michael@0: #include "ANPBase.h" michael@0: #include michael@0: #include "AndroidBridge.h" michael@0: #include "nsNPAPIPluginInstance.h" michael@0: #include "nsPluginInstanceOwner.h" michael@0: #include "nsWindow.h" michael@0: #include "mozilla/dom/ScreenOrientation.h" michael@0: michael@0: #undef LOG michael@0: #define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args) michael@0: #define ASSIGN(obj, name) (obj)->name = anp_window_##name michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::widget; michael@0: using namespace mozilla::dom; michael@0: michael@0: void michael@0: anp_window_setVisibleRects(NPP instance, const ANPRectI rects[], int32_t count) michael@0: { michael@0: NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: void michael@0: anp_window_clearVisibleRects(NPP instance) michael@0: { michael@0: NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: void michael@0: anp_window_showKeyboard(NPP instance, bool value) michael@0: { michael@0: InputContext context; michael@0: context.mIMEState.mEnabled = value ? IMEState::PLUGIN : IMEState::DISABLED; michael@0: context.mIMEState.mOpen = value ? IMEState::OPEN : IMEState::CLOSED; michael@0: context.mActionHint.Assign(EmptyString()); michael@0: michael@0: InputContextAction action; michael@0: action.mCause = InputContextAction::CAUSE_UNKNOWN; michael@0: action.mFocusChange = InputContextAction::FOCUS_NOT_CHANGED; michael@0: michael@0: nsWindow* window = nsWindow::TopWindow(); michael@0: if (!window) { michael@0: LOG("Couldn't get top window?"); michael@0: return; michael@0: } michael@0: michael@0: window->SetInputContext(context, action); michael@0: } michael@0: michael@0: void michael@0: anp_window_requestFullScreen(NPP instance) michael@0: { michael@0: nsNPAPIPluginInstance* inst = static_cast(instance->ndata); michael@0: michael@0: nsRefPtr owner = inst->GetOwner(); michael@0: if (!owner) { michael@0: return; michael@0: } michael@0: michael@0: owner->RequestFullScreen(); michael@0: } michael@0: michael@0: void michael@0: anp_window_exitFullScreen(NPP instance) michael@0: { michael@0: nsNPAPIPluginInstance* inst = static_cast(instance->ndata); michael@0: michael@0: nsRefPtr owner = inst->GetOwner(); michael@0: if (!owner) { michael@0: return; michael@0: } michael@0: michael@0: owner->ExitFullScreen(); michael@0: } michael@0: michael@0: void michael@0: anp_window_requestCenterFitZoom(NPP instance) michael@0: { michael@0: NOT_IMPLEMENTED(); michael@0: } michael@0: michael@0: ANPRectI michael@0: anp_window_visibleRect(NPP instance) michael@0: { michael@0: ANPRectI rect = { 0, 0, 0, 0 }; michael@0: michael@0: nsNPAPIPluginInstance* pinst = static_cast(instance->ndata); michael@0: michael@0: nsIntSize currentSize = pinst->CurrentSize(); michael@0: rect.left = rect.top = 0; michael@0: rect.right = currentSize.width; michael@0: rect.bottom = currentSize.height; michael@0: michael@0: return rect; michael@0: } michael@0: michael@0: void anp_window_requestFullScreenOrientation(NPP instance, ANPScreenOrientation orientation) michael@0: { michael@0: short newOrientation; michael@0: michael@0: // Convert to the ActivityInfo equivalent michael@0: switch (orientation) { michael@0: case kFixedLandscape_ANPScreenOrientation: michael@0: newOrientation = eScreenOrientation_LandscapePrimary; michael@0: break; michael@0: case kFixedPortrait_ANPScreenOrientation: michael@0: newOrientation = eScreenOrientation_PortraitPrimary; michael@0: break; michael@0: case kLandscape_ANPScreenOrientation: michael@0: newOrientation = eScreenOrientation_LandscapePrimary | michael@0: eScreenOrientation_LandscapeSecondary; michael@0: break; michael@0: case kPortrait_ANPScreenOrientation: michael@0: newOrientation = eScreenOrientation_PortraitPrimary | michael@0: eScreenOrientation_PortraitSecondary; michael@0: break; michael@0: default: michael@0: newOrientation = eScreenOrientation_None; michael@0: break; michael@0: } michael@0: michael@0: nsNPAPIPluginInstance* pinst = static_cast(instance->ndata); michael@0: pinst->SetFullScreenOrientation(newOrientation); michael@0: } michael@0: michael@0: void InitWindowInterface(ANPWindowInterfaceV0 *i) { michael@0: _assert(i->inSize == sizeof(*i)); michael@0: ASSIGN(i, setVisibleRects); michael@0: ASSIGN(i, clearVisibleRects); michael@0: ASSIGN(i, showKeyboard); michael@0: ASSIGN(i, requestFullScreen); michael@0: ASSIGN(i, exitFullScreen); michael@0: ASSIGN(i, requestCenterFitZoom); michael@0: } michael@0: michael@0: void InitWindowInterfaceV1(ANPWindowInterfaceV1 *i) { michael@0: _assert(i->inSize == sizeof(*i)); michael@0: ASSIGN(i, setVisibleRects); michael@0: ASSIGN(i, clearVisibleRects); michael@0: ASSIGN(i, showKeyboard); michael@0: ASSIGN(i, requestFullScreen); michael@0: ASSIGN(i, exitFullScreen); michael@0: ASSIGN(i, requestCenterFitZoom); michael@0: ASSIGN(i, visibleRect); michael@0: } michael@0: michael@0: void InitWindowInterfaceV2(ANPWindowInterfaceV2 *i) { michael@0: _assert(i->inSize == sizeof(*i)); michael@0: ASSIGN(i, setVisibleRects); michael@0: ASSIGN(i, clearVisibleRects); michael@0: ASSIGN(i, showKeyboard); michael@0: ASSIGN(i, requestFullScreen); michael@0: ASSIGN(i, exitFullScreen); michael@0: ASSIGN(i, requestCenterFitZoom); michael@0: ASSIGN(i, visibleRect); michael@0: ASSIGN(i, requestFullScreenOrientation); michael@0: } michael@0: