1 /* 2 * Copyright (c) 2021-2022 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_WINDOW_LISTENER_H 17 #define OHOS_JS_WINDOW_LISTENER_H 18 19 #include <map> 20 #include <mutex> 21 #include "js_window_utils.h" 22 #include "native_engine/native_engine.h" 23 #include "native_engine/native_value.h" 24 #include "refbase.h" 25 #include "window.h" 26 #include "window_manager.h" 27 #include "wm_common.h" 28 29 namespace OHOS { 30 namespace Rosen { 31 const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange"; 32 const std::string SYSTEM_BAR_TINT_CHANGE_CB = "systemBarTintChange"; 33 const std::string SYSTEM_AVOID_AREA_CHANGE_CB = "systemAvoidAreaChange"; 34 const std::string LIFECYCLE_EVENT_CB = "lifeCycleEvent"; 35 const std::string WINDOW_STAGE_EVENT_CB = "windowStageEvent"; 36 const std::string KEYBOARD_HEIGHT_CHANGE_CB = "keyboardHeightChange"; 37 38 class JsWindowListener : public IWindowChangeListener, 39 public ISystemBarChangedListener, 40 public IAvoidAreaChangedListener, 41 public IWindowLifeCycle, 42 public IOccupiedAreaChangeListener { 43 public: JsWindowListener(NativeEngine * engine,std::shared_ptr<NativeReference> callback)44 JsWindowListener(NativeEngine* engine, std::shared_ptr<NativeReference> callback) 45 : engine_(engine), jsCallBack_(callback) {} 46 virtual ~JsWindowListener() = default; 47 void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override; 48 void OnSizeChange(Rect rect, WindowSizeChangeReason reason) override; 49 void OnModeChange(WindowMode mode) override; 50 void OnAvoidAreaChanged(std::vector<Rect> avoidAreas) override; 51 void AfterForeground() override; 52 void AfterBackground() override; 53 void AfterFocused() override; 54 void AfterUnfocused() override; 55 void OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info) override; 56 private: 57 void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0); 58 void LifeCycleCallBack(LifeCycleEventType eventType); 59 NativeEngine* engine_ = nullptr; 60 std::shared_ptr<NativeReference> jsCallBack_ = nullptr; 61 }; 62 } // namespace Rosen 63 } // namespace OHOS 64 #endif /* OHOS_JS_WINDOW_LISTENER_H */