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