• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_ABILITY_H
17 #define FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_ABILITY_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "ability.h"
23 #include "ability_loader.h"
24 #include "core/common/window_animation_config.h"
25 #include "core/event/touch_event.h"
26 #include "want.h"
27 #include "wm/window.h"
28 
29 namespace OHOS::Ace {
30 class AceAbility;
31 class AceWindowListener : public OHOS::Rosen::IWindowDragListener,
32                           public OHOS::Rosen::IWindowChangeListener,
33                           public OHOS::Rosen::IOccupiedAreaChangeListener,
34                           public OHOS::Rosen::IAceAbilityHandler,
35                           public OHOS::Rosen::IInputEventConsumer {
36 public:
AceWindowListener(std::shared_ptr<AceAbility> owner)37     explicit AceWindowListener(std::shared_ptr<AceAbility> owner) : callbackOwner_(owner) {}
38     ~AceWindowListener() = default;
39     // override Rosen::IWindowDragListener virtual callback function
40     void OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event) override;
41 
42     // override Rosen::IOccupiedAreaChangeListener virtual callback function
43     void OnSizeChange(const sptr<OHOS::Rosen::OccupiedAreaChangeInfo>& info) override;
44 
45     // override Rosen::IAceAbilityHandler virtual callback function
46     void SetBackgroundColor(uint32_t color) override;
47     uint32_t GetBackgroundColor() override;
48 
49     // override Rosen::IWindowChangeListener virtual callback function
50     void OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeChangeReason reason) override;
51     void OnModeChange(OHOS::Rosen::WindowMode mode) override;
52 
53     // override Rosen::IInputEventConsumer virtual callback function
54     bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const override;
55     bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const override;
56     bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const override;
57 private:
58     std::shared_ptr<AceAbility> callbackOwner_;
59 };
60 
61 class AceAbility final : public OHOS::AppExecFwk::Ability {
62 public:
63     AceAbility();
64     ~AceAbility() override = default;
65 
66     void OnStart(const OHOS::AAFwk::Want& want) override;
67     void OnStop() override;
68     void OnActive() override;
69     void OnInactive() override;
70     void OnForeground(const OHOS::AAFwk::Want& want) override;
71     void OnBackground() override;
72     void OnBackPressed() override;
73     void OnNewWant(const OHOS::AAFwk::Want& want) override;
74     void OnRestoreAbilityState(const OHOS::AppExecFwk::PacMap& inState) override;
75     void OnSaveAbilityState(OHOS::AppExecFwk::PacMap& outState) override;
76     void OnConfigurationUpdated(const OHOS::AppExecFwk::Configuration& configuration) override;
77     void OnAbilityResult(int requestCode, int resultCode, const OHOS::AAFwk::Want& resultData) override;
78 
79     bool OnStartContinuation() override;
80     bool OnSaveData(OHOS::AAFwk::WantParams& saveData) override;
81     bool OnRestoreData(OHOS::AAFwk::WantParams& restoreData) override;
82     void OnCompleteContinuation(int result) override;
83     void OnRemoteTerminated() override;
84 
85     // handle window Rosen::IWindowDragListener
86     void OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event);
87 
88     // handle window Rosen::IWindowChangeListener
89     void OnSizeChange(const OHOS::Rosen::Rect& rect, OHOS::Rosen::WindowSizeChangeReason reason);
90     void OnModeChange(OHOS::Rosen::WindowMode mode);
91 
92     // handle window Rosen::IOccupiedAreaChangeListener
93     void OnSizeChange(const sptr<OHOS::Rosen::OccupiedAreaChangeInfo>& info);
94 
95     // handle window Rosen::IInputEventConsumer
96     bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const;
97     bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const;
98     bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const;
99 
100     // handle window Rosen::IAceAbilityHandler
101     void SetBackgroundColor(uint32_t color);
102     uint32_t GetBackgroundColor();
103 
104     void Dump(const std::vector<std::string>& params, std::vector<std::string>& info) override;
105 
106 private:
107     static const std::string START_PARAMS_KEY;
108     static const std::string PAGE_URI;
109     static const std::string CONTINUE_PARAMS_KEY;
110 
111     int32_t abilityId_ = -1;
112     float density_ = 1.0f;
113     std::string remotePageUrl_;
114     std::string remoteData_;
115     std::string pageUrl_;
116     bool isFirstActive_ = true;
117 };
118 
119 } // namespace OHOS::Ace
120 
121 #endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_ABILITY_H
122