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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_EXTENSIONS_EVENTS_ON_AREA_CHANGE_EXTENSION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_EXTENSIONS_EVENTS_ON_AREA_CHANGE_EXTENSION_H 18 19 #include <functional> 20 #include <list> 21 22 #include "base/geometry/offset.h" 23 #include "base/geometry/rect.h" 24 #include "core/components_v2/extensions/extension.h" 25 26 namespace OHOS::Ace::V2 { 27 28 using OnAreaChangeEvent = std::function<void(const Rect&, const Offset&, const Rect&, const Offset&)>; 29 30 class OnAreaChangeExtension : public Extension { 31 DECLARE_ACE_TYPE(OnAreaChangeExtension, Extension); 32 33 public: 34 OnAreaChangeExtension() = default; 35 ~OnAreaChangeExtension() override = default; 36 AddOnAreaChangeEvent(const OnAreaChangeEvent & event)37 void AddOnAreaChangeEvent(const OnAreaChangeEvent& event) 38 { 39 if (!event) { 40 return; 41 } 42 callbacks_.emplace_back(event); 43 } AddOnAreaChangeEvent(OnAreaChangeEvent && event)44 void AddOnAreaChangeEvent(OnAreaChangeEvent&& event) 45 { 46 if (!event) { 47 return; 48 } 49 callbacks_.emplace_back(std::move(event)); 50 } 51 UpdateArea(const Rect & rect,const Offset & origin,const Rect & lastRect,const Offset & lastOrigin)52 void UpdateArea(const Rect& rect, const Offset& origin, const Rect& lastRect, const Offset& lastOrigin) 53 { 54 for (const auto& callback : callbacks_) { 55 callback(lastRect, lastOrigin, rect, origin); 56 } 57 } 58 59 private: 60 std::list<OnAreaChangeEvent> callbacks_; 61 }; 62 63 } // namespace OHOS::Ace::V2 64 65 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_EXTENSIONS_EVENTS_ON