1 /* 2 * Copyright (c) 2023-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_JS_EXTENSION_WINDOW_LISTENER_H 17 #define OHOS_JS_EXTENSION_WINDOW_LISTENER_H 18 19 #include <map> 20 #include <mutex> 21 22 #include "class_var_definition.h" 23 #include "native_engine/native_engine.h" 24 #include "native_engine/native_value.h" 25 #include "refbase.h" 26 #include "window.h" 27 #include "window_manager.h" 28 #include "wm_common.h" 29 #include "js_extension_window_utils.h" 30 #include "js_window_utils.h" 31 32 namespace OHOS { 33 namespace Rosen { 34 class JsExtensionWindowListener : public IWindowChangeListener, 35 public IWindowRectChangeListener, 36 public IAvoidAreaChangedListener, 37 public IWindowLifeCycle, 38 public IOccupiedAreaChangeListener { 39 public: JsExtensionWindowListener(napi_env env,std::shared_ptr<NativeReference> callback)40 JsExtensionWindowListener(napi_env env, std::shared_ptr<NativeReference> callback) 41 : env_(env), jsCallBack_(callback), weakRef_(wptr<JsExtensionWindowListener> (this)) { 42 } 43 ~JsExtensionWindowListener(); 44 void OnSizeChange(Rect rect, WindowSizeChangeReason reason, 45 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override; 46 void OnRectChange(Rect rect, WindowSizeChangeReason reason) override; 47 void OnModeChange(WindowMode mode, bool hasDeco) override; 48 void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override; 49 void AfterForeground() override; 50 void AfterBackground() override; 51 void AfterFocused() override; 52 void AfterUnfocused() override; 53 void AfterResumed() override; 54 void AfterPaused() override; 55 void AfterDestroyed() override; 56 void OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info, 57 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override; 58 void CallJsMethod(const char* methodName, napi_value const * argv = nullptr, size_t argc = 0); 59 void SetMainEventHandler(); 60 61 private: 62 Rect currRect_; 63 napi_env env_ = nullptr; 64 WindowState state_ {WindowState::STATE_INITIAL}; 65 std::shared_ptr<NativeReference> jsCallBack_; 66 wptr<JsExtensionWindowListener> weakRef_ = nullptr; 67 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr; 68 DEFINE_VAR_DEFAULT_FUNC_SET(bool, IsDeprecatedInterface, isDeprecatedInterface, false) 69 }; 70 } // namespace Rosen 71 } // namespace OHOS 72 #endif // OHOS_JS_EXTENSION_WINDOW_LISTENER_H 73