1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_WINDOW_SCENE_JS_SCREEN_SESSION_H 17 #define OHOS_WINDOW_SCENE_JS_SCREEN_SESSION_H 18 19 #include <map> 20 21 #include <native_engine/native_engine.h> 22 #include <native_engine/native_value.h> 23 #include "session/screen/include/screen_session.h" 24 #include "screen_scene.h" 25 26 namespace OHOS::Rosen { 27 class JsScreenSession : public IScreenChangeListener { 28 public: 29 JsScreenSession(napi_env env, const sptr<ScreenSession>& screenSession); 30 virtual ~JsScreenSession(); 31 32 static napi_value Create(napi_env env, const sptr<ScreenSession>& screenSession); 33 static void Finalizer(napi_env env, void* data, void* hint); 34 35 private: 36 static napi_value LoadContent(napi_env env, napi_callback_info info); 37 napi_value OnLoadContent(napi_env env, napi_callback_info info); 38 napi_value ScheduleLoadContentTask(napi_env env, const std::string& contentUrl, 39 std::weak_ptr<AbilityRuntime::Context> contextWeakPtr, std::shared_ptr<NativeReference> contentStorage); 40 static napi_value RegisterCallback(napi_env env, napi_callback_info info); 41 napi_value OnRegisterCallback(napi_env env, napi_callback_info info); 42 static napi_value SetScreenRotationLocked(napi_env env, napi_callback_info info); 43 napi_value OnSetScreenRotationLocked(napi_env env, napi_callback_info info); 44 static napi_value SetTouchEnabled(napi_env env, napi_callback_info info); 45 napi_value OnSetTouchEnabled(napi_env env, napi_callback_info info); 46 void CallJsCallback(const std::string& callbackType); 47 void RegisterScreenChangeListener(); 48 void UnRegisterScreenChangeListener(); 49 50 void OnConnect(ScreenId screenId) override; 51 void OnDisconnect(ScreenId screenId) override; 52 void OnPropertyChange(const ScreenProperty& newProperty, ScreenPropertyChangeReason reason, 53 ScreenId screenId) override; 54 void OnPowerStatusChange(DisplayPowerEvent event, EventStatus eventStatus, 55 PowerStateChangeReason reason) override; 56 void OnSensorRotationChange(float sensorRotation, ScreenId screenId) override; 57 void OnScreenOrientationChange(float screenOrientation, ScreenId screenId) override; 58 void OnScreenRotationLockedChange(bool isLocked, ScreenId screenId) override; 59 void OnScreenDensityChange(); 60 void OnHoverStatusChange(int32_t hoverStatus, ScreenId screenId) override; 61 void OnScreenCaptureNotify(ScreenId mainScreenId, int32_t uid, const std::string& clientName) override; 62 63 napi_env env_; 64 sptr<ScreenSession> screenSession_; 65 sptr<ScreenScene> screenScene_ = nullptr; 66 std::map<std::string, std::shared_ptr<NativeReference>> mCallback_; 67 }; 68 } // namespace OHOS::Rosen 69 70 #endif // OHOS_WINDOW_SCENE_JS_SCREEN_SESSION_H 71