update event target.

Signed-off-by: sunfei <sunfei.sun@huawei.com>
Change-Id:  I19b41a8c98fdd8e04bd29b5515ecdf7a2052db8a
This commit is contained in:
yanshuifeng
2021-11-11 21:21:40 +08:00
committed by sunfei
parent f9f5b69449
commit ff9a51f012
40 changed files with 496 additions and 249 deletions
+1 -1
View File
@@ -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;
@@ -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<void()>::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_);
@@ -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<void()>::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_);
+13
View File
@@ -19,6 +19,7 @@
#include <string>
#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_);
+104
View File
@@ -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 <cmath>
#include <limits>
#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
+98
View File
@@ -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 <iomanip>
#include <limits>
#include <sstream>
#include <string>
#include "base/geometry/dimension.h"
#include "base/utils/utils.h"
namespace OHOS::Ace {
class DimensionSize {
public:
static constexpr double INFINITE_SIZE = std::numeric_limits<double>::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<class T>
static double CalcRatio(const T& rectangle)
{
if (NearZero(static_cast<double>(rectangle.Height()))) {
return INFINITE_SIZE;
}
return static_cast<double>(rectangle.Width()) / static_cast<double>(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
@@ -37,10 +37,8 @@ template("bridge_accessibility") {
]
}
} else {
sources -= [ "accessibility_node_manager.cpp" ]
sources += [
"fake_accessibility_manager.cpp",
"fake_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<V2::InspectorComposedElement>(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();
@@ -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();
@@ -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<PipelineContext>& context) {}
void AccessibilityNodeManager::SetRunningPage(const RefPtr<JsAcePage>& page) {}
std::string AccessibilityNodeManager::GetNodeChildIds(const RefPtr<AccessibilityNode>& node)
{
return "";
}
void AccessibilityNodeManager::AddNodeWithId(const std::string& key, const RefPtr<AccessibilityNode>& node) {}
void AccessibilityNodeManager::AddNodeWithTarget(const std::string& key, const RefPtr<AccessibilityNode>& node) {}
RefPtr<AccessibilityNode> AccessibilityNodeManager::GetAccessibilityNodeFromPage(NodeId nodeId) const
{
return nullptr;
}
void AccessibilityNodeManager::ClearNodeRectInfo(RefPtr<AccessibilityNode>& 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<AccessibilityNode> AccessibilityNodeManager::CreateSpecializedNode(
const std::string& tag, int32_t nodeId, int32_t parentNodeId)
{
return nullptr;
}
RefPtr<AccessibilityNode> AccessibilityNodeManager::CreateAccessibilityNode(
const std::string& tag, int32_t nodeId, int32_t parentNodeId, int32_t itemIndex)
{
return nullptr;
}
RefPtr<AccessibilityNode> AccessibilityNodeManager::GetAccessibilityNodeById(NodeId nodeId) const
{
return nullptr;
}
void AccessibilityNodeManager::AddComposedElement(const std::string& key, const RefPtr<ComposedElement>& node) {}
void AccessibilityNodeManager::RemoveComposedElementById(const std::string& key) {}
WeakPtr<ComposedElement> 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<AccessibilityNode>& 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<AccessibilityNode>& node) {}
void AccessibilityNodeManager::DumpHandleEvent(const std::vector<std::string>& params) {}
void AccessibilityNodeManager::DumpProperty(const std::vector<std::string>& 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<JsonValue> AccessibilityNodeManager::DumpComposedElementsToJson() const
{
return nullptr;
}
std::unique_ptr<JsonValue> AccessibilityNodeManager::DumpComposedElementToJson(NodeId nodeId)
{
return nullptr;
}
} // namespace OHOS::Ace::Framework
@@ -46,6 +46,8 @@ void JsClickFunction::Execute(const ClickInfo& info)
obj->SetProperty<double>("x", SystemProperties::Px2Vp(localOffset.GetX()));
obj->SetProperty<double>("y", SystemProperties::Px2Vp(localOffset.GetY()));
obj->SetProperty<double>("timestamp", static_cast<double>(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<double>("x", SystemProperties::Px2Vp(localOffset.GetX()));
obj->SetProperty<double>("y", SystemProperties::Px2Vp(localOffset.GetY()));
obj->SetProperty<double>("timestamp", static_cast<double>(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());
@@ -78,4 +78,23 @@ JSRef<JSVal> JsFunction::ExecuteJS(int argc, JSRef<JSVal> argv[])
return result;
}
JSRef<JSObject> CreateEventTargetObject(const BaseEventInfo& info)
{
JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
JSRef<JSObject> target = objectTemplate->NewInstance();
JSRef<JSObject> area = objectTemplate->NewInstance();
JSRef<JSObject> offset = objectTemplate->NewInstance();
JSRef<JSObject> globalOffset = objectTemplate->NewInstance();
offset->SetProperty<double>("dx", info.GetTarget().area.GetOffset().GetX().ConvertToVp());
offset->SetProperty<double>("dy", info.GetTarget().area.GetOffset().GetY().ConvertToVp());
globalOffset->SetProperty<double>("dx", info.GetTarget().area.GetGlobalOffset().GetX().ConvertToVp());
globalOffset->SetProperty<double>("dy", info.GetTarget().area.GetGlobalOffset().GetY().ConvertToVp());
area->SetPropertyObject("pos", offset);
area->SetPropertyObject("globalPos", globalOffset);
area->SetProperty<double>("width", info.GetTarget().area.GetWidth().ConvertToVp());
area->SetProperty<double>("height", info.GetTarget().area.GetHeight().ConvertToVp());
target->SetPropertyObject("area", area);
return target;
}
} // namespace OHOS::Ace::Framework
@@ -73,6 +73,8 @@ private:
ParseFunc parser_;
};
JSRef<JSObject> CreateEventTargetObject(const BaseEventInfo& info);
} // namespace OHOS::Ace::Framework
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_FUNCTION_JS_FUNCTION_H
@@ -56,6 +56,8 @@ JSRef<JSObject> JsGestureFunction::CreateGestureEvent(const GestureEvent& info)
}
gestureInfoObj->SetPropertyObject("fingerList", fingerArr);
auto target = CreateEventTargetObject(info);
gestureInfoObj->SetPropertyObject("target", target);
return gestureInfoObj;
}
@@ -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<JSObject> JsTouchFunction::CreateJSEventInfo(TouchEventInfo& info)
JSRef<JSArray> changeTouchArr = JSRef<JSArray>::New();
eventObj->SetProperty<double>("timestamp", static_cast<double>(info.GetTimeStamp().time_since_epoch().count()));
auto target = CreateEventTargetObject(info);
eventObj->SetPropertyObject("target", target);
const std::list<TouchLocationInfo>& touchList = info.GetTouches();
uint32_t idx = 0;
for (const TouchLocationInfo& location : touchList) {
@@ -215,13 +215,16 @@ void JSButton::JsOnClick(const JSCallbackInfo& info)
{
LOGD("JSButton JsOnClick");
if (info[0]->IsFunction()) {
auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId();
JSRef<JSFunc> clickFunction = JSRef<JSFunc>::Cast(info[0]);
auto onClickFunc = AceType::MakeRefPtr<JsClickFunction>(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<ClickInfo>(info);
func->Execute(*clickInfo);
auto newInfo = *clickInfo;
UpdateEventTarget(nodeId, newInfo);
func->Execute(newInfo);
});
auto buttonComponent =
@@ -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<JsGestureFunction> handlerFunc = AceType::MakeRefPtr<JsGestureFunction>(JSRef<JSFunc>::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<JSGestureGroup>::StaticMethod("onCancel", &JSGesture::JsHandlerOnActionCancel);
JSClass<JSGestureGroup>::Bind<>(globalObj);
}
}; // namespace OHOS::Ace::Framework
@@ -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<JsTouchFunction> jsOnTouchFunc = AceType::MakeRefPtr<JsTouchFunction>(JSRef<JSFunc>::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<TouchEventInfo>(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<JsClickFunction> jsOnClickFunc = AceType::MakeRefPtr<JsClickFunction>(JSRef<JSFunc>::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<ClickInfo>(info);
func->Execute(*clickInfo);
auto newInfo = *clickInfo;
UpdateEventTarget(nodeId, newInfo);
func->Execute(newInfo);
});
return onClickId;
}
RefPtr<Gesture> JSInteractableView::GetTapGesture(const JSCallbackInfo& info)
{
auto nodeId = ViewStackProcessor::GetInstance()->GetCurrentInspectorNodeId();
RefPtr<Gesture> tapGesture = AceType::MakeRefPtr<TapGesture>();
RefPtr<JsClickFunction> jsOnClickFunc = AceType::MakeRefPtr<JsClickFunction>(JSRef<JSFunc>::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<std::string>& keys)
{
if (!info[0]->IsFunction()) {
@@ -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<std::string>& keys);
}; // class JSInteractableView
@@ -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<JsClickFunction> jsOnClickFunc = AceType::MakeRefPtr<JsClickFunction>(JSRef<JSFunc>::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<ClickInfo>(info);
func->Execute(*clickInfo);
auto newInfo = *clickInfo;
UpdateEventTarget(nodeId, newInfo);
func->Execute(newInfo);
});
auto component = GetComponent();
if (component) {
@@ -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<JsClickFunction> jsOnClickFunc = AceType::MakeRefPtr<JsClickFunction>(JSRef<JSFunc>::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<ClickInfo>(info);
func->Execute(*clickInfo);
auto newInfo = *clickInfo;
UpdateEventTarget(nodeId, newInfo);
func->Execute(newInfo);
});
auto click = ViewStackProcessor::GetInstance()->GetClickGestureListenerComponent();
if (click) {
@@ -15,6 +15,8 @@
#include "bridge/declarative_frontend/jsview/js_view_context.h"
#include <functional>
#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<JSObject> obj = JSRef<JSObject>::Cast(info[0]);
JSRef<JSVal> onFinish = obj->GetProperty("onFinish");
EventMarker onFinishEvent;
std::function<void()> onFinishEvent;
if (onFinish->IsFunction()) {
RefPtr<JsFunction> jsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::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<JSObject> obj = JSRef<JSObject>::Cast(info[0]);
JSRef<JSVal> onFinish = obj->GetProperty("onFinish");
EventMarker onFinishEvent;
std::function<void()> onFinishEvent;
if (onFinish->IsFunction()) {
RefPtr<JsFunction> jsFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::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<void()>::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<JSFunc> jsAnimateToFunc = JSRef<JSFunc>::Cast(info[1]);
jsAnimateToFunc->Call(info[1]);
@@ -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<BoxComponent> ViewStackProcessor::GetBoxComponent()
return boxComponent;
}
RefPtr<Component> ViewStackProcessor::GetMainComponent()
RefPtr<Component> 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>& 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>& component)
}
}
NodeId ViewStackProcessor::GetCurrentInspectorNodeId() const
{
auto&& componet = GetMainComponent();
if (!componet) {
return -1;
}
return StringUtils::StringToInt(componet->GetInspectorId());
}
ScopedViewStackProcessor::ScopedViewStackProcessor()
{
std::swap(instance_, ViewStackProcessor::instance);
@@ -21,6 +21,7 @@
#include <unordered_map>
#include <vector>
#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<FlexItemComponent> GetFlexItemComponent();
RefPtr<BoxComponent> GetBoxComponent();
RefPtr<Component> GetMainComponent();
RefPtr<Component> GetMainComponent() const;
RefPtr<DisplayComponent> GetDisplayComponent();
bool HasDisplayComponent() const;
RefPtr<TransformComponent> GetTransformComponent();
@@ -128,6 +129,8 @@ public:
void SetIsPercentSize(RefPtr<Component>& component);
std::shared_ptr<JsPageRadioGroups> GetRadioGroupCompnent();
NodeId GetCurrentInspectorNodeId() const;
private:
ViewStackProcessor();
@@ -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)
{
+7 -2
View File
@@ -124,9 +124,14 @@ protected:
void ApplyAnimationOptions()
{
auto onFinishEvent = animationOption_.GetOnFinishEvent();
if (!onFinishEvent.IsEmpty()) {
if (onFinishEvent) {
animationController_->AddStopListener([onFinishEvent, weakContext = context_] {
AceAsyncEvent<void()>::Create(onFinishEvent, weakContext)();
auto context = weakContext.Upgrade();
if (context) {
context->PostAsyncEvent(onFinishEvent);
} else {
LOGE("the context is null");
}
});
}
if (stopCallback_) {
@@ -149,7 +149,7 @@ public:
Dimension GetWidthDimension() const
{
return static_cast<Dimension>(width_);
return width_;
}
virtual void SetHeight(const Dimension& height) // add for animation
@@ -162,7 +162,7 @@ public:
Dimension GetHeightDimension() const
{
return static_cast<Dimension>(height_);
return height_;
}
EdgePx GetMargin() const
@@ -106,9 +106,14 @@ private:
animationController_->AddInterpolator(colorAnimation);
auto onFinishEvent = animationOption_.GetOnFinishEvent();
if (!onFinishEvent.IsEmpty()) {
if (onFinishEvent) {
animationController_->AddStopListener([onFinishEvent, weakContext = context_] {
AceAsyncEvent<void()>::Create(onFinishEvent, weakContext)();
auto context = weakContext.Upgrade();
if (context) {
context->PostAsyncEvent(onFinishEvent);
} else {
LOGE("the context is null");
}
});
}
animationController_->SetDuration(animationOption_.GetDuration());
@@ -137,9 +137,14 @@ private:
animationController_->AddInterpolator(animation);
auto onFinishEvent = animationOption_.GetOnFinishEvent();
if (!onFinishEvent.IsEmpty()) {
if (onFinishEvent) {
animationController_->AddStopListener([onFinishEvent, weakContext = context_] {
AceAsyncEvent<void()>::Create(onFinishEvent, weakContext)();
auto context = weakContext.Upgrade();
if (context) {
context->PostAsyncEvent(onFinishEvent);
} else {
LOGE("the context is null");
}
});
}
if (stopCallback_) {
@@ -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<void()>::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());
@@ -16,12 +16,12 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_PROPERTIES_ANIMATION_OPTION_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_PROPERTIES_ANIMATION_OPTION_H
#include <functional>
#include <string>
#include <unordered_map>
#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<void()>& onFinishEvent)
{
onFinishEvent_ = onFinishEvent;
}
const EventMarker& GetOnFinishEvent() const
const std::function<void()>& GetOnFinishEvent() const
{
return onFinishEvent_;
}
@@ -141,7 +141,7 @@ private:
bool allowRunningAsynchronously_ = false;
RefPtr<Curve> curve_;
EventMarker onFinishEvent_;
std::function<void()> onFinishEvent_;
AnimationDirection direction_ = AnimationDirection::NORMAL;
};
@@ -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;
@@ -220,8 +220,10 @@ bool PipelineContext::GetIsDeclarative() const
return true;
}
void PipelineContext::AddGeometryChangedNode(const RefPtr<RenderNode>& renderNode)
{
}
void PipelineContext::AddGeometryChangedNode(const RefPtr<RenderNode>& renderNode) {}
void PipelineContext::PostAsyncEvent(const std::function<void()>&) {}
void PipelineContext::PostAsyncEvent(std::function<void()>&&) {}
} // namespace OHOS::Ace
+8 -11
View File
@@ -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;
};
+1 -1
View File
@@ -153,7 +153,7 @@ private:
TimeStamp time_;
};
class TouchLocationInfo : public TypeInfoBase {
class TouchLocationInfo : public virtual TypeInfoBase {
DECLARE_RELATIONSHIP_OF_CLASSES(TouchLocationInfo, TypeInfoBase);
public:
@@ -13,6 +13,7 @@
* limitations under the License.
*/
#include <functional>
#include "gtest/gtest.h"
#define protected public
@@ -182,6 +183,10 @@ void PipelineContext::AddGeometryChangedNode(const RefPtr<RenderNode>& renderNod
void PipelineContext::ForceLayoutForImplicitAnimation() {}
void PipelineContext::PostAsyncEvent(const std::function<void()>&) {}
void PipelineContext::PostAsyncEvent(std::function<void()>&&) {}
class FocusTest : public testing::Test {
public:
static void SetUpTestCase();
+11 -22
View File
@@ -19,16 +19,17 @@
#include <functional>
#include <list>
#include <string>
#include <vector>
#include <unordered_map>
#include <vector>
#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<FingerInfo> fingerList_;
};
using GestureEventFunc = std::function<void(const GestureEvent& info)>;
using GestureEventFunc = std::function<void(GestureEvent& info)>;
using GestureEventNoParameter = std::function<void()>;
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<GestureEventFunc>(onActionId);
}
void SetOnActionStartId(const GestureEventFunc&& onActionStartId)
void SetOnActionStartId(const GestureEventFunc& onActionStartId)
{
onActionStartId_ = std::make_unique<GestureEventFunc>(onActionStartId);
}
void SetOnActionUpdateId(const GestureEventFunc&& onActionUpdateId)
void SetOnActionUpdateId(const GestureEventFunc& onActionUpdateId)
{
onActionUpdateId_ = std::make_unique<GestureEventFunc>(onActionUpdateId);
}
void SetOnActionEndId(const GestureEventFunc&& onActionEndId)
void SetOnActionEndId(const GestureEventFunc& onActionEndId)
{
onActionEndId_ = std::make_unique<GestureEventFunc>(onActionEndId);
}
+9
View File
@@ -140,6 +140,15 @@ public:
return Rect();
}
Rect GetRenderRectInLocal() const
{
auto renderNode = GetRenderNode();
if (renderNode) {
return renderNode->GetPaintRect();
}
return Rect();
}
const std::list<RefPtr<Element>>& GetChildren() const;
const WeakPtr<PipelineContext>& GetContext() const
@@ -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
@@ -240,6 +240,10 @@ public:
eventTrigger_.TriggerSyncEvent(marker, std::forward<Args>(args)...);
}
void PostAsyncEvent(TaskExecutor::Task&& task);
void PostAsyncEvent(const TaskExecutor::Task& task);
void OnSurfaceChanged(int32_t width, int32_t height);
void OnSurfaceDensityChanged(double density);