1 /* 2 * Copyright (c) 2021-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 FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_ABILITY_H 17 #define FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_ABILITY_H 18 19 #include <atomic> 20 #include <thread> 21 22 #include "adapter/preview/entrance/ace_run_args.h" 23 #include "adapter/preview/entrance/clipboard/clipboard_impl.h" 24 #include "adapter/preview/entrance/clipboard/clipboard_proxy_impl.h" 25 #include "adapter/preview/external/ability/context.h" 26 #include "adapter/preview/external/ability/fa/fa_context.h" 27 #include "adapter/preview/external/ability/stage/stage_context.h" 28 #include "adapter/preview/external/multimodalinput/axis_event.h" 29 #include "adapter/preview/external/multimodalinput/key_event.h" 30 #include "adapter/preview/external/multimodalinput/pointer_event.h" 31 #include "frameworks/base/utils/macros.h" 32 33 #include <memory> 34 #include <refbase.h> 35 36 namespace OHOS::Rosen { 37 class Window; 38 } 39 40 namespace OHOS::Ace::Platform { 41 42 struct ConfigChanges { 43 bool watchLocale = false; 44 bool watchLayout = false; 45 bool watchFontSize = false; 46 bool watchOrientation = false; 47 bool watchDensity = false; 48 }; 49 50 struct SystemParams { 51 int32_t deviceWidth { 0 }; 52 int32_t deviceHeight { 0 }; 53 bool isRound = false; 54 double density { 1.0 }; 55 std::string language = "zh"; 56 std::string region = "CN"; 57 std::string script = ""; 58 OHOS::Ace::DeviceType deviceType { DeviceType::PHONE }; 59 OHOS::Ace::ColorMode colorMode { ColorMode::LIGHT }; 60 OHOS::Ace::DeviceOrientation orientation { DeviceOrientation::PORTRAIT }; 61 }; 62 63 class ACE_FORCE_EXPORT AceAbility { 64 public: 65 explicit AceAbility(const AceRunArgs& runArgs); 66 ~AceAbility(); 67 68 // Be called in Previewer frontend thread, which is not ACE platform thread. 69 static std::unique_ptr<AceAbility> CreateInstance(AceRunArgs& runArgs); 70 void InitEnv(); 71 void InitializeClipboard() const; 72 void OnBackPressed() const; 73 bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const; 74 bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const; 75 bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const; 76 bool OnInputMethodEvent(const unsigned int codePoint) const; 77 78 void OnConfigurationChanged(const DeviceConfig& newConfig); 79 void SurfaceChanged( 80 const DeviceOrientation& orientation, const double& resolution, int32_t& width, int32_t& height); 81 void ReplacePage(const std::string& url, const std::string& params); 82 void LoadDocument(const std::string& url, const std::string& componentName, SystemParams& systemParams); 83 84 std::string GetJSONTree(); 85 std::string GetDefaultJSONTree(); 86 bool OperateComponent(const std::string& attrsJson); 87 void SetWindow(sptr<OHOS::Rosen::Window> rsWindow); 88 sptr<OHOS::Rosen::Window> GetWindow(); 89 90 private: 91 void InitializeAppInfo(); 92 void SetConfigChanges(const std::string& configChanges); 93 94 AceRunArgs runArgs_; 95 ConfigChanges configChanges_; 96 sptr<OHOS::Rosen::Window> rsWindow_; 97 98 std::string bundleName_; 99 std::string moduleName_; 100 std::string compileMode_; 101 int32_t compatibleVersion_ = 0; 102 bool installationFree_ = false; 103 uint32_t labelId_ = 0; 104 bool useNewPipeline_ = true; 105 }; 106 107 } // namespace OHOS::Ace::Platform 108 109 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_ABILITY_H 110