From a8371e06bc4c94aa3b2fb8a2fcd6aa9c9768090e Mon Sep 17 00:00:00 2001 From: etkmao Date: Tue, 22 Aug 2023 15:47:41 +0800 Subject: [PATCH] fix(renderer): update tdfcore d47969ec25d4f403595f06219ea43b202de9af74 --- .../connector/renderer/tdf/gradle.properties | 2 +- .../com/openhippy/connector/TDFRenderer.java | 7 + modules/footstone/include/footstone/macros.h | 2 + renderer/tdf/android/build.gradle | 2 +- .../main/cpp/src/render/tdf_render_bridge.cc | 3 +- .../com/tencent/renderer/TDFRenderEngine.java | 4 +- .../com/tencent/renderer/TDFRenderer.java | 3 + renderer/tdf/common/CMakeLists.txt | 1 - .../renderer/tdf/gesture/touch_recognizer.h | 102 ---------- .../include/renderer/tdf/tdf_render_manager.h | 3 +- .../include/renderer/tdf/view/modal_view.h | 3 +- .../include/renderer/tdf/view/view_pager.h | 3 +- .../tdf/viewnode/embedded_view_node.h | 2 +- .../renderer/tdf/viewnode/image_view_node.h | 2 +- .../renderer/tdf/viewnode/list_view_node.h | 6 +- .../renderer/tdf/viewnode/modal_view_node.h | 2 +- .../tdf/viewnode/refresh_wrapper_node.h | 10 +- .../renderer/tdf/viewnode/root_view_node.h | 10 +- .../renderer/tdf/viewnode/scroll_view_node.h | 2 +- .../renderer/tdf/viewnode/text_input_node.h | 2 +- .../renderer/tdf/viewnode/text_view_node.h | 2 +- .../include/renderer/tdf/viewnode/view_node.h | 12 +- .../renderer/tdf/viewnode/view_pager_node.h | 2 +- .../renderer/tdf/devtools/devtools_util.cc | 11 +- .../renderer/tdf/gesture/touch_recognizer.cc | 174 ------------------ .../src/renderer/tdf/tdf_render_manager.cc | 4 +- .../src/renderer/tdf/view/modal_view.cc | 10 +- .../src/renderer/tdf/view/view_pager.cc | 2 +- .../tdf/viewnode/embedded_view_node.cc | 4 +- .../renderer/tdf/viewnode/image_view_node.cc | 4 +- .../renderer/tdf/viewnode/list_view_node.cc | 12 +- .../renderer/tdf/viewnode/modal_view_node.cc | 7 +- .../tdf/viewnode/refresh_wrapper_node.cc | 13 +- .../renderer/tdf/viewnode/root_view_node.cc | 20 +- .../renderer/tdf/viewnode/scroll_view_node.cc | 4 +- .../renderer/tdf/viewnode/text_input_node.cc | 36 ++-- .../renderer/tdf/viewnode/text_view_node.cc | 10 +- .../src/renderer/tdf/viewnode/view_node.cc | 147 ++++++++------- .../renderer/tdf/viewnode/view_pager_node.cc | 4 +- 39 files changed, 215 insertions(+), 434 deletions(-) delete mode 100644 renderer/tdf/common/include/renderer/tdf/gesture/touch_recognizer.h delete mode 100644 renderer/tdf/common/src/renderer/tdf/gesture/touch_recognizer.cc diff --git a/framework/android/connector/renderer/tdf/gradle.properties b/framework/android/connector/renderer/tdf/gradle.properties index 016f7e543fe..b763810a90d 100644 --- a/framework/android/connector/renderer/tdf/gradle.properties +++ b/framework/android/connector/renderer/tdf/gradle.properties @@ -20,4 +20,4 @@ # TDFCore's artifact version. # # Build from TDFCore's Git commit id: 8a14a23841. -CPP_TDF_CORE_VERSION=0.0.9 +CPP_TDF_CORE_VERSION=0.0.14 diff --git a/framework/android/connector/renderer/tdf/src/main/java/com/openhippy/connector/TDFRenderer.java b/framework/android/connector/renderer/tdf/src/main/java/com/openhippy/connector/TDFRenderer.java index 4b6a55cef25..d9a8cab37e8 100644 --- a/framework/android/connector/renderer/tdf/src/main/java/com/openhippy/connector/TDFRenderer.java +++ b/framework/android/connector/renderer/tdf/src/main/java/com/openhippy/connector/TDFRenderer.java @@ -78,6 +78,13 @@ public View replaySnapshot(@NonNull Context context, return null; } + @Override + public void removeSnapshotView() { + if (mRenderer != null) { + mRenderer.removeSnapshotView(); + } + } + @Override public void setFrameworkProxy(@NonNull Object proxy) { if (mRenderer != null && proxy instanceof FrameworkProxy) { diff --git a/modules/footstone/include/footstone/macros.h b/modules/footstone/include/footstone/macros.h index 38453f1d668..e051bc2dfac 100644 --- a/modules/footstone/include/footstone/macros.h +++ b/modules/footstone/include/footstone/macros.h @@ -29,7 +29,9 @@ constexpr inline size_t SIZE_OF = sizeof(T); template char (&ARRAY_SIZE_HELPER(CharType (&array)[N]))[N]; +#ifndef WEAK_THIS #define WEAK_THIS weak_this = weak_from_this() +#endif #define SHARED_THIS self = this->shared_from_this() // 表明该lambda不会被存储,可以安全使用this #define THIS_NO_STORE this diff --git a/renderer/tdf/android/build.gradle b/renderer/tdf/android/build.gradle index b2ee338829f..a28ece4cb56 100644 --- a/renderer/tdf/android/build.gradle +++ b/renderer/tdf/android/build.gradle @@ -43,6 +43,6 @@ dependencies { compileOnly project(path: ':pool') // tdf render need ControllerManager from native manager compileOnly project(path: ':renderer-native') - compileOnly "com.tencent.tdfcore:embedder:0.0.8" + compileOnly "com.tencent.tdfcore:embedder:0.0.16" compileOnly deps.annotation } diff --git a/renderer/tdf/android/src/main/cpp/src/render/tdf_render_bridge.cc b/renderer/tdf/android/src/main/cpp/src/render/tdf_render_bridge.cc index 72e9ee5653c..eb0d46926fa 100644 --- a/renderer/tdf/android/src/main/cpp/src/render/tdf_render_bridge.cc +++ b/renderer/tdf/android/src/main/cpp/src/render/tdf_render_bridge.cc @@ -88,7 +88,8 @@ void RegisterTDFEngine(JNIEnv *j_env, jobject j_obj, jint j_render_id, auto render_manager_object = std::static_pointer_cast( std::any_cast>(render_manager)); auto engine = reinterpret_cast(j_engine_id); - render_manager_object->RegisterShell(static_cast(j_root_view_id), engine->GetShell()); + render_manager_object->RegisterShell(static_cast(j_root_view_id), engine->GetShell(), + engine->GetPipeline()->GetRenderContext()); } void SetUriLoader(JNIEnv *j_env, jobject j_obj, diff --git a/renderer/tdf/android/src/main/java/com/tencent/renderer/TDFRenderEngine.java b/renderer/tdf/android/src/main/java/com/tencent/renderer/TDFRenderEngine.java index f106ffdf6c2..92747ddead5 100644 --- a/renderer/tdf/android/src/main/java/com/tencent/renderer/TDFRenderEngine.java +++ b/renderer/tdf/android/src/main/java/com/tencent/renderer/TDFRenderEngine.java @@ -32,8 +32,8 @@ public TDFRenderEngine(@NonNull Context context, TDFEngineConfig configuration) } @Override - public void onShellCreated(long shell) { - super.onShellCreated(shell); + public void onShellCreated(long shell, long pipelineId) { + super.onShellCreated(shell, pipelineId); LogUtils.d(TAG, "onShellCreated: " + shell); } diff --git a/renderer/tdf/android/src/main/java/com/tencent/renderer/TDFRenderer.java b/renderer/tdf/android/src/main/java/com/tencent/renderer/TDFRenderer.java index 6b974b5ae0e..c144a677385 100644 --- a/renderer/tdf/android/src/main/java/com/tencent/renderer/TDFRenderer.java +++ b/renderer/tdf/android/src/main/java/com/tencent/renderer/TDFRenderer.java @@ -153,6 +153,9 @@ public View replaySnapshot(@NonNull Context context, return null; } + @Override + public void removeSnapshotView() {} + @Override public void handleRenderException(@NonNull Exception exception) { LogUtils.d(TAG, "handleRenderException: " + exception.getMessage()); diff --git a/renderer/tdf/common/CMakeLists.txt b/renderer/tdf/common/CMakeLists.txt index d306ad9f855..35e826d8b79 100644 --- a/renderer/tdf/common/CMakeLists.txt +++ b/renderer/tdf/common/CMakeLists.txt @@ -82,7 +82,6 @@ set(SRC_SET src/renderer/tdf/viewnode/view_node.cc src/renderer/tdf/view/modal_view.cc src/renderer/tdf/view/view_pager.cc - src/renderer/tdf/gesture/touch_recognizer.cc src/renderer/tdf/devtools/devtools_util.cc ) target_sources(${PROJECT_NAME} PRIVATE ${SRC_SET}) diff --git a/renderer/tdf/common/include/renderer/tdf/gesture/touch_recognizer.h b/renderer/tdf/common/include/renderer/tdf/gesture/touch_recognizer.h deleted file mode 100644 index be838ab64ee..00000000000 --- a/renderer/tdf/common/include/renderer/tdf/gesture/touch_recognizer.h +++ /dev/null @@ -1,102 +0,0 @@ -/** - * Tencent is pleased to support the open source community by making - * Hippy available. - * - * Copyright (C) 2022 THL A29 Limited, a Tencent company. - * All rights reserved. - * - * 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. - */ - -#pragma once - -#include "footstone/hippy_value.h" -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wsign-conversion" -#pragma clang diagnostic ignored "-Wsign-compare" -#pragma clang diagnostic ignored "-Wextra-semi" -#pragma clang diagnostic ignored "-Wc++98-compat-extra-semi" -#pragma clang diagnostic ignored "-Wignored-qualifiers" -#pragma clang diagnostic ignored "-Wimplicit-float-conversion" -#pragma clang diagnostic ignored "-Wimplicit-int-conversion" -#pragma clang diagnostic ignored "-Wfloat-conversion" -#pragma clang diagnostic ignored "-Wshadow" -#include "core/support/gesture/recognizer/one_sequence_gesture_recognizer.h" -#pragma clang diagnostic pop - -namespace hippy { -inline namespace render { -inline namespace tdf { -inline namespace gesture { - -struct TouchDetails { - tdfcore::TPoint position = tdfcore::TPoint::Make(0, 0); - - explicit TouchDetails(const tdfcore::TPoint &position) : position(position) {} -}; - -using tdfcore::OneSequenceGestureRecognizer; - -using TouchClosure = std::function; - -class TouchRecognizer : public OneSequenceGestureRecognizer { - TDF_REFF_CLASS_META(TouchRecognizer) - public: - void SetTouchStart(const TouchClosure &on_touch_start) { on_touch_start_ = on_touch_start; } - void SetTouchMove(const TouchClosure &on_touch_move) { on_touch_move_ = on_touch_move; } - void SetTouchEnd(const TouchClosure &on_touch_end) { on_touch_end_ = on_touch_end; } - void SetTouchCancel(const TouchClosure &on_touch_cancel) { on_touch_cancel_ = on_touch_cancel; } - - static std::shared_ptr TouchDetails2HippyValue( - uint32_t id, const char *name, const TouchDetails &details); - - protected: - void HandlePointerDown(const tdfcore::PointerData &data) override; - void HandlePointerMove(const tdfcore::PointerData &data) override; - void HandlePointerUp(const tdfcore::PointerData &data) override; - void HandlePointerCancel(const tdfcore::PointerData &data) override; - - bool CanAddPointer(const tdfcore::PointerData &data) const override; - void AcceptGesture(tdfcore::PointerID pointer) override; - void RejectGesture(tdfcore::PointerID pointer) override; - - void DidStopTrackingLastPointer(tdfcore::PointerID pointer) override; - - private: - bool IsLegalPointer(tdfcore::PointerID pointer) const; - void CheckStart(const tdfcore::TPoint &position); - void CheckMove(const tdfcore::TPoint &position); - void CheckEnd(const tdfcore::TPoint &position); - void CheckCancel(const tdfcore::TPoint &position); - - bool sent_down_ = false; - bool is_down_ = false; - tdfcore::PointerID monitor_pointer_; - tdfcore::TPoint initial_position_; - tdfcore::TPoint move_position_; - tdfcore::TPoint up_position_; - - TouchClosure on_touch_start_; - TouchClosure on_touch_move_; - TouchClosure on_touch_end_; - TouchClosure on_touch_cancel_; - - FRIEND_OF_TDF_ALLOC -}; - -} // namespace gesture -} // namespace tdf -} // namespace render -} // namespace hippy -TDF_REFL_DEFINE(hippy::render::tdf::gesture::TouchRecognizer, bases) -TDF_REFL_END(hippy::render::tdf::gesture::TouchRecognizer) diff --git a/renderer/tdf/common/include/renderer/tdf/tdf_render_manager.h b/renderer/tdf/common/include/renderer/tdf/tdf_render_manager.h index 6d1d51e86fd..3406e95de5c 100644 --- a/renderer/tdf/common/include/renderer/tdf/tdf_render_manager.h +++ b/renderer/tdf/common/include/renderer/tdf/tdf_render_manager.h @@ -87,7 +87,8 @@ class TDFRenderManager const DomArgument ¶m, uint32_t cb_id) override; - void RegisterShell(uint32_t root_id, const std::shared_ptr &shell); + void RegisterShell(uint32_t root_id, const std::shared_ptr &shell, + const std::shared_ptr &render_context); void SetDomManager(std::weak_ptr dom_manager) { dom_manager_ = dom_manager; } diff --git a/renderer/tdf/common/include/renderer/tdf/view/modal_view.h b/renderer/tdf/common/include/renderer/tdf/view/modal_view.h index 7aad455ca51..f838c6c8a3c 100644 --- a/renderer/tdf/common/include/renderer/tdf/view/modal_view.h +++ b/renderer/tdf/common/include/renderer/tdf/view/modal_view.h @@ -45,6 +45,7 @@ inline namespace view { using tdfcore::TRect; using tdfcore::View; +using tdfcore::ViewContext; using OnShowCallBack = std::function; using OnDismissCallBack = std::function; @@ -57,7 +58,7 @@ class ModalView : public View { public: ~ModalView() override; - ModalView(); + ModalView(const std::shared_ptr &context); void AddView(const std::shared_ptr &child) override; diff --git a/renderer/tdf/common/include/renderer/tdf/view/view_pager.h b/renderer/tdf/common/include/renderer/tdf/view/view_pager.h index 2c06810c1e3..1d26daf4c62 100644 --- a/renderer/tdf/common/include/renderer/tdf/view/view_pager.h +++ b/renderer/tdf/common/include/renderer/tdf/view/view_pager.h @@ -47,6 +47,7 @@ inline namespace tdf { inline namespace view { using tdfcore::ScrollView; +using tdfcore::ViewContext; using ScrollOffsetListener = std::function; using PageSelectedListener = std::function; @@ -68,7 +69,7 @@ class ViewPager : public ScrollView { TDF_REFF_CLASS_META(ViewPager) public: - ViewPager(); + ViewPager(const std::shared_ptr &context); void Init() override; diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/embedded_view_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/embedded_view_node.h index 02d6647cb5a..c44c0b8c4e7 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/embedded_view_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/embedded_view_node.h @@ -41,7 +41,7 @@ class EmbeddedViewNode : public ViewNode { std::string DomStyleMap2String(const DomStyleMap &dom_style); private: - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; std::map property_; std::string native_view_type_; diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/image_view_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/image_view_node.h index cfc8a491749..e26938e3b70 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/image_view_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/image_view_node.h @@ -45,7 +45,7 @@ class ImageViewNode : public ViewNode { std::string default_src_; std::string image_src_; std::string scale_type_; - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; }; } // namespace tdf diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/list_view_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/list_view_node.h index 1a91c864f64..2da19a63f3a 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/list_view_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/list_view_node.h @@ -77,7 +77,7 @@ class ListViewItemNode : public ViewNode { /** * @brief ListViewItemNode's CreateView is Public, can be called by ListViewDataSource. */ - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; void UpdateViewType(const DomStyleMap& dom_style); @@ -94,7 +94,7 @@ class ListViewItemNode : public ViewNode { class ListViewNode; -class ListViewDataSource : public tdfcore::CustomLayoutViewDataSource, public tdfcore::Object { +class ListViewDataSource : public tdfcore::CustomLayoutViewDataSource { public: ListViewDataSource(std::shared_ptr host) : list_view_node_(host) {} @@ -136,7 +136,7 @@ class ListViewNode : public ScrollViewNode { void HandleStyleUpdate(const DomStyleMap& dom_style, const DomDeleteProps& dom_delete_props) override; - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; void SetShouldReload() { should_reload_ = true; } diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/modal_view_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/modal_view_node.h index 586dddc1842..0a652f9434b 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/modal_view_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/modal_view_node.h @@ -49,7 +49,7 @@ class ModalViewNode : public ViewNode { void OnCreate() override; void HandleLayoutUpdate(hippy::LayoutResult layout_result) override; void HandleStyleUpdate(const DomStyleMap& dom_style, const DomDeleteProps& dom_delete_props) override; - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; std::string GetViewName() const override { return kModaViewName; } private: diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/refresh_wrapper_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/refresh_wrapper_node.h index 892dd8f62aa..d363a3aa3e3 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/refresh_wrapper_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/refresh_wrapper_node.h @@ -40,6 +40,8 @@ namespace hippy { inline namespace render { inline namespace tdf { +using tdfcore::ViewContext; + inline namespace refreshwrapper { constexpr const char kRefreshWrapper[] = "RefreshWrapper"; constexpr const char kBounceTime[] = "bounceTime"; // int @@ -51,8 +53,8 @@ constexpr const char kRefreshComplected[] = "refreshComplected"; class HippyRefreshHeader : public tdfcore::RefreshHeader { public: - explicit HippyRefreshHeader(std::shared_ptr content_view) - : tdfcore::RefreshHeader(), content_view_(std::move(content_view)) {} + explicit HippyRefreshHeader(const std::shared_ptr &context, std::shared_ptr content_view) + : tdfcore::RefreshHeader(context), content_view_(std::move(content_view)) {} std::shared_ptr GetView() override { return content_view_; } @@ -69,7 +71,7 @@ class RefreshWrapperItemNode : public ViewNode { /** * @brief make CreateView public,because it's call by RefreshWrapperNode */ - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; void HandleLayoutUpdate(hippy::LayoutResult layout_result) override; }; @@ -86,7 +88,7 @@ class RefreshWrapperNode : public ViewNode { void CallFunction(const std::string& name, const DomArgument& param, const uint32_t call_back_id) override; private: - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; void HandleOffsetListener(int32_t position, double offset); std::shared_ptr item_node_; std::shared_ptr refresh_header_; diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/root_view_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/root_view_node.h index cff5ec8e0a2..9831ab0d4e4 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/root_view_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/root_view_node.h @@ -20,8 +20,8 @@ #pragma once -#include "dom/root_node.h" #include "renderer/tdf/viewnode/view_node.h" +#include "dom/root_node.h" namespace hippy { inline namespace render { @@ -34,12 +34,13 @@ class RootViewNode : public ViewNode { using UriDataGetter = std::function; RootViewNode(const RenderInfo info, const std::shared_ptr& shell, + const std::shared_ptr& render_context, const std::shared_ptr& manager, UriDataGetter getter); ~RootViewNode() override = default; void Init() override; - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; void RegisterViewNode(uint32_t id, const std::shared_ptr& view_node); void UnregisterViewNode(uint32_t id); @@ -55,6 +56,10 @@ class RootViewNode : public ViewNode { std::shared_ptr GetShell() { return shell_.lock(); } + std::shared_ptr GetRenderContext() { return render_context_.lock(); } + + std::shared_ptr GetViewContext() { return view_context_; } + protected: bool isRoot() override { return true; } @@ -66,6 +71,7 @@ class RootViewNode : public ViewNode { std::unordered_map> nodes_query_table_; tdfcore::NoArgListener end_batch_listener_; std::weak_ptr shell_; + std::weak_ptr render_context_; std::weak_ptr dom_manager_; std::shared_ptr view_context_; UriDataGetter getter_; diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/scroll_view_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/scroll_view_node.h index 68679c7b20b..0d9c29a9908 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/scroll_view_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/scroll_view_node.h @@ -69,7 +69,7 @@ class ScrollViewNode : public ViewNode { using ViewNode::ViewNode; protected: - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; void HandleStyleUpdate(const DomStyleMap& dom_style, const DomDeleteProps& dom_delete_props) override; diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/text_input_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/text_input_node.h index 6fb03389b42..a749ea5e097 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/text_input_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/text_input_node.h @@ -160,7 +160,7 @@ class TextInputNode : public ViewNode { protected: void HandleStyleUpdate(const DomStyleMap& dom_style, const DomDeleteProps& dom_delete_props) override; - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; private: void InitCallBackMap(); diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/text_view_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/text_view_node.h index 7eceed3a205..4fb36bc669a 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/text_view_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/text_view_node.h @@ -99,7 +99,7 @@ class TextViewNode : public ViewNode { void HandleLayoutUpdate(hippy::LayoutResult layout_result) override; private: - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; void SetText(const DomStyleMap& dom_style, std::shared_ptr& text_view); void SetTextColor(const DomStyleMap& dom_style, TextStyle& text_style); diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/view_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/view_node.h index d853b2d2d68..2a81c93165a 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/view_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/view_node.h @@ -41,7 +41,6 @@ #include "dom/dom_node.h" #include "footstone/hippy_value.h" #include "footstone/logging.h" -#include "renderer/tdf/gesture/touch_recognizer.h" #define TDF_RENDER_CHECK_ATTACH \ if (!IsAttached()) { \ @@ -151,6 +150,8 @@ class ViewNode; class RootViewNode; +using tdfcore::ViewContext; + /* * Binding a tdfcore::View with a hippy::DomNode. */ @@ -230,7 +231,7 @@ class ViewNode : public tdfcore::Object, public std::enable_shared_from_this &view = nullptr); + void Attach(const std::shared_ptr &context, const std::shared_ptr &view = nullptr); /** * @brief detach current ViewNode to a tdfcore::View. @@ -278,7 +279,7 @@ class ViewNode : public tdfcore::Object, public std::enable_shared_from_this CreateView(); + virtual std::shared_ptr CreateView(const std::shared_ptr &context); void SendGestureDomEvent(std::string type, const std::shared_ptr &value = nullptr) { SendUIDomEvent(type, value, true, true); @@ -380,6 +381,9 @@ class ViewNode : public tdfcore::Object, public std::enable_shared_from_this PointerDataList2HippyValue( + uint32_t id, const char *name, const tdfcore::PointerDataList &data_list); + /** * @brief DomNode's RenderInfo.index is not always the related View's index, it may need to be corrected. */ @@ -397,7 +401,7 @@ class ViewNode : public tdfcore::Object, public std::enable_shared_from_this tap_recognizer_; std::shared_ptr long_press_recognizer_; - std::shared_ptr touch_recognizer_; + std::shared_ptr touch_event_; std::weak_ptr tap_view_; std::weak_ptr long_press_view_; std::weak_ptr touch_view_; diff --git a/renderer/tdf/common/include/renderer/tdf/viewnode/view_pager_node.h b/renderer/tdf/common/include/renderer/tdf/viewnode/view_pager_node.h index 0e71fb59091..5de4b5de043 100644 --- a/renderer/tdf/common/include/renderer/tdf/viewnode/view_pager_node.h +++ b/renderer/tdf/common/include/renderer/tdf/viewnode/view_pager_node.h @@ -57,7 +57,7 @@ class ViewPagerNode : public ScrollViewNode { void OnChildAdd(const std::shared_ptr& child, int64_t index) override; void HandleStyleUpdate(const DomStyleMap& dom_style, const DomDeleteProps& dom_delete_props) override; - std::shared_ptr CreateView() override; + std::shared_ptr CreateView(const std::shared_ptr &context) override; void CallFunction(const std::string& function_name, const DomArgument& param, const uint32_t call_back_id) override; protected: diff --git a/renderer/tdf/common/src/renderer/tdf/devtools/devtools_util.cc b/renderer/tdf/common/src/renderer/tdf/devtools/devtools_util.cc index aad9ef30210..8fac044d42d 100644 --- a/renderer/tdf/common/src/renderer/tdf/devtools/devtools_util.cc +++ b/renderer/tdf/common/src/renderer/tdf/devtools/devtools_util.cc @@ -54,6 +54,7 @@ void DevtoolsUtil::CallDevtoolsFunction(const std::weak_ptr &root_ const DomArgument ¶m, const uint32_t call_back_id) { auto shell = root_node.lock()->GetShell(); + auto vew_context = root_node.lock()->GetViewContext(); if (name == kGetScreenShot) { GetScreenshot(root_node, view_node, name, param, call_back_id); } else if (name == kAddFrameCallback) { @@ -81,7 +82,7 @@ void DevtoolsUtil::CallDevtoolsFunction(const std::weak_ptr &root_ } } else if (name == kGetLocationOnScreen) { DomValueObjectType obj; - auto ratio = shell->GetViewportMetrics().device_pixel_ratio; + auto ratio = vew_context->GetViewportMetrics().device_pixel_ratio; int32_t x_onScreen = 0, y_onScreen = 0, view_width = 0, view_height = 0; if (view_node->IsAttached()) { auto frame = view_node->GetView()->GetFrame(); @@ -115,13 +116,15 @@ void DevtoolsUtil::GetScreenshot(const std::weak_ptr &root_node, auto max_width = hippy_value.find(kMaxWidth)->second.ToInt32Checked(); auto max_height = hippy_value.find(kMaxHeight)->second.ToInt32Checked(); auto shell = root_node.lock()->GetShell(); - auto scaleX = static_cast(max_width) / static_cast(shell->GetViewportMetrics().width); - auto scaleY = static_cast(max_height) / static_cast(shell->GetViewportMetrics().height); + auto vew_context = root_node.lock()->GetViewContext(); + auto scaleX = static_cast(max_width) / static_cast(vew_context->GetViewportMetrics().width); + auto scaleY = static_cast(max_height) / static_cast(vew_context->GetViewportMetrics().height); auto scale = std::min(scaleX, scaleY); screen_scale_ = scale; std::weak_ptr weak_view_node = view_node; std::weak_ptr weak_shell = shell; - shell->GetLastScreenshot([weak_shell, name, call_back_id, weak_view_node](const std::shared_ptr &screenshot) { + auto pipeline_id = root_node.lock()->GetRenderContext()->GetPipeline()->GetId(); + shell->GetLastScreenshot(static_cast(pipeline_id), [weak_shell, name, call_back_id, weak_view_node](const std::shared_ptr &screenshot) { auto shell = weak_shell.lock(); if (screenshot && shell) { tdfcore::RenderCommand command; diff --git a/renderer/tdf/common/src/renderer/tdf/gesture/touch_recognizer.cc b/renderer/tdf/common/src/renderer/tdf/gesture/touch_recognizer.cc deleted file mode 100644 index 3f30ece4a2c..00000000000 --- a/renderer/tdf/common/src/renderer/tdf/gesture/touch_recognizer.cc +++ /dev/null @@ -1,174 +0,0 @@ -/** - * Tencent is pleased to support the open source community by making - * Hippy available. - * - * Copyright (C) 2022 THL A29 Limited, a Tencent company. - * All rights reserved. - * - * 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 "renderer/tdf/gesture/touch_recognizer.h" -#include "footstone/logging.h" - -namespace hippy { -inline namespace render { -inline namespace tdf { -inline namespace gesture { - -void TouchRecognizer::HandlePointerDown(const tdfcore::PointerData &data) { - FOOTSTONE_LOG(INFO) << "TDFRenderer touch HandleEventDown"; - auto pointer = data.pointer; - StartTrackingPointer(pointer); - if (is_down_) { - return; - } - is_down_ = true; - monitor_pointer_ = pointer; - initial_position_ = data.position; - CheckStart(initial_position_); -} - -void TouchRecognizer::HandlePointerMove(const tdfcore::PointerData &data) { - FOOTSTONE_LOG(INFO) << "TDFRenderer touch HandleEventMove"; - auto pointer = data.pointer; - if (!IsLegalPointer(pointer)) { - StopTrackingPointer(pointer); - return; - } - move_position_ = data.position; - CheckMove(move_position_); -} - -void TouchRecognizer::HandlePointerUp(const tdfcore::PointerData &data) { - FOOTSTONE_LOG(INFO) << "TDFRenderer touch HandleEventUp"; - auto pointer = data.pointer; - if (!IsLegalPointer(pointer)) { - StopTrackingPointer(pointer); - return; - } - up_position_ = data.position; - // Touch not win other gestures, so do not use Accept() method - AcceptGesture(pointer); - StopTrackingPointer(pointer); -} - -void TouchRecognizer::HandlePointerCancel(const tdfcore::PointerData &data) { - FOOTSTONE_LOG(INFO) << "TDFRenderer touch HandleEventCancel"; - auto pointer = data.pointer; - if (!IsLegalPointer(pointer)) { - StopTrackingPointer(pointer); - return; - } - Reject(); - if (sent_down_) { - CheckCancel(data.position); - } - StopTrackingPointer(pointer); -} - -bool TouchRecognizer::CanAddPointer(const tdfcore::PointerData &data) const { - if (on_touch_start_ == nullptr && - on_touch_move_ == nullptr && - on_touch_end_ == nullptr && - on_touch_cancel_ == nullptr) { - return false; - } - if (data.button_type == tdfcore::PointerButtonType::kNone) { - return false; - } - return OneSequenceGestureRecognizer::CanAddPointer(data); -} - -void TouchRecognizer::AcceptGesture(tdfcore::PointerID pointer) { - FOOTSTONE_LOG(INFO) << "TDFRenderer touch AcceptGesture"; - if (pointer != monitor_pointer_) { - StopTrackingPointer(pointer); - return; - } - CheckStart(initial_position_); - CheckEnd(up_position_); - StopTrackingPointer(pointer); -} - -void TouchRecognizer::RejectGesture(tdfcore::PointerID pointer) { - FOOTSTONE_LOG(INFO) << "TDFRenderer touch RejectGesture"; - if (pointer != monitor_pointer_) { - StopTrackingPointer(pointer); - return; - } - if (sent_down_) { - CheckCancel(move_position_); - } - StopTrackingPointer(pointer); -} - -void TouchRecognizer::DidStopTrackingLastPointer(tdfcore::PointerID pointer) { - FOOTSTONE_LOG(INFO) << "TDFRenderer touch DidStopTrackingLastPointer"; - is_down_ = false; - sent_down_ = false; -} - -bool TouchRecognizer::IsLegalPointer(tdfcore::PointerID pointer) const { - if (!IsTrackingPointer(pointer) || - pointer != monitor_pointer_ || - !is_down_) { - return false; - } - return true; -} - -void TouchRecognizer::CheckStart(const tdfcore::TPoint &position) { - if (sent_down_) return; - if (on_touch_start_ != nullptr) { - auto details = TouchDetails(position); - on_touch_start_(details); - } - sent_down_ = true; -} - -void TouchRecognizer::CheckMove(const tdfcore::TPoint &position) { - if (on_touch_move_ != nullptr) { - auto details = TouchDetails(position); - on_touch_move_(details); - } -} - -void TouchRecognizer::CheckEnd(const tdfcore::TPoint &position) { - if (on_touch_end_ != nullptr) { - auto details = TouchDetails(position); - on_touch_end_(details); - } -} - -void TouchRecognizer::CheckCancel(const tdfcore::TPoint &position) { - if (on_touch_cancel_ != nullptr) { - auto details = TouchDetails(position); - on_touch_cancel_(details); - } -} - -std::shared_ptr TouchRecognizer::TouchDetails2HippyValue( - uint32_t id, const char *name, const TouchDetails &details) { - footstone::HippyValue::HippyValueObjectType obj; - obj["id"] = footstone::HippyValue(id); - obj["name"] = footstone::HippyValue(name); - obj["page_x"] = footstone::HippyValue(details.position.x); - obj["page_y"] = footstone::HippyValue(details.position.y); - return std::make_shared(obj); -} - -} // namespace gesture -} // namespace tdf -} // namespace render -} // namespace hippy diff --git a/renderer/tdf/common/src/renderer/tdf/tdf_render_manager.cc b/renderer/tdf/common/src/renderer/tdf/tdf_render_manager.cc index a5ffb0218d7..166b233c80a 100644 --- a/renderer/tdf/common/src/renderer/tdf/tdf_render_manager.cc +++ b/renderer/tdf/common/src/renderer/tdf/tdf_render_manager.cc @@ -129,7 +129,8 @@ TDFRenderManager::TDFRenderManager() : RenderManager("TDFRenderManager") { id_ = global_tdf_render_manager_key.fetch_add(1); } -void TDFRenderManager::RegisterShell(uint32_t root_id, const std::shared_ptr& shell) { +void TDFRenderManager::RegisterShell(uint32_t root_id, const std::shared_ptr &shell, + const std::shared_ptr &render_context) { auto uri_data_getter = [WEAK_THIS](const string_view &uri, const RootViewNode::DataCb& callback) { DEFINE_AND_CHECK_SELF(TDFRenderManager); auto uri_loader = self->GetUriLoader(); @@ -155,6 +156,7 @@ void TDFRenderManager::RegisterShell(uint32_t root_id, const std::shared_ptrGetRootView(); +ModalView::ModalView(const std::shared_ptr &context) : tdfcore::View(context) { + modal_view_ = TDF_MAKE_SHARED(View, GetViewContext()); + root_view_ = GetViewContext()->GetWindowManager()->GetMainWindow()->GetContentView(); } void ModalView::Mount() { @@ -72,7 +72,7 @@ void ModalView::InternalSetFrame(const TRect& frame) { if (is_immersion_status_bar) { modal_view_->SetFrame(frame); } else { - auto viewport = tdfcore::ViewContext::GetCurrent()->GetShell()->GetViewportMetrics(); + auto viewport = GetViewContext()->GetViewportMetrics(); auto padding_top = viewport.view_padding_top / viewport.device_pixel_ratio; modal_view_->SetFrame(TRect::MakeXYWH(frame.left, static_cast(padding_top + frame.top), frame.Width(), static_cast(frame.Height() - padding_top))); diff --git a/renderer/tdf/common/src/renderer/tdf/view/view_pager.cc b/renderer/tdf/common/src/renderer/tdf/view/view_pager.cc index 677cfca4545..7d5e806eb9e 100644 --- a/renderer/tdf/common/src/renderer/tdf/view/view_pager.cc +++ b/renderer/tdf/common/src/renderer/tdf/view/view_pager.cc @@ -33,7 +33,7 @@ using tdfcore::TPoint; using tdfcore::TRect; using tdfcore::TScalar; -ViewPager::ViewPager() : tdfcore::ScrollView() {} +ViewPager::ViewPager(const std::shared_ptr &context) : tdfcore::ScrollView(context) {} void ViewPager::Init() { ScrollView::Init(); diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/embedded_view_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/embedded_view_node.cc index 02b4dd94ac8..09409a21c75 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/embedded_view_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/embedded_view_node.cc @@ -44,8 +44,8 @@ EmbeddedViewNode::EmbeddedViewNode(const std::shared_ptr &d const std::string &native_view_type) : ViewNode(dom_node, render_info), native_view_type_(native_view_type) {} -std::shared_ptr EmbeddedViewNode::CreateView() { - auto view = TDF_MAKE_SHARED(tdfcore::EmbeddedView, native_view_type_); +std::shared_ptr EmbeddedViewNode::CreateView(const std::shared_ptr &context) { + auto view = TDF_MAKE_SHARED(tdfcore::EmbeddedView, context, native_view_type_); // 默认不要支持tdfcore手势,因为业务可以写一个全屏的自定义View在最上面但什么也不显示,从而把下面手势都竞技掉。 view->SetSupportedGestures({}); return view; diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/image_view_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/image_view_node.cc index caf56d5d9fe..2762a8de255 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/image_view_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/image_view_node.cc @@ -70,8 +70,8 @@ constexpr const char kProgress[] = "progress"; constexpr const char kAssetPrex[] = "hpfile://./"; -std::shared_ptr ImageViewNode::CreateView() { - auto image_view = TDF_MAKE_SHARED(tdfcore::ImageView); +std::shared_ptr ImageViewNode::CreateView(const std::shared_ptr &context) { + auto image_view = TDF_MAKE_SHARED(tdfcore::ImageView, context); image_view->SetClipToBounds(true); image_view->SetScaleType(tdfcore::ScaleType::kAspectFill); return image_view; diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/list_view_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/list_view_node.cc index 0e8f146153e..fb26162fd55 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/list_view_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/list_view_node.cc @@ -35,10 +35,10 @@ constexpr const char kSticky[] = "sticky"; constexpr const char kViewTypeNew[] = "itemViewType"; } // namespace listviewitem -std::shared_ptr ListViewNode::CreateView() { +std::shared_ptr ListViewNode::CreateView(const std::shared_ptr &context) { auto data_source = TDF_MAKE_SHARED(ListViewDataSource, std::static_pointer_cast(shared_from_this())); auto layout = TDF_MAKE_SHARED(tdfcore::LinearCustomLayout); - auto view = TDF_MAKE_SHARED(tdfcore::CustomLayoutView, data_source, layout); + auto view = TDF_MAKE_SHARED(tdfcore::CustomLayoutView, context, data_source, layout); view->SetClipToBounds(true); view->SetScrollDirection(tdfcore::ScrollDirection::kVertical); return view; @@ -54,7 +54,7 @@ void ListViewNode::OnAttach() { FOOTSTONE_DCHECK(new_index >= 0 && new_index < self->GetChildren().size()); auto node = self->GetChildren()[new_index]; FOOTSTONE_DCHECK(!node->IsAttached()); - node->Attach(item); + node->Attach(self->GetView()->GetViewContext(), item); } else { FOOTSTONE_DCHECK(new_index >= 0); bool found = false; @@ -179,8 +179,8 @@ void ListViewNode::OnChildAdd(const std::shared_ptr& child, int64_t in void ListViewNode::OnChildRemove(const std::shared_ptr& child) { should_reload_ = true; } -std::shared_ptr ListViewItemNode::CreateView() { - auto view = TDF_MAKE_SHARED(tdfcore::View); +std::shared_ptr ListViewItemNode::CreateView(const std::shared_ptr &context) { + auto view = TDF_MAKE_SHARED(tdfcore::View, context); view->SetClipToBounds(true); return view; } @@ -227,7 +227,7 @@ std::shared_ptr ListViewDataSource::GetItem( FOOTSTONE_DCHECK(index >= 0 && static_cast(index) < item_nodes_.size()); auto node = std::static_pointer_cast(item_nodes_[static_cast(index)]); - return node->CreateView(); + return node->CreateView(custom_layout_view->GetViewContext()); } int64_t ListViewDataSource::GetItemCount() { diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/modal_view_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/modal_view_node.cc index f743dd022ec..c20a56ea1b5 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/modal_view_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/modal_view_node.cc @@ -20,6 +20,7 @@ #include "renderer/tdf/viewnode/modal_view_node.h" #include "renderer/tdf/viewnode/root_view_node.h" +#include "tdfui/view/window_manager.h" namespace hippy { inline namespace render { @@ -50,12 +51,12 @@ void ModalViewNode::OnCreate() { void ModalViewNode::HandleLayoutUpdate(hippy::LayoutResult layout_result) { ViewNode::HandleLayoutUpdate(layout_result); - auto root_view_frame = tdfcore::ViewContext::GetCurrent()->GetRootView()->GetFrame(); + auto root_view_frame = GetView()->GetViewContext()->GetWindowManager()->GetMainWindow()->GetContentView()->GetFrame(); GetView()->SetFrame(TRect::MakeXYWH(0, 0, root_view_frame.Width(), root_view_frame.Height())); } -std::shared_ptr ModalViewNode::CreateView() { - auto modal_view = TDF_MAKE_SHARED(ModalView); +std::shared_ptr ModalViewNode::CreateView(const std::shared_ptr &context) { + auto modal_view = TDF_MAKE_SHARED(ModalView, context); modal_view->SetShowCallback([WEAK_THIS] { DEFINE_AND_CHECK_SELF(ModalViewNode) self->OnShow(); diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/refresh_wrapper_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/refresh_wrapper_node.cc index 07b924f2635..d6fbebc45eb 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/refresh_wrapper_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/refresh_wrapper_node.cc @@ -30,8 +30,8 @@ constexpr const char kRefreshEvent[] = "refresh"; void HippyRefreshHeader::Init() { tdfcore::RefreshHeader::Init(); } -std::shared_ptr RefreshWrapperItemNode::CreateView() { - auto view = ViewNode::CreateView(); +std::shared_ptr RefreshWrapperItemNode::CreateView(const std::shared_ptr &context) { + auto view = ViewNode::CreateView(context); view->SetClipToBounds(true); return view; } @@ -46,8 +46,8 @@ void RefreshWrapperItemNode::HandleLayoutUpdate(hippy::LayoutResult layout_resul ViewNode::HandleLayoutUpdate(layout_result); } -std::shared_ptr RefreshWrapperNode::CreateView() { - auto view = ViewNode::CreateView(); +std::shared_ptr RefreshWrapperNode::CreateView(const std::shared_ptr &context) { + auto view = ViewNode::CreateView(context); view->SetClipToBounds(true); return view; } @@ -58,8 +58,9 @@ void RefreshWrapperNode::OnChildAdd(const std::shared_ptr& child, int6 if (child_dom_node->GetViewName() == kRefreshWrapperItemViewName) { item_node_ = std::static_pointer_cast(child->GetSharedPtr()); item_node_id_ = child->GetRenderInfo().id; - refresh_header_ = TDF_MAKE_SHARED(HippyRefreshHeader, item_node_->CreateView()); - child->Attach(refresh_header_->GetView()); + auto view_context = GetView()->GetViewContext(); + refresh_header_ = TDF_MAKE_SHARED(HippyRefreshHeader, view_context, item_node_->CreateView(view_context)); + child->Attach(view_context, refresh_header_->GetView()); return; } diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/root_view_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/root_view_node.cc index a377723798e..9bdd40ed7d1 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/root_view_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/root_view_node.cc @@ -21,25 +21,28 @@ #include "renderer/tdf/viewnode/root_view_node.h" #include "renderer/tdf/viewnode/base64_image_loader.h" #include "renderer/tdf/viewnode/net_image_loader.h" +#include "tdfui/view/window_manager.h" namespace hippy { inline namespace render { inline namespace tdf { +using tdfcore::ViewContext; + constexpr const char kUpdateFrame[] = "frameupdate"; RootViewNode::RootViewNode(const RenderInfo info, const std::shared_ptr& shell, + const std::shared_ptr& render_context, const std::shared_ptr& manager, UriDataGetter getter) - : ViewNode(nullptr, info), shell_(shell), dom_manager_(manager), getter_(getter) {} + : ViewNode(nullptr, info), shell_(shell), render_context_(render_context), dom_manager_(manager), getter_(getter) {} void RootViewNode::Init() { RegisterViewNode(render_info_.id, shared_from_this()); shell_.lock()->GetUITaskRunner()->PostTask([WEAK_THIS] { DEFINE_AND_CHECK_SELF(RootViewNode) - self->view_context_ = TDF_MAKE_SHARED(tdfcore::ViewContext, self->shell_.lock()); - self->view_context_->SetCurrent(); - self->view_context_->SetupDefaultBuildFunction(); - self->AttachView(self->view_context_->GetRootView()); + auto on_create_content_view = [](const std::shared_ptr &vc) { return TDF_MAKE_SHARED(tdfcore::View, vc); }; + self->view_context_ = tdfcore::ViewContext::Make(self->shell_.lock(), self->render_context_.lock(), on_create_content_view); + self->AttachView(self->view_context_->GetWindowManager()->GetMainWindow()->GetContentView()); if (auto shell = self->shell_.lock()) { shell->GetEventCenter()->AddListener(tdfcore::PostRunLoopEvent::ClassType(), [weak_this](const std::shared_ptr& event, uint64_t id) { @@ -51,7 +54,7 @@ void RootViewNode::Init() { return tdfcore::EventDispatchBehavior::kContinue; }); } - self->UpdateDomeRootNodeSize(self->shell_.lock()->GetViewportMetrics()); + self->UpdateDomeRootNodeSize(self->view_context_->GetViewportMetrics()); self->GetShell()->GetEventCenter()->AddListener( tdfcore::ViewportEvent::ClassType(), [weak_this](const std::shared_ptr& event, uint64_t id) { auto self = std::static_pointer_cast(weak_this.lock()); @@ -88,7 +91,7 @@ void RootViewNode::AttachView(std::shared_ptr view) { attached_view_ = view; } -std::shared_ptr RootViewNode::CreateView() { +std::shared_ptr RootViewNode::CreateView(const std::shared_ptr &context) { // Should never be called. FOOTSTONE_UNREACHABLE(); } @@ -99,6 +102,9 @@ void RootViewNode::RegisterViewNode(uint32_t id, const std::shared_ptr } void RootViewNode::UnregisterViewNode(uint32_t id) { + if (id == hippy::dom::kInvalidId) { + return; + } FOOTSTONE_DCHECK(nodes_query_table_.find(id) != nodes_query_table_.end()); nodes_query_table_.erase(id); } diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/scroll_view_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/scroll_view_node.cc index 97a12510a46..232b354815a 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/scroll_view_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/scroll_view_node.cc @@ -26,8 +26,8 @@ namespace hippy { inline namespace render { inline namespace tdf { -std::shared_ptr ScrollViewNode::CreateView() { - auto scroll_view = TDF_MAKE_SHARED(tdfcore::ScrollView); +std::shared_ptr ScrollViewNode::CreateView(const std::shared_ptr &context) { + auto scroll_view = TDF_MAKE_SHARED(tdfcore::ScrollView, context); scroll_view->SetClipToBounds(true); scroll_view->SetVerticalOverscrollEnabled(true); // defaultValue return scroll_view; diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/text_input_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/text_input_node.cc index 60939ca8dfe..63eb515e38d 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/text_input_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/text_input_node.cc @@ -109,12 +109,12 @@ void TextInputNode::HandleStyleUpdate(const DomStyleMap& dom_style, const DomDel text_input_view->SetKeyboardAction(keyboard_action_); } -std::shared_ptr TextInputNode::CreateView() { - edit_controller_ = TDF_MAKE_SHARED(TextEditingController); +std::shared_ptr TextInputNode::CreateView(const std::shared_ptr &context) { + edit_controller_ = TDF_MAKE_SHARED(TextEditingController, context); selection_control_ = TDF_MAKE_SHARED(CupertinoTextSelectionControl); - auto text_input_view = TDF_MAKE_SHARED(TextInputView, edit_controller_, selection_control_); + auto text_input_view = TDF_MAKE_SHARED(TextInputView, context, edit_controller_, selection_control_); text_input_view->SetVerticalAlign(tdfcore::VerticalAlign::kCenter); - edit_controller_->AddListener([&, text_input_view](const auto& v) { DidChangeTextEditingValue(text_input_view); }); + edit_controller_->AddValueChangeListener([&, text_input_view](const auto& v) { DidChangeTextEditingValue(text_input_view); }); text_input_view_ = text_input_view; text_input_view->GetViewContext()->GetShell()->GetEventCenter()->AddListener( tdfcore::KeyboardActionEvent::ClassType(), @@ -166,7 +166,7 @@ void TextInputNode::SendKeyActionEvent(const std::shared_ptr& ev SendUIDomEvent(kOnEditorAction, std::make_shared(param)); DomValueObjectType param2; - auto u16text = GetView()->GetTextEditingValue().GetText(); + auto u16text = GetView()->GetTextEditingValue().text; auto u8text = std::wstring_convert, char16_t >{}.to_bytes(u16text); param2[kText] = u8text; SendUIDomEvent(kOnEndEditing, std::make_shared(param2)); @@ -230,7 +230,7 @@ void TextInputNode::InitCallBackMap() { const uint32_t callback_id, const DomArgument ¶m) { auto fn = [this, function_name, callback_id](std::shared_ptr view) { - auto u16text = std::static_pointer_cast(view)->GetTextEditingValue().GetText(); + auto u16text = std::static_pointer_cast(view)->GetTextEditingValue().text; auto text = std::wstring_convert, char16_t>{}.to_bytes(u16text); DomValueObjectType param; param["text"] = footstone::HippyValue(text); @@ -263,7 +263,7 @@ void TextInputNode::InitCallBackMap() { const uint32_t callback_id, const DomArgument ¶m) { auto fn = [](std::shared_ptr view) { - std::static_pointer_cast(view)->TryHidingInputMethod(); + std::static_pointer_cast(view)->ClearFocus(); }; INVOKE_IF_VIEW_IS_VALIDATE(fn); }; @@ -272,7 +272,7 @@ void TextInputNode::InitCallBackMap() { const uint32_t callback_id, const DomArgument ¶m) { auto fn = [](std::shared_ptr view) { - std::static_pointer_cast(view)->TryShowingInputMethod(); + std::static_pointer_cast(view)->RequestFocus(); }; INVOKE_IF_VIEW_IS_VALIDATE(fn); }; @@ -324,13 +324,13 @@ void TextInputNode::RegisterViewportListener() { return tdfcore::EventDispatchBehavior::kContinue; }; viewport_listener_id_ = - ViewContext::GetCurrent()->GetShell()->GetEventCenter()->AddListener(ViewportEvent::ClassType(), listener); + GetView()->GetViewContext()->GetShell()->GetEventCenter()->AddListener(ViewportEvent::ClassType(), listener); } } void TextInputNode::UnregisterViewportListener() { if (viewport_listener_id_ != kViewportListenerInvalidID) { - ViewContext::GetCurrent()->GetShell()->GetEventCenter()->RemoveListener(ViewportEvent::ClassType(), + GetView()->GetViewContext()->GetShell()->GetEventCenter()->RemoveListener(ViewportEvent::ClassType(), viewport_listener_id_); } } @@ -378,7 +378,9 @@ void TextInputNode::SetEditable(const DomStyleMap& dom_style, std::shared_ptrsecond != nullptr) { - text_style.font_family = it->second->ToStringChecked().c_str(); + std::vector families; + families.push_back(it->second->ToStringChecked()); + text_style.font_families = families; } } @@ -416,16 +418,16 @@ void TextInputNode::SetFontWeight(const DomStyleMap& dom_style, TextStyle& text_ } void TextInputNode::SetKeyBoardType(const DomStyleMap& dom_style, std::shared_ptr& text_input_view) { - static std::map type_map = {{kKeyboardType_Default, KeyboardInputType::Text()}, - {kKeyboardType_Numeric, KeyboardInputType::Number()}, - {kKeyboardType_Password, KeyboardInputType::Password()}, - {kKeyboardType_Email, KeyboardInputType::EmailAddress()}, - {kKeyboardType_PhonePad, KeyboardInputType::Phone()}}; + static std::map type_map = {{kKeyboardType_Default, tdfcore::KeyboardType::kText}, + {kKeyboardType_Numeric, tdfcore::KeyboardType::kNumbers}, + {kKeyboardType_Password, tdfcore::KeyboardType::kPassword}, + {kKeyboardType_Email, tdfcore::KeyboardType::kEmailAddress}, + {kKeyboardType_PhonePad, tdfcore::KeyboardType::kPhone}}; if (auto it = dom_style.find(textinput::kKeyboardType); it != dom_style.end() && it->second != nullptr) { auto key_board_type = it->second->ToStringChecked(); if (type_map.find(key_board_type) != type_map.end()) { - text_input_view->SetInputType(type_map.at(key_board_type)); + text_input_view->SetKeyboardType(type_map.at(key_board_type)); } } } diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/text_view_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/text_view_node.cc index d7652434fb7..2115022b2c9 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/text_view_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/text_view_node.cc @@ -50,7 +50,7 @@ void TextViewNode::RegisterMeasureFunction(uint32_t root_id, const std::shared_p dom_node->GetLayoutNode()->SetMeasureFunction([view_node](float width, LayoutMeasureMode width_measure_mode, float height, LayoutMeasureMode height_measure_mode, void* layoutContext) { - auto size = view_node->layout_view_->MeasureText(static_cast(width)); + auto size = view_node->layout_view_->MeasureText(width); hippy::LayoutSize layout_result{static_cast(size.width), static_cast(size.height)}; return layout_result; }); @@ -89,8 +89,8 @@ std::shared_ptr TextViewNode::GetTextView() { return GetView(); } -std::shared_ptr TextViewNode::CreateView() { - auto text_view = TDF_MAKE_SHARED(TextView); +std::shared_ptr TextViewNode::CreateView(const std::shared_ptr &context) { + auto text_view = TDF_MAKE_SHARED(TextView, context); auto text_style = text_view->GetTextStyle(); text_style.color = kDefaultTextColor; text_view->SetTextStyle(text_style); @@ -204,7 +204,9 @@ void TextViewNode::SetLetterSpacing(const DomStyleMap& dom_style, TextStyle& tex void TextViewNode::SetFontFamily(const DomStyleMap& dom_style, TextStyle& text_style) { if (auto it = dom_style.find(text::kFontFamily); it != dom_style.end() && it->second != nullptr) { - text_style.font_family = it->second->ToStringChecked(); + std::vector families; + families.push_back(it->second->ToStringChecked()); + text_style.font_families = families; } } diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/view_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/view_node.cc index b9eed514dcf..32b3733bc14 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/view_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/view_node.cc @@ -180,7 +180,7 @@ void ViewNode::SetBackgroundImage(const std::string &img_url) { auto style = std::make_shared(); style->emplace(std::string(hippy::kImageSrc), std::make_shared(img_url)); auto ext = std::make_shared(); - auto dom_node = std::make_shared(0, + auto dom_node = std::make_shared(hippy::dom::kInvalidId, id_, 0, "BackgroundImage", @@ -384,8 +384,8 @@ void ViewNode::HandleLayoutUpdate(hippy::LayoutResult layout_result) { } } -std::shared_ptr ViewNode::CreateView() { - auto view = TDF_MAKE_SHARED(tdfcore::View); +std::shared_ptr ViewNode::CreateView(const std::shared_ptr &context) { + auto view = TDF_MAKE_SHARED(tdfcore::View, context); view->SetClipToBounds(true); return view; } @@ -410,9 +410,7 @@ void ViewNode::OnRemoveEventListener(uint32_t id, const std::string& name) { } void ViewNode::HandleEventInfoUpdate() { - if (supported_events_.find(hippy::kClickEvent) != supported_events_.end() || - supported_events_.find(hippy::kPressIn) != supported_events_.end() || - supported_events_.find(hippy::kPressOut) != supported_events_.end()) { + if (supported_events_.find(hippy::kClickEvent) != supported_events_.end()) { RegisterClickEvent(); } @@ -423,7 +421,9 @@ void ViewNode::HandleEventInfoUpdate() { if (supported_events_.find(hippy::kTouchStartEvent) != supported_events_.end() || supported_events_.find(hippy::kTouchMoveEvent) != supported_events_.end() || supported_events_.find(hippy::kTouchEndEvent) != supported_events_.end() || - supported_events_.find(hippy::kTouchCancelEvent) != supported_events_.end()) { + supported_events_.find(hippy::kTouchCancelEvent) != supported_events_.end() || + supported_events_.find(hippy::kPressIn) != supported_events_.end() || + supported_events_.find(hippy::kPressOut) != supported_events_.end()) { RegisterTouchEvent(); } } @@ -436,37 +436,10 @@ void ViewNode::RegisterClickEvent() { tap_view_.lock()->AddGesture(tap_recognizer_); } - if (supported_events_.find(hippy::kClickEvent) != supported_events_.end()) { - tap_recognizer_->SetTap([WEAK_THIS]() { - DEFINE_AND_CHECK_SELF(ViewNode) - self->SendGestureDomEvent(kClickEvent, nullptr); - }); - } else { - tap_recognizer_->SetTap(nullptr); - } - - if (supported_events_.find(hippy::kPressIn) != supported_events_.end()) { - tap_recognizer_->SetTapDown([WEAK_THIS](const tdfcore::TapDetails& detail) { - DEFINE_AND_CHECK_SELF(ViewNode) - self->SendGestureDomEvent(kPressIn, nullptr); - }); - } else { - tap_recognizer_->SetTapDown(nullptr); - } - - if (supported_events_.find(hippy::kPressOut) != supported_events_.end()) { - tap_recognizer_->SetTapUp([WEAK_THIS](const tdfcore::TapDetails& detail) { - DEFINE_AND_CHECK_SELF(ViewNode) - self->SendGestureDomEvent(kPressOut, nullptr); - }); - tap_recognizer_->SetTapCancel([WEAK_THIS]() { - DEFINE_AND_CHECK_SELF(ViewNode) - self->SendGestureDomEvent(kPressOut, nullptr); - }); - } else { - tap_recognizer_->SetTapUp(nullptr); - tap_recognizer_->SetTapCancel(nullptr); - } + tap_recognizer_->SetTap([WEAK_THIS](const tdfcore::TapDetails &details) { + DEFINE_AND_CHECK_SELF(ViewNode) + self->SendGestureDomEvent(kClickEvent, nullptr); + }); } void ViewNode::RegisterLongClickEvent() { @@ -485,51 +458,72 @@ void ViewNode::RegisterLongClickEvent() { } void ViewNode::RegisterTouchEvent() { - if (touch_recognizer_ == nullptr || GetView() != touch_view_.lock()) { - touch_recognizer_ = TDF_MAKE_SHARED(TouchRecognizer); - gestures_map_[kTouchStartEvent] = touch_recognizer_; + if (touch_event_ == nullptr || GetView() != touch_view_.lock()) { + touch_event_ = TDF_MAKE_SHARED(tdfcore::PointerEventListener); touch_view_ = GetView(); - touch_view_.lock()->AddGesture(touch_recognizer_); + touch_view_.lock()->AddUIEventListener(touch_event_); } - if (supported_events_.find(hippy::kTouchStartEvent) != supported_events_.end()) { - touch_recognizer_->SetTouchStart([WEAK_THIS](const TouchDetails &details) { + bool has_touch_start = supported_events_.find(hippy::kTouchStartEvent) != supported_events_.end(); + bool has_touch_move = supported_events_.find(hippy::kTouchMoveEvent) != supported_events_.end(); + bool has_touch_end = supported_events_.find(hippy::kTouchEndEvent) != supported_events_.end(); + bool has_touch_cancel = supported_events_.find(hippy::kTouchCancelEvent) != supported_events_.end(); + bool has_press_in = supported_events_.find(hippy::kPressIn) != supported_events_.end(); + bool has_press_out = supported_events_.find(hippy::kPressOut) != supported_events_.end(); + + if (has_touch_start || has_press_in) { + touch_event_->SetTouchesBegan([WEAK_THIS, has_touch_start, has_press_in](const tdfcore::PointerDataList &data_list) { DEFINE_AND_CHECK_SELF(ViewNode) - auto value = TouchRecognizer::TouchDetails2HippyValue(self->GetRenderInfo().id, "onTouchDown", details); - self->SendGestureDomEvent(kTouchStartEvent, value); + if (has_touch_start) { + auto value = PointerDataList2HippyValue(self->GetRenderInfo().id, "onTouchDown", data_list); + self->SendGestureDomEvent(kTouchStartEvent, value); + } + if (has_press_in) { + self->SendGestureDomEvent(kPressIn, nullptr); + } }); } else { - touch_recognizer_->SetTouchStart(nullptr); + touch_event_->SetTouchesBegan(nullptr); } - if (supported_events_.find(hippy::kTouchMoveEvent) != supported_events_.end()) { - touch_recognizer_->SetTouchMove([WEAK_THIS](const TouchDetails &details) { + if (has_touch_move) { + touch_event_->SetTouchesMoved([WEAK_THIS](const tdfcore::PointerDataList &data_list) { DEFINE_AND_CHECK_SELF(ViewNode) - auto value = TouchRecognizer::TouchDetails2HippyValue(self->GetRenderInfo().id, "onTouchMove", details); + auto value = PointerDataList2HippyValue(self->GetRenderInfo().id, "onTouchMove", data_list); self->SendGestureDomEvent(kTouchMoveEvent, value); }); } else { - touch_recognizer_->SetTouchMove(nullptr); + touch_event_->SetTouchesMoved(nullptr); } - if (supported_events_.find(hippy::kTouchEndEvent) != supported_events_.end()) { - touch_recognizer_->SetTouchEnd([WEAK_THIS](const TouchDetails &details) { + if (has_touch_end || has_press_out) { + touch_event_->SetTouchesEnded([WEAK_THIS, has_touch_end, has_press_out](const tdfcore::PointerDataList &data_list) { DEFINE_AND_CHECK_SELF(ViewNode) - auto value = TouchRecognizer::TouchDetails2HippyValue(self->GetRenderInfo().id, "onTouchEnd", details); - self->SendGestureDomEvent(kTouchEndEvent, value); + if (has_touch_end) { + auto value = PointerDataList2HippyValue(self->GetRenderInfo().id, "onTouchEnd", data_list); + self->SendGestureDomEvent(kTouchEndEvent, value); + } + if (has_press_out) { + self->SendGestureDomEvent(kPressOut, nullptr); + } }); } else { - touch_recognizer_->SetTouchEnd(nullptr); + touch_event_->SetTouchesEnded(nullptr); } - if (supported_events_.find(hippy::kTouchCancelEvent) != supported_events_.end()) { - touch_recognizer_->SetTouchCancel([WEAK_THIS](const TouchDetails &details) { + if (has_touch_cancel || has_press_out) { + touch_event_->SetTouchesCanceled([WEAK_THIS, has_touch_cancel, has_press_out](const tdfcore::PointerDataList &data_list) { DEFINE_AND_CHECK_SELF(ViewNode) - auto value = TouchRecognizer::TouchDetails2HippyValue(self->GetRenderInfo().id, "onTouchCancel", details); - self->SendGestureDomEvent(kTouchCancelEvent, value); + if (has_touch_cancel) { + auto value = PointerDataList2HippyValue(self->GetRenderInfo().id, "onTouchCancel", data_list); + self->SendGestureDomEvent(kTouchCancelEvent, value); + } + if (has_press_out) { + self->SendGestureDomEvent(kPressOut, nullptr); + } }); } else { - touch_recognizer_->SetTouchCancel(nullptr); + touch_event_->SetTouchesCanceled(nullptr); } } @@ -546,10 +540,15 @@ void ViewNode::RemoveGestureEvent(std::string&& event_type) { void ViewNode::RemoveAllEventInfo() { RemoveGestureEvent(hippy::kClickEvent); RemoveGestureEvent(hippy::kLongClickEvent); - RemoveGestureEvent(hippy::kTouchStartEvent); tap_recognizer_ = nullptr; long_press_recognizer_ = nullptr; - touch_recognizer_ = nullptr; + if (touch_event_) { + auto view = attached_view_.lock(); + if (view) { + view->RemoveUIEventListener(touch_event_); + } + touch_event_ = nullptr; + } } void ViewNode::HandleInterceptEvent(const DomStyleMap& dom_style) { @@ -573,7 +572,7 @@ void ViewNode::OnChildAdd(const std::shared_ptr& child, int64_t index) if (!IsAttached()) { return; } - child->Attach(); + child->Attach(GetView()->GetViewContext()); } void ViewNode::OnChildRemove(const std::shared_ptr& child) { child->Detach(); } @@ -685,7 +684,7 @@ bool ViewNode::IsAttachViewMatch(const std::shared_ptr& node, const st return true; } -void ViewNode::Attach(const std::shared_ptr& view) { +void ViewNode::Attach(const std::shared_ptr &context, const std::shared_ptr& view) { FOOTSTONE_DCHECK(!is_attached_); FOOTSTONE_DCHECK(!parent_.expired()); FOOTSTONE_DCHECK(parent_.lock()->IsAttached()); @@ -699,7 +698,7 @@ void ViewNode::Attach(const std::shared_ptr& view) { attached_view_ = view; } else { // this should be the only caller of CreateView. - auto v = CreateView(); + auto v = CreateView(context); v->SetId(render_info_.id); v->SetHitTestBehavior(tdfcore::HitTestBehavior::kTranslucent); if (parent_.lock()->GetInterceptTouchEventFlag()) { @@ -747,7 +746,7 @@ void ViewNode::Attach(const std::shared_ptr& view) { } } if (!child->IsAttached()) { - child->Attach(child_view); + child->Attach(context, child_view); } ++child_index; } @@ -794,6 +793,20 @@ void ViewNode::CallFunction(const std::string &name, const DomArgument ¶m, c DevtoolsUtil::CallDevtoolsFunction(root_node_, shared_from_this(), name, param, call_back_id); } +std::shared_ptr ViewNode::PointerDataList2HippyValue( + uint32_t id, const char *name, const tdfcore::PointerDataList &data_list) { + if (data_list.size() == 0) { + return nullptr; + } + auto pointer = data_list[0]; + footstone::HippyValue::HippyValueObjectType obj; + obj["id"] = footstone::HippyValue(id); + obj["name"] = footstone::HippyValue(name); + obj["page_x"] = footstone::HippyValue(pointer.position.x); + obj["page_y"] = footstone::HippyValue(pointer.position.y); + return std::make_shared(obj); +} + } // namespace tdf } // namespace render } // namespace hippy diff --git a/renderer/tdf/common/src/renderer/tdf/viewnode/view_pager_node.cc b/renderer/tdf/common/src/renderer/tdf/viewnode/view_pager_node.cc index 8eadcdfc004..05b478fd0da 100644 --- a/renderer/tdf/common/src/renderer/tdf/viewnode/view_pager_node.cc +++ b/renderer/tdf/common/src/renderer/tdf/viewnode/view_pager_node.cc @@ -61,8 +61,8 @@ void ViewPagerNode::HandleLayoutUpdate(hippy::LayoutResult layout_result) { has_layout_ = true; } -std::shared_ptr ViewPagerNode::CreateView() { - auto view_pager = TDF_MAKE_SHARED(ViewPager); +std::shared_ptr ViewPagerNode::CreateView(const std::shared_ptr &context) { + auto view_pager = TDF_MAKE_SHARED(ViewPager, context); return view_pager; }