1 /* 2 * Copyright (c) 2022-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_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/pattern/window_scene/scene/window_pattern.h" 27 #include "frameworks/core/components_ng/property/property.h" 28 #include "frameworks/core/components_ng/render/canvas_image.h" 29 30 namespace OHOS::Ace::NG { 31 32 class ACE_EXPORT AbilityComponentPattern : public WindowPattern { 33 DECLARE_ACE_TYPE(AbilityComponentPattern, WindowPattern); 34 35 public: 36 AbilityComponentPattern(const std::string& bundleName, const std::string& abilityName); 37 ~AbilityComponentPattern()38 ~AbilityComponentPattern() override 39 { 40 if (adapter_) { 41 adapter_->RemoveExtension(); 42 } 43 } 44 HasStartingPage()45 bool HasStartingPage() override 46 { 47 return false; 48 } 49 CreatePaintProperty()50 RefPtr<PaintProperty> CreatePaintProperty() override 51 { 52 return MakeRefPtr<AbilityComponentRenderProperty>(); 53 } 54 CreateEventHub()55 RefPtr<EventHub> CreateEventHub() override 56 { 57 return MakeRefPtr<AbilityComponentEventHub>(); 58 } 59 CreateLayoutAlgorithm()60 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 61 { 62 return MakeRefPtr<AbilityComponentLayoutAlgorithm>(); 63 } 64 65 FocusPattern GetFocusPattern() const override; 66 void FireConnect(); 67 void FireDisConnect(); 68 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 69 void OnAreaChangedInner() override; 70 71 private: 72 void OnAttachToFrameNode() override; 73 void OnModifyDone() override; 74 75 void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub); 76 void InitMouseEvent(const RefPtr<InputEventHub>& inputHub); 77 void HandleTouchEvent(const TouchEventInfo& info); 78 void HandleMouseEvent(const MouseInfo& info); 79 void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub); 80 bool OnKeyEvent(const KeyEvent& event); 81 void HandleFocusEvent(); 82 void HandleBlurEvent(); 83 bool KeyEventConsumed(const KeyEvent& event); 84 OnVisibleChange(bool visible)85 void OnVisibleChange(bool visible) override 86 { 87 if (!adapter_) { 88 return; 89 } 90 if (visible && !isActive_) { 91 adapter_->Show(); 92 isActive_ = true; 93 } else if (!visible && isActive_) { 94 adapter_->Hide(); 95 isActive_ = false; 96 } 97 } 98 OnActive()99 void OnActive() override 100 { 101 if (!isActive_) { 102 if (adapter_) { 103 adapter_->Show(); 104 } 105 isActive_ = true; 106 } 107 } 108 OnInActive()109 void OnInActive() override 110 { 111 if (isActive_) { 112 if (adapter_) { 113 adapter_->Hide(); 114 } 115 isActive_ = false; 116 } 117 } 118 OnWindowShow()119 void OnWindowShow() override 120 { 121 if (!isActive_) { 122 if (adapter_) { 123 adapter_->Show(); 124 } 125 isActive_ = true; 126 } 127 } 128 OnWindowHide()129 void OnWindowHide() override 130 { 131 if (isActive_) { 132 if (adapter_) { 133 adapter_->Hide(); 134 } 135 isActive_ = false; 136 } 137 } 138 139 void UpdateWindowRect(); 140 bool IsCurrentFocus() const; 141 142 bool isActive_ = false; 143 bool hasConnectionToAbility_ = false; 144 Rect lastRect_; 145 RefPtr<TouchEventImpl> touchEvent_; 146 RefPtr<InputEvent> mouseEvent_; 147 RefPtr<WindowExtensionConnectionAdapterNG> adapter_; 148 ACE_DISALLOW_COPY_AND_MOVE(AbilityComponentPattern); 149 }; 150 151 } // namespace OHOS::Ace::NG 152 153 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ABILITY_COMPONENT_PATTERN_H 154