123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#ifndef FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_ABILITY_H 1723b3eb3cSopenharmony_ci#define FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_ABILITY_H 1823b3eb3cSopenharmony_ci 1923b3eb3cSopenharmony_ci#include <string> 2023b3eb3cSopenharmony_ci#include <vector> 2123b3eb3cSopenharmony_ci 2223b3eb3cSopenharmony_ci#include "ability.h" 2323b3eb3cSopenharmony_ci#include "ability_loader.h" 2423b3eb3cSopenharmony_ci#include "want.h" 2523b3eb3cSopenharmony_ci#include "window.h" 2623b3eb3cSopenharmony_ci 2723b3eb3cSopenharmony_ci#include "core/common/window_animation_config.h" 2823b3eb3cSopenharmony_ci#include "core/event/touch_event.h" 2923b3eb3cSopenharmony_ci 3023b3eb3cSopenharmony_cinamespace OHOS::Ace { 3123b3eb3cSopenharmony_ciclass AceAbility; 3223b3eb3cSopenharmony_ciclass AceWindowListener : public OHOS::Rosen::IWindowDragListener, 3323b3eb3cSopenharmony_ci public OHOS::Rosen::IWindowChangeListener, 3423b3eb3cSopenharmony_ci public OHOS::Rosen::IOccupiedAreaChangeListener, 3523b3eb3cSopenharmony_ci public OHOS::Rosen::IAceAbilityHandler, 3623b3eb3cSopenharmony_ci public OHOS::Rosen::IInputEventConsumer, 3723b3eb3cSopenharmony_ci public OHOS::Rosen::IAvoidAreaChangedListener { 3823b3eb3cSopenharmony_cipublic: 3923b3eb3cSopenharmony_ci explicit AceWindowListener(std::shared_ptr<AceAbility> owner) : callbackOwner_(owner) {} 4023b3eb3cSopenharmony_ci ~AceWindowListener() = default; 4123b3eb3cSopenharmony_ci // override Rosen::IWindowDragListener virtual callback function 4223b3eb3cSopenharmony_ci void OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event) override; 4323b3eb3cSopenharmony_ci 4423b3eb3cSopenharmony_ci // override Rosen::IOccupiedAreaChangeListener virtual callback function 4523b3eb3cSopenharmony_ci void OnSizeChange(const sptr<OHOS::Rosen::OccupiedAreaChangeInfo>& info, 4623b3eb3cSopenharmony_ci const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr) override; 4723b3eb3cSopenharmony_ci 4823b3eb3cSopenharmony_ci // override Rosen::IAceAbilityHandler virtual callback function 4923b3eb3cSopenharmony_ci void SetBackgroundColor(uint32_t color) override; 5023b3eb3cSopenharmony_ci uint32_t GetBackgroundColor() override; 5123b3eb3cSopenharmony_ci 5223b3eb3cSopenharmony_ci // override Rosen::IWindowChangeListener virtual callback function 5323b3eb3cSopenharmony_ci void OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeChangeReason reason, 5423b3eb3cSopenharmony_ci const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr) override; 5523b3eb3cSopenharmony_ci void OnModeChange(OHOS::Rosen::WindowMode mode, bool hasDeco = true) override; 5623b3eb3cSopenharmony_ci 5723b3eb3cSopenharmony_ci // override Rosen::IInputEventConsumer virtual callback function 5823b3eb3cSopenharmony_ci bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const override; 5923b3eb3cSopenharmony_ci bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const override; 6023b3eb3cSopenharmony_ci bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const override; 6123b3eb3cSopenharmony_ci 6223b3eb3cSopenharmony_ci // override Rosen::IAvoidAreaChangedListener virtual callback function 6323b3eb3cSopenharmony_ci void OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea avoidArea, OHOS::Rosen::AvoidAreaType type) override; 6423b3eb3cSopenharmony_ci 6523b3eb3cSopenharmony_ciprivate: 6623b3eb3cSopenharmony_ci std::shared_ptr<AceAbility> callbackOwner_; 6723b3eb3cSopenharmony_ci}; 6823b3eb3cSopenharmony_ci 6923b3eb3cSopenharmony_ciclass AceAbility final : public OHOS::AppExecFwk::Ability { 7023b3eb3cSopenharmony_cipublic: 7123b3eb3cSopenharmony_ci AceAbility(); 7223b3eb3cSopenharmony_ci ~AceAbility() override = default; 7323b3eb3cSopenharmony_ci 7423b3eb3cSopenharmony_ci void OnStart(const OHOS::AAFwk::Want& want, sptr<AAFwk::SessionInfo> sessionInfo = nullptr) override; 7523b3eb3cSopenharmony_ci void OnStop() override; 7623b3eb3cSopenharmony_ci void OnActive() override; 7723b3eb3cSopenharmony_ci void OnInactive() override; 7823b3eb3cSopenharmony_ci void OnForeground(const OHOS::AAFwk::Want& want) override; 7923b3eb3cSopenharmony_ci void OnBackground() override; 8023b3eb3cSopenharmony_ci void OnBackPressed() override; 8123b3eb3cSopenharmony_ci void OnNewWant(const OHOS::AAFwk::Want& want) override; 8223b3eb3cSopenharmony_ci void OnRestoreAbilityState(const OHOS::AppExecFwk::PacMap& inState) override; 8323b3eb3cSopenharmony_ci void OnSaveAbilityState(OHOS::AppExecFwk::PacMap& outState) override; 8423b3eb3cSopenharmony_ci void OnConfigurationUpdated(const OHOS::AppExecFwk::Configuration& configuration) override; 8523b3eb3cSopenharmony_ci void OnAbilityResult(int requestCode, int resultCode, const OHOS::AAFwk::Want& resultData) override; 8623b3eb3cSopenharmony_ci 8723b3eb3cSopenharmony_ci bool OnStartContinuation() override; 8823b3eb3cSopenharmony_ci bool OnSaveData(OHOS::AAFwk::WantParams& saveData) override; 8923b3eb3cSopenharmony_ci bool OnRestoreData(OHOS::AAFwk::WantParams& restoreData) override; 9023b3eb3cSopenharmony_ci void OnCompleteContinuation(int result) override; 9123b3eb3cSopenharmony_ci void OnRemoteTerminated() override; 9223b3eb3cSopenharmony_ci 9323b3eb3cSopenharmony_ci // handle window Rosen::IWindowDragListener 9423b3eb3cSopenharmony_ci void OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event); 9523b3eb3cSopenharmony_ci 9623b3eb3cSopenharmony_ci // handle window Rosen::IWindowChangeListener 9723b3eb3cSopenharmony_ci void OnSizeChange(const OHOS::Rosen::Rect& rect, OHOS::Rosen::WindowSizeChangeReason reason, 9823b3eb3cSopenharmony_ci const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr); 9923b3eb3cSopenharmony_ci void OnModeChange(OHOS::Rosen::WindowMode mode, bool hasDeco = true); 10023b3eb3cSopenharmony_ci 10123b3eb3cSopenharmony_ci // handle window Rosen::IOccupiedAreaChangeListener 10223b3eb3cSopenharmony_ci void OnSizeChange(const sptr<OHOS::Rosen::OccupiedAreaChangeInfo>& info, 10323b3eb3cSopenharmony_ci const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction = nullptr); 10423b3eb3cSopenharmony_ci 10523b3eb3cSopenharmony_ci // handle window Rosen::IInputEventConsumer 10623b3eb3cSopenharmony_ci bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const; 10723b3eb3cSopenharmony_ci bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const; 10823b3eb3cSopenharmony_ci bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const; 10923b3eb3cSopenharmony_ci 11023b3eb3cSopenharmony_ci // handle window Rosen::IAceAbilityHandler 11123b3eb3cSopenharmony_ci void SetBackgroundColor(uint32_t color); 11223b3eb3cSopenharmony_ci uint32_t GetBackgroundColor(); 11323b3eb3cSopenharmony_ci 11423b3eb3cSopenharmony_ci // handle window Rosen::IAvoidAreaChangedListener 11523b3eb3cSopenharmony_ci void OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea& avoidArea, OHOS::Rosen::AvoidAreaType type); 11623b3eb3cSopenharmony_ci 11723b3eb3cSopenharmony_ci void Dump(const std::vector<std::string>& params, std::vector<std::string>& info) override; 11823b3eb3cSopenharmony_ci 11923b3eb3cSopenharmony_ciprivate: 12023b3eb3cSopenharmony_ci static const std::string START_PARAMS_KEY; 12123b3eb3cSopenharmony_ci static const std::string PAGE_URI; 12223b3eb3cSopenharmony_ci static const std::string CONTINUE_PARAMS_KEY; 12323b3eb3cSopenharmony_ci 12423b3eb3cSopenharmony_ci int32_t abilityId_ = -1; 12523b3eb3cSopenharmony_ci float density_ = 1.0f; 12623b3eb3cSopenharmony_ci std::string remotePageUrl_; 12723b3eb3cSopenharmony_ci std::string remoteData_; 12823b3eb3cSopenharmony_ci std::string pageUrl_; 12923b3eb3cSopenharmony_ci bool isFirstActive_ = true; 13023b3eb3cSopenharmony_ci}; 13123b3eb3cSopenharmony_ci 13223b3eb3cSopenharmony_ci} // namespace OHOS::Ace 13323b3eb3cSopenharmony_ci 13423b3eb3cSopenharmony_ci#endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_ABILITY_H 135