• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_RENDER_ABILITY_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_RENDER_ABILITY_COMPONENT_H
18 
19 #include <string>
20 
21 #include "base/geometry/rect.h"
22 #include "core/common/window/window_extension_connection_proxy.h"
23 #include "core/components_v2/ability_component/ability_component.h"
24 #include "core/pipeline/base/render_node.h"
25 
26 namespace OHOS::Ace::V2 {
27 class RenderAbilityComponent : public RenderNode {
28     DECLARE_ACE_TYPE(V2::RenderAbilityComponent, RenderNode);
29 
30 public:
31     ~RenderAbilityComponent() override;
32 
33     static RefPtr<RenderNode> Create();
34     void Update(const RefPtr<Component>& component) override;
35     void PerformLayout() override;
36     void Paint(RenderContext &context, const Offset &offset) override;
OnAppShow()37     void OnAppShow() override
38     {
39         if (adapter_) {
40             adapter_->Show();
41         }
42     }
43 
OnAppHide()44     void OnAppHide() override
45     {
46         if (adapter_) {
47             adapter_->Hide();
48         }
49     }
50 
FireConnect()51     void FireConnect()
52     {
53         if (adapter_) {
54             adapter_->UpdateRect(currentRect_);
55         }
56         hasConnectionToAbility_ = true;
57         if (component_) {
58             component_->FireOnConnected();
59         } else {
60             LOGI("ability component fire event fail");
61         }
62     }
63 
FireDisconnect()64     void FireDisconnect()
65     {
66         hasConnectionToAbility_ = false;
67         if (component_) {
68             component_->FireOnDisconnected();
69         } else {
70             LOGI("ability component fire event fail");
71         }
72     }
73 
74     void ConnectOrUpdateExtension();
75 
76     void OnPaintFinish() override;
77 
78 private:
79     Rect currentRect_;
80     bool needLayout_ = false;
81     bool hasConnectionToAbility_ = false;
82     int32_t callbackId_ = 0;
83     Dimension width_;
84     Dimension height_;
85     Offset globalOffsetExternal_;
86 
87     RefPtr<WindowExtensionConnectionAdapter> adapter_;
88     RefPtr<V2::AbilityComponent> component_;
89 };
90 } // namespace OHOS::Ace::V2
91 
92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_ABILITY_COMPONENT_RENDER_ABILITY_COMPONENT_H
93