1 /*
2  * Copyright (c) 2021 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_ABILITY_COMPONENT_RESOURCE_ABILITY_COMPONENT_DELEGATE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_RESOURCE_ABILITY_COMPONENT_DELEGATE_H
18 
19 #include "core/components/ability_component/ability_component.h"
20 #include "core/components/ability_component/resource/ability_component_resource.h"
21 #include "core/components/common/layout/constants.h"
22 
23 namespace OHOS::Ace {
24 
25 class AbilityComponentDelegate : public AbilityComponentResource {
26     DECLARE_ACE_TYPE(AbilityComponentDelegate, AbilityComponentResource);
27 
28 public:
29     enum class State : char {
30         WAITING_FOR_SIZE,
31         CREATING,
32         CREATED,
33         CREATE_FAILED,
34         RELEASED,
35     };
36 
37     AbilityComponentDelegate() = delete;
38     ~AbilityComponentDelegate() override;
39     AbilityComponentDelegate(const RefPtr<AbilityComponent>& abilityComponent, const WeakPtr<PipelineContext>& context,
40         const std::string& type);
41 
42     void CreatePlatformResource(const WeakPtr<PipelineContext>& context, const Rect& rect);
43     void ReleasePlatformResource();
44     void UpdateRenderRect(const Rect& rect);
45 
46 private:
47     void CreatePluginResource(const WeakPtr<PipelineContext>& context, const Rect& rect);
48     void Stop();
49     void RegisterEvent();
50     void UnregisterEvent();
51     void InitControllerImpl();
52 
53     // Events of ability component.
54     void OnReady() const;
55     void OnDestroy() const;
56     void OnAbilityCreated(const std::string& param) const;
57     void OnAbilityMovedFront() const;
58     void OnAbilityWillRemove() const;
59 
60     // Implement of methods of ability component.
61     void StartAbility(const std::string& want);
62     void PerformBackPress();
63     int32_t GetStackCount();
64 
65     RefPtr<AbilityComponent> abilityComponent_;
66     State state_ { State::WAITING_FOR_SIZE };
67 };
68 
69 } // namespace OHOS::Ace
70 
71 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_ABILITY_COMPONENT_RESOURCE_ABILITY_COMPONENT_DELEGATE_H
72