• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OnModifyDone() override;
73 
74     void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
75     void InitMouseEvent(const RefPtr<InputEventHub>& inputHub);
76     void HandleTouchEvent(const TouchEventInfo& info);
77     void HandleMouseEvent(const MouseInfo& info);
78     void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
79     bool OnKeyEvent(const KeyEvent& event);
80     void HandleFocusEvent();
81     void HandleBlurEvent();
82     bool KeyEventConsumed(const KeyEvent& event);
83 
OnVisibleChange(bool visible)84     void OnVisibleChange(bool visible) override
85     {
86         if (!adapter_) {
87             return;
88         }
89         if (visible && !isActive_) {
90             adapter_->Show();
91             isActive_ = true;
92         } else if (!visible && isActive_) {
93             adapter_->Hide();
94             isActive_ = false;
95         }
96     }
97 
OnActive()98     void OnActive() override
99     {
100         if (!isActive_) {
101             if (adapter_) {
102                 adapter_->Show();
103             }
104             isActive_ = true;
105         }
106     }
107 
OnInActive()108     void OnInActive() override
109     {
110         if (isActive_) {
111             if (adapter_) {
112                 adapter_->Hide();
113             }
114             isActive_ = false;
115         }
116     }
117 
OnWindowShow()118     void OnWindowShow() override
119     {
120         if (!isActive_) {
121             if (adapter_) {
122                 adapter_->Show();
123             }
124             isActive_ = true;
125         }
126     }
127 
OnWindowHide()128     void OnWindowHide() override
129     {
130         if (isActive_) {
131             if (adapter_) {
132                 adapter_->Hide();
133             }
134             isActive_ = false;
135         }
136     }
137 
138     void UpdateWindowRect();
139     bool IsCurrentFocus() const;
140 
141     bool isActive_ = false;
142     bool hasConnectionToAbility_ = false;
143     Rect lastRect_;
144     RefPtr<TouchEventImpl> touchEvent_;
145     RefPtr<InputEvent> mouseEvent_;
146     RefPtr<WindowExtensionConnectionAdapterNG> adapter_;
147     ACE_DISALLOW_COPY_AND_MOVE(AbilityComponentPattern);
148 };
149 
150 } // namespace OHOS::Ace::NG
151 
152 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_ABILITY_COMPONENT_PATTERN_H
153