dom/plugins/base/android/ANPWindow.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/base/android/ANPWindow.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,165 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "base/basictypes.h"
    1.10 +#include "assert.h"
    1.11 +#include "ANPBase.h"
    1.12 +#include <android/log.h>
    1.13 +#include "AndroidBridge.h"
    1.14 +#include "nsNPAPIPluginInstance.h"
    1.15 +#include "nsPluginInstanceOwner.h"
    1.16 +#include "nsWindow.h"
    1.17 +#include "mozilla/dom/ScreenOrientation.h"
    1.18 +
    1.19 +#undef LOG
    1.20 +#define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
    1.21 +#define ASSIGN(obj, name)   (obj)->name = anp_window_##name
    1.22 +
    1.23 +using namespace mozilla;
    1.24 +using namespace mozilla::widget;
    1.25 +using namespace mozilla::dom;
    1.26 +
    1.27 +void
    1.28 +anp_window_setVisibleRects(NPP instance, const ANPRectI rects[], int32_t count)
    1.29 +{
    1.30 +  NOT_IMPLEMENTED();
    1.31 +}
    1.32 +
    1.33 +void
    1.34 +anp_window_clearVisibleRects(NPP instance)
    1.35 +{
    1.36 +  NOT_IMPLEMENTED();
    1.37 +}
    1.38 +
    1.39 +void
    1.40 +anp_window_showKeyboard(NPP instance, bool value)
    1.41 +{
    1.42 +  InputContext context;
    1.43 +  context.mIMEState.mEnabled = value ? IMEState::PLUGIN : IMEState::DISABLED;
    1.44 +  context.mIMEState.mOpen = value ? IMEState::OPEN : IMEState::CLOSED;
    1.45 +  context.mActionHint.Assign(EmptyString());
    1.46 +
    1.47 +  InputContextAction action;
    1.48 +  action.mCause = InputContextAction::CAUSE_UNKNOWN;
    1.49 +  action.mFocusChange = InputContextAction::FOCUS_NOT_CHANGED;
    1.50 +
    1.51 +  nsWindow* window = nsWindow::TopWindow();
    1.52 +  if (!window) {
    1.53 +    LOG("Couldn't get top window?");
    1.54 +    return;
    1.55 +  }
    1.56 +
    1.57 +  window->SetInputContext(context, action);
    1.58 +}
    1.59 +
    1.60 +void
    1.61 +anp_window_requestFullScreen(NPP instance)
    1.62 +{
    1.63 +  nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    1.64 +
    1.65 +  nsRefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
    1.66 +  if (!owner) {
    1.67 +    return;
    1.68 +  }
    1.69 +
    1.70 +  owner->RequestFullScreen();
    1.71 +}
    1.72 +
    1.73 +void
    1.74 +anp_window_exitFullScreen(NPP instance)
    1.75 +{
    1.76 +  nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    1.77 +
    1.78 +  nsRefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
    1.79 +  if (!owner) {
    1.80 +    return;
    1.81 +  }
    1.82 +
    1.83 +  owner->ExitFullScreen();
    1.84 +}
    1.85 +
    1.86 +void
    1.87 +anp_window_requestCenterFitZoom(NPP instance)
    1.88 +{
    1.89 +  NOT_IMPLEMENTED();
    1.90 +}
    1.91 +
    1.92 +ANPRectI
    1.93 +anp_window_visibleRect(NPP instance)
    1.94 +{
    1.95 +  ANPRectI rect = { 0, 0, 0, 0 };
    1.96 +
    1.97 +  nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    1.98 +
    1.99 +  nsIntSize currentSize = pinst->CurrentSize();
   1.100 +  rect.left = rect.top = 0;
   1.101 +  rect.right = currentSize.width;
   1.102 +  rect.bottom = currentSize.height;
   1.103 +
   1.104 +  return rect;
   1.105 +}
   1.106 +
   1.107 +void anp_window_requestFullScreenOrientation(NPP instance, ANPScreenOrientation orientation)
   1.108 +{
   1.109 +  short newOrientation;
   1.110 +
   1.111 +  // Convert to the ActivityInfo equivalent
   1.112 +  switch (orientation) {
   1.113 +    case kFixedLandscape_ANPScreenOrientation:
   1.114 +      newOrientation = eScreenOrientation_LandscapePrimary;
   1.115 +      break;
   1.116 +    case kFixedPortrait_ANPScreenOrientation:
   1.117 +      newOrientation = eScreenOrientation_PortraitPrimary;
   1.118 +      break;
   1.119 +    case kLandscape_ANPScreenOrientation:
   1.120 +      newOrientation = eScreenOrientation_LandscapePrimary |
   1.121 +                       eScreenOrientation_LandscapeSecondary;
   1.122 +      break;
   1.123 +    case kPortrait_ANPScreenOrientation:
   1.124 +      newOrientation = eScreenOrientation_PortraitPrimary |
   1.125 +                       eScreenOrientation_PortraitSecondary;
   1.126 +      break;
   1.127 +    default:
   1.128 +      newOrientation = eScreenOrientation_None;
   1.129 +      break;
   1.130 +  }
   1.131 +
   1.132 +  nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
   1.133 +  pinst->SetFullScreenOrientation(newOrientation);
   1.134 +}
   1.135 +
   1.136 +void InitWindowInterface(ANPWindowInterfaceV0 *i) {
   1.137 +  _assert(i->inSize == sizeof(*i));
   1.138 +  ASSIGN(i, setVisibleRects);
   1.139 +  ASSIGN(i, clearVisibleRects);
   1.140 +  ASSIGN(i, showKeyboard);
   1.141 +  ASSIGN(i, requestFullScreen);
   1.142 +  ASSIGN(i, exitFullScreen);
   1.143 +  ASSIGN(i, requestCenterFitZoom);
   1.144 +}
   1.145 +
   1.146 +void InitWindowInterfaceV1(ANPWindowInterfaceV1 *i) {
   1.147 +  _assert(i->inSize == sizeof(*i));
   1.148 +  ASSIGN(i, setVisibleRects);
   1.149 +  ASSIGN(i, clearVisibleRects);
   1.150 +  ASSIGN(i, showKeyboard);
   1.151 +  ASSIGN(i, requestFullScreen);
   1.152 +  ASSIGN(i, exitFullScreen);
   1.153 +  ASSIGN(i, requestCenterFitZoom);
   1.154 +  ASSIGN(i, visibleRect);
   1.155 +}
   1.156 +
   1.157 +void InitWindowInterfaceV2(ANPWindowInterfaceV2 *i) {
   1.158 +  _assert(i->inSize == sizeof(*i));
   1.159 +  ASSIGN(i, setVisibleRects);
   1.160 +  ASSIGN(i, clearVisibleRects);
   1.161 +  ASSIGN(i, showKeyboard);
   1.162 +  ASSIGN(i, requestFullScreen);
   1.163 +  ASSIGN(i, exitFullScreen);
   1.164 +  ASSIGN(i, requestCenterFitZoom);
   1.165 +  ASSIGN(i, visibleRect);
   1.166 +  ASSIGN(i, requestFullScreenOrientation);
   1.167 +}
   1.168 +

mercurial