dom/plugins/base/android/ANPWindow.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     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"
    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
    20 using namespace mozilla;
    21 using namespace mozilla::widget;
    22 using namespace mozilla::dom;
    24 void
    25 anp_window_setVisibleRects(NPP instance, const ANPRectI rects[], int32_t count)
    26 {
    27   NOT_IMPLEMENTED();
    28 }
    30 void
    31 anp_window_clearVisibleRects(NPP instance)
    32 {
    33   NOT_IMPLEMENTED();
    34 }
    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());
    44   InputContextAction action;
    45   action.mCause = InputContextAction::CAUSE_UNKNOWN;
    46   action.mFocusChange = InputContextAction::FOCUS_NOT_CHANGED;
    48   nsWindow* window = nsWindow::TopWindow();
    49   if (!window) {
    50     LOG("Couldn't get top window?");
    51     return;
    52   }
    54   window->SetInputContext(context, action);
    55 }
    57 void
    58 anp_window_requestFullScreen(NPP instance)
    59 {
    60   nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    62   nsRefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
    63   if (!owner) {
    64     return;
    65   }
    67   owner->RequestFullScreen();
    68 }
    70 void
    71 anp_window_exitFullScreen(NPP instance)
    72 {
    73   nsNPAPIPluginInstance* inst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    75   nsRefPtr<nsPluginInstanceOwner> owner = inst->GetOwner();
    76   if (!owner) {
    77     return;
    78   }
    80   owner->ExitFullScreen();
    81 }
    83 void
    84 anp_window_requestCenterFitZoom(NPP instance)
    85 {
    86   NOT_IMPLEMENTED();
    87 }
    89 ANPRectI
    90 anp_window_visibleRect(NPP instance)
    91 {
    92   ANPRectI rect = { 0, 0, 0, 0 };
    94   nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
    96   nsIntSize currentSize = pinst->CurrentSize();
    97   rect.left = rect.top = 0;
    98   rect.right = currentSize.width;
    99   rect.bottom = currentSize.height;
   101   return rect;
   102 }
   104 void anp_window_requestFullScreenOrientation(NPP instance, ANPScreenOrientation orientation)
   105 {
   106   short newOrientation;
   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   }
   129   nsNPAPIPluginInstance* pinst = static_cast<nsNPAPIPluginInstance*>(instance->ndata);
   130   pinst->SetFullScreenOrientation(newOrientation);
   131 }
   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 }
   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 }
   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 }

mercurial