• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_ABILITY_WINDOW_H
17 #define OHOS_ABILITY_WINDOW_H
18 
19 #include "window_manager.h"
20 
21 #include <map>
22 #include "nocopyable.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class IAbilityEvent;
27 class Ability;
28 class AbilityHandler;
29 class AbilityWindow : public NoCopyable {
30 public:
31     AbilityWindow();
32     virtual ~AbilityWindow();
33 
34     /**
35      * @brief Init the AbilityWindow object.
36      *
37      * @param handler The EventHandler of the Ability the AbilityWindow belong.
38      */
39     void Init(std::shared_ptr<AbilityHandler> &handler, std::shared_ptr<Ability> ability);
40 
41     /**
42      * @brief Sets the window config for the host ability to create window.
43      *
44      * @param config Indicates window config.
45      */
46     bool SetWindowConfig(const sptr<WindowOption> &config);
47 
48     /**
49      * @brief Called when the KeyEvent sent.
50      *
51      * @param KeyEvent the key event.
52      *
53      * @return Returns true if the listener has processed the event; returns false otherwise.
54      *
55      */
56     bool OnKeyEvent(KeyEvent event);
57 
58     /**
59      * @brief Called back when the Back key is pressed.
60      *
61      * @param ability The ability receive the event.
62      *
63      * @return Returns true if the listener has processed the event; returns false otherwise.
64      *
65      */
66     bool OnBackPressed(std::shared_ptr<IAbilityEvent> &ability);
67 
68     /**
69      * @brief Called when this ability is started.
70      *
71      */
72     void OnPostAbilityStart();
73 
74     /**
75      * @brief Called when this ability is activated.
76      *
77      */
78     void OnPostAbilityActive();
79 
80     /**
81      * @brief Called when this ability is inactivated.
82      *
83      */
84     void OnPostAbilityInactive();
85 
86     /**
87      * @brief Called when this ability is background.
88      *
89      */
90     void OnPostAbilityBackground();
91 
92     /**
93      * @brief Called when this ability is foreground.
94      *
95      */
96     void OnPostAbilityForeground();
97 
98     /**
99      * @brief Called when this ability is stopped.
100      *
101      */
102     void OnPostAbilityStop();
103 
104     /**
105      * @brief Get the window belong to the ability.
106      *
107      * @return Returns a Window object pointer.
108      */
109     const sptr<Window> GetWindow();
110 
111 private:
112     std::shared_ptr<AbilityHandler> handler_ = nullptr;
113     std::weak_ptr<IAbilityEvent> ability_;
114     sptr<Window> windowNew_;
115     bool isWindowAttached = false;
116 };
117 }  // namespace AppExecFwk
118 }  // namespace OHOS
119 #endif  // OHOS_ABILITY_WINDOW_H