From ff9a51f012df3788f0c98eef7172b7ecde5f1deb Mon Sep 17 00:00:00 2001 From: yanshuifeng Date: Thu, 11 Nov 2021 21:21:40 +0800 Subject: [PATCH] update event target. Signed-off-by: sunfei Change-Id: I19b41a8c98fdd8e04bd29b5515ecdf7a2052db8a --- adapter/ohos/osal/system_properties.cpp | 2 +- .../base/geometry/animatable_dimension.cpp | 12 +- .../base/geometry/animatable_matrix4.cpp | 12 +- frameworks/base/geometry/dimension.h | 13 ++ frameworks/base/geometry/dimension_rect.h | 104 +++++++++++++++ frameworks/base/geometry/dimension_size.h | 98 ++++++++++++++ .../bridge/common/accessibility/BUILD.gn | 2 - .../accessibility_node_manager.cpp | 17 +++ .../accessibility_node_manager.h | 4 +- .../fake_accessibility_node_manager.cpp | 120 ------------------ .../engine/functions/js_click_function.cpp | 4 + .../engine/functions/js_function.cpp | 19 +++ .../engine/functions/js_function.h | 2 + .../engine/functions/js_gesture_function.cpp | 2 + .../engine/functions/js_touch_function.cpp | 4 + .../declarative_frontend/jsview/js_button.cpp | 7 +- .../jsview/js_gesture.cpp | 14 +- .../jsview/js_interactable_view.cpp | 39 +++++- .../jsview/js_interactable_view.h | 2 + .../declarative_frontend/jsview/js_span.cpp | 7 +- .../declarative_frontend/jsview/js_text.cpp | 7 +- .../jsview/js_view_context.cpp | 17 +-- .../view_stack_processor.cpp | 49 ++++--- .../view_stack_processor.h | 5 +- .../accessibility/accessibility_manager.h | 1 + frameworks/core/animation/animatable_base.h | 9 +- .../core/components/box/render_box_base.h | 4 +- .../common/properties/animatable_color.h | 9 +- .../common/properties/animatable_double.h | 9 +- .../common/properties/animatable_path.cpp | 12 +- .../common/properties/animation_option.h | 8 +- .../components/image/rosen_render_image.cpp | 33 +---- .../test/unittest/theme/theme_mock.cpp | 8 +- frameworks/core/event/ace_events.h | 19 ++- frameworks/core/event/touch_event.h | 2 +- .../focus/test/unittest/focus/focus_test.cpp | 5 + frameworks/core/gestures/gesture_info.h | 33 ++--- frameworks/core/pipeline/base/element.h | 9 ++ frameworks/core/pipeline/pipeline_context.cpp | 18 +++ frameworks/core/pipeline/pipeline_context.h | 4 + 40 files changed, 496 insertions(+), 249 deletions(-) create mode 100644 frameworks/base/geometry/dimension_rect.h create mode 100644 frameworks/base/geometry/dimension_size.h delete mode 100644 frameworks/bridge/common/accessibility/fake_accessibility_node_manager.cpp diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index 725a7e98..03932344 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -68,7 +68,7 @@ bool SystemProperties::accessibilityEnabled_ = IsAccessibilityEnabled(); bool SystemProperties::isRound_ = false; int32_t SystemProperties::deviceWidth_ = 0; int32_t SystemProperties::deviceHeight_ = 0; -double SystemProperties::resolution_ = 1.0; +double SystemProperties::resolution_ = 2.0; DeviceType SystemProperties::deviceType_ { DeviceType::UNKNOWN }; DeviceOrientation SystemProperties::orientation_ { DeviceOrientation::PORTRAIT }; std::string SystemProperties::brand_ = INVALID_PARAM; diff --git a/frameworks/base/geometry/animatable_dimension.cpp b/frameworks/base/geometry/animatable_dimension.cpp index aa0a7f5a..6d5850cf 100644 --- a/frameworks/base/geometry/animatable_dimension.cpp +++ b/frameworks/base/geometry/animatable_dimension.cpp @@ -78,9 +78,15 @@ void AnimatableDimension::AnimateTo(double endValue) animationController_->AddInterpolator(animation); auto onFinishEvent = animationOption_.GetOnFinishEvent(); - if (!onFinishEvent.IsEmpty()) { - animationController_->AddStopListener( - [onFinishEvent, weakContext = context_] { AceAsyncEvent::Create(onFinishEvent, weakContext)(); }); + if (onFinishEvent) { + animationController_->AddStopListener([onFinishEvent, weakContext = context_] { + auto context = weakContext.Upgrade(); + if (context) { + context->PostAsyncEvent(onFinishEvent); + } else { + LOGE("the context is null"); + } + }); } if (stopCallback_) { animationController_->AddStopListener(stopCallback_); diff --git a/frameworks/base/geometry/animatable_matrix4.cpp b/frameworks/base/geometry/animatable_matrix4.cpp index e23d7b6f..7f353c6c 100644 --- a/frameworks/base/geometry/animatable_matrix4.cpp +++ b/frameworks/base/geometry/animatable_matrix4.cpp @@ -95,9 +95,15 @@ void AnimatableMatrix4::AnimateTo(const Matrix4& endValue) animation->AddListener(std::bind(&AnimatableMatrix4::OnAnimationCallback, this, std::placeholders::_1)); animationController_->AddInterpolator(animation); auto onFinishEvent = animationOption_.GetOnFinishEvent(); - if (!onFinishEvent.IsEmpty()) { - animationController_->AddStopListener( - [onFinishEvent, weakContext = context_] { AceAsyncEvent::Create(onFinishEvent, weakContext)(); }); + if (onFinishEvent) { + animationController_->AddStopListener([onFinishEvent, weakContext = context_] { + auto context = weakContext.Upgrade(); + if (context) { + context->PostAsyncEvent(onFinishEvent); + } else { + LOGE("the context is null"); + } + }); } if (stopCallback_) { animationController_->AddStopListener(stopCallback_); diff --git a/frameworks/base/geometry/dimension.h b/frameworks/base/geometry/dimension.h index 9c2c3111..1e44800e 100644 --- a/frameworks/base/geometry/dimension.h +++ b/frameworks/base/geometry/dimension.h @@ -19,6 +19,7 @@ #include #include "base/utils/macros.h" +#include "base/utils/system_properties.h" #include "base/utils/utils.h" #define NEAR_ZERO(value) ((value > 0.0) ? ((value - 0.0) <= 0.000001f) : ((0.0 - value) <= 0.000001f)) @@ -96,6 +97,18 @@ public: } } + double ConvertToVp() const + { + if (unit_ == DimensionUnit::VP) { + return value_; + } + if (unit_ == DimensionUnit::PX) { + return SystemProperties::Px2Vp(value_); + } + // TODO: add fp and lpx convert. + return 0; + } + constexpr Dimension operator*(double value) const { return Dimension(value_ * value, unit_); diff --git a/frameworks/base/geometry/dimension_rect.h b/frameworks/base/geometry/dimension_rect.h new file mode 100644 index 00000000..ceeaf7ed --- /dev/null +++ b/frameworks/base/geometry/dimension_rect.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_DIMENSION_RECT_H +#define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_DIMENSION_RECT_H + +#include +#include + +#include "base/geometry/dimension.h" +#include "base/geometry/dimension_offset.h" +#include "base/geometry/dimension_size.h" + +namespace OHOS::Ace { + +class DimensionRect { +public: + DimensionRect() = default; + ~DimensionRect() = default; + + DimensionRect(const Dimension& width, const Dimension& height, const DimensionOffset& offset, + const DimensionOffset& globalOffset) + : width_(width), height_(height), offset_(offset), globalOffset_(globalOffset) + {} + + DimensionRect(const Dimension& width, const Dimension& height) : width_(width), height_(height) {} + + const Dimension& GetWidth() const + { + return width_; + } + + const Dimension& GetHeight() const + { + return height_; + } + + const DimensionOffset& GetOffset() const + { + return offset_; + } + + const DimensionOffset& GetGlobalOffset() const + { + return globalOffset_; + } + + void SetOffset(const DimensionOffset& offset) + { + offset_ = offset; + } + + void SetSize(const DimensionSize& size) + { + width_ = size.Width(); + height_ = size.Height(); + } + + + void SetWidth(const Dimension& width) + { + width_ = width; + } + + void SetHeight(const Dimension& height) + { + height_ = height; + } + + void SetGlobaleOffset(const DimensionOffset& offset) + { + globalOffset_ = offset; + } + + void Reset() + { + width_ = 0.0_vp; + height_ = 0.0_vp; + offset_ = DimensionOffset(); + globalOffset_ = DimensionOffset(); + } + +private: + Dimension width_ = 0.0_vp; + Dimension height_ = 0.0_vp; + DimensionOffset offset_; + DimensionOffset globalOffset_; +}; + +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_DIMENSION_RECT_H diff --git a/frameworks/base/geometry/dimension_size.h b/frameworks/base/geometry/dimension_size.h new file mode 100644 index 00000000..23aa35ad --- /dev/null +++ b/frameworks/base/geometry/dimension_size.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_DIMENSION_SIZE_H +#define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_DIMENSION_SIZE_H + +#include +#include +#include +#include + +#include "base/geometry/dimension.h" +#include "base/utils/utils.h" + +namespace OHOS::Ace { + +class DimensionSize { +public: + static constexpr double INFINITE_SIZE = std::numeric_limits::max(); + DimensionSize() = default; + ~DimensionSize() = default; + DimensionSize(const Dimension& width, const Dimension& height) : width_(width), height_(height) {} + + const Dimension& Width() const + { + return width_; + } + + const Dimension& Height() const + { + return height_; + } + + void SetWidth(const Dimension& width) + { + width_ = width; + } + + void SetHeight(const Dimension& height) + { + height_ = height; + } + + void SetSize(const DimensionSize& size) + { + width_ = size.Width(); + height_ = size.Height(); + } + + template + static double CalcRatio(const T& rectangle) + { + if (NearZero(static_cast(rectangle.Height()))) { + return INFINITE_SIZE; + } + return static_cast(rectangle.Width()) / static_cast(rectangle.Height()); + } + + std::string ToString() const + { + std::stringstream ss; + ss << "[" << std::fixed << std::setprecision(2); + if (NearEqual(width_.Value(), INFINITE_SIZE)) { + ss << "INFINITE"; + } else { + ss << width_.ToString(); + } + ss << " x "; + if (NearEqual(height_.Value(), INFINITE_SIZE)) { + ss << "INFINITE"; + } else { + ss << height_.ToString(); + } + ss << "]"; + std::string output = ss.str(); + return output; + } + +private: + Dimension width_ = 0.0_vp; + Dimension height_ = 0.0_vp; +}; + +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_DIMENSION_SIZE_H diff --git a/frameworks/bridge/common/accessibility/BUILD.gn b/frameworks/bridge/common/accessibility/BUILD.gn index cb230bb1..e7e09cf8 100644 --- a/frameworks/bridge/common/accessibility/BUILD.gn +++ b/frameworks/bridge/common/accessibility/BUILD.gn @@ -37,10 +37,8 @@ template("bridge_accessibility") { ] } } else { - sources -= [ "accessibility_node_manager.cpp" ] sources += [ "fake_accessibility_manager.cpp", - "fake_accessibility_node_manager.cpp", ] } diff --git a/frameworks/bridge/common/accessibility/accessibility_node_manager.cpp b/frameworks/bridge/common/accessibility/accessibility_node_manager.cpp index a473390c..959dae9a 100644 --- a/frameworks/bridge/common/accessibility/accessibility_node_manager.cpp +++ b/frameworks/bridge/common/accessibility/accessibility_node_manager.cpp @@ -513,6 +513,23 @@ void AccessibilityNodeManager::SetCardViewPosition(int id, float offsetX, float "setcardview id=%{public}d offsetX=%{public}f, offsetY=%{public}f", id, cardOffset_.GetX(), cardOffset_.GetY()); } +void AccessibilityNodeManager::UpdateEventTarget(NodeId id, BaseEventInfo& info) +{ + auto composedElement = GetComposedElementFromPage(id); + auto inspector = AceType::DynamicCast(composedElement.Upgrade()); + if (!inspector) { + LOGE("this is not Inspector composed element"); + return; + } + auto rectInLocal = inspector->GetRenderRectInLocal(); + auto rectInGlobal = inspector->GetRenderRect(); + auto& target = info.GetTargetWichModify(); + target.area.SetOffset(DimensionOffset(rectInLocal.GetOffset())); + target.area.SetGlobaleOffset(DimensionOffset(rectInGlobal.GetOffset())); + target.area.SetWidth(Dimension(rectInLocal.Width())); + target.area.SetHeight(Dimension(rectInLocal.Height())); +} + bool AccessibilityNodeManager::IsDeclarative() { auto context = context_.Upgrade(); diff --git a/frameworks/bridge/common/accessibility/accessibility_node_manager.h b/frameworks/bridge/common/accessibility/accessibility_node_manager.h index c8738fb8..2fbce020 100644 --- a/frameworks/bridge/common/accessibility/accessibility_node_manager.h +++ b/frameworks/bridge/common/accessibility/accessibility_node_manager.h @@ -119,7 +119,9 @@ public: void SetCardViewParams(const std::string& key, bool focus) override; void SetCardViewPosition(int id, float offsetX, float offsetY) override; - virtual void SetSupportAction(uint32_t action, bool isEnable) override {} + void SetSupportAction(uint32_t action, bool isEnable) override {} + + void UpdateEventTarget(NodeId id, BaseEventInfo& info) override; bool IsDeclarative(); diff --git a/frameworks/bridge/common/accessibility/fake_accessibility_node_manager.cpp b/frameworks/bridge/common/accessibility/fake_accessibility_node_manager.cpp deleted file mode 100644 index 9dc8977f..00000000 --- a/frameworks/bridge/common/accessibility/fake_accessibility_node_manager.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "frameworks/bridge/common/accessibility/accessibility_node_manager.h" - -#include "base/log/dump_log.h" -#include "base/log/event_report.h" -#include "base/log/log.h" -#include "base/utils/linear_map.h" -#include "base/utils/string_utils.h" -#include "base/utils/utils.h" -#include "frameworks/bridge/common/dom/dom_type.h" - -namespace OHOS::Ace::Framework { - -AccessibilityNodeManager::~AccessibilityNodeManager() = default; - -void AccessibilityNodeManager::InitializeCallback() {} - -void AccessibilityNodeManager::SetPipelineContext(const RefPtr& context) {} - -void AccessibilityNodeManager::SetRunningPage(const RefPtr& page) {} - -std::string AccessibilityNodeManager::GetNodeChildIds(const RefPtr& node) -{ - return ""; -} - -void AccessibilityNodeManager::AddNodeWithId(const std::string& key, const RefPtr& node) {} - -void AccessibilityNodeManager::AddNodeWithTarget(const std::string& key, const RefPtr& node) {} - -RefPtr AccessibilityNodeManager::GetAccessibilityNodeFromPage(NodeId nodeId) const -{ - return nullptr; -} - -void AccessibilityNodeManager::ClearNodeRectInfo(RefPtr& node, bool isPopDialog) {} - -void AccessibilityNodeManager::SendAccessibilityAsyncEvent(const AccessibilityEvent& accessibilityEvent) {} - -int32_t AccessibilityNodeManager::GenerateNextAccessibilityId() -{ - return 0; -} - -// combined components which pop up through js api, such as dialog/toast -RefPtr AccessibilityNodeManager::CreateSpecializedNode( - const std::string& tag, int32_t nodeId, int32_t parentNodeId) -{ - return nullptr; -} - -RefPtr AccessibilityNodeManager::CreateAccessibilityNode( - const std::string& tag, int32_t nodeId, int32_t parentNodeId, int32_t itemIndex) -{ - return nullptr; -} - -RefPtr AccessibilityNodeManager::GetAccessibilityNodeById(NodeId nodeId) const -{ - return nullptr; -} - -void AccessibilityNodeManager::AddComposedElement(const std::string& key, const RefPtr& node) {} - -void AccessibilityNodeManager::RemoveComposedElementById(const std::string& key) {} - -WeakPtr AccessibilityNodeManager::GetComposedElementFromPage(NodeId nodeId) -{ - return nullptr; -} -void AccessibilityNodeManager::TriggerVisibleChangeEvent() {} - -void AccessibilityNodeManager::AddVisibleChangeNode(NodeId nodeId, double ratio, VisibleRatioCallback callback) {} - -void AccessibilityNodeManager::RemoveVisibleChangeNode(NodeId nodeId) {} - -void AccessibilityNodeManager::RemoveAccessibilityNodes(RefPtr& node) {} - -void AccessibilityNodeManager::RemoveAccessibilityNodeById(NodeId nodeId) {} - -void AccessibilityNodeManager::ClearPageAccessibilityNodes(int32_t pageId) {} - -void AccessibilityNodeManager::TrySaveTargetAndIdNode( - const std::string& id, const std::string& target, const RefPtr& node) {} - -void AccessibilityNodeManager::DumpHandleEvent(const std::vector& params) {} - -void AccessibilityNodeManager::DumpProperty(const std::vector& params) {} - -void AccessibilityNodeManager::DumpTree(int32_t depth, NodeId nodeID) {} - -void AccessibilityNodeManager::SetCardViewParams(const std::string& key, bool focus) {} - -void AccessibilityNodeManager::SetCardViewPosition(int id, float offsetX, float offsetY) {} - -std::unique_ptr AccessibilityNodeManager::DumpComposedElementsToJson() const -{ - return nullptr; -} - -std::unique_ptr AccessibilityNodeManager::DumpComposedElementToJson(NodeId nodeId) -{ - return nullptr; -} - -} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.cpp index ee03b7ef..8cff94b4 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_click_function.cpp @@ -46,6 +46,8 @@ void JsClickFunction::Execute(const ClickInfo& info) obj->SetProperty("x", SystemProperties::Px2Vp(localOffset.GetX())); obj->SetProperty("y", SystemProperties::Px2Vp(localOffset.GetY())); obj->SetProperty("timestamp", static_cast(info.GetTimeStamp().time_since_epoch().count())); + auto target = CreateEventTargetObject(info); + obj->SetPropertyObject("target", target); LOGD("globalOffset.GetX() = %lf, globalOffset.GetY() = %lf, localOffset.GetX() = %lf, localOffset.GetY() = %lf", globalOffset.GetX(), globalOffset.GetY(), localOffset.GetX(), localOffset.GetY()); @@ -64,6 +66,8 @@ void JsClickFunction::Execute(const GestureEvent& info) obj->SetProperty("x", SystemProperties::Px2Vp(localOffset.GetX())); obj->SetProperty("y", SystemProperties::Px2Vp(localOffset.GetY())); obj->SetProperty("timestamp", static_cast(info.GetTimeStamp().time_since_epoch().count())); + auto target = CreateEventTargetObject(info); + obj->SetPropertyObject("target", target); LOGD("globalOffset.GetX() = %lf, globalOffset.GetY() = %lf, localOffset.GetX() = %lf, localOffset.GetY() = %lf", globalOffset.GetX(), globalOffset.GetY(), localOffset.GetX(), localOffset.GetY()); diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp index 01b41353..b6ac5973 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_function.cpp @@ -78,4 +78,23 @@ JSRef JsFunction::ExecuteJS(int argc, JSRef argv[]) return result; } +JSRef CreateEventTargetObject(const BaseEventInfo& info) +{ + JSRef objectTemplate = JSRef::New(); + JSRef target = objectTemplate->NewInstance(); + JSRef area = objectTemplate->NewInstance(); + JSRef offset = objectTemplate->NewInstance(); + JSRef globalOffset = objectTemplate->NewInstance(); + offset->SetProperty("dx", info.GetTarget().area.GetOffset().GetX().ConvertToVp()); + offset->SetProperty("dy", info.GetTarget().area.GetOffset().GetY().ConvertToVp()); + globalOffset->SetProperty("dx", info.GetTarget().area.GetGlobalOffset().GetX().ConvertToVp()); + globalOffset->SetProperty("dy", info.GetTarget().area.GetGlobalOffset().GetY().ConvertToVp()); + area->SetPropertyObject("pos", offset); + area->SetPropertyObject("globalPos", globalOffset); + area->SetProperty("width", info.GetTarget().area.GetWidth().ConvertToVp()); + area->SetProperty("height", info.GetTarget().area.GetHeight().ConvertToVp()); + target->SetPropertyObject("area", area); + return target; +} + } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_function.h b/frameworks/bridge/declarative_frontend/engine/functions/js_function.h index b1c54bba..314c96e8 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_function.h +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_function.h @@ -73,6 +73,8 @@ private: ParseFunc parser_; }; +JSRef CreateEventTargetObject(const BaseEventInfo& info); + } // namespace OHOS::Ace::Framework #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_FUNCTION_H diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp index 672f3cd1..d8de6665 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.cpp @@ -56,6 +56,8 @@ JSRef JsGestureFunction::CreateGestureEvent(const GestureEvent& info) } gestureInfoObj->SetPropertyObject("fingerList", fingerArr); + auto target = CreateEventTargetObject(info); + gestureInfoObj->SetPropertyObject("target", target); return gestureInfoObj; } diff --git a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.cpp b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.cpp index def283ac..04cf31e5 100644 --- a/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.cpp +++ b/frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.cpp @@ -16,6 +16,7 @@ #include "frameworks/bridge/declarative_frontend/engine/functions/js_touch_function.h" #include "base/log/log.h" +#include "bridge/declarative_frontend/engine/functions/js_function.h" #include "frameworks/bridge/declarative_frontend/jsview/js_view_register.h" namespace OHOS::Ace::Framework { @@ -43,6 +44,9 @@ JSRef JsTouchFunction::CreateJSEventInfo(TouchEventInfo& info) JSRef changeTouchArr = JSRef::New(); eventObj->SetProperty("timestamp", static_cast(info.GetTimeStamp().time_since_epoch().count())); + auto target = CreateEventTargetObject(info); + eventObj->SetPropertyObject("target", target); + const std::list& touchList = info.GetTouches(); uint32_t idx = 0; for (const TouchLocationInfo& location : touchList) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_button.cpp b/frameworks/bridge/declarative_frontend/jsview/js_button.cpp index 9d32727c..20e8b0d8 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_button.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_button.cpp @@ -215,13 +215,16 @@ void JSButton::JsOnClick(const JSCallbackInfo& info) { LOGD("JSButton JsOnClick"); if (info[0]->IsFunction()) { + auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId(); JSRef clickFunction = JSRef::Cast(info[0]); auto onClickFunc = AceType::MakeRefPtr(clickFunction); EventMarker clickEventId( - [execCtx = info.GetExecutionContext(), func = std::move(onClickFunc)](const BaseEventInfo* info) { + [execCtx = info.GetExecutionContext(), func = std::move(onClickFunc), nodeId](const BaseEventInfo* info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto clickInfo = TypeInfoHelper::DynamicCast(info); - func->Execute(*clickInfo); + auto newInfo = *clickInfo; + UpdateEventTarget(nodeId, newInfo); + func->Execute(newInfo); }); auto buttonComponent = diff --git a/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp b/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp index 77d4ae69..7ebb4f41 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_gesture.cpp @@ -16,6 +16,7 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_gesture.h" #include "frameworks/bridge/declarative_frontend/engine/functions/js_gesture_function.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" #include "frameworks/bridge/declarative_frontend/view_stack_processor.h" #include "frameworks/core/components/gesture_listener/gesture_component.h" #include "frameworks/core/gestures/gesture_group.h" @@ -287,20 +288,24 @@ void JSGesture::JsHandlerOnGestureEvent(JSGestureEvent action, const JSCallbackI return; } + auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId(); RefPtr handlerFunc = AceType::MakeRefPtr(JSRef::Cast(args[0])); if (action == JSGestureEvent::CANCEL) { - auto onActionCancelFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc)]() { + auto onActionCancelFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc), nodeId]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); - func->Execute(); + auto info = GestureEvent(); + JSInteractableView::UpdateEventTarget(nodeId, info); + func->Execute(info); }; gesture->SetOnActionCancelId(onActionCancelFunc); return; } - auto onActionFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc)]( - const GestureEvent& info) { + auto onActionFunc = [execCtx = args.GetExecutionContext(), func = std::move(handlerFunc), nodeId]( + GestureEvent& info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + JSInteractableView::UpdateEventTarget(nodeId, info); func->Execute(info); }; @@ -481,4 +486,5 @@ void JSGesture::JSBind(BindingTarget globalObj) JSClass::StaticMethod("onCancel", &JSGesture::JsHandlerOnActionCancel); JSClass::Bind<>(globalObj); } + }; // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_interactable_view.cpp b/frameworks/bridge/declarative_frontend/jsview/js_interactable_view.cpp index bfe03055..de30d495 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_interactable_view.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_interactable_view.cpp @@ -15,6 +15,8 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h" +#include "base/log/log_wrapper.h" +#include "core/common/container.h" #include "core/components/gesture_listener/gesture_listener_component.h" #include "core/gestures/click_recognizer.h" #include "core/pipeline/base/single_child.h" @@ -32,10 +34,12 @@ void JSInteractableView::JsOnTouch(const JSCallbackInfo& args) { LOGD("JSInteractableView JsOnTouch"); if (args[0]->IsFunction()) { + auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId(); RefPtr jsOnTouchFunc = AceType::MakeRefPtr(JSRef::Cast(args[0])); auto onTouchId = EventMarker( - [execCtx = args.GetExecutionContext(), func = std::move(jsOnTouchFunc)](BaseEventInfo* info) { + [execCtx = args.GetExecutionContext(), func = std::move(jsOnTouchFunc), nodeId](BaseEventInfo* info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + UpdateEventTarget(nodeId, *info); auto touchInfo = TypeInfoHelper::DynamicCast(info); func->Execute(*touchInfo); }, @@ -113,23 +117,28 @@ void JSInteractableView::JsOnClick(const JSCallbackInfo& info) EventMarker JSInteractableView::GetClickEventMarker(const JSCallbackInfo& info) { + auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId(); RefPtr jsOnClickFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); - auto onClickId = EventMarker([execCtx = info.GetExecutionContext(), func = std::move(jsOnClickFunc)] + auto onClickId = EventMarker([execCtx = info.GetExecutionContext(), func = std::move(jsOnClickFunc), nodeId] (const BaseEventInfo* info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); auto clickInfo = TypeInfoHelper::DynamicCast(info); - func->Execute(*clickInfo); + auto newInfo = *clickInfo; + UpdateEventTarget(nodeId, newInfo); + func->Execute(newInfo); }); return onClickId; } RefPtr JSInteractableView::GetTapGesture(const JSCallbackInfo& info) { + auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId(); RefPtr tapGesture = AceType::MakeRefPtr(); RefPtr jsOnClickFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); - tapGesture->SetOnActionId([execCtx = info.GetExecutionContext(), func = std::move(jsOnClickFunc)] - (const GestureEvent& info) { + tapGesture->SetOnActionId([execCtx = info.GetExecutionContext(), func = std::move(jsOnClickFunc), nodeId] + (GestureEvent& info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + UpdateEventTarget(nodeId, info); func->Execute(info); }); return tapGesture; @@ -196,6 +205,26 @@ void JSInteractableView::JsOnAccessibility(const JSCallbackInfo& info) } } +void JSInteractableView::UpdateEventTarget(NodeId id, BaseEventInfo& info) +{ + auto container = Container::Current(); + if (!container) { + LOGE("fail to get container"); + return; + } + auto context = container->GetPipelineContext(); + if (!context) { + LOGE("fail to get context"); + return; + } + auto accessibilityManager = context->GetAccessibilityManager(); + if (!accessibilityManager) { + LOGE("fail to get accessibility manager"); + return; + } + accessibilityManager->UpdateEventTarget(id, info); +} + EventMarker JSInteractableView::GetEventMarker(const JSCallbackInfo& info, const std::vector& keys) { if (!info[0]->IsFunction()) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h b/frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h index 39d4821e..c00fd3c9 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_interactable_view.h @@ -42,6 +42,8 @@ public: static void JsOnDelete(const JSCallbackInfo& info); static void JsOnAccessibility(const JSCallbackInfo& info); + static void UpdateEventTarget(NodeId nodeId, BaseEventInfo& info); + private: static EventMarker GetEventMarker(const JSCallbackInfo& info, const std::vector& keys); }; // class JSInteractableView diff --git a/frameworks/bridge/declarative_frontend/jsview/js_span.cpp b/frameworks/bridge/declarative_frontend/jsview/js_span.cpp index dc45abee..5dcf02d4 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_span.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_span.cpp @@ -234,13 +234,16 @@ void JSSpan::SetDecoration(const JSCallbackInfo& info) void JSSpan::JsOnClick(const JSCallbackInfo& info) { if (info[0]->IsFunction()) { + auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId(); RefPtr jsOnClickFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); - auto onClickId = EventMarker([execCtx = info.GetExecutionContext(), func = std::move(jsOnClickFunc)] + auto onClickId = EventMarker([execCtx = info.GetExecutionContext(), func = std::move(jsOnClickFunc), nodeId] (const BaseEventInfo* info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); LOGD("About to call onclick method on js"); auto clickInfo = TypeInfoHelper::DynamicCast(info); - func->Execute(*clickInfo); + auto newInfo = *clickInfo; + UpdateEventTarget(nodeId, newInfo); + func->Execute(newInfo); }); auto component = GetComponent(); if (component) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp index 4ec826d1..2ad9149a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp @@ -361,13 +361,16 @@ void JSText::SetDecoration(const JSCallbackInfo& info) void JSText::JsOnClick(const JSCallbackInfo& info) { if (info[0]->IsFunction()) { + auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId(); RefPtr jsOnClickFunc = AceType::MakeRefPtr(JSRef::Cast(info[0])); - auto onClickId = EventMarker([execCtx = info.GetExecutionContext(), func = std::move(jsOnClickFunc)] + auto onClickId = EventMarker([execCtx = info.GetExecutionContext(), func = std::move(jsOnClickFunc), nodeId] (const BaseEventInfo* info) { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); LOGD("About to call onclick method on js"); auto clickInfo = TypeInfoHelper::DynamicCast(info); - func->Execute(*clickInfo); + auto newInfo = *clickInfo; + UpdateEventTarget(nodeId, newInfo); + func->Execute(newInfo); }); auto click = ViewStackProcessor::GetInstance()->GetClickGestureListenerComponent(); if (click) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_context.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_context.cpp index a438054d..d5643e69 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_context.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_context.cpp @@ -15,6 +15,8 @@ #include "bridge/declarative_frontend/jsview/js_view_context.h" +#include + #include "base/utils/system_properties.h" #include "bridge/common/utils/utils.h" #include "bridge/declarative_frontend/engine/functions/js_function.h" @@ -95,13 +97,13 @@ void JSViewContext::JSAnimation(const JSCallbackInfo& info) JSRef obj = JSRef::Cast(info[0]); JSRef onFinish = obj->GetProperty("onFinish"); - EventMarker onFinishEvent; + std::function onFinishEvent; if (onFinish->IsFunction()) { RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(onFinish)); - onFinishEvent = EventMarker([execCtx = info.GetExecutionContext(), func = std::move(jsFunc)]() { + onFinishEvent = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc)]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); func->Execute(); - }); + }; } auto animationArgs = JsonUtil::ParseJsonString(info[0]->ToString()); @@ -136,13 +138,13 @@ void JSViewContext::JSAnimateTo(const JSCallbackInfo& info) JSRef obj = JSRef::Cast(info[0]); JSRef onFinish = obj->GetProperty("onFinish"); - EventMarker onFinishEvent; + std::function onFinishEvent; if (onFinish->IsFunction()) { RefPtr jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(onFinish)); - onFinishEvent = EventMarker([execCtx = info.GetExecutionContext(), func = std::move(jsFunc)]() { + onFinishEvent = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc)]() { JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); func->Execute(); - }); + }; } auto animationArgs = JsonUtil::ParseJsonString(info[0]->ToString()); @@ -167,11 +169,10 @@ void JSViewContext::JSAnimateTo(const JSCallbackInfo& info) AnimationOption option = CreateAnimation(animationArgs); if (SystemProperties::GetRosenBackendEnabled()) { LOGD("RSAnimationInfo: Begin JSAnimateTo"); - auto finishCallBack = AceAsyncEvent::Create(onFinishEvent, pipelineContext); pipelineContext->FlushBuild(); auto curve = option.GetCurve() != nullptr ? option.GetCurve()->ToNativeCurve() : Rosen::RSAnimationTimingCurve::DEFAULT; - pipelineContext->OpenImplicitAnimation(option, curve, finishCallBack); + pipelineContext->OpenImplicitAnimation(option, curve, onFinishEvent); // Execute the function. JSRef jsAnimateToFunc = JSRef::Cast(info[1]); jsAnimateToFunc->Call(info[1]); diff --git a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp index 6b81471f..83fc3afe 100644 --- a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp +++ b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp @@ -19,6 +19,7 @@ #include "base/log/ace_trace.h" #include "base/utils/system_properties.h" +#include "core/accessibility/accessibility_node.h" #include "core/common/ace_application_info.h" #include "core/components/button/button_component.h" #include "core/components/grid_layout/grid_layout_item_component.h" @@ -29,6 +30,7 @@ #include "core/components/text_span/text_span_component.h" #include "core/components/video/video_component_v2.h" #include "core/components_v2/list/list_item_component.h" +#include "core/pipeline/base/component.h" #include "core/pipeline/base/multi_composed_component.h" #include "core/pipeline/base/sole_child_component.h" @@ -136,13 +138,17 @@ RefPtr ViewStackProcessor::GetBoxComponent() return boxComponent; } -RefPtr ViewStackProcessor::GetMainComponent() +RefPtr ViewStackProcessor::GetMainComponent() const { if (componentsStack_.empty()) { return nullptr; } auto& wrappingComponentsMap = componentsStack_.top(); - return wrappingComponentsMap["main"]; + auto main = wrappingComponentsMap.find("main"); + if (main == wrappingComponentsMap.end()) { + return nullptr; + } + return main->second; } bool ViewStackProcessor::HasDisplayComponent() const @@ -339,14 +345,22 @@ void ViewStackProcessor::CreateAccessibilityNode( return; } component->SetInspectorId(GenerateId()); - int32_t inspectorId = StringUtils::StringToInt(component->GetInspectorId()); - std::string tag = inspectorTag.empty() ? AceType::TypeName(component) : inspectorTag; - int32_t parentId = - componentsStack_.empty() ? stackRootId_ : StringUtils::StringToInt(GetMainComponent()->GetInspectorId()); - auto node = OHOS::Ace::V2::InspectorComposedComponent::CreateAccessibilityNode(tag, inspectorId, parentId, -1); - if (!node) { - LOGD("Create AccessibilityNode:%{public}s Failed", tag.c_str()); - return; + +#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM) + bool needCreate = true; +#else + bool needCreate = false; +#endif + if (AceApplicationInfo::GetInstance().IsAccessibilityEnabled() || SystemProperties::GetAccessibilityEnabled() || + needCreate) { + int32_t inspectorId = StringUtils::StringToInt(component->GetInspectorId()); + std::string tag = inspectorTag.empty() ? AceType::TypeName(component) : inspectorTag; + int32_t parentId = + componentsStack_.empty() ? stackRootId_ : StringUtils::StringToInt(GetMainComponent()->GetInspectorId()); + auto node = OHOS::Ace::V2::InspectorComposedComponent::CreateAccessibilityNode(tag, inspectorId, parentId, -1); + if (!node) { + LOGD("Create AccessibilityNode:%{public}s Failed", tag.c_str()); + } } } @@ -356,13 +370,7 @@ void ViewStackProcessor::Push(const RefPtr& component, bool isCustomV if (componentsStack_.size() > 1 && ShouldPopImmediately()) { Pop(); } -#if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM) CreateAccessibilityNode(component, isCustomView, inspectorTag); -#else - if (AceApplicationInfo::GetInstance().IsAccessibilityEnabled() || SystemProperties::GetAccessibilityEnabled()) { - CreateAccessibilityNode(component, isCustomView, inspectorTag); - } -#endif wrappingComponentsMap.emplace("main", component); componentsStack_.push(wrappingComponentsMap); #if defined(WINDOWS_PLATFORM) || defined(MAC_PLATFORM) @@ -739,6 +747,15 @@ void ViewStackProcessor::SetIsPercentSize(RefPtr& component) } } +NodeId ViewStackProcessor::GetCurrentInspectorNodeId() const +{ + auto&& componet = GetMainComponent(); + if (!componet) { + return -1; + } + return StringUtils::StringToInt(componet->GetInspectorId()); +} + ScopedViewStackProcessor::ScopedViewStackProcessor() { std::swap(instance_, ViewStackProcessor::instance); diff --git a/frameworks/bridge/declarative_frontend/view_stack_processor.h b/frameworks/bridge/declarative_frontend/view_stack_processor.h index 2ec1d6c1..3600bb5d 100644 --- a/frameworks/bridge/declarative_frontend/view_stack_processor.h +++ b/frameworks/bridge/declarative_frontend/view_stack_processor.h @@ -21,6 +21,7 @@ #include #include +#include "core/accessibility/accessibility_node.h" #include "core/components/common/properties/animation_option.h" #include "core/pipeline/base/component.h" #include "frameworks/core/components/box/box_component.h" @@ -57,7 +58,7 @@ public: static std::string GenerateId(); RefPtr GetFlexItemComponent(); RefPtr GetBoxComponent(); - RefPtr GetMainComponent(); + RefPtr GetMainComponent() const; RefPtr GetDisplayComponent(); bool HasDisplayComponent() const; RefPtr GetTransformComponent(); @@ -128,6 +129,8 @@ public: void SetIsPercentSize(RefPtr& component); std::shared_ptr GetRadioGroupCompnent(); + NodeId GetCurrentInspectorNodeId() const; + private: ViewStackProcessor(); diff --git a/frameworks/core/accessibility/accessibility_manager.h b/frameworks/core/accessibility/accessibility_manager.h index a635af43..c38943a5 100644 --- a/frameworks/core/accessibility/accessibility_manager.h +++ b/frameworks/core/accessibility/accessibility_manager.h @@ -71,6 +71,7 @@ public: virtual void AddVisibleChangeNode(NodeId nodeId, double ratio, VisibleRatioCallback callback) = 0; virtual void RemoveVisibleChangeNode(NodeId nodeId) = 0; virtual bool IsVisibleChangeNodeExists(NodeId nodeId) = 0; + virtual void UpdateEventTarget(NodeId id, BaseEventInfo& info) = 0; void SetVersion(AccessibilityVersion version) { diff --git a/frameworks/core/animation/animatable_base.h b/frameworks/core/animation/animatable_base.h index 79ce1770..3ae14a4b 100644 --- a/frameworks/core/animation/animatable_base.h +++ b/frameworks/core/animation/animatable_base.h @@ -124,9 +124,14 @@ protected: void ApplyAnimationOptions() { auto onFinishEvent = animationOption_.GetOnFinishEvent(); - if (!onFinishEvent.IsEmpty()) { + if (onFinishEvent) { animationController_->AddStopListener([onFinishEvent, weakContext = context_] { - AceAsyncEvent::Create(onFinishEvent, weakContext)(); + auto context = weakContext.Upgrade(); + if (context) { + context->PostAsyncEvent(onFinishEvent); + } else { + LOGE("the context is null"); + } }); } if (stopCallback_) { diff --git a/frameworks/core/components/box/render_box_base.h b/frameworks/core/components/box/render_box_base.h index 62e932d0..cdaf2890 100644 --- a/frameworks/core/components/box/render_box_base.h +++ b/frameworks/core/components/box/render_box_base.h @@ -149,7 +149,7 @@ public: Dimension GetWidthDimension() const { - return static_cast(width_); + return width_; } virtual void SetHeight(const Dimension& height) // add for animation @@ -162,7 +162,7 @@ public: Dimension GetHeightDimension() const { - return static_cast(height_); + return height_; } EdgePx GetMargin() const diff --git a/frameworks/core/components/common/properties/animatable_color.h b/frameworks/core/components/common/properties/animatable_color.h index e5cf736d..39a35749 100644 --- a/frameworks/core/components/common/properties/animatable_color.h +++ b/frameworks/core/components/common/properties/animatable_color.h @@ -106,9 +106,14 @@ private: animationController_->AddInterpolator(colorAnimation); auto onFinishEvent = animationOption_.GetOnFinishEvent(); - if (!onFinishEvent.IsEmpty()) { + if (onFinishEvent) { animationController_->AddStopListener([onFinishEvent, weakContext = context_] { - AceAsyncEvent::Create(onFinishEvent, weakContext)(); + auto context = weakContext.Upgrade(); + if (context) { + context->PostAsyncEvent(onFinishEvent); + } else { + LOGE("the context is null"); + } }); } animationController_->SetDuration(animationOption_.GetDuration()); diff --git a/frameworks/core/components/common/properties/animatable_double.h b/frameworks/core/components/common/properties/animatable_double.h index 4d0e0eb0..d7903bbc 100644 --- a/frameworks/core/components/common/properties/animatable_double.h +++ b/frameworks/core/components/common/properties/animatable_double.h @@ -137,9 +137,14 @@ private: animationController_->AddInterpolator(animation); auto onFinishEvent = animationOption_.GetOnFinishEvent(); - if (!onFinishEvent.IsEmpty()) { + if (onFinishEvent) { animationController_->AddStopListener([onFinishEvent, weakContext = context_] { - AceAsyncEvent::Create(onFinishEvent, weakContext)(); + auto context = weakContext.Upgrade(); + if (context) { + context->PostAsyncEvent(onFinishEvent); + } else { + LOGE("the context is null"); + } }); } if (stopCallback_) { diff --git a/frameworks/core/components/common/properties/animatable_path.cpp b/frameworks/core/components/common/properties/animatable_path.cpp index ca11376c..ce4167c3 100644 --- a/frameworks/core/components/common/properties/animatable_path.cpp +++ b/frameworks/core/components/common/properties/animatable_path.cpp @@ -82,9 +82,15 @@ void AnimatablePath::AnimateTo(std::string endValue) animationController_->AddInterpolator(animation); auto onFinishEvent = animationOption_.GetOnFinishEvent(); - if (!onFinishEvent.IsEmpty()) { - animationController_->AddStopListener( - [onFinishEvent, weakContext = context_] { AceAsyncEvent::Create(onFinishEvent, weakContext)(); }); + if (onFinishEvent) { + animationController_->AddStopListener([onFinishEvent, weakContext = context_] { + auto context = weakContext.Upgrade(); + if (context) { + context->PostAsyncEvent(onFinishEvent); + } else { + LOGE("the context is null"); + } + }); } animationController_->SetDuration(animationOption_.GetDuration()); animationController_->SetStartDelay(animationOption_.GetDelay()); diff --git a/frameworks/core/components/common/properties/animation_option.h b/frameworks/core/components/common/properties/animation_option.h index 16448222..9dddffbe 100644 --- a/frameworks/core/components/common/properties/animation_option.h +++ b/frameworks/core/components/common/properties/animation_option.h @@ -16,12 +16,12 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_PROPERTIES_ANIMATION_OPTION_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_PROPERTIES_ANIMATION_OPTION_H +#include #include #include #include "core/animation/animation_pub.h" #include "core/animation/curve.h" -#include "core/event/ace_event_handler.h" namespace OHOS::Ace { @@ -107,12 +107,12 @@ public: return fillMode_; } - void SetOnFinishEvent(const EventMarker& onFinishEvent) + void SetOnFinishEvent(const std::function& onFinishEvent) { onFinishEvent_ = onFinishEvent; } - const EventMarker& GetOnFinishEvent() const + const std::function& GetOnFinishEvent() const { return onFinishEvent_; } @@ -141,7 +141,7 @@ private: bool allowRunningAsynchronously_ = false; RefPtr curve_; - EventMarker onFinishEvent_; + std::function onFinishEvent_; AnimationDirection direction_ = AnimationDirection::NORMAL; }; diff --git a/frameworks/core/components/image/rosen_render_image.cpp b/frameworks/core/components/image/rosen_render_image.cpp index 2320144f..4c8ad7d9 100644 --- a/frameworks/core/components/image/rosen_render_image.cpp +++ b/frameworks/core/components/image/rosen_render_image.cpp @@ -328,17 +328,8 @@ void RosenRenderImage::FetchImageObject() SrcType srcType = ImageLoader::ResolveURI(sourceInfo_.GetSrc()); if (srcType != SrcType::MEMORY) { bool syncMode = context->IsBuildingFirstPage() && frontend->GetType() == FrontendType::JS_CARD; - ImageProvider::FetchImageObject( - sourceInfo_, - imageObjSuccessCallback_, - uploadSuccessCallback_, - failedCallback_, - GetContext(), - syncMode, - useSkiaSvg_, - autoResize_, - renderTaskHolder_, - onPostBackgroundTask_); + ImageProvider::FetchImageObject(sourceInfo_, imageObjSuccessCallback_, uploadSuccessCallback_, failedCallback_, + GetContext(), syncMode, useSkiaSvg_, autoResize_, renderTaskHolder_, onPostBackgroundTask_); return; } auto sharedImageManager = context->GetSharedImageManager(); @@ -506,16 +497,14 @@ void RosenRenderImage::ApplyColorFilter(SkPaint& paint) return; } paint.setColorFilter(SkColorFilter::MakeModeFilter( - SkColorSetARGB(color.GetAlpha(), color.GetRed(), color.GetGreen(), color.GetBlue()), - SkBlendMode::kPlus)); + SkColorSetARGB(color.GetAlpha(), color.GetRed(), color.GetGreen(), color.GetBlue()), SkBlendMode::kPlus)); #else if (imageRenderMode_ == ImageRenderMode::TEMPLATE) { paint.setColorFilter(SkColorFilters::Matrix(GRAY_COLOR_MATRIX)); return; } paint.setColorFilter(SkColorFilters::Blend( - SkColorSetARGB(color.GetAlpha(), color.GetRed(), color.GetGreen(), color.GetBlue()), - SkBlendMode::kPlus)); + SkColorSetARGB(color.GetAlpha(), color.GetRed(), color.GetGreen(), color.GetBlue()), SkBlendMode::kPlus)); #endif } @@ -989,18 +978,8 @@ bool RosenRenderImage::RetryLoading() return false; } bool syncMode = context->IsBuildingFirstPage() && frontend->GetType() == FrontendType::JS_CARD; - - ImageProvider::FetchImageObject( - sourceInfo_, - imageObjSuccessCallback_, - uploadSuccessCallback_, - failedCallback_, - GetContext(), - syncMode, - useSkiaSvg_, - autoResize_, - renderTaskHolder_, - onPostBackgroundTask_); + ImageProvider::FetchImageObject(sourceInfo_, imageObjSuccessCallback_, uploadSuccessCallback_, failedCallback_, + GetContext(), syncMode, useSkiaSvg_, autoResize_, renderTaskHolder_, onPostBackgroundTask_); LOGW("Retry loading time: %{public}d, triggered by GetImageSize fail, imageSrc: %{private}s", retryCnt_, sourceInfo_.ToString().c_str()); return true; diff --git a/frameworks/core/components/test/unittest/theme/theme_mock.cpp b/frameworks/core/components/test/unittest/theme/theme_mock.cpp index b99b4e87..d02a54cf 100644 --- a/frameworks/core/components/test/unittest/theme/theme_mock.cpp +++ b/frameworks/core/components/test/unittest/theme/theme_mock.cpp @@ -220,8 +220,10 @@ bool PipelineContext::GetIsDeclarative() const return true; } -void PipelineContext::AddGeometryChangedNode(const RefPtr& renderNode) -{ -} +void PipelineContext::AddGeometryChangedNode(const RefPtr& renderNode) {} + +void PipelineContext::PostAsyncEvent(const std::function&) {} + +void PipelineContext::PostAsyncEvent(std::function&&) {} } // namespace OHOS::Ace diff --git a/frameworks/core/event/ace_events.h b/frameworks/core/event/ace_events.h index 67edc258..f0d67d5c 100644 --- a/frameworks/core/event/ace_events.h +++ b/frameworks/core/event/ace_events.h @@ -21,12 +21,14 @@ #include "base/memory/type_info_base.h" #include "base/utils/type_definition.h" +#include "base/geometry/dimension_rect.h" namespace OHOS::Ace { struct EventTarget final { std::string id; std::string type; + DimensionRect area; }; class BaseEventInfo : public virtual TypeInfoBase { @@ -55,21 +57,17 @@ public: { return target_; } + EventTarget& GetTargetWichModify() + { + return target_; + } + BaseEventInfo& SetTarget(const EventTarget& target) { target_ = target; return *this; } - const EventTarget& GetCurrentTarget() const - { - return currentTarget_; - } - BaseEventInfo& SetCurrentTarget(const EventTarget& currentTarget) - { - currentTarget_ = currentTarget; - return *this; - } int64_t GetDeviceId() const { return deviceId_; @@ -87,13 +85,12 @@ public: stopPropagation_ = stopPropagation; } -private: +protected: // Event type like onTouchDown, onClick and so on. std::string type_; // The origin event time stamp. TimeStamp timeStamp_; EventTarget target_; - EventTarget currentTarget_; int64_t deviceId_ = 0; bool stopPropagation_ = false; }; diff --git a/frameworks/core/event/touch_event.h b/frameworks/core/event/touch_event.h index c5c070c5..45eca00c 100644 --- a/frameworks/core/event/touch_event.h +++ b/frameworks/core/event/touch_event.h @@ -153,7 +153,7 @@ private: TimeStamp time_; }; -class TouchLocationInfo : public TypeInfoBase { +class TouchLocationInfo : public virtual TypeInfoBase { DECLARE_RELATIONSHIP_OF_CLASSES(TouchLocationInfo, TypeInfoBase); public: diff --git a/frameworks/core/focus/test/unittest/focus/focus_test.cpp b/frameworks/core/focus/test/unittest/focus/focus_test.cpp index 44fffc7b..59fe540d 100644 --- a/frameworks/core/focus/test/unittest/focus/focus_test.cpp +++ b/frameworks/core/focus/test/unittest/focus/focus_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "gtest/gtest.h" #define protected public @@ -182,6 +183,10 @@ void PipelineContext::AddGeometryChangedNode(const RefPtr& renderNod void PipelineContext::ForceLayoutForImplicitAnimation() {} +void PipelineContext::PostAsyncEvent(const std::function&) {} + +void PipelineContext::PostAsyncEvent(std::function&&) {} + class FocusTest : public testing::Test { public: static void SetUpTestCase(); diff --git a/frameworks/core/gestures/gesture_info.h b/frameworks/core/gestures/gesture_info.h index 1a568c79..9ed42fe2 100644 --- a/frameworks/core/gestures/gesture_info.h +++ b/frameworks/core/gestures/gesture_info.h @@ -19,16 +19,17 @@ #include #include #include -#include #include +#include -#include "base/image/pixel_map.h" #include "base/geometry/offset.h" #include "base/geometry/point.h" +#include "base/image/pixel_map.h" #include "base/memory/ace_type.h" +#include "base/utils/event_callback.h" #include "base/utils/macros.h" #include "base/utils/type_definition.h" -#include "base/utils/event_callback.h" +#include "core/event/ace_events.h" namespace OHOS::Ace { @@ -274,9 +275,9 @@ struct FingerInfo { Offset localLocation_; }; -class GestureEvent { +class GestureEvent : public BaseEventInfo { public: - GestureEvent() {} + GestureEvent() : BaseEventInfo("gesture") {} ~GestureEvent() = default; void SetRepeat(bool repeat) @@ -329,17 +330,6 @@ public: return angle_; } - GestureEvent& SetTimeStamp(const TimeStamp& timeStamp) - { - timeStamp_ = timeStamp; - return *this; - } - - const TimeStamp& GetTimeStamp() const - { - return timeStamp_; - } - GestureEvent& SetGlobalPoint(const Point& globalPoint) { globalPoint_ = globalPoint; @@ -398,7 +388,6 @@ private: double offsetY_ = 0.0; double scale_ = 1.0; double angle_ = 0.0; - TimeStamp timeStamp_; Point globalPoint_; // global position at which the touch point contacts the screen. Offset globalLocation_; @@ -409,7 +398,7 @@ private: std::list fingerList_; }; -using GestureEventFunc = std::function; +using GestureEventFunc = std::function; using GestureEventNoParameter = std::function; class ACE_EXPORT Gesture : public virtual AceType { @@ -420,19 +409,19 @@ public: explicit Gesture(int32_t fingers) : fingers_(fingers) {}; ~Gesture() override = default; - void SetOnActionId(const GestureEventFunc&& onActionId) + void SetOnActionId(const GestureEventFunc& onActionId) { onActionId_ = std::make_unique(onActionId); } - void SetOnActionStartId(const GestureEventFunc&& onActionStartId) + void SetOnActionStartId(const GestureEventFunc& onActionStartId) { onActionStartId_ = std::make_unique(onActionStartId); } - void SetOnActionUpdateId(const GestureEventFunc&& onActionUpdateId) + void SetOnActionUpdateId(const GestureEventFunc& onActionUpdateId) { onActionUpdateId_ = std::make_unique(onActionUpdateId); } - void SetOnActionEndId(const GestureEventFunc&& onActionEndId) + void SetOnActionEndId(const GestureEventFunc& onActionEndId) { onActionEndId_ = std::make_unique(onActionEndId); } diff --git a/frameworks/core/pipeline/base/element.h b/frameworks/core/pipeline/base/element.h index 05b0003f..40175ed8 100644 --- a/frameworks/core/pipeline/base/element.h +++ b/frameworks/core/pipeline/base/element.h @@ -140,6 +140,15 @@ public: return Rect(); } + Rect GetRenderRectInLocal() const + { + auto renderNode = GetRenderNode(); + if (renderNode) { + return renderNode->GetPaintRect(); + } + return Rect(); + } + const std::list>& GetChildren() const; const WeakPtr& GetContext() const diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index b79ba658..c997d600 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -2929,4 +2929,22 @@ bool PipelineContext::IsVisibleChangeNodeExists(NodeId index) const return accessibilityManager->IsVisibleChangeNodeExists(index); } +void PipelineContext::PostAsyncEvent(TaskExecutor::Task&& task) +{ + if (taskExecutor_) { + taskExecutor_->PostTask(std::move(task), TaskExecutor::TaskType::UI); + } else { + LOGE("the task executor is nullptr"); + } +} + +void PipelineContext::PostAsyncEvent(const TaskExecutor::Task& task) +{ + if (taskExecutor_) { + taskExecutor_->PostTask(task, TaskExecutor::TaskType::UI); + } else { + LOGE("the task executor is nullptr"); + } +} + } // namespace OHOS::Ace diff --git a/frameworks/core/pipeline/pipeline_context.h b/frameworks/core/pipeline/pipeline_context.h index 0012e2fb..d832ae68 100644 --- a/frameworks/core/pipeline/pipeline_context.h +++ b/frameworks/core/pipeline/pipeline_context.h @@ -240,6 +240,10 @@ public: eventTrigger_.TriggerSyncEvent(marker, std::forward(args)...); } + void PostAsyncEvent(TaskExecutor::Task&& task); + + void PostAsyncEvent(const TaskExecutor::Task& task); + void OnSurfaceChanged(int32_t width, int32_t height); void OnSurfaceDensityChanged(double density);