• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_PATTERN_UI_EXTENSION_UI_EXTENSION_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_PATTERN_H
18 
19 #include <cstdint>
20 
21 #include "base/memory/referenced.h"
22 #include "base/want/want_wrap.h"
23 #include "core/components_ng/event/gesture_event_hub.h"
24 #include "core/components_ng/pattern/window_scene/scene/window_pattern.h"
25 #include "core/event/mouse_event.h"
26 #include "core/event/touch_event.h"
27 
28 namespace OHOS::AAFwk {
29 class Want;
30 class WantParams;
31 } // namespace OHOS::AAFwk
32 
33 namespace OHOS::Ace::NG {
34 class UIExtensionProxy;
35 class UIExtensionPattern : public WindowPattern {
36     DECLARE_ACE_TYPE(UIExtensionPattern, WindowPattern);
37 
38 public:
39     explicit UIExtensionPattern(const RefPtr<OHOS::Ace::WantWrap>& wantWrap);
40     explicit UIExtensionPattern(const AAFwk::Want& want);
41     ~UIExtensionPattern() override;
42 
43     void OnWindowShow() override;
44     void OnWindowHide() override;
45     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override;
46     FocusPattern GetFocusPattern() const override;
47     void OnVisibleChange(bool visible) override;
48     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
49 
HasStartingPage()50     bool HasStartingPage() override
51     {
52         return false;
53     }
54 
55     int32_t GetSessionId();
56 
57     void SetOnRemoteReadyCallback(const std::function<void(const RefPtr<UIExtensionProxy>&)>&& callback);
58     void SetOnReleaseCallback(const std::function<void(int32_t)>&& callback);
59     void SetOnResultCallback(const std::function<void(int32_t, const AAFwk::Want&)>&& callback);
60     void SetOnReceiveCallback(const std::function<void(const AAFwk::WantParams&)>&& callback);
61     void SetOnErrorCallback(
62         const std::function<void(int32_t code, const std::string& name, const std::string& message)>&& callback);
63 
64     void OnConnect() override;
65     void OnDisconnect() override;
66     void OnExtensionDied() override;
67 
68     void RequestExtensionSessionActivation();
69     void RequestExtensionSessionBackground();
70     void RequestExtensionSessionDestruction();
71 
72 private:
73     enum ReleaseCode {
74         DESTROY_NORMAL = 0,
75         CONNECT_BROKEN,
76     };
77 
78     struct ErrorMsg {
79         int32_t code = 0;
80         std::string name;
81         std::string message;
82     };
83 
84     void OnModifyDone() override;
85     void OnDetachFromFrameNode(FrameNode* frameNode) override;
86 
87     void InitOnKeyEvent(const RefPtr<FocusHub>& focusHub);
88     bool OnKeyEvent(const KeyEvent& event);
89     void HandleFocusEvent();
90     void HandleBlurEvent();
91     bool KeyEventConsumed(const KeyEvent& event);
92 
93     void InitTouchEvent(const RefPtr<GestureEventHub>& gestureHub);
94     void InitMouseEvent(const RefPtr<InputEventHub>& inputHub);
95     void HandleTouchEvent(const TouchEventInfo& info);
96     void HandleMouseEvent(const MouseInfo& info);
97     void UnregisterAbilityResultListener();
98     void OnConnectInner();
99 
100     void RegisterVisibleAreaChange();
101     void UpdateTextFieldManager(const Offset& offset, float height);
102     bool IsCurrentFocus() const;
103 
104     RefPtr<TouchEventImpl> touchEvent_;
105     RefPtr<InputEvent> mouseEvent_;
106 
107     std::function<void(const RefPtr<UIExtensionProxy>&)> onRemoteReadyCallback_;
108     std::function<void(int32_t)> onReleaseCallback_;
109     std::function<void(int32_t, const AAFwk::Want&)> onResultCallback_;
110     std::function<void(const AAFwk::WantParams&)> onReceiveCallback_;
111     std::function<void(int32_t code, const std::string& name, const std::string& message)> onErrorCallback_;
112 
113     bool isDestruction_ = false;
114     ErrorMsg lastError_;
115     ACE_DISALLOW_COPY_AND_MOVE(UIExtensionPattern);
116 };
117 } // namespace OHOS::Ace::NG
118 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_UI_EXTENSION_UI_EXTENSION_PATTERN_H
119