• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H
18 
19 #include "ability_info.h"
20 #include "interfaces/innerkits/ace/ui_content.h"
21 #include "interfaces/innerkits/ace/viewport_config.h"
22 #include "key_event.h"
23 #include "native_engine/native_value.h"
24 #include "native_engine/native_engine.h"
25 
26 #include "base/utils/macros.h"
27 #include "wm/window.h"
28 
29 namespace OHOS {
30 
31 class Window;
32 
33 } // namespace OHOS
34 
35 namespace OHOS::Ace {
36 
37 class ACE_FORCE_EXPORT UIContentImpl : public UIContent {
38 public:
39     UIContentImpl(OHOS::AbilityRuntime::Context* context, void* runtime);
40     UIContentImpl(OHOS::AppExecFwk::Ability* ability);
41     ~UIContentImpl() = default;
42 
43     // UI content lifecycles
44     void Initialize(OHOS::Rosen::Window* window, const std::string& url, NativeValue* storage) override;
45     void Foreground() override;
46     void Background() override;
47     void Focus() override;
48     void UnFocus() override;
49     void Destroy() override;
50 
51     // distribute
52     void Restore(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage) override;
53     std::string GetContentInfo() const override;
54 
55     // UI content event process
56     bool ProcessBackPressed() override;
57     bool ProcessPointerEvent(const std::shared_ptr<OHOS::MMI::PointerEvent>& pointerEvent) override;
58     bool ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>& keyEvent) override;
59     bool ProcessAxisEvent(const std::shared_ptr<OHOS::MMI::AxisEvent>& axisEvent) override;
60     bool ProcessVsyncEvent(uint64_t timeStampNanos) override;
61     void UpdateConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config) override;
62     void UpdateViewportConfig(const ViewportConfig& config, OHOS::Rosen::WindowSizeChangeReason reason) override;
63     void UpdateWindowMode(OHOS::Rosen::WindowMode mode) override;
64 
65     // Window color
66     uint32_t GetBackgroundColor() override;
67     void SetBackgroundColor(uint32_t color) override;
68 
69     void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;
70 
71 private:
72     void CommonInitialize(OHOS::Rosen::Window* window, const std::string& contentInfo, NativeValue* storage);
73     void InitWindowCallback(const std::shared_ptr<OHOS::AppExecFwk::AbilityInfo>& info);
74     void InitializeSubWindow(OHOS::Rosen::Window* window);
75     std::weak_ptr<OHOS::AbilityRuntime::Context> context_;
76     void* runtime_ = nullptr;
77     OHOS::Rosen::Window* window_ = nullptr;
78     ViewportConfig config_;
79     std::string startUrl_;
80     int32_t instanceId_ = -1;
81     bool updateConfig_ = false;
82     OHOS::sptr<OHOS::Rosen::IWindowDragListener> dragWindowListener_ = nullptr;
83     OHOS::sptr<OHOS::Rosen::IOccupiedAreaChangeListener> occupiedAreaChangeListener_ = nullptr;
84 };
85 
86 } // namespace OHOS::Ace
87 
88 #endif // FOUNDATION_ACE_ADAPTER_OHOS_ENTRANCE_ACE_UI_CONTENT_IMPL_H
89