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_NG_PATTERNS_ABILITY_COMPONENT_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ABILITY_COMPONENT_PATTERN_H 18 19 #include "frameworks/base/geometry/rect.h" 20 #include "frameworks/base/memory/referenced.h" 21 #include "frameworks/core/common/window_ng/window_extension_connection_proxy_ng.h" 22 #include "frameworks/core/components_ng/pattern/ability_component/ability_component_event_hub.h" 23 #include "frameworks/core/components_ng/pattern/ability_component/ability_component_layout_algorithm.h" 24 #include "frameworks/core/components_ng/pattern/ability_component/ability_component_render_property.h" 25 #include "frameworks/core/components_ng/pattern/pattern.h" 26 #include "frameworks/core/components_ng/property/property.h" 27 #include "frameworks/core/components_ng/render/canvas_image.h" 28 29 namespace OHOS::Ace::NG { 30 31 class ACE_EXPORT AbilityComponentPattern : public Pattern { 32 DECLARE_ACE_TYPE(AbilityComponentPattern, Pattern); 33 34 public: 35 AbilityComponentPattern() = default; ~AbilityComponentPattern()36 ~AbilityComponentPattern() override 37 { 38 if (adapter_) { 39 adapter_->RemoveExtension(); 40 } 41 } 42 CreatePaintProperty()43 RefPtr<PaintProperty> CreatePaintProperty() override 44 { 45 return MakeRefPtr<AbilityComponentRenderProperty>(); 46 } 47 CreateEventHub()48 RefPtr<EventHub> CreateEventHub() override 49 { 50 return MakeRefPtr<AbilityComponentEventHub>(); 51 } 52 CreateLayoutAlgorithm()53 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 54 { 55 return MakeRefPtr<AbilityComponentLayoutAlgorithm>(); 56 } 57 58 void OnModifyDone() override; 59 void FireConnect(); 60 void FireDisConnect(); 61 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 62 void OnAreaChangedInner() override; 63 private: OnActive()64 void OnActive() override 65 { 66 if (!isActive_) { 67 if (adapter_) { 68 adapter_->Show(); 69 } 70 isActive_ = true; 71 } 72 } 73 OnInActive()74 void OnInActive() override 75 { 76 if (isActive_) { 77 if (adapter_) { 78 adapter_->Hide(); 79 } 80 isActive_ = false; 81 } 82 } 83 OnWindowShow()84 void OnWindowShow() override 85 { 86 if (!isActive_) { 87 if (adapter_) { 88 adapter_->Show(); 89 } 90 isActive_ = true; 91 } 92 } 93 OnWindowHide()94 void OnWindowHide() override 95 { 96 if (isActive_) { 97 if (adapter_) { 98 adapter_->Hide(); 99 } 100 isActive_ = false; 101 } 102 } 103 104 void UpdateWindowRect(); 105 bool isActive_ = false; 106 bool hasConnectionToAbility_ = false; 107 RefPtr<WindowExtensionConnectionAdapterNG> adapter_; 108 Rect lastRect_; 109 ACE_DISALLOW_COPY_AND_MOVE(AbilityComponentPattern); 110 }; 111 112 } // namespace OHOS::Ace::NG 113 114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ABILITY_COMPONENT_PATTERN_H 115