• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <map>
21 #include <memory>
22 #include <refbase.h>
23 #include <string>
24 #include <thread>
25 
26 #include "adapter/preview/entrance/ace_run_args.h"
27 #include "adapter/preview/entrance/clipboard/clipboard_impl.h"
28 #include "adapter/preview/entrance/clipboard/clipboard_proxy_impl.h"
29 #include "adapter/preview/external/ability/context.h"
30 #include "adapter/preview/external/ability/fa/fa_context.h"
31 #include "adapter/preview/external/ability/stage/stage_context.h"
32 #include "adapter/preview/external/multimodalinput/axis_event.h"
33 #include "adapter/preview/external/multimodalinput/key_event.h"
34 #include "adapter/preview/external/multimodalinput/pointer_event.h"
35 #include "frameworks/base/utils/macros.h"
36 #include "frameworks/core/common/window_animation_config.h"
37 
38 namespace OHOS::Rosen {
39 class Window;
40 class IAvoidAreaChangedListener;
41 class IIgnoreViewSafeAreaListener;
42 }
43 
44 namespace OHOS::Ace::Platform {
45 
46 class ACE_FORCE_EXPORT AceAbility {
47 public:
48     explicit AceAbility(const AceRunArgs& runArgs);
49     ~AceAbility();
50 
51     // Be called in Previewer frontend thread, which is not ACE platform thread.
52     static std::unique_ptr<AceAbility> CreateInstance(AceRunArgs& runArgs);
53     void SetMockModuleList(const std::map<std::string, std::string>& mockJsonInfo);
54     void InitEnv();
55     void InitializeClipboard() const;
56     void OnBackPressed() const;
57     bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const;
58     bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const;
59     bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const;
60     bool OnInputMethodEvent(const unsigned int codePoint) const;
61 
62     void OnConfigurationChanged(const DeviceConfig& newConfig);
63     void SurfaceChanged(
64         const DeviceOrientation& orientation, const double& resolution, int32_t& width, int32_t& height,
65         WindowSizeChangeReason type = WindowSizeChangeReason::UNDEFINED);
66     void ReplacePage(const std::string& url, const std::string& params);
67     void LoadDocument(const std::string& url, const std::string& componentName, SystemParams& systemParams);
68 
69     std::string GetJSONTree();
70     std::string GetDefaultJSONTree();
71     bool OperateComponent(const std::string& attrsJson);
72     void SetWindow(sptr<OHOS::Rosen::Window> rsWindow);
73     sptr<OHOS::Rosen::Window> GetWindow();
74 
GetBundleName()75     std::string GetBundleName()
76     {
77         return bundleName_;
78     }
79 
GetModuleName()80     std::string GetModuleName()
81     {
82         return moduleName_;
83     }
84 
85 private:
86     void InitializeAppInfo();
87     void SetConfigChanges(const std::string& configChanges);
88 
89     AceRunArgs runArgs_;
90     ConfigChanges configChanges_;
91     sptr<OHOS::Rosen::Window> rsWindow_;
92     sptr<OHOS::Rosen::IAvoidAreaChangedListener> avoidAreaChangedListener_;
93     sptr<OHOS::Rosen::IIgnoreViewSafeAreaListener> ignoreViewSafeAreaListener_;
94 
95     std::string bundleName_;
96     std::string moduleName_;
97     std::string compileMode_;
98     int32_t compatibleVersion_ = 0;
99     bool installationFree_ = false;
100     uint32_t labelId_ = 0;
101     bool useNewPipeline_ = true;
102 };
103 
104 } // namespace OHOS::Ace::Platform
105 
106 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_ACE_ABILITY_H
107