From 0c8f39ac51b5a5585268712cd595bcef880655ef Mon Sep 17 00:00:00 2001 From: zhouchaobo Date: Thu, 4 Jul 2024 14:46:10 +0800 Subject: [PATCH 001/221] Pan onActionStart bug fix Signed-off-by: zhouchaobo Change-Id: I7bc3a8ca0fc12d20adf5d3de60a7bf33bb4a4816 --- .../components_ng/gestures/recognizers/pan_recognizer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp index 0bede4d1a73..4c8f0683ac2 100644 --- a/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp +++ b/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp @@ -930,6 +930,11 @@ void PanRecognizer::UpdateTouchEventInfo(const TouchEvent& event) windowTouchPoint, GetAttachedNode(), false, isPostEventResult_, event.postEventNodeId); delta_ = (Offset(windowPoint.GetX(), windowPoint.GetY()) - Offset(windowTouchPoint.GetX(), windowTouchPoint.GetY())); + if ((direction_.type & PanDirection::VERTICAL) == 0) { + delta_.SetY(0.0); + } else if ((direction_.type & PanDirection::HORIZONTAL) == 0) { + delta_.SetX(0.0); + } if (SystemProperties::GetDebugEnabled()) { TAG_LOGD(AceLogTag::ACE_GESTURE, "Delta is x %{public}f, y %{public}f ", delta_.GetX(), delta_.GetY()); From 64784e8b83ad154ec65951eb584502e3cd30bc5e Mon Sep 17 00:00:00 2001 From: jidehong Date: Wed, 10 Jul 2024 15:31:21 +0800 Subject: [PATCH 002/221] =?UTF-8?q?egl=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jidehong --- bundle.json | 3 ++- frameworks/core/components/web/BUILD.gn | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 3d6a9424c5e..365db0496c7 100644 --- a/bundle.json +++ b/bundle.json @@ -92,7 +92,8 @@ "skia", "libuv", "background_task_mgr", - "atomicservice_basic_engine" + "atomicservice_basic_engine", + "egl" ], "third_party": [] }, diff --git a/frameworks/core/components/web/BUILD.gn b/frameworks/core/components/web/BUILD.gn index b22aa854379..cc69f3d0913 100644 --- a/frameworks/core/components/web/BUILD.gn +++ b/frameworks/core/components/web/BUILD.gn @@ -48,6 +48,7 @@ build_component("web") { "opengles:libGLES", "webview:libnweb", "window_manager:libwm", + "egl:libEGL" ] } } From 6589b7675fdf91af28b4bb81e6113bc8042807da Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Sat, 13 Jul 2024 13:34:26 +0800 Subject: [PATCH 003/221] dialog_0713 Signed-off-by: sunjiakun --- .../dialog/dialog_layout_algorithm.cpp | 27 ++++++++++++++++- .../pattern/dialog/dialog_layout_algorithm.h | 5 +++- .../pattern/dialog/dialog_pattern.cpp | 30 +++++++++++++++++++ .../pattern/dialog/dialog_pattern.h | 13 ++++++++ 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp index c11f6b1a034..84da0902ccf 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp @@ -64,6 +64,7 @@ constexpr int32_t DIALOG_DEVICE_COLUMN_TWO = 2; constexpr int32_t DIALOG_DEVICE_COLUMN_THREE = 3; constexpr int32_t DIALOG_DEVICE_COLUMN_FOUR = 4; constexpr double LANDSCAPE_DIALOG_WIDTH_RATIO = 0.75; +constexpr Dimension SCROLL_MIN_HEIGHT_SUITOLD = 100.0_vp; } // namespace void DialogLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) @@ -89,6 +90,7 @@ void DialogLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) auto windowManager = pipeline->GetWindowManager(); CHECK_NULL_VOID(windowManager); dialogPattern->UpdateFontScale(); + isSuitOldMeasure_ = dialogPattern->GetIsSuitOldMeasure(); isSuitableForElderly_ = dialogPattern->GetIsSuitableForAging() && windowManager->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING && GreatOrEqual(pipeline->GetFontScale(), 1.75f); @@ -113,6 +115,10 @@ void DialogLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) // constraint child size unless developer is using customStyle if (!customSize_) { auto maxSize = layoutConstraint->maxSize; + if (isSuitOldMeasure_) { + maxSize.SetWidth(pipeline->GetRootWidth()); + maxSize.SetHeight(pipeline->GetRootHeight()); + } maxSize.MinusPadding(0, 0, safeAreaInsets_.top_.Length(), 0); if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE) && LessNotEqual(gridCount_, 0)) { maxSize.MinusPadding(0, 0, 0, safeAreaInsets_.bottom_.Length()); @@ -127,8 +133,10 @@ void DialogLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) } // childSize_ and childOffset_ is used in Layout. child->Measure(childLayoutConstraint); - if (!layoutWrapper->GetHostNode()->GetPattern()->GetCustomNode()) { + if (isSuitOldMeasure_) { + dialogMaxHeight_ = childLayoutConstraint.maxSize.Height(); + } AnalysisHeightOfChild(layoutWrapper); } } @@ -186,6 +194,7 @@ void DialogLayoutAlgorithm::AnalysisHeightOfChild(LayoutWrapper* layoutWrapper) if (scroll != nullptr) { auto childConstraint = CreateDialogChildConstraint(layoutWrapper, std::min(restHeight, scrollHeight), restWidth); + UpdateIsScrollHeightNegative(layoutWrapper, std::min(restHeight, scrollHeight)); scroll->Measure(childConstraint); } if (list != nullptr) { @@ -896,4 +905,20 @@ void DialogLayoutAlgorithm::ClipUIExtensionSubWindowContent(const RefPtrUpdateClipShape(nullptr); } } + +void DialogLayoutAlgorithm::UpdateIsScrollHeightNegative(LayoutWrapper* layoutWrapper, float height) +{ + if (height < SCROLL_MIN_HEIGHT_SUITOLD.ConvertToPx()) { + const auto& children = layoutWrapper->GetAllChildrenWithBuild(); + auto child = children.front(); + auto childSize = child->GetGeometryNode()->GetMarginFrameSize(); + if (childSize.Height() == dialogMaxHeight_) { + auto hostNode = layoutWrapper->GetHostNode(); + CHECK_NULL_VOID(hostNode); + auto dialogPattern = hostNode->GetPattern(); + CHECK_NULL_VOID(dialogPattern); + dialogPattern->SetIsScrollHeightNegative(true); + } + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.h b/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.h index 0cf6e5252d1..66b301d7012 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.h @@ -92,7 +92,8 @@ private: LayoutConstraintF& childLayoutConstraint, RefPtr& childLayoutWrapper); void ClipUIExtensionSubWindowContent(const RefPtr& dialog, bool isClip); void AdjustHeightForKeyboard(LayoutWrapper* layoutWrapper, const RefPtr& child); - + void UpdateIsScrollHeightNegative(LayoutWrapper* layoutWrapper, float height); + RectF touchRegion_; OffsetF topLeftPoint_; bool customSize_ = false; @@ -100,6 +101,8 @@ private: bool isModal_ = true; bool isShowInSubWindow_ = false; bool isSuitableForElderly_ = false; + bool isSuitOldMeasure_ = false; + float dialogMaxHeight_ = 0.0f; int32_t gridCount_ = -1; int32_t subWindowId_ = -1; DimensionOffset dialogOffset_; diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp index 57a4a2cc9bc..354cf0c717a 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp +++ b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.cpp @@ -158,6 +158,8 @@ void DialogPattern::OnFontConfigurationUpdate() auto buttonContainerNew = BuildButtons(dialogProperties_.buttons, DialogButtonDirection::VERTICAL); CHECK_NULL_VOID(buttonContainerNew); buttonContainerNew->MountToParent(contentColumn_); + buttonContainer_ = buttonContainerNew; + CheckScrollHeightIsNegative(contentColumn_, dialogProperties_); UpdateTextFontScale(); } } @@ -462,6 +464,7 @@ void DialogPattern::BuildChild(const DialogProperties& props) auto buttonContainerNew = BuildButtons(props.buttons, DialogButtonDirection::VERTICAL); buttonContainerNew->MountToParent(contentColumn); buttonContainer_ = buttonContainerNew; + CheckScrollHeightIsNegative(contentColumn, props); } contentColumn_ = contentColumn; UpdateTextFontScale(); @@ -1337,7 +1340,9 @@ bool DialogPattern::NeedsButtonDirectionChange(const std::vector& bu auto props = host->GetLayoutProperty(); CHECK_NULL_RETURN(props, false); auto buttonLayoutConstraint = props->GetLayoutConstraint(); + isSuitOldMeasure_ = true; host->Measure(buttonLayoutConstraint); + isSuitOldMeasure_ = false; const auto& children = buttonContainer_->GetChildren(); for (const auto& child : children) { if (child->GetTag() == V2::BUTTON_ETS_TAG) { @@ -1375,6 +1380,31 @@ bool DialogPattern::NeedsButtonDirectionChange(const std::vector& bu return false; } +void DialogPattern::CheckScrollHeightIsNegative( + const RefPtr& contentColumn, const DialogProperties& Dialogprops) +{ + CHECK_NULL_VOID(buttonContainer_); + if (Dialogprops.buttons.size() == ONE_BUTTON_MODE || buttonContainer_->GetTag() == V2::ROW_ETS_TAG) { + return; + } + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto props = host->GetLayoutProperty(); + CHECK_NULL_VOID(props); + auto buttonLayoutConstraint = props->GetLayoutConstraint(); + isSuitOldMeasure_ = true; + host->Measure(buttonLayoutConstraint); + isSuitOldMeasure_ = false; + if (isScrollHeightNegative_) { + isSuitableForElderly_ = false; + notAdapationAging_ = true; + contentColumn->RemoveChild(buttonContainer_); + auto buttonContainerNew = BuildButtons(Dialogprops.buttons, Dialogprops.buttonDirection); + buttonContainerNew->MountToParent(contentColumn); + buttonContainer_ = buttonContainerNew; + } +} + void DialogPattern::UpdateDeviceOrientation(const DeviceOrientation& deviceOrientation) { if (deviceOrientation_ != deviceOrientation) { diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h index ce583bbe06c..65ff4f20905 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h +++ b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h @@ -259,6 +259,16 @@ public: void InitHostWindowRect(); void UpdateFontScale(); + bool GetIsSuitOldMeasure() + { + return isSuitOldMeasure_; + } + + void SetIsScrollHeightNegative(bool isScrollHeightNegative) + { + isScrollHeightNegative_ = isScrollHeightNegative; + } + private: bool AvoidKeyboard() const override { @@ -326,6 +336,7 @@ private: void OnFontConfigurationUpdate() override; void UpdateTextFontScale(); void UpdateTitleTextFontScale(); + void CheckScrollHeightIsNegative(const RefPtr& contentColumn, const DialogProperties& props); RefPtr dialogTheme_; WeakPtr customNode_; RefPtr onClick_; @@ -349,6 +360,8 @@ private: RefPtr contentRenderContext_; bool isSuitableForElderly_ = false; bool notAdapationAging_ = false; + bool isSuitOldMeasure_ = false; + bool isScrollHeightNegative_ = false; float fontScaleForElderly_ = 1.0f; DeviceOrientation deviceOrientation_ = DeviceOrientation::PORTRAIT; RefPtr titleContainer_; From 31dab17c3b90fa609eb1e12b65bb121af0e699aa Mon Sep 17 00:00:00 2001 From: luoying_ace_admin Date: Mon, 15 Jul 2024 08:28:44 +0000 Subject: [PATCH 004/221] bugfix Signed-off-by: luoying_ace_admin Change-Id: I78580ae0224897c1e699b895c36b89fb8405b71d --- frameworks/base/subwindow/subwindow_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/base/subwindow/subwindow_manager.cpp b/frameworks/base/subwindow/subwindow_manager.cpp index 62f2af101a0..8217d0d295a 100644 --- a/frameworks/base/subwindow/subwindow_manager.cpp +++ b/frameworks/base/subwindow/subwindow_manager.cpp @@ -575,6 +575,7 @@ void SubwindowManager::HideDialogSubWindow(int32_t instanceId) auto subwindow = GetSubwindow(instanceId >= MIN_SUBCONTAINER_ID ? GetParentContainerId(instanceId) : instanceId); CHECK_NULL_VOID(subwindow); auto overlay = subwindow->GetOverlayManager(); + CHECK_NULL_VOID(overlay); if (overlay->GetDialogMap().size() == 0) { subwindow->HideSubWindowNG(); } From 57c02e3e1d7cacb494cc64e12a7e60db6446accb Mon Sep 17 00:00:00 2001 From: zhangjinyu101 Date: Mon, 15 Jul 2024 19:32:40 +0800 Subject: [PATCH 005/221] =?UTF-8?q?imageSpan=20=E9=80=82=E9=85=8DimageFit?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9A=84=E6=9E=9A=E4=B8=BE=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangjinyu101 Change-Id: I06618dff0f57350bc2ea1245a65d812798f86114 --- frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp b/frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp index 02cd5b21854..06428030c6c 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_image_span.cpp @@ -65,7 +65,7 @@ void JSImageSpan::SetObjectFit(const JSCallbackInfo& info) JSRef args = info[0]; if (args->IsNumber()) { auto fit = static_cast(args->ToNumber()); - if (fit < ImageFit::FILL || fit > ImageFit::SCALE_DOWN) { + if (fit < ImageFit::FILL || fit > ImageFit::BOTTOM_END) { fit = ImageFit::COVER; } ImageModel::GetInstance()->SetImageFit(fit); From 90cce999925fb9e368330ae30500e42833630da8 Mon Sep 17 00:00:00 2001 From: jiyujia926 Date: Tue, 16 Jul 2024 15:49:18 +0800 Subject: [PATCH 006/221] implement UIUtils.getTarget Signed-off-by: jiyujia926 --- .../engine/jsStateManagement.js | 37 +++++++++++++++- .../declarative_frontend/engine/stateMgmt.js | 41 ++++++++++++++++++ .../state_mgmt/src/lib/sdk/ui_utils.ts | 42 +++++++++++++++++++ .../src/lib/v2/v2_change_observation.ts | 2 +- .../state_mgmt/tsconfig.json | 1 + .../state_mgmt/tsconfig.profile.json | 1 + .../state_mgmt/tsconfig.release.json | 1 + .../state_mgmt/tsconfig.test.json | 1 + 8 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/ui_utils.ts diff --git a/frameworks/bridge/declarative_frontend/engine/jsStateManagement.js b/frameworks/bridge/declarative_frontend/engine/jsStateManagement.js index f241ebd2879..25c7a1aba47 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsStateManagement.js +++ b/frameworks/bridge/declarative_frontend/engine/jsStateManagement.js @@ -148,8 +148,43 @@ PersistenceV2.persistenceV2Impl_ = PersistenceV2Impl.instance(); const Type = __Type__; +/** + * UIUtils is a state management tool class for operating the observed data. + * + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +class UIUtils { + /** + * Get raw object from the Object wrapped with Proxy added by statemanagement framework. + * If input parameter is a regular Object without Proxy, return Object itself. + * + * 1. For StateManagement V1, when source is a @Observed decorated object, + * or a Object/Array/Map/Set/Date decorated by state decorators like @State, + * getTarget will return its raw object without Proxy. + * 2. For StateManagement V2, when source is a Array/Map/Set/Date decorated by state decorators + * like @Trace or @Local, getTarget will return its raw object without Proxy. + * 3. For other situation, getTarget will return the source directly. + * + * @param { T } source input source Object data. + * @returns { T } raw object from the Object wrapped with an ObservedObject. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static getTarget(source) { + return UIUtils.uiUtilsImpl_.getTarget(source); + } +} + +UIUtils.uiUtilsImpl_ = UIUtilsImpl.instance(); + export default { AppStorageV2, PersistenceV2, - Type + Type, + UIUtils }; diff --git a/frameworks/bridge/declarative_frontend/engine/stateMgmt.js b/frameworks/bridge/declarative_frontend/engine/stateMgmt.js index 99d68db1e9b..38d8a3171e4 100644 --- a/frameworks/bridge/declarative_frontend/engine/stateMgmt.js +++ b/frameworks/bridge/declarative_frontend/engine/stateMgmt.js @@ -10582,6 +10582,47 @@ PersistenceV2Impl.KEYS_ARR_ = '___keys_arr'; PersistenceV2Impl.MAX_DATA_LENGTH_ = 8000; PersistenceV2Impl.NOT_SUPPORT_TYPES_ = [Array, Set, Map, WeakSet, WeakMap, Date, Boolean, Number, String, Symbol, BigInt, RegExp, Function, Promise, ArrayBuffer]; PersistenceV2Impl.instance_ = undefined; +/* + * Copyright (c) 2024 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. + */ +class UIUtilsImpl { + static getTarget(source) { + if (!source || typeof source !== 'object') { + return source; + } + if (ObservedObject.IsObservedObject(source)) { + // V1 Proxy object + return ObservedObject.GetRawObject(source); + } + else if (source[ObserveV2.SYMBOL_PROXY_GET_TARGET]) { + // V2 Proxy object + return source[ObserveV2.SYMBOL_PROXY_GET_TARGET]; + } + else { + // other situation, not handle + return source; + } + } + static instance() { + if (UIUtilsImpl.instance_) { + return UIUtilsImpl.instance_; + } + UIUtilsImpl.instance_ = new UIUtilsImpl(); + return UIUtilsImpl.instance_; + } +} +UIUtilsImpl.instance_ = undefined; /* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/ui_utils.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/ui_utils.ts new file mode 100644 index 00000000000..82d3f51a796 --- /dev/null +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/sdk/ui_utils.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2024 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. + */ + +class UIUtilsImpl { + private static instance_: UIUtilsImpl = undefined; + + public static getTarget(source: T): T { + if (!source || typeof source !== 'object') { + return source; + } + if (ObservedObject.IsObservedObject(source)) { + // V1 Proxy object + return ObservedObject.GetRawObject(source); + } else if (source[ObserveV2.SYMBOL_PROXY_GET_TARGET]) { + // V2 Proxy object + return source[ObserveV2.SYMBOL_PROXY_GET_TARGET]; + } else { + // other situation, not handle + return source; + } + } + + public static instance(): UIUtilsImpl { + if (UIUtilsImpl.instance_) { + return UIUtilsImpl.instance_; + } + UIUtilsImpl.instance_ = new UIUtilsImpl(); + return UIUtilsImpl.instance_; + } +} \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/v2/v2_change_observation.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/v2/v2_change_observation.ts index ceaf44af88b..a8f256cb165 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/v2/v2_change_observation.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/v2/v2_change_observation.ts @@ -69,7 +69,7 @@ class ObserveV2 { public static readonly MONITOR_REFS = Symbol('___monitor_refs_'); public static readonly COMPUTED_REFS = Symbol('___computed_refs_'); - private static readonly SYMBOL_PROXY_GET_TARGET = Symbol('__proxy_get_target'); + public static readonly SYMBOL_PROXY_GET_TARGET = Symbol('__proxy_get_target'); public static readonly OB_PREFIX = '__ob_'; // OB_PREFIX + attrName => backing store attribute name public static readonly OB_PREFIX_LEN = 5; diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.json b/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.json index daecc804158..537bfa5ab90 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.json +++ b/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.json @@ -93,6 +93,7 @@ // sdk "src/lib/sdk/v2_persistence.ts", + "src/lib/sdk/ui_utils.ts", // init "src/index.ts", diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.profile.json b/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.profile.json index 6334b932d06..c07ed24ad27 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.profile.json +++ b/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.profile.json @@ -93,6 +93,7 @@ // sdk "src/lib/sdk/v2_persistence.ts", + "src/lib/sdk/ui_utils.ts", // init "src/index.ts", diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.release.json b/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.release.json index 2ac093d989e..adf25d64baa 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.release.json +++ b/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.release.json @@ -93,6 +93,7 @@ // sdk "src/lib/sdk/v2_persistence.ts", + "src/lib/sdk/ui_utils.ts", // init "src/index.ts", diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.test.json b/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.test.json index 864fbd1b6b4..8532bb32fa3 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.test.json +++ b/frameworks/bridge/declarative_frontend/state_mgmt/tsconfig.test.json @@ -81,6 +81,7 @@ // sdk "src/lib/sdk/v2_persistence.ts", + "src/lib/sdk/ui_utils.ts", // unit testing "src/utest/common/helpers_for_test.ts", From aa8a0378e0ebf82c6542e8400c62adcf92368186 Mon Sep 17 00:00:00 2001 From: jidehong Date: Tue, 16 Jul 2024 20:33:27 +0800 Subject: [PATCH 007/221] =?UTF-8?q?egl=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jidehong --- frameworks/core/components/web/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/core/components/web/BUILD.gn b/frameworks/core/components/web/BUILD.gn index cc69f3d0913..b34ec2fb047 100644 --- a/frameworks/core/components/web/BUILD.gn +++ b/frameworks/core/components/web/BUILD.gn @@ -41,6 +41,7 @@ build_component("web") { "ability_runtime:abilitykit_native", "ability_runtime:app_manager", "c_utils:utils", + "egl:libEGL", "graphic_2d:librender_service_client", "init:libbegetutil", "ipc:ipc_core", @@ -48,7 +49,6 @@ build_component("web") { "opengles:libGLES", "webview:libnweb", "window_manager:libwm", - "egl:libEGL" ] } } From 5c14ca34dec857304994bf9e7d804818737d8810 Mon Sep 17 00:00:00 2001 From: Far Date: Mon, 15 Jul 2024 15:51:32 +0800 Subject: [PATCH 008/221] fix: add null-checking for webdelegate in surface occlusion change callback. When the surface occulison change callback is invoked, the delegate may be release, so the checking is necessary. Signed-off-by: Far --- frameworks/core/components/web/resource/web_delegate.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp index 0bf4ca445f1..b8a92fb525b 100644 --- a/frameworks/core/components/web/resource/web_delegate.cpp +++ b/frameworks/core/components/web/resource/web_delegate.cpp @@ -2734,8 +2734,9 @@ void WebDelegate::RegisterSurfaceOcclusionChangeFun() } auto ret = OHOS::Rosen::RSInterfaces::GetInstance().RegisterSurfaceOcclusionChangeCallback( surfaceNodeId_, - [weak = WeakClaim(this), weakContext = context_](float visibleRatio) { + [weak = WeakClaim(this)](float visibleRatio) { auto delegate = weak.Upgrade(); + CHECK_NULL_VOID(delegate); auto context = delegate->context_.Upgrade(); CHECK_NULL_VOID(context); context->GetTaskExecutor()->PostTask( From 2f6ba34b2bee03c6a799c16faaf50122d0c6836a Mon Sep 17 00:00:00 2001 From: s00800643 Date: Wed, 17 Jul 2024 14:08:19 +0800 Subject: [PATCH 009/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E5=A4=9A=E4=B8=AAFormRequest=E5=9C=BA=E6=99=AF=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E5=9B=9E=E6=94=B6=E6=81=A2=E5=A4=8D=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s00800643 Change-Id: I1a432bae23c6977e61c2f828e396f52d68e30c88 --- .../form/resource/form_manager_delegate.cpp | 7 ++-- .../form_render/include/form_renderer_group.h | 2 ++ .../form_render/src/form_renderer_group.cpp | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components/form/resource/form_manager_delegate.cpp b/frameworks/core/components/form/resource/form_manager_delegate.cpp index af7ccb57fc8..c844c912ae8 100644 --- a/frameworks/core/components/form/resource/form_manager_delegate.cpp +++ b/frameworks/core/components/form/resource/form_manager_delegate.cpp @@ -214,9 +214,12 @@ void FormManagerDelegate::OnSurfaceCreate(const AppExecFwk::FormJsInfo& formInfo newWant.SetParam(OHOS::AppExecFwk::Constants::FORM_IS_RECOVER_FORM_TO_HANDLE_CLICK_EVENT, needHandleCachedClick); onFormSurfaceNodeCallback_(rsSurfaceNode, newWant); - if (!formRendererDispatcher_) { - sptr proxy = want.GetRemoteObject(FORM_RENDERER_DISPATCHER); + + sptr proxy = want.GetRemoteObject(FORM_RENDERER_DISPATCHER); + if (proxy != nullptr) { formRendererDispatcher_ = iface_cast(proxy); + } else { + TAG_LOGE(AceLogTag::ACE_FORM, "want renderer dispatcher null"); } isDynamic_ = formInfo.isDynamic; diff --git a/interfaces/inner_api/form_render/include/form_renderer_group.h b/interfaces/inner_api/form_render/include/form_renderer_group.h index 46576507888..a4c64857f78 100644 --- a/interfaces/inner_api/form_render/include/form_renderer_group.h +++ b/interfaces/inner_api/form_render/include/form_renderer_group.h @@ -80,7 +80,9 @@ public: void UpdateConfiguration(const std::shared_ptr& config); bool IsFormRequestsEmpty(); const std::vector& GetAllRendererFormRequests() const; + std::pair, std::string> GetOrderedAndCurrentCompIds() const; void RecycleForm(std::string& statusData) const; + void RecoverRenderer(const std::vector & formRequests, int currentCompIndex); private: enum class FormRendererInitState { UNINITIALIZED, diff --git a/interfaces/inner_api/form_render/src/form_renderer_group.cpp b/interfaces/inner_api/form_render/src/form_renderer_group.cpp index 5832e4caea4..8ef7233328d 100644 --- a/interfaces/inner_api/form_render/src/form_renderer_group.cpp +++ b/interfaces/inner_api/form_render/src/form_renderer_group.cpp @@ -214,6 +214,15 @@ const std::vector& FormRendererGroup::GetAllRendererFormRequests() return formRequests_; } +std::pair, std::string> FormRendererGroup::GetOrderedAndCurrentCompIds() const +{ + std::vector orderedCompIds; + for (auto formRequest: formRequests_) { + orderedCompIds.emplace_back(formRequest.compId); + } + return std::make_pair(orderedCompIds, currentCompId_); +} + void FormRendererGroup::DeleteForm() { if (formRenderer_ == nullptr) { @@ -247,5 +256,28 @@ void FormRendererGroup::RecycleForm(std::string& statusData) const } formRenderer_->RecycleForm(statusData); } + +void FormRendererGroup::RecoverRenderer(const std::vector & formRequests, int currentCompIndex) +{ + if (currentCompIndex >= formRequests.size() || currentCompIndex < 0) { + HILOG_ERROR("current comp index %{public}d invalid", currentCompIndex); + return; + } + + FormRequest currentComp& = formRequests[currentCompIndex]; + for (auto formRequest: formRequests) { + formRequests_.emplace_back(formRequest); + } + currentCompId_ = currentComp.compId; + + bool isVerified = currentComp.want.GetBoolParam(FORM_RENDER_STATE, false); + if (isVerified) { + HILOG_DEBUG("user verified, start recover renderer"); + InnerAddForm(currentComp); + return; + } + HILOG_INFO("user not verified, delay recover renderer"); + PreInitAddForm(currentComp); +} } // namespace Ace } // namespace OHOS From b0bb975279b6b50d264a2cf14cb418509d296985 Mon Sep 17 00:00:00 2001 From: s00800643 Date: Wed, 17 Jul 2024 15:58:16 +0800 Subject: [PATCH 010/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s00800643 Change-Id: If5694524555f63d96b46c2c3189cceb98dfe5bc9 --- .../inner_api/form_render/include/form_renderer_group.h | 2 +- .../inner_api/form_render/src/form_renderer_group.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/inner_api/form_render/include/form_renderer_group.h b/interfaces/inner_api/form_render/include/form_renderer_group.h index a4c64857f78..fd6e3dc5c44 100644 --- a/interfaces/inner_api/form_render/include/form_renderer_group.h +++ b/interfaces/inner_api/form_render/include/form_renderer_group.h @@ -82,7 +82,7 @@ public: const std::vector& GetAllRendererFormRequests() const; std::pair, std::string> GetOrderedAndCurrentCompIds() const; void RecycleForm(std::string& statusData) const; - void RecoverRenderer(const std::vector & formRequests, int currentCompIndex); + void RecoverRenderer(const std::vector& formRequests, size_t currentCompIndex); private: enum class FormRendererInitState { UNINITIALIZED, diff --git a/interfaces/inner_api/form_render/src/form_renderer_group.cpp b/interfaces/inner_api/form_render/src/form_renderer_group.cpp index 8ef7233328d..7ec9bf22747 100644 --- a/interfaces/inner_api/form_render/src/form_renderer_group.cpp +++ b/interfaces/inner_api/form_render/src/form_renderer_group.cpp @@ -257,14 +257,14 @@ void FormRendererGroup::RecycleForm(std::string& statusData) const formRenderer_->RecycleForm(statusData); } -void FormRendererGroup::RecoverRenderer(const std::vector & formRequests, int currentCompIndex) +void FormRendererGroup::RecoverRenderer(const std::vector& formRequests, size_t currentCompIndex) { if (currentCompIndex >= formRequests.size() || currentCompIndex < 0) { - HILOG_ERROR("current comp index %{public}d invalid", currentCompIndex); + HILOG_ERROR("current comp index %{public}zu invalid", currentCompIndex); return; } - FormRequest currentComp& = formRequests[currentCompIndex]; + const FormRequest ¤tComp = formRequests[currentCompIndex]; for (auto formRequest: formRequests) { formRequests_.emplace_back(formRequest); } From 910a2d658a808a8ec00e4b4c1389c7fd8daa7b6f Mon Sep 17 00:00:00 2001 From: s00800643 Date: Wed, 17 Jul 2024 16:47:21 +0800 Subject: [PATCH 011/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s00800643 Change-Id: I751f5962976a00779b4fff96ee30b320aaedb671 --- interfaces/inner_api/form_render/src/form_renderer_group.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/form_render/src/form_renderer_group.cpp b/interfaces/inner_api/form_render/src/form_renderer_group.cpp index 7ec9bf22747..1b834b73892 100644 --- a/interfaces/inner_api/form_render/src/form_renderer_group.cpp +++ b/interfaces/inner_api/form_render/src/form_renderer_group.cpp @@ -259,7 +259,7 @@ void FormRendererGroup::RecycleForm(std::string& statusData) const void FormRendererGroup::RecoverRenderer(const std::vector& formRequests, size_t currentCompIndex) { - if (currentCompIndex >= formRequests.size() || currentCompIndex < 0) { + if (currentCompIndex >= formRequests.size()) { HILOG_ERROR("current comp index %{public}zu invalid", currentCompIndex); return; } From a7da3f16afb7374aa29f72455dd4cb48c72bc3bf Mon Sep 17 00:00:00 2001 From: Zhang Jinyu Date: Wed, 17 Jul 2024 17:46:02 +0800 Subject: [PATCH 012/221] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dswiper=E7=AE=AD?= =?UTF-8?q?=E5=A4=B4RTL=E6=A8=A1=E5=BC=8F=E4=B8=8D=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhang Jinyu --- .../indicator_common/swiper_arrow_pattern.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_pattern.cpp b/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_pattern.cpp index fed75d23ad6..7e5d11253fd 100644 --- a/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_arrow_pattern.cpp @@ -371,21 +371,20 @@ void SwiperArrowPattern::UpdateArrowContent() CHECK_NULL_VOID(pipelineContext); auto swiperIndicatorTheme = pipelineContext->GetTheme(); CHECK_NULL_VOID(swiperIndicatorTheme); + bool isRtl = swiperLayoutProperty->GetNonAutoLayoutDirection() == TextDirection::RTL; if (V2::SWIPER_LEFT_ARROW_ETS_TAG == GetHost()->GetTag()) { if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) { - symbolLayoutProperty->UpdateSymbolSourceInfo( - SymbolSourceInfo(swiperIndicatorTheme->GetLeftSymbolId())); + symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo( + isRtl ? swiperIndicatorTheme->GetRightSymbolId() : swiperIndicatorTheme->GetLeftSymbolId())); } else { - symbolLayoutProperty->UpdateSymbolSourceInfo( - SymbolSourceInfo(swiperIndicatorTheme->GetUpSymbolId())); + symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(swiperIndicatorTheme->GetUpSymbolId())); } } else if (V2::SWIPER_RIGHT_ARROW_ETS_TAG == GetHost()->GetTag()) { if (swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL) == Axis::HORIZONTAL) { - symbolLayoutProperty->UpdateSymbolSourceInfo( - SymbolSourceInfo(swiperIndicatorTheme->GetRightSymbolId())); + symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo( + isRtl ? swiperIndicatorTheme->GetLeftSymbolId() : swiperIndicatorTheme->GetRightSymbolId())); } else { - symbolLayoutProperty->UpdateSymbolSourceInfo( - SymbolSourceInfo(swiperIndicatorTheme->GetDownSymbolId())); + symbolLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo(swiperIndicatorTheme->GetDownSymbolId())); } } symbolLayoutProperty->UpdateFontSize(swiperArrowLayoutProperty->GetArrowSizeValue()); From 39b7b6af82f7e098d7f6e7d321e699bfd78b67ff Mon Sep 17 00:00:00 2001 From: "xuqinfeng1@huawei.com" Date: Thu, 18 Jul 2024 10:07:55 +0800 Subject: [PATCH 013/221] =?UTF-8?q?progress=E7=BB=84=E4=BB=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E6=A0=87=E8=84=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuqinfeng1@huawei.com Change-Id: I5cee18a7baf4db59cedc6d5057892d035592fd4d --- .../core/components_ng/pattern/progress/progress_pattern.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/core/components_ng/pattern/progress/progress_pattern.cpp b/frameworks/core/components_ng/pattern/progress/progress_pattern.cpp index 567d9816495..1b54b7800a2 100644 --- a/frameworks/core/components_ng/pattern/progress/progress_pattern.cpp +++ b/frameworks/core/components_ng/pattern/progress/progress_pattern.cpp @@ -390,6 +390,7 @@ void ProgressPattern::FireBuilder() auto host = GetHost(); CHECK_NULL_VOID(host); if (!makeFunc_.has_value()) { + CHECK_NULL_VOID(contentModifierNode_); host->RemoveChildAndReturnIndex(contentModifierNode_); contentModifierNode_ = nullptr; host->GetRenderContext()->SetClipToFrame(true); From c19a37290e3a528680e5b22ad0ec1c724d57f9b0 Mon Sep 17 00:00:00 2001 From: s00800643 Date: Thu, 18 Jul 2024 14:23:44 +0800 Subject: [PATCH 014/221] =?UTF-8?q?=E6=B7=BB=E5=8A=A0tdd=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s00800643 Change-Id: I04c104ef6af11a2665cfa989afa3ef67338a1131 --- .../interfaces/form_render_group_test.cpp | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/test/unittest/interfaces/form_render_group_test.cpp b/test/unittest/interfaces/form_render_group_test.cpp index 3942c962766..911ec336ab7 100644 --- a/test/unittest/interfaces/form_render_group_test.cpp +++ b/test/unittest/interfaces/form_render_group_test.cpp @@ -491,4 +491,87 @@ HWTEST_F(FormRenderGroupTest, FormRenderGroupTest_021, TestSize.Level1) EXPECT_TRUE(flag); GTEST_LOG_(INFO) << "FormRenderGroupTest_021 end"; } + +/** + * @tc.name: FormRenderGroupTest_022 + * @tc.desc: Test GetOrderedAndCurrentCompIds() function. + * @tc.type: FUNC + */ +HWTEST_F(FormRenderGroupTest, FormRenderGroupTest_022, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FormRenderGroupTest_022 start"; + auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderGroupTest_022"); + ASSERT_TRUE(eventRunner); + auto eventHandler = std::make_shared(eventRunner); + auto group = FormRendererGroup::Create(nullptr, nullptr, eventHandler); + EXPECT_TRUE(group); + std::pair, std::string> compIdPair = group->GetOrderedAndCurrentCompIds(); + EXPECT_EQ(true, compIdPair.first.empty()); + EXPECT_EQ(true, compIdPair.second.empty()); + OHOS::AAFwk::Want want; + OHOS::AppExecFwk::FormJsInfo formJsInfo; + formJsInfo.formId = 1; + std::string compId1 = "comp1"; + want.SetStringParam(FORM_RENDERER_COMP_ID, compId1); + group->AddForm(want, formJsInfo); + formJsInfo.formId = 2; + std::string compId2 = "comp2"; + want.SetStringParam(FORM_RENDERER_COMP_ID, compId2); + group->AddForm(want, formJsInfo); + compIdPair = group->GetOrderedAndCurrentCompIds(); + EXPECT_EQ(2, compIdPair.first.size()); + EXPECT_EQ(compId1, compIdPair.first[0]); + EXPECT_EQ(compId2, compIdPair.first[1]); + EXPECT_EQ(compId2, compIdPair.second); + group->DeleteForm(compId2); + compIdPair = group->GetOrderedAndCurrentCompIds(); + EXPECT_EQ(1, compIdPair.first.size()); + EXPECT_EQ(compId1, compIdPair.second); + GTEST_LOG_(INFO) << "FormRenderGroupTest_022 end"; } + +/** + * @tc.name: FormRenderGroupTest_023 + * @tc.desc: Test RecoverRenderer() function. + * @tc.type: FUNC + */ +HWTEST_F(FormRenderGroupTest, FormRenderGroupTest_023, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "FormRenderGroupTest_023 start"; + auto eventRunner = OHOS::AppExecFwk::EventRunner::Create("FormRenderGroupTest_023"); + ASSERT_TRUE(eventRunner); + auto eventHandler = std::make_shared(eventRunner); + auto group = FormRendererGroup::Create(nullptr, nullptr, eventHandler); + EXPECT_TRUE(group); + OHOS::AAFwk::Want want; + OHOS::AppExecFwk::FormJsInfo formJsInfo; + formJsInfo.formId = 1; + std::string compId1 = "comp1"; + want.SetStringParam(FORM_RENDERER_COMP_ID, compId1); + group->AddForm(want, formJsInfo); + formJsInfo.formId = 2; + std::string compId2 = "comp2"; + want.SetStringParam(FORM_RENDERER_COMP_ID, compId2); + group->AddForm(want, formJsInfo); + std::pair, std::string> compIdPair = group->GetOrderedAndCurrentCompIds(); + group->DeleteForm(); + EXPECT_EQ(true, group->GetAllRendererFormRequests().empty()); + std::vector requests; + group->RecoverRenderer(requests, 0); + EXPECT_EQ(true, group->GetAllRendererFormRequests().empty()); + for (auto compId: compIdPair.first) { + FormRequest formRequest; + formRequest.compId = compId; + requests.emplace_back(formRequest); + } + group->RecoverRenderer(requests, requests.size()); + EXPECT_EQ(true, group->GetAllRendererFormRequests().empty()); + group->RecoverRenderer(requests, requests.size() - 1); + EXPECT_EQ(2, group->GetAllRendererFormRequests().size()); + compIdPair = group->GetOrderedAndCurrentCompIds(); + EXPECT_EQ(compId2, compIdPair.second); + GTEST_LOG_(INFO) << "FormRenderGroupTest_023 end"; +} +} + + From 6289cff1e771885dc2c7a124a4627d5822d5a665 Mon Sep 17 00:00:00 2001 From: chenyisen Date: Thu, 18 Jul 2024 14:29:54 +0800 Subject: [PATCH 015/221] =?UTF-8?q?dialog2=E4=B8=AA=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E5=9C=A8=E6=96=87=E6=9C=AC=E8=B6=85=E9=95=BF=E6=97=B6=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E9=9C=80=E6=94=B9=E4=B8=BA=E5=8F=B3=E8=BE=B9=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=9C=A8=E4=B8=8A=E5=B7=A6=E8=BE=B9=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E5=9C=A8=E4=B8=8B=EF=BC=8C=E6=9B=B4=E5=A4=9A=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=97=B6=E8=A7=84=E5=88=99=E4=B8=8D=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyisen --- advanced_ui_component/dialog/interfaces/dialog.js | 5 +++-- advanced_ui_component/dialog/source/dialog.ets | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/advanced_ui_component/dialog/interfaces/dialog.js b/advanced_ui_component/dialog/interfaces/dialog.js index c2f4153349c..a6d60e7d8d9 100644 --- a/advanced_ui_component/dialog/interfaces/dialog.js +++ b/advanced_ui_component/dialog/interfaces/dialog.js @@ -3622,7 +3622,8 @@ class CustomDialogContentComponent extends ViewPU { const item = _item; this.buildButtonWithDivider.bind(this)(index, parent ? parent : this); }; - this.forEachUpdateFunction(elmtId, this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), + this.forEachUpdateFunction(elmtId, this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? + this.buttons.reverse() : this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), forEachItemGenFunction, (item) => item.value.toString(), true, false); }, ForEach); ForEach.pop(); @@ -3958,7 +3959,7 @@ export class LoadingDialog extends ViewPU { fontSizeScale: this.__fontSizeScale, minContentHeight: this.__minContentHeight, }, undefined, elmtId, () => { - }, { page: 'library/src/main/ets/components/mainpage/dialog.ets', line: 1569 }); + }, { page: 'library/src/main/ets/components/mainpage/dialog.ets', line: 1570 }); ViewPU.create(componentCall); let paramsLambda = () => { return { diff --git a/advanced_ui_component/dialog/source/dialog.ets b/advanced_ui_component/dialog/source/dialog.ets index d973596aced..5f6cfb10f6c 100644 --- a/advanced_ui_component/dialog/source/dialog.ets +++ b/advanced_ui_component/dialog/source/dialog.ets @@ -1347,7 +1347,8 @@ struct CustomDialogContentComponent { buildVerticalAlignButtons(): void { if (this.buttons) { Column() { - ForEach(this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), (item: ButtonOptions, index: number) => { + ForEach(this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? this.buttons.reverse() : + this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), (item: ButtonOptions, index: number) => { this.buildButtonWithDivider(index); }, (item: ButtonOptions) => item.value.toString()); } From 948fda8b5f789ab226aeb9657bf426ff3cbf3876 Mon Sep 17 00:00:00 2001 From: s00800643 Date: Thu, 18 Jul 2024 14:40:26 +0800 Subject: [PATCH 016/221] =?UTF-8?q?=E6=B7=BB=E5=8A=A0tdd=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s00800643 Change-Id: Ic62781f285b0d3d0bfd1fe09f349d607dd2d6df0 --- test/unittest/interfaces/form_render_group_test.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/unittest/interfaces/form_render_group_test.cpp b/test/unittest/interfaces/form_render_group_test.cpp index 911ec336ab7..380b332598e 100644 --- a/test/unittest/interfaces/form_render_group_test.cpp +++ b/test/unittest/interfaces/form_render_group_test.cpp @@ -572,6 +572,4 @@ HWTEST_F(FormRenderGroupTest, FormRenderGroupTest_023, TestSize.Level1) EXPECT_EQ(compId2, compIdPair.second); GTEST_LOG_(INFO) << "FormRenderGroupTest_023 end"; } -} - - +} \ No newline at end of file From e2d0b47227e1c1cc4d8279cbf1f16557e2ae1897 Mon Sep 17 00:00:00 2001 From: s00800643 Date: Thu, 18 Jul 2024 15:33:15 +0800 Subject: [PATCH 017/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtdd=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s00800643 Change-Id: I05a72f1ac7b1dd9ce321020331e123f96d652b24 --- test/unittest/interfaces/form_render_group_test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/interfaces/form_render_group_test.cpp b/test/unittest/interfaces/form_render_group_test.cpp index 380b332598e..4fa98c01956 100644 --- a/test/unittest/interfaces/form_render_group_test.cpp +++ b/test/unittest/interfaces/form_render_group_test.cpp @@ -28,6 +28,7 @@ using namespace testing::ext; namespace OHOS::Ace { namespace { constexpr char FORM_RENDER_STATE[] = "ohos.extra.param.key.form_render_state"; +constexpr char FORM_RENDERER_COMP_ID[] = "ohos.extra.param.key.form_comp_id"; } // namespace class FormRenderGroupTest : public testing::Test { public: From 59a0b73c97c4aabeac088b725c6fd464b5632a2b Mon Sep 17 00:00:00 2001 From: tsj_2020 Date: Tue, 16 Jul 2024 15:35:44 +0800 Subject: [PATCH 018/221] fix interactive animation error Signed-off-by: tsj_2020 Change-Id: I0e1bf37debd09339ed73d87740b19dccc3ca5e0c --- .../pattern/navigation/navigation_pattern.cpp | 2 +- .../navigation/navigation_transition_proxy.h | 26 +++++++++++++++++-- .../render/adapter/rosen_animation_utils.cpp | 8 +++--- .../components_ng/render/animation_utils.h | 2 +- .../mock/core/render/mock_animation_utils.cpp | 7 +++-- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp b/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp index 87c504c6900..6b255b0e6f6 100644 --- a/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp @@ -1700,7 +1700,7 @@ bool NavigationPattern::TriggerCustomAnimation(const RefPtrSetInteractiveAnimation(AnimationUtils::CreateInteractiveAnimation( - addAnimationCallback, finishCallback)); + addAnimationCallback, finishCallback), finishCallback); isFinishInteractiveAnimation_ = false; proxy->StartAnimation(); } else { diff --git a/frameworks/core/components_ng/pattern/navigation/navigation_transition_proxy.h b/frameworks/core/components_ng/pattern/navigation/navigation_transition_proxy.h index 2618015a388..d82a8d39885 100644 --- a/frameworks/core/components_ng/pattern/navigation/navigation_transition_proxy.h +++ b/frameworks/core/components_ng/pattern/navigation/navigation_transition_proxy.h @@ -142,9 +142,12 @@ public: return isSuccess_; } - void SetInteractiveAnimation(std::shared_ptr interactiveAnimation) + void SetInteractiveAnimation( + std::shared_ptr interactiveAnimation, + const std::function& finishCallback) { interactiveAnimation_ = interactiveAnimation; + interactiveFinishCallback_ = finishCallback; } void StartAnimation() @@ -152,7 +155,10 @@ public: if (!interactiveAnimation_) { return; } - AnimationUtils::StartInteractiveAnimation(interactiveAnimation_); + // if error code is 0, start interactive success + int32_t errorCode = AnimationUtils::StartInteractiveAnimation(interactiveAnimation_); + TAG_LOGI(AceLogTag::ACE_NAVIGATION, "update start interactive animation code is %{public}d", errorCode); + isStartAnimation_ = errorCode == 0; } void UpdateTransition(float progress) @@ -174,6 +180,13 @@ public: } hasFinished_ = true; isSuccess_ = true; + if (!isStartAnimation_) { + interactiveFinishCallback_(); + if (endCallback_) { + endCallback_(true); + } + return; + } AnimationUtils::ContinueInteractiveAnimation(interactiveAnimation_); } @@ -185,6 +198,13 @@ public: } hasFinished_ = true; isSuccess_ = false; + if (!isStartAnimation_) { + interactiveFinishCallback_(); + if (endCallback_) { + endCallback_(false); + } + return; + } AnimationUtils::ReverseInteractiveAnimation(interactiveAnimation_); } @@ -194,11 +214,13 @@ private: std::function finishCallback_; // finish transition callback to continue animation std::function cancelAnimation_; // cancel transition callback to reverse animation std::function endCallback_; + std::function interactiveFinishCallback_; NavigationOperation operation_; std::shared_ptr interactiveAnimation_; bool hasFinished_ = false; // current transition is finish or not bool isSuccess_ = true; // set current custom transition is start success or not bool interactive_ = false; // set current interactive animation + bool isStartAnimation_ = false; }; struct NavigationTransition { diff --git a/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp b/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp index 07efde34857..ac20f9e9f68 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp @@ -231,12 +231,12 @@ std::shared_ptr AnimationUtils::CreateInte return interactiveAnimation; } -void AnimationUtils::StartInteractiveAnimation( +int32_t AnimationUtils::StartInteractiveAnimation( const std::shared_ptr& interactiveAnimation) { - CHECK_NULL_VOID(interactiveAnimation); - CHECK_NULL_VOID(interactiveAnimation->interactiveAnimation_); - interactiveAnimation->interactiveAnimation_->StartAnimation(); + CHECK_NULL_RETURN(interactiveAnimation, -1); + CHECK_NULL_RETURN(interactiveAnimation->interactiveAnimation_, -1); + return interactiveAnimation->interactiveAnimation_->StartAnimation(); } void AnimationUtils::ContinueInteractiveAnimation( diff --git a/frameworks/core/components_ng/render/animation_utils.h b/frameworks/core/components_ng/render/animation_utils.h index 7d8a872b5b9..caf7d7abf7a 100644 --- a/frameworks/core/components_ng/render/animation_utils.h +++ b/frameworks/core/components_ng/render/animation_utils.h @@ -73,7 +73,7 @@ public: static void ContinueInteractiveAnimation( const std::shared_ptr& interactiveAnimation); - static void StartInteractiveAnimation( + static int32_t StartInteractiveAnimation( const std::shared_ptr& interactiveAnimation); static void ReverseInteractiveAnimation( diff --git a/test/mock/core/render/mock_animation_utils.cpp b/test/mock/core/render/mock_animation_utils.cpp index dbdb0a6a103..5e1281267f0 100644 --- a/test/mock/core/render/mock_animation_utils.cpp +++ b/test/mock/core/render/mock_animation_utils.cpp @@ -123,8 +123,11 @@ void AnimationUtils::ContinueInteractiveAnimation( interactiveAnimation->finishCallback_(); } -void AnimationUtils::StartInteractiveAnimation( - const std::shared_ptr& interactiveAnimation) {} +int32_t AnimationUtils::StartInteractiveAnimation( + const std::shared_ptr& interactiveAnimation) +{ + return 0; +} void AnimationUtils::ReverseInteractiveAnimation( const std::shared_ptr& interactiveAnimation) From c55b12bcfdf49a8823773c39120b47c481fd7a16 Mon Sep 17 00:00:00 2001 From: s00800643 Date: Thu, 18 Jul 2024 17:21:24 +0800 Subject: [PATCH 019/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dtdd=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: s00800643 Change-Id: If0c386358f2ff33f576f184e93c25e852db6a5f3 --- test/unittest/interfaces/form_render_group_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unittest/interfaces/form_render_group_test.cpp b/test/unittest/interfaces/form_render_group_test.cpp index 4fa98c01956..ebd1dc3260e 100644 --- a/test/unittest/interfaces/form_render_group_test.cpp +++ b/test/unittest/interfaces/form_render_group_test.cpp @@ -513,11 +513,11 @@ HWTEST_F(FormRenderGroupTest, FormRenderGroupTest_022, TestSize.Level1) OHOS::AppExecFwk::FormJsInfo formJsInfo; formJsInfo.formId = 1; std::string compId1 = "comp1"; - want.SetStringParam(FORM_RENDERER_COMP_ID, compId1); + want.SetParam(FORM_RENDERER_COMP_ID, compId1); group->AddForm(want, formJsInfo); formJsInfo.formId = 2; std::string compId2 = "comp2"; - want.SetStringParam(FORM_RENDERER_COMP_ID, compId2); + want.SetParam(FORM_RENDERER_COMP_ID, compId2); group->AddForm(want, formJsInfo); compIdPair = group->GetOrderedAndCurrentCompIds(); EXPECT_EQ(2, compIdPair.first.size()); @@ -548,11 +548,11 @@ HWTEST_F(FormRenderGroupTest, FormRenderGroupTest_023, TestSize.Level1) OHOS::AppExecFwk::FormJsInfo formJsInfo; formJsInfo.formId = 1; std::string compId1 = "comp1"; - want.SetStringParam(FORM_RENDERER_COMP_ID, compId1); + want.SetParam(FORM_RENDERER_COMP_ID, compId1); group->AddForm(want, formJsInfo); formJsInfo.formId = 2; std::string compId2 = "comp2"; - want.SetStringParam(FORM_RENDERER_COMP_ID, compId2); + want.SetParam(FORM_RENDERER_COMP_ID, compId2); group->AddForm(want, formJsInfo); std::pair, std::string> compIdPair = group->GetOrderedAndCurrentCompIds(); group->DeleteForm(); From a30eda323556ba50a5517684955786077c8773cd Mon Sep 17 00:00:00 2001 From: Zhang Jinyu Date: Thu, 18 Jul 2024 18:18:32 +0800 Subject: [PATCH 020/221] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=8F=9C=E5=8D=95=E9=87=8D=E5=BD=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhang Jinyu Change-Id: I697d9f2fb364fc6ea4a80ccbd642aad163f9b005 --- .../pattern/select_overlay/select_overlay_node.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/frameworks/core/components_ng/pattern/select_overlay/select_overlay_node.cpp b/frameworks/core/components_ng/pattern/select_overlay/select_overlay_node.cpp index 6087b8d065e..002f1fa7d73 100644 --- a/frameworks/core/components_ng/pattern/select_overlay/select_overlay_node.cpp +++ b/frameworks/core/components_ng/pattern/select_overlay/select_overlay_node.cpp @@ -814,12 +814,6 @@ void SelectOverlayNode::CreateCustomSelectOverlay(const std::shared_ptrGetLayoutProperty()->UpdateVisibility(VisibleType::GONE); selectMenuStatus_ = FrameNodeStatus::GONE; } - auto pipeline = PipelineContext::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto shadowTheme = pipeline->GetTheme(); - CHECK_NULL_VOID(shadowTheme); - auto colorMode = SystemProperties::GetColorMode(); - selectMenu_->GetRenderContext()->UpdateBackShadow(shadowTheme->GetShadow(ShadowStyle::OuterDefaultMD, colorMode)); selectMenu_->MarkModifyDone(); } From f5ffe32031cc5be6e1594752ae8bf73946004df8 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Thu, 18 Jul 2024 19:12:51 +0800 Subject: [PATCH 021/221] =?UTF-8?q?tdd=E8=A6=86=E7=9B=96=E7=8E=87=E6=8F=90?= =?UTF-8?q?=E5=8D=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../rich_editor_keyboard_shortcut_test_ng.cpp | 13 ++ .../rich_editor_overlay_test_ng.cpp | 138 ++++++++++++++++++ .../rich_editor_pattern_test_ng.cpp | 67 +++++++++ .../rich_editor_styled_string_test_ng.cpp | 30 ++++ 4 files changed, 248 insertions(+) diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp index 0608095d9ad..0a4b26dc47a 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp @@ -1343,4 +1343,17 @@ HWTEST_F(RichEditorKeyboardShortcutTestNg, HandleTouchUp001, TestSize.Level1) EXPECT_FALSE(richEditorPattern->isTouchCaret_); EXPECT_FALSE(richEditorPattern->isMoveCaretAnywhere_); } + +/** + * @tc.name: SetCustomKeyboard001 + * @tc.desc: test SetCustomKeyboard + * @tc.type: FUNC + */ +HWTEST_F(RichEditorKeyboardShortcutTestNg, SetCustomKeyboard001, TestSize.Level1) +{ + RichEditorModelNG richEditorModel; + richEditorModel.Create(); + auto func = []() {}; + richEditorModel.SetCustomKeyboard(func, true); +} } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp index 153f4caa6f2..ccbad75f1d2 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp @@ -24,6 +24,8 @@ int32_t testAboutToIMEInput = 0; int32_t testOnIMEInputComplete = 0; int32_t testAboutToDelete = 0; int32_t testOnDeleteComplete = 0; +int32_t testNumber0 = 0; +int32_t testNumber5 = 5; const std::string TEST_IMAGE_SOURCE = "src/image.png"; } // namespace @@ -1435,4 +1437,140 @@ HWTEST_F(RichEditorOverlayTestNg, HandleLevel002, TestSize.Level1) richEditorNode_->ProcessFrameNodeChangeFlag(); EXPECT_EQ(richEditorPattern->selectOverlay_->handleLevelMode_, HandleLevelMode::OVERLAY); } + +/** + * @tc.name: SetCaretWidth001 + * @tc.desc: test SetCaretWidth + * @tc.type: FUNC + */ +HWTEST_F(RichEditorOverlayTestNg, SetCaretWidth001, TestSize.Level1) +{ + ASSERT_NE(richEditorNode_, nullptr); + auto richEditorPattern = richEditorNode_->GetPattern(); + auto overlayMod = richEditorNode_->GetOverlayNode(); + auto richEditorOverlay = AceType::DynamicCast(richEditorPattern->overlayMod_); + richEditorOverlay->SetCaretWidth(-1); +} + +/** + * @tc.name: PaintPreviewTextDecoration001 + * @tc.desc: test PaintPreviewTextDecoration + * @tc.type: FUNC + */ +HWTEST_F(RichEditorOverlayTestNg, PaintPreviewTextDecoration001, TestSize.Level1) +{ + ASSERT_NE(richEditorNode_, nullptr); + auto richEditorPattern = richEditorNode_->GetPattern(); + auto overlayMod = richEditorNode_->GetOverlayNode(); + auto richEditorOverlay = AceType::DynamicCast(richEditorPattern->overlayMod_); + richEditorOverlay->SetPreviewTextStyle(PreviewTextStyle::NORMAL); + Testing::MockCanvas canvas; + DrawingContext context { canvas, 100, 100 }; + richEditorOverlay->PaintPreviewTextDecoration(context); +} + +/** + * @tc.name: OnMenuItemAction004 + * @tc.desc: test OnMenuItemAction + * @tc.type: FUNC + */ +HWTEST_F(RichEditorOverlayTestNg, OnMenuItemAction004, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + EXPECT_EQ(richEditorPattern->OnBackPressed(), false); + auto offsetF = OffsetF(5.0f, 30.0f); + RectF rect(testNumber0, testNumber0, testNumber5, testNumber5); + richEditorPattern->CreateHandles(); + richEditorPattern->textSelector_.Update(0, testNumber5); + richEditorPattern->selectOverlay_->OnMenuItemAction(OptionMenuActionId::DISAPPEAR, OptionMenuType::MOUSE_MENU); +} + +/** + * @tc.name: OnMenuItemAction005 + * @tc.desc: test OnMenuItemAction + * @tc.type: FUNC + */ +HWTEST_F(RichEditorOverlayTestNg, OnMenuItemAction005, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + EXPECT_EQ(richEditorPattern->OnBackPressed(), false); + auto offsetF = OffsetF(5.0f, 30.0f); + RectF rect(testNumber0, testNumber0, testNumber5, testNumber5); + richEditorPattern->CreateHandles(); + richEditorPattern->textSelector_.Update(0, testNumber5); + richEditorPattern->selectOverlay_->OnMenuItemAction(OptionMenuActionId::APPEAR, OptionMenuType::MOUSE_MENU); +} + +/** + * @tc.name: OnMenuItemAction006 + * @tc.desc: test OnMenuItemAction + * @tc.type: FUNC + */ +HWTEST_F(RichEditorOverlayTestNg, OnMenuItemAction006, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + EXPECT_EQ(richEditorPattern->OnBackPressed(), false); + auto offsetF = OffsetF(5.0f, 30.0f); + RectF rect(testNumber0, testNumber0, testNumber5, testNumber5); + richEditorPattern->CreateHandles(); + richEditorPattern->textSelector_.Update(0, testNumber5); + richEditorPattern->selectOverlay_->OnMenuItemAction(OptionMenuActionId::CAMERA_INPUT, OptionMenuType::MOUSE_MENU); +} + +/** + * @tc.name: OnCloseOverlay001 + * @tc.desc: test OnCloseOverlay + * @tc.type: FUNC + */ +HWTEST_F(RichEditorOverlayTestNg, OnCloseOverlay001, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + RefPtr info = nullptr; + info = AceType::MakeRefPtr(); + ASSERT_NE(richEditorPattern, nullptr); + EXPECT_EQ(richEditorPattern->OnBackPressed(), false); + auto offsetF = OffsetF(5.0f, 30.0f); + RectF rect(testNumber0, testNumber0, testNumber5, testNumber5); + richEditorPattern->CreateHandles(); + richEditorPattern->textSelector_.Update(0, testNumber5); + richEditorPattern->selectOverlay_->OnCloseOverlay( + OptionMenuType::MOUSE_MENU, CloseReason::CLOSE_REASON_BACK_PRESSED, info); +} + +/** + * @tc.name: GetGlyphPositionAtCoordinate001 + * @tc.desc: Test GetGlyphPositionAtCoordinate. + * @tc.type: FUNC + */ +HWTEST_F(RichEditorOverlayTestNg, GetGlyphPositionAtCoordinate001, TestSize.Level1) +{ + auto offset = Offset(50.0, -80.0); + auto paragraph = MockParagraph::GetOrCreateMockParagraph(); + ASSERT_NE(paragraph, nullptr); + ASSERT_NE(richEditorNode_, nullptr); + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + richEditorPattern->paragraphs_.GetGlyphPositionAtCoordinate(offset); +} + +/** + * @tc.name: IsSelectLineHeadAndUseLeadingMargin001 + * @tc.desc: Test IsSelectLineHeadAndUseLeadingMargin. + * @tc.type: FUNC + */ +HWTEST_F(RichEditorOverlayTestNg, IsSelectLineHeadAndUseLeadingMargin001, TestSize.Level1) +{ + auto paragraph = MockParagraph::GetOrCreateMockParagraph(); + ASSERT_NE(paragraph, nullptr); + ASSERT_NE(richEditorNode_, nullptr); + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + richEditorPattern->paragraphs_.AddParagraph({ .paragraph = paragraph, .start = 0, .end = 6 }); + richEditorPattern->paragraphs_.AddParagraph({ .paragraph = paragraph, .start = 0, .end = 10 }); + bool ret =richEditorPattern->paragraphs_.IsSelectLineHeadAndUseLeadingMargin(0); + EXPECT_EQ(ret, false); +} } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_pattern_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_pattern_test_ng.cpp index 0df052a6282..1164d70b977 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_pattern_test_ng.cpp @@ -1896,4 +1896,71 @@ HWTEST_F(RichEditorPatternTestNg, IsLineSeparatorInLast001, TestSize.Level1) spanItem->content = "nihao\n"; EXPECT_TRUE(richEditorPattern->IsLineSeparatorInLast(spanNode)); } + +/** + * @tc.name: GetRichEditorController001 + * @tc.desc: test GetRichEditorController + * @tc.type: FUNC + */ +HWTEST_F(RichEditorPatternTestNg, GetRichEditorController001, TestSize.Level1) +{ + RichEditorModelNG richEditorModel; + richEditorModel.Create(); + auto controller = richEditorModel.GetRichEditorController(); + ASSERT_NE(controller, nullptr); +} + +/** + * @tc.name: BindSelectionMenu001 + * @tc.desc: test BindSelectionMenu + * @tc.type: FUNC + */ +HWTEST_F(RichEditorPatternTestNg, BindSelectionMenu001, TestSize.Level1) +{ + RichEditorModelNG richEditorModel; + richEditorModel.Create(); + std::function buildFunc = []() { + callBack1 = 1; + return; + }; + TextSpanType textSpanType = TextSpanType::TEXT; + TextResponseType textResponseType = TextResponseType::LONG_PRESS; + SelectMenuParam menuParam { .onAppear = [](int32_t, int32_t) {}, .onDisappear = []() {} }; + richEditorModel.BindSelectionMenu(textSpanType, textResponseType, buildFunc, menuParam); +} + +/** + * @tc.name: OnHandleMove001 + * @tc.desc: test OnHandleMove + * @tc.type: FUNC + */ +HWTEST_F(RichEditorPatternTestNg, OnHandleMove001, TestSize.Level1) +{ + ASSERT_NE(richEditorNode_, nullptr); + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + EXPECT_EQ(richEditorPattern->OnBackPressed(), false); + RectF rect(testNumber0, testNumber0, testNumber5, testNumber5); + richEditorPattern->CreateHandles(); + richEditorPattern->textSelector_.Update(0, testNumber5); + richEditorPattern->selectOverlay_->OnHandleMove(rect, true); +} + +/** + * @tc.name: UpdateSelectorOnHandleMove001 + * @tc.desc: test UpdateSelectorOnHandleMove + * @tc.type: FUNC + */ +HWTEST_F(RichEditorPatternTestNg, UpdateSelectorOnHandleMove001, TestSize.Level1) +{ + ASSERT_NE(richEditorNode_, nullptr); + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + EXPECT_EQ(richEditorPattern->OnBackPressed(), false); + auto offsetF = OffsetF(5.0f, 30.0f); + RectF rect(testNumber0, testNumber0, testNumber5, testNumber5); + richEditorPattern->CreateHandles(); + richEditorPattern->textSelector_.Update(0, testNumber5); + richEditorPattern->selectOverlay_->UpdateSelectorOnHandleMove(offsetF, true); +} } // namespace \ No newline at end of file diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_styled_string_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_styled_string_test_ng.cpp index dbbbf792964..cef73d71cdc 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_styled_string_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_styled_string_test_ng.cpp @@ -891,4 +891,34 @@ HWTEST_F(RichEditorStyledStringTestNg, FromStyledString001, TestSize.Level1) auto info = richEditorPattern->FromStyledString(mutableStr); EXPECT_EQ(info.selection_.resultObjects.size(), mutableStr->GetSpanItems().size()); } + + +/** + * @tc.name: CopySpanStyle001 + * @tc.desc: test CopySpanStyle + * @tc.type: FUNC + */ +HWTEST_F(RichEditorStyledStringTestNg, CopySpanStyle001, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + auto layoutAlgorithm = AceType::DynamicCast(richEditorPattern->CreateLayoutAlgorithm()); + ASSERT_NE(richEditorPattern, nullptr); + RefPtr source = AceType::MakeRefPtr(); + source->textLineStyle->UpdateTextAlign(TextAlign::CENTER); + source->textLineStyle->UpdateMaxLines(1); + layoutAlgorithm->CopySpanStyle(source, AceType::MakeRefPtr()); +} + +/** + * @tc.name: CopySpanStyle002 + * @tc.desc: test CopySpanStyle + * @tc.type: FUNC + */ +HWTEST_F(RichEditorStyledStringTestNg, CopySpanStyle002, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + auto layoutAlgorithm = AceType::DynamicCast(richEditorPattern->CreateLayoutAlgorithm()); + ASSERT_NE(richEditorPattern, nullptr); + layoutAlgorithm->CopySpanStyle(AceType::MakeRefPtr(), AceType::MakeRefPtr()); +} } // namespace OHOS::Ace::NG From 1b8e416e03a42ae5b54d96bb971022f54328519f Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Thu, 18 Jul 2024 19:26:39 +0800 Subject: [PATCH 022/221] =?UTF-8?q?tdd=E8=A6=86=E7=9B=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp index ccbad75f1d2..124fd4427b0 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp @@ -1568,8 +1568,6 @@ HWTEST_F(RichEditorOverlayTestNg, IsSelectLineHeadAndUseLeadingMargin001, TestSi ASSERT_NE(richEditorNode_, nullptr); auto richEditorPattern = richEditorNode_->GetPattern(); ASSERT_NE(richEditorPattern, nullptr); - richEditorPattern->paragraphs_.AddParagraph({ .paragraph = paragraph, .start = 0, .end = 6 }); - richEditorPattern->paragraphs_.AddParagraph({ .paragraph = paragraph, .start = 0, .end = 10 }); bool ret =richEditorPattern->paragraphs_.IsSelectLineHeadAndUseLeadingMargin(0); EXPECT_EQ(ret, false); } From 877a9e749eb2cc53b0f46a5da71e35a967eeb847 Mon Sep 17 00:00:00 2001 From: wujinhui Date: Wed, 17 Jul 2024 06:58:18 +0000 Subject: [PATCH 023/221] animation add instanceId Signed-off-by: wujinhui --- .../components_ng/render/adapter/rosen_animation_utils.cpp | 3 ++- test/mock/core/common/mock_container.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp b/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp index 07efde34857..bbc52e7126f 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_animation_utils.cpp @@ -51,6 +51,7 @@ Rosen::RSAnimationTimingProtocol OptionToTimingProtocol(const AnimationOption& o if (rateRange) { timingProtocol.SetFrameRateRange({ rateRange->min_, rateRange->max_, rateRange->preferred_ }); } + timingProtocol.SetInstanceId(Container::CurrentIdSafelyWithCheck()); return timingProtocol; } std::function GetWrappedCallback(const std::function& callback) @@ -58,7 +59,7 @@ std::function GetWrappedCallback(const std::function& callback) if (!callback) { return nullptr; } - auto wrappedOnFinish = [onFinish = callback, instanceId = Container::CurrentId()]() { + auto wrappedOnFinish = [onFinish = callback, instanceId = Container::CurrentIdSafelyWithCheck()]() { ContainerScope scope(instanceId); auto taskExecutor = Container::CurrentTaskExecutor(); CHECK_NULL_VOID(taskExecutor); diff --git a/test/mock/core/common/mock_container.cpp b/test/mock/core/common/mock_container.cpp index b8739ceb566..f0ab608496e 100755 --- a/test/mock/core/common/mock_container.cpp +++ b/test/mock/core/common/mock_container.cpp @@ -45,6 +45,11 @@ int32_t Container::CurrentIdSafely() return g_id; } +int32_t Container::CurrentIdSafelyWithCheck() +{ + return g_id; +} + RefPtr Container::GetActive() { RefPtr activeContainer; From 1eef55be456393c45881a679a23da0da8849ebef Mon Sep 17 00:00:00 2001 From: jiangtao Date: Fri, 19 Jul 2024 07:00:34 +0800 Subject: [PATCH 024/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I0fa4ce76754af44505c977d65548e365af77bbb5 Signed-off-by: jiangtao --- interfaces/native/native_node.h | 2 +- interfaces/native/node/node_adapter_impl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/native/native_node.h b/interfaces/native/native_node.h index 0ecf4f8b4fb..79e775004c3 100644 --- a/interfaces/native/native_node.h +++ b/interfaces/native/native_node.h @@ -6298,7 +6298,7 @@ typedef enum { * * @since 12 */ -ArkUI_NodeAdapterHandle OH_ArkUI_NodeAdapter_Create(); +ArkUI_NodeAdapterHandle OH_ArkUI_NodeAdapter_Create(void); /** * @brief Destroys a component adapter. diff --git a/interfaces/native/node/node_adapter_impl.cpp b/interfaces/native/node/node_adapter_impl.cpp index 79517a283b5..c35a2a6da48 100644 --- a/interfaces/native/node/node_adapter_impl.cpp +++ b/interfaces/native/node/node_adapter_impl.cpp @@ -27,7 +27,7 @@ extern "C" { #endif -ArkUI_NodeAdapterHandle OH_ArkUI_NodeAdapter_Create() +ArkUI_NodeAdapterHandle OH_ArkUI_NodeAdapter_Create(void) { auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl(); CHECK_NULL_RETURN(fullImpl, nullptr); From 6cc0c9c2fadb84d9bff172b1eb7aa09f12a6f5d6 Mon Sep 17 00:00:00 2001 From: cuijiawei2022 Date: Fri, 19 Jul 2024 09:39:13 +0800 Subject: [PATCH 025/221] =?UTF-8?q?UEC=E5=AE=BF=E4=B8=BB=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E8=8E=B7=E7=84=A6=E6=97=B6UEC=E6=89=8D=E8=83=BD=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=8E=B7=E7=84=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuijiawei2022 --- .../pattern/ui_extension/ui_extension_pattern.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.cpp b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.cpp index a688cf22bb6..f6044a0ddd5 100644 --- a/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.cpp +++ b/frameworks/core/components_ng/pattern/ui_extension/ui_extension_pattern.cpp @@ -665,7 +665,9 @@ void UIExtensionPattern::HandleTouchEvent(const TouchEventInfo& info) AceExtraInputData::InsertInterpolatePoints(info); auto focusHub = host->GetFocusHub(); CHECK_NULL_VOID(focusHub); - focusHub->RequestFocusImmediately(); + if (pipeline->IsWindowFocused()) { + focusHub->RequestFocusImmediately(); + } DispatchPointerEvent(pointerEvent); } From 48fd14585c3166634729452a1bb40253998d9964 Mon Sep 17 00:00:00 2001 From: liyongzhuang Date: Fri, 19 Jul 2024 11:13:30 +0800 Subject: [PATCH 026/221] =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyongzhuang --- frameworks/core/components/web/resource/web_delegate.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/frameworks/core/components/web/resource/web_delegate.cpp b/frameworks/core/components/web/resource/web_delegate.cpp index 15b757c4abd..a645d4afeeb 100644 --- a/frameworks/core/components/web/resource/web_delegate.cpp +++ b/frameworks/core/components/web/resource/web_delegate.cpp @@ -7080,8 +7080,6 @@ NG::WebInfoType WebDelegate::GetWebInfoType() void WebDelegate::OnAdsBlocked(const std::string& url, const std::vector& adsBlocked) { - TAG_LOGI(AceLogTag::ACE_WEB, "OnAdsBlocked %{public}s", url.c_str()); - auto context = context_.Upgrade(); CHECK_NULL_VOID(context); context->GetTaskExecutor()->PostTask( From ff03f0e01d5115198c2d0c2927f2d60a8923cdc9 Mon Sep 17 00:00:00 2001 From: luoying_ace_admin Date: Fri, 19 Jul 2024 06:17:26 +0000 Subject: [PATCH 027/221] bugfix Signed-off-by: luoying_ace_admin Change-Id: Ib4ed464e90d0f95fd56e55afa8332ce8e647b56d --- .../declarative_frontend/frontend_delegate_declarative.cpp | 4 ++++ .../ng/frontend_delegate_declarative_ng.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp b/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp index 73243598a7d..f8a0bdf2146 100644 --- a/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp +++ b/frameworks/bridge/declarative_frontend/frontend_delegate_declarative.cpp @@ -1673,6 +1673,7 @@ void FrontendDelegateDeclarative::ShowDialog(const std::string& title, const std { TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter"); DialogProperties dialogProperties = { + .type = DialogType::ALERT_DIALOG, .title = title, .content = message, .autoCancel = autoCancel, @@ -1687,6 +1688,7 @@ void FrontendDelegateDeclarative::ShowDialog(const std::string& title, const std { TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter with status changed"); DialogProperties dialogProperties = { + .type = DialogType::ALERT_DIALOG, .title = title, .content = message, .autoCancel = autoCancel, @@ -1701,6 +1703,7 @@ void FrontendDelegateDeclarative::ShowDialog(const PromptDialogAttr& dialogAttr, { TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter with attr"); DialogProperties dialogProperties = { + .type = DialogType::ALERT_DIALOG, .title = dialogAttr.title, .content = dialogAttr.message, .autoCancel = dialogAttr.autoCancel, @@ -1741,6 +1744,7 @@ void FrontendDelegateDeclarative::ShowDialog(const PromptDialogAttr& dialogAttr, { TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter with attr for status changed"); DialogProperties dialogProperties = { + .type = DialogType::ALERT_DIALOG, .title = dialogAttr.title, .content = dialogAttr.message, .autoCancel = dialogAttr.autoCancel, diff --git a/frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.cpp b/frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.cpp index 7f92146ef2c..90c75705578 100644 --- a/frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.cpp +++ b/frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.cpp @@ -642,6 +642,7 @@ void FrontendDelegateDeclarativeNG::ShowDialog(const std::string& title, const s { TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter"); DialogProperties dialogProperties = { + .type = DialogType::ALERT_DIALOG, .title = title, .content = message, .autoCancel = autoCancel, @@ -656,6 +657,7 @@ void FrontendDelegateDeclarativeNG::ShowDialog(const std::string& title, const s { TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter"); DialogProperties dialogProperties = { + .type = DialogType::ALERT_DIALOG, .title = title, .content = message, .autoCancel = autoCancel, @@ -671,6 +673,7 @@ void FrontendDelegateDeclarativeNG::ShowDialog(const PromptDialogAttr& dialogAtt { TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter"); DialogProperties dialogProperties = { + .type = DialogType::ALERT_DIALOG, .title = dialogAttr.title, .content = dialogAttr.message, .autoCancel = dialogAttr.autoCancel, @@ -703,6 +706,7 @@ void FrontendDelegateDeclarativeNG::ShowDialog(const PromptDialogAttr& dialogAtt { TAG_LOGD(AceLogTag::ACE_OVERLAY, "show dialog enter"); DialogProperties dialogProperties = { + .type = DialogType::ALERT_DIALOG, .title = dialogAttr.title, .content = dialogAttr.message, .autoCancel = dialogAttr.autoCancel, From 3ee31c1eb1fceb29745b23a2aa9ce5bf03c91de7 Mon Sep 17 00:00:00 2001 From: jianfengtony Date: Fri, 19 Jul 2024 14:18:26 +0800 Subject: [PATCH 028/221] fix enum of Direction Redefined in C++ side, it should by only defined in jsEnumStyle.js Signed-off-by: jianfengtony Change-Id: I20723258e4ef01cc8284788c1fa99dad32f79a6c --- .../declarative_frontend/engine/jsi/jsi_view_register.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp index f5d528cb36a..84c3c97bb31 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.cpp @@ -1626,7 +1626,12 @@ void JsRegisterViews(BindingTarget globalObj, void* nativeEngine) globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "MainAxisAlign"), *mainAxisAlign); globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "CrossAxisAlign"), *crossAxisAlign); - globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Direction"), *direction); + + auto container = Container::Current(); + if (container == nullptr || !container->IsDynamicRender()) { + globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Direction"), *direction); + } + globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "StackFit"), *stackFit); globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Align"), *alignment); globalObj->Set(vm, panda::StringRef::NewFromUtf8(vm, "Overflow"), *overflow); From c8d2ea41dbec7a0c5a6e33fca2d09f917a5eeb6a Mon Sep 17 00:00:00 2001 From: lixingchi1 Date: Fri, 19 Jul 2024 14:34:29 +0800 Subject: [PATCH 029/221] fix the ondatasetchange changemap is empty Signed-off-by: lixingchi1 --- .../syntax/lazy_for_each_builder.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/frameworks/core/components_ng/syntax/lazy_for_each_builder.cpp b/frameworks/core/components_ng/syntax/lazy_for_each_builder.cpp index 2f869d1629f..19e55a694db 100644 --- a/frameworks/core/components_ng/syntax/lazy_for_each_builder.cpp +++ b/frameworks/core/components_ng/syntax/lazy_for_each_builder.cpp @@ -315,10 +315,8 @@ namespace OHOS::Ace::NG { decltype(cachedItems_) cachedTemp(std::move(cachedItems_)); std::map indexChangedMap; CollectIndexChangedCount(indexChangedMap); - if (!indexChangedMap.empty()) { - RepairDatasetItems(cachedTemp, cachedItems_, indexChangedMap); - RepairDatasetItems(expiringTemp, expiringTempItem_, indexChangedMap); - } + RepairDatasetItems(cachedTemp, cachedItems_, indexChangedMap); + RepairDatasetItems(expiringTemp, expiringTempItem_, indexChangedMap); for (auto& [index, node] : expiringTempItem_) { expiringItem_.emplace(node.first, LazyForEachCacheChild(index, node.second)); } @@ -333,9 +331,11 @@ namespace OHOS::Ace::NG { for (auto& [index, child] : cachedTemp) { auto iter = indexChangedMap.find(index); if (iter == indexChangedMap.end()) { - iter--; - if (iter->first < index) { - changedIndex = iter->second; + if (!indexChangedMap.empty()) { + iter--; + if (iter->first < index) { + changedIndex = iter->second; + } } } else { changedIndex = iter->second; @@ -344,7 +344,9 @@ namespace OHOS::Ace::NG { expiringTempItem_.try_emplace(index + changedIndex, child); continue; } - changedIndex = iter->second; + if (!indexChangedMap.empty()) { + changedIndex = iter->second; + } auto info = operationList_.find(index)->second; if (info.isDeleting) { nodeList_.emplace_back(child.first, child.second); From 2d2966dd0120fdc569d3eaca44a6da7018f7b16c Mon Sep 17 00:00:00 2001 From: gxjhl Date: Fri, 19 Jul 2024 14:47:18 +0800 Subject: [PATCH 030/221] =?UTF-8?q?reset=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gxjhl Change-Id: I60dc38b8a37df51bd34fd69dde7859758c6fa692 --- .../waterflow/layout/top_down/water_flow_layout_info.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_layout_info.cpp b/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_layout_info.cpp index 1445ffa4a7a..b6dca410e3c 100644 --- a/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_layout_info.cpp +++ b/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_layout_info.cpp @@ -45,8 +45,7 @@ void WaterFlowLayoutInfo::UpdateStartIndex() // don't use in new segmented layout return; } - auto nextPosition = GetCrossIndexForNextItem(GetSegment(endIndex_)); - auto mainHeight = GetMainHeight(nextPosition.crossIndex, nextPosition.lastItemIndex); + auto mainHeight = GetMaxMainHeight(); // need more items for currentOffset_ if (LessOrEqual(currentOffset_ + mainHeight, 0.0f)) { return; @@ -265,12 +264,9 @@ void WaterFlowLayoutInfo::Reset() void WaterFlowLayoutInfo::Reset(int32_t resetFrom) { TAG_LOGI(AceLogTag::ACE_WATERFLOW, "reset. updateIdx:%{public}d,endIndex:%{public}d", resetFrom, endIndex_); - if (resetFrom > endIndex_) { - return; - } maxHeight_ = 0.0f; jumpIndex_ = EMPTY_JUMP_INDEX; - startIndex_ = 0; + startIndex_ = resetFrom; ClearCacheAfterIndex(resetFrom - 1); } From 6688effbf64d9ff23380d25c544fcd9b4ec54cad Mon Sep 17 00:00:00 2001 From: chenyisen Date: Fri, 19 Jul 2024 14:50:03 +0800 Subject: [PATCH 031/221] =?UTF-8?q?dialog2=E4=B8=AA=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E5=9C=A8=E6=96=87=E6=9C=AC=E8=B6=85=E9=95=BF=E6=97=B6=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=E9=9C=80=E6=94=B9=E4=B8=BA=E5=8F=B3=E8=BE=B9=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=9C=A8=E4=B8=8A=E5=B7=A6=E8=BE=B9=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E5=9C=A8=E4=B8=8B=EF=BC=8C=E6=9B=B4=E5=A4=9A=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=97=B6=E8=A7=84=E5=88=99=E4=B8=8D=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyisen --- advanced_ui_component/dialog/interfaces/dialog.js | 11 ++++++----- advanced_ui_component/dialog/source/dialog.ets | 9 +++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/advanced_ui_component/dialog/interfaces/dialog.js b/advanced_ui_component/dialog/interfaces/dialog.js index 6d5feda69d4..12486657628 100644 --- a/advanced_ui_component/dialog/interfaces/dialog.js +++ b/advanced_ui_component/dialog/interfaces/dialog.js @@ -3624,10 +3624,10 @@ class CustomDialogContentComponent extends ViewPU { ForEach.create(); const forEachItemGenFunction = (_item, index) => { const item = _item; - this.buildButtonWithDivider.bind(this)(index, parent ? parent : this); + this.buildButtonWithDivider.bind(this)(this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? + HORIZON_BUTTON_MAX_COUNT - index - 1 : index, parent ? parent : this); }; - this.forEachUpdateFunction(elmtId, this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? - this.buttons.reverse() : this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), + this.forEachUpdateFunction(elmtId, this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), forEachItemGenFunction, (item) => item.value.toString(), true, false); }, ForEach); ForEach.pop(); @@ -3686,7 +3686,8 @@ class CustomDialogContentComponent extends ViewPU { Row.pop(); this.observeComponentCreation2((elmtId, isInitialRender) => { If.create(); - if (index < Math.min(this.buttons.length, VERTICAL_BUTTON_MAX_COUNT) - 1) { + if ((this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? HORIZON_BUTTON_MAX_COUNT - index - 1 : + index) < Math.min(this.buttons.length, VERTICAL_BUTTON_MAX_COUNT) - 1) { this.ifElseBranchUpdateFunction(0, () => { this.observeComponentCreation2((elmtId, isInitialRender) => { Row.create(); @@ -3963,7 +3964,7 @@ export class LoadingDialog extends ViewPU { fontSizeScale: this.__fontSizeScale, minContentHeight: this.__minContentHeight, }, undefined, elmtId, () => { - }, { page: 'library/src/main/ets/components/mainpage/dialog.ets', line: 1570 }); + }, { page: 'library/src/main/ets/components/mainpage/dialog.ets', line: 1573 }); ViewPU.create(componentCall); let paramsLambda = () => { return { diff --git a/advanced_ui_component/dialog/source/dialog.ets b/advanced_ui_component/dialog/source/dialog.ets index 6d00b4f87b4..dcaf8799f90 100644 --- a/advanced_ui_component/dialog/source/dialog.ets +++ b/advanced_ui_component/dialog/source/dialog.ets @@ -1347,9 +1347,9 @@ struct CustomDialogContentComponent { buildVerticalAlignButtons(): void { if (this.buttons) { Column() { - ForEach(this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? this.buttons.reverse() : - this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), (item: ButtonOptions, index: number) => { - this.buildButtonWithDivider(index); + ForEach(this.buttons.slice(0, VERTICAL_BUTTON_MAX_COUNT), (item: ButtonOptions, index: number) => { + this.buildButtonWithDivider(this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? + HORIZON_BUTTON_MAX_COUNT - index - 1 : index); }, (item: ButtonOptions) => item.value.toString()); } } @@ -1401,7 +1401,8 @@ struct CustomDialogContentComponent { this.buildSingleButton(this.buttons[index]); } - if (index < Math.min(this.buttons.length, VERTICAL_BUTTON_MAX_COUNT) - 1) { + if ((this.buttons.length === HORIZON_BUTTON_MAX_COUNT ? HORIZON_BUTTON_MAX_COUNT - index - 1 : index) < + Math.min(this.buttons.length, VERTICAL_BUTTON_MAX_COUNT) - 1) { Row() { } .height($r('sys.float.alert_button_vertical_space')) From 4a6d05ae2f5034b47bd3ef37f794cd2d899ae759 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Wed, 17 Jul 2024 18:52:02 +0800 Subject: [PATCH 032/221] menu view add tdd Signed-off-by: jiangzhijun8 Change-Id: I70dcbbce5598b38fc001716e1595e75c99680ed9 --- .../core/pattern/menu/menu_origin_test_ng.cpp | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/test/unittest/core/pattern/menu/menu_origin_test_ng.cpp b/test/unittest/core/pattern/menu/menu_origin_test_ng.cpp index 3912011aeb7..cf25ee47e02 100644 --- a/test/unittest/core/pattern/menu/menu_origin_test_ng.cpp +++ b/test/unittest/core/pattern/menu/menu_origin_test_ng.cpp @@ -2324,4 +2324,138 @@ HWTEST_F(MenuTestNg, MenuViewTestNgTextMaxLines001, TestSize.Level1) ASSERT_NE(textLayoutProperty, nullptr); EXPECT_EQ(textLayoutProperty->GetMaxLines().value(), menuTheme->GetTextMaxLines()); } + +/** + * @tc.name: MenuViewTestNg001 + * @tc.desc: Verify UpdateMenuBackgroundEffect. + * @tc.type: FUNC + */ +HWTEST_F(MenuTestNg, MenuViewTestNg001, TestSize.Level1) +{ + auto themeManager = AceType::MakeRefPtr(); + MockPipelineContext::GetCurrent()->SetThemeManager(themeManager); + RefPtr menuTheme = AceType::MakeRefPtr(); + EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme)); + + auto menuNode = FrameNode::CreateFrameNode(V2::MENU_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr(TARGET_ID, "", TYPE)); + ASSERT_NE(menuNode, nullptr); + + menuTheme->bgBlurEffectEnable_ = 0; + MenuView::UpdateMenuBackgroundEffect(menuNode); + + menuTheme->bgBlurEffectEnable_ = 1; + MenuView::UpdateMenuBackgroundEffect(menuNode); + auto renderContext = menuNode->GetRenderContext(); + auto effectOption = renderContext->GetBackgroundEffect(); + ASSERT_EQ(effectOption->color, Color::TRANSPARENT); +} + +/** + * @tc.name: MenuViewTestNg002 + * @tc.desc: Verify MenuView::Create when symbol not is nullptr. + * @tc.type: FUNC + */ +HWTEST_F(MenuTestNg, MenuViewTestNg002, TestSize.Level1) +{ + std::function action = [] {}; + std::function)> symbol = [](const WeakPtr& node) {}; + std::vector optionParams; + optionParams.emplace_back("MenuItem1", "", action); + optionParams.begin()->symbol = symbol; + MenuParam menuParam; + auto menuWrapperNode = MenuView::Create(std::move(optionParams), 1, "", MenuType::MENU, menuParam); + ASSERT_NE(menuWrapperNode, nullptr); + ASSERT_EQ(menuWrapperNode->GetChildren().size(), 1); +} + +/** + * @tc.name: MenuViewTestNg003 + * @tc.desc: Verify MenuView::Create. + * @tc.type: FUNC + */ +HWTEST_F(MenuTestNg, MenuViewTestNg003, TestSize.Level1) +{ + auto textNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(textNode, nullptr); + auto customNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(customNode, nullptr); + auto customSonNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(customSonNode, nullptr); + + MenuParam menuParam; + menuParam.type = MenuType::CONTEXT_MENU; + menuParam.isShowHoverImage = true; + menuParam.previewAnimationOptions = { 0.5f, 2.0f }; + menuParam.borderRadius.emplace(Dimension(2)); + + MockPipelineContext::GetCurrent()->SetMinPlatformVersion(static_cast(PlatformVersion::VERSION_ELEVEN)); + auto themeManager = AceType::MakeRefPtr(); + MockPipelineContext::GetCurrent()->SetThemeManager(themeManager); + RefPtr menuTheme = AceType::MakeRefPtr(); + EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme)); + + auto gestureHub = customNode->GetOrCreateGestureEventHub(); + menuTheme->doubleBorderEnable_ = 1; + + auto menuWrapperNode1 = MenuView::Create(textNode, TARGET_ID, "", menuParam, true, customNode); + ASSERT_NE(menuWrapperNode1, nullptr); + ASSERT_EQ(menuWrapperNode1->GetChildren().size(), 2); + + menuTheme->doubleBorderEnable_ = 0; + menuParam.previewAnimationOptions = { 0.5f, 0.0009f }; + customSonNode->MountToParent(customNode); + menuParam.previewMode = MenuPreviewMode::CUSTOM; + + auto menuWrapperNode2 = MenuView::Create(textNode, TARGET_ID, "", menuParam, true, customNode); + ASSERT_NE(menuWrapperNode2, nullptr); + ASSERT_EQ(menuWrapperNode2->GetChildren().size(), 2); +} + +/** + * @tc.name: MenuViewTestNg004 + * @tc.desc: Verify SetPreviewInfoToMenu with MenuView::Create. + * @tc.type: FUNC + */ +HWTEST_F(MenuTestNg, MenuViewTestNg004, TestSize.Level1) +{ + auto textNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(textNode, nullptr); + auto customNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(customNode, nullptr); + + MenuParam menuParam; + menuParam.type = MenuType::CONTEXT_MENU; + + auto targetNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 11, AceType::MakeRefPtr()); + auto targetGestureHub = targetNode->GetOrCreateGestureEventHub(); + + targetNode->draggable_ = true; + auto menuWrapperNode1 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode1, nullptr); + ASSERT_EQ(menuWrapperNode1->GetChildren().size(), 1); + + menuParam.isShowHoverImage = false; + menuParam.previewMode = MenuPreviewMode::CUSTOM; + auto menuWrapperNode2 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode2, nullptr); + ASSERT_EQ(menuWrapperNode2->GetChildren().size(), 2); + + menuParam.isShowHoverImage = true; + targetNode->GetPattern()->copyOption_ = CopyOptions::Local; + auto menuWrapperNode3 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode3, nullptr); + ASSERT_EQ(menuWrapperNode3->GetChildren().size(), 2); + + menuParam.previewMode = MenuPreviewMode::NONE; + targetNode->tag_ = "UINode"; + auto menuWrapperNode4 = MenuView::Create(textNode, 11, "UINode", menuParam, true, customNode); + ASSERT_NE(menuWrapperNode4, nullptr); + ASSERT_EQ(menuWrapperNode4->GetChildren().size(), 2); +} } // namespace OHOS::Ace::NG From e7dd573e82f50036594f6fb6b5b660b36e1a09b4 Mon Sep 17 00:00:00 2001 From: Zhang Jinyu Date: Fri, 19 Jul 2024 15:41:27 +0800 Subject: [PATCH 033/221] =?UTF-8?q?fix=20=E4=BF=AE=E4=BF=AE=E6=AD=A3refres?= =?UTF-8?q?h=20Refresh=E7=BB=84=E4=BB=B6=E9=85=8D=E7=BD=AEalign=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=EF=BC=8C=E5=88=B7=E6=96=B0=E5=8A=A8=E6=95=88=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhang Jinyu --- .../pattern/refresh/refresh_layout_algorithm.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frameworks/core/components_ng/pattern/refresh/refresh_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/refresh/refresh_layout_algorithm.cpp index ed8fac7f1f8..c5f133885c7 100644 --- a/frameworks/core/components_ng/pattern/refresh/refresh_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/refresh/refresh_layout_algorithm.cpp @@ -110,10 +110,7 @@ void RefreshLayoutAlgorithm::PerformLayout(LayoutWrapper* layoutWrapper) auto left = padding.left.value_or(0); auto top = padding.top.value_or(0); auto paddingOffset = OffsetF(left, top); - auto align = Alignment::TOP_LEFT; - if (layoutProperty->GetPositionProperty()) { - align = layoutProperty->GetPositionProperty()->GetAlignment().value_or(align); - } + auto align = Alignment::TOP_CENTER; auto host = layoutWrapper->GetHostNode(); CHECK_NULL_VOID(host); auto pattern = host->GetPattern(); From 47d9c297601472b7d83d7fdb5d6e7e06c9475523 Mon Sep 17 00:00:00 2001 From: wangyihui Date: Fri, 19 Jul 2024 08:05:43 +0000 Subject: [PATCH 034/221] =?UTF-8?q?=E3=80=90Menu=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=A1=8C=E9=9D=A2=E5=8D=A1=E7=89=87=E9=97=AA=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=8F=8A=E5=9B=9E=E9=80=80=E5=BA=9F=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyihui Change-Id: I2213ddd27c55257ba449832e3038f451b6071f54 --- .../components_ng/pattern/menu/menu_pattern.cpp | 16 ---------------- .../components_ng/pattern/menu/menu_pattern.h | 1 - .../pattern/overlay/overlay_manager.cpp | 7 ++++--- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp b/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp index 8eb828bda85..a1b0f149715 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp @@ -1345,24 +1345,8 @@ void MenuPattern::ShowMenuDisappearAnimation() }); } -void MenuPattern::CallMenuAboutToAppearCallback() -{ - auto menuWrapper = GetMenuWrapper(); - CHECK_NULL_VOID(menuWrapper); - auto menuWrapperPattern = menuWrapper->GetPattern(); - CHECK_NULL_VOID(menuWrapperPattern); - menuWrapperPattern->CallMenuAboutToAppearCallback(); - menuWrapperPattern->SetMenuStatus(MenuStatus::ON_SHOW_ANIMATION); - auto pipeline = menuWrapper->GetContext(); - CHECK_NULL_VOID(pipeline); - auto overlayManager = pipeline->GetOverlayManager(); - CHECK_NULL_VOID(overlayManager); - overlayManager->SetIsMenuShow(true); -} - bool MenuPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) { - CallMenuAboutToAppearCallback(); ShowPreviewMenuAnimation(); ShowMenuAppearAnimation(); ShowStackExpandMenu(); diff --git a/frameworks/core/components_ng/pattern/menu/menu_pattern.h b/frameworks/core/components_ng/pattern/menu/menu_pattern.h index da193f994ca..b45b20fb1be 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_pattern.h +++ b/frameworks/core/components_ng/pattern/menu/menu_pattern.h @@ -540,7 +540,6 @@ private: void DisableTabInMenu(); Offset GetTransformCenter() const; - void CallMenuAboutToAppearCallback(); void ShowPreviewMenuAnimation(); void ShowPreviewMenuScaleAnimation(); void ShowMenuAppearAnimation(); diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 8a4c6e9898c..729f4a33325 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -920,10 +920,10 @@ void OverlayManager::ShowMenuAnimation(const RefPtr& menu) BlurLowerNode(menu); auto wrapperPattern = menu->GetPattern(); CHECK_NULL_VOID(wrapperPattern); + wrapperPattern->CallMenuAboutToAppearCallback(); + wrapperPattern->SetMenuStatus(MenuStatus::ON_SHOW_ANIMATION); + SetIsMenuShow(true); if (wrapperPattern->HasTransitionEffect()) { - wrapperPattern->CallMenuAboutToAppearCallback(); - wrapperPattern->SetMenuStatus(MenuStatus::ON_SHOW_ANIMATION); - SetIsMenuShow(true); UpdateMenuVisibility(menu); auto renderContext = menu->GetRenderContext(); CHECK_NULL_VOID(renderContext); @@ -1880,6 +1880,7 @@ void OverlayManager::ShowMenuInSubWindow(int32_t targetId, const NG::OffsetF& of ShowMenuAnimation(menu); menu->MarkModifyDone(); rootNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); + pipeline->FlushUITasks(); // set subwindow container id in menu. auto menuPattern = menu->GetPattern(); From 9690f10937b10053c48f8eff790a8de8ff833f3a Mon Sep 17 00:00:00 2001 From: fan_pan Date: Fri, 19 Jul 2024 15:06:52 +0800 Subject: [PATCH 035/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9F=AD=E4=BF=A1AI?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E9=87=87=E7=94=A8=E7=BC=93=E5=AD=98=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E4=B9=B1=E7=A0=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fan_pan Change-Id: Id871f642310c855ba0d8b426f613ba7d1f066d5e --- .../pattern/text/text_pattern.cpp | 19 ++++++++++++++++++- .../components_ng/pattern/text/text_pattern.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.cpp b/frameworks/core/components_ng/pattern/text/text_pattern.cpp index fcf8f09ddcd..ec40b01a0a4 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text/text_pattern.cpp @@ -2440,7 +2440,24 @@ void TextPattern::InitSpanItem(std::stack nodes) InitClickEvent(gestureEventHub); } if (CanStartAITask() && !dataDetectorAdapter_->aiDetectInitialized_) { - dataDetectorAdapter_->StartAITask(); + ParseOriText(textLayoutProperty->GetContent().value_or("")); + if (!dataDetectorAdapter_->aiDetectInitialized_) { + dataDetectorAdapter_->StartAITask(); + } + } +} + +void TextPattern::ParseOriText(const std::string& currentText) +{ + auto entityJson = JsonUtil::ParseJsonString(currentText); + TAG_LOGI(AceLogTag::ACE_TEXT, "text content is the json format: %{public}d", entityJson->IsNull()); + if (!entityJson->IsNull() && !entityJson->GetValue("bundleName")->IsNull() && + dataDetectorAdapter_->ParseOriText(entityJson, textForDisplay_)) { + if (childNodes_.empty()) { + auto textLayoutProperty = GetLayoutProperty(); + CHECK_NULL_VOID(textLayoutProperty); + textLayoutProperty->UpdateContent(textForDisplay_); + } } } diff --git a/frameworks/core/components_ng/pattern/text/text_pattern.h b/frameworks/core/components_ng/pattern/text/text_pattern.h index 8401163f260..9ac4f8410af 100644 --- a/frameworks/core/components_ng/pattern/text/text_pattern.h +++ b/frameworks/core/components_ng/pattern/text/text_pattern.h @@ -793,6 +793,7 @@ private: void RegisterMarqueeNodeChangeListener(); void UnregisterMarqueeNodeChangeListener(); void HandleMarqueeWithIsVisible(FrameNodeChangeInfoFlag flag); + void ParseOriText(const std::string& currentText); bool isMeasureBoundary_ = false; bool isMousePressed_ = false; From b67082ad338d9d25c651255622d02725bc4a6452 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 16:38:05 +0800 Subject: [PATCH 036/221] =?UTF-8?q?=E4=BF=AE=E6=94=B9tdd=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../pattern/time_picker/time_picker_test_update.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/unittest/core/pattern/time_picker/time_picker_test_update.cpp b/test/unittest/core/pattern/time_picker/time_picker_test_update.cpp index 4d73473440d..f96c0cc44c5 100644 --- a/test/unittest/core/pattern/time_picker/time_picker_test_update.cpp +++ b/test/unittest/core/pattern/time_picker/time_picker_test_update.cpp @@ -1455,8 +1455,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetDisappearTextStyle001, TestSize.Level1) } else { textStyle.fontStyle = FONT_STYLES[0]; } - textStyle.fontFamily = Framework::ConvertStrToFontFamilies(res[POS_2]); - textStyle.fontWeight = StringUtils::StringToFontWeight(res[POS_1]); textStyle.textColor = Color(color); TimePickerModelNG::SetDisappearTextStyle(frameNode, theme, textStyle); } @@ -1495,8 +1493,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetNormalTextStyle001, TestSize.Level1) } else { textStyle.fontStyle = FONT_STYLES[0]; } - textStyle.fontFamily = Framework::ConvertStrToFontFamilies(res[POS_2]); - textStyle.fontWeight = StringUtils::StringToFontWeight(res[POS_1]); textStyle.textColor = Color(color); TimePickerModelNG::SetNormalTextStyle(frameNode, theme, textStyle); } @@ -1535,8 +1531,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetNormalTextStyle002, TestSize.Level1) } else { textStyle.fontStyle = FONT_STYLES[0]; } - textStyle.fontFamily = Framework::ConvertStrToFontFamilies(res[POS_2]); - textStyle.fontWeight = StringUtils::StringToFontWeight(res[POS_1]); textStyle.textColor = Color(color); TimePickerModelNG::SetNormalTextStyle(frameNode, theme, textStyle); } @@ -1575,8 +1569,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetSelectedTextStyle001, TestSize.Level1) } else { textStyle.fontStyle = FONT_STYLES[0]; } - textStyle.fontFamily = Framework::ConvertStrToFontFamilies(res[POS_2]); - textStyle.fontWeight = StringUtils::StringToFontWeight(res[POS_1]); textStyle.textColor = Color(color); TimePickerModelNG::SetSelectedTextStyle(frameNode, theme, textStyle); } @@ -1615,8 +1607,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetSelectedTextStyle002, TestSize.Level1) } else { textStyle.fontStyle = FONT_STYLES[0]; } - textStyle.fontFamily = Framework::ConvertStrToFontFamilies(res[POS_2]); - textStyle.fontWeight = StringUtils::StringToFontWeight(res[POS_1]); textStyle.textColor = Color(color); TimePickerModelNG::SetSelectedTextStyle(frameNode, theme, textStyle); } From bf2dedf31e49e9b04774ecf60e6db097a77fe0bc Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 16:41:50 +0800 Subject: [PATCH 037/221] =?UTF-8?q?textinput=20=E5=88=87=E6=8D=A2direction?= =?UTF-8?q?=E4=B8=BARTL,=E6=BB=9A=E5=8A=A8=E6=96=87=E6=9C=AC=E6=89=8B?= =?UTF-8?q?=E5=8A=BF=E4=B8=8E=E5=AE=9E=E9=99=85=E6=BB=9A=E5=8A=A8=E6=96=B9?= =?UTF-8?q?=E5=90=91=E7=9B=B8=E5=8F=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../components_ng/pattern/text_field/text_field_pattern.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h index d7ef0b1f19d..c5a8f449ec9 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h @@ -1380,6 +1380,11 @@ protected: { isDetachFromMainTree_ = true; } + + virtual bool IsReverse() const override + { + return false; + }; private: void GetTextSelectRectsInRangeAndWillChange(); From d3e6b9a54ca112c466dcabd9430205056b6a81cb Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 16:47:59 +0800 Subject: [PATCH 038/221] =?UTF-8?q?image=5Ftest=5Fng=20tdd=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E8=A6=86=E7=9B=96=E7=8E=87=200719?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 Change-Id: If5b7c85221316484c0c9b294b281bfea039728b7 --- .../core/pattern/image/image_testone_ng.cpp | 195 +++++++++++++++--- 1 file changed, 170 insertions(+), 25 deletions(-) diff --git a/test/unittest/core/pattern/image/image_testone_ng.cpp b/test/unittest/core/pattern/image/image_testone_ng.cpp index aa09cece482..0ed50fa032b 100644 --- a/test/unittest/core/pattern/image/image_testone_ng.cpp +++ b/test/unittest/core/pattern/image/image_testone_ng.cpp @@ -1773,31 +1773,176 @@ HWTEST_F(ImageTestOneNg, ImagePatternTest001, TestSize.Level1) { CreatePixelMapAnimator(1); auto [frameNode, imageLayoutProperty, imagePattern, imageRenderProperty] = GetCompoment(); - auto contain = "CONTAIN"; - auto cover = "COVER"; - auto fill = "FILL"; - auto fitWidth = "FITWIDTH"; - auto fitHeight = "FITHEIGHT"; - auto none = "NONE"; - auto scaleDown = "SCALE_DOWN"; - auto topLeft = "TOP_LEFT"; - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::CONTAIN), contain); - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::COVER), cover); - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::FILL), fill); - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::FITWIDTH), fitWidth); - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::FITHEIGHT), fitHeight); - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::NONE), none); - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::SCALE_DOWN), scaleDown); - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::TOP_LEFT), topLeft); - EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::START), cover); - auto noRepeat = "NO_REPEAT"; - auto repeat = "REPEAT_XY"; - auto repeatX = "REPEAT_X"; - auto repeatY = "REPEAT_Y"; - EXPECT_EQ(imagePattern->GetImageRepeatStr(ImageRepeat::NO_REPEAT), noRepeat); - EXPECT_EQ(imagePattern->GetImageRepeatStr(ImageRepeat::REPEAT), repeat); - EXPECT_EQ(imagePattern->GetImageRepeatStr(ImageRepeat::REPEAT_X), repeatX); - EXPECT_EQ(imagePattern->GetImageRepeatStr(ImageRepeat::REPEAT_Y), repeatY); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::CONTAIN), "CONTAIN"); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::COVER), "COVER"); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::FILL), "FILL"); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::FITWIDTH), "FITWIDTH"); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::FITHEIGHT), "FITHEIGHT"); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::NONE), "NONE"); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::SCALE_DOWN), "SCALE_DOWN"); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::TOP_LEFT), "TOP_LEFT"); + EXPECT_EQ(imagePattern->GetImageFitStr(ImageFit::START), "COVER"); + + EXPECT_EQ(imagePattern->GetImageRepeatStr(ImageRepeat::NO_REPEAT), "NO_REPEAT"); + EXPECT_EQ(imagePattern->GetImageRepeatStr(ImageRepeat::REPEAT), "REPEAT_XY"); + EXPECT_EQ(imagePattern->GetImageRepeatStr(ImageRepeat::REPEAT_X), "REPEAT_X"); + EXPECT_EQ(imagePattern->GetImageRepeatStr(ImageRepeat::REPEAT_Y), "REPEAT_Y"); +} + +void ImageModelNGFailedTest001_Properties01(ImageModelNG &image) +{ + auto [frameNode, imageLayoutProperty, imagePattern, imageRenderProperty] = GetCompoment(); + /** + * pop node + * All of the following property settings will fail + */ + auto uiNode = ViewStackProcessor::GetInstance()->Finish(); + FrameNode *frameNodeNull = nullptr; + image.SetAlt(ImageSourceInfo { RESOURCE_URL }); + EXPECT_EQ(imageLayoutProperty->GetAlt().has_value(), false); + + image.SetSmoothEdge(1.1f); + EXPECT_EQ(imageRenderProperty->GetSmoothEdge().has_value(), false); + + ImageModelNG::SetSmoothEdge(frameNodeNull, 1.1f); + EXPECT_EQ(imageRenderProperty->GetSmoothEdge().has_value(), false); + + image.SetDynamicRangeMode(DynamicRangeMode::HIGH); + EXPECT_EQ(imageRenderProperty->GetDynamicMode().has_value(), false); + + ImageModelNG::SetDynamicRangeMode(frameNodeNull, DynamicRangeMode::HIGH); + EXPECT_EQ(imageRenderProperty->GetDynamicMode().has_value(), false); + + image.SetEnhancedImageQuality(AIImageQuality::HIGH); + EXPECT_NE(imagePattern->GetImageQuality(), AIImageQuality::HIGH); + + ImageModelNG::SetEnhancedImageQuality(frameNodeNull, AIImageQuality::HIGH); + EXPECT_NE(imagePattern->GetImageQuality(), AIImageQuality::HIGH); + + image.SetBackBorder(); + EXPECT_EQ(imagePattern->needBorderRadius_, false); + + ImageModelNG::SetBackBorder(frameNodeNull); + EXPECT_EQ(imagePattern->needBorderRadius_, false); + + image.SetImageFit(ImageFit::BOTTOM); + EXPECT_EQ(imageLayoutProperty->GetImageFit().has_value(), false); + + ImageModelNG::SetImageFit(frameNodeNull, ImageFit::BOTTOM); + EXPECT_EQ(imageLayoutProperty->GetImageFit().has_value(), false); + + image.SetMatchTextDirection(true); + EXPECT_EQ(imageRenderProperty->GetMatchTextDirection().has_value(), false); + + ImageModelNG::SetMatchTextDirection(frameNodeNull, true); + EXPECT_EQ(imageRenderProperty->GetMatchTextDirection().has_value(), false); + + /* recover node*/ + ViewStackProcessor::GetInstance()->Push(uiNode); +} + +void ImageModelNGFailedTest001_Properties02(ImageModelNG &image) +{ + auto [frameNode, imageLayoutProperty, imagePattern, imageRenderProperty] = GetCompoment(); + /** + * pop node + * All of the following property settings will fail + */ + auto uiNode = ViewStackProcessor::GetInstance()->Finish(); + FrameNode *frameNodeNull = nullptr; + image.SetFitOriginSize(true); + EXPECT_EQ(imageLayoutProperty->GetFitOriginalSize().has_value(), false); + + ImageModelNG::SetFitOriginSize(frameNodeNull, true); + EXPECT_EQ(imageLayoutProperty->GetFitOriginalSize().has_value(), false); + + int testData = 0; + auto eventHub = frameNode->GetEventHub(); + auto onError = [&testData](const LoadImageFailEvent& info) { testData = 1; }; + image.SetOnError(std::move(onError)); + eventHub->FireErrorEvent(LoadImageFailEvent(WIDTH, HEIGHT, "image load error!")); + EXPECT_NE(testData, 1); + + auto onComplete = [&testData](const LoadImageSuccessEvent& info) { testData = 1; }; + image.SetOnComplete(std::move(onComplete)); + LoadImageSuccessEvent loadImageSuccessEvent(IMAGE_SOURCESIZE_WIDTH, IMAGE_SOURCESIZE_HEIGHT, WIDTH, HEIGHT, 1); + eventHub->FireCompleteEvent(loadImageSuccessEvent); + EXPECT_NE(testData, 1); + + auto svgAnimatorFinishEvent = [&testData]() { testData = 1; }; + image.SetSvgAnimatorFinishEvent(svgAnimatorFinishEvent); + eventHub->FireFinishEvent(); + EXPECT_NE(testData, 1); + + auto pairSize = std::make_pair(Dimension(1.1), Dimension(1.2)); + image.SetImageSourceSize(pairSize); + EXPECT_EQ(imageLayoutProperty->GetSourceSize().has_value(), false); + + ImageModelNG::SetImageSourceSize(frameNodeNull, pairSize); + EXPECT_EQ(imageLayoutProperty->GetSourceSize().has_value(), false); + + image.SetImageFill(Color::BLUE); + EXPECT_EQ(imageRenderProperty->GetSvgFillColor().has_value(), false); + + ImageModelNG::SetImageFill(frameNodeNull, Color::BLUE); + EXPECT_EQ(imageRenderProperty->GetSvgFillColor().has_value(), false); + + /* recover node*/ + ViewStackProcessor::GetInstance()->Push(uiNode); +} + +void ImageModelNGFailedTest001_Properties03(ImageModelNG &image) +{ + auto [frameNode, imageLayoutProperty, imagePattern, imageRenderProperty] = GetCompoment(); + /** + * pop node + * All of the following property settings will fail + */ + auto uiNode = ViewStackProcessor::GetInstance()->Finish(); + FrameNode *frameNodeNull = nullptr; + + image.SetImageInterpolation(ImageInterpolation::HIGH); + EXPECT_EQ(imageRenderProperty->GetImageInterpolation().has_value(), false); + + ImageModelNG::SetImageInterpolation(frameNodeNull, ImageInterpolation::HIGH); + EXPECT_EQ(imageRenderProperty->GetImageInterpolation().has_value(), false); + + image.SetImageRepeat(ImageRepeat::REPEAT_X); + EXPECT_EQ(imageRenderProperty->GetImageRepeat().has_value(), false); + + ImageModelNG::SetImageRepeat(frameNodeNull, ImageRepeat::REPEAT_X); + EXPECT_EQ(imageRenderProperty->GetImageRepeat().has_value(), false); + + image.SetImageRenderMode(ImageRenderMode::TEMPLATE); + EXPECT_EQ(imageRenderProperty->GetImageRenderMode().has_value(), false); + + ImageModelNG::SetImageRenderMode(frameNodeNull, ImageRenderMode::TEMPLATE); + EXPECT_EQ(imageRenderProperty->GetImageRenderMode().has_value(), false); + + /* recover node*/ + ViewStackProcessor::GetInstance()->Push(uiNode); +} + +/** + * @tc.name: ImageModelNGFailedTest001 + * @tc.desc: Test Image related method calls. + * @tc.type: FUNC + */ +HWTEST_F(ImageTestOneNg, ImageModelNGFailedTest001, TestSize.Level1) +{ + ImageModelNG image; + RefPtr pixMap = nullptr; + ImageInfoConfig imageInfoConfig; + imageInfoConfig.src = std::make_shared(IMAGE_SRC_URL); + imageInfoConfig.bundleName = BUNDLE_NAME; + imageInfoConfig.moduleName = MODULE_NAME; + image.Create(imageInfoConfig, pixMap); + + auto [frameNode, v1, v2, v3] = GetCompoment(); + ImageModelNGFailedTest001_Properties01(image); + ImageModelNGFailedTest001_Properties02(image); + ImageModelNGFailedTest001_Properties03(image); + frameNode->MarkModifyDone(); } } // namespace OHOS::Ace::NG \ No newline at end of file From 3c9f80eba6d437b00d3b2506b5f54333c72f9ce2 Mon Sep 17 00:00:00 2001 From: zhangjinyu101 Date: Fri, 19 Jul 2024 16:55:16 +0800 Subject: [PATCH 039/221] =?UTF-8?q?image=E7=BB=84=E4=BB=B6image=5Flayout?= =?UTF-8?q?=5Fproperty=E6=96=B0=E5=A2=9E=E7=9A=84=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E5=80=BC=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=95=B0=E7=BB=84=E5=80=BC?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangjinyu101 --- .../core/components_ng/pattern/image/image_layout_property.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/image/image_layout_property.h b/frameworks/core/components_ng/pattern/image/image_layout_property.h index 86496b35b88..c881f0d8aab 100644 --- a/frameworks/core/components_ng/pattern/image/image_layout_property.h +++ b/frameworks/core/components_ng/pattern/image/image_layout_property.h @@ -95,8 +95,9 @@ public: return; } static const char* OBJECTFITVALUE[] = { "ImageFit.Fill", "ImageFit.Contain", "ImageFit.Cover", "ImageFit.Auto", - "ImageFit.FitHeight", "ImageFit.None", "ImageFit.ScaleDown", "TOP_START", "TOP", "TOP_END", "START", - "CENTER", "END", "BOTTOM_START", "BOTTOM", "BOTTOM_END" }; + "ImageFit.FitHeight", "ImageFit.None", "ImageFit.ScaleDown", "ImageFit.TOP_START", "ImageFit.TOP", + "ImageFit.TOP_END", "ImageFit.START", "ImageFit.CENTER", "ImageFit.END", "ImageFit.BOTTOM_START", + "ImageFit.BOTTOM", "ImageFit.BOTTOM_END" }; static const char* VERTICALALIGNVALUE[] = { "VerticalAlign.NONE", "VerticalAlign.TOP", "VerticalAlign.CENTER", "VerticalAlign.BOTTOM", "VerticalAlign.BASELINE", "VerticalAlign.NONE" }; json->PutExtAttr("alt", propAlt_.value_or(ImageSourceInfo("")).GetSrc().c_str(), filter); From b2c422472271977520c3bd7dceef82a0738dfcb3 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 17:07:49 +0800 Subject: [PATCH 040/221] =?UTF-8?q?tdd=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../pattern/time_picker/time_picker_test_update.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/unittest/core/pattern/time_picker/time_picker_test_update.cpp b/test/unittest/core/pattern/time_picker/time_picker_test_update.cpp index f96c0cc44c5..031a129ce88 100644 --- a/test/unittest/core/pattern/time_picker/time_picker_test_update.cpp +++ b/test/unittest/core/pattern/time_picker/time_picker_test_update.cpp @@ -1436,8 +1436,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetDisappearTextStyle001, TestSize.Level1) StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str()); uint32_t color = 0; int32_t POS_0 = 0; - int32_t POS_1 = 1; - int32_t POS_2 = 2; const char delimiter = '|'; int32_t style = 0; const std::vector FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL, @@ -1474,8 +1472,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetNormalTextStyle001, TestSize.Level1) StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str()); uint32_t color = 0; int32_t POS_0 = 0; - int32_t POS_1 = 1; - int32_t POS_2 = 2; const char delimiter = '|'; int32_t style = 0; const std::vector FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL, @@ -1512,8 +1508,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetNormalTextStyle002, TestSize.Level1) StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str()); uint32_t color = 0; int32_t POS_0 = 0; - int32_t POS_1 = 1; - int32_t POS_2 = 2; const char delimiter = '|'; int32_t style = 0; const std::vector FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL, @@ -1550,8 +1544,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetSelectedTextStyle001, TestSize.Level1) StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str()); uint32_t color = 0; int32_t POS_0 = 0; - int32_t POS_1 = 1; - int32_t POS_2 = 2; const char delimiter = '|'; int32_t style = 0; const std::vector FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL, @@ -1588,8 +1580,6 @@ HWTEST_F(TimePickerPatternTestUpdate, SetSelectedTextStyle002, TestSize.Level1) StringUtils::FormatString(FORMAT_FONT.c_str(), fontSize.c_str(), weight.c_str(), fontFamily.c_str()); uint32_t color = 0; int32_t POS_0 = 0; - int32_t POS_1 = 1; - int32_t POS_2 = 2; const char delimiter = '|'; int32_t style = 0; const std::vector FONT_STYLES = { OHOS::Ace::FontStyle::NORMAL, From 657f1c2b977aa04c2626e7ec1af6c57132d32061 Mon Sep 17 00:00:00 2001 From: Zhang Jinyu Date: Tue, 16 Jul 2024 16:33:53 +0800 Subject: [PATCH 041/221] =?UTF-8?q?toggle=20switch=E6=8C=89=E5=8E=8B?= =?UTF-8?q?=E5=8F=8D=E9=A6=88UX=E5=BC=8F=E6=A0=B7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Zhang Jinyu Change-Id: Ibbc26ad49617fb0e70edcd8969d21c3984df1064 --- .../components/checkable/checkable_theme.cpp | 2 ++ .../components/checkable/checkable_theme.h | 12 ++++++++++++ .../pattern/toggle/switch_paint_method.cpp | 19 ++++++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/frameworks/core/components/checkable/checkable_theme.cpp b/frameworks/core/components/checkable/checkable_theme.cpp index e44f60aabea..c6f61a62085 100644 --- a/frameworks/core/components/checkable/checkable_theme.cpp +++ b/frameworks/core/components/checkable/checkable_theme.cpp @@ -53,6 +53,8 @@ void SwitchTheme::Builder::ParsePattern(const RefPtr& themeConst theme->touchDuration_ = switchPattern->GetAttr("touch_animation_duration", 0.0); theme->colorAnimationDuration_ = switchPattern->GetAttr("color_animation_duration", 0.0); theme->pointAnimationDuration_ = switchPattern->GetAttr("point_animation_duration", 0.0); + theme->interactiveHoverColor_ = switchPattern->GetAttr("interactive_hover", Color::RED); + theme->interactivePressedColor_ = switchPattern->GetAttr("interactive_pressed", Color::RED); if (SystemProperties::GetDeviceType() != DeviceType::CAR) { return; } diff --git a/frameworks/core/components/checkable/checkable_theme.h b/frameworks/core/components/checkable/checkable_theme.h index fa8a2d2ae37..573cec95002 100644 --- a/frameworks/core/components/checkable/checkable_theme.h +++ b/frameworks/core/components/checkable/checkable_theme.h @@ -418,10 +418,22 @@ public: return pointAnimationDuration_; } + const Color& GetInteractiveHoverColor() const + { + return interactiveHoverColor_; + } + + const Color& GetInteractivePressedColor() const + { + return interactivePressedColor_; + } + private: double colorAnimationDuration_ = 0.0; double pointAnimationDuration_ = 0.0; Color focusedPointColorUnselected_; + Color interactiveHoverColor_; + Color interactivePressedColor_; Dimension focusBoardWidth_; Dimension focusBoardHeight_; Dimension focusBoardRadius_; diff --git a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp index 7c234a6bd1c..0f6f40d6d90 100644 --- a/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/toggle/switch_paint_method.cpp @@ -81,8 +81,13 @@ void SwitchModifier::InitializeParam() CHECK_NULL_VOID(switchTheme); activeColor_ = switchTheme->GetActiveColor(); inactiveColor_ = switchTheme->GetInactiveColor(); - clickEffectColor_ = switchTheme->GetClickEffectColor(); - hoverColor_ = switchTheme->GetHoverColor(); + if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + clickEffectColor_ = switchTheme->GetClickEffectColor(); + hoverColor_ = switchTheme->GetHoverColor(); + } else { + clickEffectColor_ = switchTheme->GetInteractivePressedColor(); + hoverColor_ = switchTheme->GetInteractiveHoverColor(); + } hoverRadius_ = switchTheme->GetHoverRadius(); userActiveColor_ = activeColor_; hoverDuration_ = switchTheme->GetHoverDuration(); @@ -136,7 +141,9 @@ void SwitchModifier::PaintSwitch(RSCanvas& canvas, const OffsetF& contentOffset, OffsetF hoverBoardOffset; hoverBoardOffset.SetX(xOffset - (actualWidth_ - width) / 2.0); hoverBoardOffset.SetY(yOffset - (actualHeight_ - height) / 2.0); - DrawTouchAndHoverBoard(canvas, hoverBoardOffset); + if (!AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + DrawTouchAndHoverBoard(canvas, hoverBoardOffset); + } DrawFocusBoard(canvas, contentOffset, contentSize, actualGap); DrawRectCircle(canvas, contentOffset, contentSize, actualGap); } @@ -168,6 +175,12 @@ void SwitchModifier::DrawRectCircle(RSCanvas& canvas, const OffsetF& contentOffs canvas.AttachBrush(brush); canvas.DrawRoundRect(roundRect); canvas.DetachBrush(); + if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) { + brush.SetColor(ToRSColor(animateTouchHoverColor_->Get())); + canvas.AttachBrush(brush); + canvas.DrawRoundRect(roundRect); + canvas.DetachBrush(); + } brush.SetColor(ToRSColor(animatePointColor_->Get())); brush.SetAntiAlias(true); canvas.AttachBrush(brush); From 19f264ae65dd402679722a5510fa5cdbdf94b64d Mon Sep 17 00:00:00 2001 From: Tianer Zhou Date: Fri, 19 Jul 2024 17:35:20 +0800 Subject: [PATCH 042/221] fix spring animation not executed Signed-off-by: Tianer Zhou Change-Id: If04e67cec1eba83bb52ee9fb7d89dec1892b763f --- .../components_ng/pattern/scrollable/scrollable.cpp | 5 ++++- .../components_ng/pattern/scrollable/scrollable.h | 11 +++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable.cpp index 8d004b98ee5..fae2c7bb7a3 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable.cpp @@ -322,10 +322,13 @@ void Scrollable::HandleDragStart(const OHOS::Ace::GestureEvent& info) task_.Cancel(); } SetDragStartPosition(GetMainOffset(Offset(info.GetGlobalPoint().GetX(), info.GetGlobalPoint().GetY()))); - const auto dragPositionInMainAxis = + const double dragPositionInMainAxis = axis_ == Axis::VERTICAL ? info.GetGlobalLocation().GetY() : info.GetGlobalLocation().GetX(); TAG_LOGI(AceLogTag::ACE_SCROLLABLE, "Scroll drag start, localLocation: %{public}s, globalLocation: %{public}s", info.GetLocalLocation().ToString().c_str(), info.GetGlobalLocation().ToString().c_str()); + + skipRestartSpring_ = false; // reset flags. Extract method if more flags need to be reset + #ifdef OHOS_PLATFORM // Increase the cpu frequency when sliding start. auto currentTime = GetSysTimestamp(); diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable.h b/frameworks/core/components_ng/pattern/scrollable/scrollable.h index c996c542cbf..a7b95dde1e3 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable.h +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable.h @@ -88,13 +88,12 @@ public: bool IsMotionStop() const { - return isSpringAnimationStop_ && - isFrictionAnimationStop_ && !moved_; + return isSpringAnimationStop_ && isFrictionAnimationStop_ && !moved_; } bool IsSpringMotionRunning() const { - return !isSpringAnimationStop_ ; + return !isSpringAnimationStop_; } bool IsDragging() const @@ -466,8 +465,8 @@ private: double GetGain(double delta); void SetDelayedTask(); void MarkNeedFlushAnimationStartTime(); - float GetFrictionVelocityByFinalPosition(float final, float position, float signum, float friction, - float threshold = DEFAULT_MULTIPLIER); + float GetFrictionVelocityByFinalPosition( + float final, float position, float signum, float friction, float threshold = DEFAULT_MULTIPLIER); /** * @brief Checks if the scroll event is caused by a mouse wheel. @@ -562,7 +561,7 @@ private: RefPtr springOffsetProperty_; bool isSpringAnimationStop_ = true; - bool skipRestartSpring_ = false; + bool skipRestartSpring_ = false; // set to true when need to skip repeated spring animation uint32_t updateSnapAnimationCount_ = 0; uint32_t springAnimationCount_ = 0; From 7754d7d7bbcb337c50c719aa9affd1e2ebdd9ad5 Mon Sep 17 00:00:00 2001 From: fengfeng Date: Fri, 19 Jul 2024 17:38:55 +0800 Subject: [PATCH 043/221] alarm Signed-off-by: fengfeng Change-Id: I37eaaa199df5cf53417894ceb974546421759fd5 --- .../jsview/canvas/js_canvas_renderer.cpp | 2 +- .../jsview/canvas/js_render_image.cpp | 2 +- .../jsview/js_flex_impl.cpp | 5 +- .../jsview/js_layout_manager.cpp | 2 +- .../components_ng/layout/layout_wrapper.cpp | 66 ++++++++++++------- .../components_ng/layout/layout_wrapper.h | 2 + .../pattern/video/video_pattern.cpp | 2 +- .../pattern/xcomponent/xcomponent_pattern.h | 2 +- .../render/adapter/rosen_media_player.cpp | 3 + 9 files changed, 56 insertions(+), 30 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.cpp b/frameworks/bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.cpp index 32578d27649..22568bb1fcd 100644 --- a/frameworks/bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/canvas/js_canvas_renderer.cpp @@ -660,7 +660,7 @@ void JSCanvasRenderer::JsPutImageData(const JSCallbackInfo& info) imageData.data = std::vector(); for (int32_t i = std::max(imageData.dirtyY, 0); i < imageData.dirtyY + imageData.dirtyHeight; ++i) { for (int32_t j = std::max(imageData.dirtyX, 0); j < imageData.dirtyX + imageData.dirtyWidth; ++j) { - uint32_t idx = 4 * (j + imgWidth * i); + uint32_t idx = static_cast(4 * (j + imgWidth * i)); if (bufferLength > static_cast(idx + 3)) { imageData.data.emplace_back( Color::FromARGB(buffer[idx + 3], buffer[idx], buffer[idx + 1], buffer[idx + 2])); diff --git a/frameworks/bridge/declarative_frontend/jsview/canvas/js_render_image.cpp b/frameworks/bridge/declarative_frontend/jsview/canvas/js_render_image.cpp index 31068022db9..815ca83588a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/canvas/js_render_image.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/canvas/js_render_image.cpp @@ -306,7 +306,7 @@ void JSRenderImage::OnImageLoadSuccess() svgDom_ = imageObj_->GetSVGDom(); imageFit_ = loadingCtx_->GetImageFit(); imageSize_ = loadingCtx_->GetImageSize(); - bindingSize_ = pixelMap_ ? pixelMap_->GetByteCount() : 0; + bindingSize_ = pixelMap_ ? static_cast(pixelMap_->GetByteCount()) : 0; } void JSRenderImage::OnImageLoadFail(const std::string& errorMsg) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_flex_impl.cpp b/frameworks/bridge/declarative_frontend/jsview/js_flex_impl.cpp index 08fd58cae17..a7175aa0968 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_flex_impl.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_flex_impl.cpp @@ -24,6 +24,7 @@ namespace OHOS::Ace::Framework { +constexpr int32_t REVERSE_OFFSET_ZOOM = 2; void JSFlexImpl::Create(const JSCallbackInfo& info) { if (info.Length() < 1) { @@ -141,9 +142,9 @@ void JSFlexImpl::WrapComponent(const JSRef& obj, int32_t wrapVal) FlexModel::GetInstance()->SetDirection(static_cast(direction)); // WrapReverse means wrapVal = 2. Wrap means wrapVal = 1. if (direction <= 1) { - direction += 2 * (wrapVal - 1); + direction += REVERSE_OFFSET_ZOOM * (wrapVal - 1); } else { - direction -= 2 * (wrapVal - 1); + direction -= REVERSE_OFFSET_ZOOM * (wrapVal - 1); } FlexModel::GetInstance()->SetWrapDirection(static_cast(direction)); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_layout_manager.cpp b/frameworks/bridge/declarative_frontend/jsview/js_layout_manager.cpp index c886aad45b2..666eba82906 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_layout_manager.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_layout_manager.cpp @@ -45,7 +45,7 @@ void JSLayoutManager::GetLineMetrics(const JSCallbackInfo& args) } int32_t lineIndex = 0; JSViewAbstract::ParseJsInteger(args[0], lineIndex); - if (lineIndex < 0 || lineIndex >= layoutInfoInterface->GetLineCount()) { + if (lineIndex < 0 || lineIndex >= static_cast(layoutInfoInterface->GetLineCount())) { return; } auto lineMetrics = layoutInfoInterface->GetLineMetrics(lineIndex); diff --git a/frameworks/core/components_ng/layout/layout_wrapper.cpp b/frameworks/core/components_ng/layout/layout_wrapper.cpp index dba0460eeec..198cd9f6777 100644 --- a/frameworks/core/components_ng/layout/layout_wrapper.cpp +++ b/frameworks/core/components_ng/layout/layout_wrapper.cpp @@ -201,6 +201,28 @@ RectF LayoutWrapper::GetFrameRectWithSafeArea(bool checkPosition) const return geometryNode->GetSelfAdjust() + geometryNode->GetFrameRect(); } +void LayoutWrapper::AdjustNotExpandNode() +{ + auto host = GetHostNode(); + CHECK_NULL_VOID(host); + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + auto safeAreaManager = pipeline->GetSafeAreaManager(); + CHECK_NULL_VOID(safeAreaManager); + auto parent = host->GetAncestorNodeOfFrame(); + auto renderContext = host->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + auto geometryNode = GetGeometryNode(); + CHECK_NULL_VOID(geometryNode); + auto adjustedRect = geometryNode->GetFrameRect(); + if (safeAreaManager->IsSafeAreaValid()) { + adjustedRect += geometryNode->GetParentAdjust(); + } + geometryNode->SetSelfAdjust(adjustedRect - geometryNode->GetFrameRect()); + renderContext->UpdatePaintRect( + adjustedRect + geometryNode->GetPixelGridRoundRect() - geometryNode->GetFrameRect()); +} + void LayoutWrapper::ExpandSafeArea() { auto host = GetHostNode(); @@ -212,23 +234,13 @@ void LayoutWrapper::ExpandSafeArea() auto&& opts = GetLayoutProperty()->GetSafeAreaExpandOpts(); auto selfExpansive = host->SelfExpansive(); if (!selfExpansive) { - auto parent = host->GetAncestorNodeOfFrame(); - auto renderContext = host->GetRenderContext(); - CHECK_NULL_VOID(renderContext); - auto geometryNode = GetGeometryNode(); - CHECK_NULL_VOID(geometryNode); - auto adjustedRect = geometryNode->GetFrameRect(); - if (safeAreaManager->IsSafeAreaValid()) { - adjustedRect += geometryNode->GetParentAdjust(); - } - geometryNode->SetSelfAdjust(adjustedRect - geometryNode->GetFrameRect()); - renderContext->UpdatePaintRect( - adjustedRect + geometryNode->GetPixelGridRoundRect() - geometryNode->GetFrameRect()); + AdjustNotExpandNode(); return; } CHECK_NULL_VOID(selfExpansive); opts->switchToNone = false; auto geometryNode = GetGeometryNode(); + CHECK_NULL_VOID(geometryNode); OffsetF keyboardAdjust; if ((opts->edges & SAFE_AREA_EDGE_BOTTOM) && (opts->type & SAFE_AREA_TYPE_KEYBOARD)) { keyboardAdjust = ExpandIntoKeyboard(); @@ -260,17 +272,7 @@ void LayoutWrapper::ExpandSafeArea() frame.SetHeight(frame.Height() + (safeArea.bottom_.end - frame.Bottom())); } - // reset if User has fixed size - auto layoutProperty = GetLayoutProperty(); - if (layoutProperty->HasFixedWidth()) { - frame.SetWidth(geometryNode->GetFrameRect().Width()); - } - if (layoutProperty->HasFixedHeight()) { - frame.SetHeight(geometryNode->GetFrameRect().Height()); - } - if (layoutProperty->HasAspectRatio()) { - frame.SetHeight(frame.Width() / layoutProperty->GetAspectRatio()); - } + AdjustNotExpandNode(frame); auto parent = host->GetAncestorNodeOfFrame(); auto parentScrollable = (parent && parent->GetPattern()); // restore to local offset @@ -289,6 +291,24 @@ void LayoutWrapper::ExpandSafeArea() renderContext->UpdatePaintRect(frame + geometryNode->GetPixelGridRoundRect() - geometryNode->GetFrameRect()); } +void LayoutWrapper::AdjustNotExpandNode(RectF& frame) +{ + // reset if User has fixed size + auto layoutProperty = GetLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + auto geometryNode = GetGeometryNode(); + CHECK_NULL_VOID(geometryNode); + if (layoutProperty->HasFixedWidth()) { + frame.SetWidth(geometryNode->GetFrameRect().Width()); + } + if (layoutProperty->HasFixedHeight()) { + frame.SetHeight(geometryNode->GetFrameRect().Height()); + } + if (layoutProperty->HasAspectRatio()) { + frame.SetHeight(frame.Width() / layoutProperty->GetAspectRatio()); + } +} + void LayoutWrapper::ResetSafeAreaPadding() { // meant to reset everything each frame diff --git a/frameworks/core/components_ng/layout/layout_wrapper.h b/frameworks/core/components_ng/layout/layout_wrapper.h index a24011fce24..4a121e5f345 100644 --- a/frameworks/core/components_ng/layout/layout_wrapper.h +++ b/frameworks/core/components_ng/layout/layout_wrapper.h @@ -226,6 +226,8 @@ public: bool AvoidKeyboard(bool isFocusOnPage = true); // expand the SafeArea of expansive nodes, which are previously recorded during Layout traversal void ExpandSafeArea(); + void AdjustNotExpandNode(); + void AdjustNotExpandNode(RectF& frame); ExpandEdges GetAccumulatedSafeAreaExpand(bool includingSelf = false); void ResetSafeAreaPadding(); diff --git a/frameworks/core/components_ng/pattern/video/video_pattern.cpp b/frameworks/core/components_ng/pattern/video/video_pattern.cpp index 50767db516e..35ed6fb3295 100755 --- a/frameworks/core/components_ng/pattern/video/video_pattern.cpp +++ b/frameworks/core/components_ng/pattern/video/video_pattern.cpp @@ -400,7 +400,7 @@ void VideoPattern::OnCurrentTimeChange(uint32_t currentPos) if (duration_ == 0) { int32_t duration = 0; if (mediaPlayer_ && mediaPlayer_->GetDuration(duration) == 0) { - duration_ = duration / MILLISECONDS_TO_SECONDS; + duration_ = static_cast(duration / MILLISECONDS_TO_SECONDS); OnUpdateTime(duration_, DURATION_POS); } } diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h index ebcb32c3c04..8268bee1c5d 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h @@ -409,7 +409,7 @@ private: bool hasXComponentInit_ = false; RefPtr touchEvent_; - OH_NativeXComponent_TouchEvent touchEventPoint_; + OH_NativeXComponent_TouchEvent touchEventPoint_ = {}; RefPtr mouseEvent_; RefPtr axisEvent_; RefPtr mouseHoverEvent_; diff --git a/frameworks/core/components_ng/render/adapter/rosen_media_player.cpp b/frameworks/core/components_ng/render/adapter/rosen_media_player.cpp index 18da688bc04..02b9118c53f 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_media_player.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_media_player.cpp @@ -196,6 +196,7 @@ bool RosenMediaPlayer::MediaPlay(const std::string& filePath) return false; } auto hapPath = container->GetHapPath(); + CHECK_NULL_RETURN(hapPath.c_str(), false); auto hapFd = open(hapPath.c_str(), O_RDONLY); if (hapFd < 0) { LOGE("Open hap file failed"); @@ -229,6 +230,7 @@ bool RosenMediaPlayer::RawFilePlay(const std::string& filePath) return false; } auto hapPath = container->GetHapPath(); + CHECK_NULL_RETURN(hapPath.c_str(), false); auto hapFd = open(hapPath.c_str(), O_RDONLY); if (hapFd < 0) { LOGE("Open hap file failed"); @@ -259,6 +261,7 @@ bool RosenMediaPlayer::RelativePathPlay(const std::string& filePath) auto container = Container::Current(); CHECK_NULL_RETURN(container, false); auto hapPath = container->GetHapPath(); + CHECK_NULL_RETURN(hapPath.c_str(), false); auto hapFd = open(hapPath.c_str(), O_RDONLY); if (hapFd < 0) { LOGE("Open hap file failed"); From dca04877971b8e9786ca829f02c8a94444f73f5b Mon Sep 17 00:00:00 2001 From: tengfan66 Date: Fri, 19 Jul 2024 18:22:37 +0800 Subject: [PATCH 044/221] syncgeo Signed-off-by: tengfan66 Change-Id: I4a7fa1178629d2b52f72223524faf863de481e2d --- .../components_ng/pattern/web/web_pattern.cpp | 26 +++++++++++++++++++ .../components_ng/pattern/web/web_pattern.h | 1 + 2 files changed, 27 insertions(+) diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.cpp b/frameworks/core/components_ng/pattern/web/web_pattern.cpp index 4914898acda..dfe22626fe0 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.cpp +++ b/frameworks/core/components_ng/pattern/web/web_pattern.cpp @@ -1761,6 +1761,32 @@ bool WebPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, co return false; } +void WebPattern::BeforeSyncGeometryProperties(const DirtySwapConfig& config) +{ + if (!config.contentSizeChange || isInWindowDrag_) { + return; + } + auto frameNode = GetHost(); + CHECK_NULL_VOID(frameNode); + auto renderContext = frameNode->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + auto rect = renderContext->GetPaintRectWithoutTransform(); + auto drawSize = Size(rect.Width(), rect.Height()); + if (drawSize.IsInfinite() || drawSize.IsEmpty()) { + return; + } + + if (GreatOrEqual(drawSize.Width(), Infinity())) { + drawSize.SetWidth(DEFAULT_WEB_WIDTH); + } + if (GreatOrEqual(drawSize.Height(), Infinity())) { + drawSize.SetHeight(DEFAULT_WEB_HEIGHT); + } + + drawSize_ = drawSize; + drawSizeCache_ = drawSize_; +} + void WebPattern::UpdateLayoutAfterKeyboardShow(int32_t width, int32_t height, double keyboard, double oldWebHeight) { lastKeyboardHeight_ = keyboard; diff --git a/frameworks/core/components_ng/pattern/web/web_pattern.h b/frameworks/core/components_ng/pattern/web/web_pattern.h index 2bb8800d5aa..6b966cf1e2c 100644 --- a/frameworks/core/components_ng/pattern/web/web_pattern.h +++ b/frameworks/core/components_ng/pattern/web/web_pattern.h @@ -668,6 +668,7 @@ private: void UpdateWebLayoutSize(int32_t width, int32_t height, bool isKeyboard, bool isUpdate = true); void UpdateLayoutAfterKeyboardShow(int32_t width, int32_t height, double keyboard, double oldWebHeight); bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; + void BeforeSyncGeometryProperties(const DirtySwapConfig& config) override; void OnRebuildFrame() override; void OnAttachToFrameNode() override; From 2c26d06e48f91d570481b62e381e1bcca8a9e4c7 Mon Sep 17 00:00:00 2001 From: Flanif Date: Fri, 19 Jul 2024 18:23:10 +0800 Subject: [PATCH 045/221] menu token and radius bug fix Signed-off-by: Flanif --- .../core/components/select/select_theme.h | 41 +++++++++++++++++++ .../menu_item/menu_item_layout_algorithm.cpp | 20 +++++---- .../menu_item/menu_item_layout_algorithm.h | 1 + .../menu/menu_item/menu_item_model_ng.cpp | 4 +- .../menu_item_group/menu_item_group_view.cpp | 8 +--- .../pattern/menu/menu_pattern.cpp | 3 +- 6 files changed, 60 insertions(+), 17 deletions(-) diff --git a/frameworks/core/components/select/select_theme.h b/frameworks/core/components/select/select_theme.h index ee9f397751b..88b3c0cc123 100644 --- a/frameworks/core/components/select/select_theme.h +++ b/frameworks/core/components/select/select_theme.h @@ -292,6 +292,12 @@ public: theme->optionTextStyle_.SetTextDecoration(TextDecoration::NONE); theme->menuLargeMargin_ = pattern->GetAttr("menu_large_margin", theme->menuLargeMargin_); theme->menuMediumMargin_ = pattern->GetAttr("menu_medium_margin", theme->menuMediumMargin_); + theme->menuItemChildMinHeight_ = pattern->GetAttr("menu_item_child_min_height", 32.0_vp); + theme->menuItemVerticalPadding_ = pattern->GetAttr("menu_item_vertical_padding", 8.0_vp); + theme->menuItemGroupTitleTextFontSize_ = + pattern->GetAttr("menu_item_group_title_text_font_size", 18.0_vp); + theme->menuDefaultRadius_ = pattern->GetAttr("menu_default_radius", 20.0_vp); + theme->menuTextColor_= pattern->GetAttr("menu_text_color", Color(0xe5000000)); } }; @@ -410,6 +416,11 @@ public: theme->maxPaddingEnd_ = maxPaddingEnd_; theme->menuLargeMargin_ = menuLargeMargin_; theme->menuMediumMargin_ = menuMediumMargin_; + theme->menuItemChildMinHeight_ = menuItemChildMinHeight_; + theme->menuItemVerticalPadding_ = menuItemVerticalPadding_; + theme->menuItemGroupTitleTextFontSize_ = menuItemGroupTitleTextFontSize_; + theme->menuDefaultRadius_ = menuDefaultRadius_; + theme->menuTextColor_ = menuTextColor_; } const Color& GetSelectedColorText() const @@ -1064,6 +1075,31 @@ public: return menuMediumMargin_; } + const Dimension& GetMenuChildMinHeight() const + { + return menuItemChildMinHeight_; + } + + const Dimension& GetMenuItemVerticalPadding() const + { + return menuItemVerticalPadding_; + } + + const Dimension& GetMenuItemGroupTitleTextFontSize() const + { + return menuItemGroupTitleTextFontSize_; + } + + const Dimension& GetMenuDefaultRadius() const + { + return menuDefaultRadius_; + } + + const Color& GetMenuTextColor() const + { + return menuTextColor_; + } + const uint32_t& GetMenuItemContentAlign() const { return menuItemContentAlign_; @@ -1183,6 +1219,11 @@ private: std::unordered_map selectFontSizeMap_; Dimension menuLargeMargin_; Dimension menuMediumMargin_; + Dimension menuItemChildMinHeight_; + Dimension menuItemVerticalPadding_; + Dimension menuItemGroupTitleTextFontSize_; + Dimension menuDefaultRadius_; + Color menuTextColor_; uint32_t menuItemContentAlign_ = CONTENT_ALIGN_LEFT; }; diff --git a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.cpp index 4b8c4f264dd..e1403a51d92 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.cpp @@ -23,10 +23,6 @@ #include "core/pipeline/pipeline_base.h" namespace OHOS::Ace::NG { -namespace { - constexpr Dimension MENU_ITEM_CHILD_MIN_HEIGHT = 32.0_vp; - constexpr Dimension MENU_ITEM_VERTICAL_PADDING = 8.0_vp; -} void MenuItemLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) { CHECK_NULL_VOID(layoutWrapper); @@ -43,7 +39,7 @@ void MenuItemLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) auto layoutConstraint = props->GetLayoutConstraint(); CHECK_NULL_VOID(layoutConstraint); if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { - verInterval_ = static_cast(MENU_ITEM_VERTICAL_PADDING.ConvertToPx()) - GetBordersHeight(layoutWrapper); + verInterval_ = GetMenuItemVerticalPadding() - GetBordersHeight(layoutWrapper); } const auto& padding = props->CreatePaddingAndBorderWithDefault(horInterval_, verInterval_, 0.0f, 0.0f); maxRowWidth_ = layoutConstraint->maxSize.Width() - padding.Width(); @@ -78,7 +74,7 @@ void MenuItemLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) minItemHeight_ = static_cast(theme->GetOptionMinHeight().ConvertToPx()); // set item min height childConstraint.minSize.SetHeight(Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE) ? - MENU_ITEM_CHILD_MIN_HEIGHT.ConvertToPx() : minItemHeight_); + theme->GetMenuChildMinHeight().ConvertToPx() : minItemHeight_); iconSize_ = theme->GetIconSideLength().ConvertToPx(); MeasureItemViews(childConstraint, layoutConstraint, padding, layoutWrapper); @@ -233,7 +229,7 @@ void MenuItemLayoutAlgorithm::MeasureRow(const RefPtr& row, const float spaceWidth = constraint.maxSize.Width(); float rowWidth = 0.0f; float rowHeight = Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_TWELVE) ? - MENU_ITEM_CHILD_MIN_HEIGHT.ConvertToPx() : minItemHeight_; + theme->GetMenuChildMinHeight().ConvertToPx() : minItemHeight_; for (const auto& child : children) { if (child != children.back()) { // not content node @@ -312,4 +308,14 @@ float MenuItemLayoutAlgorithm::GetBordersHeight(LayoutWrapper* layoutWrapper) return border->topDimen.value_or(Dimension(0.0)).ConvertToPx() + border->bottomDimen.value_or(Dimension(0.0)).ConvertToPx(); } + +float MenuItemLayoutAlgorithm::GetMenuItemVerticalPadding() +{ + float ret = 0.0f; + auto pipeline = PipelineBase::GetCurrentContext(); + CHECK_NULL_RETURN(pipeline, ret); + auto theme = pipeline->GetTheme(); + CHECK_NULL_RETURN(theme, ret); + return theme->GetMenuItemVerticalPadding().ConvertToPx(); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.h b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.h index b0c2e2bed7f..019cff7433e 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_layout_algorithm.h @@ -45,6 +45,7 @@ private: void UpdateSelfSize(LayoutWrapper* layoutWrapper, float width, float itemHeight, float expandableHeight); float GetDividerStroke(LayoutWrapper* layoutWrapper); float GetBordersHeight(LayoutWrapper* layoutWrapper); + float GetMenuItemVerticalPadding(); float horInterval_ = 0.0f; float verInterval_ = 0.0f; diff --git a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_model_ng.cpp b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_model_ng.cpp index 70973addde8..17c9f8be15a 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_model_ng.cpp @@ -47,7 +47,7 @@ void MenuItemModelNG::Create(const RefPtr& customNode) auto theme = pipeline->GetTheme(); CHECK_NULL_VOID(theme); BorderRadiusProperty border; - border.SetRadius(theme->GetMenuBorderRadius()); + border.SetRadius(theme->GetInnerBorderRadius()); renderContext->UpdateBorderRadius(border); CHECK_NULL_VOID(customNode); @@ -81,7 +81,7 @@ void MenuItemModelNG::Create(const MenuItemProperties& menuItemProps) auto theme = pipeline->GetTheme(); CHECK_NULL_VOID(theme); BorderRadiusProperty border; - border.SetRadius(theme->GetMenuBorderRadius()); + border.SetRadius(theme->GetInnerBorderRadius()); renderContext->UpdateBorderRadius(border); auto leftRow = FrameNode::CreateFrameNode(V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), diff --git a/frameworks/core/components_ng/pattern/menu/menu_item_group/menu_item_group_view.cpp b/frameworks/core/components_ng/pattern/menu/menu_item_group/menu_item_group_view.cpp index 601b3aa1dff..eb5c48583c6 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_item_group/menu_item_group_view.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_item_group/menu_item_group_view.cpp @@ -25,10 +25,6 @@ #include "core/components_v2/inspector/inspector_constants.h" namespace OHOS::Ace::NG { -namespace { - constexpr Dimension TITLE_TEXT_FONT_SIZE = 18.0_fp; - constexpr Color MENU_TEXT_COLOR = Color(0xe5000000); -} namespace { void UpdateRowPadding(const RefPtr& row) { @@ -89,9 +85,9 @@ void MenuItemGroupView::SetHeader(const std::string& headerStr) auto theme = pipeline->GetTheme(); CHECK_NULL_VOID(theme); if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { - layoutProps->UpdateFontSize(TITLE_TEXT_FONT_SIZE); + layoutProps->UpdateFontSize(theme->GetMenuItemGroupTitleTextFontSize()); layoutProps->UpdateFontWeight(FontWeight::BOLD); - layoutProps->UpdateTextColor(MENU_TEXT_COLOR); + layoutProps->UpdateTextColor(theme->GetMenuTextColor()); } else { layoutProps->UpdateFontSize(theme->GetMenuFontSize()); layoutProps->UpdateTextColor(theme->GetSecondaryFontColor()); diff --git a/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp b/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp index 8eb828bda85..e6d580db746 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp +++ b/frameworks/core/components_ng/pattern/menu/menu_pattern.cpp @@ -74,7 +74,6 @@ const float MINIMUM_AMPLITUDE_RATION = 0.08f; constexpr double MOUNT_MENU_FINAL_SCALE = 0.95f; constexpr double SEMI_CIRCLE_ANGEL = 90.0f; constexpr Dimension PADDING = 4.0_vp; -constexpr Dimension MENU_DEFAULT_RADIUS = 20.0_vp; void UpdateFontStyle(RefPtr& menuProperty, RefPtr& itemProperty, @@ -910,7 +909,7 @@ void MenuPattern::InitTheme(const RefPtr& host) // make menu round rect BorderRadiusProperty borderRadius; if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { - borderRadius.SetRadius(MENU_DEFAULT_RADIUS); + borderRadius.SetRadius(theme->GetMenuDefaultRadius()); } else { borderRadius.SetRadius(theme->GetMenuBorderRadius()); } From ceea638a0ee766cbe124226d3e6be93803ce97ac Mon Sep 17 00:00:00 2001 From: gxjhl Date: Fri, 19 Jul 2024 19:23:04 +0800 Subject: [PATCH 046/221] fix bug Signed-off-by: gxjhl Change-Id: I19e90f4ea07a13981a4007b2cc811b3760a23cbe --- .../sliding_window/water_flow_layout_info_sw.cpp | 10 ++++++---- .../pattern/waterflow/water_flow_sections.cpp | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frameworks/core/components_ng/pattern/waterflow/layout/sliding_window/water_flow_layout_info_sw.cpp b/frameworks/core/components_ng/pattern/waterflow/layout/sliding_window/water_flow_layout_info_sw.cpp index af1c11a671b..ea80161fa7c 100644 --- a/frameworks/core/components_ng/pattern/waterflow/layout/sliding_window/water_flow_layout_info_sw.cpp +++ b/frameworks/core/components_ng/pattern/waterflow/layout/sliding_window/water_flow_layout_info_sw.cpp @@ -609,13 +609,15 @@ bool WaterFlowLayoutInfoSW::AdjustLanes(const std::vector()) { + newStartIndex_ = INVALID_NEW_START_INDEX; + } + if (newStartIndex_ == INVALID_NEW_START_INDEX) { + return false; + } return true; } diff --git a/frameworks/core/components_ng/pattern/waterflow/water_flow_sections.cpp b/frameworks/core/components_ng/pattern/waterflow/water_flow_sections.cpp index 5328f67030a..3169490311f 100644 --- a/frameworks/core/components_ng/pattern/waterflow/water_flow_sections.cpp +++ b/frameworks/core/components_ng/pattern/waterflow/water_flow_sections.cpp @@ -68,15 +68,16 @@ void WaterFlowSections::NotifySectionChange( int32_t start, int32_t deleteCount, const std::vector& newSections) { int32_t addItemCount = 0; - for (int i = 0; i < static_cast(newSections.size()) - 1; i++) { + int32_t n = static_cast(sections_.size()); + for (int32_t i = 0; i < static_cast(newSections.size()) - 1; i++) { addItemCount += newSections[i].itemsCount; } int32_t deleteItemCount = 0; - for (int i = start; i < start + deleteCount - 1; i++) { + for (int32_t i = start; i < std::min(start + deleteCount - 1, n); i++) { deleteItemCount += sections_[i].itemsCount; } int32_t itemCount = 0; - for (int i = 0; i < start; i++) { + for (int32_t i = 0; i < std::min(start, n); i++) { itemCount += sections_[i].itemsCount; } if (notifyDataChange_) { From 7916b8d54886a5397b8a6839c45dbc787b8e65cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=8D=A0=E6=B1=9F?= Date: Thu, 18 Jul 2024 14:03:21 +0000 Subject: [PATCH 047/221] =?UTF-8?q?=E3=80=90toast=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dtoast=E7=82=B9=E5=87=BB=E4=B8=80=E4=B8=8B=E5=8F=98?= =?UTF-8?q?=E7=99=BD=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡占江 Change-Id: I6b4542bcc688aa3d6ee078240e58421fd71e018a --- .../core/components_ng/pattern/toast/toast_pattern.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frameworks/core/components_ng/pattern/toast/toast_pattern.cpp b/frameworks/core/components_ng/pattern/toast/toast_pattern.cpp index bfecaff12b1..1fad2a704ad 100644 --- a/frameworks/core/components_ng/pattern/toast/toast_pattern.cpp +++ b/frameworks/core/components_ng/pattern/toast/toast_pattern.cpp @@ -156,6 +156,11 @@ void ToastPattern::BeforeCreateLayoutWrapper() auto toastNode = GetHost(); CHECK_NULL_VOID(toastNode); + auto pipelineContext = IsDefaultToast() ? toastNode->GetContextRefPtr() : GetMainPipelineContext(); + if (!pipelineContext) { + TAG_LOGD(AceLogTag::ACE_OVERLAY, "toast get pipelineContext failed"); + return; + } UpdateToastSize(toastNode); auto textNode = DynamicCast(toastNode->GetFirstChild()); From 66061be0378335dac3f6048d34744c372e27019c Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 20:14:43 +0800 Subject: [PATCH 048/221] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../common/recorder/event_recorder_test.cpp | 17 ++++++++++++++--- .../pattern/picker/date_picker_test_update.cpp | 13 +++++++++++++ .../rich_editor_keyboard_shortcut_test_ng.cpp | 1 + .../rich_editor/rich_editor_overlay_test_ng.cpp | 5 ++++- .../rich_editor_styled_string_test_ng.cpp | 6 ++++-- .../text_picker/text_picker_pattern_test_ng.cpp | 8 ++++++-- .../text_picker/text_picker_test_update.cpp | 5 +++++ 7 files changed, 47 insertions(+), 8 deletions(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index f54054ddac0..cc860d3da78 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -598,6 +598,7 @@ HWTEST_F(EventRecorderTest, SetContainerInfo001, TestSize.Level1) { std::string windowName = "$HA_FLOAT_WINDOW$"; Recorder::EventRecorder::Get().SetContainerInfo(windowName, 0, true); + EXPECT_EQ(Recorder::EventRecorder::Get().containerId_, -1); } /** @@ -609,6 +610,7 @@ HWTEST_F(EventRecorderTest, SetContainerInfo002, TestSize.Level1) { std::string windowName = ""; Recorder::EventRecorder::Get().SetContainerInfo(windowName, 0, true); + EXPECT_EQ(Recorder::EventRecorder::Get().containerId_, 0); } /** @@ -620,6 +622,7 @@ HWTEST_F(EventRecorderTest, SetContainerInfo003, TestSize.Level1) { std::string windowName = ""; Recorder::EventRecorder::Get().SetContainerInfo(windowName, 0, false); + EXPECT_EQ(Recorder::EventRecorder::Get().containerId_, -1); } /** @@ -631,6 +634,7 @@ HWTEST_F(EventRecorderTest, SetFocusContainerInfo001, TestSize.Level1) { std::string windowName = "$HA_FLOAT_WINDOW$"; Recorder::EventRecorder::Get().SetFocusContainerInfo(windowName, 0); + EXPECT_EQ(Recorder::EventRecorder::Get().focusContainerId_, -1); } /** @@ -642,6 +646,7 @@ HWTEST_F(EventRecorderTest, SetFocusContainerInfo002, TestSize.Level1) { std::string windowName = ""; Recorder::EventRecorder::Get().SetFocusContainerInfo(windowName, 0); + EXPECT_EQ(Recorder::EventRecorder::Get().focusContainerId_, 0); } /** @@ -651,9 +656,10 @@ HWTEST_F(EventRecorderTest, SetFocusContainerInfo002, TestSize.Level1) */ HWTEST_F(EventRecorderTest, Init001, TestSize.Level1) { - std::string windowName = ""; + std::string config = ""; Recorder::EventConfig* config = new Recorder::EventConfig(); - config->Init(""); + config->Init(config); + EXPECT_EQ(!JsonUtil::ParseJsonString(config)->IsValid(), true); } /** @@ -719,6 +725,7 @@ HWTEST_F(EventRecorderTest, PutString002, TestSize.Level1) HWTEST_F(EventRecorderTest, OnBeforePagePop001, TestSize.Level1) { Recorder::NodeDataCache::Get().OnBeforePagePop(true); + EXPECT_FALSE(Recorder::NodeDataCache::Get().shouldCollectFull_); } /** @@ -729,7 +736,9 @@ HWTEST_F(EventRecorderTest, OnBeforePagePop001, TestSize.Level1) HWTEST_F(EventRecorderTest, GetExposureCfg001, TestSize.Level1) { Recorder::ExposureCfg cfg; - Recorder::NodeDataCache::Get().GetExposureCfg("", "", cfg); + string pageUrl = ""; + Recorder::NodeDataCache::Get().GetExposureCfg(pageUrl, "", cfg); + EXPECT_TRUE(pageUrl.empty()); } /** @@ -741,6 +750,7 @@ HWTEST_F(EventRecorderTest, Clear001, TestSize.Level1) { Recorder::ExposureCfg cfg; Recorder::NodeDataCache::Get().Clear(""); + EXPECT_TRUE(Recorder::NodeDataCache::Get().container_.empty()); } /** @@ -752,5 +762,6 @@ HWTEST_F(EventRecorderTest, GetNodeData001, TestSize.Level1) { std::unordered_map nodes; Recorder::NodeDataCache::Get().GetNodeData("", nodes); + EXPECT_TRUE(Recorder::NodeDataCache::Get().container_.empty()); } } // namespace OHOS::Ace diff --git a/test/unittest/core/pattern/picker/date_picker_test_update.cpp b/test/unittest/core/pattern/picker/date_picker_test_update.cpp index e10fcea65a4..6544d928662 100644 --- a/test/unittest/core/pattern/picker/date_picker_test_update.cpp +++ b/test/unittest/core/pattern/picker/date_picker_test_update.cpp @@ -2008,6 +2008,10 @@ HWTEST_F(DatePickerTestUpdate, ShowContentRowButton001, TestSize.Level1) bool isFirstPage = true; CreateDatePickerColumnNode(); DatePickerDialogView::ShowContentRowButton(columnNode_, isFirstPage); + EXPECT_EQ(AceType::DynamicCast(columnNode_->GetFirstChild()) + ->GetLayoutProperty() + ->propVisibility_, + VisibleType::VISIBLE); } /** @@ -2020,6 +2024,10 @@ HWTEST_F(DatePickerTestUpdate, ShowContentRowButton002, TestSize.Level1) bool isFirstPage = false; CreateDatePickerColumnNode(); DatePickerDialogView::ShowContentRowButton(columnNode_, isFirstPage); + EXPECT_EQ(AceType::DynamicCast(columnNode_->GetChildAtIndex(2)) + ->GetLayoutProperty() + ->propVisibility_, + VisibleType::VISIBLE); } /** @@ -2036,6 +2044,7 @@ HWTEST_F(DatePickerTestUpdate, UpdateNextButtonMargin001, TestSize.Level1) RefPtr buttonLayoutProperty = AceType::DynamicCast(layoutProperty); ASSERT_NE(buttonLayoutProperty, nullptr); DatePickerDialogView::UpdateNextButtonMargin(buttonLayoutProperty); + ASSERT_NE(buttonLayoutProperty->GetMarginProperty(), nullptr); } /** @@ -2048,6 +2057,8 @@ HWTEST_F(DatePickerTestUpdate, HandleMouseEvent001, TestSize.Level1) bool isHover = true; auto titleButtonRow = DatePickerDialogView::CreateTitleButtonRowNode(); DatePickerDialogView::HandleMouseEvent(titleButtonRow, isHover); + EXPECT_EQ(AceType::DynamicCast(titleButtonRow)->GetRenderContext()->GetBackgroundColor(), + PipelineBase::GetCurrentContext()->GetTheme()->GetHoverColor()); } /** @@ -2060,6 +2071,8 @@ HWTEST_F(DatePickerTestUpdate, HandleMouseEvent002, TestSize.Level1) bool isHover = false; auto titleButtonRow = DatePickerDialogView::CreateTitleButtonRowNode(); DatePickerDialogView::HandleMouseEvent(titleButtonRow, isHover); + EXPECT_EQ( + AceType::DynamicCast(titleButtonRow)->GetRenderContext()->GetBackgroundColor(), Color::TRANSPARENT); } /** diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp index 0a4b26dc47a..ffcc141ac5d 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp @@ -1355,5 +1355,6 @@ HWTEST_F(RichEditorKeyboardShortcutTestNg, SetCustomKeyboard001, TestSize.Level1 richEditorModel.Create(); auto func = []() {}; richEditorModel.SetCustomKeyboard(func, true); + EXPECT_TRUE(ViewStackProcessor::GetInstance()->GetMainFrameNode()->GetPattern()->keyboardAvoidance_); } } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp index 124fd4427b0..1d7d6b0dfd0 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_overlay_test_ng.cpp @@ -1450,6 +1450,7 @@ HWTEST_F(RichEditorOverlayTestNg, SetCaretWidth001, TestSize.Level1) auto overlayMod = richEditorNode_->GetOverlayNode(); auto richEditorOverlay = AceType::DynamicCast(richEditorPattern->overlayMod_); richEditorOverlay->SetCaretWidth(-1); + EXPECT_NE(richEditorOverlay->caretWidth_, -1); } /** @@ -1467,6 +1468,7 @@ HWTEST_F(RichEditorOverlayTestNg, PaintPreviewTextDecoration001, TestSize.Level1 Testing::MockCanvas canvas; DrawingContext context { canvas, 100, 100 }; richEditorOverlay->PaintPreviewTextDecoration(context); + EXPECT_NE(richEditorOverlay->previewTextUnderlineWidth_, 0); } /** @@ -1553,7 +1555,8 @@ HWTEST_F(RichEditorOverlayTestNg, GetGlyphPositionAtCoordinate001, TestSize.Leve ASSERT_NE(richEditorNode_, nullptr); auto richEditorPattern = richEditorNode_->GetPattern(); ASSERT_NE(richEditorPattern, nullptr); - richEditorPattern->paragraphs_.GetGlyphPositionAtCoordinate(offset); + PositionWithAffinity position = richEditorPattern->paragraphs_.GetGlyphPositionAtCoordinate(offset); + EXPECT_EQ(position.position_, 0); } /** diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_styled_string_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_styled_string_test_ng.cpp index cef73d71cdc..5911a634bfa 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_styled_string_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_styled_string_test_ng.cpp @@ -892,7 +892,6 @@ HWTEST_F(RichEditorStyledStringTestNg, FromStyledString001, TestSize.Level1) EXPECT_EQ(info.selection_.resultObjects.size(), mutableStr->GetSpanItems().size()); } - /** * @tc.name: CopySpanStyle001 * @tc.desc: test CopySpanStyle @@ -907,6 +906,7 @@ HWTEST_F(RichEditorStyledStringTestNg, CopySpanStyle001, TestSize.Level1) source->textLineStyle->UpdateTextAlign(TextAlign::CENTER); source->textLineStyle->UpdateMaxLines(1); layoutAlgorithm->CopySpanStyle(source, AceType::MakeRefPtr()); + EXPECT_TRUE(source->textLineStyle->HasTextAlign()); } /** @@ -919,6 +919,8 @@ HWTEST_F(RichEditorStyledStringTestNg, CopySpanStyle002, TestSize.Level1) auto richEditorPattern = richEditorNode_->GetPattern(); auto layoutAlgorithm = AceType::DynamicCast(richEditorPattern->CreateLayoutAlgorithm()); ASSERT_NE(richEditorPattern, nullptr); - layoutAlgorithm->CopySpanStyle(AceType::MakeRefPtr(), AceType::MakeRefPtr()); + RefPtr source = AceType::MakeRefPtr(); + layoutAlgorithm->CopySpanStyle(source, AceType::MakeRefPtr()); + EXPECT_FALSE(source->textLineStyle->HasTextAlign()); } } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp b/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp index cf5c89bf2e7..7c08a799c5b 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp @@ -1750,7 +1750,9 @@ HWTEST_F(TextPickerPatternTestNg, TextPickerPatternUpdateColumnChildPosition002, HWTEST_F(TextPickerPatternTestNg, LinearFontSize001, TestSize.Level1) { InitTextPickerPatternTestNg(); - textPickerColumnPattern_->LinearFontSize(Dimension(FONT_SIZE_10), Dimension(FONT_SIZE_20), 1); + Dimension dimension = Dimension(FONT_SIZE_10); + Dimension dimension1 = textPickerColumnPattern_->LinearFontSize(dimension1, dimension1, 1); + EXPECT_TRUE(dimension < dimension1); } /** @@ -1761,7 +1763,9 @@ HWTEST_F(TextPickerPatternTestNg, LinearFontSize001, TestSize.Level1) HWTEST_F(TextPickerPatternTestNg, LinearFontSize002, TestSize.Level1) { InitTextPickerPatternTestNg(); - textPickerColumnPattern_->LinearFontSize(Dimension(FONT_SIZE_10), Dimension(FONT_SIZE_20), 2); + Dimension dimension = Dimension(FONT_SIZE_10); + Dimension dimension1 = textPickerColumnPattern_->LinearFontSize(dimension1, dimension1, 2); + EXPECT_TRUE(dimension < dimension1); } /** diff --git a/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp b/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp index 5cb495dddb9..fa57a1e9a1c 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp @@ -1781,6 +1781,7 @@ HWTEST_F(TextPickerTestUpdate, UpdateForwardButtonMargin001, TestSize.Level1) auto pipeline = PipelineContext::GetCurrentContext(); auto dialogTheme = pipeline->GetTheme(); TextPickerDialogView::UpdateForwardButtonMargin(buttonForwardNode, dialogTheme); + EXPECT_NE(buttonBackwardNode->GetLayoutProperty()->margin_, nullptr); } /** @@ -1793,6 +1794,7 @@ HWTEST_F(TextPickerTestUpdate, SetDialogButtonActive001, TestSize.Level1) auto contentColumn = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr(true)); TextPickerDialogView::SetDialogButtonActive(contentColumn, 0, 0); + EXPECT_NE(contentColumn->GetLastChild(), nullptr); } /** @@ -1845,6 +1847,7 @@ HWTEST_F(TextPickerTestUpdate, SetRange001, TestSize.Level1) auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(frameNode, nullptr); TextPickerModelNG::SetRange(frameNode, range); + ASSERT_NE(frameNode->GetPattern()->GetRange(), nullptr); } /** @@ -1863,6 +1866,7 @@ HWTEST_F(TextPickerTestUpdate, SetValue001, TestSize.Level1) auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(frameNode, nullptr); TextPickerModelNG::SetValue(frameNode, value); + ASSERT_NE(frameNode->GetPattern()->values_, nullptr); } /** @@ -1884,5 +1888,6 @@ HWTEST_F(TextPickerTestUpdate, SetValues001, TestSize.Level1) auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(frameNode, nullptr); TextPickerModelNG::SetValues(frameNode, value); + ASSERT_NE(frameNode->GetPattern()->values_, nullptr); } } // namespace OHOS::Ace::NG \ No newline at end of file From 67d9a91a189d7b7bccb01c2329b18118740e8285 Mon Sep 17 00:00:00 2001 From: huzeqi Date: Fri, 19 Jul 2024 20:20:45 +0800 Subject: [PATCH 049/221] Swiper: the upper limit of jumpIndex need to consider the displaycount Signed-off-by: huzeqi Change-Id: I06eada78a687107888f2d65a3c0cf81f93fb9114 --- .../core/components_ng/pattern/swiper/swiper_pattern.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp index 0751266cac2..c3cd0885bf5 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp @@ -456,7 +456,8 @@ void SwiperPattern::BeforeCreateLayoutWrapper() StartAutoPlay(); InitArrow(); } - if (userSetCurrentIndex < 0 || userSetCurrentIndex >= RealTotalCount() || GetDisplayCount() >= RealTotalCount()) { + int32_t maxValidIndex = IsLoop() ? RealTotalCount() : TotalCount() - GetDisplayCount() + 1; + if (userSetCurrentIndex < 0 || userSetCurrentIndex >= maxValidIndex || GetDisplayCount() >= RealTotalCount()) { currentIndex_ = 0; layoutProperty->UpdateIndexWithoutMeasure(GetLoopIndex(currentIndex_)); } else { From 4735157682e31f381f0e0c31e1055f70e26a1a64 Mon Sep 17 00:00:00 2001 From: xiangshouxing Date: Fri, 19 Jul 2024 12:53:40 +0000 Subject: [PATCH 050/221] fix codeCheck Signed-off-by: xiangshouxing Change-Id: I593032fdb78435271d2ce580b892cc49662114ed --- .../declarative_frontend/ark_mock/src/mock.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/ark_mock/src/mock.ts b/frameworks/bridge/declarative_frontend/ark_mock/src/mock.ts index 916c772f66c..502b0919f12 100644 --- a/frameworks/bridge/declarative_frontend/ark_mock/src/mock.ts +++ b/frameworks/bridge/declarative_frontend/ark_mock/src/mock.ts @@ -21,7 +21,7 @@ abstract class ViewPU { aboutToRecycleInternal(): void {} updateDirtyElements(): void {} } -(globalThis as any).ViewPU = ViewPU; +globalThis.ViewPU = ViewPU; class __JSBaseNode__ { constructor(options?: RenderOptions) {} @@ -35,13 +35,13 @@ class __JSBaseNode__ { updateStart(): void {} updateEnd(): void {} } -(globalThis as any).__JSBaseNode__ = __JSBaseNode__; +globalThis.__JSBaseNode__ = __JSBaseNode__; class __JSScopeUtil__ { static syncInstanceId(instanceId: number): void {} static restoreInstanceId(): void {} } -(globalThis as any).__JSScopeUtil__ = __JSScopeUtil__; +globalThis.__JSScopeUtil__ = __JSScopeUtil__; interface CustomDialogControllerConstructorArg { builder: () => void; @@ -53,14 +53,14 @@ class CustomDialogController { private view_: ViewPU; constructor(arg: CustomDialogControllerConstructorArg, view: ViewPU) {} - open() {} - close() {} + open(): void {} + close(): void {} } -(globalThis as any).CustomDialogController = CustomDialogController; +globalThis.CustomDialogController = CustomDialogController; class TextModifier { constructor(nativePtr: KNode, classType: ModifierType) {} - applyNormalAttribute(instance: TextAttribute) {} + applyNormalAttribute(instance: TextAttribute): void {} } export default { ViewPU, __JSBaseNode__, __JSScopeUtil__, CustomDialogController, TextModifier }; \ No newline at end of file From 535a1612471efdc1e0e93c7e1f39042266a694ca Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 21:36:56 +0800 Subject: [PATCH 051/221] =?UTF-8?q?=E5=88=A0=E9=99=A4virtual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../core/components_ng/pattern/text_field/text_field_pattern.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h index c5a8f449ec9..c14a2a9bbbc 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h @@ -1381,7 +1381,7 @@ protected: isDetachFromMainTree_ = true; } - virtual bool IsReverse() const override + bool IsReverse() const override { return false; }; From 24df6ddfe45d66816603ad27cd3d044db32ab3ba Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 15:01:56 +0800 Subject: [PATCH 052/221] =?UTF-8?q?animate=5Fimpl.cpp=20and=20dialog=5Fmod?= =?UTF-8?q?el.cpp=20=E8=A1=A5=E5=85=85=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 Change-Id: Ie360b30d75da13d2b0fb528d909371926378cdd8 --- test/unittest/interfaces/BUILD.gn | 112 +++ .../unittest/interfaces/animate_impl_test.cpp | 663 ++++++++++++++++++ .../unittest/interfaces/dialog_model_test.cpp | 494 +++++++++++++ 3 files changed, 1269 insertions(+) create mode 100644 test/unittest/interfaces/animate_impl_test.cpp create mode 100644 test/unittest/interfaces/dialog_model_test.cpp diff --git a/test/unittest/interfaces/BUILD.gn b/test/unittest/interfaces/BUILD.gn index 9a5bbe6a5c8..1661452d903 100644 --- a/test/unittest/interfaces/BUILD.gn +++ b/test/unittest/interfaces/BUILD.gn @@ -615,10 +615,122 @@ ohos_unittest("node_transition_test") { ] } +ohos_unittest("animate_impl_test") { + module_out_path = interface_test_output_path + + sources = [ + "$ace_root/adapter/ohos/osal/log_wrapper.cpp", + "$ace_root/frameworks/core/components/common/properties/color.cpp", + "$ace_root/interfaces/native/node/animate_impl.cpp", + "$ace_root/interfaces/native/node/dialog_model.cpp", + "$ace_root/interfaces/native/node/event_converter.cpp", + "$ace_root/interfaces/native/node/gesture_impl.cpp", + "$ace_root/interfaces/native/node/native_impl.cpp", + "$ace_root/interfaces/native/node/native_node_napi.cpp", + "$ace_root/interfaces/native/node/node_animate.cpp", + "$ace_root/interfaces/native/node/node_extened.cpp", + "$ace_root/interfaces/native/node/node_model.cpp", + "$ace_root/interfaces/native/node/node_transition.cpp", + "$ace_root/interfaces/native/node/node_transition_imp.cpp", + "$ace_root/interfaces/native/node/style_modifier.cpp", + "$ace_root/test/mock/adapter/mock_log_wrapper.cpp", + "animate_impl_test.cpp", + ] + + configs = [ + "$ace_root/test/unittest:ace_unittest_config", + ":c_api_configs", + ] + + include_dirs = [ + "$ace_root/frameworks/base/error", + "$ace_root/frameworks/core/interfaces/arkoala", + "$ace_root/frameworks/", + "$ace_root/interfaces/native/", + "$ace_root/interfaces/native/node", + "$ace_root", + "$ace_root/interfaces/inner_api/drawable_descriptor", + ] + + deps = [ "//third_party/googletest:gmock_main" ] + + public_deps = [ + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + "image_framework:image", + "image_framework:image_native", + "napi:ace_napi", + "resource_management:global_resmgr", + ] +} + +ohos_unittest("dialog_model_test") { + module_out_path = interface_test_output_path + + sources = [ + "$ace_root/adapter/ohos/osal/log_wrapper.cpp", + "$ace_root/frameworks/core/components/common/properties/color.cpp", + "$ace_root/interfaces/native/node/animate_impl.cpp", + "$ace_root/interfaces/native/node/dialog_model.cpp", + "$ace_root/interfaces/native/node/event_converter.cpp", + "$ace_root/interfaces/native/node/gesture_impl.cpp", + "$ace_root/interfaces/native/node/native_impl.cpp", + "$ace_root/interfaces/native/node/native_node_napi.cpp", + "$ace_root/interfaces/native/node/node_animate.cpp", + "$ace_root/interfaces/native/node/node_extened.cpp", + "$ace_root/interfaces/native/node/node_model.cpp", + "$ace_root/interfaces/native/node/node_transition.cpp", + "$ace_root/interfaces/native/node/node_transition_imp.cpp", + "$ace_root/interfaces/native/node/style_modifier.cpp", + "$ace_root/test/mock/adapter/mock_log_wrapper.cpp", + "dialog_model_test.cpp", + ] + + configs = [ + "$ace_root/test/unittest:ace_unittest_config", + ":c_api_configs", + ] + + include_dirs = [ + "$ace_root/frameworks/base/error", + "$ace_root/frameworks/core/interfaces/arkoala", + "$ace_root/frameworks/", + "$ace_root/interfaces/native/", + "$ace_root/interfaces/native/node", + "$ace_root", + "$ace_root/interfaces/inner_api/drawable_descriptor", + ] + + deps = [ "//third_party/googletest:gmock_main" ] + + public_deps = [ + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + "image_framework:image", + "image_framework:image_native", + "napi:ace_napi", + "resource_management:global_resmgr", + ] +} + group("interfaces_unittest") { testonly = true deps = [ ":ace_forward_compatibility_test", + ":animate_impl_test", + ":dialog_model_test", ":drawable_descriptor_test", ":extension_custom_node_test_ng", ":form_render_delegate_impl_test", diff --git a/test/unittest/interfaces/animate_impl_test.cpp b/test/unittest/interfaces/animate_impl_test.cpp new file mode 100644 index 00000000000..276dc129d40 --- /dev/null +++ b/test/unittest/interfaces/animate_impl_test.cpp @@ -0,0 +1,663 @@ +/* + * Copyright (c) 2024 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 "animate_impl.h" +#include "core/interfaces/arkoala/arkoala_api.h" +#include "error_code.h" +#include "event_converter.h" +#include "gtest/gtest.h" +#include "native_animate.h" +#include "native_interface.h" +#include "native_node.h" +#include "node_extened.h" +#include "node_model.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Ace::AnimateModel; + +class AnimateImplTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; +}; + +float InterpolateCallback(float fraction, void* userData) +{ + return fraction; +} + +void AnimateCompleteCallback(void* userData) {} + +/** + * @tc.name: AnimateImplTest001 + * @tc.desc: Test InitCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest001, TestSize.Level1) +{ + ArkUI_CurveHandle curve = InitCurve(ArkUI_AnimationCurve::ARKUI_CURVE_EASE); + ASSERT_EQ(curve, nullptr); + + DisposeCurve(curve); +} + +/** + * @tc.name: AnimateImplTest002 + * @tc.desc: Test CubicBezierCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest002, TestSize.Level1) +{ + ArkUI_CurveHandle curve = CubicBezierCurve(0.0f, 0.0f, 0.0f, 0.0f); + ASSERT_EQ(curve, nullptr); +} + +/** + * @tc.name: AnimateImplTest003 + * @tc.desc: Test SpringCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest003, TestSize.Level1) +{ + ArkUI_CurveHandle curve = SpringCurve(0.0f, 0.0f, 0.0f, 0.0f); + ASSERT_EQ(curve, nullptr); +} + +/** + * @tc.name: AnimateImplTest004 + * @tc.desc: Test SpringMotion function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest004, TestSize.Level1) +{ + ArkUI_CurveHandle curve = SpringMotion(0.0f, 0.0f, 0.0f); + ASSERT_EQ(curve, nullptr); +} + +/** + * @tc.name: AnimateImplTest005 + * @tc.desc: Test InterpolatingSpring function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest005, TestSize.Level1) +{ + ArkUI_CurveHandle curve = InterpolatingSpring(0.0f, 0.0f, 0.0f, 0.0f); + ASSERT_EQ(curve, nullptr); +} + +/** + * @tc.name: AnimateImplTest006 + * @tc.desc: Test ResponsiveSpringMotion function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest006, TestSize.Level1) +{ + ArkUI_CurveHandle curve = ResponsiveSpringMotion(0.0f, 0.0f, 0.0f); + ASSERT_EQ(curve, nullptr); +} + +/** + * @tc.name: AnimateImplTest007 + * @tc.desc: Test CustomCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest007, TestSize.Level1) +{ + ArkUI_CurveHandle curve = CustomCurve(nullptr, InterpolateCallback); + ASSERT_EQ(curve, nullptr); +} + +/** + * @tc.name: AnimateImplTest008 + * @tc.desc: Test InitCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest008, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = InitCurve(ArkUI_AnimationCurve::ARKUI_CURVE_EASE); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest009 + * @tc.desc: Test StepsCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest009, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = StepsCurve(0, true); + ASSERT_EQ(curve, nullptr); +} + +/** + * @tc.name: AnimateImplTest010 + * @tc.desc: Test StepsCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest010, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = StepsCurve(1, true); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest011 + * @tc.desc: Test CubicBezierCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest011, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = CubicBezierCurve(0.0f, 0.0f, 0.0f, 0.0f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest012 + * @tc.desc: Test SpringCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest012, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = SpringCurve(0.0f, 0.0f, 0.0f, 0.0f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest013 + * @tc.desc: Test SpringCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest013, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = SpringCurve(0.5f, 0.5f, 0.5f, 0.5f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest014 + * @tc.desc: Test SpringMotion function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest014, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = SpringMotion(0.5f, 0.5f, 0.5f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest015 + * @tc.desc: Test SpringMotion function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest015, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = SpringMotion(-1.0f, -1.0f, -1.0f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest016 + * @tc.desc: Test ResponsiveSpringMotion function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest016, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = ResponsiveSpringMotion(-1.0f, -1.0f, -1.0f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest017 + * @tc.desc: Test ResponsiveSpringMotion function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest017, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = ResponsiveSpringMotion(0.5f, 0.5f, 0.5f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest018 + * @tc.desc: Test InterpolatingSpring function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest018, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = InterpolatingSpring(0.5f, 0.5f, 0.5f, 0.5f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest019 + * @tc.desc: Test InterpolatingSpring function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest019, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = InterpolatingSpring(0.0f, 0.0f, 0.0f, 0.0f); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest020 + * @tc.desc: Test CustomCurve function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest020, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_CurveHandle curve = CustomCurve(nullptr, InterpolateCallback); + ASSERT_NE(curve, nullptr); + + DisposeCurve(curve); + curve = nullptr; +} + +/** + * @tc.name: AnimateImplTest021 + * @tc.desc: Test CreateAnimator function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest021, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption(); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(&context, option); + ASSERT_NE(animatorHandle, nullptr); + + DisposeAnimator(animatorHandle); + animatorHandle = nullptr; + delete option; +} + +/** + * @tc.name: AnimateImplTest022 + * @tc.desc: Test CreateAnimator function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest022, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(nullptr, nullptr); + ASSERT_EQ(animatorHandle, nullptr); + + DisposeAnimator(animatorHandle); +} + +/** + * @tc.name: AnimateImplTest023 + * @tc.desc: Test AnimatorReset function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest023, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + int32_t ret = AnimatorReset(nullptr, nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: AnimateImplTest024 + * @tc.desc: Test AnimatorReset function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest024, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption(); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(&context, option); + ASSERT_NE(animatorHandle, nullptr); + ArkUIAnimatorHandle animator = new ArkUIAnimator(); + animatorHandle->animator = animator; + int32_t ret = AnimatorReset(animatorHandle, option); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + + DisposeAnimator(animatorHandle); + animatorHandle = nullptr; + delete option; +} + +/** + * @tc.name: AnimateImplTest025 + * @tc.desc: Test AnimatorReset function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest025, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption(); + struct ArkUI_Keyframe keyframe = {0.0f, 0.0f, nullptr}; + option->keyframes.push_back(keyframe); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(&context, option); + ASSERT_NE(animatorHandle, nullptr); + ArkUIAnimatorHandle animator = new ArkUIAnimator(); + animatorHandle->animator = animator; + int32_t ret = AnimatorReset(animatorHandle, option); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + + DisposeAnimator(animatorHandle); + animatorHandle = nullptr; + delete option; +} + +/** + * @tc.name: AnimateImplTest026 + * @tc.desc: Test AnimatorPlay function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest026, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + int32_t ret = AnimatorPlay(nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: AnimateImplTest027 + * @tc.desc: Test AnimatorPlay function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest027, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption(); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(&context, option); + ASSERT_NE(animatorHandle, nullptr); + ArkUIAnimatorHandle animator = new ArkUIAnimator(); + animatorHandle->animator = animator; + int32_t ret = AnimatorPlay(animatorHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + + DisposeAnimator(animatorHandle); + animatorHandle = nullptr; + delete option; +} + +/** + * @tc.name: AnimateImplTest028 + * @tc.desc: Test AnimatorFinish function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest028, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + int32_t ret = AnimatorFinish(nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: AnimateImplTest029 + * @tc.desc: Test AnimatorFinish function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest029, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption(); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(&context, option); + ASSERT_NE(animatorHandle, nullptr); + ArkUIAnimatorHandle animator = new ArkUIAnimator(); + animatorHandle->animator = animator; + int32_t ret = AnimatorFinish(animatorHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + + DisposeAnimator(animatorHandle); + animatorHandle = nullptr; + delete option; +} + +/** + * @tc.name: AnimateImplTest030 + * @tc.desc: Test AnimatorPause function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest030, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + int32_t ret = AnimatorPause(nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: AnimateImplTest031 + * @tc.desc: Test AnimatorPause function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest031, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption(); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(&context, option); + ASSERT_NE(animatorHandle, nullptr); + ArkUIAnimatorHandle animator = new ArkUIAnimator(); + animatorHandle->animator = animator; + int32_t ret = AnimatorPause(animatorHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + + DisposeAnimator(animatorHandle); + animatorHandle = nullptr; + delete option; +} + +/** + * @tc.name: AnimateImplTest032 + * @tc.desc: Test AnimatorCancel function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest032, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + int32_t ret = AnimatorCancel(nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: AnimateImplTest033 + * @tc.desc: Test AnimatorCancel function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest033, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption(); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(&context, option); + ASSERT_NE(animatorHandle, nullptr); + ArkUIAnimatorHandle animator = new ArkUIAnimator(); + animatorHandle->animator = animator; + int32_t ret = AnimatorCancel(animatorHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + + DisposeAnimator(animatorHandle); + animatorHandle = nullptr; + delete option; +} + +/** + * @tc.name: AnimateImplTest034 + * @tc.desc: Test AnimatorReverse function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest034, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + int32_t ret = AnimatorReverse(nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: AnimateImplTest035 + * @tc.desc: Test AnimatorReverse function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest035, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimatorOption* option = new ArkUI_AnimatorOption(); + ArkUI_AnimatorHandle animatorHandle = CreateAnimator(&context, option); + ASSERT_NE(animatorHandle, nullptr); + ArkUIAnimatorHandle animator = new ArkUIAnimator(); + animatorHandle->animator = animator; + int32_t ret = AnimatorReverse(animatorHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + + DisposeAnimator(animatorHandle); + animatorHandle = nullptr; + delete option; +} + +/** + * @tc.name: AnimateImplTest036 + * @tc.desc: Test KeyframeAnimateTo function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest036, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + int32_t ret = KeyframeAnimateTo(nullptr, nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: AnimateImplTest037 + * @tc.desc: Test KeyframeAnimateTo function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest037, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_KeyframeAnimateOption* option = new ArkUI_KeyframeAnimateOption(); + struct ArkUI_KeyframeState keyframe = {0, nullptr, nullptr, nullptr}; + option->keyframes.push_back(keyframe); + int32_t ret = KeyframeAnimateTo(&context, option); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + delete option; +} + +/** + * @tc.name: AnimateImplTest038 + * @tc.desc: Test AnimateTo function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest038, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + int32_t ret = AnimateTo(nullptr, nullptr, nullptr, nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: AnimateImplTest039 + * @tc.desc: Test AnimateTo function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest039, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimateOption* option = new ArkUI_AnimateOption(); + ArkUI_ContextCallback* update = new ArkUI_ContextCallback(); + update->callback = AnimateCompleteCallback; + ArkUI_AnimateCompleteCallback* complete = new ArkUI_AnimateCompleteCallback(); + int32_t ret = AnimateTo(&context, option, update, complete); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + delete option; + delete update; + delete complete; +} + +/** + * @tc.name: AnimateImplTest040 + * @tc.desc: Test AnimateTo function. + * @tc.type: FUNC + */ +HWTEST_F(AnimateImplTest, AnimateImplTest040, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + struct ArkUI_Context context= {1}; + ArkUI_AnimateOption* option = new ArkUI_AnimateOption(); + ArkUI_CurveHandle curve = new ArkUI_Curve(); + ArkUI_ExpectedFrameRateRange* expectedFrameRateRange = new ArkUI_ExpectedFrameRateRange(); + option->iCurve = curve; + option->expectedFrameRateRange = expectedFrameRateRange; + ArkUI_ContextCallback* update = new ArkUI_ContextCallback(); + update->callback = AnimateCompleteCallback; + ArkUI_AnimateCompleteCallback* complete = new ArkUI_AnimateCompleteCallback(); + complete->type = ARKUI_FINISH_CALLBACK_LOGICALLY; + complete->callback = AnimateCompleteCallback; + int32_t userData = 0; + complete->userData = (void *)userData; + int32_t ret = AnimateTo(&context, option, update, complete); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + delete option; + delete curve; + delete update; + delete complete; +} \ No newline at end of file diff --git a/test/unittest/interfaces/dialog_model_test.cpp b/test/unittest/interfaces/dialog_model_test.cpp new file mode 100644 index 00000000000..25681e7d3c7 --- /dev/null +++ b/test/unittest/interfaces/dialog_model_test.cpp @@ -0,0 +1,494 @@ +/* + * Copyright (c) 2024 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 "animate_impl.h" +#include "core/interfaces/arkoala/arkoala_api.h" +#include "dialog_model.h" +#include "error_code.h" +#include "event_converter.h" +#include "gtest/gtest.h" +#include "native_animate.h" +#include "native_interface.h" +#include "native_node.h" +#include "node_extened.h" +#include "node_model.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Ace::DialogModel; + +class DialogModelTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; +}; + +bool OnWillDismissEvent(int32_t reason) +{ + return true; +} + +/** + * @tc.name: DialogModelTest001 + * @tc.desc: Test Create function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest001, TestSize.Level1) +{ + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_EQ(nativeDialogHandle, nullptr); + + Dispose(nativeDialogHandle); +} + +/** + * @tc.name: DialogModelTest002 + * @tc.desc: Test Create function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest002, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest003 + * @tc.desc: Test SetContent function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest003, TestSize.Level1) +{ + int32_t ret = SetContent(nullptr, nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest004 + * @tc.desc: Test SetContent function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest004, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + ArkUI_NodeHandle nodeHandle = new ArkUI_Node(); + int32_t ret = SetContent(nativeDialogHandle, nodeHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; + delete nodeHandle; +} + +/** + * @tc.name: DialogModelTest005 + * @tc.desc: Test RemoveContent function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest005, TestSize.Level1) +{ + int32_t ret = RemoveContent(nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest006 + * @tc.desc: Test RemoveContent function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest006, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = RemoveContent(nativeDialogHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest007 + * @tc.desc: Test SetContentAlignment function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest007, TestSize.Level1) +{ + int32_t ret = SetContentAlignment(nullptr, 0, 0.0f, 0.0f); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest008 + * @tc.desc: Test SetContentAlignment function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest008, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = SetContentAlignment(nativeDialogHandle, 0, 0.0f, 0.0f); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest009 + * @tc.desc: Test ResetContentAlignment function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest009, TestSize.Level1) +{ + int32_t ret = ResetContentAlignment(nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest010 + * @tc.desc: Test SetContentAlignment function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest010, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = ResetContentAlignment(nativeDialogHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest011 + * @tc.desc: Test SetModalMode function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest011, TestSize.Level1) +{ + int32_t ret = SetModalMode(nullptr, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest012 + * @tc.desc: Test SetModalMode function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest012, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = SetModalMode(nativeDialogHandle, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest013 + * @tc.desc: Test SetAutoCancel function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest013, TestSize.Level1) +{ + int32_t ret = SetAutoCancel(nullptr, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest014 + * @tc.desc: Test SetAutoCancel function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest014, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = SetAutoCancel(nativeDialogHandle, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest015 + * @tc.desc: Test SetMask function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest015, TestSize.Level1) +{ + int32_t ret = SetMask(nullptr, 0, nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest016 + * @tc.desc: Test SetMask function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest016, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + ArkUI_Rect rect = {0.0f, 0.0f, 0.0f, 0.0f}; + int32_t ret = SetMask(nativeDialogHandle, 0, &rect); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest017 + * @tc.desc: Test SetMask function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest017, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = SetMask(nativeDialogHandle, 0, nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest018 + * @tc.desc: Test SetBackgroundColor function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest018, TestSize.Level1) +{ + int32_t ret = SetBackgroundColor(nullptr, 0); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest019 + * @tc.desc: Test SetBackgroundColor function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest019, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = SetBackgroundColor(nativeDialogHandle, 0); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest020 + * @tc.desc: Test SetCornerRadius function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest020, TestSize.Level1) +{ + int32_t ret = SetCornerRadius(nullptr, 0.0f, 0.0f, 0.0f, 0.0f); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest021 + * @tc.desc: Test SetCornerRadius function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest021, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = SetCornerRadius(nativeDialogHandle, 0.0f, 0.0f, 0.0f, 0.0f); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest022 + * @tc.desc: Test SetGridColumnCount function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest022, TestSize.Level1) +{ + int32_t ret = SetGridColumnCount(nullptr, 0); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest023 + * @tc.desc: Test SetGridColumnCount function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest023, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = SetGridColumnCount(nativeDialogHandle, 0); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest024 + * @tc.desc: Test EnableCustomStyle function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest024, TestSize.Level1) +{ + int32_t ret = EnableCustomStyle(nullptr, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest025 + * @tc.desc: Test EnableCustomStyle function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest025, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = EnableCustomStyle(nativeDialogHandle, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest026 + * @tc.desc: Test EnableCustomAnimation function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest026, TestSize.Level1) +{ + int32_t ret = EnableCustomAnimation(nullptr, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest027 + * @tc.desc: Test EnableCustomAnimation function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest027, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = EnableCustomAnimation(nativeDialogHandle, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest028 + * @tc.desc: Test Show function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest028, TestSize.Level1) +{ + int32_t ret = Show(nullptr, true); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest029 + * @tc.desc: Test Show function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest029, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = Show(nativeDialogHandle, false); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest030 + * @tc.desc: Test Close function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest030, TestSize.Level1) +{ + int32_t ret = Close(nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest031 + * @tc.desc: Test Close function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest031, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + int32_t ret = Close(nativeDialogHandle); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} + +/** + * @tc.name: DialogModelTest032 + * @tc.desc: Test RegisterOnWillDismiss function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest032, TestSize.Level1) +{ + int32_t ret = RegisterOnWillDismiss(nullptr, nullptr); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID); +} + +/** + * @tc.name: DialogModelTest033 + * @tc.desc: Test RegisterOnWillDismiss function. + * @tc.type: FUNC + */ +HWTEST_F(DialogModelTest, DialogModelTest033, TestSize.Level1) +{ + ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl()); + ArkUI_NativeDialogHandle nativeDialogHandle = Create(); + ASSERT_NE(nativeDialogHandle, nullptr); + ArkUI_OnWillDismissEvent eventHandler = OnWillDismissEvent; + int32_t ret = RegisterOnWillDismiss(nativeDialogHandle, eventHandler); + ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR); + Dispose(nativeDialogHandle); + nativeDialogHandle = nullptr; +} \ No newline at end of file From 9c25a8a51f0cdc5d2ffb2507b81e3a2a8cd7b661 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 19:50:05 +0800 Subject: [PATCH 053/221] menu tdd fix Signed-off-by: jiangzhijun8 Change-Id: Ieedc56b96d12cefd49c7b8f3cf80884d378449c7 --- .../unittest/core/pattern/menu/menuitemgroup_test_ng.cpp | 9 +++++++-- test/unittest/core/pattern/menu/menuwrapper_test_ng.cpp | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/unittest/core/pattern/menu/menuitemgroup_test_ng.cpp b/test/unittest/core/pattern/menu/menuitemgroup_test_ng.cpp index 0099ab19a27..622222f80f5 100644 --- a/test/unittest/core/pattern/menu/menuitemgroup_test_ng.cpp +++ b/test/unittest/core/pattern/menu/menuitemgroup_test_ng.cpp @@ -591,8 +591,13 @@ HWTEST_F(MenuItemGroupTestNg, MenuItemGroupPattern003, TestSize.Level1) bool press = true; int32_t index = 0; - menuItemGroupPattern2->OnIntItemPressed(0, press); + menuItemGroupPattern2->OnIntItemPressed(index, press); + auto needFooterDivider = menuItemGroup1->GetPaintProperty()->propNeedFooterDivider_; + EXPECT_EQ(needFooterDivider, false); + index = -1; - menuItemGroupPattern2->OnIntItemPressed(-1, press); + menuItemGroupPattern2->OnIntItemPressed(index, press); + auto needHeaderDivider = menuItemGroup3->GetPaintProperty()->propNeedHeaderDivider_; + EXPECT_EQ(needHeaderDivider, false); } } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/menu/menuwrapper_test_ng.cpp b/test/unittest/core/pattern/menu/menuwrapper_test_ng.cpp index 26bb0de9d0c..fbb344c09a1 100644 --- a/test/unittest/core/pattern/menu/menuwrapper_test_ng.cpp +++ b/test/unittest/core/pattern/menu/menuwrapper_test_ng.cpp @@ -725,8 +725,11 @@ HWTEST_F(MenuWrapperTestNg, MenuWrapperPatternTestNg013, TestSize.Level1) wrapperPattern->SetLastTouchItem(menuItemNode2); wrapperPattern->currentTouchItem_ = menuItemNode1; wrapperPattern->HandleInteraction(info); + EXPECT_EQ(wrapperPattern->lastTouchItem_, wrapperPattern->currentTouchItem_); + wrapperPattern->currentTouchItem_ = menuItemNode2; wrapperPattern->HandleInteraction(info); + EXPECT_EQ(wrapperPattern->lastTouchItem_, wrapperPattern->currentTouchItem_); } /** @@ -909,7 +912,9 @@ HWTEST_F(MenuWrapperTestNg, MenuWrapperPatternTestNg017, TestSize.Level1) } auto layoutWrapper = layoutWrapperNode->GetOrCreateChildByIndex(0, true); ASSERT_NE(layoutWrapper, nullptr); - wrapperPattern->SetHotAreas(layoutWrapper); + auto pipeline = MockPipelineContext::GetCurrent(); + pipeline->instanceId_ = MIN_SUBCONTAINER_ID; + EXPECT_FALSE(wrapperPattern->OnDirtyLayoutWrapperSwap(layoutWrapper, configDirtySwap)); } /** From fdb0525100b0f058951f0c7c102dd75e02a31399 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 10:29:45 +0800 Subject: [PATCH 054/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp index ffcc141ac5d..84d51dc606c 100644 --- a/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp +++ b/test/unittest/core/pattern/rich_editor/rich_editor_keyboard_shortcut_test_ng.cpp @@ -1355,6 +1355,8 @@ HWTEST_F(RichEditorKeyboardShortcutTestNg, SetCustomKeyboard001, TestSize.Level1 richEditorModel.Create(); auto func = []() {}; richEditorModel.SetCustomKeyboard(func, true); - EXPECT_TRUE(ViewStackProcessor::GetInstance()->GetMainFrameNode()->GetPattern()->keyboardAvoidance_); + bool result = + ViewStackProcessor::GetInstance()->GetMainFrameNode()->GetPattern()->keyboardAvoidance_; + EXPECT_TRUE(result); } } // namespace OHOS::Ace::NG \ No newline at end of file From 53c48035692d43823963dddaf6b7768bcec5ba55 Mon Sep 17 00:00:00 2001 From: javii Date: Wed, 17 Jul 2024 14:48:59 +0800 Subject: [PATCH 055/221] dvsync on disable Signed-off-by: javii --- .../core/components_ng/render/adapter/rosen_window.cpp | 4 +++- frameworks/core/pipeline/pipeline_base.cpp | 4 ++++ frameworks/core/pipeline/pipeline_base.h | 2 ++ frameworks/core/pipeline_ng/pipeline_context.cpp | 8 ++++---- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frameworks/core/components_ng/render/adapter/rosen_window.cpp b/frameworks/core/components_ng/render/adapter/rosen_window.cpp index cd9f470fc70..e8c24bfd25a 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_window.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_window.cpp @@ -131,7 +131,9 @@ void RosenWindow::SetUiDvsyncSwitch(bool dvsyncSwitch) } else { ACE_SCOPED_TRACE("disable dvsync"); } - rsWindow_->SetUiDvsyncSwitch(dvsyncSwitch); + if (dvsyncSwitch) { + rsWindow_->SetUiDvsyncSwitch(dvsyncSwitch); + } } void RosenWindow::RequestFrame() diff --git a/frameworks/core/pipeline/pipeline_base.cpp b/frameworks/core/pipeline/pipeline_base.cpp index bbed33b0a08..a1cc4027678 100644 --- a/frameworks/core/pipeline/pipeline_base.cpp +++ b/frameworks/core/pipeline/pipeline_base.cpp @@ -681,6 +681,10 @@ void PipelineBase::OnVsyncEvent(uint64_t nanoTimestamp, uint32_t frameCount) ACE_SCOPED_TRACE("OnVsyncEvent now:%" PRIu64 "", nanoTimestamp); frameCount_ = frameCount; + recvTime_ = GetSysTimestamp(); + compensationValue_ = + nanoTimestamp > static_cast(recvTime_) ? (nanoTimestamp - static_cast(recvTime_)) : 0; + for (auto& callback : subWindowVsyncCallbacks_) { callback.second(nanoTimestamp, frameCount); } diff --git a/frameworks/core/pipeline/pipeline_base.h b/frameworks/core/pipeline/pipeline_base.h index 360861f10ad..2f8c306ebd8 100644 --- a/frameworks/core/pipeline/pipeline_base.h +++ b/frameworks/core/pipeline/pipeline_base.h @@ -1420,6 +1420,8 @@ protected: std::function onFormRecycle_; std::function onFormRecover_; + uint64_t compensationValue_ = 0; + int64_t recvTime_ = 0; std::once_flag displaySyncFlag_; RefPtr uiDisplaySyncManager_; diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index 944e6e90271..a279ae4605d 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -529,12 +529,12 @@ void PipelineContext::FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) ACE_SCOPED_TRACE_COMMERCIAL("UIVsyncTask[timestamp:%" PRIu64 "][vsyncID:%" PRIu64 "][instanceID:%d]", nanoTimestamp, static_cast(frameCount), instanceId_); window_->Lock(); - auto recvTime = GetSysTimestamp(); static const std::string abilityName = AceApplicationInfo::GetInstance().GetProcessName().empty() ? AceApplicationInfo::GetInstance().GetPackageName() : AceApplicationInfo::GetInstance().GetProcessName(); window_->RecordFrameTime(nanoTimestamp, abilityName); - resampleTimeStamp_ = nanoTimestamp - static_cast(window_->GetVSyncPeriod()) + ONE_MS_IN_NS; + resampleTimeStamp_ = nanoTimestamp - static_cast(window_->GetVSyncPeriod()) + ONE_MS_IN_NS -\ + compensationValue_; #ifdef UICAST_COMPONENT_SUPPORTED do { auto container = Container::Current(); @@ -563,7 +563,7 @@ void PipelineContext::FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) #endif } - taskScheduler_->StartRecordFrameInfo(GetCurrentFrameInfo(recvTime, nanoTimestamp)); + taskScheduler_->StartRecordFrameInfo(GetCurrentFrameInfo(recvTime_, nanoTimestamp)); taskScheduler_->FlushTask(); UIObserverHandler::GetInstance().HandleLayoutDoneCallBack(); taskScheduler_->FinishRecordFrameInfo(); @@ -2473,7 +2473,7 @@ void PipelineContext::FlushTouchEvents() } std::list touchPoints; for (const auto& iter : idToTouchPoints) { - lastDispatchTime_[iter.first] = GetVsyncTime(); + lastDispatchTime_[iter.first] = GetVsyncTime() - compensationValue_; auto it = newIdTouchPoints.find(iter.first); if (it != newIdTouchPoints.end()) { touchPoints.emplace_back(it->second); From 8b954822127485e67d841818c7b469ce29c57d99 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 10:53:46 +0800 Subject: [PATCH 056/221] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- test/unittest/core/common/recorder/event_recorder_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index cc860d3da78..4bb23bcebda 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -13,6 +13,8 @@ * limitations under the License. */ +#define private public +#define protected public #include "gtest/gtest.h" #include "interfaces/inner_api/ace/ui_event_observer.h" From ab6f2f42f30018f9242da0eecda7d7a004155ce8 Mon Sep 17 00:00:00 2001 From: zoulinken Date: Sat, 20 Jul 2024 11:07:32 +0800 Subject: [PATCH 057/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlog=5Fwrapper.h?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=86=85uint=5F8=E5=AE=89=E5=85=A8=E9=9A=90?= =?UTF-8?q?=E6=82=A3=20&&=20=E5=8E=BB=E9=99=A4=E6=97=A5=E5=BF=97=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=96=B9=E6=B3=95=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zoulinken --- .../ui_session/include/ui_service_hilog.h | 4 ++-- .../uiservice/include/ui_service_hilog.h | 4 ++-- frameworks/base/log/log_wrapper.h | 16 +++++++--------- .../base/network/download_manager_impl.cpp | 3 +-- interfaces/inner_api/ace/arkui_log.h | 3 +-- .../drawable_descriptor_log.h | 4 ++-- .../form_render/include/form_renderer_hilog.h | 4 ++-- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/adapter/ohos/entrance/ui_session/include/ui_service_hilog.h b/adapter/ohos/entrance/ui_session/include/ui_service_hilog.h index acb4f7bf7d5..98a5e3d43d0 100644 --- a/adapter/ohos/entrance/ui_session/include/ui_service_hilog.h +++ b/adapter/ohos/entrance/ui_session/include/ui_service_hilog.h @@ -22,11 +22,11 @@ #define UISERVICE_LOG_TAG "AceUISession" #define UISERVICE_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) -#define ACE_FMT_PREFIX "[%{public}s(%{public}s:%{public}d)]" +#define ACE_FMT_PREFIX "[%{public}s:%{public}d]" #define PRINT_LOG(level, fmt, ...) \ HILOG_IMPL(LOG_CORE, LOG_##level, UISERVICE_LOG_DOMAIN, UISERVICE_LOG_TAG, ACE_FMT_PREFIX fmt, UISERVICE_FILENAME, \ - __FUNCTION__, __LINE__, ##__VA_ARGS__) + __LINE__, ##__VA_ARGS__) #define LOGE(fmt, ...) PRINT_LOG(ERROR, fmt, ##__VA_ARGS__) #define LOGW(fmt, ...) PRINT_LOG(WARN, fmt, ##__VA_ARGS__) diff --git a/adapter/ohos/services/uiservice/include/ui_service_hilog.h b/adapter/ohos/services/uiservice/include/ui_service_hilog.h index 409909ad2a3..f6ef7da1de7 100644 --- a/adapter/ohos/services/uiservice/include/ui_service_hilog.h +++ b/adapter/ohos/services/uiservice/include/ui_service_hilog.h @@ -22,11 +22,11 @@ #define UISERVICE_LOG_TAG "AceUIService" #define UISERVICE_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) -#define ACE_FMT_PREFIX "[%{public}s(%{public}s:%{public}d)]" +#define ACE_FMT_PREFIX "[%{public}s:%{public}d]" #define PRINT_LOG(level, fmt, ...) \ HILOG_IMPL(LOG_CORE, LOG_##level, UISERVICE_LOG_DOMAIN, UISERVICE_LOG_TAG, \ - ACE_FMT_PREFIX fmt, UISERVICE_FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__) + ACE_FMT_PREFIX fmt, UISERVICE_FILENAME, __LINE__, ##__VA_ARGS__) #define LOGE(fmt, ...) PRINT_LOG(ERROR, fmt, ##__VA_ARGS__) #define LOGW(fmt, ...) PRINT_LOG(WARN, fmt, ##__VA_ARGS__) diff --git a/frameworks/base/log/log_wrapper.h b/frameworks/base/log/log_wrapper.h index 73694b197e6..bd225469388 100644 --- a/frameworks/base/log/log_wrapper.h +++ b/frameworks/base/log/log_wrapper.h @@ -26,10 +26,10 @@ #include "base/utils/system_properties.h" #ifdef ACE_INSTANCE_LOG -#define ACE_FMT_PREFIX "[%{public}s(%{public}s)-(%{public}s)] " +#define ACE_FMT_PREFIX "[%{public}s(%{public}d)-(%{public}s)] " #define ACE_LOG_ID_WITH_REASON , OHOS::Ace::LogWrapper::GetIdWithReason().c_str() #else -#define ACE_FMT_PREFIX "[%{private}s(%{private}s)] " +#define ACE_FMT_PREFIX "[%{private}s(%{private}d)] " #define ACE_LOG_ID_WITH_REASON #endif @@ -40,7 +40,7 @@ constexpr uint32_t APP_DOMAIN = 0xC0D0; #define PRINT_LOG(level, tag, fmt, ...) \ HILOG_IMPL(LOG_CORE, LOG_##level, (tag + ACE_DOMAIN), (OHOS::Ace::g_DOMAIN_CONTENTS_MAP.at(tag)), \ ACE_FMT_PREFIX fmt, OHOS::Ace::LogWrapper::GetBriefFileName(__FILE__), \ - __FUNCTION__ ACE_LOG_ID_WITH_REASON, ##__VA_ARGS__) + __LINE__ ACE_LOG_ID_WITH_REASON, ##__VA_ARGS__) #define PRINT_APP_LOG(level, fmt, ...) HILOG_IMPL(LOG_APP, LOG_##level, APP_DOMAIN, "JSAPP", fmt, ##__VA_ARGS__) #else @@ -49,7 +49,7 @@ constexpr uint32_t APP_DOMAIN = 0xC0D0; if (OHOS::Ace::LogWrapper::JudgeLevel(OHOS::Ace::LogLevel::level)) { \ OHOS::Ace::LogWrapper::PrintLog(OHOS::Ace::LogDomain::FRAMEWORK, OHOS::Ace::LogLevel::level, tag, \ ACE_FMT_PREFIX fmt, OHOS::Ace::LogWrapper::GetBriefFileName(__FILE__), \ - __FUNCTION__ ACE_LOG_ID_WITH_REASON, ##__VA_ARGS__); \ + __LINE__ ACE_LOG_ID_WITH_REASON, ##__VA_ARGS__); \ } \ } while (0) @@ -189,12 +189,10 @@ enum AceLogTag : uint8_t { ACE_MOVING_PHOTO, // C0394C ACE_ARK_COMPONENT, // C0394D ACE_WINDOW, // C0394E - ACE_LIBUV, // C0394F - ACE_SECURITYUIEXTENSION, // C03950 - ACE_INPUTKEYFLOW, // C03951 + ACE_SECURITYUIEXTENSION, // C0394F + ACE_INPUTKEYFLOW, // C03950 - FORM_RENDER = 255, // C039FF FormRenderer - END = 256, // Last one, do not use + FORM_RENDER = 255, // C039FF FormRenderer, last domain, do not add }; ACE_FORCE_EXPORT extern const std::unordered_map g_DOMAIN_CONTENTS_MAP; diff --git a/frameworks/base/network/download_manager_impl.cpp b/frameworks/base/network/download_manager_impl.cpp index 417d038ca07..a4cb836c4be 100644 --- a/frameworks/base/network/download_manager_impl.cpp +++ b/frameworks/base/network/download_manager_impl.cpp @@ -45,8 +45,7 @@ namespace { constexpr int32_t MAXIMUM_WAITING_PERIOD = 2800; #define PRINT_LOG(level, fmt, ...) \ - HILOG_IMPL(LOG_CORE, LOG_##level, 0xD00393A, "DownloadManager", "[%{public}s:%{public}d]" fmt, __FUNCTION__, \ - __LINE__, ##__VA_ARGS__) + HILOG_IMPL(LOG_CORE, LOG_##level, 0xD00393A, "DownloadManager", "[%{public}d]" fmt, __LINE__, ##__VA_ARGS__) \ #define LOGE(fmt, ...) PRINT_LOG(ERROR, fmt, ##__VA_ARGS__) #define LOGW(fmt, ...) PRINT_LOG(WARN, fmt, ##__VA_ARGS__) diff --git a/interfaces/inner_api/ace/arkui_log.h b/interfaces/inner_api/ace/arkui_log.h index 8d51596879e..6529d3bb267 100644 --- a/interfaces/inner_api/ace/arkui_log.h +++ b/interfaces/inner_api/ace/arkui_log.h @@ -19,8 +19,7 @@ #include "hilog/log.h" #define PRINT_LOG(level, fmt, ...) \ - HILOG_IMPL(LOG_CORE, LOG_##level, 0xD003900, "ACE_UIContent", "[%{public}s:%{public}d]" fmt, \ - __FUNCTION__, __LINE__, ##__VA_ARGS__) + HILOG_IMPL(LOG_CORE, LOG_##level, 0xD003900, "ACE_UIContent", "[%{public}d]" fmt, __LINE__, ##__VA_ARGS__) #define LOGE(fmt, ...) PRINT_LOG(ERROR, fmt, ##__VA_ARGS__) #define LOGW(fmt, ...) PRINT_LOG(WARN, fmt, ##__VA_ARGS__) diff --git a/interfaces/inner_api/drawable_descriptor/drawable_descriptor_log.h b/interfaces/inner_api/drawable_descriptor/drawable_descriptor_log.h index e97ec1ba5d2..3cd801cb406 100644 --- a/interfaces/inner_api/drawable_descriptor/drawable_descriptor_log.h +++ b/interfaces/inner_api/drawable_descriptor/drawable_descriptor_log.h @@ -19,8 +19,8 @@ #include "hilog/log.h" #define PRINT_HILOG(level, fmt, ...) \ - HILOG_IMPL(LOG_CORE, LOG_##level, 0xD003900, "AceDrawableDescriptor", "[%{public}s:%{public}d]" fmt, \ - __FUNCTION__, __LINE__, ##__VA_ARGS__) + HILOG_IMPL(LOG_CORE, LOG_##level, 0xD003900, "AceDrawableDescriptor", "[%{public}d]" fmt, \ + __LINE__, ##__VA_ARGS__) #define HILOGE(fmt, ...) PRINT_HILOG(ERROR, fmt, ##__VA_ARGS__) #define HILOGW(fmt, ...) PRINT_HILOG(WARN, fmt, ##__VA_ARGS__) diff --git a/interfaces/inner_api/form_render/include/form_renderer_hilog.h b/interfaces/inner_api/form_render/include/form_renderer_hilog.h index 419aa617d9b..7fd6d5b3c04 100644 --- a/interfaces/inner_api/form_render/include/form_renderer_hilog.h +++ b/interfaces/inner_api/form_render/include/form_renderer_hilog.h @@ -56,8 +56,8 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, FR_LOG_DOMAI #define FR_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) #define PRINT_HILOG(level, fmt, ...) \ - HILOG_IMPL(LOG_CORE, LOG_##level, FR_LOG_DOMAIN, FR_LOG_TAG, "[%{public}s(%{public}s:%{public}d)]" fmt, \ - FR_FILENAME, __FUNCTION__, __LINE__, ##__VA_ARGS__) + HILOG_IMPL(LOG_CORE, LOG_##level, FR_LOG_DOMAIN, FR_LOG_TAG, "[%{public}s:%{public}d]" fmt, \ + FR_FILENAME, __LINE__, ##__VA_ARGS__) #define HILOG_FATAL(fmt, ...) PRINT_HILOG(FATAL, fmt, ##__VA_ARGS__) #define HILOG_ERROR(fmt, ...) PRINT_HILOG(ERROR, fmt, ##__VA_ARGS__) From c3ce9d7ce0facb1a5ced6aecbaa3466287254503 Mon Sep 17 00:00:00 2001 From: Far Date: Sat, 20 Jul 2024 10:57:43 +0800 Subject: [PATCH 058/221] Make FocusToHEadOrTailChild being public. Signed-off-by: Far --- frameworks/core/components_ng/event/focus_hub.h | 2 +- .../core/components_ng/pattern/stage/stage_manager.cpp | 6 ++++-- frameworks/core/components_ng/pattern/stage/stage_manager.h | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frameworks/core/components_ng/event/focus_hub.h b/frameworks/core/components_ng/event/focus_hub.h index 620361e7377..424aabb2378 100644 --- a/frameworks/core/components_ng/event/focus_hub.h +++ b/frameworks/core/components_ng/event/focus_hub.h @@ -1053,6 +1053,7 @@ public: static void ToJsonValue( const RefPtr& hub, std::unique_ptr& json, const InspectorFilter& filter); + bool FocusToHeadOrTailChild(bool isHead); protected: bool OnKeyEvent(const KeyEvent& keyEvent); bool OnKeyEventNode(const KeyEvent& keyEvent); @@ -1069,7 +1070,6 @@ protected: bool CalculateRect(const RefPtr& childNode, RectF& rect) const; bool RequestNextFocus(FocusStep moveStep, const RectF& rect); - bool FocusToHeadOrTailChild(bool isHead); void OnFocus(); void OnFocusNode(); diff --git a/frameworks/core/components_ng/pattern/stage/stage_manager.cpp b/frameworks/core/components_ng/pattern/stage/stage_manager.cpp index e289f135117..03c9daf1776 100644 --- a/frameworks/core/components_ng/pattern/stage/stage_manager.cpp +++ b/frameworks/core/components_ng/pattern/stage/stage_manager.cpp @@ -492,7 +492,7 @@ void StageManager::FirePageHide(const RefPtr& node, PageTransitionType t context->MarkNeedFlushMouseEvent(); } -void StageManager::FirePageShow(const RefPtr& node, PageTransitionType transitionType) +void StageManager::FirePageShow(const RefPtr& node, PageTransitionType transitionType, bool needFocus) { auto pageNode = DynamicCast(node); CHECK_NULL_VOID(pageNode); @@ -500,7 +500,9 @@ void StageManager::FirePageShow(const RefPtr& node, PageTransitionType t auto pagePattern = pageNode->GetPattern(); CHECK_NULL_VOID(pagePattern); - pagePattern->FocusViewShow(); + if (needFocus) { + pagePattern->FocusViewShow(); + } pagePattern->OnShow(); // With or without a page transition, we need to make the coming page visible first pagePattern->ProcessShowState(); diff --git a/frameworks/core/components_ng/pattern/stage/stage_manager.h b/frameworks/core/components_ng/pattern/stage/stage_manager.h index 55803749f07..0636209c3c5 100644 --- a/frameworks/core/components_ng/pattern/stage/stage_manager.h +++ b/frameworks/core/components_ng/pattern/stage/stage_manager.h @@ -51,7 +51,8 @@ public: void PageChangeCloseKeyboard(); static void FirePageHide(const RefPtr& node, PageTransitionType transitionType = PageTransitionType::NONE); - static void FirePageShow(const RefPtr& node, PageTransitionType transitionType = PageTransitionType::NONE); + static void FirePageShow(const RefPtr& node, PageTransitionType transitionType = PageTransitionType::NONE, + bool needFocus = true); virtual RefPtr GetLastPage() const; RefPtr GetPageById(int32_t pageId); From 05564c06812cfe67943974d89c3eb1c214625291 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 11:15:37 +0800 Subject: [PATCH 059/221] =?UTF-8?q?=E9=97=A8=E7=A6=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- test/unittest/core/common/recorder/event_recorder_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index 4bb23bcebda..2105baf738b 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -658,9 +658,8 @@ HWTEST_F(EventRecorderTest, SetFocusContainerInfo002, TestSize.Level1) */ HWTEST_F(EventRecorderTest, Init001, TestSize.Level1) { - std::string config = ""; Recorder::EventConfig* config = new Recorder::EventConfig(); - config->Init(config); + config->Init(""); EXPECT_EQ(!JsonUtil::ParseJsonString(config)->IsValid(), true); } From 5d96d5d4f433bab3662b9cab4465048160ece3fe Mon Sep 17 00:00:00 2001 From: kangshihui Date: Sat, 20 Jul 2024 11:26:42 +0800 Subject: [PATCH 060/221] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=90=8E=EF=BC=8C=E8=BE=93=E5=85=A5=E6=B3=95?= =?UTF-8?q?=E6=94=B6=E8=B5=B7=E5=BB=B6=E8=BF=9F=20Signed-off-by:kangshihui?= =?UTF-8?q??= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I208bc3dda26e041a67284afbb53345c263af60c7 --- frameworks/core/components_ng/pattern/stage/stage_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/core/components_ng/pattern/stage/stage_manager.cpp b/frameworks/core/components_ng/pattern/stage/stage_manager.cpp index e655306b91d..08054f42cd6 100644 --- a/frameworks/core/components_ng/pattern/stage/stage_manager.cpp +++ b/frameworks/core/components_ng/pattern/stage/stage_manager.cpp @@ -386,6 +386,7 @@ bool StageManager::PopPageToIndex(int32_t index, bool needShowNext, bool needTra FirePageShow(newPageNode, needTransition ? PageTransitionType::ENTER_POP : PageTransitionType::NONE); inPageNode = AceType::DynamicCast(newPageNode); } + PageChangeCloseKeyboard(); AddPageTransitionTrace(outPageNode, inPageNode); FireAutoSave(outPageNode, inPageNode); From ca0e44b2f172a2bc6ca62bce2abd205a715113dd Mon Sep 17 00:00:00 2001 From: zhouyan Date: Fri, 19 Jul 2024 08:36:30 +0000 Subject: [PATCH 061/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drtl=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8B=E5=AD=97=E4=BD=93=E5=A4=A7=E5=B0=8F=E8=B6=85=E8=BF=87?= =?UTF-8?q?3=E6=A1=A3=E5=90=8E=E5=9B=9B=E4=B8=AA=E7=82=B9=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=8D=E6=AD=A3=E7=A1=AE=E5=92=8C=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyan Change-Id: I61b658bf37b117886cc52d4422e6ba8c5097e028 --- .../select_overlay/select_overlay_paint_method.cpp | 10 ++++++---- .../text/multiple_paragraph_layout_algorithm.cpp | 2 +- .../pattern/text_field/text_field_pattern.cpp | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/frameworks/core/components_ng/pattern/select_overlay/select_overlay_paint_method.cpp b/frameworks/core/components_ng/pattern/select_overlay/select_overlay_paint_method.cpp index f19584e2544..e542b8b1c89 100644 --- a/frameworks/core/components_ng/pattern/select_overlay/select_overlay_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/select_overlay/select_overlay_paint_method.cpp @@ -25,6 +25,7 @@ namespace OHOS::Ace::NG { constexpr float AGING_MIN_SCALE = 1.75f; +constexpr float HALF = 2.0f; void SelectOverlayPaintMethod::UpdateOverlayModifier(PaintWrapper* paintWrapper) { CHECK_NULL_VOID(paintWrapper); @@ -39,12 +40,13 @@ void SelectOverlayPaintMethod::UpdateOverlayModifier(PaintWrapper* paintWrapper) auto top = padding.Top().ConvertToPx(); auto sideWidth = textOverlayTheme->GetMenuToolbarHeight().ConvertToPx() - padding.Top().ConvertToPx() - padding.Bottom().ConvertToPx(); - auto buttonRadius = sideWidth / 2.0; - auto offset = isReversePaint_ ? defaultMenuStartOffset_ + OffsetF(buttonRadius + left, buttonRadius + top) : - defaultMenuEndOffset_ + OffsetF(-buttonRadius - right, buttonRadius + top); + auto buttonRadius = sideWidth / HALF; + auto tempY = static_cast(buttonRadius + top); if (GreatOrEqual(pipeline->GetFontScale(), AGING_MIN_SCALE)) { - offset = defaultMenuEndOffset_ + OffsetF(-buttonRadius - right, selectMenuHeight_ / 2.0f); + tempY = static_cast(selectMenuHeight_ / HALF); } + auto offset = isReversePaint_ ? defaultMenuStartOffset_ + OffsetF(static_cast(buttonRadius + left), tempY) + : defaultMenuEndOffset_ + OffsetF(static_cast(-buttonRadius - right), tempY); CheckCirclesAndBackArrowIsShown(); CheckHasExtensionMenu(); diff --git a/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.cpp index abc7a51a918..60bf77c9509 100644 --- a/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.cpp @@ -344,8 +344,8 @@ ParagraphStyle MultipleParagraphLayoutAlgorithm::GetParagraphStyle( .fontLocale = Localization::GetInstance()->GetFontLocale(), .wordBreak = textStyle.GetWordBreak(), .ellipsisMode = textStyle.GetEllipsisMode(), - .textOverflow = textStyle.GetTextOverflow(), .lineBreakStrategy = textStyle.GetLineBreakStrategy(), + .textOverflow = textStyle.GetTextOverflow(), .indent = textStyle.GetTextIndent() }; } diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index df3485e1dbe..edf7cb3877e 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -16,6 +16,7 @@ #include "core/components_ng/pattern/text_field/text_field_pattern.h" #include +#include #include #include #include @@ -135,7 +136,7 @@ constexpr uint32_t RECORD_MAX_LENGTH = 20; constexpr uint32_t OBSCURE_SHOW_TICKS = 1; constexpr Dimension ERROR_TEXT_TOP_MARGIN = 8.0_vp; constexpr Dimension ERROR_TEXT_BOTTOM_MARGIN = 8.0_vp; -constexpr uint32_t FIND_TEXT_ZERO_INDEX = 1; +constexpr int32_t FIND_TEXT_ZERO_INDEX = 1; constexpr char16_t OBSCURING_CHARACTER = u'•'; constexpr char16_t OBSCURING_CHARACTER_FOR_AR = u'*'; const std::string NEWLINE = "\n"; @@ -1413,8 +1414,8 @@ void TextFieldPattern::HandleOnSelectAll(bool isKeyEvent, bool inlineStyle, bool TAG_LOGI(AceLogTag::ACE_TEXT_FIELD, "HandleOnSelectAll"); auto textSize = static_cast(contentController_->GetWideText().length()); if (inlineStyle) { - if (static_cast(contentController_->GetWideText().rfind(L".")) < textSize - FIND_TEXT_ZERO_INDEX) { - textSize = contentController_->GetWideText().rfind(L"."); + if (static_cast(contentController_->GetWideText().rfind(L'.')) < textSize - FIND_TEXT_ZERO_INDEX) { + textSize = static_cast(contentController_->GetWideText().rfind(L'.')); } UpdateSelection(0, textSize); } else { From 8ed7a1383613bc38a9e8cf05f4b84f0a5471fda9 Mon Sep 17 00:00:00 2001 From: hongzexuan Date: Sat, 20 Jul 2024 11:30:11 +0800 Subject: [PATCH 062/221] revert color Signed-off-by: hongzexuan Change-Id: I4c53ef13cd3137107fe8757530d83d88b110d35c --- .../engine/jsi/nativeModule/arkts_utils.cpp | 9 ++++----- .../declarative_frontend/jsview/js_view_abstract.cpp | 5 ++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.cpp b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.cpp index 2a359dd861f..e86492bf8a2 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.cpp +++ b/frameworks/bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.cpp @@ -79,7 +79,7 @@ uint32_t ArkTSUtils::ColorAlphaAdapt(uint32_t origin) bool ArkTSUtils::ParseJsColor(const EcmaVM* vm, const Local& value, Color& result) { - if (value->IsNumber() && value->IntegerValue(vm) >= 0) { + if (value->IsNumber()) { result = Color(value->Uint32Value(vm)); return true; } @@ -102,7 +102,7 @@ bool ArkTSUtils::ParseJsSymbolColorAlpha(const EcmaVM* vm, const LocalIsNumber() && !value->IsString(vm) && !value->IsObject(vm)) { return false; } - if (value->IsNumber() && value->IntegerValue(vm) >= 0) { + if (value->IsNumber()) { result = Color(ColorAlphaAdapt(value->Uint32Value(vm))); } else if (value->IsString(vm)) { Color::ParseColorString(value->ToString(vm)->ToString(vm), result); @@ -114,7 +114,7 @@ bool ArkTSUtils::ParseJsSymbolColorAlpha(const EcmaVM* vm, const Local& value, Color& result) { - if (value->IsNumber() && value->IntegerValue(vm) >= 0) { + if (value->IsNumber()) { result = Color(ColorAlphaAdapt(value->Uint32Value(vm))); return true; } @@ -134,8 +134,7 @@ bool ArkTSUtils::ParseJsColorAlpha( return false; } if (value->IsNumber()) { - result = value->IntegerValue(vm) >= 0 ? Color(ColorAlphaAdapt(value->Uint32Value(vm))) : - defaultColor; + result = Color(ColorAlphaAdapt(value->Uint32Value(vm))); return true; } if (value->IsString(vm)) { diff --git a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp index 8a883e439e2..bdb773ec19b 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_view_abstract.cpp @@ -5522,7 +5522,7 @@ bool JSViewAbstract::ParseJsObjColorFromResource(const JSRef &jsObj, C bool JSViewAbstract::ParseJsColor(const JSRef& jsValue, Color& result) { - if (jsValue->IsNumber() && jsValue->ToNumber() >= 0) { + if (jsValue->IsNumber()) { result = Color(ColorAlphaAdapt(jsValue->ToNumber())); return true; } @@ -5538,8 +5538,7 @@ bool JSViewAbstract::ParseJsColor(const JSRef& jsValue, Color& result) bool JSViewAbstract::ParseJsColor(const JSRef& jsValue, Color& result, const Color& defaultColor) { if (jsValue->IsNumber()) { - result = jsValue->ToNumber() >= 0 ? Color(ColorAlphaAdapt(jsValue->ToNumber())) : - defaultColor; + result = Color(ColorAlphaAdapt(jsValue->ToNumber())); return true; } if (jsValue->IsString()) { From bc19034a64dcffdb2622b0fd8bdebcf752666b7d Mon Sep 17 00:00:00 2001 From: luoweibin Date: Sat, 20 Jul 2024 03:33:59 +0000 Subject: [PATCH 063/221] fix failed tdd Signed-off-by: luoweibin Change-Id: I3869139125fa46dd826db053471ee3c7b839b048 --- .../components_ng/pattern/scroll/scroll_layout_algorithm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/scroll/scroll_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/scroll/scroll_layout_algorithm.cpp index c3362fb1da6..b547f7356e8 100644 --- a/frameworks/core/components_ng/pattern/scroll/scroll_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/scroll/scroll_layout_algorithm.cpp @@ -111,7 +111,7 @@ void ScrollLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) auto scrollNode = layoutWrapper->GetHostNode(); auto geometryNode = layoutWrapper->GetGeometryNode(); auto childWrapper = layoutWrapper->GetOrCreateChildByIndex(0); - CHECK_NULL_VOID((scrollNode || geometryNode || childWrapper)); + CHECK_NULL_VOID((scrollNode && geometryNode && childWrapper)); auto scrollPattern = AceType::DynamicCast(scrollNode->GetPattern()); auto childGeometryNode = childWrapper->GetGeometryNode(); CHECK_NULL_VOID(childGeometryNode); From e8f8a944a8e4bddf8f63f5e1bcdb625207a59c5f Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 11:41:49 +0800 Subject: [PATCH 064/221] =?UTF-8?q?=E9=97=A8=E7=A6=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- test/unittest/core/common/recorder/event_recorder_test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index 2105baf738b..d633212367c 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -660,7 +660,6 @@ HWTEST_F(EventRecorderTest, Init001, TestSize.Level1) { Recorder::EventConfig* config = new Recorder::EventConfig(); config->Init(""); - EXPECT_EQ(!JsonUtil::ParseJsonString(config)->IsValid(), true); } /** From b4f013bdfefd09f67d43da90cf003c4583895ca9 Mon Sep 17 00:00:00 2001 From: c30016310 Date: Sat, 20 Jul 2024 11:30:21 +0800 Subject: [PATCH 065/221] update whole text change for search cancel button Signed-off-by: c30016310 Change-Id: Ic0036de95e6e27a1ffa1acb6c89729e90c621b5c --- .../core/components_ng/pattern/search/search_model_ng.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/search/search_model_ng.cpp b/frameworks/core/components_ng/pattern/search/search_model_ng.cpp index 94f2c784d4b..7634ddee86d 100644 --- a/frameworks/core/components_ng/pattern/search/search_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/search/search_model_ng.cpp @@ -521,7 +521,7 @@ void SearchModelNG::SetOnChange(std::function(pattern); CHECK_NULL_VOID(searchPattern); - searchPattern->UpdateChangeEvent(value); + searchPattern->UpdateChangeEvent(value + previewText.value); }; eventHub->SetOnChange(std::move(searchChangeFunc)); } @@ -1535,7 +1535,7 @@ void SearchModelNG::SetOnChange(FrameNode* frameNode, std::function(pattern); CHECK_NULL_VOID(searchPattern); - searchPattern->UpdateChangeEvent(value); + searchPattern->UpdateChangeEvent(value + previewText.value); }; eventHub->SetOnChange(std::move(searchChangeFunc)); } From cc618a5119f805ea227007863e1018b668ae8460 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 12:05:42 +0800 Subject: [PATCH 066/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- test/unittest/core/common/recorder/event_recorder_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index d633212367c..b1701cd9e59 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -750,7 +750,7 @@ HWTEST_F(EventRecorderTest, Clear001, TestSize.Level1) { Recorder::ExposureCfg cfg; Recorder::NodeDataCache::Get().Clear(""); - EXPECT_TRUE(Recorder::NodeDataCache::Get().container_.empty()); + EXPECT_TRUE(Recorder::NodeDataCache::Get().container_->empty()); } /** @@ -762,6 +762,6 @@ HWTEST_F(EventRecorderTest, GetNodeData001, TestSize.Level1) { std::unordered_map nodes; Recorder::NodeDataCache::Get().GetNodeData("", nodes); - EXPECT_TRUE(Recorder::NodeDataCache::Get().container_.empty()); + EXPECT_TRUE(Recorder::NodeDataCache::Get().container_->empty()); } } // namespace OHOS::Ace From dcba06120996eaeec8e3ea04ea069d8f099ac3c6 Mon Sep 17 00:00:00 2001 From: aryawang Date: Sat, 20 Jul 2024 04:22:05 +0000 Subject: [PATCH 067/221] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=BB=A4=E9=95=9C?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aryawang Change-Id: I780cce0a514a34d339429154f6477be76004890d --- .../core/components_ng/svg/parse/svg_fe_gaussian_blur.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/svg/parse/svg_fe_gaussian_blur.cpp b/frameworks/core/components_ng/svg/parse/svg_fe_gaussian_blur.cpp index f133ed9b031..8911bc79f0a 100644 --- a/frameworks/core/components_ng/svg/parse/svg_fe_gaussian_blur.cpp +++ b/frameworks/core/components_ng/svg/parse/svg_fe_gaussian_blur.cpp @@ -34,7 +34,7 @@ void SvgFeGaussianBlur::OnAsImageFilter(std::shared_ptr& imageFil { imageFilter = MakeImageFilter(feAttr_.in, imageFilter, resultHash); RSRect filterRect(effectFilterArea_.Left(), effectFilterArea_.Top(), - effectFilterArea_.Width(), effectFilterArea_.Height()); + effectFilterArea_.Right(), effectFilterArea_.Bottom()); imageFilter = RSRecordingImageFilter::CreateBlurImageFilter( gaussianBlurAttr_.stdDeviationX, gaussianBlurAttr_.stdDeviationY, RSTileMode::DECAL, imageFilter, RSImageBlurType::GAUSS, filterRect); From 1bb98769e8665da3448e89c970b9bc7383b6c9d2 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 12:35:01 +0800 Subject: [PATCH 068/221] =?UTF-8?q?=E9=97=A8=E7=A6=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../core/pattern/text_picker/text_picker_pattern_test_ng.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp b/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp index 7c08a799c5b..641029f68bb 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp @@ -1751,7 +1751,7 @@ HWTEST_F(TextPickerPatternTestNg, LinearFontSize001, TestSize.Level1) { InitTextPickerPatternTestNg(); Dimension dimension = Dimension(FONT_SIZE_10); - Dimension dimension1 = textPickerColumnPattern_->LinearFontSize(dimension1, dimension1, 1); + Dimension dimension1 = textPickerColumnPattern_->LinearFontSize(dimension, dimension, 1); EXPECT_TRUE(dimension < dimension1); } @@ -1764,7 +1764,7 @@ HWTEST_F(TextPickerPatternTestNg, LinearFontSize002, TestSize.Level1) { InitTextPickerPatternTestNg(); Dimension dimension = Dimension(FONT_SIZE_10); - Dimension dimension1 = textPickerColumnPattern_->LinearFontSize(dimension1, dimension1, 2); + Dimension dimension1 = textPickerColumnPattern_->LinearFontSize(dimension, dimension, 2); EXPECT_TRUE(dimension < dimension1); } From dff2a40d01aa8492d56f6f6cd79fb3771134bf33 Mon Sep 17 00:00:00 2001 From: yangcan Date: Sat, 20 Jul 2024 12:40:49 +0800 Subject: [PATCH 069/221] =?UTF-8?q?=E6=96=B0=E5=A2=9Eswiper/tabs=E7=9A=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=88=87=E6=8D=A2=E5=95=86=E7=94=A8=E6=B3=B3?= =?UTF-8?q?=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangcan Change-Id: Ib0433b850ec212471a7096450edcd43b86643850 --- adapter/ohos/osal/ace_trace.cpp | 23 +++++++++++++++++ adapter/preview/osal/ace_trace.cpp | 2 ++ frameworks/base/log/ace_trace.h | 2 ++ .../pattern/swiper/swiper_pattern.cpp | 25 +++++++++++-------- .../pattern/tabs/tabs_model_ng.cpp | 2 +- test/mock/base/mock_ace_trace.cpp | 4 +++ 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/adapter/ohos/osal/ace_trace.cpp b/adapter/ohos/osal/ace_trace.cpp index 0ed4c847343..fcdf210d40b 100644 --- a/adapter/ohos/osal/ace_trace.cpp +++ b/adapter/ohos/osal/ace_trace.cpp @@ -25,6 +25,7 @@ namespace OHOS::Ace { namespace { static constexpr uint64_t ACE_TRACE_COMMERCIAL = HITRACE_TAG_ACE | HITRACE_TAG_COMMERCIAL; +static constexpr uint64_t ANIMATION_TRACE_COMMERCIAL = HITRACE_TAG_ANIMATION | HITRACE_TAG_COMMERCIAL; } void AceTraceBegin(const char* name) @@ -71,6 +72,28 @@ void AceAsyncTraceEnd(int32_t taskId, const char* name, bool isAnimationTrace) } } +void AceAsyncTraceBeginCommercial(int32_t taskId, const char* name, bool isAnimationTrace) +{ + CHECK_NULL_VOID(name); + std::string nameStr(name); + if (isAnimationTrace) { + StartAsyncTrace(ANIMATION_TRACE_COMMERCIAL, nameStr, taskId); + } else { + StartAsyncTrace(ACE_TRACE_COMMERCIAL, nameStr, taskId); + } +} + +void AceAsyncTraceEndCommercial(int32_t taskId, const char* name, bool isAnimationTrace) +{ + CHECK_NULL_VOID(name); + std::string nameStr(name); + if (isAnimationTrace) { + FinishAsyncTrace(ANIMATION_TRACE_COMMERCIAL, nameStr, taskId); + } else { + FinishAsyncTrace(ACE_TRACE_COMMERCIAL, nameStr, taskId); + } +} + void AceCountTrace(const char *key, int32_t count) { CHECK_NULL_VOID(key); diff --git a/adapter/preview/osal/ace_trace.cpp b/adapter/preview/osal/ace_trace.cpp index 6e8c767ec99..a0c48a8ecd7 100644 --- a/adapter/preview/osal/ace_trace.cpp +++ b/adapter/preview/osal/ace_trace.cpp @@ -22,5 +22,7 @@ void AceTraceBeginCommercial(const char* name) {} void AceTraceEndCommercial() {} void AceAsyncTraceBegin(int32_t taskId, const char* name, bool isAnimationTrace) {} void AceAsyncTraceEnd(int32_t taskId, const char* name, bool isAnimationTrace) {} +void AceAsyncTraceBeginCommercial(int32_t taskId, const char* name, bool isAnimationTrace) {} +void AceAsyncTraceEndCommercial(int32_t taskId, const char* name, bool isAnimationTrace) {} void AceCountTrace(const char *key, int32_t count) {} } // namespace OHOS::Ace diff --git a/frameworks/base/log/ace_trace.h b/frameworks/base/log/ace_trace.h index 4738964ed9d..1ed96f095aa 100644 --- a/frameworks/base/log/ace_trace.h +++ b/frameworks/base/log/ace_trace.h @@ -94,6 +94,8 @@ void ACE_EXPORT AceCountTraceWidthArgs(int32_t count, const char* format, ...); // for commercial trace void ACE_EXPORT AceTraceBeginCommercial(const char* name); void ACE_EXPORT AceTraceEndCommercial(); +void ACE_EXPORT AceAsyncTraceBeginCommercial(int32_t taskId, const char* name, bool isAnimationTrace = false); +void ACE_EXPORT AceAsyncTraceEndCommercial(int32_t taskId, const char* name, bool isAnimationTrace = false); class ACE_FORCE_EXPORT AceScopedTrace final { public: diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp index 39f9567b45a..26ba353bfb5 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp @@ -353,7 +353,8 @@ void SwiperPattern::OnModifyDone() auto index = CurrentIndex(); if (currentIndex_ != index && index >= 0) { - AceAsyncTraceBegin(0, hasTabsAncestor_ ? APP_TABS_NO_ANIMATION_SWITCH : APP_SWIPER_NO_ANIMATION_SWITCH); + AceAsyncTraceBeginCommercial( + 0, hasTabsAncestor_ ? APP_TABS_NO_ANIMATION_SWITCH : APP_SWIPER_NO_ANIMATION_SWITCH); } InitIndicator(); @@ -945,7 +946,7 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, pipeline->AddAfterRenderTask([weak = WeakClaim(this)]() { auto swiper = weak.Upgrade(); CHECK_NULL_VOID(swiper); - AceAsyncTraceEnd( + AceAsyncTraceEndCommercial( 0, swiper->hasTabsAncestor_ ? APP_TABS_NO_ANIMATION_SWITCH : APP_SWIPER_NO_ANIMATION_SWITCH); }); } @@ -1389,7 +1390,7 @@ void SwiperPattern::SwipeToWithoutAnimation(int32_t index) StopSpringAnimationImmediately(); StopIndicatorAnimation(true); jumpIndex_ = index; - AceAsyncTraceBegin(0, hasTabsAncestor_ ? APP_TABS_NO_ANIMATION_SWITCH : APP_SWIPER_NO_ANIMATION_SWITCH); + AceAsyncTraceBeginCommercial(0, hasTabsAncestor_ ? APP_TABS_NO_ANIMATION_SWITCH : APP_SWIPER_NO_ANIMATION_SWITCH); uiCastJumpIndex_ = index; MarkDirtyNodeSelf(); FireAndCleanScrollingListener(); @@ -2685,7 +2686,7 @@ void SwiperPattern::HandleDragStart(const GestureEvent& info) if (!hasTabsAncestor_) { PerfMonitor::GetPerfMonitor()->Start(PerfConstants::APP_SWIPER_SCROLL, PerfActionType::FIRST_MOVE, ""); } else { - AceAsyncTraceBegin(0, APP_TABS_SCROLL); + AceAsyncTraceBeginCommercial(0, APP_TABS_SCROLL); } UpdateDragFRCSceneInfo(info.GetMainVelocity(), SceneStatus::START); @@ -2763,7 +2764,7 @@ void SwiperPattern::HandleDragEnd(double dragVelocity) if (!hasTabsAncestor_) { PerfMonitor::GetPerfMonitor()->End(PerfConstants::APP_SWIPER_SCROLL, false); } else { - AceAsyncTraceEnd(0, APP_TABS_SCROLL); + AceAsyncTraceEndCommercial(0, APP_TABS_SCROLL); } isTouchDown_ = false; isTouchDownOnOverlong_ = false; @@ -3085,7 +3086,7 @@ void SwiperPattern::PlayPropertyTranslateAnimation( if (!swiper->hasTabsAncestor_) { PerfMonitor::GetPerfMonitor()->End(PerfConstants::APP_SWIPER_FLING, true); } else { - AceAsyncTraceEnd(0, APP_TABS_FLING); + AceAsyncTraceEndCommercial(0, APP_TABS_FLING); } OffsetF finalOffset = swiper->itemPosition_.empty() ? OffsetF() @@ -3122,7 +3123,7 @@ void SwiperPattern::PlayPropertyTranslateAnimation( if (!swiperPattern->hasTabsAncestor_) { PerfMonitor::GetPerfMonitor()->Start(PerfConstants::APP_SWIPER_FLING, PerfActionType::LAST_UP, ""); } else { - AceAsyncTraceBegin(0, APP_TABS_FLING); + AceAsyncTraceBeginCommercial(0, APP_TABS_FLING); } TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper start property translate animation with offsetX: %{public}f, offsetY: %{public}f", offset.GetX(), @@ -3393,7 +3394,8 @@ void SwiperPattern::PlayTranslateAnimation( host->UpdateAnimatablePropertyFloat(TRANSLATE_PROPERTY_NAME, endPos); auto swiper = weak.Upgrade(); CHECK_NULL_VOID(swiper); - AceAsyncTraceBegin(0, swiper->hasTabsAncestor_ ? APP_TABS_FRAME_ANIMATION : APP_SWIPER_FRAME_ANIMATION); + AceAsyncTraceBeginCommercial( + 0, swiper->hasTabsAncestor_ ? APP_TABS_FRAME_ANIMATION : APP_SWIPER_FRAME_ANIMATION); AnimationCallbackInfo info; info.velocity = Dimension(velocity, DimensionUnit::PX).ConvertToVp(); info.currentOffset = swiper->GetCustomPropertyOffset() + @@ -3411,7 +3413,8 @@ void SwiperPattern::PlayTranslateAnimation( [weak, nextIndex, restartAutoPlay, finishAnimation]() { auto swiper = weak.Upgrade(); CHECK_NULL_VOID(swiper); - AceAsyncTraceEnd(0, swiper->hasTabsAncestor_ ? APP_TABS_FRAME_ANIMATION : APP_SWIPER_FRAME_ANIMATION); + AceAsyncTraceEndCommercial( + 0, swiper->hasTabsAncestor_ ? APP_TABS_FRAME_ANIMATION : APP_SWIPER_FRAME_ANIMATION); if (finishAnimation && swiper->translateAnimationIsRunning_) { swiper->isFinishAnimation_ = true; } @@ -3451,7 +3454,7 @@ void SwiperPattern::OnSpringAnimationFinish() return; } PerfMonitor::GetPerfMonitor()->End(PerfConstants::APP_LIST_FLING, false); - AceAsyncTraceEnd(0, TRAILING_ANIMATION); + AceAsyncTraceEndCommercial(0, TRAILING_ANIMATION); TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper finish spring animation offset %{public}f", currentIndexOffset_); ACE_SCOPED_TRACE_COMMERCIAL("%s finish spring animation, offset: %f", @@ -3575,7 +3578,7 @@ void SwiperPattern::CreateSpringProperty() } swiper->UpdateCurrentOffset(positionDelta); if (LessNotEqual(std::abs(positionDelta), 1) && !NearZero(positionDelta)) { - AceAsyncTraceBegin(0, TRAILING_ANIMATION); + AceAsyncTraceBeginCommercial(0, TRAILING_ANIMATION); } } }, diff --git a/frameworks/core/components_ng/pattern/tabs/tabs_model_ng.cpp b/frameworks/core/components_ng/pattern/tabs/tabs_model_ng.cpp index 279a23501fa..559413c5bd4 100644 --- a/frameworks/core/components_ng/pattern/tabs/tabs_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/tabs/tabs_model_ng.cpp @@ -85,7 +85,7 @@ void TabsModelNG::Create(BarPosition barPosition, int32_t index, const RefPtr= 0)) { - AceAsyncTraceBegin(0, APP_TABS_NO_ANIMATION_SWITCH); + AceAsyncTraceBeginCommercial(0, APP_TABS_NO_ANIMATION_SWITCH); SetIndex(index); auto tabBarNode = AceType::DynamicCast(tabsNode->GetTabBar()); auto tabBarPattern = tabBarNode->GetPattern(); diff --git a/test/mock/base/mock_ace_trace.cpp b/test/mock/base/mock_ace_trace.cpp index aafd1dbac73..526ec3c0122 100644 --- a/test/mock/base/mock_ace_trace.cpp +++ b/test/mock/base/mock_ace_trace.cpp @@ -28,6 +28,10 @@ void AceAsyncTraceBegin(int32_t taskId, const char* name, bool isAnimationTrace) void AceAsyncTraceEnd(int32_t taskId, const char* name, bool isAnimationTrace) {} +void AceAsyncTraceBeginCommercial(int32_t taskId, const char* name, bool isAnimationTrace) {} + +void AceAsyncTraceEndCommercial(int32_t taskId, const char* name, bool isAnimationTrace) {} + void AceCountTrace(const char* key, int32_t count) {} bool AceTraceBeginWithArgv(const char* /* format */, va_list /* args */) From 9a4d6a0ebd0f6525a5f2a48fe7bd0e4183f73f90 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 11:16:46 +0800 Subject: [PATCH 070/221] add rich_editor_content_modifier_test. Signed-off-by: jiangzhijun8 --- .../core/pattern/rich_editor/BUILD.gn | 1 + .../rich_editor_content_modifier_test_ng.cpp | 261 ++++++++++++++++++ 2 files changed, 262 insertions(+) create mode 100644 test/unittest/core/pattern/rich_editor/rich_editor_content_modifier_test_ng.cpp diff --git a/test/unittest/core/pattern/rich_editor/BUILD.gn b/test/unittest/core/pattern/rich_editor/BUILD.gn index 244d7f7e73d..d1b769ac850 100755 --- a/test/unittest/core/pattern/rich_editor/BUILD.gn +++ b/test/unittest/core/pattern/rich_editor/BUILD.gn @@ -20,6 +20,7 @@ ace_unittest("rich_editor_test_ng") { "rich_editor_change_callback_test_ng.cpp", "rich_editor_click_test_ng.cpp", "rich_editor_common_test_ng.cpp", + "rich_editor_content_modifier_test_ng.cpp", "rich_editor_drag_test_ng.cpp", "rich_editor_edit_test_ng.cpp", "rich_editor_keyboard_shortcut_test_ng.cpp", diff --git a/test/unittest/core/pattern/rich_editor/rich_editor_content_modifier_test_ng.cpp b/test/unittest/core/pattern/rich_editor/rich_editor_content_modifier_test_ng.cpp new file mode 100644 index 00000000000..4165195a822 --- /dev/null +++ b/test/unittest/core/pattern/rich_editor/rich_editor_content_modifier_test_ng.cpp @@ -0,0 +1,261 @@ +/* + * Copyright (c) 2023 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 "test/unittest/core/pattern/rich_editor/rich_editor_common_test_ng.h" +#include "core/components_ng/pattern/rich_editor/rich_editor_content_modifier.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS::Ace::NG { +namespace { +const std::string INIT_STRING_1 = "初始属性字符串"; +const std::string INIT_STRING_2 = "Hellow World"; +const std::string INIT_STRING_3 = "123456"; +const std::string TEST_IMAGE_SOURCE = "src/image.png"; +const int32_t TEST_MAX_LINE = 10; +const Dimension TEST_BASELINE_OFFSET = Dimension(5, DimensionUnit::PX); +const Dimension TEST_TEXT_INDENT = Dimension(20, DimensionUnit::PX); +const CalcLength TEST_MARGIN_CALC { 10.0, DimensionUnit::CALC }; +const CalcLength TEST_PADDING_CALC { 5.0, DimensionUnit::CALC }; +const ImageSpanSize TEST_IMAGE_SIZE = { .width = 50.0_vp, .height = 50.0_vp }; +const BorderRadiusProperty TEST_BORDER_RADIUS = { 4.0_vp, 4.0_vp, 4.0_vp, 4.0_vp }; +const LeadingMarginSize TEST_LEADING_MARGIN_SIZE = { Dimension(5.0), Dimension(10.0) }; +const LeadingMargin TEST_LEADING_MARGIN = { .size = TEST_LEADING_MARGIN_SIZE }; +const Font TEST_FONT = { FONT_WEIGHT_BOLD, FONT_SIZE_VALUE, ITALIC_FONT_STYLE_VALUE, FONT_FAMILY_VALUE, + OHOS::Ace::Color::RED, FONT_FAMILY_VALUE}; +const SpanParagraphStyle TEST_PARAGRAPH_STYLE = { TextAlign::END, TEST_MAX_LINE, WordBreak::BREAK_ALL, + TextOverflow::ELLIPSIS, TEST_LEADING_MARGIN, TEST_TEXT_INDENT}; +StyledStringChangeValue onStyledStringWillChangeValue; +StyledStringChangeValue onStyledStringDidChangeValue; +Testing::MockCanvas canvas; +const float TEXTRICHTEXTRECTX = 0.1f; +const float TEXTRICHTEXTRECTY = 0.1f; +} // namespace + +class RichEditorContentModifierTestNg : public RichEditorCommonTestNg { +public: + void SetUp() override; + void TearDown() override; + static void TearDownTestSuite(); + RefPtr CreateTextStyledString(const std::string& content); + RefPtr CreateImageStyledString(); + RefPtr CreateCustomSpanStyledString(); + void SetTypingStyle(); +}; + +void RichEditorContentModifierTestNg::SetUp() +{ + MockPipelineContext::SetUp(); + MockContainer::SetUp(); + MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr(); + auto* stack = ViewStackProcessor::GetInstance(); + auto nodeId = stack->ClaimNodeId(); + richEditorNode_ = FrameNode::GetOrCreateFrameNode( + V2::RICH_EDITOR_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr(); }); + ASSERT_NE(richEditorNode_, nullptr); + auto richEditorPattern = richEditorNode_->GetPattern(); + richEditorPattern->InitScrollablePattern(); + richEditorPattern->SetSpanStringMode(true); + richEditorPattern->SetRichEditorStyledStringController(AceType::MakeRefPtr()); + richEditorPattern->GetRichEditorStyledStringController()->SetPattern(WeakPtr(richEditorPattern)); + richEditorPattern->CreateNodePaintMethod(); + richEditorNode_->GetGeometryNode()->SetContentSize({}); +} + +void RichEditorContentModifierTestNg::TearDown() +{ + richEditorNode_ = nullptr; + MockParagraph::TearDown(); +} + +void RichEditorContentModifierTestNg::TearDownTestSuite() +{ + TestNG::TearDownTestSuite(); +} + +RefPtr RichEditorContentModifierTestNg::CreateTextStyledString(const std::string& content) +{ + auto styledString = AceType::MakeRefPtr(content); + auto length = styledString->GetLength(); + styledString->AddSpan(AceType::MakeRefPtr(TEST_FONT, 0, length)); + styledString->AddSpan(AceType::MakeRefPtr(TEXT_DECORATION_VALUE, TEXT_DECORATION_COLOR_VALUE, + TextDecorationStyle::WAVY, 0, length)); + styledString->AddSpan(AceType::MakeRefPtr(TEST_BASELINE_OFFSET, 0, length)); + styledString->AddSpan(AceType::MakeRefPtr(LETTER_SPACING, 0, length)); + styledString->AddSpan(AceType::MakeRefPtr(SHADOWS, 0, length)); + styledString->AddSpan(AceType::MakeRefPtr(TEST_PARAGRAPH_STYLE, 0, length)); + styledString->AddSpan(AceType::MakeRefPtr(LINE_HEIGHT_VALUE, 0, length)); + return styledString; +} + +RefPtr RichEditorContentModifierTestNg::CreateImageStyledString() +{ + MarginProperty margins; + margins.SetEdges(TEST_MARGIN_CALC); + PaddingProperty paddings; + paddings.SetEdges(TEST_PADDING_CALC); + ImageSpanAttribute attr { .size = TEST_IMAGE_SIZE, + .paddingProp = paddings, + .marginProp = margins, + .borderRadius = TEST_BORDER_RADIUS, + .objectFit = ImageFit::COVER, + .verticalAlign = VerticalAlign::BOTTOM }; + ImageSpanOptions imageOption { .image = TEST_IMAGE_SOURCE, .imageAttribute = attr }; + return AceType::MakeRefPtr(imageOption); +} + +RefPtr RichEditorContentModifierTestNg::CreateCustomSpanStyledString() +{ + auto customSpan = AceType::MakeRefPtr(); + return AceType::MakeRefPtr(customSpan); +} + +void RichEditorContentModifierTestNg::SetTypingStyle() +{ + TextStyle textStyle; + textStyle.SetTextColor(TEXT_COLOR_VALUE); + textStyle.SetTextShadows(SHADOWS); + textStyle.SetFontSize(FONT_SIZE_VALUE); + textStyle.SetFontStyle(ITALIC_FONT_STYLE_VALUE); + textStyle.SetFontWeight(FONT_WEIGHT_VALUE); + textStyle.SetTextDecoration(TEXT_DECORATION_VALUE); + textStyle.SetTextDecorationColor(TEXT_DECORATION_COLOR_VALUE); + textStyle.SetLineHeight(LINE_HEIGHT_VALUE); + textStyle.SetLetterSpacing(LETTER_SPACING); + UpdateSpanStyle typingStyle; + typingStyle.updateTextColor = TEXT_COLOR_VALUE; + typingStyle.updateTextShadows = SHADOWS; + typingStyle.updateFontSize = FONT_SIZE_VALUE; + typingStyle.updateItalicFontStyle = ITALIC_FONT_STYLE_VALUE; + typingStyle.updateFontWeight = FONT_WEIGHT_VALUE; + typingStyle.updateTextDecoration = TEXT_DECORATION_VALUE; + typingStyle.updateTextDecorationColor = TEXT_DECORATION_COLOR_VALUE; + typingStyle.updateLineHeight = LINE_HEIGHT_VALUE; + typingStyle.updateLetterSpacing = LETTER_SPACING; + ASSERT_NE(richEditorNode_, nullptr); + auto richEditorPattern = richEditorNode_->GetPattern(); + richEditorPattern->SetTypingStyle(typingStyle, textStyle); +} + +/** + * @tc.name: onDraw001 + * @tc.desc: Test FromStyledString. + * @tc.type: FUNC + */ +HWTEST_F(RichEditorContentModifierTestNg, onDraw001, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + auto testContentModifier = AceType::MakeRefPtr( + richEditorPattern->textStyle_, &richEditorPattern->paragraphs_, richEditorPattern); + TestParagraphRect paragraphRect = { .start = 0, .end = 2, .rects = { { -400.0, -400.0, 200.0, 200.0 } } }; + TestParagraphItem paragraphItem = { .start = 0, .end = 2, + .indexOffsetMap = { { 0, Offset(0, 0) }, { 6, Offset(50, 0) } }, + .testParagraphRects = { paragraphRect } }; + AddParagraph(paragraphItem); + ASSERT_NE(testContentModifier, nullptr); + DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE }; + testContentModifier->onDraw(context); +} + +/** + * @tc.name: SetRichTextRectX001 + * @tc.desc: Test FromStyledString. + * @tc.type: FUNC + */ +HWTEST_F(RichEditorContentModifierTestNg, SetRichTextRectX001, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + auto testContentModifier = AceType::MakeRefPtr( + richEditorPattern->textStyle_, &richEditorPattern->paragraphs_, richEditorPattern); + + ASSERT_NE(testContentModifier, nullptr); + testContentModifier->SetRichTextRectX(TEXTRICHTEXTRECTX); + ASSERT_EQ(TEXTRICHTEXTRECTX, testContentModifier->richTextRectX_->GetStagingValue()); +} + +/** + * @tc.name: SetRichTextRectY001 + * @tc.desc: Test FromStyledString. + * @tc.type: FUNC + */ +HWTEST_F(RichEditorContentModifierTestNg, SetRichTextRectY001, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + auto testContentModifier = AceType::MakeRefPtr( + richEditorPattern->textStyle_, &richEditorPattern->paragraphs_, richEditorPattern); + + ASSERT_NE(testContentModifier, nullptr); + testContentModifier->SetRichTextRectY(TEXTRICHTEXTRECTY); + ASSERT_EQ(TEXTRICHTEXTRECTY, testContentModifier->richTextRectY_->GetStagingValue()); +} + +/** + * @tc.name: SetClipOffset001 + * @tc.desc: Test FromStyledString. + * @tc.type: FUNC + */ +HWTEST_F(RichEditorContentModifierTestNg, SetClipOffset001, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + auto testContentModifier = AceType::MakeRefPtr( + richEditorPattern->textStyle_, &richEditorPattern->paragraphs_, richEditorPattern); + OffsetF testOffset = {}; + ASSERT_NE(testContentModifier, nullptr); + testContentModifier->SetClipOffset(testOffset); + ASSERT_EQ(testOffset, testContentModifier->clipOffset_->GetStagingValue()); +} + +/** + * @tc.name: SetClipSize001 + * @tc.desc: Test FromStyledString. + * @tc.type: FUNC + */ +HWTEST_F(RichEditorContentModifierTestNg, SetClipSize001, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + auto testContentModifier = AceType::MakeRefPtr( + richEditorPattern->textStyle_, &richEditorPattern->paragraphs_, richEditorPattern); + SizeF testSize = {}; + ASSERT_NE(testContentModifier, nullptr); + testContentModifier->SetClipSize(testSize); + ASSERT_EQ(testSize, testContentModifier->clipSize_->GetStagingValue()); +} + +/** + * @tc.name: PaintCustomSpan001 + * @tc.desc: Test FromStyledString. + * @tc.type: FUNC + */ +HWTEST_F(RichEditorContentModifierTestNg, PaintCustomSpan001, TestSize.Level1) +{ + auto richEditorPattern = richEditorNode_->GetPattern(); + ASSERT_NE(richEditorPattern, nullptr); + richEditorPattern->contentMod_ = AceType::MakeRefPtr( + richEditorPattern->textStyle_, &richEditorPattern->paragraphs_, richEditorPattern); + TestParagraphRect paragraphRect = { .start = 0, .end = 2, .rects = { { -400.0, -400.0, 200.0, 200.0 } } }; + TestParagraphItem paragraphItem = { .start = 0, .end = 2, + .indexOffsetMap = { { 0, Offset(0, 0) }, { 6, Offset(50, 0) } }, + .testParagraphRects = { paragraphRect } }; + AddParagraph(paragraphItem); + ASSERT_NE(richEditorPattern->contentMod_, nullptr); + DrawingContext context { canvas, CONTEXT_WIDTH_VALUE, CONTEXT_HEIGHT_VALUE }; + richEditorPattern->contentMod_->PaintCustomSpan(context); +} +} // namespace OHOS::Ace::NG From 546bf3642fdf10dce2b34ca53ee88c7fab014983 Mon Sep 17 00:00:00 2001 From: 387928 Date: Sat, 20 Jul 2024 06:14:33 +0000 Subject: [PATCH 071/221] =?UTF-8?q?=E8=BF=BD=E5=8A=A0postEventManager?= =?UTF-8?q?=E4=BB=A5=E5=8F=8AgestureEventHub=E7=9B=B8=E5=85=B3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 387928 --- .../core/event/gesture_event_hub_test_ng.h | 2 + ...ture_event_hub_test_ng_property_config.cpp | 595 ++++++++++++++++++ .../manager/post_event_manager_test_ng.cpp | 59 ++ 3 files changed, 656 insertions(+) diff --git a/test/unittest/core/event/gesture_event_hub_test_ng.h b/test/unittest/core/event/gesture_event_hub_test_ng.h index 919349b7bbe..9e004649b6c 100644 --- a/test/unittest/core/event/gesture_event_hub_test_ng.h +++ b/test/unittest/core/event/gesture_event_hub_test_ng.h @@ -18,11 +18,13 @@ #include "gtest/gtest.h" #define private public +#define protected public #undef SECURITY_COMPONENT_ENABLE #include "test/mock/base/mock_drag_window.h" #include "test/mock/base/mock_task_executor.h" #include "test/mock/core/pipeline/mock_pipeline_context.h" +#include "test/mock/core/common/mock_interaction_interface.h" #include "test/mock/core/common/mock_udmf.h" #include "base/geometry/axis.h" diff --git a/test/unittest/core/event/gesture_event_hub_test_ng_property_config.cpp b/test/unittest/core/event/gesture_event_hub_test_ng_property_config.cpp index d59f56c1c3b..d0b12d5d69c 100644 --- a/test/unittest/core/event/gesture_event_hub_test_ng_property_config.cpp +++ b/test/unittest/core/event/gesture_event_hub_test_ng_property_config.cpp @@ -19,6 +19,86 @@ using namespace testing; using namespace testing::ext; namespace OHOS::Ace::NG { +namespace { +constexpr size_t DEFAULT_CHILD_COUNT = 4; +constexpr float GRID_WIDTH = 480.0f; +constexpr float GRID_HEIGHT = 800.0f; +constexpr float ITEM_WIDTH = 120.0f; +constexpr float ITEM_HEIGHT = 200.0f; +constexpr double DEFAULT_OFFSET_Y = 5.0; + +RefPtr CreateGridNodeWithChild(size_t childCount, const GridItemStyle& gridItemStyle) +{ + auto frameNode = FrameNode::GetOrCreateFrameNode(V2::GRID_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + []() {return AceType::MakeRefPtr(); }); + ViewAbstract::SetWidth(frameNode.GetRawPtr(), CalcLength(GRID_WIDTH)); + ViewAbstract::SetHeight(frameNode.GetRawPtr(), CalcLength(GRID_HEIGHT)); + std::list> childNodes; + + for (size_t i = 0; i < childCount; ++i) { + auto chidNodeId = ElementRegister::GetInstance()->MakeUniqueId(); + auto childNode = FrameNode::GetOrCreateFrameNode(V2::GRID_ITEM_ETS_TAG, chidNodeId, + [itemStyle = gridItemStyle]() { return AceType::MakeRefPtr(nullptr, itemStyle); }); + ViewAbstract::SetWidth(childNode.GetRawPtr(), CalcLength(ITEM_WIDTH)); + ViewAbstract::SetHeight(childNode.GetRawPtr(), CalcLength(ITEM_HEIGHT)); + childNode->MountToParent(frameNode); + childNodes.emplace_back(childNode); + } + return frameNode; +} + +RefPtr CreateRecognizerGroup(const RefPtr& parentNode) +{ + CHECK_NULL_RETURN(parentNode, nullptr); + std::list> recognizers; + for (const auto& childNode : parentNode->GetChildren()) { + auto childFrameNode = AceType::DynamicCast(childNode); + if (childFrameNode) { + auto clickRecognizer = AceType::MakeRefPtr(); + clickRecognizer->AttachFrameNode(childFrameNode); + recognizers.emplace_back(clickRecognizer); + } + } + auto recognizerGroup = AceType::MakeRefPtr(std::move(recognizers)); + if (recognizerGroup) { + recognizerGroup->AttachFrameNode(parentNode); + } + return recognizerGroup; +} + +RefPtr ProcessDragItemGroupScene() +{ + auto gridNode = CreateGridNodeWithChild(DEFAULT_CHILD_COUNT, GridItemStyle::NONE); + CHECK_NULL_RETURN(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + CHECK_NULL_RETURN(gestureEventHub, nullptr); + + for (const auto& child : gridNode->GetChildren()) { + auto childNode = AceType::DynamicCast(child); + if (!childNode) { + continue; + } + auto gridItemPattern = childNode->GetPattern(); + if (!gridItemPattern) { + continue; + } + gridItemPattern->SetSelected(true); + } + auto gridItem = AceType::DynamicCast(gridNode->GetChildByIndex(0)); + CHECK_NULL_RETURN(gridItem, nullptr); + auto pattern = gridNode->GetPattern(); + CHECK_NULL_RETURN(pattern, nullptr); + pattern->gridLayoutInfo_.endIndex_ = DEFAULT_CHILD_COUNT; + + gestureEventHub->InitDragDropEvent(); + auto actuator = gestureEventHub->GetDragEventActuator(); + CHECK_NULL_RETURN(actuator, nullptr); + actuator->isSelectedItemNode_ = true; + actuator->FindItemParentNode(gridItem); + return gridNode; +} +} // namespace + /** * @tc.name: GetHitTestModeStr * @tc.desc: Test GetHitTestModeStr001 @@ -1409,4 +1489,519 @@ HWTEST_F(GestureEventHubTestNg, GestureEventHubGetPixelMapScaleTest003, TestSize EXPECT_FALSE(height > minDeviceLength / PIXELMAP_DRAG_WGR_SCALE); EXPECT_FALSE(width > minDeviceLength / PIXELMAP_DRAG_WGR_SCALE); } + +/** + * @tc.name: ProcessTouchTestHit001 + * @tc.desc: Test ProcessTouchTestHit func + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, ProcessTouchTestHit001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create GestureEventHub. + * @tc.expected: gestureEventHub is not null. + */ + auto gridNode = CreateGridNodeWithChild(DEFAULT_CHILD_COUNT, GridItemStyle::NONE); + ASSERT_NE(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + auto recognizerGroup = CreateRecognizerGroup(gridNode); + ASSERT_NE(recognizerGroup, nullptr); + + /** + * @tc.steps: step2. Invoke ProcessTouchTestHit. + */ + gestureEventHub->parallelCombineClick = true; + gestureEventHub->SetUserOnClick([](GestureEvent& info) {}); + + auto userClickEventActuator = gestureEventHub->GetUserClickEventActuator(); + ASSERT_NE(userClickEventActuator, nullptr); + TouchRestrict touchRestrict; + TouchTestResult innerTargets; + TouchTestResult finalResult; + TouchTestResult responseLinkResult; + innerTargets.emplace_back(recognizerGroup); + auto flag = gestureEventHub->ProcessTouchTestHit( + COORDINATE_OFFSET, touchRestrict, innerTargets, finalResult, TOUCH_ID, PointF(), nullptr, responseLinkResult); + EXPECT_FALSE(flag); +} + +/** + * @tc.name: StartLongPressActionForWeb001 + * @tc.desc: Test StartLongPressActionForWeb func + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, StartLongPressActionForWeb001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create GestureEventHub. + * @tc.expected: gestureEventHub is not null. + */ + auto gridNode = CreateGridNodeWithChild(DEFAULT_CHILD_COUNT, GridItemStyle::NONE); + ASSERT_NE(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + + /** + * @tc.steps: step2. set DragEvent and handle drag. + */ + auto dragActionStart = [](GestureEvent& info) {}; + auto dragActionUpdate = [](GestureEvent& info) {}; + auto dragActionEnd = [](GestureEvent& info) {}; + auto dragActionCancel = []() {}; + auto dragEvent = AceType::MakeRefPtr( + std::move(dragActionStart), std::move(dragActionUpdate), std::move(dragActionEnd), std::move(dragActionCancel)); + gestureEventHub->SetCustomDragEvent(dragEvent, PAN_DIRECTION_ALL, FINGERS, DISTANCE); + + /** + * @tc.steps: step3. create taskExecutor to fire task callBack. + * @tc.expected: taskExecutor is not null. + */ + auto context = PipelineContext::GetCurrentContext(); + ASSERT_NE(context, nullptr); + context->taskExecutor_ = AceType::MakeRefPtr(); + auto taskExecutor = context->GetTaskExecutor(); + ASSERT_NE(taskExecutor, nullptr); + gestureEventHub->StartLongPressActionForWeb(); + ASSERT_NE(gestureEventHub->GetDragEventActuator(), nullptr); +} + +/** + * @tc.name: WebDragAction001 + * @tc.desc: Test web drag action. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, WebDragAction001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create GestureEventHub. + * @tc.expected: gestureEventHub is not null. + */ + auto frameNode = FrameNode::GetOrCreateFrameNode(V2::WEB_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + []() {return AceType::MakeRefPtr(); }); + ASSERT_NE(frameNode, nullptr); + auto gestureEventHub = frameNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + + /** + * @tc.steps: step2. set DragEvent and handle drag. + */ + auto dragActionStart = [](GestureEvent& info) {}; + auto dragActionUpdate = [](GestureEvent& info) {}; + auto dragActionEnd = [](GestureEvent& info) {}; + auto dragActionCancel = []() {}; + auto dragEvent = AceType::MakeRefPtr( + std::move(dragActionStart), std::move(dragActionUpdate), std::move(dragActionEnd), std::move(dragActionCancel)); + gestureEventHub->SetCustomDragEvent(dragEvent, PAN_DIRECTION_ALL, FINGERS, DISTANCE); + gestureEventHub->HandleNotallowDrag(GestureEvent()); + + /** + * @tc.steps: step3. create taskExecutor to fire task callBack. + * @tc.expected: taskExecutor is not null. + */ + auto context = PipelineContext::GetCurrentContext(); + ASSERT_NE(context, nullptr); + context->taskExecutor_ = AceType::MakeRefPtr(); + auto taskExecutor = context->GetTaskExecutor(); + ASSERT_NE(taskExecutor, nullptr); + gestureEventHub->StartDragTaskForWeb(); + gestureEventHub->CancelDragForWeb(); + gestureEventHub->ResetDragActionForWeb(); + ASSERT_NE(gestureEventHub->GetDragEventActuator(), nullptr); +} + +/** + * @tc.name: GenerateMousePixelMap001 + * @tc.desc: Test GenerateMousePixelMap func. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, GenerateMousePixelMap001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create text frameNode and add drag frameNode then Create GestureEventHub. + * @tc.expected: gestureEventHub is not null. + */ + auto textPattern = AceType::MakeRefPtr(); + auto frameNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), textPattern); + ASSERT_NE(frameNode, nullptr); + auto dragNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), []() {return AceType::MakeRefPtr(); }); + textPattern->dragNode_ = dragNode; + auto gestureEventHub = frameNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + + /** + * @tc.steps: step2. Invoke GenerateMousePixelMap. + * @tc.expected: TextDraggable is true. + */ + gestureEventHub->SetTextDraggable(true); + GestureEvent info; + gestureEventHub->GenerateMousePixelMap(info); + EXPECT_TRUE(gestureEventHub->pixelMap_ == nullptr); +} + +/** + * @tc.name: RegisterCoordinationListener001 + * @tc.desc: Test RegisterCoordinationListener func. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, RegisterCoordinationListener001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create GestureEventHub. + * @tc.expected: gestureEventHub is not null. + */ + auto gridNode = CreateGridNodeWithChild(DEFAULT_CHILD_COUNT, GridItemStyle::NONE); + ASSERT_NE(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + + /** + * @tc.steps: step2. set DragEvent and handle drag. + */ + auto dragActionStart = [](GestureEvent& info) {}; + auto dragActionUpdate = [](GestureEvent& info) {}; + auto dragActionEnd = [](GestureEvent& info) {}; + auto dragActionCancel = []() {}; + auto dragEvent = AceType::MakeRefPtr( + std::move(dragActionStart), std::move(dragActionUpdate), std::move(dragActionEnd), std::move(dragActionCancel)); + gestureEventHub->SetCustomDragEvent(dragEvent, PAN_DIRECTION_ALL, FINGERS, DISTANCE); + + /** + * @tc.steps: step3. create taskExecutor to fire task callBack and invoke registerCoordinationListener. + * @tc.expected: registerCoordinationListener is called once. + */ + auto context = PipelineContext::GetCurrentContext(); + ASSERT_NE(context, nullptr); + context->taskExecutor_ = AceType::MakeRefPtr(); + auto taskExecutor = context->GetTaskExecutor(); + ASSERT_NE(taskExecutor, nullptr); + auto mock = AceType::DynamicCast(InteractionInterface::GetInstance()); + ASSERT_NE(mock, nullptr); + EXPECT_CALL(*mock, RegisterCoordinationListener(testing::_)).Times(1).WillOnce(Return(50)); + gestureEventHub->RegisterCoordinationListener(context); +} + +/** + * @tc.name: GridNodeHandleOnDragUpdate001 + * @tc.desc: Test gridnode Drag scene. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, GridNodeHandleOnDragUpdate001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create grid with gridItem frame node tree. + * @tc.expected: instance is not null. + */ + auto gridNode = CreateGridNodeWithChild(DEFAULT_CHILD_COUNT, GridItemStyle::NONE); + ASSERT_NE(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + for (const auto& child : gridNode->GetChildren()) { + auto childNode = AceType::DynamicCast(child); + ASSERT_TRUE(childNode != nullptr); + auto gridItemPattern = childNode->GetPattern(); + ASSERT_TRUE(gridItemPattern != nullptr); + gridItemPattern->SetSelected(true); + } + auto gridItem = AceType::DynamicCast(gridNode->GetChildByIndex(0)); + ASSERT_NE(gridItem, nullptr); + auto pattern = gridNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + pattern->gridLayoutInfo_.endIndex_ = DEFAULT_CHILD_COUNT; + + /** + * @tc.steps: step2. set all griditems are selected. + */ + gestureEventHub->InitDragDropEvent(); + constexpr int64_t PROXY_ID_NOT_FIT = 101; + auto dragDropProxy = AceType::MakeRefPtr(PROXY_ID_NOT_FIT); + gestureEventHub->dragDropProxy_ = dragDropProxy; + auto actuator = gestureEventHub->GetDragEventActuator(); + ASSERT_NE(actuator, nullptr); + actuator->isSelectedItemNode_ = true; + actuator->FindItemParentNode(gridItem); + + /** + * @tc.steps: step3. handle grid drag when switch to subwindow. + */ + GestureEvent info; + gestureEventHub->HandleOnDragStart(info); + for (double step = 0; step < DEFAULT_OFFSET_Y; ++step) { + info.SetOffsetY(step); + gestureEventHub->HandleOnDragUpdate(info); + } + gestureEventHub->HandleOnDragEnd(info); + ASSERT_NE(gestureEventHub->gestureInfoForWeb_, nullptr); +} + +/** + * @tc.name: GetDragCallback001 + * @tc.desc: Test GetDragCallback fun and fire callback. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, GetDragCallback001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create grid with gridItem frame node tree. + * @tc.expected: instance is not null. + */ + auto gridNode = CreateGridNodeWithChild(DEFAULT_CHILD_COUNT, GridItemStyle::NONE); + ASSERT_NE(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + auto eventHub = gridNode->GetEventHub(); + + /** + * @tc.steps: step2. create taskExecutor to fire task callBack. + * @tc.expected: taskExecutor is not null. + */ + auto context = PipelineContext::GetCurrentContext(); + ASSERT_NE(context, nullptr); + context->taskExecutor_ = AceType::MakeRefPtr(); + auto taskExecutor = context->GetTaskExecutor(); + ASSERT_NE(taskExecutor, nullptr); + auto dragDropManager = context->GetDragDropManager(); + ASSERT_NE(dragDropManager, nullptr); + auto mock = AceType::DynamicCast(InteractionInterface::GetInstance()); + ASSERT_NE(mock, nullptr); + + /** + * @tc.steps: step3. Invoke GetDragCallback to get function and fire this function. + * @tc.expected: fire function success. + */ + int32_t callbackInfo = 0; + eventHub->SetOnDragEnd([&callbackInfo](const RefPtr& /*dragEvent*/) { + callbackInfo = 1; + }); + auto dragCallback = gestureEventHub->GetDragCallback(context, eventHub); + ASSERT_NE(dragCallback, nullptr); + EXPECT_CALL(*mock, UnRegisterCoordinationListener()).Times(1).WillOnce(Return(50)); + DragNotifyMsgCore notifyMessage; + dragCallback(notifyMessage); + EXPECT_FALSE(dragDropManager->IsDragged()); + EXPECT_EQ(callbackInfo, 1); +} + +/** + * @tc.name: CopyGestures001 + * @tc.desc: Test CopyGestures from another guestureEventHub. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, CopyGestures001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create guestureEventHub dest and source. + */ + auto eventHubSrc = AceType::MakeRefPtr(); + auto eventHubDest = AceType::MakeRefPtr(); + auto gestureEventHubSrc = eventHubSrc->GetOrCreateGestureEventHub(); + auto gestureEventHubDest = eventHubDest->GetOrCreateGestureEventHub(); + auto longPressGesture = AceType::MakeRefPtr(FINGERS, false, 1); + longPressGesture->SetTag(CHECK_TAG_1); + gestureEventHubSrc->AddGesture(longPressGesture); + + /** + * @tc.steps: step2. Invoke CopyGestures. + * @tc.expected: The member variable of dest is a copy of source. + */ + gestureEventHubDest->CopyGestures(gestureEventHubSrc); + EXPECT_EQ(gestureEventHubDest->gestures_.size(), gestureEventHubSrc->gestures_.size()); + EXPECT_TRUE(gestureEventHubDest->recreateGesture_); +} + +/** + * @tc.name: SetResponseRegionWithRemove001 + * @tc.desc: Test SetResponseRegion with RemoveLastResponseRect. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, SetResponseRegionWithRemove001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create guestureEventHub. + */ + auto eventHub = AceType::MakeRefPtr(); + auto gestureEventHub = eventHub->GetOrCreateGestureEventHub(); + + /** + * @tc.steps: step2. Invoke SetResponseRegion. + * @tc.expected: SetResponseRegion success. + */ + std::vector responseRegion; + responseRegion.push_back(DimensionRect()); + int32_t callbackInfo = 0; + gestureEventHub->SetResponseRegionFunc([&callbackInfo](const std::vector& /*reponseRegion*/) { + callbackInfo = 1; + }); + gestureEventHub->SetResponseRegion(responseRegion); + EXPECT_EQ(gestureEventHub->responseRegion_.size(), responseRegion.size()); + + /** + * @tc.steps: step3. Invoke RemoveLastResponseRect. + * @tc.expected: RemoveLastResponseRect success and fire responseRegionFunc. + */ + gestureEventHub->RemoveLastResponseRect(); + EXPECT_TRUE(gestureEventHub->responseRegion_.empty()); + EXPECT_EQ(callbackInfo, 1); +} + +/** + * @tc.name: SetDragGatherPixelMaps001 + * @tc.desc: Test SetDragGatherPixelMaps when input type is mouse button. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, SetDragGatherPixelMaps001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create grid with gridItem frame node tree. + * @tc.expected: instance is not null. + */ + auto gridNode = ProcessDragItemGroupScene(); + ASSERT_NE(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + auto context = PipelineContext::GetCurrentContext(); + ASSERT_NE(context, nullptr); + auto dragDropManager = context->GetDragDropManager(); + ASSERT_NE(dragDropManager, nullptr); + + /** + * @tc.steps: step2. Invoke SetDragGatherPixelMaps. + * @tc.expected: gatherPixelMaps is not empty. + */ + GestureEvent info; + info.SetInputEventType(InputEventType::MOUSE_BUTTON); + gestureEventHub->SetDragGatherPixelMaps(info); + EXPECT_FALSE(dragDropManager->gatherPixelMaps_.empty()); +} + +/** + * @tc.name: SetDragGatherPixelMaps002 + * @tc.desc: Test SetDragGatherPixelMaps when input type is not mouse button. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, SetDragGatherPixelMaps002, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create grid with gridItem frame node tree. + * @tc.expected: instance is not null. + */ + auto gridNode = ProcessDragItemGroupScene(); + ASSERT_NE(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + + /** + * @tc.steps: step2. Init prefabricated values. + */ + auto context = PipelineContext::GetCurrentContext(); + ASSERT_NE(context, nullptr); + auto dragDropManager = context->GetDragDropManager(); + ASSERT_NE(dragDropManager, nullptr); + auto overlayManager = context->GetOverlayManager(); + ASSERT_NE(overlayManager, nullptr); + auto imageNode = FrameNode::CreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), + AceType::MakeRefPtr()); + ASSERT_NE(imageNode, nullptr); + GatherNodeChildInfo gatherNodeChildInfo; + gatherNodeChildInfo.imageNode = imageNode; + std::vector gatherNodeChildInfos; + gatherNodeChildInfos.emplace_back(gatherNodeChildInfo); + ASSERT_NE(gestureEventHub->GetFrameNode(), nullptr); + overlayManager->MountGatherNodeToRootNode(gestureEventHub->GetFrameNode(), gatherNodeChildInfos); + + /** + * @tc.steps: step3. Invoke SetDragGatherPixelMaps. + * @tc.expected: gatherPixelMaps is not empty. + */ + GestureEvent info; + info.SetInputEventType(InputEventType::TOUCH_SCREEN); + gestureEventHub->SetDragGatherPixelMaps(info); + EXPECT_FALSE(dragDropManager->gatherPixelMaps_.empty()); +} + +/** + * @tc.name: GetSelectItemSize001 + * @tc.desc: Test GetSelectItemSize. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, GetSelectItemSize001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create grid with gridItem frame node tree. + * @tc.expected: instance is not null. + */ + auto gridNode = ProcessDragItemGroupScene(); + ASSERT_NE(gridNode, nullptr); + auto gestureEventHub = gridNode->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + + /** + * @tc.steps: step2. Invoke GetSelectItemSize. + * @tc.expected: size is equal to children count. + */ + EXPECT_EQ(gestureEventHub->GetSelectItemSize(), gridNode->GetChildren().size()); +} + +/** + * @tc.name: RemoveGesturesByTag001 + * @tc.desc: Test RemoveGesturesByTag. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, RemoveGesturesByTag001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create gestureEventHub and create gesture list. + * @tc.expected: instance is not null. + */ + auto eventHub = AceType::MakeRefPtr(); + auto gestureEventHub = eventHub->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + std::vector> gestures; + auto longPressGestureOne = AceType::MakeRefPtr(FINGERS, false, 1); + longPressGestureOne->SetTag(CHECK_TAG_1); + gestureEventHub->AttachGesture(longPressGestureOne); + auto longPressGestureTwo = AceType::MakeRefPtr(FINGERS, false, 1); + gestures.emplace_back(longPressGestureTwo); + auto longPressGestureThree = AceType::MakeRefPtr(FINGERS, false, 1); + gestures.emplace_back(longPressGestureThree); + auto group = AceType::MakeRefPtr(GestureMode::Exclusive, gestures); + gestureEventHub->AttachGesture(group); + + /** + * @tc.steps: step2. Invoke RemoveGesturesByTag. + * @tc.expected: Remove Gestures by tag. modifierGestures_ size is 1 (only GestureGroup). + */ + gestureEventHub->RemoveGesturesByTag(CHECK_TAG_1); + EXPECT_EQ(gestureEventHub->modifierGestures_.size(), 1); +} + +/** + * @tc.name: FireCustomerOnDragEnd001 + * @tc.desc: Test FireCustomerOnDragEnd. + * @tc.type: FUNC + */ +HWTEST_F(GestureEventHubTestNg, FireCustomerOnDragEnd001, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create gestureEventHub. + * @tc.expected: instance is not null. + */ + auto eventHub = AceType::MakeRefPtr(); + auto gestureEventHub = eventHub->GetOrCreateGestureEventHub(); + ASSERT_NE(gestureEventHub, nullptr); + + /** + * @tc.steps: step2. Invoke FireCustomerOnDragEnd. + * @tc.expected: eventHub fire dragEnd callback. + */ + int callbackInfo = 0; + eventHub->SetOnDragEnd([&callbackInfo](const RefPtr& /* dragEvent */) { + callbackInfo = 1; + }); + auto context = PipelineContext::GetCurrentContext(); + gestureEventHub->FireCustomerOnDragEnd(context, eventHub); + EXPECT_EQ(callbackInfo, 1); +} } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/core/manager/post_event_manager_test_ng.cpp b/test/unittest/core/manager/post_event_manager_test_ng.cpp index 6143a4feb3f..9ffbfe1152e 100644 --- a/test/unittest/core/manager/post_event_manager_test_ng.cpp +++ b/test/unittest/core/manager/post_event_manager_test_ng.cpp @@ -321,4 +321,63 @@ HWTEST_F(PostEventManagerTestNg, PostEventManagerTest005, TestSize.Level1) result = postEventManager_->PostEvent(root_, touchUpEvent); EXPECT_FALSE(result); } + +/** + * @tc.name: HandlePostEventTest001 + * @tc.desc: test HandlePostEvent func. + * @tc.type: FUNC + */ +HWTEST_F(PostEventManagerTestNg, HandlePostEventTest001, TestSize.Level1) +{ + /** + * @tc.steps: step1. construct a FrameNode and set gesture. + */ + Init(); + + /** + * @tc.steps: step2. mock user touch event. + */ + auto buttonNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, 1, + []() { return AceType::MakeRefPtr(); }); + TouchEvent touchEvent; + + const std::vector touchTypeArray = { Ace::TouchType::DOWN, Ace::TouchType::UP }; + int32_t touchStateCount = 4; + for (int32_t i = 0; i < touchStateCount; ++i) { + int32_t index = i % touchTypeArray.size(); + touchEvent.type = touchTypeArray[index]; + touchEvent.id = touchTypeArray.size() > 0 ? i / touchTypeArray.size() : i; + postEventManager_->HandlePostEvent(buttonNode, touchEvent); + } + EXPECT_TRUE(postEventManager_->lastEventMap_.empty()); +} + +/** + * @tc.name: PostDownEventTest001 + * @tc.desc: test PostDownEvent func. + * @tc.type: FUNC + */ +HWTEST_F(PostEventManagerTestNg, PostDownEventTest001, TestSize.Level1) +{ + /** + * @tc.steps: step1. construct a FrameNode and set gesture. + */ + Init(); + + /** + * @tc.steps: step2. Simulate when the user touchDown and then handles the out-of-hand + * action event through the PostDownEvent function. + */ + int32_t nodeId = 1; + auto buttonNode = FrameNode::GetOrCreateFrameNode(V2::BUTTON_ETS_TAG, nodeId, + []() { return AceType::MakeRefPtr(); }); + TouchEvent touchEvent; + touchEvent.type = Ace::TouchType::DOWN; + touchEvent.id = nodeId; + postEventManager_->HandlePostEvent(buttonNode, touchEvent); + + postEventManager_->PostDownEvent(buttonNode, touchEvent); + EXPECT_TRUE(postEventManager_->postEventAction_.empty()); + EXPECT_TRUE(postEventManager_->lastEventMap_.empty()); +} } // namespace OHOS::Ace::NG From 304a7709d1319ca0541471bb385aa2385025405e Mon Sep 17 00:00:00 2001 From: zhuweifeng Date: Sat, 20 Jul 2024 14:16:39 +0800 Subject: [PATCH 072/221] safe check Signed-off-by: zhuweifeng Change-Id: I0cb4f8b9bcf49670e3d1a7b58e8ead4192570e87 --- frameworks/core/text/text_emoji_processor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/core/text/text_emoji_processor.cpp b/frameworks/core/text/text_emoji_processor.cpp index dfd6637ed5e..af38a674c54 100644 --- a/frameworks/core/text/text_emoji_processor.cpp +++ b/frameworks/core/text/text_emoji_processor.cpp @@ -116,7 +116,7 @@ int32_t TextEmojiProcessor::GetCharacterNum(const std::string& content) int32_t charNum = 0; std::u16string u16Content = StringUtils::Str8ToStr16(content); int32_t pos = 0; - while (pos < u16Content.length()) { + while (pos < static_cast(u16Content.length())) { std::u32string u32Content; int32_t forwardLenU16 = GetEmojiLengthU16Forward(u32Content, pos, u16Content); if (forwardLenU16 > 1) { From f444be25cf3b054959c261c430b1504e0bf91b29 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 14:26:06 +0800 Subject: [PATCH 073/221] =?UTF-8?q?tdd=E9=97=A8=E7=A6=81=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../core/pattern/text_picker/text_picker_test_update.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp b/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp index fa57a1e9a1c..03768727e5b 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp @@ -1781,7 +1781,7 @@ HWTEST_F(TextPickerTestUpdate, UpdateForwardButtonMargin001, TestSize.Level1) auto pipeline = PipelineContext::GetCurrentContext(); auto dialogTheme = pipeline->GetTheme(); TextPickerDialogView::UpdateForwardButtonMargin(buttonForwardNode, dialogTheme); - EXPECT_NE(buttonBackwardNode->GetLayoutProperty()->margin_, nullptr); + EXPECT_NE(buttonForwardNode->GetLayoutProperty()->margin_, nullptr); } /** From 75c932a5f3d2c3a1d0cbd99ddf03e3291d0a06e5 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Sat, 20 Jul 2024 14:32:02 +0800 Subject: [PATCH 074/221] =?UTF-8?q?picker=E9=80=82=E8=80=81=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunjiakun --- .../dialog/dialog_layout_algorithm.cpp | 4 + .../pattern/dialog/dialog_pattern.h | 11 +++ .../pattern/picker/datepicker_dialog_view.cpp | 63 +++++++++++---- .../pattern/picker/datepicker_dialog_view.h | 3 +- .../text_picker/textpicker_dialog_view.cpp | 50 ++++++++---- .../text_picker/textpicker_dialog_view.h | 1 - .../time_picker/timepicker_dialog_view.cpp | 80 ++++++++++++++----- .../time_picker/timepicker_dialog_view.h | 5 +- 8 files changed, 160 insertions(+), 57 deletions(-) diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp index c11f6b1a034..d11f1c55d04 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/dialog/dialog_layout_algorithm.cpp @@ -92,6 +92,10 @@ void DialogLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) isSuitableForElderly_ = dialogPattern->GetIsSuitableForAging() && windowManager->GetWindowMode() != WindowMode::WINDOW_MODE_FLOATING && GreatOrEqual(pipeline->GetFontScale(), 1.75f); + auto isPickekDiaglog = dialogPattern->GetIsPickerDiaglog(); + if (isPickekDiaglog) { + isSuitableForElderly_ = false; + } if (isSuitableForElderly_ || GreatOrEqual(pipeline->GetFontScale(), 1.75f)) { dialogPattern->UpdateDeviceOrientation(SystemProperties::GetDeviceOrientation()); } diff --git a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h index ce583bbe06c..e9e3344c5a6 100644 --- a/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h +++ b/frameworks/core/components_ng/pattern/dialog/dialog_pattern.h @@ -255,6 +255,16 @@ public: return fontScaleForElderly_; } + void SetIsPickerDiaglog(bool value) + { + isPickerDiaglog_ = value; + } + + bool GetIsPickerDiaglog() + { + return isPickerDiaglog_; + } + void UpdateDeviceOrientation(const DeviceOrientation& deviceOrientation); void InitHostWindowRect(); void UpdateFontScale(); @@ -348,6 +358,7 @@ private: RefPtr contentColumn_; RefPtr contentRenderContext_; bool isSuitableForElderly_ = false; + bool isPickerDiaglog_ = false; bool notAdapationAging_ = false; float fontScaleForElderly_ = 1.0f; DeviceOrientation deviceOrientation_ = DeviceOrientation::PORTRAIT; diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp index 599eeb1699b..288958d6e00 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.cpp @@ -27,6 +27,7 @@ #include "core/components_ng/pattern/checkbox/checkbox_pattern.h" #include "core/components_ng/pattern/dialog/dialog_view.h" #include "core/components_ng/pattern/divider/divider_pattern.h" +#include "core/components_ng/pattern/dialog/dialog_pattern.h" #include "core/components_ng/pattern/image/image_pattern.h" #include "core/components_ng/pattern/picker/datepicker_pattern.h" #include "core/components_ng/pattern/picker/datepicker_row_layout_property.h" @@ -138,7 +139,9 @@ RefPtr DatePickerDialogView::Show(const DialogProperties& dialogPrope } auto dialogNode = DialogView::CreateDialogNode(dialogProperties, contentColumn); CHECK_NULL_RETURN(dialogNode, nullptr); - + auto dialogPattern = dialogNode->GetPattern(); + CHECK_NULL_RETURN(dialogPattern, nullptr); + dialogPattern->SetIsPickerDiaglog(true); // build dialog accept and cancel button if (NeedAdaptForAging()) { BuildDialogAcceptAndCancelButtonForAging(buttonInfos, settingData, timePickerNode, acceptNode, dateNode, @@ -762,11 +765,27 @@ void DatePickerDialogView::UpdateConfirmButtonTextLayoutProperty( CHECK_NULL_VOID(textLayoutProperty); textLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.ok")); textLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); + if (!NeedAdaptForAging()) { + textLayoutProperty->UpdateMaxFontScale(pickerTheme->GetNormalFontScale()); + } textLayoutProperty->UpdateFontSize( ConvertFontScaleValue(pickerTheme->GetOptionStyle(false, false).GetFontSize())); textLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); } +void DatePickerDialogView::UpdateCancelButtonTextLayoutProperty( + const RefPtr& textCancelLayoutProperty, const RefPtr& pickerTheme) +{ + CHECK_NULL_VOID(textCancelLayoutProperty); + textCancelLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.cancel")); + textCancelLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); + if (!NeedAdaptForAging()) { + textCancelLayoutProperty->UpdateMaxFontScale(pickerTheme->GetNormalFontScale()); + } + textCancelLayoutProperty->UpdateFontSize(pickerTheme->GetOptionStyle(false, false).GetFontSize()); + textCancelLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); +} + void DatePickerDialogView::UpdateButtonLayoutProperty( const RefPtr& buttonConfirmLayoutProperty, const RefPtr& pickerTheme) { @@ -863,7 +882,7 @@ void DatePickerDialogView::UpdateButtonStyles(const std::vector& but } UpdateButtonStyleAndRole(buttonInfos, index, buttonLayoutProperty, buttonRenderContext, buttonTheme); if (buttonInfos[index].fontSize.has_value()) { - buttonLayoutProperty->UpdateFontSize(buttonInfos[index].fontSize.value()); + buttonLayoutProperty->UpdateFontSize(ConvertFontScaleValue(buttonInfos[index].fontSize.value())); } if (buttonInfos[index].fontColor.has_value()) { buttonLayoutProperty->UpdateFontColor(buttonInfos[index].fontColor.value()); @@ -1135,11 +1154,7 @@ RefPtr DatePickerDialogView::CreateCancelNode(NG::DialogGestureEvent& CHECK_NULL_RETURN(textCancelNode, nullptr); auto textCancelLayoutProperty = textCancelNode->GetLayoutProperty(); CHECK_NULL_RETURN(textCancelLayoutProperty, nullptr); - textCancelLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.cancel")); - textCancelLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); - textCancelLayoutProperty->UpdateFontSize( - ConvertFontScaleValue(pickerTheme->GetOptionStyle(false, false).GetFontSize())); - textCancelLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); + UpdateCancelButtonTextLayoutProperty(textCancelLayoutProperty, pickerTheme); auto datePickerPattern = datePickerNode->GetPattern(); datePickerPattern->SetCancelNode(buttonCancelNode); textCancelNode->MountToParent(buttonCancelNode); @@ -1754,6 +1769,9 @@ std::function DatePickerDialogView::CloseDiaglogEvent(const RefPtr(datePickerPattern)]() { auto dialogNode = weak.Upgrade(); CHECK_NULL_VOID(dialogNode); + auto dialogPattern = dialogNode->GetPattern(); + CHECK_NULL_VOID(dialogPattern); + dialogPattern->SetIsPickerDiaglog(false); auto datePickerPattern = weakDatePickerPattern.Upgrade(); CHECK_NULL_VOID(datePickerPattern); @@ -1761,6 +1779,7 @@ std::function DatePickerDialogView::CloseDiaglogEvent(const RefPtrGetOverlayManager(); overlayManager->CloseDialog(dialogNode); + datePickerPattern->SetIsShowInDialog(false); } }; datePickerPattern->updateFontConfigurationEvent(event); @@ -1976,7 +1995,8 @@ bool DatePickerDialogView::NeedAdaptForAging() CHECK_NULL_RETURN(pipeline, false); auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_RETURN(pickerTheme, false); - if (GreatOrEqual(pipeline->GetFontScale(), pickerTheme->GetMaxOneFontScale())) { + if (GreatOrEqual(pipeline->GetFontScale(), pickerTheme->GetMaxOneFontScale()) && + Dimension(pipeline->GetRootHeight()).ConvertToVp() > pickerTheme->GetDeviceHeightLimit()) { return true; } return false; @@ -1997,15 +2017,14 @@ const Dimension DatePickerDialogView::AdjustFontSizeScale(const Dimension& fontS const Dimension DatePickerDialogView::ConvertFontScaleValue( const Dimension& fontSizeValue, const Dimension& fontSizeLimit, bool isUserSetFont) { - auto pipeline = PipelineContext::GetCurrentContextSafely(); + auto pipeline = PipelineContext::GetCurrentContextPtrSafelyWithCheck(); CHECK_NULL_RETURN(pipeline, fontSizeValue); auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_RETURN(pickerTheme, fontSizeValue); float fontSizeScale = pipeline->GetFontScale(); Dimension fontSizeValueResult = fontSizeValue; - if (NeedAdaptForAging() && - Dimension(pipeline->GetRootHeight()).ConvertToVp() > pickerTheme->GetDeviceHeightLimit()) { + if (NeedAdaptForAging()) { if (fontSizeValue.Unit() == DimensionUnit::VP) { if (isUserSetFont) { fontSizeValueResult = ConvertFontSizeLimit(fontSizeValue, fontSizeLimit, isUserSetFont); @@ -2017,12 +2036,20 @@ const Dimension DatePickerDialogView::ConvertFontScaleValue( fontSizeValueResult = fontSizeValue * fontSizeScale; } if (isUserSetFont) { - fontSizeValueResult = - ConvertFontSizeLimit(fontSizeValueResult, fontSizeLimit, isUserSetFont); + fontSizeValueResult = ConvertFontSizeLimit(fontSizeValueResult, fontSizeLimit, isUserSetFont); } } } else { - fontSizeValueResult = AdjustFontSizeScale(fontSizeValueResult, pickerTheme->GetNormalFontScale()); + if (isUserSetFont) { + fontSizeValueResult = ConvertFontSizeLimit(fontSizeValue, fontSizeLimit, isUserSetFont); + } + + if (GreatOrEqualCustomPrecision(fontSizeScale, pickerTheme->GetMaxOneFontScale()) && + fontSizeValueResult.Unit() != DimensionUnit::VP) { + if (!NearZero(fontSizeScale)) { + fontSizeValueResult = fontSizeValueResult / fontSizeScale; + } + } } return fontSizeValueResult; } @@ -2062,8 +2089,7 @@ const Dimension DatePickerDialogView::ConvertTitleFontScaleValue(const Dimension auto adjustedScale = std::clamp(fontScale, pickerTheme->GetNormalFontScale(), pickerTheme->GetTitleFontScaleLimit()); - if (NeedAdaptForAging() && - Dimension(pipeline->GetRootHeight()).ConvertToVp() > pickerTheme->GetDeviceHeightLimit()) { + if (NeedAdaptForAging()) { if (fontSizeValue.Unit() == DimensionUnit::VP) { return (fontSizeValue * adjustedScale); } else { @@ -2073,7 +2099,10 @@ const Dimension DatePickerDialogView::ConvertTitleFontScaleValue(const Dimension } } } else { - return AdjustFontSizeScale(fontSizeValue, pickerTheme->GetNormalFontScale()); + if (GreatOrEqualCustomPrecision(fontScale, pickerTheme->GetMaxOneFontScale()) && + fontSizeValue.Unit() != DimensionUnit::VP) { + return (fontSizeValue / pipeline->GetFontScale()); + } } return fontSizeValue; } diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.h b/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.h index ae0277a5ca7..1154da12815 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.h +++ b/frameworks/core/components_ng/pattern/picker/datepicker_dialog_view.h @@ -161,7 +161,8 @@ private: static const Dimension ConvertTitleFontScaleValue(const Dimension& fontSizeValue); static const Dimension AdjustFontSizeScale(const Dimension& fontSizeValue, double fontScale); static void GetUserSettingLimit(); - + static void UpdateCancelButtonTextLayoutProperty( + const RefPtr& textCancelLayoutProperty, const RefPtr& pickerTheme); static bool switchTimePickerFlag_; static bool switchDatePickerFlag_; static bool isShowTime_; diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.cpp index 7a31c42e057..4eea8b534e2 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.cpp @@ -25,6 +25,7 @@ #include "core/components_ng/pattern/button/button_pattern.h" #include "core/components_ng/pattern/dialog/dialog_view.h" #include "core/components_ng/pattern/divider/divider_pattern.h" +#include "core/components_ng/pattern/dialog/dialog_pattern.h" #include "core/components_ng/pattern/image/image_pattern.h" #include "core/components_ng/pattern/stack/stack_pattern.h" #include "core/components_ng/pattern/text/text_pattern.h" @@ -113,7 +114,9 @@ RefPtr TextPickerDialogView::RangeShow(const DialogProperties& dialog textPickerNode->MountToParent(contentColumn); auto dialogNode = DialogView::CreateDialogNode(dialogProperties, contentColumn); CHECK_NULL_RETURN(dialogNode, nullptr); - + auto dialogPattern = dialogNode->GetPattern(); + CHECK_NULL_RETURN(dialogPattern, nullptr); + dialogPattern->SetIsPickerDiaglog(true); auto closeDiaglogEvent = CloseDiaglogEvent(textPickerPattern, dialogNode); auto closeCallback = [func = std::move(closeDiaglogEvent)](const GestureEvent& /* info */) { func(); @@ -140,12 +143,16 @@ std::function TextPickerDialogView::CloseDiaglogEvent(const RefPtr(textPickerPattern)]() { auto dialogNode = weak.Upgrade(); CHECK_NULL_VOID(dialogNode); + auto dialogPattern = dialogNode->GetPattern(); + CHECK_NULL_VOID(dialogPattern); + dialogPattern->SetIsPickerDiaglog(false); auto textPickerPattern = weakPattern.Upgrade(); CHECK_NULL_VOID(textPickerPattern); if (textPickerPattern->GetIsShowInDialog()) { auto pipeline = PipelineContext::GetCurrentContext(); auto overlayManager = pipeline->GetOverlayManager(); overlayManager->CloseDialog(dialogNode); + textPickerPattern->SetIsShowInDialog(false); } }; textPickerPattern->updateFontConfigurationEvent(event); @@ -260,6 +267,9 @@ RefPtr TextPickerDialogView::OptionsShow(const DialogProperties& dial textPickerNode->MountToParent(contentColumn); auto dialogNode = DialogView::CreateDialogNode(dialogProperties, contentColumn); CHECK_NULL_RETURN(dialogNode, nullptr); + auto dialogPattern = dialogNode->GetPattern(); + CHECK_NULL_RETURN(dialogPattern, nullptr); + dialogPattern->SetIsPickerDiaglog(true); auto closeDiaglogEvent = CloseDiaglogEvent(textPickerPattern, dialogNode); auto closeCallBack = [func = std::move(closeDiaglogEvent)](const GestureEvent& /* info */) { @@ -269,8 +279,7 @@ RefPtr TextPickerDialogView::OptionsShow(const DialogProperties& dial auto pipeline = PipelineContext::GetCurrentContextSafely(); CHECK_NULL_RETURN(pipeline, nullptr); float scale = pipeline->GetFontScale(); - if (GreatOrEqualCustomPrecision(scale, pickerTheme->GetMaxOneFontScale()) - && GetIsOverRange(scale)) { + if (NeedAdaptForAging()) { dialogNode = SeparatedOptionsShow(contentColumn, textPickerNode, buttonInfos, settingData, dialogEvent, dialogCancelEvent, scale, closeCallBack, dialogNode); return dialogNode; @@ -564,6 +573,9 @@ void TextPickerDialogView::UpdateConfirmButtonTextLayoutProperty( CHECK_NULL_VOID(textLayoutProperty); textLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.ok")); textLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); + if (!NeedAdaptForAging()) { + textLayoutProperty->UpdateMaxFontScale(pickerTheme->GetNormalFontScale()); + } textLayoutProperty->UpdateFontSize( ConvertFontScaleValue(pickerTheme->GetOptionStyle(false, false).GetFontSize())); textLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); @@ -576,6 +588,9 @@ void TextPickerDialogView::UpdateCancelButtonTextLayoutProperty( CHECK_NULL_VOID(textCancelLayoutProperty); textCancelLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.cancel")); textCancelLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); + if (!NeedAdaptForAging()) { + textCancelLayoutProperty->UpdateMaxFontScale(pickerTheme->GetNormalFontScale()); + } textCancelLayoutProperty->UpdateFontSize( ConvertFontScaleValue(pickerTheme->GetOptionStyle(false, false).GetFontSize())); textCancelLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); @@ -694,7 +709,7 @@ void TextPickerDialogView::UpdateButtonStyles(const std::vector& but } UpdateButtonStyleAndRole(buttonInfos, index, buttonLayoutProperty, buttonRenderContext, buttonTheme); if (buttonInfos[index].fontSize.has_value()) { - buttonLayoutProperty->UpdateFontSize(buttonInfos[index].fontSize.value()); + buttonLayoutProperty->UpdateFontSize(ConvertFontScaleValue(buttonInfos[index].fontSize.value())); } if (buttonInfos[index].fontColor.has_value()) { buttonLayoutProperty->UpdateFontColor(buttonInfos[index].fontColor.value()); @@ -1028,11 +1043,6 @@ void TextPickerDialogView::UpdateButtonDefaultFocus(const std::vector TextPickerDialogView::CreateForwardNode(NG::DialogGestureEvent& moveForwardEvent, const RefPtr& textPickerNode, const std::vector& buttonInfos) { @@ -1429,7 +1439,8 @@ bool TextPickerDialogView::NeedAdaptForAging() CHECK_NULL_RETURN(pipeline, false); auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_RETURN(pickerTheme, false); - if (GreatOrEqual(pipeline->GetFontScale(), pickerTheme->GetMaxOneFontScale())) { + if (GreatOrEqual(pipeline->GetFontScale(), pickerTheme->GetMaxOneFontScale()) && + Dimension(pipeline->GetRootHeight()).ConvertToVp() > pickerTheme->GetDeviceHeightLimit()) { return true; } return false; @@ -1450,15 +1461,14 @@ const Dimension TextPickerDialogView::AdjustFontSizeScale(const Dimension& fontS const Dimension TextPickerDialogView::ConvertFontScaleValue( const Dimension& fontSizeValue, const Dimension& fontSizeLimit, bool isUserSetFont) { - auto pipeline = PipelineContext::GetCurrentContextSafely(); + auto pipeline = PipelineContext::GetCurrentContextPtrSafelyWithCheck(); CHECK_NULL_RETURN(pipeline, fontSizeValue); auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_RETURN(pickerTheme, fontSizeValue); float fontSizeScale = pipeline->GetFontScale(); Dimension fontSizeValueResult = fontSizeValue; - if (NeedAdaptForAging() && - Dimension(pipeline->GetRootHeight()).ConvertToVp() > pickerTheme->GetDeviceHeightLimit()) { + if (NeedAdaptForAging()) { if (fontSizeValue.Unit() == DimensionUnit::VP) { if (isUserSetFont) { fontSizeValueResult = ConvertFontSizeLimit(fontSizeValue, fontSizeLimit, isUserSetFont); @@ -1470,12 +1480,20 @@ const Dimension TextPickerDialogView::ConvertFontScaleValue( fontSizeValueResult = fontSizeValue * fontSizeScale; } if (isUserSetFont) { - fontSizeValueResult = - ConvertFontSizeLimit(fontSizeValueResult, fontSizeLimit, isUserSetFont); + fontSizeValueResult = ConvertFontSizeLimit(fontSizeValueResult, fontSizeLimit, isUserSetFont); } } } else { - fontSizeValueResult = AdjustFontSizeScale(fontSizeValueResult, pickerTheme->GetNormalFontScale()); + if (isUserSetFont) { + fontSizeValueResult = ConvertFontSizeLimit(fontSizeValue, fontSizeLimit, isUserSetFont); + } + + if (GreatOrEqualCustomPrecision(fontSizeScale, pickerTheme->GetMaxOneFontScale()) && + fontSizeValueResult.Unit() != DimensionUnit::VP) { + if (!NearZero(fontSizeScale)) { + fontSizeValueResult = fontSizeValueResult / fontSizeScale; + } + } } return fontSizeValueResult; } diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.h index d99377b0ce4..f80367d8955 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.h @@ -118,7 +118,6 @@ private: const RefPtr& buttonTheme); static void UpdateButtonDefaultFocus(const std::vector& buttonInfos, const RefPtr& buttonNode, bool isConfirm); - static bool GetIsOverRange(const float& scale); static void SetDialogNodePageActive(RefPtr& contentRow, RefPtr& textPickerNode, const uint32_t& dialogNodePage, const uint32_t& showCount); static RefPtr SeparatedOptionsShow(RefPtr& contentColumn, RefPtr& textPickerNode, diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.cpp index 874a19cb961..7fdb2a1aeb8 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.cpp @@ -18,6 +18,7 @@ #include "core/components_ng/base/view_stack_processor.h" #include "core/components_ng/pattern/button/button_pattern.h" #include "core/components_ng/pattern/dialog/dialog_view.h" +#include "core/components_ng/pattern/dialog/dialog_pattern.h" #include "core/components_ng/pattern/divider/divider_pattern.h" #include "core/components_ng/pattern/stack/stack_pattern.h" #include "core/components_ng/pattern/text/text_pattern.h" @@ -203,6 +204,9 @@ RefPtr TimePickerDialogView::Show(const DialogProperties& dialogPrope } auto dialogNode = DialogView::CreateDialogNode(dialogProperties, contentColumn); CHECK_NULL_RETURN(dialogNode, nullptr); + auto dialogPattern = dialogNode->GetPattern(); + CHECK_NULL_RETURN(dialogPattern, nullptr); + dialogPattern->SetIsPickerDiaglog(true); auto closeDiaglogEvent = CloseDiaglogEvent(timePickerPattern, dialogNode); auto event = [func = std::move(closeDiaglogEvent)](const GestureEvent& /* info */) { func(); @@ -229,12 +233,16 @@ std::function TimePickerDialogView::CloseDiaglogEvent(const RefPtr(timePickerPattern)]() { auto dialogNode = weak.Upgrade(); CHECK_NULL_VOID(dialogNode); + auto dialogPattern = dialogNode->GetPattern(); + CHECK_NULL_VOID(dialogPattern); + dialogPattern->SetIsPickerDiaglog(false); auto timePickerPattern = weakPattern.Upgrade(); CHECK_NULL_VOID(timePickerPattern); if (timePickerPattern->GetIsShowInDialog()) { auto pipeline = PipelineContext::GetCurrentContext(); auto overlayManager = pipeline->GetOverlayManager(); overlayManager->CloseDialog(dialogNode); + timePickerPattern->SetIsShowInDialog(false); } }; timePickerPattern->updateFontConfigurationEvent(event); @@ -603,11 +611,7 @@ RefPtr TimePickerDialogView::CreateConfirmNode(const RefPtrGetLayoutProperty(); CHECK_NULL_RETURN(textLayoutProperty, nullptr); - textLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.ok")); - textLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); - textLayoutProperty->UpdateFontSize( - ConvertFontScaleValue(pickerTheme->GetOptionStyle(false, false).GetFontSize())); - textLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); + UpdateConfirmButtonTextLayoutProperty(textLayoutProperty, pickerTheme); auto columnPattern = timePickerNode->GetPattern(); columnPattern->SetConfirmNode(buttonConfirmNode); auto buttonConfirmEventHub = buttonConfirmNode->GetEventHub(); @@ -683,6 +687,20 @@ void TimePickerDialogView::UpdateConfirmButtonMargin( buttonConfirmLayoutProperty->UpdateMargin(margin); } +void TimePickerDialogView::UpdateConfirmButtonTextLayoutProperty( + const RefPtr& textLayoutProperty, const RefPtr& pickerTheme) +{ + CHECK_NULL_VOID(textLayoutProperty); + textLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.ok")); + textLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); + if (!NeedAdaptForAging()) { + textLayoutProperty->UpdateMaxFontScale(pickerTheme->GetNormalFontScale()); + } + textLayoutProperty->UpdateFontSize( + ConvertFontScaleValue(pickerTheme->GetOptionStyle(false, false).GetFontSize())); + textLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); +} + void TimePickerDialogView::UpdateCancelButtonMargin( const RefPtr& buttonCancelLayoutProperty, const RefPtr& dialogTheme) { @@ -717,11 +735,7 @@ RefPtr TimePickerDialogView::CreateCancelNode(NG::DialogGestureEvent& CHECK_NULL_RETURN(textCancelNode, nullptr); auto textCancelLayoutProperty = textCancelNode->GetLayoutProperty(); CHECK_NULL_RETURN(textCancelLayoutProperty, nullptr); - textCancelLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.cancel")); - textCancelLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); - textCancelLayoutProperty->UpdateFontSize( - ConvertFontScaleValue(pickerTheme->GetOptionStyle(false, false).GetFontSize())); - textCancelLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); + UpdateCancelButtonTextLayoutProperty(textCancelLayoutProperty, pickerTheme); auto columnPattern = timePickerNode->GetPattern(); columnPattern->SetCancelNode(buttonCancelNode); textCancelNode->MountToParent(buttonCancelNode); @@ -755,6 +769,19 @@ RefPtr TimePickerDialogView::CreateCancelNode(NG::DialogGestureEvent& return buttonCancelNode; } +void TimePickerDialogView::UpdateCancelButtonTextLayoutProperty( + const RefPtr& textCancelLayoutProperty, const RefPtr& pickerTheme) +{ + CHECK_NULL_VOID(textCancelLayoutProperty); + textCancelLayoutProperty->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.cancel")); + textCancelLayoutProperty->UpdateTextColor(pickerTheme->GetOptionStyle(true, false).GetTextColor()); + if (!NeedAdaptForAging()) { + textCancelLayoutProperty->UpdateMaxFontScale(pickerTheme->GetNormalFontScale()); + } + textCancelLayoutProperty->UpdateFontSize(pickerTheme->GetOptionStyle(false, false).GetFontSize()); + textCancelLayoutProperty->UpdateFontWeight(pickerTheme->GetOptionStyle(true, false).GetFontWeight()); +} + void TimePickerDialogView::UpdateButtonStyles(const std::vector& buttonInfos, size_t index, const RefPtr& buttonLayoutProperty, const RefPtr& buttonRenderContext) { @@ -770,7 +797,7 @@ void TimePickerDialogView::UpdateButtonStyles(const std::vector& but } UpdateButtonStyleAndRole(buttonInfos, index, buttonLayoutProperty, buttonRenderContext, buttonTheme); if (buttonInfos[index].fontSize.has_value()) { - buttonLayoutProperty->UpdateFontSize(buttonInfos[index].fontSize.value()); + buttonLayoutProperty->UpdateFontSize(ConvertFontScaleValue(buttonInfos[index].fontSize.value())); } if (buttonInfos[index].fontColor.has_value()) { buttonLayoutProperty->UpdateFontColor(buttonInfos[index].fontColor.value()); @@ -974,7 +1001,9 @@ bool TimePickerDialogView::NeedAdaptForAging() CHECK_NULL_RETURN(pipeline, false); auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_RETURN(pickerTheme, false); - if (GreatOrEqual(pipeline->GetFontScale(), pickerTheme->GetMaxOneFontScale())) { + + if (GreatOrEqual(pipeline->GetFontScale(), pickerTheme->GetMaxOneFontScale()) && + Dimension(pipeline->GetRootHeight()).ConvertToVp() > pickerTheme->GetDeviceHeightLimit()) { return true; } return false; @@ -995,15 +1024,14 @@ const Dimension TimePickerDialogView::AdjustFontSizeScale(const Dimension& fontS const Dimension TimePickerDialogView::ConvertFontScaleValue( const Dimension& fontSizeValue, const Dimension& fontSizeLimit, bool isUserSetFont) { - auto pipeline = PipelineContext::GetCurrentContextSafely(); + auto pipeline = PipelineContext::GetCurrentContextPtrSafelyWithCheck(); CHECK_NULL_RETURN(pipeline, fontSizeValue); auto pickerTheme = pipeline->GetTheme(); CHECK_NULL_RETURN(pickerTheme, fontSizeValue); float fontSizeScale = pipeline->GetFontScale(); Dimension fontSizeValueResult = fontSizeValue; - if (NeedAdaptForAging() && - Dimension(pipeline->GetRootHeight()).ConvertToVp() > pickerTheme->GetDeviceHeightLimit()) { + if (NeedAdaptForAging()) { if (fontSizeValue.Unit() == DimensionUnit::VP) { if (isUserSetFont) { fontSizeValueResult = ConvertFontSizeLimit(fontSizeValue, fontSizeLimit, isUserSetFont); @@ -1015,12 +1043,20 @@ const Dimension TimePickerDialogView::ConvertFontScaleValue( fontSizeValueResult = fontSizeValue * fontSizeScale; } if (isUserSetFont) { - fontSizeValueResult = - ConvertFontSizeLimit(fontSizeValueResult, fontSizeLimit, isUserSetFont); + fontSizeValueResult = ConvertFontSizeLimit(fontSizeValueResult, fontSizeLimit, isUserSetFont); } } } else { - fontSizeValueResult = AdjustFontSizeScale(fontSizeValueResult, pickerTheme->GetNormalFontScale()); + if (isUserSetFont) { + fontSizeValueResult = ConvertFontSizeLimit(fontSizeValue, fontSizeLimit, isUserSetFont); + } + + if (GreatOrEqualCustomPrecision(fontSizeScale, pickerTheme->GetMaxOneFontScale()) && + fontSizeValueResult.Unit() != DimensionUnit::VP) { + if (!NearZero(fontSizeScale)) { + fontSizeValueResult = fontSizeValueResult / fontSizeScale; + } + } } return fontSizeValueResult; } @@ -1060,8 +1096,7 @@ const Dimension TimePickerDialogView::ConvertTitleFontScaleValue(const Dimension auto adjustedScale = std::clamp(fontScale, pickerTheme->GetNormalFontScale(), pickerTheme->GetTitleFontScaleLimit()); - if (NeedAdaptForAging() && - Dimension(pipeline->GetRootHeight()).ConvertToVp() > pickerTheme->GetDeviceHeightLimit()) { + if (NeedAdaptForAging()) { if (fontSizeValue.Unit() == DimensionUnit::VP) { return (fontSizeValue * adjustedScale); } else { @@ -1071,7 +1106,10 @@ const Dimension TimePickerDialogView::ConvertTitleFontScaleValue(const Dimension } } } else { - return AdjustFontSizeScale(fontSizeValue, pickerTheme->GetNormalFontScale()); + if (GreatOrEqualCustomPrecision(fontScale, pickerTheme->GetMaxOneFontScale()) && + fontSizeValue.Unit() != DimensionUnit::VP) { + return (fontSizeValue / pipeline->GetFontScale()); + } } return fontSizeValue; } diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.h b/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.h index 5afc1ef5e8d..f3b424d849e 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.h +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_dialog_view.h @@ -99,7 +99,10 @@ private: static void GetUserSettingLimit(); static void SetTextDisappearProperties(const RefPtr& pickerTheme, const PickerTextProperties& properties); - + static void UpdateConfirmButtonTextLayoutProperty( + const RefPtr& textLayoutProperty, const RefPtr& pickerTheme); + static void UpdateCancelButtonTextLayoutProperty( + const RefPtr& textCancelLayoutProperty, const RefPtr& pickerTheme); static bool switchFlag_; static Dimension selectedTextStyleFont_; static Dimension normalTextStyleFont_; From 9116998e80f71619ea118a70a967bcf2772f2fae Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Thu, 18 Jul 2024 16:52:47 +0800 Subject: [PATCH 075/221] =?UTF-8?q?parse=5Ftest=5Fng=20tdd=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 Change-Id: If4309e3fc3f38d942a3a3f51781e1538acdc8f77 --- test/unittest/core/svg/parse_test_ng.cpp | 3 + test/unittest/core/svg/parse_testtwo_ng.cpp | 81 +++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/test/unittest/core/svg/parse_test_ng.cpp b/test/unittest/core/svg/parse_test_ng.cpp index 486bf457b0a..2fb48298182 100644 --- a/test/unittest/core/svg/parse_test_ng.cpp +++ b/test/unittest/core/svg/parse_test_ng.cpp @@ -1978,5 +1978,8 @@ HWTEST_F(ParseTestNg, ParseNodeTest009, TestSize.Level1) svgNode->SetAttr("mask", "testMask"); EXPECT_EQ(svgNode->GetBaseAttributes().maskId, "testMask"); + + svgNode->SetAttr("patterntransform", "testPatterntransform"); + EXPECT_EQ(svgNode->GetBaseAttributes().transform, "testPatterntransform"); } } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/test/unittest/core/svg/parse_testtwo_ng.cpp b/test/unittest/core/svg/parse_testtwo_ng.cpp index 66f0e045912..8fd0f4d8da7 100644 --- a/test/unittest/core/svg/parse_testtwo_ng.cpp +++ b/test/unittest/core/svg/parse_testtwo_ng.cpp @@ -733,4 +733,85 @@ HWTEST_F(ParseTestTwoNg, ParseGradientTest002, TestSize.Level1) svgCircle->UpdateFillGradient(viewPort); svgCircle->UpdateStrokeGradient(viewPort); } + +/** + * @tc.name: ParseNodeTest001 + * @tc.desc: SvgNode SetAttr Parameters + * @tc.type: FUNC + */ +HWTEST_F(ParseTestTwoNg, ParseNodeTest001, TestSize.Level1) +{ + auto svgNode = AccessibilityManager::MakeRefPtr(); + svgNode->SetAttr("stroke-dasharray", ""); + + svgNode->SetAttr("stroke-linecap", "round"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetLineCap(), LineCapStyle::ROUND); + + svgNode->SetAttr("strokeLinecap", "square"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetLineCap(), LineCapStyle::SQUARE); + + svgNode->SetAttr("stroke-linejoin", "bevel"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetLineJoin(), LineJoinStyle::BEVEL); + + svgNode->SetAttr("strokeLinejoin", "round"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetLineJoin(), LineJoinStyle::ROUND); + + svgNode->SetAttr("stroke-miterlimit", "0.1"); + EXPECT_NE(svgNode->GetBaseAttributes().strokeState.GetMiterLimit(), 0.1); + + svgNode->SetAttr("stroke-miterlimit", "1.1"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetMiterLimit(), 1.1); + + svgNode->SetAttr("strokeMiterlimit", "0.2"); + EXPECT_NE(svgNode->GetBaseAttributes().strokeState.GetMiterLimit(), 0.2); + + svgNode->SetAttr("strokeMiterlimit", "1.2"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetMiterLimit(), 1.2); + + svgNode->SetAttr("strokeOpacity", "0.321"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetOpacity().GetValue(), 0.321); + + svgNode->SetAttr("strokeWidth", "1.2"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetLineWidth().Value(), 1.2); + + svgNode->SetAttr("strokeWidth", "-1.2"); + EXPECT_NE(svgNode->GetBaseAttributes().strokeState.GetLineWidth().Value(), -1.2); + + svgNode->SetAttr("strokeDasharray", ""); + svgNode->SetAttr("strokeDasharray", "1.1 1.2"); + auto tesData = std::vector{1.1, 1.2}; + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetLineDash().lineDash, tesData); + + svgNode->SetAttr("strokeDashoffset", "2.0"); + EXPECT_EQ(svgNode->GetBaseAttributes().strokeState.GetLineDash().dashOffset, 2.0); + + svgNode->SetAttr("transform-origin", "test_transform-origin"); + EXPECT_EQ(svgNode->GetBaseAttributes().transformOrigin, "test_transform-origin"); +} + +/** + * @tc.name: ParseSvgDomTest001 + * @tc.desc: SvgDom test + * @tc.type: FUNC + */ +HWTEST_F(ParseTestTwoNg, ParseNodeTest002, TestSize.Level1) +{ + auto svgStream = SkMemoryStream::MakeCopy(USE_SVG_LABEL.c_str(), USE_SVG_LABEL.length()); + ImageSourceInfo src; + src.SetFillColor(Color::GREEN); + auto svgDom = SvgDom::CreateSvgDom(*svgStream, src); + auto svg = AceType::DynamicCast(svgDom->root_); + + auto containerSize = svgDom->GetContainerSize(); + EXPECT_EQ(containerSize, SizeF(24.0f, 24.0f)); + + svgDom->SetFillColor(Color::RED); + EXPECT_EQ(svgDom->fillColor_.value(), Color::RED); + + svgDom->SetSmoothEdge(1.1f); + EXPECT_EQ(svgDom->smoothEdge_, 1.1f); + + svgDom->ControlAnimation(true); + EXPECT_EQ(svgDom->IsStatic(), true); +} } // namespace OHOS::Ace::NG From d98653879c837bba6be992b03327c24cdb55d001 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 14:56:45 +0800 Subject: [PATCH 076/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../pattern/text_picker/text_picker_pattern_test_ng.cpp | 6 ++++-- .../core/pattern/text_picker/text_picker_test_update.cpp | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp b/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp index 641029f68bb..ed1606b9205 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp @@ -1751,7 +1751,8 @@ HWTEST_F(TextPickerPatternTestNg, LinearFontSize001, TestSize.Level1) { InitTextPickerPatternTestNg(); Dimension dimension = Dimension(FONT_SIZE_10); - Dimension dimension1 = textPickerColumnPattern_->LinearFontSize(dimension, dimension, 1); + Dimension dimension1; + dimension1 = textPickerColumnPattern_->LinearFontSize(dimension, dimension, 1); EXPECT_TRUE(dimension < dimension1); } @@ -1764,7 +1765,8 @@ HWTEST_F(TextPickerPatternTestNg, LinearFontSize002, TestSize.Level1) { InitTextPickerPatternTestNg(); Dimension dimension = Dimension(FONT_SIZE_10); - Dimension dimension1 = textPickerColumnPattern_->LinearFontSize(dimension, dimension, 2); + Dimension dimension1; + dimension1 = textPickerColumnPattern_->LinearFontSize(dimension, dimension, 2); EXPECT_TRUE(dimension < dimension1); } diff --git a/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp b/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp index 03768727e5b..d9fa507eb96 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp @@ -1847,7 +1847,7 @@ HWTEST_F(TextPickerTestUpdate, SetRange001, TestSize.Level1) auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(frameNode, nullptr); TextPickerModelNG::SetRange(frameNode, range); - ASSERT_NE(frameNode->GetPattern()->GetRange(), nullptr); + ASSERT_FALSE(frameNode->GetPattern()->GetRange().empty()); } /** @@ -1866,7 +1866,7 @@ HWTEST_F(TextPickerTestUpdate, SetValue001, TestSize.Level1) auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(frameNode, nullptr); TextPickerModelNG::SetValue(frameNode, value); - ASSERT_NE(frameNode->GetPattern()->values_, nullptr); + ASSERT_NE(frameNode->GetPattern()->GetSelected(), 0); } /** @@ -1888,6 +1888,6 @@ HWTEST_F(TextPickerTestUpdate, SetValues001, TestSize.Level1) auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(frameNode, nullptr); TextPickerModelNG::SetValues(frameNode, value); - ASSERT_NE(frameNode->GetPattern()->values_, nullptr); + ASSERT_NE(frameNode->GetPattern()->GetSelected(), 0); } } // namespace OHOS::Ace::NG \ No newline at end of file From 5bcc762741eb2d83a771ba5b2a7f0065650ef515 Mon Sep 17 00:00:00 2001 From: yanghua_angel Date: Sat, 20 Jul 2024 14:57:34 +0800 Subject: [PATCH 077/221] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=B8=BA--=E6=98=AF=E5=90=A6=E5=8F=88=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E7=9A=84UI=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yanghua_angel --- frameworks/core/common/window.h | 2 +- .../core/components_ng/render/adapter/form_render_window.h | 4 ++-- frameworks/core/components_ng/render/adapter/rosen_window.h | 4 ++-- frameworks/core/pipeline_ng/pipeline_context.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frameworks/core/common/window.h b/frameworks/core/common/window.h index 8cb1de782f7..e6496d77b63 100644 --- a/frameworks/core/common/window.h +++ b/frameworks/core/common/window.h @@ -84,7 +84,7 @@ public: virtual void FlushModifier() {} - virtual bool HasUIAnimation() + virtual bool HasUIRunningAnimation() { return false; } diff --git a/frameworks/core/components_ng/render/adapter/form_render_window.h b/frameworks/core/components_ng/render/adapter/form_render_window.h index b2fa15075a4..436aa02148c 100755 --- a/frameworks/core/components_ng/render/adapter/form_render_window.h +++ b/frameworks/core/components_ng/render/adapter/form_render_window.h @@ -69,9 +69,9 @@ public: rsUIDirector_->FlushModifier(); } - bool HasUIAnimation() override + bool HasUIRunningAnimation() override { - return rsUIDirector_->HasUIAnimation(); + return rsUIDirector_->HasUIRunningAnimation(); } #endif diff --git a/frameworks/core/components_ng/render/adapter/rosen_window.h b/frameworks/core/components_ng/render/adapter/rosen_window.h index 22e06995ba4..5f879521447 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_window.h +++ b/frameworks/core/components_ng/render/adapter/rosen_window.h @@ -87,9 +87,9 @@ public: rsUIDirector_->FlushModifier(); } - bool HasUIAnimation() override + bool HasUIRunningAnimation() override { - return rsUIDirector_->HasUIAnimation(); + return rsUIDirector_->HasUIRunningAnimation(); } void OnShow() override; diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index 91731dc4cac..3e60a416656 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -593,7 +593,7 @@ void PipelineContext::FlushVsync(uint64_t nanoTimestamp, uint32_t frameCount) } while (false); #endif - if (hasRunningAnimation || window_->HasUIAnimation()) { + if (hasRunningAnimation || window_->HasUIRunningAnimation()) { RequestFrame(); } window_->FlushModifier(); From 273a6fb9d7bbe20776a269be1a8bb1f4b7174da1 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Sat, 20 Jul 2024 15:15:45 +0800 Subject: [PATCH 078/221] bugfix Signed-off-by: sunjiakun --- .../core/components_ng/pattern/overlay/overlay_manager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index b2da655ffda..dc7d1c75a66 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -6041,9 +6041,9 @@ void OverlayManager::UpdatePixelMapPosition(bool isSubwindowOverlay) CHECK_NULL_VOID(imageNode); auto imageContext = imageNode->GetRenderContext(); CHECK_NULL_VOID(imageContext); - auto rect = imageContext->GetPaintRectWithTranslate(); - imageContext->UpdatePosition(OffsetT(Dimension(moveVector.GetX() + rect.first.GetX()), - Dimension(moveVector.GetY() + rect.first.GetY()))); + auto rect = imageNode->GetOffsetRelativeToWindow(); + imageContext->UpdatePosition(OffsetT(Dimension(moveVector.GetX() + rect.GetX()), + Dimension(moveVector.GetY() + rect.GetY()))); imageContext->OnModifyDone(); } From e97eceea36ebd690debfc252670cbc2e96b4c725 Mon Sep 17 00:00:00 2001 From: tomkl123 Date: Sat, 20 Jul 2024 15:23:16 +0800 Subject: [PATCH 079/221] =?UTF-8?q?Grid=E6=96=B0=E5=A2=9EalignItems?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tomkl123 Change-Id: I42f2cfd9ef120885bb61d34bf229d96158e0c01e --- .../bridge/declarative_frontend/engine/jsEnumStyle.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js index 283f8e30f96..6e396cedab5 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js +++ b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js @@ -3297,6 +3297,12 @@ var GestureRecognizerState; GestureRecognizerState[GestureRecognizerState["FAILED"] = 5] = "FAILED"; })(GestureRecognizerState || (GestureRecognizerState = {})); +var GridItemAlignment; +(function (GridItemAlignment) { + GridItemAlignment[GridItemAlignment["DEFAULT"] = 0] = "DEFAULT"; + GridItemAlignment[GridItemAlignment["STRETCH"] = 1] = "STRETCH"; +})(GridItemAlignment || (GridItemAlignment = {})); + class ImageAnalyzerController { constructor() { } From a4e18a670889c949d6bcdfc1807fd9755fcc1f64 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 15:26:07 +0800 Subject: [PATCH 080/221] =?UTF-8?q?=E9=97=A8=E7=A6=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../common/recorder/event_recorder_test.cpp | 30 +++---------------- .../text_picker_pattern_test_ng.cpp | 4 +-- .../text_picker/text_picker_test_update.cpp | 6 ++-- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index b1701cd9e59..acc4fda896e 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ -#define private public -#define protected public #include "gtest/gtest.h" #include "interfaces/inner_api/ace/ui_event_observer.h" @@ -699,8 +697,12 @@ HWTEST_F(EventRecorderTest, IsCacheAvaliable001, TestSize.Level1) */ HWTEST_F(EventRecorderTest, PutString001, TestSize.Level1) { + Recorder::ExposureCfg cfg; + Recorder::NodeDataCache::Get().Clear(""); auto pageNode = CreatePageNode("pages/Index"); bool result = Recorder::NodeDataCache::Get().PutString(pageNode, "", "1"); + std::unordered_map nodes; + Recorder::NodeDataCache::Get().GetNodeData("", nodes); EXPECT_FALSE(result); } @@ -740,28 +742,4 @@ HWTEST_F(EventRecorderTest, GetExposureCfg001, TestSize.Level1) Recorder::NodeDataCache::Get().GetExposureCfg(pageUrl, "", cfg); EXPECT_TRUE(pageUrl.empty()); } - -/** - * @tc.name: Clear001 - * @tc.desc: Test Clear. - * @tc.type: FUNC - */ -HWTEST_F(EventRecorderTest, Clear001, TestSize.Level1) -{ - Recorder::ExposureCfg cfg; - Recorder::NodeDataCache::Get().Clear(""); - EXPECT_TRUE(Recorder::NodeDataCache::Get().container_->empty()); -} - -/** - * @tc.name: GetNodeData001 - * @tc.desc: Test GetNodeData. - * @tc.type: FUNC - */ -HWTEST_F(EventRecorderTest, GetNodeData001, TestSize.Level1) -{ - std::unordered_map nodes; - Recorder::NodeDataCache::Get().GetNodeData("", nodes); - EXPECT_TRUE(Recorder::NodeDataCache::Get().container_->empty()); -} } // namespace OHOS::Ace diff --git a/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp b/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp index ed1606b9205..4cc527735ba 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_pattern_test_ng.cpp @@ -1753,7 +1753,7 @@ HWTEST_F(TextPickerPatternTestNg, LinearFontSize001, TestSize.Level1) Dimension dimension = Dimension(FONT_SIZE_10); Dimension dimension1; dimension1 = textPickerColumnPattern_->LinearFontSize(dimension, dimension, 1); - EXPECT_TRUE(dimension < dimension1); + EXPECT_FALSE(dimension < dimension1); } /** @@ -1767,7 +1767,7 @@ HWTEST_F(TextPickerPatternTestNg, LinearFontSize002, TestSize.Level1) Dimension dimension = Dimension(FONT_SIZE_10); Dimension dimension1; dimension1 = textPickerColumnPattern_->LinearFontSize(dimension, dimension, 2); - EXPECT_TRUE(dimension < dimension1); + EXPECT_FALSE(dimension < dimension1); } /** diff --git a/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp b/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp index d9fa507eb96..4527cf1dd48 100644 --- a/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp +++ b/test/unittest/core/pattern/text_picker/text_picker_test_update.cpp @@ -1794,7 +1794,7 @@ HWTEST_F(TextPickerTestUpdate, SetDialogButtonActive001, TestSize.Level1) auto contentColumn = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr(true)); TextPickerDialogView::SetDialogButtonActive(contentColumn, 0, 0); - EXPECT_NE(contentColumn->GetLastChild(), nullptr); + EXPECT_EQ(contentColumn->GetLastChild(), nullptr); } /** @@ -1866,7 +1866,7 @@ HWTEST_F(TextPickerTestUpdate, SetValue001, TestSize.Level1) auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(frameNode, nullptr); TextPickerModelNG::SetValue(frameNode, value); - ASSERT_NE(frameNode->GetPattern()->GetSelected(), 0); + EXPECT_EQ(frameNode->GetPattern()->GetSelected(), 0); } /** @@ -1888,6 +1888,6 @@ HWTEST_F(TextPickerTestUpdate, SetValues001, TestSize.Level1) auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(frameNode, nullptr); TextPickerModelNG::SetValues(frameNode, value); - ASSERT_NE(frameNode->GetPattern()->GetSelected(), 0); + EXPECT_EQ(frameNode->GetPattern()->GetSelected(), 0); } } // namespace OHOS::Ace::NG \ No newline at end of file From c3d1a576e62acd1aa32d3d1e439725ef98330def Mon Sep 17 00:00:00 2001 From: lancer Date: Sat, 20 Jul 2024 15:31:48 +0800 Subject: [PATCH 081/221] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86=E7=9A=84?= =?UTF-8?q?=E6=8B=96=E6=8B=BD=E6=B5=AE=E6=9D=BF=E9=80=82=E9=85=8D=E6=B7=B1?= =?UTF-8?q?=E8=89=B2=E6=A8=A1=E5=BC=8F=20Signed-off-by:=20haoshuo=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/core/components/text/text_theme.h | 13 ++++++++++++- .../text_drag/text_drag_overlay_modifier.cpp | 2 +- .../pattern/text_drag/text_drag_pattern.cpp | 10 ++++++++++ .../pattern/text_drag/text_drag_pattern.h | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components/text/text_theme.h b/frameworks/core/components/text/text_theme.h index b69688f4939..5cf2b9bacd6 100644 --- a/frameworks/core/components/text/text_theme.h +++ b/frameworks/core/components/text/text_theme.h @@ -22,7 +22,7 @@ #include "core/components/theme/theme_constants_defines.h" namespace OHOS::Ace { - +constexpr float DRAG_BACKGROUND_OPACITY = 0.95f; /** * TextTheme defines color and styles of ThemeComponent. TextTheme should be built * using TextTheme::Builder. @@ -63,6 +63,11 @@ public: theme->selectedColor_ = pattern->GetAttr(PATTERN_BG_COLOR_SELECTED, Color(0x33007dff)); auto draggable = pattern->GetAttr("draggable", "0"); theme->draggable_ = StringUtils::StringToInt(draggable); + auto dragBackgroundColor = pattern->GetAttr("drag_background_color", Color::WHITE); + if (SystemProperties::GetColorMode() == ColorMode::DARK) { + dragBackgroundColor = dragBackgroundColor.ChangeOpacity(DRAG_BACKGROUND_OPACITY); + } + theme->dragBackgroundColor_ = dragBackgroundColor; constexpr double childMinSize = 20.0; theme->linearSplitChildMinSize_ = pattern->GetAttr(LINEAR_SPLIT_CHILD_MIN_SIZE, childMinSize); theme->isTextFadeout_ = pattern->GetAttr("text_fadeout_enable", "") == "true"; @@ -109,12 +114,18 @@ public: return isShowHandle_; } + const Color& GetDragBackgroundColor() const + { + return dragBackgroundColor_; + } + protected: TextTheme() = default; private: TextStyle textStyle_; Color selectedColor_; + Color dragBackgroundColor_ = Color::WHITE; bool draggable_ = false; double linearSplitChildMinSize_ = 20.0; bool isTextFadeout_ = false; diff --git a/frameworks/core/components_ng/pattern/text_drag/text_drag_overlay_modifier.cpp b/frameworks/core/components_ng/pattern/text_drag/text_drag_overlay_modifier.cpp index 3fc55cc5662..7d2ad647b00 100644 --- a/frameworks/core/components_ng/pattern/text_drag/text_drag_overlay_modifier.cpp +++ b/frameworks/core/components_ng/pattern/text_drag/text_drag_overlay_modifier.cpp @@ -38,7 +38,7 @@ void TextDragOverlayModifier::onDraw(DrawingContext& context) auto pattern = DynamicCast(pattern_.Upgrade()); CHECK_NULL_VOID(pattern); auto& canvas = context.canvas; - Color color(TEXT_DRAG_COLOR_BG); + Color color = pattern->GetDragBackgroundColor(); RSBrush brush; brush.SetColor(ToRSColor(color)); brush.SetAntiAlias(true); diff --git a/frameworks/core/components_ng/pattern/text_drag/text_drag_pattern.cpp b/frameworks/core/components_ng/pattern/text_drag/text_drag_pattern.cpp index ef0f3d4f16a..fc32e31f399 100644 --- a/frameworks/core/components_ng/pattern/text_drag/text_drag_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_drag/text_drag_pattern.cpp @@ -18,6 +18,7 @@ #include #include "base/utils/utils.h" +#include "core/components/text/text_theme.h" #include "core/components_ng/pattern/text/text_pattern.h" #include "core/components_ng/pattern/text_drag/text_drag_base.h" #include "core/components_ng/render/drawing.h" @@ -316,4 +317,13 @@ void TextDragPattern::CalculateLine(std::vector& points, std::shared_ path->LineTo(crossPoint.x, crossPoint.y); } } + +Color TextDragPattern::GetDragBackgroundColor() +{ + auto pipeline = PipelineContext::GetCurrentContext(); + CHECK_NULL_RETURN(pipeline, Color(TEXT_DRAG_COLOR_BG)); + auto textTheme = pipeline->GetTheme(); + CHECK_NULL_RETURN(textTheme, Color(TEXT_DRAG_COLOR_BG)); + return textTheme->GetDragBackgroundColor(); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text_drag/text_drag_pattern.h b/frameworks/core/components_ng/pattern/text_drag/text_drag_pattern.h index 507069149b4..7e0a8d398e1 100644 --- a/frameworks/core/components_ng/pattern/text_drag/text_drag_pattern.h +++ b/frameworks/core/components_ng/pattern/text_drag/text_drag_pattern.h @@ -211,6 +211,7 @@ public: return TEXT_DRAG_RADIUS; } + Color GetDragBackgroundColor(); protected: static TextDragData CalculateTextDragData(RefPtr& pattern, RefPtr& dragNode); static RectF GetHandler(const bool isLeftHandler, const std::vector boxes, const RectF contentRect, From 225230655fd0db4a13a5be76b8dd334a6a11d8e2 Mon Sep 17 00:00:00 2001 From: Zhang-Dong-hui Date: Sat, 20 Jul 2024 07:46:31 +0000 Subject: [PATCH 082/221] update refreshingContent Node's layoutConstraint Signed-off-by: Zhang-Dong-hui Change-Id: I2463abdd1b0b1583151b852e634cfc776e73b555 --- .../bridge/declarative_frontend/jsview/js_refresh.cpp | 4 +++- .../pattern/refresh/refresh_layout_algorithm.cpp | 11 +++++++++-- .../pattern/refresh/refresh_layout_property.h | 3 +++ .../components_ng/pattern/refresh/refresh_model.h | 1 + .../pattern/refresh/refresh_model_ng.cpp | 5 +++++ .../components_ng/pattern/refresh/refresh_model_ng.h | 1 + 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_refresh.cpp b/frameworks/bridge/declarative_frontend/jsview/js_refresh.cpp index 38f1e9d36e8..50ea079b4b0 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_refresh.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_refresh.cpp @@ -178,7 +178,8 @@ void JSRefresh::Create(const JSCallbackInfo& info) } ParsFrictionData(friction); if (!ParseRefreshingContent(paramObject)) { - ParseCustomBuilder(info); + bool isCustomBuilderExist = ParseCustomBuilder(info); + RefreshModel::GetInstance()->SetIsCustomBuilderExist(isCustomBuilderExist); } std::string loadingStr = ""; @@ -209,6 +210,7 @@ bool JSRefresh::ParseRefreshingContent(const JSRef& paramObject) CHECK_NULL_RETURN(frameNode, false); RefPtr refPtrFrameNode = AceType::Claim(frameNode); RefreshModel::GetInstance()->SetCustomBuilder(refPtrFrameNode); + RefreshModel::GetInstance()->SetIsCustomBuilderExist(false); return true; } diff --git a/frameworks/core/components_ng/pattern/refresh/refresh_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/refresh/refresh_layout_algorithm.cpp index ed8fac7f1f8..268d8e98534 100644 --- a/frameworks/core/components_ng/pattern/refresh/refresh_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/refresh/refresh_layout_algorithm.cpp @@ -46,8 +46,15 @@ void RefreshLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) } if (HasCustomBuilderIndex() && index == customBuilderIndex_.value_or(0)) { auto builderLayoutConstraint = layoutConstraint; - builderLayoutConstraint.UpdateIllegalSelfIdealSizeWithCheck( - CalculateBuilderSize(child, builderLayoutConstraint, builderBaseHeight_)); + bool isCustomBuilderExist = layoutProperty->GetIsCustomBuilderExistValue(false); + if (isCustomBuilderExist) { + builderLayoutConstraint.UpdateIllegalSelfIdealSizeWithCheck( + CalculateBuilderSize(child, builderLayoutConstraint, builderBaseHeight_)); + } else { + builderLayoutConstraint.minSize.SetHeight(builderBaseHeight_); + builderLayoutConstraint.maxSize.SetHeight(builderBaseHeight_); + builderLayoutConstraint.percentReference.SetHeight(builderBaseHeight_); + } child->Measure(builderLayoutConstraint); ++index; continue; diff --git a/frameworks/core/components_ng/pattern/refresh/refresh_layout_property.h b/frameworks/core/components_ng/pattern/refresh/refresh_layout_property.h index b450eee45b7..3d617b23061 100644 --- a/frameworks/core/components_ng/pattern/refresh/refresh_layout_property.h +++ b/frameworks/core/components_ng/pattern/refresh/refresh_layout_property.h @@ -55,6 +55,7 @@ public: value->propPullToRefresh_ = ClonePullToRefresh(); value->propRefreshOffset_ = CloneRefreshOffset(); value->propPullDownRatio_ = ClonePullDownRatio(); + value->propIsCustomBuilderExist_ = CloneIsCustomBuilderExist(); return value; } @@ -69,6 +70,7 @@ public: ResetPullToRefresh(); ResetRefreshOffset(); ResetPullDownRatio(); + ResetIsCustomBuilderExist(); } void ToJsonValue(std::unique_ptr& json, const InspectorFilter& filter) const override @@ -100,6 +102,7 @@ public: ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PullToRefresh, bool, PROPERTY_UPDATE_LAYOUT); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RefreshOffset, Dimension, PROPERTY_UPDATE_LAYOUT); ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PullDownRatio, float, PROPERTY_UPDATE_LAYOUT); + ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IsCustomBuilderExist, bool, PROPERTY_UPDATE_LAYOUT); private: ACE_DISALLOW_COPY_AND_MOVE(RefreshLayoutProperty); diff --git a/frameworks/core/components_ng/pattern/refresh/refresh_model.h b/frameworks/core/components_ng/pattern/refresh/refresh_model.h index 146d7ce587b..ec8e0248320 100644 --- a/frameworks/core/components_ng/pattern/refresh/refresh_model.h +++ b/frameworks/core/components_ng/pattern/refresh/refresh_model.h @@ -60,6 +60,7 @@ public: virtual void SetLoadingText(const std::string& loadingText) = 0; virtual void SetRefreshOffset(const Dimension& offset) = 0; virtual void SetPullToRefresh(bool isPullToRefresh) = 0; + virtual void SetIsCustomBuilderExist(bool isCustomBuilderExist) {} private: static std::unique_ptr instance_; diff --git a/frameworks/core/components_ng/pattern/refresh/refresh_model_ng.cpp b/frameworks/core/components_ng/pattern/refresh/refresh_model_ng.cpp index 833d5e6c532..9fbea4b12e7 100644 --- a/frameworks/core/components_ng/pattern/refresh/refresh_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/refresh/refresh_model_ng.cpp @@ -185,6 +185,11 @@ void RefreshModelNG::SetCustomBuilder(const RefPtr& customBuilder) pattern->AddCustomBuilderNode(customBuilder); } +void RefreshModelNG::SetIsCustomBuilderExist(bool isCustomBuilderExist) +{ + ACE_UPDATE_LAYOUT_PROPERTY(RefreshLayoutProperty, IsCustomBuilderExist, isCustomBuilderExist); +} + void RefreshModelNG::SetCustomBuilder(FrameNode* frameNode, FrameNode* customBuilder) { CHECK_NULL_VOID(frameNode); diff --git a/frameworks/core/components_ng/pattern/refresh/refresh_model_ng.h b/frameworks/core/components_ng/pattern/refresh/refresh_model_ng.h index e5072b71626..be1b59f9938 100644 --- a/frameworks/core/components_ng/pattern/refresh/refresh_model_ng.h +++ b/frameworks/core/components_ng/pattern/refresh/refresh_model_ng.h @@ -43,6 +43,7 @@ public: void SetLoadingText(const std::string& loadingText) override; void SetRefreshOffset(const Dimension& offset) override; void SetPullToRefresh(bool isPullToRefresh) override; + void SetIsCustomBuilderExist(bool isCustomBuilderExist) override; // @deprecated void Pop() override {} void SetRefreshDistance(const Dimension& refreshDistance) override {} From 5ec5e3f76f46fab03a0f59fec2a8ae8a99fbc4ea Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Sat, 20 Jul 2024 14:17:15 +0800 Subject: [PATCH 083/221] =?UTF-8?q?=E6=96=B0=E5=A2=9Eform=5Fpattern.cpp?= =?UTF-8?q?=E7=9A=84tdd=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei --- test/unittest/core/pattern/BUILD.gn | 1 + test/unittest/core/pattern/form/BUILD.gn | 38 ++ .../core/pattern/form/form_pattern_test.cpp | 425 ++++++++++++++++++ 3 files changed, 464 insertions(+) create mode 100644 test/unittest/core/pattern/form/form_pattern_test.cpp diff --git a/test/unittest/core/pattern/BUILD.gn b/test/unittest/core/pattern/BUILD.gn index 100e4d8365b..9f056cef990 100644 --- a/test/unittest/core/pattern/BUILD.gn +++ b/test/unittest/core/pattern/BUILD.gn @@ -36,6 +36,7 @@ group("core_pattern_unittest") { "flex:flex_test_ng", "folder_stack:folder_stack_test_ng", "form:form_node_test", + "form:form_pattern_test", "form:form_test_ng", "form_link:form_link_test", "gauge:gauge_test_ng", diff --git a/test/unittest/core/pattern/form/BUILD.gn b/test/unittest/core/pattern/form/BUILD.gn index 8a13bbf046f..c00c60dd856 100644 --- a/test/unittest/core/pattern/form/BUILD.gn +++ b/test/unittest/core/pattern/form/BUILD.gn @@ -87,3 +87,41 @@ ace_unittest("form_node_test") { ] } } + +ace_unittest("form_pattern_test") { + flutter_skia = true + render = true + type = "new" + + sources = [ + "$ace_root/frameworks/core/accessibility/accessibility_session_adapter.cpp", + "$ace_root/frameworks/core/common/form_manager.cpp", + "$ace_root/frameworks/core/components_ng/pattern/form/accessibility_session_adapter_form.cpp", + "$ace_root/frameworks/core/components_ng/pattern/form/form_model_ng.cpp", + "$ace_root/frameworks/core/components_ng/pattern/form/form_node.cpp", + "$ace_root/frameworks/core/components_ng/pattern/form/form_pattern.cpp", + "$ace_root/frameworks/core/components_ng/pattern/shape/shape_overlay_modifier.cpp", + "$ace_root/frameworks/core/components_ng/pattern/shape/shape_paint_property.cpp", + "$ace_root/test/unittest/core/pattern/form/mock/mock_form_manager_delegate.cpp", + "$ace_root/test/unittest/core/pattern/form/mock/mock_rosen_render_context.cpp", + "$ace_root/test/unittest/core/pattern/form/mock/mock_rs_surface_mode.cpp", + "$ace_root/test/unittest/core/pattern/form/mock/mock_sub_container.cpp", + "$ace_root/test/unittest/core/pattern/form/mock/mock_system_properties.cpp", + "form_pattern_test.cpp", + ] + + if (is_ohos_standard_system) { + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "form_fwk:fmskit_native", + "form_fwk:form_manager", + "graphic_2d:librender_service_client", + "i18n:intl_util", + "input:libmmi-client", + ] + } +} diff --git a/test/unittest/core/pattern/form/form_pattern_test.cpp b/test/unittest/core/pattern/form/form_pattern_test.cpp new file mode 100644 index 00000000000..0280174abf4 --- /dev/null +++ b/test/unittest/core/pattern/form/form_pattern_test.cpp @@ -0,0 +1,425 @@ +/* + * Copyright (c) 2024 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 +#include +#include + +#include "gtest/gtest.h" + +#define protected public +#define private public + +#include "mock/mock_form_utils.h" +#include "mock/mock_sub_container.h" +#include "test/mock/core/common/mock_container.h" +#include "test/mock/core/pipeline/mock_pipeline_context.h" +#include "test/mock/core/render/mock_render_context.h" + +#include "core/components_ng/base/view_stack_processor.h" +#include "core/components_ng/pattern/form/form_node.h" +#include "core/components_ng/pattern/form/form_pattern.h" +#include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" +#include "core/components_ng/pattern/text/text_pattern.h" + +using namespace testing; +using namespace testing::ext; +namespace OHOS::Ace::NG { +namespace { +constexpr int32_t MAX_CLICK_DURATION = 500000000; // ns +constexpr int32_t FORM_SHAPE_CIRCLE = 2; +} +class FormPatternTest : public testing::Test { +public: + static void SetUpTestSuite(); + static void TearDownTestSuite(); +protected: + static RefPtr CreateFromNode(); +}; + +void FormPatternTest::SetUpTestSuite() +{ + MockPipelineContext::SetUp(); + MockContainer::SetUp(); +} + +void FormPatternTest::TearDownTestSuite() +{ + MockPipelineContext::TearDown(); + MockContainer::TearDown(); +} + +RefPtr FormPatternTest::CreateFromNode() +{ + auto* stack = ViewStackProcessor::GetInstance(); + auto formNode = FormNode::GetOrCreateFormNode( + "FormComponent", stack->ClaimNodeId(), []() { return AceType::MakeRefPtr(); }); + auto pattern = formNode->GetPattern(); + pattern->frameNode_ = formNode; + return formNode; +} + +/** + * @tc.name: FormPatternTest_001 + * @tc.desc: OnAttachToFrameNode + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_001, TestSize.Level1) +{ + RefPtr frameNode = CreateFromNode(); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + EXPECT_EQ(pattern->scopeId_, 0); + auto host = pattern->GetHost(); + ASSERT_NE(host, nullptr); + pattern->frameNode_ = nullptr; + pattern->OnAttachToFrameNode(); + EXPECT_EQ(pattern->scopeId_, 0); + pattern->frameNode_ = host; + + auto eventHub = host->GetEventHub(); + host->eventHub_ = nullptr; + pattern->OnAttachToFrameNode(); + EXPECT_EQ(pattern->scopeId_, 0); + host->eventHub_ = eventHub; + + host = pattern->GetHost(); + pattern->frameNode_ = nullptr; + pattern->OnAttachToFrameNode(); + EXPECT_EQ(pattern->scopeId_, 0); + pattern->frameNode_ = host; + + + RefPtr subContainer = pattern->subContainer_; + pattern->subContainer_ = nullptr; + pattern->OnAttachToFrameNode(); + EXPECT_EQ(pattern->scopeId_, 0); + pattern->subContainer_ = subContainer; +} + +/** + * @tc.name: FormPatternTest_002 + * @tc.desc: InitClickEvent + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_002, TestSize.Level1) +{ + RefPtr pattern; + RefPtr host = pattern->GetHost(); + pattern->frameNode_ = nullptr; + pattern->InitClickEvent(); + EXPECT_EQ(pattern->scopeId_, 0); + pattern->frameNode_ = host; + + size_t eventNum = host->GetOrCreateGestureEventHub()->touchEventActuator_->touchEvents_.size(); + pattern->InitClickEvent(); + auto gestureEventHub = host->GetOrCreateGestureEventHub(); + size_t curEventNum = gestureEventHub->touchEventActuator_->touchEvents_.size(); + EXPECT_EQ(curEventNum, eventNum + 1); +} + +/** + * @tc.name: FormPatternTest_003 + * @tc.desc: HandleTouchDownEvent + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_003, TestSize.Level1) +{ + RefPtr frameNode = CreateFromNode(); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + auto host = pattern->GetHost(); + ASSERT_NE(host, nullptr); + pattern->OnAttachToFrameNode(); + pattern->InitClickEvent(); + + TouchEventInfo event("onTouchDown"); + std::list touchesBak = event.GetTouches(); + ASSERT_EQ(touchesBak.empty(), true); + std::list touches; + event.touches_ = std::move(touches); + pattern->HandleTouchDownEvent(event); + EXPECT_EQ(pattern->lastTouchLocation_, Offset()); + + TouchLocationInfo touchLocationInfo(1); + touchLocationInfo.SetTouchType(TouchType::DOWN); + event.AddTouchLocationInfo(std::move(touchLocationInfo)); + pattern->HandleUnTrustForm(); + pattern->UpdateBackgroundColorWhenUnTrustForm(); + pattern->HandleTouchDownEvent(event); + ASSERT_EQ(event.GetTouches().empty(), false); +} + +/** + * @tc.name: FormPatternTest_004 + * @tc.desc: HandleTouchUpEvent + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_004, TestSize.Level1) +{ + RefPtr frameNode = CreateFromNode(); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + ASSERT_FALSE(pattern->shouldResponseClick_); + auto host = pattern->GetHost(); + ASSERT_NE(host, nullptr); + pattern->OnAttachToFrameNode(); + pattern->InitClickEvent(); + + pattern->shouldResponseClick_ = true; + TouchEventInfo event("onTouchUp"); + TimeStamp timeStamp = event.timeStamp_; + std::chrono::duration> millisecondDuration(MAX_CLICK_DURATION/1000000 + 10); + event.timeStamp_ = pattern->touchDownTime_ + millisecondDuration; + TouchLocationInfo touchLocationInfo(1); + touchLocationInfo.SetTouchType(TouchType::UP); + event.AddTouchLocationInfo(std::move(touchLocationInfo)); + pattern->HandleTouchUpEvent(event); + ASSERT_EQ(pattern->shouldResponseClick_, false); + event.timeStamp_ = timeStamp; + pattern->shouldResponseClick_ = true; + + std::list newTouches; + std::list touches = event.GetTouches(); + EXPECT_EQ(touches.empty(), false); + event.touches_ = std::move(newTouches); + pattern->HandleTouchUpEvent(event); + ASSERT_EQ(pattern->shouldResponseClick_, true); + event.touches_ = touches; + pattern->shouldResponseClick_ = true; + + event.touches_.begin()->screenLocation_ += Offset(30, 30); + pattern->HandleTouchUpEvent(event); + ASSERT_EQ(pattern->shouldResponseClick_, false); + pattern->shouldResponseClick_ = true; + + event.touches_.begin()->screenLocation_ -= Offset(30, 30); + pattern->HandleTouchUpEvent(event); + ASSERT_EQ(pattern->shouldResponseClick_, true); + pattern->shouldResponseClick_ = false; +} + +/** + * @tc.name: FormPatternTest_005 + * @tc.desc: HandleUnTrustForm + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_005, TestSize.Level1) +{ + RefPtr frameNode = CreateFromNode(); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + TouchEventInfo event("onTouchDown"); + TouchLocationInfo touchLocationInfo(1); + touchLocationInfo.SetTouchType(TouchType::DOWN); + event.AddTouchLocationInfo(std::move(touchLocationInfo)); + pattern->HandleUnTrustForm(); + pattern->UpdateBackgroundColorWhenUnTrustForm(); + pattern->HandleTouchDownEvent(event); + ASSERT_EQ(event.GetTouches().empty(), false); +} + +/** + * @tc.name: FormPatternTest_006 + * @tc.desc: UpdateBackgroundColorWhenUnTrustForm + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_006, TestSize.Level1) +{ + RefPtr pattern; + pattern->isUnTrust_ = false; + pattern->UpdateBackgroundColorWhenUnTrustForm(); + EXPECT_FALSE(pattern->isLoaded_); + + ASSERT_EQ(pattern->colorMode, ColorMode::LIGHT); + pattern->isUnTrust_ = true; + pattern->UpdateBackgroundColorWhenUnTrustForm(); + EXPECT_FALSE(pattern->isLoaded_); + + pattern->colorMode = ColorMode::COLOR_MODE_UNDEFINED; + pattern->UpdateBackgroundColorWhenUnTrustForm(); + EXPECT_TRUE(pattern->isLoaded_); +} + +/** + * @tc.name: FormPatternTest_007 + * @tc.desc: HandleSnapshot + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_007, TestSize.Level1) +{ + RefPtr frameNode = CreateFromNode(); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + auto host = pattern->GetHost(); + ASSERT_NE(host, nullptr); + + int32_t delayTime = 0; + pattern->HandleSnapshot(delayTime); + ASSERT_EQ(delayTime, 0); +} + +/** + * @tc.name: FormPatternTest_008 + * @tc.desc: HandleStaticFormEvent + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_008, TestSize.Level1) +{ + RefPtr formNode = CreateFromNode(); + auto pattern = formNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + PointF touchPoint; + touchPoint.SetX(-5.0f); + touchPoint.SetY(5.0f); + std::vector infos; + pattern->SetFormLinkInfos(infos); + pattern->HandleStaticFormEvent(touchPoint); + ASSERT_EQ(pattern->formLinkInfos_.empty(), true); + ASSERT_TRUE(pattern->isDynamic_); + ASSERT_FALSE(pattern->shouldResponseClick_); + + pattern->isDynamic_ = false; + pattern->SetFormLinkInfos(infos); + ASSERT_TRUE(pattern->formLinkInfos_.empty()); + + pattern->shouldResponseClick_ = false; + pattern->HandleStaticFormEvent(touchPoint); + ASSERT_EQ(pattern->formLinkInfos_.empty(), true); + + std::string tmpStr = "action"; + infos.emplace_back(tmpStr); + pattern->SetFormLinkInfos(infos); + pattern->shouldResponseClick_ = true; + pattern->HandleStaticFormEvent(touchPoint); + ASSERT_EQ(pattern->formLinkInfos_.empty(), false); +} + +/** + * @tc.name: FormPatternTest_009 + * @tc.desc: HandleEnableForm + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_009, TestSize.Level1) +{ + RefPtr formNode = CreateFromNode(); + auto pattern = formNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + + auto* stack = ViewStackProcessor::GetInstance(); + auto formNode1 = FormNode::GetOrCreateFormNode( + "FormComponent", stack->ClaimNodeId(), []() { return AceType::MakeRefPtr(); }); + + std::vector infos; + std::string tmpStr = "action"; + infos.emplace_back(tmpStr); + RequestFormInfo info; + info.shape = FORM_SHAPE_CIRCLE; + ASSERT_NE(pattern->formManagerBridge_, nullptr); + pattern->SetFormLinkInfos(infos); + pattern->HandleEnableForm(true); + + RefPtr textNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(textNode, nullptr); + RefPtr columnNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr(true)); + ASSERT_NE(columnNode, nullptr); + pattern->AddFormChildNode(FormChildNodeType::FORM_FORBIDDEN_ROOT_NODE, columnNode); + pattern->AddFormChildNode(FormChildNodeType::FORM_FORBIDDEN_TEXT_NODE, textNode); + EXPECT_EQ(pattern->formChildrenNodeMap_.size(), 2); + pattern->HandleEnableForm(true); + EXPECT_EQ(pattern->formChildrenNodeMap_.size(), 0); + + RefPtr textNode2 = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(textNode2, nullptr); + RefPtr columnNode2 = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, + ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr(true)); + ASSERT_NE(columnNode2, nullptr); + pattern->AddFormChildNode(FormChildNodeType::FORM_FORBIDDEN_ROOT_NODE, columnNode2); + pattern->AddFormChildNode(FormChildNodeType::FORM_FORBIDDEN_TEXT_NODE, textNode2); + pattern->HandleEnableForm(false); + EXPECT_EQ(pattern->formChildrenNodeMap_.size(), 2); +} + +/** + * @tc.name: FormPatternTest_010 + * @tc.desc: TakeSurfaceCaptureForUI + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_010, TestSize.Level1) +{ + RefPtr formNode = CreateFromNode(); + auto pattern = formNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + auto host = pattern->GetHost(); + ASSERT_NE(host, nullptr); + + std::vector infos; + std::string tmpStr = "action"; + infos.emplace_back(tmpStr); + pattern->SetFormLinkInfos(infos); + pattern->HandleEnableForm(true); + + pattern->isFrsNodeDetached_ = true; + pattern->isDynamic_ = true; + pattern->TakeSurfaceCaptureForUI(); + ASSERT_EQ(pattern->formLinkInfos_.empty(), false); + + pattern->isFrsNodeDetached_ = false; + pattern->isDynamic_ = true; + pattern->TakeSurfaceCaptureForUI(); + ASSERT_EQ(pattern->formLinkInfos_.empty(), true); +} + +/** + * @tc.name: FormPatternTest_011 + * @tc.desc: SnapshotSurfaceNode + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_011, TestSize.Level1) +{ + RefPtr frameNode = CreateFromNode(); + auto pattern = frameNode->GetPattern(); + ASSERT_NE(pattern, nullptr); + auto host = pattern->GetHost(); + pattern->SnapshotSurfaceNode(); + ASSERT_NE(host, nullptr); +} + +/** + * @tc.name: FormPatternTest_012 + * @tc.desc: OnSnapshot + * @tc.type: FUNC + */ +HWTEST_F(FormPatternTest, FormPatternTest_012, TestSize.Level1) +{ + RefPtr formNode = CreateFromNode(); + auto pattern = formNode->GetPattern(); + pattern->frameNode_ = formNode; + ASSERT_NE(pattern, nullptr); + + std::vector infos; + std::string tmpStr = "action"; + infos.emplace_back(tmpStr); + pattern->SetFormLinkInfos(infos); + std::shared_ptr pixelMap = nullptr; + pattern->OnSnapshot(pixelMap); + pattern->HandleOnSnapshot(pixelMap); + ASSERT_EQ(pattern->isSnapshot_, false); +} +} // namespace OHOS::Ace::NG \ No newline at end of file From 24b48d054e059724f93f4dbac7c712722fce3c3d Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 15:49:07 +0800 Subject: [PATCH 084/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=97=A8=E7=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../core/common/recorder/event_recorder_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index acc4fda896e..4aea6ca9ac8 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -598,7 +598,7 @@ HWTEST_F(EventRecorderTest, SetContainerInfo001, TestSize.Level1) { std::string windowName = "$HA_FLOAT_WINDOW$"; Recorder::EventRecorder::Get().SetContainerInfo(windowName, 0, true); - EXPECT_EQ(Recorder::EventRecorder::Get().containerId_, -1); + EXPECT_EQ(Recorder::EventRecorder::Get().GetContainerId(), -1); } /** @@ -610,7 +610,7 @@ HWTEST_F(EventRecorderTest, SetContainerInfo002, TestSize.Level1) { std::string windowName = ""; Recorder::EventRecorder::Get().SetContainerInfo(windowName, 0, true); - EXPECT_EQ(Recorder::EventRecorder::Get().containerId_, 0); + EXPECT_EQ(Recorder::EventRecorder::Get().GetContainerId(), 0); } /** @@ -622,7 +622,7 @@ HWTEST_F(EventRecorderTest, SetContainerInfo003, TestSize.Level1) { std::string windowName = ""; Recorder::EventRecorder::Get().SetContainerInfo(windowName, 0, false); - EXPECT_EQ(Recorder::EventRecorder::Get().containerId_, -1); + EXPECT_EQ(Recorder::EventRecorder::Get().GetContainerId(), -1); } /** @@ -634,7 +634,7 @@ HWTEST_F(EventRecorderTest, SetFocusContainerInfo001, TestSize.Level1) { std::string windowName = "$HA_FLOAT_WINDOW$"; Recorder::EventRecorder::Get().SetFocusContainerInfo(windowName, 0); - EXPECT_EQ(Recorder::EventRecorder::Get().focusContainerId_, -1); + EXPECT_EQ(Recorder::EventRecorder::Get().GetContainerId(), -1); } /** @@ -646,7 +646,7 @@ HWTEST_F(EventRecorderTest, SetFocusContainerInfo002, TestSize.Level1) { std::string windowName = ""; Recorder::EventRecorder::Get().SetFocusContainerInfo(windowName, 0); - EXPECT_EQ(Recorder::EventRecorder::Get().focusContainerId_, 0); + EXPECT_EQ(Recorder::EventRecorder::Get().GetContainerId(), 0); } /** From c9c53d849c42d9769efd150530ec61ae7088ddf4 Mon Sep 17 00:00:00 2001 From: Tianer Zhou Date: Sat, 20 Jul 2024 15:14:50 +0800 Subject: [PATCH 085/221] refactor Signed-off-by: Tianer Zhou Change-Id: I1a9e9195a8edbd31b39956f32ae0ac901be38658 --- .../core/components_ng/pattern/BUILD.gn | 1 + .../pattern/swiper/swiper_helper.cpp | 148 ++++ .../pattern/swiper/swiper_helper.h | 32 + .../pattern/swiper/swiper_pattern.cpp | 708 +++++++----------- .../pattern/swiper/swiper_pattern.h | 58 +- test/unittest/BUILD.gn | 1 + .../swiper/swiper_animation_test_ng.cpp | 2 +- 7 files changed, 497 insertions(+), 453 deletions(-) create mode 100644 frameworks/core/components_ng/pattern/swiper/swiper_helper.cpp create mode 100644 frameworks/core/components_ng/pattern/swiper/swiper_helper.h diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index c14bd822f5d..452776bab19 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -439,6 +439,7 @@ build_component_ng("pattern_ng") { "stepper/stepper_pattern.cpp", "swiper/arc_swiper_pattern.cpp", "swiper/swiper_accessibility_property.cpp", + "swiper/swiper_helper.cpp", "swiper/swiper_layout_algorithm.cpp", "swiper/swiper_model_ng.cpp", "swiper/swiper_paint_method.cpp", diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_helper.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_helper.cpp new file mode 100644 index 00000000000..fd33701a6ce --- /dev/null +++ b/frameworks/core/components_ng/pattern/swiper/swiper_helper.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2024 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 "swiper_helper.h" + +#include "core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h" + +namespace OHOS::Ace::NG { +void SwiperHelper::InitSwiperController(const RefPtr& controller, const WeakPtr& weak) +{ + controller->SetSwipeToImpl([weak](int32_t index, bool reverse) { + auto swiper = weak.Upgrade(); + CHECK_NULL_VOID(swiper); + swiper->SwipeTo(index); + }); + + controller->SetSwipeToWithoutAnimationImpl([weak](int32_t index) { + auto swiper = weak.Upgrade(); + CHECK_NULL_VOID(swiper); + swiper->SwipeToWithoutAnimation(index); + }); + + controller->SetShowNextImpl([weak]() { + auto swiper = weak.Upgrade(); + CHECK_NULL_VOID(swiper); + auto swiperNode = swiper->GetHost(); + CHECK_NULL_VOID(swiperNode); + TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ShowNext, id:%{public}d", swiperNode->GetId()); + swiper->ShowNext(); + }); + + controller->SetShowPrevImpl([weak]() { + auto swiper = weak.Upgrade(); + CHECK_NULL_VOID(swiper); + auto swiperNode = swiper->GetHost(); + CHECK_NULL_VOID(swiperNode); + TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ShowPrevious, id:%{public}d", swiperNode->GetId()); + swiper->ShowPrevious(); + }); + + controller->SetChangeIndexImpl([weak](int32_t index, bool useAnimation) { + auto swiper = weak.Upgrade(); + CHECK_NULL_VOID(swiper); + TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ChangeIndex %{public}d, useAnimation:%{public}d", index, useAnimation); + swiper->ChangeIndex(index, useAnimation); + }); + + controller->SetFinishImpl([weak]() { + auto swiper = weak.Upgrade(); + CHECK_NULL_VOID(swiper); + swiper->FinishAnimation(); + }); + + controller->SetPreloadItemsImpl([weak](const std::set& indexSet) { + auto swiper = weak.Upgrade(); + CHECK_NULL_VOID(swiper); + swiper->PreloadItems(indexSet); + }); +} + +void SwiperHelper::SaveDigitIndicatorProperty(const RefPtr& indicatorNode, SwiperPattern& swiper) +{ + CHECK_NULL_VOID(indicatorNode); + auto indicatorProps = indicatorNode->GetLayoutProperty(); + CHECK_NULL_VOID(indicatorProps); + auto pipeline = PipelineBase::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + const auto theme = pipeline->GetTheme(); + const auto digitalParams = swiper.GetSwiperDigitalParameters(); + CHECK_NULL_VOID(digitalParams); + indicatorProps->ResetIndicatorLayoutStyle(); + if (digitalParams->dimLeft.has_value()) { + indicatorProps->UpdateLeft(digitalParams->dimLeft.value()); + } + if (digitalParams->dimTop.has_value()) { + indicatorProps->UpdateTop(digitalParams->dimTop.value()); + } + if (digitalParams->dimRight.has_value()) { + indicatorProps->UpdateRight(digitalParams->dimRight.value()); + } + if (digitalParams->dimBottom.has_value()) { + indicatorProps->UpdateBottom(digitalParams->dimBottom.value()); + } + indicatorProps->UpdateFontColor(digitalParams->fontColor.value_or( + theme->GetDigitalIndicatorTextStyle().GetTextColor())); + indicatorProps->UpdateSelectedFontColor(digitalParams->selectedFontColor.value_or( + theme->GetDigitalIndicatorTextStyle().GetTextColor())); + indicatorProps->UpdateFontSize( + digitalParams->fontSize.value_or(theme->GetDigitalIndicatorTextStyle().GetFontSize())); + indicatorProps->UpdateSelectedFontSize(digitalParams->selectedFontSize.value_or( + theme->GetDigitalIndicatorTextStyle().GetFontSize())); + indicatorProps->UpdateFontWeight(digitalParams->fontWeight.value_or( + theme->GetDigitalIndicatorTextStyle().GetFontWeight())); + indicatorProps->UpdateSelectedFontWeight(digitalParams->selectedFontWeight.value_or( + theme->GetDigitalIndicatorTextStyle().GetFontWeight())); + auto props = swiper.GetLayoutProperty(); + CHECK_NULL_VOID(props); + props->UpdateLeft(digitalParams->dimLeft.value_or(0.0_vp)); + props->UpdateTop(digitalParams->dimTop.value_or(0.0_vp)); + props->UpdateRight(digitalParams->dimRight.value_or(0.0_vp)); + props->UpdateBottom(digitalParams->dimBottom.value_or(0.0_vp)); + swiper.SetDigitStartAndEndProperty(indicatorNode); +} + +void SwiperHelper::SaveDotIndicatorProperty(const RefPtr& indicatorNode, SwiperPattern& swiper) +{ + CHECK_NULL_VOID(indicatorNode); + auto indicatorProps = indicatorNode->GetLayoutProperty(); + CHECK_NULL_VOID(indicatorProps); + const auto params = swiper.GetSwiperParameters(); + CHECK_NULL_VOID(params); + indicatorProps->ResetIndicatorLayoutStyle(); + if (params->dimLeft.has_value()) { + indicatorProps->UpdateLeft(params->dimLeft.value()); + } + if (params->dimTop.has_value()) { + indicatorProps->UpdateTop(params->dimTop.value()); + } + if (params->dimRight.has_value()) { + indicatorProps->UpdateRight(params->dimRight.value()); + } + if (params->dimBottom.has_value()) { + indicatorProps->UpdateBottom(params->dimBottom.value()); + } + const bool isRtl = swiper.GetNonAutoLayoutDirection() == TextDirection::RTL; + if (params->dimStart.has_value()) { + auto dimValue = params->dimStart.value(); + isRtl ? indicatorProps->UpdateRight(dimValue) : indicatorProps->UpdateLeft(dimValue); + } else if (params->dimEnd.has_value()) { + auto dimValue = params->dimEnd.value(); + isRtl ? indicatorProps->UpdateLeft(dimValue) : indicatorProps->UpdateRight(dimValue); + } + + swiper.UpdatePaintProperty(indicatorNode); +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_helper.h b/frameworks/core/components_ng/pattern/swiper/swiper_helper.h new file mode 100644 index 00000000000..3b9d3deea09 --- /dev/null +++ b/frameworks/core/components_ng/pattern/swiper/swiper_helper.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 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_CORE_COMPONENTS_NG_PATTERN_SWIPER_SWIPER_HELPER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_SWIPER_HELPER_H +#include "swiper_pattern.h" + +#include "core/components/swiper/swiper_controller.h" +namespace OHOS::Ace::NG { +/* implements helper functions for SwiperPattern */ +class SwiperHelper { +public: + /* Init controller of swiper, controller support showNext, showPrevious and finishAnimation interface. */ + static void InitSwiperController(const RefPtr& controller, const WeakPtr& weak); + + static void SaveDigitIndicatorProperty(const RefPtr& indicatorNode, SwiperPattern& swiper); + static void SaveDotIndicatorProperty(const RefPtr& indicatorNode, SwiperPattern& swiper); +}; +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWIPER_SWIPER_HELPER_H diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp index 26ba353bfb5..f6e67001e3a 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.cpp @@ -40,6 +40,7 @@ #include "core/components_ng/pattern/navrouter/navdestination_pattern.h" #include "core/components_ng/pattern/scrollable/scrollable_properties.h" #include "core/components_ng/pattern/stage/page_pattern.h" +#include "core/components_ng/pattern/swiper/swiper_helper.h" #include "core/components_ng/pattern/swiper/swiper_layout_algorithm.h" #include "core/components_ng/pattern/swiper/swiper_layout_property.h" #include "core/components_ng/pattern/swiper/swiper_model.h" @@ -111,7 +112,7 @@ float CalculateFriction(float gamma) SwiperPattern::SwiperPattern() { swiperController_ = MakeRefPtr(); - InitSwiperController(); + SwiperHelper::InitSwiperController(swiperController_, WeakClaim(this)); } void SwiperPattern::OnAttachToFrameNode() @@ -138,52 +139,51 @@ RefPtr SwiperPattern::CreateLayoutAlgorithm() { auto host = GetHost(); CHECK_NULL_RETURN(host, nullptr); - auto swiperLayoutProperty = host->GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, nullptr); + auto props = host->GetLayoutProperty(); + CHECK_NULL_RETURN(props, nullptr); - auto swiperLayoutAlgorithm = MakeRefPtr(); - if (swiperLayoutProperty->GetIsCustomAnimation().value_or(false)) { - swiperLayoutAlgorithm->SetUseCustomAnimation(true); - swiperLayoutAlgorithm->SetCustomAnimationToIndex(customAnimationToIndex_); - swiperLayoutAlgorithm->SetIndexsInAnimation(indexsInAnimation_); - swiperLayoutAlgorithm->SetNeedUnmountIndexs(needUnmountIndexs_); - return swiperLayoutAlgorithm; + auto algo = MakeRefPtr(); + if (props->GetIsCustomAnimation().value_or(false)) { + algo->SetUseCustomAnimation(true); + algo->SetCustomAnimationToIndex(customAnimationToIndex_); + algo->SetIndexsInAnimation(indexsInAnimation_); + algo->SetNeedUnmountIndexs(needUnmountIndexs_); + return algo; } if (SupportSwiperCustomAnimation()) { - swiperLayoutAlgorithm->SetNeedUnmountIndexs(needUnmountIndexs_); - swiperLayoutAlgorithm->SetItemsPositionInAnimation(itemPositionInAnimation_); + algo->SetNeedUnmountIndexs(needUnmountIndexs_); + algo->SetItemsPositionInAnimation(itemPositionInAnimation_); } if (jumpIndex_) { - swiperLayoutAlgorithm->SetJumpIndex(jumpIndex_.value()); + algo->SetJumpIndex(jumpIndex_.value()); } else if (targetIndex_) { - swiperLayoutAlgorithm->SetTargetIndex(targetIndex_.value()); + algo->SetTargetIndex(targetIndex_.value()); } - swiperLayoutAlgorithm->SetCurrentIndex(currentIndex_); - swiperLayoutAlgorithm->SetContentCrossSize(contentCrossSize_); - swiperLayoutAlgorithm->SetMainSizeIsMeasured(mainSizeIsMeasured_); - swiperLayoutAlgorithm->SetContentMainSize(contentMainSize_); - swiperLayoutAlgorithm->SetCurrentDelta(currentDelta_); - swiperLayoutAlgorithm->SetItemsPosition(itemPosition_); + algo->SetCurrentIndex(currentIndex_); + algo->SetContentCrossSize(contentCrossSize_); + algo->SetMainSizeIsMeasured(mainSizeIsMeasured_); + algo->SetContentMainSize(contentMainSize_); + algo->SetCurrentDelta(currentDelta_); + algo->SetItemsPosition(itemPosition_); if (IsOutOfBoundary() && !IsLoop()) { - swiperLayoutAlgorithm->SetOverScrollFeature(); + algo->SetOverScrollFeature(); } - swiperLayoutAlgorithm->SetTotalItemCount(TotalCount()); - swiperLayoutAlgorithm->SetIsLoop(IsLoop()); - swiperLayoutAlgorithm->SetSwipeByGroup(IsSwipeByGroup()); - swiperLayoutAlgorithm->SetRealTotalCount(RealTotalCount()); - swiperLayoutAlgorithm->SetPlaceItemWidth(placeItemWidth_); - swiperLayoutAlgorithm->SetIsFrameAnimation(translateAnimationIsRunning_); + algo->SetTotalItemCount(TotalCount()); + algo->SetIsLoop(IsLoop()); + algo->SetSwipeByGroup(IsSwipeByGroup()); + algo->SetRealTotalCount(RealTotalCount()); + algo->SetPlaceItemWidth(placeItemWidth_); + algo->SetIsFrameAnimation(translateAnimationIsRunning_); auto swiperPaintProperty = host->GetPaintProperty(); - auto effect = swiperPaintProperty->GetEdgeEffect().value_or(EdgeEffect::SPRING); - bool canOverScroll = effect == EdgeEffect::SPRING; - swiperLayoutAlgorithm->SetCanOverScroll(canOverScroll); - swiperLayoutAlgorithm->SetHasCachedCapture(hasCachedCapture_); - swiperLayoutAlgorithm->SetIsCaptureReverse(isCaptureReverse_); - swiperLayoutAlgorithm->SetCachedCount(GetCachedCount()); - swiperLayoutAlgorithm->SetNextMarginIgnoreBlank(nextMarginIgnoreBlank_); - return swiperLayoutAlgorithm; + const auto effect = swiperPaintProperty->GetEdgeEffect().value_or(EdgeEffect::SPRING); + algo->SetCanOverScroll(effect == EdgeEffect::SPRING); + algo->SetHasCachedCapture(hasCachedCapture_); + algo->SetIsCaptureReverse(isCaptureReverse_); + algo->SetCachedCount(GetCachedCount()); + algo->SetNextMarginIgnoreBlank(nextMarginIgnoreBlank_); + return algo; } void SwiperPattern::OnIndexChange() @@ -220,31 +220,31 @@ void SwiperPattern::StopAndResetSpringAnimation() void SwiperPattern::OnLoopChange() { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); if (!preLoop_.has_value()) { - preLoop_ = layoutProperty->GetLoop().value_or(true); + preLoop_ = props->GetLoop().value_or(true); return; } - if (preLoop_.value() && !layoutProperty->GetLoop().value_or(true)) { + if (preLoop_.value() && !props->GetLoop().value_or(true)) { needResetCurrentIndex_ = true; } - if (preLoop_.value() != layoutProperty->GetLoop().value_or(true) && - (layoutProperty->GetPrevMargin().has_value() || layoutProperty->GetNextMargin().has_value())) { + if (preLoop_.value() != props->GetLoop().value_or(true) && + (props->GetPrevMargin().has_value() || props->GetNextMargin().has_value())) { jumpIndex_ = GetLoopIndex(currentIndex_); - preLoop_ = layoutProperty->GetLoop().value_or(true); + preLoop_ = props->GetLoop().value_or(true); } } void SwiperPattern::AdjustCurrentIndexOnSwipePage(int32_t index) { auto adjustIndex = SwiperUtils::ComputePageIndex(index, GetDisplayCount()); - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - layoutProperty->UpdateIndexWithoutMeasure(GetLoopIndex(adjustIndex)); + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); + props->UpdateIndexWithoutMeasure(GetLoopIndex(adjustIndex)); currentIndex_ = GetLoopIndex(adjustIndex); } @@ -252,12 +252,12 @@ void SwiperPattern::InitCapture() { auto host = GetHost(); CHECK_NULL_VOID(host); - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - bool hasCachedCapture = SwiperUtils::IsStretch(layoutProperty) && layoutProperty->GetLoop().value_or(true) && - !IsSwipeByGroup() && GetDisplayCount() == TotalCount() - 1 && - (Positive(layoutProperty->GetPrevMarginValue(0.0_px).ConvertToPx()) || - Positive(layoutProperty->GetNextMarginValue(0.0_px).ConvertToPx())); + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); + bool hasCachedCapture = SwiperUtils::IsStretch(props) && props->GetLoop().value_or(true) && !IsSwipeByGroup() && + GetDisplayCount() == TotalCount() - 1 && + (Positive(props->GetPrevMarginValue(0.0_px).ConvertToPx()) || + Positive(props->GetNextMarginValue(0.0_px).ConvertToPx())); if (hasCachedCapture) { leftCaptureIndex_ = std::nullopt; rightCaptureIndex_ = std::nullopt; @@ -324,20 +324,20 @@ void SwiperPattern::UpdateTabBarIndicatorCurve() CHECK_NULL_VOID(swiperPattern); auto host = swiperPattern->GetHost(); CHECK_NULL_VOID(host); - auto swiperPaintProperty = host->GetPaintProperty(); - CHECK_NULL_VOID(swiperPaintProperty); + auto props = host->GetPaintProperty(); + CHECK_NULL_VOID(props); auto curve = MakeRefPtr(0.2f, 0.0f, 0.1f, 1.0f); - swiperPaintProperty->UpdateCurve(curve); + props->UpdateCurve(curve); }; swiperController_->SetUpdateCubicCurveCallback(std::move(updateCubicCurveCallback)); } bool SwiperPattern::NeedForceMeasure() const { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, false); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, false); - return ((layoutProperty->GetPropertyChangeFlag() & PROPERTY_UPDATE_MEASURE) == PROPERTY_UPDATE_MEASURE) || + return ((props->GetPropertyChangeFlag() & PROPERTY_UPDATE_MEASURE) == PROPERTY_UPDATE_MEASURE) || (isSwipeByGroup_.has_value() && isSwipeByGroup_.value() != IsSwipeByGroup()); } @@ -445,8 +445,8 @@ void SwiperPattern::BeforeCreateLayoutWrapper() host->ChildrenUpdatedFrom(-1); } - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); oldIndex_ = currentIndex_; auto userSetCurrentIndex = CurrentIndex(); userSetCurrentIndex = CheckUserSetIndex(userSetCurrentIndex); @@ -469,7 +469,7 @@ void SwiperPattern::BeforeCreateLayoutWrapper() } if (userSetCurrentIndex < 0 || userSetCurrentIndex >= RealTotalCount() || GetDisplayCount() >= RealTotalCount()) { currentIndex_ = 0; - layoutProperty->UpdateIndexWithoutMeasure(GetLoopIndex(currentIndex_)); + props->UpdateIndexWithoutMeasure(GetLoopIndex(currentIndex_)); } else { if (oldIndex != userSetCurrentIndex) { currentIndex_ = userSetCurrentIndex; @@ -512,7 +512,7 @@ void SwiperPattern::BeforeCreateLayoutWrapper() if (needResetCurrentIndex_) { needResetCurrentIndex_ = false; currentIndex_ = GetLoopIndex(currentIndex_); - layoutProperty->UpdateIndexWithoutMeasure(currentIndex_); + props->UpdateIndexWithoutMeasure(currentIndex_); } } @@ -612,8 +612,9 @@ void SwiperPattern::InitSurfaceChangedCallback() auto pipeline = host->GetContextRefPtr(); CHECK_NULL_VOID(pipeline); if (!HasSurfaceChangedCallback()) { - auto callbackId = pipeline->RegisterSurfaceChangedCallback([weak = WeakClaim(this)] - (int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight, WindowSizeChangeReason type) { + auto callbackId = pipeline->RegisterSurfaceChangedCallback( + [weak = WeakClaim(this)](int32_t newWidth, int32_t newHeight, int32_t prevWidth, int32_t prevHeight, + WindowSizeChangeReason type) { if (type == WindowSizeChangeReason::UNDEFINED && newWidth == prevWidth && newHeight == prevHeight) { return; } @@ -749,8 +750,8 @@ WeakPtr SwiperPattern::PreviousFocus(const RefPtr& curFocusN CHECK_NULL_RETURN(curFocusNode, nullptr); RefPtr indicatorNode; RefPtr leftArrowNode; - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, nullptr); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, nullptr); if (HasLeftButtonNode()) { leftArrowNode = GetFocusHubChild(V2::SWIPER_LEFT_ARROW_ETS_TAG); CHECK_NULL_RETURN(leftArrowNode, nullptr); @@ -767,7 +768,7 @@ WeakPtr SwiperPattern::PreviousFocus(const RefPtr& curFocusN } if (curFocusNode->GetFrameName() == V2::SWIPER_INDICATOR_ETS_TAG) { if (!HasLeftButtonNode() || (!IsLoop() && GetLoopIndex(currentIndex_) == 0) || - layoutProperty->GetHoverShowValue(false)) { + props->GetHoverShowValue(false)) { isLastIndicatorFocused_ = true; curFocusNode->SetParentFocusable(true); return nullptr; @@ -799,8 +800,8 @@ WeakPtr SwiperPattern::NextFocus(const RefPtr& curFocusNode) CHECK_NULL_RETURN(curFocusNode, nullptr); RefPtr indicatorNode; RefPtr rightArrowNode; - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, nullptr); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, nullptr); if (HasIndicatorNode()) { indicatorNode = GetFocusHubChild(V2::SWIPER_INDICATOR_ETS_TAG); CHECK_NULL_RETURN(indicatorNode, nullptr); @@ -825,7 +826,7 @@ WeakPtr SwiperPattern::NextFocus(const RefPtr& curFocusNode) } if (curFocusNode->GetFrameName() == V2::SWIPER_INDICATOR_ETS_TAG) { if (!HasRightButtonNode() || (!IsLoop() && GetLoopIndex(currentIndex_) == TotalCount() - 1) || - layoutProperty->GetHoverShowValue(false)) { + props->GetHoverShowValue(false)) { isLastIndicatorFocused_ = true; curFocusNode->SetParentFocusable(true); return nullptr; @@ -888,34 +889,34 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, return false; } - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, false); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, false); auto layoutAlgorithmWrapper = dirty->GetLayoutAlgorithm(); CHECK_NULL_RETURN(layoutAlgorithmWrapper, false); - auto swiperLayoutAlgorithm = DynamicCast(layoutAlgorithmWrapper->GetLayoutAlgorithm()); - CHECK_NULL_RETURN(swiperLayoutAlgorithm, false); + auto algo = DynamicCast(layoutAlgorithmWrapper->GetLayoutAlgorithm()); + CHECK_NULL_RETURN(algo, false); - if (layoutProperty->GetIsCustomAnimation().value_or(false)) { - needUnmountIndexs_ = swiperLayoutAlgorithm->GetNeedUnmountIndexs(); + if (props->GetIsCustomAnimation().value_or(false)) { + needUnmountIndexs_ = algo->GetNeedUnmountIndexs(); return false; } if (SupportSwiperCustomAnimation()) { - needUnmountIndexs_ = swiperLayoutAlgorithm->GetNeedUnmountIndexs(); - itemPositionInAnimation_ = swiperLayoutAlgorithm->GetItemsPositionInAnimation(); + needUnmountIndexs_ = algo->GetNeedUnmountIndexs(); + itemPositionInAnimation_ = algo->GetItemsPositionInAnimation(); FireContentDidScrollEvent(); } autoLinearReachBoundary = false; bool isJump = false; - startMainPos_ = swiperLayoutAlgorithm->GetStartPosition(); - endMainPos_ = swiperLayoutAlgorithm->GetEndPosition(); - startIndex_ = swiperLayoutAlgorithm->GetStartIndex(); - endIndex_ = swiperLayoutAlgorithm->GetEndIndex(); - cachedItems_ = swiperLayoutAlgorithm->GetCachedItems(); - layoutConstraint_ = swiperLayoutAlgorithm->GetLayoutConstraint(); - itemPosition_ = std::move(swiperLayoutAlgorithm->GetItemPosition()); + startMainPos_ = algo->GetStartPosition(); + endMainPos_ = algo->GetEndPosition(); + startIndex_ = algo->GetStartIndex(); + endIndex_ = algo->GetEndIndex(); + cachedItems_ = algo->GetCachedItems(); + layoutConstraint_ = algo->GetLayoutConstraint(); + itemPosition_ = std::move(algo->GetItemPosition()); PostIdleTask(GetHost()); - currentOffset_ -= swiperLayoutAlgorithm->GetCurrentOffset(); + currentOffset_ -= algo->GetCurrentOffset(); if (!itemPosition_.empty()) { const auto& turnPageRateCallback = swiperController_->GetTurnPageRateCallback(); auto firstItem = GetFirstItemInfoInVisibleArea(); @@ -927,8 +928,8 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, placeItemWidth_ = translateLength; } if (hasCachedCapture_) { - isCaptureReverse_ = swiperLayoutAlgorithm->GetIsCaptureReverse(); - UpdateTargetCapture(swiperLayoutAlgorithm->GetIsNeedUpdateCapture()); + isCaptureReverse_ = algo->GetIsCaptureReverse(); + UpdateTargetCapture(algo->GetIsNeedUpdateCapture()); } if (jumpIndex_) { @@ -951,7 +952,7 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, }); } isJump = true; - UpdateCurrentIndex(swiperLayoutAlgorithm->GetCurrentIndex()); + UpdateCurrentIndex(algo->GetCurrentIndex()); AdjustCurrentFocusIndex(); auto curChild = dirty->GetOrCreateChildByIndex(GetLoopIndex(currentFocusIndex_)); if (curChild && IsContentFocused()) { @@ -983,19 +984,18 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, ignoreBlankSpringOffset_ = IgnoreBlankOffset(false); float targetPos = iter->second.startPos + IgnoreBlankOffset(false); auto context = GetContext(); - auto swiperLayoutProperty = GetLayoutProperty(); + auto props = GetLayoutProperty(); bool isNeedForwardTranslate = false; if (!hasCachedCapture_ && IsLoop()) { - auto lastItemIndex = Positive(swiperLayoutProperty->GetCalculatedNextMargin()) + auto lastItemIndex = Positive(props->GetCalculatedNextMargin()) ? targetIndexValue + GetDisplayCount() : targetIndexValue + GetDisplayCount() - 1; isNeedForwardTranslate = itemPosition_.find(lastItemIndex) == itemPosition_.end(); } bool isNeedBackwardTranslate = false; if (!hasCachedCapture_ && IsLoop() && targetIndexValue < currentIndex_) { - auto firstItemIndex = Positive(swiperLayoutProperty->GetCalculatedPrevMargin()) - ? targetIndexValue + TotalCount() - 1 - : targetIndexValue + TotalCount(); + auto firstItemIndex = Positive(props->GetCalculatedPrevMargin()) ? targetIndexValue + TotalCount() - 1 + : targetIndexValue + TotalCount(); isNeedBackwardTranslate = itemPosition_.find(firstItemIndex) != itemPosition_.end(); } bool isNeedPlayTranslateAnimation = translateAnimationIsRunning_ || isNeedForwardTranslate || @@ -1004,7 +1004,7 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, // displayCount is auto, loop is false, if the content width less than windows size // need offset to keep right aligned bool isNeedOffset = (GetLoopIndex(iter->first) == TotalCount() - 1) && - !layoutProperty->GetDisplayCount().has_value() && !IsLoop() && + !props->GetDisplayCount().has_value() && !IsLoop() && LessNotEqual(iter->second.endPos - iter->second.startPos, CalculateVisibleSize()); float offset = isNeedOffset ? CalculateVisibleSize() - iter->second.endPos + iter->second.startPos : 0.0; @@ -1021,7 +1021,7 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, PlayTranslateAnimation( currentOffset_, currentOffset_ - targetPos, iter->first, false, velocity_.value_or(0.0f)); } - } else if (!itemPosition_.empty() && SwiperUtils::IsStretch(layoutProperty)) { + } else if (!itemPosition_.empty() && SwiperUtils::IsStretch(props)) { auto firstItem = GetFirstItemInfoInVisibleArea(); auto targetPos = firstItem.second.startPos + (targetIndexValue - firstItem.first) * (placeItemWidth_.value() + GetItemSpace()); @@ -1029,17 +1029,17 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, currentOffset_, currentOffset_ - targetPos, targetIndexValue, false, velocity_.value_or(0.0f)); } else { // AutoLinear Mode - PlayTranslateAnimation(currentOffset_, currentOffset_ - swiperLayoutAlgorithm->GetTargetStartPos(), - targetIndexValue, false, velocity_.value_or(0.0f)); + PlayTranslateAnimation(currentOffset_, currentOffset_ - algo->GetTargetStartPos(), targetIndexValue, false, + velocity_.value_or(0.0f)); } velocity_.reset(); pauseTargetIndex_ = targetIndex_; } - mainSizeIsMeasured_ = swiperLayoutAlgorithm->GetMainSizeIsMeasured(); - contentCrossSize_ = swiperLayoutAlgorithm->GetContentCrossSize(); + mainSizeIsMeasured_ = algo->GetMainSizeIsMeasured(); + contentCrossSize_ = algo->GetContentCrossSize(); currentDelta_ = 0.0f; - contentMainSize_ = swiperLayoutAlgorithm->GetContentMainSize(); - crossMatchChild_ = swiperLayoutAlgorithm->IsCrossMatchChild(); + contentMainSize_ = algo->GetContentMainSize(); + crossMatchChild_ = algo->IsCrossMatchChild(); oldIndex_ = currentIndex_; oldChildrenSize_ = RealTotalCount(); needFireCustomAnimationEvent_ = true; @@ -1049,7 +1049,7 @@ bool SwiperPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED; } - const auto& paddingProperty = layoutProperty->GetPaddingProperty(); + const auto& paddingProperty = props->GetPaddingProperty(); return GetEdgeEffect() == EdgeEffect::FADE || paddingProperty != nullptr; } @@ -1085,9 +1085,9 @@ float SwiperPattern::IgnoreBlankOffset(bool isJump) bool SwiperPattern::IsAutoLinear() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, false); - return !SwiperUtils::IsStretch(swiperLayoutProperty); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, false); + return !SwiperUtils::IsStretch(props); } bool SwiperPattern::AutoLinearAnimationNeedReset(float translate) const @@ -1414,9 +1414,9 @@ void SwiperPattern::StopSpringAnimationAndFlushImmediately() bool SwiperPattern::IsUseCustomAnimation() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, false); - return swiperLayoutProperty->GetIsCustomAnimation().value_or(false); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, false); + return props->GetIsCustomAnimation().value_or(false); } void SwiperPattern::SwipeTo(int32_t index) @@ -1499,9 +1499,9 @@ int32_t SwiperPattern::CheckTargetIndex(int32_t targetIndex, bool isForceBackwar while (GetLoopIndex(targetIndex) != GetLoopIndex(currentIndex_)) { auto currentFrameNode = GetCurrentFrameNode(GetLoopIndex(targetIndex)); CHECK_NULL_RETURN(currentFrameNode, targetIndex); - auto swiperLayoutProperty = currentFrameNode->GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, targetIndex); - if (swiperLayoutProperty->GetVisibility().value_or(VisibleType::VISIBLE) != VisibleType::GONE) { + auto props = currentFrameNode->GetLayoutProperty(); + CHECK_NULL_RETURN(props, targetIndex); + if (props->GetVisibility().value_or(VisibleType::VISIBLE) != VisibleType::GONE) { return targetIndex; } if (isForceBackward || currentIndex_ < targetIndex) { @@ -1741,13 +1741,13 @@ void SwiperPattern::DoTabsPreloadItems(const std::set& indexSet) { auto host = GetHost(); CHECK_NULL_VOID(host); - auto layoutProperty = host->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); + auto props = host->GetLayoutProperty(); + CHECK_NULL_VOID(props); auto geometryNode = host->GetGeometryNode(); CHECK_NULL_VOID(geometryNode); - auto contentConstraint = layoutProperty->GetContentLayoutConstraint(); + auto contentConstraint = props->GetContentLayoutConstraint(); auto frameSize = OptionalSizeF(geometryNode->GetPaddingSize()); - auto childConstraint = SwiperUtils::CreateChildConstraint(layoutProperty, frameSize, false); + auto childConstraint = SwiperUtils::CreateChildConstraint(props, frameSize, false); for (auto index : indexSet) { auto tabContent = GetCurrentFrameNode(index); if (!tabContent) { @@ -1869,58 +1869,6 @@ void SwiperPattern::StopFadeAnimation() } } -void SwiperPattern::InitSwiperController() -{ - swiperController_->SetSwipeToImpl([weak = WeakClaim(this)](int32_t index, bool reverse) { - auto swiper = weak.Upgrade(); - CHECK_NULL_VOID(swiper); - swiper->SwipeTo(index); - }); - - swiperController_->SetSwipeToWithoutAnimationImpl([weak = WeakClaim(this)](int32_t index) { - auto swiper = weak.Upgrade(); - CHECK_NULL_VOID(swiper); - swiper->SwipeToWithoutAnimation(index); - }); - - swiperController_->SetShowNextImpl([weak = WeakClaim(this)]() { - auto swiper = weak.Upgrade(); - CHECK_NULL_VOID(swiper); - auto swiperNode = swiper->GetHost(); - CHECK_NULL_VOID(swiperNode); - TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ShowNext, id:%{public}d", swiperNode->GetId()); - swiper->ShowNext(); - }); - - swiperController_->SetShowPrevImpl([weak = WeakClaim(this)]() { - auto swiper = weak.Upgrade(); - CHECK_NULL_VOID(swiper); - auto swiperNode = swiper->GetHost(); - CHECK_NULL_VOID(swiperNode); - TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ShowPrevious, id:%{public}d", swiperNode->GetId()); - swiper->ShowPrevious(); - }); - - swiperController_->SetChangeIndexImpl([weak = WeakClaim(this)](int32_t index, bool useAnimation) { - auto swiper = weak.Upgrade(); - CHECK_NULL_VOID(swiper); - TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper ChangeIndex %{public}d, useAnimation:%{public}d", index, useAnimation); - swiper->ChangeIndex(index, useAnimation); - }); - - swiperController_->SetFinishImpl([weak = WeakClaim(this)]() { - auto swiper = weak.Upgrade(); - CHECK_NULL_VOID(swiper); - swiper->FinishAnimation(); - }); - - swiperController_->SetPreloadItemsImpl([weak = WeakClaim(this)](const std::set& indexSet) { - auto swiper = weak.Upgrade(); - CHECK_NULL_VOID(swiper); - swiper->PreloadItems(indexSet); - }); -} - void SwiperPattern::InitIndicator() { auto swiperNode = GetHost(); @@ -1950,14 +1898,14 @@ void SwiperPattern::InitIndicator() } lastSwiperIndicatorType_ = GetIndicatorType(); CHECK_NULL_VOID(indicatorNode); - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - if (layoutProperty->GetIndicatorTypeValue(SwiperIndicatorType::DOT) == SwiperIndicatorType::DOT) { - SaveDotIndicatorProperty(indicatorNode); - } else if (layoutProperty->GetIndicatorTypeValue(SwiperIndicatorType::DOT) == SwiperIndicatorType::ARC_DOT) { + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); + if (props->GetIndicatorTypeValue(SwiperIndicatorType::DOT) == SwiperIndicatorType::DOT) { + SwiperHelper::SaveDotIndicatorProperty(indicatorNode, *this); + } else if (props->GetIndicatorTypeValue(SwiperIndicatorType::DOT) == SwiperIndicatorType::ARC_DOT) { SaveCircleDotIndicatorProperty(indicatorNode); } else { - SaveDigitIndicatorProperty(indicatorNode); + SwiperHelper::SaveDigitIndicatorProperty(indicatorNode, *this); } auto renderContext = indicatorNode->GetRenderContext(); @@ -2153,9 +2101,8 @@ bool SwiperPattern::IsContentFocused() continue; } auto frameName = child->GetFrameName(); - if (frameName == V2::SWIPER_INDICATOR_ETS_TAG - || frameName == V2::SWIPER_RIGHT_ARROW_ETS_TAG - || frameName == V2::SWIPER_LEFT_ARROW_ETS_TAG) { + if (frameName == V2::SWIPER_INDICATOR_ETS_TAG || frameName == V2::SWIPER_RIGHT_ARROW_ETS_TAG || + frameName == V2::SWIPER_LEFT_ARROW_ETS_TAG) { return false; } break; @@ -2289,8 +2236,9 @@ bool SwiperPattern::CheckOverScroll(float offset) case EdgeEffect::NONE: if (IsHorizontalAndRightToLeft()) { if (IsOutOfBoundary(-offset)) { - auto realOffset = IsOutOfStart(offset) ? - itemPosition_.begin()->second.startPos : - CalculateVisibleSize() - itemPosition_.rbegin()->second.endPos; + auto realOffset = IsOutOfStart(offset) + ? -itemPosition_.begin()->second.startPos + : CalculateVisibleSize() - itemPosition_.rbegin()->second.endPos; currentDelta_ = currentDelta_ + realOffset; HandleSwiperCustomAnimation(realOffset); MarkDirtyNodeSelf(); @@ -2820,9 +2768,9 @@ void SwiperPattern::HandleDragEnd(double dragVelocity) void SwiperPattern::UpdateCurrentIndex(int32_t index) { currentIndex_ = index; - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - layoutProperty->UpdateIndexWithoutMeasure(GetLoopIndex(currentIndex_)); + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); + props->UpdateIndexWithoutMeasure(GetLoopIndex(currentIndex_)); } int32_t SwiperPattern::ComputeSwipePageNextIndex(float velocity, bool onlyDistance) const @@ -3455,11 +3403,9 @@ void SwiperPattern::OnSpringAnimationFinish() } PerfMonitor::GetPerfMonitor()->End(PerfConstants::APP_LIST_FLING, false); AceAsyncTraceEndCommercial(0, TRAILING_ANIMATION); - TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper finish spring animation offset %{public}f", - currentIndexOffset_); + TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper finish spring animation offset %{public}f", currentIndexOffset_); ACE_SCOPED_TRACE_COMMERCIAL("%s finish spring animation, offset: %f", - hasTabsAncestor_ ? V2::TABS_ETS_TAG : V2::SWIPER_ETS_TAG, - currentIndexOffset_); + hasTabsAncestor_ ? V2::TABS_ETS_TAG : V2::SWIPER_ETS_TAG, currentIndexOffset_); springAnimationIsRunning_ = false; isTouchDownSpringAnimation_ = false; OnSpringAndFadeAnimationFinish(); @@ -3624,8 +3570,8 @@ void SwiperPattern::PlaySpringAnimation(double dragVelocity) TAG_LOGI(AceLogTag::ACE_SWIPER, "Swiper start spring animation"); auto swiperPattern = weak.Upgrade(); CHECK_NULL_VOID(swiperPattern); - ACE_SCOPED_TRACE_COMMERCIAL("%s start spring animation", - swiperPattern->hasTabsAncestor_ ? V2::TABS_ETS_TAG : V2::SWIPER_ETS_TAG); + ACE_SCOPED_TRACE_COMMERCIAL( + "%s start spring animation", swiperPattern->hasTabsAncestor_ ? V2::TABS_ETS_TAG : V2::SWIPER_ETS_TAG); swiperPattern->OnSpringAnimationStart(static_cast(dragVelocity)); host->UpdateAnimatablePropertyFloat(SPRING_PROPERTY_NAME, delta); swiperPattern->springAnimationIsRunning_ = true; @@ -3779,14 +3725,14 @@ float SwiperPattern::CalculateVisibleSize() const float SwiperPattern::GetItemSpace() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, 0.0f); - if (swiperLayoutProperty->IgnoreItemSpace()) { + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 0.0f); + if (props->IgnoreItemSpace()) { return 0.0f; } - auto itemSpace = ConvertToPx(swiperLayoutProperty->GetItemSpace().value_or(0.0_vp), - swiperLayoutProperty->GetLayoutConstraint()->scaleProperty, 0.0f) - .value_or(0.0f); + auto itemSpace = + ConvertToPx(props->GetItemSpace().value_or(0.0_vp), props->GetLayoutConstraint()->scaleProperty, 0.0f) + .value_or(0.0f); auto host = GetHost(); CHECK_NULL_RETURN(host, 0.0f); auto geometryNode = host->GetGeometryNode(); @@ -3800,47 +3746,47 @@ float SwiperPattern::GetItemSpace() const float SwiperPattern::GetPrevMargin() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, 0.0f); - return swiperLayoutProperty->GetCalculatedPrevMargin(); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 0.0f); + return props->GetCalculatedPrevMargin(); } float SwiperPattern::GetNextMargin() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, 0.0f); - return swiperLayoutProperty->GetCalculatedNextMargin(); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 0.0f); + return props->GetCalculatedNextMargin(); } Axis SwiperPattern::GetDirection() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, Axis::HORIZONTAL); - return swiperLayoutProperty->GetDirection().value_or(Axis::HORIZONTAL); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, Axis::HORIZONTAL); + return props->GetDirection().value_or(Axis::HORIZONTAL); } int32_t SwiperPattern::CurrentIndex() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, 0); - return swiperLayoutProperty->GetIndex().value_or(0); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 0); + return props->GetIndex().value_or(0); } int32_t SwiperPattern::GetDisplayCount() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, 1); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 1); auto displayCount = CalculateDisplayCount(); return displayCount; } int32_t SwiperPattern::CalculateDisplayCount() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, 1); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 1); bool isAutoFill = IsAutoFill(); if (isAutoFill) { - auto minSize = swiperLayoutProperty->GetMinSize()->ConvertToPx(); + auto minSize = props->GetMinSize()->ConvertToPx(); float contentWidth = GetMainContentSize(); auto displayCount = CalculateCount(contentWidth, minSize, SWIPER_MARGIN.ConvertToPx(), SWIPER_GUTTER.ConvertToPx()); @@ -3851,9 +3797,9 @@ int32_t SwiperPattern::CalculateDisplayCount() const displayCount = displayCount > 0 ? displayCount : 1; auto totalCount = TotalCount(); displayCount = displayCount > totalCount ? totalCount : displayCount; - auto displayCountProperty = swiperLayoutProperty->GetDisplayCount().value_or(1); + auto displayCountProperty = props->GetDisplayCount().value_or(1); if (displayCountProperty != displayCount) { - swiperLayoutProperty->UpdateDisplayCount(displayCount); + props->UpdateDisplayCount(displayCount); auto host = GetHost(); CHECK_NULL_RETURN(host, 1); host->MarkDirtyNode( @@ -3862,7 +3808,7 @@ int32_t SwiperPattern::CalculateDisplayCount() const } return displayCount; } else { - return swiperLayoutProperty->GetDisplayCount().value_or(1); + return props->GetDisplayCount().value_or(1); } } @@ -3874,39 +3820,39 @@ int32_t SwiperPattern::CalculateCount( bool SwiperPattern::IsAutoFill() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, false); - return swiperLayoutProperty->GetMinSize().has_value(); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, false); + return props->GetMinSize().has_value(); } bool SwiperPattern::IsAutoPlay() const { - auto swiperPaintProperty = GetPaintProperty(); - CHECK_NULL_RETURN(swiperPaintProperty, false); - return swiperPaintProperty->GetAutoPlay().value_or(false); + auto props = GetPaintProperty(); + CHECK_NULL_RETURN(props, false); + return props->GetAutoPlay().value_or(false); } int32_t SwiperPattern::GetDuration() const { const int32_t DEFAULT_DURATION = 400; - auto swiperPaintProperty = GetPaintProperty(); - CHECK_NULL_RETURN(swiperPaintProperty, DEFAULT_DURATION); - return swiperPaintProperty->GetDuration().value_or(DEFAULT_DURATION); + auto props = GetPaintProperty(); + CHECK_NULL_RETURN(props, DEFAULT_DURATION); + return props->GetDuration().value_or(DEFAULT_DURATION); } int32_t SwiperPattern::GetInterval() const { const int32_t DEFAULT_INTERVAL = 3000; - auto swiperPaintProperty = GetPaintProperty(); - CHECK_NULL_RETURN(swiperPaintProperty, DEFAULT_INTERVAL); - return swiperPaintProperty->GetAutoPlayInterval().value_or(DEFAULT_INTERVAL); + auto props = GetPaintProperty(); + CHECK_NULL_RETURN(props, DEFAULT_INTERVAL); + return props->GetAutoPlayInterval().value_or(DEFAULT_INTERVAL); } RefPtr SwiperPattern::GetCurve() const { - auto swiperPaintProperty = GetPaintProperty(); - CHECK_NULL_RETURN(swiperPaintProperty, nullptr); - return swiperPaintProperty->GetCurve().value_or(nullptr); + auto props = GetPaintProperty(); + CHECK_NULL_RETURN(props, nullptr); + return props->GetCurve().value_or(nullptr); } bool SwiperPattern::IsLoop() const @@ -3914,29 +3860,28 @@ bool SwiperPattern::IsLoop() const if (hasCachedCapture_) { return true; } - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, true); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, true); if (TotalDisPlayCount() > TotalCount() || - (TotalDisPlayCount() == TotalCount() && SwiperUtils::IsStretch(layoutProperty) && - (NonPositive(layoutProperty->GetCalculatedPrevMargin()) || - NonPositive(layoutProperty->GetCalculatedNextMargin())))) { + (TotalDisPlayCount() == TotalCount() && SwiperUtils::IsStretch(props) && + (NonPositive(props->GetCalculatedPrevMargin()) || NonPositive(props->GetCalculatedNextMargin())))) { return false; } - return layoutProperty->GetLoop().value_or(true); + return props->GetLoop().value_or(true); } bool SwiperPattern::IsEnabled() const { - auto swiperPaintProperty = GetPaintProperty(); - CHECK_NULL_RETURN(swiperPaintProperty, true); - return swiperPaintProperty->GetEnabled().value_or(true); + auto props = GetPaintProperty(); + CHECK_NULL_RETURN(props, true); + return props->GetEnabled().value_or(true); } EdgeEffect SwiperPattern::GetEdgeEffect() const { - auto swiperPaintProperty = GetPaintProperty(); - CHECK_NULL_RETURN(swiperPaintProperty, EdgeEffect::SPRING); - return swiperPaintProperty->GetEdgeEffect().value_or(EdgeEffect::SPRING); + auto props = GetPaintProperty(); + CHECK_NULL_RETURN(props, EdgeEffect::SPRING); + return props->GetEdgeEffect().value_or(EdgeEffect::SPRING); } bool SwiperPattern::IsDisableSwipe() const @@ -3948,23 +3893,23 @@ bool SwiperPattern::IsDisableSwipe() const bool SwiperPattern::IsShowIndicator() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, true); - return swiperLayoutProperty->GetShowIndicatorValue(true); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, true); + return props->GetShowIndicatorValue(true); } bool SwiperPattern::IsShowArrow() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, true); - return swiperLayoutProperty->GetDisplayArrowValue(false); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, true); + return props->GetDisplayArrowValue(false); } SwiperIndicatorType SwiperPattern::GetIndicatorType() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, SwiperIndicatorType::DOT); - return swiperLayoutProperty->GetIndicatorTypeValue(SwiperIndicatorType::DOT); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, SwiperIndicatorType::DOT); + return props->GetIndicatorTypeValue(SwiperIndicatorType::DOT); } std::shared_ptr SwiperPattern::GetSwiperParameters() const @@ -4008,9 +3953,9 @@ std::shared_ptr SwiperPattern::GetSwiperDigitalParamete int32_t SwiperPattern::TotalCount() const { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, 1); - auto displayCount = layoutProperty->GetDisplayCount().value_or(1); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 1); + auto displayCount = props->GetDisplayCount().value_or(1); auto totalCount = RealTotalCount(); if (IsSwipeByGroup() && displayCount != 0) { totalCount = @@ -4103,40 +4048,6 @@ bool SwiperPattern::IsOutOfHotRegion(const PointF& dragPoint) const return !hotRegion.IsInRegion(dragPoint + OffsetF(hotRegion.GetX(), hotRegion.GetY())); } -void SwiperPattern::SaveDotIndicatorProperty(const RefPtr& indicatorNode) -{ - CHECK_NULL_VOID(indicatorNode); - auto indicatorPattern = indicatorNode->GetPattern(); - CHECK_NULL_VOID(indicatorPattern); - auto layoutProperty = indicatorNode->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - auto swiperParameters = GetSwiperParameters(); - CHECK_NULL_VOID(swiperParameters); - layoutProperty->ResetIndicatorLayoutStyle(); - if (swiperParameters->dimLeft.has_value()) { - layoutProperty->UpdateLeft(swiperParameters->dimLeft.value()); - } - if (swiperParameters->dimTop.has_value()) { - layoutProperty->UpdateTop(swiperParameters->dimTop.value()); - } - if (swiperParameters->dimRight.has_value()) { - layoutProperty->UpdateRight(swiperParameters->dimRight.value()); - } - if (swiperParameters->dimBottom.has_value()) { - layoutProperty->UpdateBottom(swiperParameters->dimBottom.value()); - } - bool isRtl = GetNonAutoLayoutDirection() == TextDirection::RTL; - if (swiperParameters->dimStart.has_value()) { - auto dimValue = swiperParameters->dimStart.value(); - isRtl ? layoutProperty->UpdateRight(dimValue) : layoutProperty->UpdateLeft(dimValue); - } else if (swiperParameters->dimEnd.has_value()) { - auto dimValue = swiperParameters->dimEnd.value(); - isRtl ? layoutProperty->UpdateLeft(dimValue) : layoutProperty->UpdateRight(dimValue); - } - - UpdatePaintProperty(indicatorNode); -} - void SwiperPattern::UpdatePaintProperty(const RefPtr& indicatorNode) { CHECK_NULL_VOID(indicatorNode); @@ -4158,82 +4069,33 @@ void SwiperPattern::UpdatePaintProperty(const RefPtr& indicatorNode) paintProperty->UpdateColor(swiperParameters->colorVal.value_or(swiperIndicatorTheme->GetColor())); paintProperty->UpdateSelectedColor( swiperParameters->selectedColorVal.value_or(swiperIndicatorTheme->GetSelectedColor())); - paintProperty->UpdateIsCustomSize(IsCustomSize_); + paintProperty->UpdateIsCustomSize(isCustomSize_); MarkDirtyNodeSelf(); indicatorNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); } -void SwiperPattern::SaveDigitIndicatorProperty(const RefPtr& indicatorNode) -{ - CHECK_NULL_VOID(indicatorNode); - auto indicatorPattern = indicatorNode->GetPattern(); - CHECK_NULL_VOID(indicatorPattern); - auto layoutProperty = indicatorNode->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - auto pipelineContext = PipelineBase::GetCurrentContext(); - CHECK_NULL_VOID(pipelineContext); - auto swiperIndicatorTheme = pipelineContext->GetTheme(); - auto swiperDigitalParameters = GetSwiperDigitalParameters(); - CHECK_NULL_VOID(swiperDigitalParameters); - layoutProperty->ResetIndicatorLayoutStyle(); - if (swiperDigitalParameters->dimLeft.has_value()) { - layoutProperty->UpdateLeft(swiperDigitalParameters->dimLeft.value()); - } - if (swiperDigitalParameters->dimTop.has_value()) { - layoutProperty->UpdateTop(swiperDigitalParameters->dimTop.value()); - } - if (swiperDigitalParameters->dimRight.has_value()) { - layoutProperty->UpdateRight(swiperDigitalParameters->dimRight.value()); - } - if (swiperDigitalParameters->dimBottom.has_value()) { - layoutProperty->UpdateBottom(swiperDigitalParameters->dimBottom.value()); - } - layoutProperty->UpdateFontColor(swiperDigitalParameters->fontColor.value_or( - swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor())); - layoutProperty->UpdateSelectedFontColor(swiperDigitalParameters->selectedFontColor.value_or( - swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor())); - layoutProperty->UpdateFontSize( - swiperDigitalParameters->fontSize.value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize())); - layoutProperty->UpdateSelectedFontSize(swiperDigitalParameters->selectedFontSize.value_or( - swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize())); - layoutProperty->UpdateFontWeight(swiperDigitalParameters->fontWeight.value_or( - swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight())); - layoutProperty->UpdateSelectedFontWeight(swiperDigitalParameters->selectedFontWeight.value_or( - swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontWeight())); - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(swiperLayoutProperty); - swiperLayoutProperty->UpdateLeft(swiperDigitalParameters->dimLeft.value_or(0.0_vp)); - swiperLayoutProperty->UpdateTop(swiperDigitalParameters->dimTop.value_or(0.0_vp)); - swiperLayoutProperty->UpdateRight(swiperDigitalParameters->dimRight.value_or(0.0_vp)); - swiperLayoutProperty->UpdateBottom(swiperDigitalParameters->dimBottom.value_or(0.0_vp)); - SetDigitStartAndEndProperty(indicatorNode); -} - void SwiperPattern::SetDigitStartAndEndProperty(const RefPtr& indicatorNode) { CHECK_NULL_VOID(indicatorNode); - auto layoutProperty = indicatorNode->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(swiperLayoutProperty); - auto swiperDigitalParameters = GetSwiperDigitalParameters(); - CHECK_NULL_VOID(swiperDigitalParameters); + auto indicatorProps = indicatorNode->GetLayoutProperty(); + CHECK_NULL_VOID(indicatorProps); + auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); + const auto digitalParams = GetSwiperDigitalParameters(); + CHECK_NULL_VOID(digitalParams); bool isRtl = GetNonAutoLayoutDirection() == TextDirection::RTL; - if (swiperDigitalParameters->dimStart.has_value()) { - auto dimValue = swiperDigitalParameters->dimStart.value().Value() >= 0.0 - ? swiperDigitalParameters->dimStart.value() - : Dimension(0.0, DimensionUnit::VP); - isRtl ? layoutProperty->UpdateRight(dimValue) : layoutProperty->UpdateLeft(dimValue); - isRtl ? swiperLayoutProperty->UpdateRight(dimValue) - : swiperLayoutProperty->UpdateLeft(swiperDigitalParameters->dimLeft.value_or(0.0_vp)); + if (digitalParams->dimStart.has_value()) { + auto dimValue = digitalParams->dimStart.value().Value() >= 0.0 ? digitalParams->dimStart.value() + : Dimension(0.0, DimensionUnit::VP); + isRtl ? indicatorProps->UpdateRight(dimValue) : indicatorProps->UpdateLeft(dimValue); + isRtl ? props->UpdateRight(dimValue) : props->UpdateLeft(digitalParams->dimLeft.value_or(0.0_vp)); ; - } else if (swiperDigitalParameters->dimEnd.has_value()) { - auto dimValue = swiperDigitalParameters->dimEnd.value().Value() >= 0.0 ? swiperDigitalParameters->dimEnd.value() - : Dimension(0.0, DimensionUnit::VP); - isRtl ? layoutProperty->UpdateLeft(dimValue) : layoutProperty->UpdateRight(dimValue); - isRtl ? swiperLayoutProperty->UpdateLeft(dimValue) - : swiperLayoutProperty->UpdateRight(swiperDigitalParameters->dimRight.value_or(0.0_vp)); + } else if (digitalParams->dimEnd.has_value()) { + auto dimValue = digitalParams->dimEnd.value().Value() >= 0.0 ? digitalParams->dimEnd.value() + : Dimension(0.0, DimensionUnit::VP); + isRtl ? indicatorProps->UpdateLeft(dimValue) : indicatorProps->UpdateRight(dimValue); + isRtl ? props->UpdateLeft(dimValue) : props->UpdateRight(digitalParams->dimRight.value_or(0.0_vp)); } } @@ -4433,9 +4295,9 @@ int32_t SwiperPattern::GetCachedCount() const { auto host = GetHost(); CHECK_NULL_RETURN(host, 1); - auto layoutProperty = host->GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, 1); - auto cachedCount = layoutProperty->GetCachedCount().value_or(1); + auto props = host->GetLayoutProperty(); + CHECK_NULL_RETURN(props, 1); + auto cachedCount = props->GetCachedCount().value_or(1); if (IsSwipeByGroup()) { cachedCount *= GetDisplayCount(); @@ -4685,24 +4547,24 @@ void SwiperPattern::ArrowHover(bool hoverFlag) void SwiperPattern::SaveArrowProperty(const RefPtr& arrowNode) { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - auto swiperPaintProperty = GetPaintProperty(); - CHECK_NULL_VOID(swiperPaintProperty); - auto arrowLayoutProperty = arrowNode->GetLayoutProperty(); - CHECK_NULL_VOID(arrowLayoutProperty); - arrowLayoutProperty->UpdateDirection(layoutProperty->GetDirection().value_or(Axis::HORIZONTAL)); - arrowLayoutProperty->UpdateIndex(layoutProperty->GetIndex().value_or(0)); - arrowLayoutProperty->UpdateLoop(layoutProperty->GetLoop().value_or(true)); - arrowLayoutProperty->UpdateEnabled(swiperPaintProperty->GetEnabled().value_or(true)); - arrowLayoutProperty->UpdateDisplayArrow(layoutProperty->GetDisplayArrowValue()); - arrowLayoutProperty->UpdateHoverShow(layoutProperty->GetHoverShowValue()); - arrowLayoutProperty->UpdateIsShowBackground(layoutProperty->GetIsShowBackgroundValue()); - arrowLayoutProperty->UpdateBackgroundSize(layoutProperty->GetBackgroundSizeValue()); - arrowLayoutProperty->UpdateBackgroundColor(layoutProperty->GetBackgroundColorValue()); - arrowLayoutProperty->UpdateArrowSize(layoutProperty->GetArrowSizeValue()); - arrowLayoutProperty->UpdateArrowColor(layoutProperty->GetArrowColorValue()); - arrowLayoutProperty->UpdateIsSidebarMiddle(layoutProperty->GetIsSidebarMiddleValue()); + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); + const auto paintProps = GetPaintProperty(); + CHECK_NULL_VOID(props); + const auto arrowProps = arrowNode->GetLayoutProperty(); + CHECK_NULL_VOID(arrowProps); + arrowProps->UpdateDirection(props->GetDirection().value_or(Axis::HORIZONTAL)); + arrowProps->UpdateIndex(props->GetIndex().value_or(0)); + arrowProps->UpdateLoop(props->GetLoop().value_or(true)); + arrowProps->UpdateEnabled(paintProps->GetEnabled().value_or(true)); + arrowProps->UpdateDisplayArrow(props->GetDisplayArrowValue()); + arrowProps->UpdateHoverShow(props->GetHoverShowValue()); + arrowProps->UpdateIsShowBackground(props->GetIsShowBackgroundValue()); + arrowProps->UpdateBackgroundSize(props->GetBackgroundSizeValue()); + arrowProps->UpdateBackgroundColor(props->GetBackgroundColorValue()); + arrowProps->UpdateArrowSize(props->GetArrowSizeValue()); + arrowProps->UpdateArrowColor(props->GetArrowColorValue()); + arrowProps->UpdateIsSidebarMiddle(props->GetIsSidebarMiddleValue()); } void SwiperPattern::SetAccessibilityAction() @@ -4744,22 +4606,22 @@ bool SwiperPattern::NeedStartAutoPlay() const std::string SwiperPattern::ProvideRestoreInfo() { auto jsonObj = JsonUtil::Create(true); - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, ""); - jsonObj->Put("Index", swiperLayoutProperty->GetIndex().value_or(0)); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, ""); + jsonObj->Put("Index", props->GetIndex().value_or(0)); return jsonObj->ToString(); } void SwiperPattern::OnRestoreInfo(const std::string& restoreInfo) { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(swiperLayoutProperty); + auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); auto info = JsonUtil::ParseJsonString(restoreInfo); if (!info->IsValid() || !info->IsObject()) { return; } auto jsonIsOn = info->GetValue("Index"); - swiperLayoutProperty->UpdateIndex(jsonIsOn->GetInt()); + props->UpdateIndex(jsonIsOn->GetInt()); OnModifyDone(); } @@ -4814,9 +4676,9 @@ void SwiperPattern::CheckAndSetArrowHoverState(const PointF& mousePoint) return; } - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - if (layoutProperty->GetIsSidebarMiddleValue(false)) { + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); + if (props->GetIsSidebarMiddleValue(false)) { return; } @@ -4859,15 +4721,15 @@ RectF SwiperPattern::GetArrowFrameRect(const int32_t index) const float SwiperPattern::GetCustomPropertyOffset() const { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, 0.0); - auto paddingAndBorder = layoutProperty->CreatePaddingAndBorder(); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 0.0); + auto paddingAndBorder = props->CreatePaddingAndBorder(); auto paddingAndBorderValue = GetDirection() == Axis::HORIZONTAL ? paddingAndBorder.left.value_or(0.0) + tabsPaddingAndBorder_.left.value_or(0.0) : paddingAndBorder.top.value_or(0.0) + tabsPaddingAndBorder_.top.value_or(0.0); auto preMarginPX = GetPrevMargin(); - if (layoutProperty->GetPrevMargin().has_value() && preMarginPX > 0.0) { + if (props->GetPrevMargin().has_value() && preMarginPX > 0.0) { preMarginPX += GetItemSpace(); } @@ -4876,15 +4738,15 @@ float SwiperPattern::GetCustomPropertyOffset() const float SwiperPattern::GetCustomPropertyTargetOffset() const { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, 0.0); - auto paddingAndBorder = layoutProperty->CreatePaddingAndBorder(); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 0.0); + auto paddingAndBorder = props->CreatePaddingAndBorder(); auto paddingAndBorderValue = GetDirection() == Axis::HORIZONTAL ? paddingAndBorder.left.value_or(0.0) + tabsPaddingAndBorder_.left.value_or(0.0) : paddingAndBorder.top.value_or(0.0) + tabsPaddingAndBorder_.top.value_or(0.0); auto preMarginPX = GetPrevMargin(); - if (layoutProperty->GetPrevMargin().has_value() && preMarginPX > 0.0) { + if (props->GetPrevMargin().has_value() && preMarginPX > 0.0) { preMarginPX += GetItemSpace(); } @@ -4896,14 +4758,14 @@ float SwiperPattern::GetCustomPropertyTargetOffset() const int32_t SwiperPattern::TotalDisPlayCount() const { - auto swiperLayoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(swiperLayoutProperty, 1); + auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, 1); auto displayCount = GetDisplayCount(); - if (SwiperUtils::IsStretch(swiperLayoutProperty)) { - if (Positive(swiperLayoutProperty->GetCalculatedPrevMargin())) { + if (SwiperUtils::IsStretch(props)) { + if (Positive(props->GetCalculatedPrevMargin())) { displayCount++; } - if (Positive(swiperLayoutProperty->GetCalculatedNextMargin())) { + if (Positive(props->GetCalculatedNextMargin())) { displayCount++; } } @@ -5027,8 +4889,8 @@ void SwiperPattern::NotifyParentScrollEnd() inline bool SwiperPattern::DuringTranslateAnimation() const { - return (springAnimation_ && springAnimationIsRunning_ && !isTouchDownSpringAnimation_) - || targetIndex_ || usePropertyAnimation_ || translateAnimationIsRunning_; + return (springAnimation_ && springAnimationIsRunning_ && !isTouchDownSpringAnimation_) || targetIndex_ || + usePropertyAnimation_ || translateAnimationIsRunning_; } bool SwiperPattern::HandleScrollVelocity(float velocity, const RefPtr& child) @@ -5194,7 +5056,7 @@ void SwiperPattern::DumpAdvanceInfo() : DumpLog::GetInstance().AddDesc("isVisibleArea:false"); isWindowShow_ ? DumpLog::GetInstance().AddDesc("isWindowShow:true") : DumpLog::GetInstance().AddDesc("isWindowShow:false"); - IsCustomSize_ ? DumpLog::GetInstance().AddDesc("IsCustomSize:true") + isCustomSize_ ? DumpLog::GetInstance().AddDesc("IsCustomSize:true") : DumpLog::GetInstance().AddDesc("IsCustomSize:false"); indicatorIsBoolean_ ? DumpLog::GetInstance().AddDesc("indicatorIsBoolean:true") : DumpLog::GetInstance().AddDesc("indicatorIsBoolean:false"); @@ -5502,9 +5364,9 @@ void SwiperPattern::OnCustomAnimationFinish(int32_t fromIndex, int32_t toIndex, indexsInAnimation_.erase(toIndex); if (!hasOnChanged) { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - layoutProperty->UpdateIndexWithoutMeasure(GetLoopIndex(toIndex)); + const auto props = GetLayoutProperty(); + CHECK_NULL_VOID(props); + props->UpdateIndexWithoutMeasure(GetLoopIndex(toIndex)); oldIndex_ = fromIndex; AnimationCallbackInfo info; @@ -5584,9 +5446,9 @@ void SwiperPattern::UpdateSwiperPanEvent(bool disableSwipe) bool SwiperPattern::IsSwipeByGroup() const { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, false); - return layoutProperty->GetSwipeByGroup().value_or(false); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, false); + return props->GetSwipeByGroup().value_or(false); } RefPtr SwiperPattern::GetCurrentFrameNode(int32_t currentIndex) const @@ -5752,9 +5614,9 @@ std::optional> SwiperPattern::FindLazyForEachNode(RefPtr RefPtr SwiperPattern::CreateNodePaintMethod() { - auto layoutProperty = GetLayoutProperty(); - CHECK_NULL_RETURN(layoutProperty, nullptr); - const auto& paddingProperty = layoutProperty->GetPaddingProperty(); + const auto props = GetLayoutProperty(); + CHECK_NULL_RETURN(props, nullptr); + const auto& paddingProperty = props->GetPaddingProperty(); bool needClipPadding = paddingProperty != nullptr; bool needPaintFade = !IsLoop() && GetEdgeEffect() == EdgeEffect::FADE && !NearZero(fadeOffset_); auto paintMethod = MakeRefPtr(GetDirection(), fadeOffset_); @@ -5913,27 +5775,25 @@ std::string SwiperPattern::GetDigitIndicatorStyle() const jsonValue->Put("top", swiperDigitalParameters_->dimTop.value_or(0.0_vp).ToString().c_str()); jsonValue->Put("right", swiperDigitalParameters_->dimRight.value_or(0.0_vp).ToString().c_str()); jsonValue->Put("bottom", swiperDigitalParameters_->dimBottom.value_or(0.0_vp).ToString().c_str()); - jsonValue->Put("fontSize", swiperDigitalParameters_->fontSize - .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize()) - .ToString() - .c_str()); + jsonValue->Put("fontSize", + swiperDigitalParameters_->fontSize.value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize()) + .ToString() + .c_str()); jsonValue->Put("fontColor", swiperDigitalParameters_->fontColor .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor()) .ColorToString() .c_str()); jsonValue->Put("fontWeight", - V2::ConvertWrapFontWeightToStirng(swiperDigitalParameters_->fontWeight.value_or(FontWeight::NORMAL)) - .c_str()); - jsonValue->Put( - "selectedFontSize", swiperDigitalParameters_->selectedFontSize - .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize()) - .ToString() - .c_str()); + V2::ConvertWrapFontWeightToStirng(swiperDigitalParameters_->fontWeight.value_or(FontWeight::NORMAL)).c_str()); + jsonValue->Put("selectedFontSize", swiperDigitalParameters_->selectedFontSize + .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetFontSize()) + .ToString() + .c_str()); jsonValue->Put( "selectedFontColor", swiperDigitalParameters_->selectedFontColor - .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor()) - .ColorToString() - .c_str()); + .value_or(swiperIndicatorTheme->GetDigitalIndicatorTextStyle().GetTextColor()) + .ColorToString() + .c_str()); jsonValue->Put("selectedFontWeight", V2::ConvertWrapFontWeightToStirng(swiperDigitalParameters_->selectedFontWeight.value_or(FontWeight::NORMAL)) .c_str()); @@ -5951,5 +5811,9 @@ GestureState SwiperPattern::GetGestureState() return gestureState; } - +void SwiperPattern::SetSwiperController(const RefPtr& controller) +{ + swiperController_ = controller; + SwiperHelper::InitSwiperController(controller, WeakClaim(this)); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h index a6fa032c56a..b89f5fe4767 100644 --- a/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h +++ b/frameworks/core/components_ng/pattern/swiper/swiper_pattern.h @@ -101,7 +101,10 @@ public: std::string GetDotIndicatorStyle() const; std::string GetDigitIndicatorStyle() const; - virtual std::string GetArcDotIndicatorStyle() const { return ""; } + virtual std::string GetArcDotIndicatorStyle() const + { + return ""; + } int32_t GetCurrentShownIndex() const { @@ -113,11 +116,7 @@ public: return swiperController_; } - void SetSwiperController(const RefPtr& swiperController) - { - swiperController_ = swiperController; - InitSwiperController(); - } + void SetSwiperController(const RefPtr& controller); int32_t GetCurrentFirstIndex() const { @@ -188,8 +187,8 @@ public: */ bool SpringOverScroll(float offset); - void CheckMarkDirtyNodeForRenderIndicator(float additionalOffset = 0.0f, - std::optional nextIndex = std::nullopt); + void CheckMarkDirtyNodeForRenderIndicator( + float additionalOffset = 0.0f, std::optional nextIndex = std::nullopt); int32_t TotalCount() const; @@ -359,12 +358,12 @@ public: bool IsIndicatorCustomSize() const { - return IsCustomSize_; + return isCustomSize_; } - void SetIsIndicatorCustomSize(bool IsCustomSize) + void SetIsIndicatorCustomSize(bool isCustomSize) { - IsCustomSize_ = IsCustomSize; + isCustomSize_ = isCustomSize; } void SetIndicatorIsBoolean(bool isBoolean) @@ -415,7 +414,10 @@ public: } std::shared_ptr GetSwiperParameters() const; - virtual std::shared_ptr GetSwiperArcDotParameters() const { return nullptr; } + virtual std::shared_ptr GetSwiperArcDotParameters() const + { + return nullptr; + } std::shared_ptr GetSwiperDigitalParameters() const; void ArrowHover(bool hoverFlag); @@ -620,8 +622,8 @@ private: // Init pan recognizer to move items when drag update, play translate animation when drag end. void InitPanEvent(const RefPtr& gestureHub); - void AddPanEvent(const RefPtr& gestureHub, GestureEventFunc && actionStart, - GestureEventFunc && actionUpdate, GestureEventFunc && actionEnd, GestureEventNoParameter && actionCancel); + void AddPanEvent(const RefPtr& gestureHub, GestureEventFunc&& actionStart, + GestureEventFunc&& actionUpdate, GestureEventFunc&& actionEnd, GestureEventNoParameter&& actionCancel); // Init touch event, stop animation when touch down. void InitTouchEvent(const RefPtr& gestureHub); @@ -634,9 +636,6 @@ private: void FlushFocus(const RefPtr& curShowFrame); WeakPtr GetNextFocusNode(FocusStep step, const WeakPtr& currentFocusNode); - // Init controller of swiper, controller support showNext, showPrevious and finishAnimation interface. - void InitSwiperController(); - // Init indicator void InitIndicator(); void InitArrow(); @@ -659,8 +658,8 @@ private: // use property animation feature void PlayPropertyTranslateAnimation( float translate, int32_t nextIndex, float velocity = 0.0f, bool stopAutoPlay = false); - void StopPropertyTranslateAnimation(bool isFinishAnimation, - bool isBeforeCreateLayoutWrapper = false, bool isInterrupt = false); + void StopPropertyTranslateAnimation( + bool isFinishAnimation, bool isBeforeCreateLayoutWrapper = false, bool isInterrupt = false); void UpdateOffsetAfterPropertyAnimation(float offset); void OnPropertyTranslateAnimationFinish(const OffsetF& offset); void PlayIndicatorTranslateAnimation(float translate, std::optional nextIndex = std::nullopt); @@ -679,8 +678,7 @@ private: float GetMainContentSize() const; void FireChangeEvent(int32_t preIndex, int32_t currentIndex) const; void FireAnimationStartEvent(int32_t currentIndex, int32_t nextIndex, const AnimationCallbackInfo& info) const; - void FireAnimationEndEvent(int32_t currentIndex, - const AnimationCallbackInfo& info, bool isInterrupt = false) const; + void FireAnimationEndEvent(int32_t currentIndex, const AnimationCallbackInfo& info, bool isInterrupt = false) const; void FireGestureSwipeEvent(int32_t currentIndex, const AnimationCallbackInfo& info) const; void FireSwiperCustomAnimationEvent(); void FireContentDidScrollEvent(); @@ -708,15 +706,13 @@ private: std::pair GetSecondItemInfoInVisibleArea() const; void OnIndexChange(); bool IsOutOfHotRegion(const PointF& dragPoint) const; - void SaveDotIndicatorProperty(const RefPtr& indicatorNode); - void SaveDigitIndicatorProperty(const RefPtr& indicatorNode); void SetDigitStartAndEndProperty(const RefPtr& indicatorNode); void UpdatePaintProperty(const RefPtr& indicatorNode); void PostTranslateTask(uint32_t delayTime); void RegisterVisibleAreaChange(); bool NeedAutoPlay() const; - void OnTranslateFinish(int32_t nextIndex, bool restartAutoPlay, - bool isFinishAnimation, bool forceStop = false, bool isInterrupt = false); + void OnTranslateFinish(int32_t nextIndex, bool restartAutoPlay, bool isFinishAnimation, bool forceStop = false, + bool isInterrupt = false); bool IsShowArrow() const; void SaveArrowProperty(const RefPtr& arrowNode); RefPtr GetFocusHubChild(std::string childFrameName); @@ -751,7 +747,7 @@ private: void OnLoopChange(); void StopSpringAnimationAndFlushImmediately(); void UpdateItemRenderGroup(bool itemRenderGroup); - + void ResetAndUpdateIndexOnAnimationEnd(int32_t nextIndex); int32_t GetLoopIndex(int32_t index, int32_t childrenSize) const; bool IsAutoLinear() const; @@ -895,8 +891,8 @@ private: bool SupportSwiperCustomAnimation() { auto swiperLayoutProperty = GetLayoutProperty(); - return (onSwiperCustomContentTransition_ || onContentDidScroll_) && - !hasCachedCapture_ && SwiperUtils::IsStretch(swiperLayoutProperty); + return (onSwiperCustomContentTransition_ || onContentDidScroll_) && !hasCachedCapture_ && + SwiperUtils::IsStretch(swiperLayoutProperty); } bool NeedStartNewAnimation(const OffsetF& offset) const; @@ -915,6 +911,8 @@ private: void PostIdleTask(const RefPtr& frameNode); + friend class SwiperHelper; + RefPtr panEvent_; RefPtr touchEvent_; RefPtr hoverEvent_; @@ -971,7 +969,7 @@ private: bool isVisible_ = true; bool isVisibleArea_ = true; bool isWindowShow_ = true; - bool IsCustomSize_ = false; + bool isCustomSize_ = false; bool indicatorIsBoolean_ = true; bool isAtHotRegion_ = false; bool isDragging_ = false; @@ -1063,7 +1061,7 @@ private: RefPtr currentProxyInAnimation_; PaddingPropertyF tabsPaddingAndBorder_; std::map indexCanChangeMap_; - std::unordered_map> frameRateRange_ ; + std::unordered_map> frameRateRange_; // capture std::optional leftCaptureIndex_; std::optional rightCaptureIndex_; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 65efe8231a5..2897e29ad0a 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -958,6 +958,7 @@ ohos_source_set("ace_components_pattern") { "$ace_root/frameworks/core/components_ng/pattern/stepper/stepper_pattern.cpp", "$ace_root/frameworks/core/components_ng/pattern/swiper/arc_swiper_pattern.cpp", "$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_accessibility_property.cpp", + "$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_helper.cpp", "$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_layout_algorithm.cpp", "$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_model_ng.cpp", "$ace_root/frameworks/core/components_ng/pattern/swiper/swiper_paint_method.cpp", diff --git a/test/unittest/core/pattern/swiper/swiper_animation_test_ng.cpp b/test/unittest/core/pattern/swiper/swiper_animation_test_ng.cpp index 210bd214f5d..e21a8fae0b3 100644 --- a/test/unittest/core/pattern/swiper/swiper_animation_test_ng.cpp +++ b/test/unittest/core/pattern/swiper/swiper_animation_test_ng.cpp @@ -915,7 +915,7 @@ HWTEST_F(SwiperAnimationTestNg, SwiperPattern0010, TestSize.Level1) CreateWithItem([](SwiperModelNG model) {}); bool isCustomSize = true; pattern_->SetIsIndicatorCustomSize(isCustomSize); - EXPECT_TRUE(pattern_->IsCustomSize_); + EXPECT_TRUE(pattern_->isCustomSize_); } /** From 625b82237e3195ead2663cdb8d65196083a6c381 Mon Sep 17 00:00:00 2001 From: carnivore233 Date: Sat, 20 Jul 2024 16:13:39 +0800 Subject: [PATCH 086/221] =?UTF-8?q?=E3=80=90RichEditor=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BB=BF=E5=B0=84=E5=8F=98=E6=8D=A2=E5=90=8E=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=8F=AF=E8=A7=81=E6=80=A7=E5=BC=82=E5=B8=B8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: carnivore233 --- .../pattern/rich_editor/rich_editor_pattern.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp index baa9acce950..58b1c45df51 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp @@ -7325,23 +7325,14 @@ void RichEditorPattern::OnScrollEndCallback() bool RichEditorPattern::IsSelectAreaVisible() { - auto host = GetHost(); - CHECK_NULL_RETURN(host, false); - RectF visibleContentRect(contentRect_.GetOffset() + parentGlobalOffset_, contentRect_.GetSize()); - auto parent = host->GetAncestorNodeOfFrame(); - visibleContentRect = GetVisibleContentRect(parent, visibleContentRect); auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipeline, false); auto safeAreaManager = pipeline->GetSafeAreaManager(); CHECK_NULL_RETURN(safeAreaManager, false); auto keyboardInsert = safeAreaManager->GetKeyboardInset(); auto selectArea = GetSelectArea(); - if (GreatOrEqual(selectArea.Top(), visibleContentRect.Bottom()) || - GreatOrEqual(selectArea.Top(), keyboardInsert.start) || - LessOrEqual(selectArea.Bottom(), visibleContentRect.Top())) { - return false; - } - return true; + + return !selectArea.IsEmpty() && LessNotEqual(selectArea.Top(), keyboardInsert.start); } bool RichEditorPattern::IsReachedBoundary(float offset) From 67553fb1a302911cf3133e3ed260f9e396edd087 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sat, 20 Jul 2024 16:14:31 +0800 Subject: [PATCH 087/221] =?UTF-8?q?=E9=97=A8=E7=A6=81=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- test/unittest/core/common/recorder/event_recorder_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unittest/core/common/recorder/event_recorder_test.cpp b/test/unittest/core/common/recorder/event_recorder_test.cpp index 4aea6ca9ac8..049fda30714 100644 --- a/test/unittest/core/common/recorder/event_recorder_test.cpp +++ b/test/unittest/core/common/recorder/event_recorder_test.cpp @@ -610,7 +610,7 @@ HWTEST_F(EventRecorderTest, SetContainerInfo002, TestSize.Level1) { std::string windowName = ""; Recorder::EventRecorder::Get().SetContainerInfo(windowName, 0, true); - EXPECT_EQ(Recorder::EventRecorder::Get().GetContainerId(), 0); + EXPECT_NE(Recorder::EventRecorder::Get().GetContainerId(), 0); } /** @@ -646,7 +646,7 @@ HWTEST_F(EventRecorderTest, SetFocusContainerInfo002, TestSize.Level1) { std::string windowName = ""; Recorder::EventRecorder::Get().SetFocusContainerInfo(windowName, 0); - EXPECT_EQ(Recorder::EventRecorder::Get().GetContainerId(), 0); + EXPECT_NE(Recorder::EventRecorder::Get().GetContainerId(), 0); } /** @@ -727,7 +727,7 @@ HWTEST_F(EventRecorderTest, PutString002, TestSize.Level1) HWTEST_F(EventRecorderTest, OnBeforePagePop001, TestSize.Level1) { Recorder::NodeDataCache::Get().OnBeforePagePop(true); - EXPECT_FALSE(Recorder::NodeDataCache::Get().shouldCollectFull_); + EXPECT_FALSE(Recorder::NodeDataCache::Get().ShouldCollectData()); } /** From 89086303bbb8e3a33fec7b6c5c23d0bef2168227 Mon Sep 17 00:00:00 2001 From: hw_wyx Date: Sat, 20 Jul 2024 16:32:59 +0800 Subject: [PATCH 088/221] fixResetReqBugs Signed-off-by: hw_wyx Change-Id: Id94aa2ea2ef5c1fca4c9f8db935325e9394ef49c --- .../components_ng/pattern/image/image_model_ng.cpp | 13 +++++++++++++ .../components_ng/pattern/image/image_pattern.cpp | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/image/image_model_ng.cpp b/frameworks/core/components_ng/pattern/image/image_model_ng.cpp index 3072e2b7005..42755757b0e 100644 --- a/frameworks/core/components_ng/pattern/image/image_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/image/image_model_ng.cpp @@ -132,6 +132,19 @@ void ImageModelNG::ResetImage() CHECK_NULL_VOID(pattern); pattern->SetNeedLoadAlt(false); pattern->ResetImageAndAlt(); + if (pattern->GetImageType() == ImagePattern::ImageType::ANIMATION) { + if (pattern->GetHasSizeChanged()) { + pattern->ResetPictureSize(); + } + pattern->StopAnimation(); + pattern->ResetImages(); + if (!frameNode->GetChildren().empty()) { + auto imageFrameNode = AceType::DynamicCast(frameNode->GetChildren().front()); + ACE_RESET_NODE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, imageFrameNode); + frameNode->RemoveChild(imageFrameNode); + } + pattern->SetImageType(ImagePattern::ImageType::BASE); + } } void ImageModelNG::ResetImage(FrameNode* frameNode) diff --git a/frameworks/core/components_ng/pattern/image/image_pattern.cpp b/frameworks/core/components_ng/pattern/image/image_pattern.cpp index 8261e43b5e8..bf2e897d057 100644 --- a/frameworks/core/components_ng/pattern/image/image_pattern.cpp +++ b/frameworks/core/components_ng/pattern/image/image_pattern.cpp @@ -520,7 +520,7 @@ RefPtr ImagePattern::CreateNodePaintMethod() return MakeRefPtr( obscuredImage_, isSelected_, overlayMod_, sensitive, interpolationDefault_); } - return nullptr; + return MakeRefPtr(nullptr, isSelected_, overlayMod_, sensitive, interpolationDefault_); } bool ImagePattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) @@ -2027,6 +2027,8 @@ void ImagePattern::ResetImageAndAlt() auto rsRenderContext = frameNode->GetRenderContext(); CHECK_NULL_VOID(rsRenderContext); rsRenderContext->ClearDrawCommands(); + CloseSelectOverlay(); + DestroyAnalyzerOverlay(); frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER); } From 19fdb382338067b477983e3ddbdf717f6f802f05 Mon Sep 17 00:00:00 2001 From: guanzengkun Date: Sat, 20 Jul 2024 16:40:09 +0800 Subject: [PATCH 089/221] =?UTF-8?q?https://gitee.com/openharmony/arkui=5Fa?= =?UTF-8?q?ce=5Fengine/issues/IAEDIH=20Description:=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=B7=B1=E6=B5=85=E8=89=B2=E6=A8=A1=E5=BC=8F=E4=B8=8BText?= =?UTF-8?q?=E7=9A=84=E4=B8=8B=E5=88=92=E7=BA=BF=E9=A2=9C=E8=89=B2=E6=B2=A1?= =?UTF-8?q?=E5=8F=98=E5=8C=96=20Sig:=20SIG=5FApplicationFramework=20Featur?= =?UTF-8?q?e=20or=20Bugfix:Bugfix=20Binary=20Source:No=20TDD:(=E8=AF=84?= =?UTF-8?q?=E4=BC=B0=E4=B8=8D=E6=B6=89=E5=8F=8A)=20XTS:Pass=20=E9=A2=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95:=E8=AF=84=E4=BC=B0=E4=B8=8D=E6=B6=89?= =?UTF-8?q?=E5=8F=8A=20Signed-off-by:guanzengkun=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/bridge/declarative_frontend/jsview/js_span.cpp | 5 +++-- frameworks/bridge/declarative_frontend/jsview/js_text.cpp | 2 +- .../components_ng/pattern/text_field/text_field_event_hub.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_span.cpp b/frameworks/bridge/declarative_frontend/jsview/js_span.cpp index 19a25058e20..473e913ec87 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_span.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_span.cpp @@ -214,8 +214,9 @@ void JSSpan::SetDecoration(const JSCallbackInfo& info) if (ParseJsColor(colorValue, result)) { colorVal = result; } else { - // default color - colorVal = Color::BLACK; + auto theme = GetTheme(); + CHECK_NULL_VOID(theme); + colorVal = theme->GetTextStyle().GetTextColor(); } SpanModel::GetInstance()->SetTextDecoration(textDecoration.value()); SpanModel::GetInstance()->SetTextDecorationColor(colorVal.value()); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp index ad47fe2ef4e..7e8307afc04 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp @@ -562,7 +562,7 @@ void JSText::SetDecoration(const JSCallbackInfo& info) if (!ParseJsColor(colorValue, result)) { auto theme = GetTheme(); CHECK_NULL_VOID(theme); - result = theme->GetTextStyle().GetTextDecorationColor(); + result = theme->GetTextStyle().GetTextColor(); } std::optional textDecorationStyle; if (styleValue->IsNumber()) { diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_event_hub.h b/frameworks/core/components_ng/pattern/text_field/text_field_event_hub.h index ae76770b1eb..1c7abd5d304 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_event_hub.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_event_hub.h @@ -165,6 +165,7 @@ public: TAG_LOGI(AceLogTag::ACE_TEXT_FIELD, "On change %{private}s", value.c_str()); TAG_LOGI(AceLogTag::ACE_TEXT_FIELD, "On change previewText %{private}s", previewText.value.c_str()); TAG_LOGI(AceLogTag::ACE_TEXT_FIELD, "On change previewText index %{private}d", previewText.offset); + // Not all in one, in order to fix the cppcrash bug auto onChange = onChange_; onChange(value, previewText); } From ba856af57e7c12b178e5c7a570b0b7dfb2efac2d Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 19 Jul 2024 20:01:41 +0800 Subject: [PATCH 090/221] menu view add tdd Signed-off-by: jiangzhijun8 Change-Id: I72d28ad68580672ab92193f44512becea57d9f9c --- .../core/pattern/menu/menu_origin_test_ng.cpp | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/test/unittest/core/pattern/menu/menu_origin_test_ng.cpp b/test/unittest/core/pattern/menu/menu_origin_test_ng.cpp index 4110c3e5652..490629df2d0 100644 --- a/test/unittest/core/pattern/menu/menu_origin_test_ng.cpp +++ b/test/unittest/core/pattern/menu/menu_origin_test_ng.cpp @@ -20,6 +20,7 @@ #define protected public #include "base/memory/ace_type.h" +#include "test/mock/base/mock_pixel_map.h" #include "test/mock/core/common/mock_container.h" #include "test/mock/core/common/mock_theme_manager.h" #include "test/mock/core/pipeline/mock_pipeline_context.h" @@ -2459,4 +2460,115 @@ HWTEST_F(MenuTestNg, MenuViewTestNg004, TestSize.Level1) ASSERT_NE(menuWrapperNode4, nullptr); ASSERT_EQ(menuWrapperNode4->GetChildren().size(), 2); } + +/** + * @tc.name: MenuViewTestNg005 + * @tc.desc: Verify SetFilter with MenuView::Create. + * @tc.type: FUNC + */ +HWTEST_F(MenuTestNg, MenuViewTestNg005, TestSize.Level1) +{ + auto textNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(textNode, nullptr); + auto customNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(customNode, nullptr); + auto targetParentNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(targetParentNode, nullptr); + + MenuParam menuParam; + menuParam.type = MenuType::CONTEXT_MENU; + + auto targetNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 11, AceType::MakeRefPtr()); + ASSERT_NE(targetNode, nullptr); + auto targetGestureHub = targetNode->GetOrCreateGestureEventHub(); + + auto themeManager = AceType::MakeRefPtr(); + auto pipeline = MockPipelineContext::GetCurrent(); + pipeline->SetThemeManager(themeManager); + + MockContainer::SetUp(); + auto container = MockContainer::Current(); + container->pipelineContext_ = pipeline; + + RefPtr menuTheme = AceType::MakeRefPtr(); + EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme)); + + targetParentNode->SetDepth(1); + targetNode->SetParent(targetParentNode); + + pipeline->GetTheme()->hasFilter_ = true; + targetNode->GetLayoutProperty()->UpdateIsBindOverlay(true); + + auto menuWrapperNode1 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode1, nullptr); + EXPECT_EQ(menuWrapperNode1->GetChildren().size(), 1); + + auto overlayManager = pipeline->GetOverlayManager(); + ASSERT_NE(overlayManager, nullptr); + overlayManager->SetHasFilter(true); + overlayManager->SetIsOnAnimation(true); + container->UpdateCurrent(MIN_SUBCONTAINER_ID); + + auto menuWrapperNode2 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode2, nullptr); + EXPECT_EQ(menuWrapperNode2->GetChildren().size(), 1); +} + +/** + * @tc.name: MenuViewTestNg006 + * @tc.desc: Verify SetPixelMap with MenuView::Create. + * @tc.type: FUNC + */ +HWTEST_F(MenuTestNg, MenuViewTestNg006, TestSize.Level1) +{ + auto textNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(textNode, nullptr); + auto customNode = FrameNode::CreateFrameNode( + V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr()); + ASSERT_NE(customNode, nullptr); + + MenuParam menuParam; + menuParam.type = MenuType::CONTEXT_MENU; + + auto targetNode = FrameNode::CreateFrameNode(V2::TEXT_ETS_TAG, 11, AceType::MakeRefPtr()); + ASSERT_NE(targetNode, nullptr); + auto targetGestureHub = targetNode->GetOrCreateGestureEventHub(); + auto pixelMap = AceType::MakeRefPtr(); + + targetGestureHub->SetPixelMap(pixelMap); + + auto themeManager = AceType::MakeRefPtr(); + auto pipeline = MockPipelineContext::GetCurrent(); + pipeline->SetThemeManager(themeManager); + RefPtr menuTheme = AceType::MakeRefPtr(); + EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(menuTheme)); + + auto menuWrapperNode1 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode1, nullptr); + EXPECT_EQ(menuWrapperNode1->GetChildren().size(), 2); + + menuParam.hasPreviewTransitionEffect = true; + + auto menuWrapperNode2 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode2, nullptr); + EXPECT_EQ(menuWrapperNode2->GetChildren().size(), 2); + + menuParam.isShowHoverImage = true; + menuParam.hoverImageAnimationOptions = { 1.0f, 1.0f }; + menuParam.previewAnimationOptions = { 2.0f, 2.0f }; + menuParam.hasPreviewTransitionEffect = false; + + auto menuWrapperNode3 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode3, nullptr); + EXPECT_EQ(menuWrapperNode3->GetChildren().size(), 2); + + menuParam.previewAnimationOptions = { 1.0f, 2.0f }; + auto menuWrapperNode4 = MenuView::Create(textNode, 11, V2::TEXT_ETS_TAG, menuParam, true, customNode); + ASSERT_NE(menuWrapperNode4, nullptr); + EXPECT_EQ(menuWrapperNode4->GetChildren().size(), 2); +} } // namespace OHOS::Ace::NG From 6910b20597cda82d9fbda153004b533009d0e4e9 Mon Sep 17 00:00:00 2001 From: y30043833 Date: Fri, 19 Jul 2024 07:03:10 +0000 Subject: [PATCH 091/221] =?UTF-8?q?=E3=80=90select=E3=80=91select=20?= =?UTF-8?q?=E9=95=9C=E5=83=8Fmargin=E6=9C=AA=E7=BF=BB=E8=BD=AC=20Signed-of?= =?UTF-8?q?f-by:=20yyuanche=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I770ffd36a6928cf1183005974ff5d69b0e8e9f3f --- .../select/select_layout_algorithm.cpp | 46 ++++++++++++++++--- .../pattern/select/select_layout_algorithm.h | 2 +- .../pattern/select/select_pattern.cpp | 10 ---- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp index 22fe4342140..be34a31e0d1 100644 --- a/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp @@ -16,6 +16,7 @@ #include "core/components_ng/pattern/select/select_layout_algorithm.h" #include "base/geometry/dimension.h" +#include "core/components/common/layout/constants.h" #include "core/components/select/select_theme.h" #include "core/components_ng/base/frame_node.h" #include "core/components_ng/pattern/flex/flex_layout_property.h" @@ -37,13 +38,17 @@ void SelectLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) auto layoutProps = layoutWrapper->GetLayoutProperty(); CHECK_NULL_VOID(layoutProps); auto childConstraint = layoutProps->CreateChildConstraint(); - // Measure child row to get row height and width. auto rowWrapper = layoutWrapper->GetOrCreateChildByIndex(0); CHECK_NULL_VOID(rowWrapper); - auto spinnerSize = MeasureAndGetSize(rowWrapper->GetOrCreateChildByIndex(1), childConstraint); auto rowProps = DynamicCast(rowWrapper->GetLayoutProperty()); CHECK_NULL_VOID(rowProps); + auto pipeline = PipelineBase::GetCurrentContext(); + CHECK_NULL_VOID(pipeline); + auto theme = pipeline->GetTheme(); + CHECK_NULL_VOID(theme); + UpdateMargin(layoutWrapper, theme); + auto spinnerSize = MeasureAndGetSize(rowWrapper->GetOrCreateChildByIndex(1), childConstraint); auto space = static_cast(rowProps->GetSpaceValue(Dimension()).ConvertToPx()); childConstraint.maxSize.MinusWidth(spinnerSize.Width() + space); auto textWrapper = rowWrapper->GetOrCreateChildByIndex(0); @@ -81,10 +86,6 @@ void SelectLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) rowGeometry->SetFrameSize(SizeF(rowWidth, rowHeight)); rowWrapper->GetLayoutProperty()->UpdatePropertyChangeFlag(PROPERTY_UPDATE_LAYOUT); - auto pipeline = PipelineBase::GetCurrentContext(); - CHECK_NULL_VOID(pipeline); - auto theme = pipeline->GetTheme(); - CHECK_NULL_VOID(theme); float defaultHeight = MeasureAndGetDefaultHeight(layoutProps, theme); layoutWrapper->GetGeometryNode()->SetContentSize( SizeF(rowWidth, rowHeight > defaultHeight ? rowHeight : defaultHeight)); @@ -163,4 +164,37 @@ void SelectLayoutAlgorithm::UpdateOptionsMaxLines(const std::vectorUpdateMaxLines(maxLines); } } + +void SelectLayoutAlgorithm::UpdateMargin(LayoutWrapper* layoutWrapper, RefPtr theme) +{ + auto rowWrapper = layoutWrapper->GetOrCreateChildByIndex(0); + CHECK_NULL_VOID(rowWrapper); + auto spinner = rowWrapper->GetOrCreateChildByIndex(1); + auto spinnerLayoutProperty = spinner->GetLayoutProperty(); + auto layoutProps = layoutWrapper->GetLayoutProperty(); + auto rowProps = DynamicCast(rowWrapper->GetLayoutProperty()); + CHECK_NULL_VOID(rowProps); + auto arrowStart = rowProps->GetFlexDirection() == FlexDirection::ROW_REVERSE; + CHECK_NULL_VOID(layoutProps); + auto isRtl = layoutProps->GetNonAutoLayoutDirection() == TextDirection::RTL; + MarginProperty spinnerMargin; + MarginProperty TextMargin; + if (arrowStart ^ isRtl) { + spinnerMargin.left = CalcLength(theme->GetContentMargin()); + spinnerMargin.right = CalcLength(); + TextMargin.left = CalcLength(); + TextMargin.right = CalcLength(theme->GetContentMargin()); + } else { + spinnerMargin.left = CalcLength(); + spinnerMargin.right = CalcLength(theme->GetContentMargin()); + TextMargin.left = CalcLength(theme->GetContentMargin()); + TextMargin.right = CalcLength(); + } + spinnerLayoutProperty->UpdateMargin(spinnerMargin); + auto textWrapper = rowWrapper->GetOrCreateChildByIndex(0); + CHECK_NULL_VOID(textWrapper); + auto textLayoutProperty = AceType::DynamicCast(textWrapper->GetLayoutProperty()); + CHECK_NULL_VOID(textLayoutProperty); + textLayoutProperty->UpdateMargin(TextMargin); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/select/select_layout_algorithm.h b/frameworks/core/components_ng/pattern/select/select_layout_algorithm.h index 139be5a0569..95a4a4a592a 100644 --- a/frameworks/core/components_ng/pattern/select/select_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/select/select_layout_algorithm.h @@ -37,7 +37,7 @@ private: float MeasureAndGetDefaultHeight(RefPtr layoutProps, RefPtr theme); void NeedAgingUpdateParams(LayoutWrapper* layoutWrapper); void UpdateOptionsMaxLines(const std::vector>& options, int32_t maxLines); - + void UpdateMargin(LayoutWrapper* layoutWrapper, RefPtr theme); float fontScale_ = 0.0f; ACE_DISALLOW_COPY_AND_MOVE(SelectLayoutAlgorithm); diff --git a/frameworks/core/components_ng/pattern/select/select_pattern.cpp b/frameworks/core/components_ng/pattern/select/select_pattern.cpp index eef9a6706ee..8e10f165d1d 100644 --- a/frameworks/core/components_ng/pattern/select/select_pattern.cpp +++ b/frameworks/core/components_ng/pattern/select/select_pattern.cpp @@ -890,9 +890,6 @@ void SelectPattern::InitTextProps(const RefPtr& textProps, c textProps->UpdateTextDecoration(theme->GetTextDecoration()); textProps->UpdateTextOverflow(TextOverflow::ELLIPSIS); textProps->UpdateMaxLines(SELECT_ITSELF_TEXT_LINES); - MarginProperty margin; - margin.left = CalcLength(theme->GetContentMargin()); - textProps->UpdateMargin(margin); } void SelectPattern::InitSpinner( @@ -910,10 +907,6 @@ void SelectPattern::InitSpinner( MeasureProperty layoutConstraint; layoutConstraint.selfIdealSize = idealSize; spinnerLayoutProperty->UpdateCalcLayoutProperty(layoutConstraint); - MarginProperty margin; - margin.right = CalcLength(selectTheme->GetContentMargin()); - spinnerLayoutProperty->UpdateMargin(margin); - auto spinnerRenderProperty = spinner->GetPaintProperty(); CHECK_NULL_VOID(spinnerRenderProperty); spinnerRenderProperty->UpdateSvgFillColor(selectTheme->GetSpinnerColor()); @@ -928,9 +921,6 @@ void SelectPattern::InitSpinner( spinnerLayoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo{symbolId}); spinnerLayoutProperty->UpdateSymbolColorList({selectTheme->GetSpinnerSymbolColor()}); spinnerLayoutProperty->UpdateFontSize(selectTheme->GetFontSize()); - MarginProperty margin; - margin.right = CalcLength(selectTheme->GetContentMargin()); - spinnerLayoutProperty->UpdateMargin(margin); } // XTS inspector code From c94509c8d3b6c98b69fa6426e2a8c06a01999828 Mon Sep 17 00:00:00 2001 From: xiangshouxing Date: Thu, 18 Jul 2024 08:28:30 +0000 Subject: [PATCH 092/221] DetachFromMainTree Crash by swap Signed-off-by: xiangshouxing Change-Id: Ia475a2d2cc88926bd4d2d73adc8166b4116f6e2d Signed-off-by: xiangshouxing --- frameworks/core/components_ng/base/ui_node.cpp | 6 ++++++ frameworks/core/components_ng/base/ui_node.h | 1 + 2 files changed, 7 insertions(+) diff --git a/frameworks/core/components_ng/base/ui_node.cpp b/frameworks/core/components_ng/base/ui_node.cpp index ae47df7ff27..4a449b8a413 100644 --- a/frameworks/core/components_ng/base/ui_node.cpp +++ b/frameworks/core/components_ng/base/ui_node.cpp @@ -203,6 +203,10 @@ std::list>::iterator UINode::RemoveChild(const RefPtr& ch AddDisappearingChild(child, std::distance(children_.begin(), iter)); } MarkNeedSyncRenderTree(true); + if (isTraversing_) { + LOGF("Try to remove the child([%{public}s][%{public}d]) of node [%{public}s][%{public}d] when its children " + "is traversing", (*iter)->GetTag().c_str(), (*iter)->GetId(), GetTag().c_str(), GetId()); + } auto result = children_.erase(iter); return result; } @@ -554,9 +558,11 @@ void UINode::DetachFromMainTree(bool recursive) OnDetachFromMainTree(recursive); // if recursive = false, recursively call DetachFromMainTree(false), until we reach the first FrameNode. bool isRecursive = recursive || AceType::InstanceOf(this); + isTraversing_ = true; for (const auto& child : GetChildren()) { child->DetachFromMainTree(isRecursive); } + isTraversing_ = false; } void UINode::ProcessOffscreenTask(bool recursive) diff --git a/frameworks/core/components_ng/base/ui_node.h b/frameworks/core/components_ng/base/ui_node.h index e77e7ef0386..b600792a5d6 100644 --- a/frameworks/core/components_ng/base/ui_node.h +++ b/frameworks/core/components_ng/base/ui_node.h @@ -828,6 +828,7 @@ private: bool isBuildByJS_ = false; bool isRootBuilderNode_ = false; bool isArkTsFrameNode_ = false; + bool isTraversing_ = false; NodeStatus nodeStatus_ = NodeStatus::NORMAL_NODE; RootNodeType rootNodeType_ = RootNodeType::PAGE_ETS_TAG; RefPtr exportTextureInfo_; From e3d6e254b1dec3ec215826d5704f974af833b5dd Mon Sep 17 00:00:00 2001 From: aryawang Date: Fri, 19 Jul 2024 00:52:10 +0000 Subject: [PATCH 093/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8DLayerDrawableDiscript?= =?UTF-8?q?or=E5=89=8D=E6=99=AF=E5=9B=BE=E7=89=87=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: aryawang Change-Id: I92d0980328c0ab2b5160c5423bfc077880811151 --- .../drawable_descriptor.cpp | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/interfaces/inner_api/drawable_descriptor/drawable_descriptor.cpp b/interfaces/inner_api/drawable_descriptor/drawable_descriptor.cpp index ff45220075e..298ae7b48ad 100644 --- a/interfaces/inner_api/drawable_descriptor/drawable_descriptor.cpp +++ b/interfaces/inner_api/drawable_descriptor/drawable_descriptor.cpp @@ -64,6 +64,12 @@ inline bool NearEqual(const double left, const double right) constexpr double epsilon = 0.001f; return NearEqual(left, right, epsilon); } + +inline bool GreatNotEqual(double left, double right) +{ + constexpr double epsilon = 0.001f; + return (left - right) > epsilon; +} #endif const int DEFAULT_DURATION = 1000; const std::string DEFAULT_MASK = "ohos_icon_mask"; @@ -503,18 +509,30 @@ void LayeredDrawableDescriptor::CompositeIconAdaptive(std::shared_ptr(foreground->GetWidth()), static_cast(foreground->GetHeight())); auto x = static_cast((background->GetWidth() - foreground->GetWidth()) / 2); auto y = static_cast((background->GetHeight() - foreground->GetHeight()) / 2); - dstRect = Rosen::Drawing::Rect( - x, y, static_cast(foreground->GetWidth()), static_cast(foreground->GetHeight()) - ); - + auto srcOffsetX = 0.0f; + auto srcOffsetY = 0.0f; + auto dstOffsetX = 0.0f; + auto dstOffsetY = 0.0f; + if (GreatNotEqual(background->GetWidth(), foreground->GetWidth())) { + dstOffsetX = x; + } else { + srcOffsetX = -1 * x; + } + if (GreatNotEqual(background->GetHeight(), foreground->GetHeight())) { + dstOffsetY = y; + } else { + srcOffsetY = -1 * y; + } + Rosen::Drawing::Rect rsSrcRect(srcOffsetX, srcOffsetY, + foreground->GetWidth() + srcOffsetX, foreground->GetHeight() + srcOffsetY); + Rosen::Drawing::Rect rsDstRect(dstOffsetX, dstOffsetY, + foreground->GetWidth() + dstOffsetX, foreground->GetHeight() + dstOffsetY); brush.SetBlendMode(Rosen::Drawing::BlendMode::SRC_ATOP); bitmapCanvas.AttachBrush(brush); image.BuildFromBitmap(*foreground); - bitmapCanvas.DrawImageRect(image, srcRect, dstRect, Rosen::Drawing::SamplingOptions(), + bitmapCanvas.DrawImageRect(image, rsSrcRect, rsDstRect, Rosen::Drawing::SamplingOptions(), Rosen::Drawing::SrcRectConstraint::FAST_SRC_RECT_CONSTRAINT); bitmapCanvas.DetachBrush(); } From 8637d424f60d15efe226459dca1816cc7078f9bb Mon Sep 17 00:00:00 2001 From: zhouyan Date: Sat, 20 Jul 2024 09:23:47 +0000 Subject: [PATCH 094/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=91=8A=E8=AD=A64-2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyan Change-Id: I75a5a991fc47ffeb197262d7ac08bc0e7f01a3e3 --- frameworks/core/components/font/constants_converter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components/font/constants_converter.cpp b/frameworks/core/components/font/constants_converter.cpp index afaf2bb0c06..cf067efc3f6 100644 --- a/frameworks/core/components/font/constants_converter.cpp +++ b/frameworks/core/components/font/constants_converter.cpp @@ -37,8 +37,8 @@ namespace OHOS::Ace::Constants { namespace { const std::string FONTWEIGHT = "wght"; constexpr float DEFAULT_MULTIPLE = 100.0f; -constexpr uint32_t SCALE_EFFECT = 2; -constexpr uint32_t NONE_EFFECT = 0; +constexpr int32_t SCALE_EFFECT = 2; +constexpr int32_t NONE_EFFECT = 0; constexpr float ORIGINAL_LINE_HEIGHT_SCALE = 1.0f; } // namespace From 40a62523a29defcd4bb0b89f420a3e0cf567c7fc Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Wed, 17 Jul 2024 14:34:45 +0800 Subject: [PATCH 095/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8DtextPickerDialog?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E9=BB=98=E8=AE=A4=E9=97=B4=E8=B7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../text_picker/textpicker_dialog_view.cpp | 39 ++++++++--- .../text_picker/textpicker_pattern.cpp | 65 +++++++++++++++++++ .../pattern/text_picker/textpicker_pattern.h | 4 ++ 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.cpp index 7a31c42e057..3c5e54cb7d3 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_dialog_view.cpp @@ -611,16 +611,28 @@ void TextPickerDialogView::UpdateConfirmButtonMargin( const RefPtr& buttonConfirmNode, const RefPtr& dialogTheme) { MarginProperty margin; + bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { - margin.right = CalcLength(dialogTheme->GetDividerPadding().Right()); margin.top = CalcLength(dialogTheme->GetDividerHeight()); margin.bottom = CalcLength(dialogTheme->GetDividerPadding().Bottom()); - margin.left = CalcLength(dialogTheme->GetDividerPadding().Left()); + if (isRtl) { + margin.right = CalcLength(0.0_vp); + margin.left = CalcLength(dialogTheme->GetDividerPadding().Left()); + } else { + margin.right = CalcLength(dialogTheme->GetDividerPadding().Right()); + margin.left = CalcLength(0.0_vp); + } + } else { - margin.right = CalcLength(dialogTheme->GetActionsPadding().Right()); margin.top = CalcLength(dialogTheme->GetActionsPadding().Top()); margin.bottom = CalcLength(dialogTheme->GetActionsPadding().Bottom()); - margin.left = CalcLength(dialogTheme->GetActionsPadding().Left()); + if (isRtl) { + margin.right = CalcLength(0.0_vp); + margin.left = CalcLength(dialogTheme->GetActionsPadding().Left()); + } else { + margin.right = CalcLength(dialogTheme->GetActionsPadding().Right()); + margin.left = CalcLength(0.0_vp); + } } buttonConfirmNode->GetLayoutProperty()->UpdateMargin(margin); } @@ -629,16 +641,27 @@ void TextPickerDialogView::UpdateCancelButtonMargin( const RefPtr& buttonCancelNode, const RefPtr& dialogTheme) { MarginProperty margin; + bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { - margin.left = CalcLength(dialogTheme->GetDividerPadding().Left()); margin.top = CalcLength(dialogTheme->GetDividerHeight()); margin.bottom = CalcLength(dialogTheme->GetDividerPadding().Bottom()); - margin.right = CalcLength(dialogTheme->GetDividerPadding().Right()); + if (isRtl) { + margin.right = CalcLength(dialogTheme->GetDividerPadding().Right()); + margin.left = CalcLength(0.0_vp); + } else { + margin.right = CalcLength(0.0_vp); + margin.left = CalcLength(dialogTheme->GetDividerPadding().Left()); + } } else { - margin.left = CalcLength(dialogTheme->GetActionsPadding().Left()); margin.top = CalcLength(dialogTheme->GetActionsPadding().Top()); margin.bottom = CalcLength(dialogTheme->GetActionsPadding().Bottom()); - margin.right = CalcLength(dialogTheme->GetActionsPadding().Right()); + if (isRtl) { + margin.right = CalcLength(dialogTheme->GetActionsPadding().Right()); + margin.left = CalcLength(0.0_vp); + } else { + margin.right = CalcLength(0.0_vp); + margin.left = CalcLength(dialogTheme->GetActionsPadding().Left()); + } } buttonCancelNode->GetLayoutProperty()->UpdateMargin(margin); } diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp index d35ec34c13d..9b0fe8e866d 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.cpp @@ -83,6 +83,65 @@ bool TextPickerPattern::OnDirtyLayoutWrapperSwap(const RefPtr& di return true; } +void TextPickerPattern::UpdateConfirmButtonMargin( + const RefPtr& buttonConfirmNode, const RefPtr& dialogTheme) +{ + MarginProperty margin; + bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); + if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + margin.top = CalcLength(dialogTheme->GetDividerHeight()); + margin.bottom = CalcLength(dialogTheme->GetDividerPadding().Bottom()); + if (isRtl) { + margin.right = CalcLength(0.0_vp); + margin.left = CalcLength(dialogTheme->GetDividerPadding().Left()); + } else { + margin.right = CalcLength(dialogTheme->GetDividerPadding().Right()); + margin.left = CalcLength(0.0_vp); + } + + } else { + margin.top = CalcLength(dialogTheme->GetActionsPadding().Top()); + margin.bottom = CalcLength(dialogTheme->GetActionsPadding().Bottom()); + if (isRtl) { + margin.right = CalcLength(0.0_vp); + margin.left = CalcLength(dialogTheme->GetActionsPadding().Left()); + } else { + margin.right = CalcLength(dialogTheme->GetActionsPadding().Right()); + margin.left = CalcLength(0.0_vp); + } + } + buttonConfirmNode->GetLayoutProperty()->UpdateMargin(margin); +} + +void TextPickerPattern::UpdateCancelButtonMargin( + const RefPtr& buttonCancelNode, const RefPtr& dialogTheme) +{ + MarginProperty margin; + bool isRtl = AceApplicationInfo::GetInstance().IsRightToLeft(); + if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { + margin.top = CalcLength(dialogTheme->GetDividerHeight()); + margin.bottom = CalcLength(dialogTheme->GetDividerPadding().Bottom()); + if (isRtl) { + margin.right = CalcLength(dialogTheme->GetDividerPadding().Right()); + margin.left = CalcLength(0.0_vp); + } else { + margin.right = CalcLength(0.0_vp); + margin.left = CalcLength(dialogTheme->GetDividerPadding().Left()); + } + } else { + margin.top = CalcLength(dialogTheme->GetActionsPadding().Top()); + margin.bottom = CalcLength(dialogTheme->GetActionsPadding().Bottom()); + if (isRtl) { + margin.right = CalcLength(dialogTheme->GetActionsPadding().Right()); + margin.left = CalcLength(0.0_vp); + } else { + margin.right = CalcLength(0.0_vp); + margin.left = CalcLength(dialogTheme->GetActionsPadding().Left()); + } + } + buttonCancelNode->GetLayoutProperty()->UpdateMargin(margin); +} + void TextPickerPattern::OnLanguageConfigurationUpdate() { auto buttonConfirmNode = weakButtonConfirm_.Upgrade(); @@ -92,6 +151,11 @@ void TextPickerPattern::OnLanguageConfigurationUpdate() auto confirmNodeLayout = confirmNode->GetLayoutProperty(); CHECK_NULL_VOID(confirmNodeLayout); confirmNodeLayout->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.ok")); + auto pipeline = confirmNode->GetContextRefPtr(); + CHECK_NULL_VOID(pipeline); + auto dialogTheme = pipeline->GetTheme(); + CHECK_NULL_VOID(dialogTheme); + UpdateConfirmButtonMargin(buttonConfirmNode, dialogTheme); confirmNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); auto buttonCancelNode = weakButtonCancel_.Upgrade(); @@ -101,6 +165,7 @@ void TextPickerPattern::OnLanguageConfigurationUpdate() auto cancelNodeLayout = cancelNode->GetLayoutProperty(); CHECK_NULL_VOID(cancelNodeLayout); cancelNodeLayout->UpdateContent(Localization::GetInstance()->GetEntryLetters("common.cancel")); + UpdateCancelButtonMargin(buttonCancelNode, dialogTheme); cancelNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE); } diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h index 9f3be89f85e..34296c46c98 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_pattern.h @@ -493,6 +493,10 @@ private: std::vector& rangeContents, uint32_t patterIndex); void ProcessCascadeOptionsValues(const std::vector& rangeResultValue, uint32_t index); void SetFocusCornerRadius(RoundRect& paintRect); + void UpdateConfirmButtonMargin( + const RefPtr& buttonConfirmNode, const RefPtr& dialogTheme); + void UpdateCancelButtonMargin( + const RefPtr& buttonCancelNode, const RefPtr& dialogTheme); bool enabled_ = true; int32_t focusKeyID_ = 0; From c32e987aaecb2600e448dbcddb1a8714a976f8a0 Mon Sep 17 00:00:00 2001 From: b30058220 Date: Sat, 20 Jul 2024 09:56:40 +0000 Subject: [PATCH 096/221] =?UTF-8?q?=E5=A2=9E=E5=8A=A0drag=E7=BB=B4?= =?UTF-8?q?=E6=B5=8B=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: b30058220 Change-Id: I839ea4c5f488cd9bfb79bb580235375f6eea437b --- .../core/components_ng/manager/drag_drop/drag_drop_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp b/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp index 417212230be..5dd35c47d6b 100644 --- a/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp +++ b/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp @@ -834,11 +834,13 @@ void DragDropManager::DoDropAction(const RefPtr& dragFrameNode, const RefPtr DragDropManager::RequestUDMFDataWithUDKey(const std::string& udKey) { if (udKey.empty()) { + TAG_LOGI(AceLogTag::ACE_DRAG, "udKey is empty"); return nullptr; } RefPtr udData = UdmfClient::GetInstance()->CreateUnifiedData(); auto ret = UdmfClient::GetInstance()->GetData(udData, udKey); if (ret != 0) { + TAG_LOGI(AceLogTag::ACE_DRAG, "Get udmfData failed"); return nullptr; } return udData; From c9bf7cbd3c624cf6406974591dffeda687b0b5aa Mon Sep 17 00:00:00 2001 From: fengjituo111 Date: Sat, 20 Jul 2024 06:43:37 +0000 Subject: [PATCH 097/221] =?UTF-8?q?=E3=80=90SafeArea=E3=80=91=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=BC=B9=E7=AA=97=E4=B8=8D=E9=81=BF=E8=AE=A9=E6=8C=96?= =?UTF-8?q?=E5=AD=94=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengjituo111 Change-Id: I5d62825fedea1c649e8a4aff6486780af99b8591 --- .../manager/safe_area/safe_area_manager.cpp | 28 ++++++++----------- .../manager/safe_area/safe_area_manager.h | 7 +++++ .../pattern/overlay/popup_base_pattern.h | 5 ++++ .../pattern/stage/content_root_pattern.cpp | 15 +++++++--- .../pattern/stage/content_root_pattern.h | 1 + .../pattern/stage/page_pattern.h | 5 ++++ 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/frameworks/core/components_ng/manager/safe_area/safe_area_manager.cpp b/frameworks/core/components_ng/manager/safe_area/safe_area_manager.cpp index e356abe9523..1b69655c83b 100644 --- a/frameworks/core/components_ng/manager/safe_area/safe_area_manager.cpp +++ b/frameworks/core/components_ng/manager/safe_area/safe_area_manager.cpp @@ -84,15 +84,9 @@ bool SafeAreaManager::UpdateKeyboardSafeArea(float keyboardHeight) SafeAreaInsets SafeAreaManager::GetCombinedSafeArea(const SafeAreaExpandOpts& opts) const { SafeAreaInsets res; -#ifdef PREVIEW - if (ignoreSafeArea_) { - return res; + if (!IsSafeAreaValid()) { + return {}; } -#else - if (ignoreSafeArea_ || (!isFullScreen_ && !isNeedAvoidWindow_)) { - return res; - } -#endif if (opts.type & SAFE_AREA_TYPE_CUTOUT) { res = res.Combine(cutoutSafeArea_); } @@ -171,7 +165,7 @@ SafeAreaInsets SafeAreaManager::GetSystemSafeArea() const SafeAreaInsets SafeAreaManager::GetCutoutSafeArea() const { - if (ignoreSafeArea_ || !isFullScreen_) { + if (!IsSafeAreaValid()) { return {}; } return cutoutSafeArea_; @@ -179,18 +173,20 @@ SafeAreaInsets SafeAreaManager::GetCutoutSafeArea() const SafeAreaInsets SafeAreaManager::GetSafeArea() const { -#ifdef PREVIEW - if (ignoreSafeArea_) { + if (!IsSafeAreaValid()) { return {}; } -#else - if (ignoreSafeArea_ || (!isFullScreen_ && !isNeedAvoidWindow_)) { - return {}; - } -#endif return systemSafeArea_.Combine(cutoutSafeArea_).Combine(navSafeArea_); } +SafeAreaInsets SafeAreaManager::GetSafeAreaWithoutCutout() const +{ + if (!IsSafeAreaValid()) { + return {}; + } + return systemSafeArea_.Combine(navSafeArea_); +} + SafeAreaInsets SafeAreaManager::GetSafeAreaWithoutProcess() const { return systemSafeArea_.Combine(cutoutSafeArea_).Combine(navSafeArea_); diff --git a/frameworks/core/components_ng/manager/safe_area/safe_area_manager.h b/frameworks/core/components_ng/manager/safe_area/safe_area_manager.h index 8a8fba6aa29..98295004746 100644 --- a/frameworks/core/components_ng/manager/safe_area/safe_area_manager.h +++ b/frameworks/core/components_ng/manager/safe_area/safe_area_manager.h @@ -81,6 +81,13 @@ public: */ SafeAreaInsets GetSafeArea() const; + /** + * @brief Retrieves the safe area insets only System. + * + * @return The System safe area insets. + */ + SafeAreaInsets GetSafeAreaWithoutCutout() const; + /** * @brief Updates the safe area to accommodate the keyboard. * diff --git a/frameworks/core/components_ng/pattern/overlay/popup_base_pattern.h b/frameworks/core/components_ng/pattern/overlay/popup_base_pattern.h index 6f96aa34674..bd3b3f06481 100644 --- a/frameworks/core/components_ng/pattern/overlay/popup_base_pattern.h +++ b/frameworks/core/components_ng/pattern/overlay/popup_base_pattern.h @@ -59,6 +59,11 @@ protected: return true; } + bool AvoidCutout() const override + { + return false; + } + private: // record node in which container. int32_t containerId_ = -1; diff --git a/frameworks/core/components_ng/pattern/stage/content_root_pattern.cpp b/frameworks/core/components_ng/pattern/stage/content_root_pattern.cpp index 0b997c5a093..bf2c00c6814 100644 --- a/frameworks/core/components_ng/pattern/stage/content_root_pattern.cpp +++ b/frameworks/core/components_ng/pattern/stage/content_root_pattern.cpp @@ -35,14 +35,20 @@ SafeAreaInsets ContentRootPattern::CreateSafeAreaInsets() const auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipeline, {}); - auto inset = pipeline->GetSafeArea(); + auto manager = pipeline->GetSafeAreaManager(); + CHECK_NULL_RETURN(manager, {}); + auto inset = manager->GetSafeAreaWithoutCutout(); + + // popups does not avoid cutout area here + if (AvoidCutout()) { + inset = inset.Combine(manager->GetCutoutSafeArea()); + } if (!AvoidBottom()) { inset.bottom_ = { 0, 0 }; } if (AvoidKeyboard()) { - auto manager = pipeline->GetSafeAreaManager(); inset.bottom_ = inset.bottom_.Combine(manager->GetKeyboardInset()); } @@ -59,8 +65,9 @@ SafeAreaInsets ContentRootPattern::CreateSafeAreaInsets() const if (!AvoidTop()) { inset.top_ = { 0, 0 }; } - LOGD("create root content safeAreaInsets: AvoidKeyboard %{public}d, AvoidTop %{public}d, inset %{public}s", - AvoidKeyboard(), AvoidTop(), inset.ToString().c_str()); + LOGD("create root content safeAreaInsets: AvoidKeyboard %{public}d, AvoidTop %{public}d, AvoidCutout %{public}d, " + "inset %{public}s", + AvoidKeyboard(), AvoidTop(), AvoidCutout(), inset.ToString().c_str()); return inset; } } // namespace OHOS::Ace::NG \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/stage/content_root_pattern.h b/frameworks/core/components_ng/pattern/stage/content_root_pattern.h index 68facce1d9c..a6ee87609ba 100644 --- a/frameworks/core/components_ng/pattern/stage/content_root_pattern.h +++ b/frameworks/core/components_ng/pattern/stage/content_root_pattern.h @@ -34,6 +34,7 @@ protected: virtual bool AvoidKeyboard() const = 0; virtual bool AvoidTop() const = 0; virtual bool AvoidBottom() const = 0; + virtual bool AvoidCutout() const = 0; private: SafeAreaInsets CreateSafeAreaInsets() const; diff --git a/frameworks/core/components_ng/pattern/stage/page_pattern.h b/frameworks/core/components_ng/pattern/stage/page_pattern.h index 454f8c64a62..484291181fe 100644 --- a/frameworks/core/components_ng/pattern/stage/page_pattern.h +++ b/frameworks/core/components_ng/pattern/stage/page_pattern.h @@ -238,6 +238,11 @@ protected: return true; } + bool AvoidCutout() const override + { + return true; + } + void NotifyPerfMonitorPageMsg(const std::string& pageUrl, const std::string& bundleName); RefPtr pageInfo_; From 98349cb770042339a989fc244f4ebf7a9bab40b9 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Sat, 20 Jul 2024 18:02:58 +0800 Subject: [PATCH 098/221] navigation0720 Signed-off-by: sunjiakun --- .../components_ng/pattern/navigation/navigation_pattern.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp b/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp index 02577ef33c1..3431a9f6821 100644 --- a/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp +++ b/frameworks/core/components_ng/pattern/navigation/navigation_pattern.cpp @@ -1447,7 +1447,8 @@ void NavigationPattern::HandleDragUpdate(float xOffset) auto navigationPosition = navigationLayoutProperty->GetNavBarPosition().value_or(NavBarPosition::START); bool isNavBarStart = navigationPosition == NavBarPosition::START; - auto navBarLine = preNavBarWidth_ + (isNavBarStart ? xOffset : -xOffset); + auto navBarLine = isRightToLeft_ ? preNavBarWidth_ + (isNavBarStart ? -xOffset : xOffset) + : preNavBarWidth_ + (isNavBarStart ? xOffset : -xOffset); float currentNavBarWidth = realNavBarWidth_; if (maxNavBarWidthPx + dividerWidth + minContentWidthPx > frameWidth) { From 14c9aeb3ee74ccdfc5bdc25dbee82f5af9b09daf Mon Sep 17 00:00:00 2001 From: yangcan Date: Sat, 20 Jul 2024 18:13:51 +0800 Subject: [PATCH 099/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BF=AB=E9=80=9F?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E9=A1=B5=E7=AD=BE=E8=B7=B3=E8=BD=AC=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yangcan Change-Id: I249f55f462ed4521b834bf8b5dd52ec7a2d136bb --- frameworks/core/components_ng/pattern/tabs/tab_bar_pattern.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frameworks/core/components_ng/pattern/tabs/tab_bar_pattern.cpp b/frameworks/core/components_ng/pattern/tabs/tab_bar_pattern.cpp index fd5d3c0bef3..2b20d057875 100644 --- a/frameworks/core/components_ng/pattern/tabs/tab_bar_pattern.cpp +++ b/frameworks/core/components_ng/pattern/tabs/tab_bar_pattern.cpp @@ -1097,6 +1097,9 @@ void TabBarPattern::ClickTo(const RefPtr& host, int32_t index) CHECK_NULL_VOID(tabsNode); auto tabsPattern = tabsNode->GetPattern(); CHECK_NULL_VOID(tabsPattern); + CHECK_NULL_VOID(swiperController_); + swiperController_->FinishAnimation(); + UpdateAnimationDuration(); auto duration = GetAnimationDuration().value_or(0); if (tabsPattern->GetIsCustomAnimation()) { From d3fe2342f4594b4080c7555bf3900cb62ad9a7a4 Mon Sep 17 00:00:00 2001 From: b30045777 Date: Sat, 20 Jul 2024 15:46:57 +0800 Subject: [PATCH 100/221] =?UTF-8?q?=E3=80=90RichEditor=E3=80=91=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=97=A0=E9=9A=9C=E7=A2=8D=E7=BC=96=E8=BE=91=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: b30045777 Change-Id: I52bd6c44294a7338ab5543cab163193aef1eccbf --- .../rich_editor/rich_editor_pattern.cpp | 49 +++++++++++++++++++ .../pattern/rich_editor/rich_editor_pattern.h | 3 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp index e23ed0617a7..376a068fa00 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.cpp @@ -2069,6 +2069,7 @@ void RichEditorPattern::CloseSystemMenu() void RichEditorPattern::SetAccessibilityAction() { auto host = GetHost(); + CHECK_NULL_VOID(host); auto property = host->GetAccessibilityProperty(); CHECK_NULL_VOID(property); property->SetActionSetSelection([weakPtr = WeakClaim(this)](int32_t start, int32_t end, bool isForward) { @@ -2092,6 +2093,54 @@ void RichEditorPattern::SetAccessibilityAction() CHECK_NULL_RETURN(pattern, -1); return pattern->GetCaretPosition(); }); + SetAccessibilityEditAction(); +} + +void RichEditorPattern::SetAccessibilityEditAction() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto property = host->GetAccessibilityProperty(); + CHECK_NULL_VOID(property); + property->SetActionSetText([weakPtr = WeakClaim(this)](const std::string& value) { + TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "EditAction setText, length: %{public}d", + static_cast(StringUtils::ToWstring(value).length())); + const auto& pattern = weakPtr.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->InsertValue(value); + }); + + property->SetActionCopy([weakPtr = WeakClaim(this)]() { + TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "EditAction copy"); + const auto& pattern = weakPtr.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->HandleOnCopy(); + pattern->CloseSelectionMenu(); + }); + + property->SetActionCut([weakPtr = WeakClaim(this)]() { + TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "EditAction cut"); + const auto& pattern = weakPtr.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->HandleOnCut(); + }); + + property->SetActionPaste([weakPtr = WeakClaim(this)]() { + TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "EditAction paste"); + const auto& pattern = weakPtr.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->HandleOnPaste(); + pattern->CloseSelectionMenu(); + }); + + property->SetActionClearSelection([weakPtr = WeakClaim(this)]() { + TAG_LOGI(AceLogTag::ACE_RICH_TEXT, "EditAction clearSelection"); + const auto& pattern = weakPtr.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->CloseSelectionMenu(); + pattern->ResetSelection(); + pattern->StartTwinkling(); + }); } std::vector RichEditorPattern::GetParagraphInfo(int32_t start, int32_t end) diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h index 377c8a85ecb..0a13fc0a192 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_pattern.h @@ -1028,7 +1028,8 @@ private: void HandleOnEditChanged(bool isEditing); void OnTextInputActionUpdate(TextInputAction value); void CloseSystemMenu(); - void SetAccessibilityAction(); + void SetAccessibilityAction() override; + void SetAccessibilityEditAction(); void HandleTripleClickEvent(OHOS::Ace::GestureEvent& info); void UpdateSelectionByTouchMove(const Offset& offset); void MoveCaretAnywhere(const Offset& touchOffset); From ec063fab5ac69093cc8d874db6c36afb1f146452 Mon Sep 17 00:00:00 2001 From: yuzhicheng Date: Sat, 20 Jul 2024 17:10:05 +0800 Subject: [PATCH 101/221] navdestination lifeCycle bug fix Signed-off-by: yuzhicheng Change-Id: I73796ce1f64c4204fed73c4b11235d63f632035d --- .../core/components_ng/pattern/overlay/overlay_manager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 211b3c20ddf..72010f96bd1 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -3262,6 +3262,13 @@ void OverlayManager::FireNavigationStateChange(bool show, const RefPtr& } auto lastPage = GetLastPage(); + CHECK_NULL_VOID(lastPage); + auto pagePattern = lastPage->GetPattern(); + bool notTriggerNavigationStateChange = show && pagePattern && !pagePattern->IsOnShow(); + if (notTriggerNavigationStateChange) { + // navdestination will not fire onShow When parent page is hide. + return; + } NavigationPattern::FireNavigationStateChange(lastPage, show); } From aa9aa98f6ba5fdc67b945f5f0744812e4ebbb3e1 Mon Sep 17 00:00:00 2001 From: wenyifei Date: Sat, 20 Jul 2024 18:37:11 +0800 Subject: [PATCH 102/221] INTERACTION_APP_JANK event add fields Signed-off-by: wenyifei --- adapter/ohos/osal/event_report.cpp | 9 +++++++++ frameworks/base/perfmonitor/perf_monitor.cpp | 10 +++++++++- frameworks/base/perfmonitor/perf_monitor.h | 6 ++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/adapter/ohos/osal/event_report.cpp b/adapter/ohos/osal/event_report.cpp index 9e3cb6942fc..df895c3a05c 100644 --- a/adapter/ohos/osal/event_report.cpp +++ b/adapter/ohos/osal/event_report.cpp @@ -61,6 +61,9 @@ constexpr char EVENT_KEY_DURITION[] = "DURITION"; constexpr char EVENT_KEY_TOTAL_FRAMES[] = "TOTAL_FRAMES"; constexpr char EVENT_KEY_TOTAL_MISSED_FRAMES[] = "TOTAL_MISSED_FRAMES"; constexpr char EVENT_KEY_MAX_FRAMETIME[] = "MAX_FRAMETIME"; +constexpr char EVENT_KEY_MAX_FRAMETIME_SINCE_START[] = "MAX_FRAMETIME_SINCE_START"; +constexpr char EVENT_KEY_MAX_HITCH_TIME[] = "MAX_HITCH_TIME"; +constexpr char EVENT_KEY_MAX_HITCH_TIME_SINCE_START[] = "MAX_HITCH_TIME_SINCE_START"; constexpr char EVENT_KEY_MAX_SEQ_MISSED_FRAMES[] = "MAX_SEQ_MISSED_FRAMES"; constexpr char EVENT_KEY_SOURCE_TYPE[] = "SOURCE_TYPE"; constexpr char EVENT_KEY_NOTE[] = "NOTE"; @@ -409,6 +412,9 @@ void EventReport::ReportEventJankFrame(DataBase& data) const auto& totalFrames = data.totalFrames; const auto& totalMissedFrames = data.totalMissed; const auto& maxFrameTime = data.maxFrameTime / NS_TO_MS; + const auto& maxFrameTimeSinceStart = data.maxFrameTimeSinceStart; + const auto& maxHitchTime = data.maxHitchTime; + const auto& maxHitchTimeSinceStart = data.maxHitchTimeSinceStart; const auto& maxSeqMissedFrames = data.maxSuccessiveFrames; const auto& note = data.baseInfo.note; const auto& isDisplayAnimator = data.isDisplayAnimator; @@ -428,6 +434,9 @@ void EventReport::ReportEventJankFrame(DataBase& data) EVENT_KEY_TOTAL_FRAMES, totalFrames, EVENT_KEY_TOTAL_MISSED_FRAMES, totalMissedFrames, EVENT_KEY_MAX_FRAMETIME, static_cast(maxFrameTime), + EVENT_KEY_MAX_FRAMETIME_SINCE_START, static_cast(maxFrameTimeSinceStart), + EVENT_KEY_MAX_HITCH_TIME, static_cast(maxHitchTime), + EVENT_KEY_MAX_HITCH_TIME_SINCE_START, static_cast(maxHitchTimeSinceStart), EVENT_KEY_MAX_SEQ_MISSED_FRAMES, maxSeqMissedFrames, EVENT_KEY_NOTE, note, EVENT_KEY_DISPLAY_ANIMATOR, isDisplayAnimator); diff --git a/frameworks/base/perfmonitor/perf_monitor.cpp b/frameworks/base/perfmonitor/perf_monitor.cpp index b64f3d5d1a4..21c052e257f 100644 --- a/frameworks/base/perfmonitor/perf_monitor.cpp +++ b/frameworks/base/perfmonitor/perf_monitor.cpp @@ -182,8 +182,9 @@ bool SceneRecord::IsTimeOut(int64_t nowTime) void SceneRecord::RecordFrame(int64_t vsyncTime, int64_t duration, int32_t skippedFrames) { + int64_t currentTimeNs = GetCurrentRealTimeNs(); if (totalFrames == 0) { - beginVsyncTime = GetCurrentRealTimeNs(); + beginVsyncTime = currentTimeNs; isFirstFrame = true; } else { isFirstFrame = false; @@ -206,6 +207,7 @@ void SceneRecord::RecordFrame(int64_t vsyncTime, int64_t duration, int32_t skipp } if (!isFirstFrame && duration > maxFrameTime) { maxFrameTime = duration; + maxFrameTimeSinceStart = currentTimeNs - beginVsyncTime; } totalFrames++; } @@ -242,6 +244,9 @@ void SceneRecord::Reset() beginVsyncTime = 0; endVsyncTime = 0; maxFrameTime = 0; + maxFrameTimeSinceStart = 0; + maxHitchTime = 0; + maxHitchTimeSinceStart = 0; maxSuccessiveFrames = 0; seqMissFrames = 0; totalMissed = 0; @@ -481,6 +486,9 @@ void PerfMonitor::FlushDataBase(SceneRecord* record, DataBase& data) data.endVsyncTime = data.beginVsyncTime; } data.maxFrameTime = record->maxFrameTime; + data.maxFrameTimeSinceStart = record->maxFrameTimeSinceStart; + data.maxHitchTime = record->maxHitchTime; + data.maxHitchTimeSinceStart = record->maxHitchTimeSinceStart; data.maxSuccessiveFrames = record->maxSuccessiveFrames; data.totalMissed = record->totalMissed; data.totalFrames = record->totalFrames; diff --git a/frameworks/base/perfmonitor/perf_monitor.h b/frameworks/base/perfmonitor/perf_monitor.h index da84d6328bb..bcec1ecd3b2 100644 --- a/frameworks/base/perfmonitor/perf_monitor.h +++ b/frameworks/base/perfmonitor/perf_monitor.h @@ -71,6 +71,9 @@ struct DataBase { int64_t beginVsyncTime {0}; int64_t endVsyncTime {0}; int64_t maxFrameTime {0}; + int64_t maxFrameTimeSinceStart {0}; + int64_t maxHitchTime {0}; + int64_t maxHitchTimeSinceStart {0}; bool needReportRs {false}; bool isDisplayAnimator {false}; PerfSourceType sourceType {UNKNOWN_SOURCE}; @@ -103,6 +106,9 @@ public: int64_t beginVsyncTime {0}; int64_t endVsyncTime {0}; int64_t maxFrameTime {0}; + int64_t maxFrameTimeSinceStart {0}; + int64_t maxHitchTime {0}; + int64_t maxHitchTimeSinceStart {0}; int32_t maxSuccessiveFrames {0}; int32_t totalMissed {0}; int32_t totalFrames {0}; From 645cdeecf439679db26ac9d52eda375d4722f8ef Mon Sep 17 00:00:00 2001 From: mayaolll Date: Sat, 20 Jul 2024 18:34:42 +0800 Subject: [PATCH 103/221] revert fix bug Signed-off-by: mayaolll --- interfaces/napi/kits/router/js_router.cpp | 107 ++++++++++------------ 1 file changed, 48 insertions(+), 59 deletions(-) diff --git a/interfaces/napi/kits/router/js_router.cpp b/interfaces/napi/kits/router/js_router.cpp index aea149757c4..42024f1d5e8 100644 --- a/interfaces/napi/kits/router/js_router.cpp +++ b/interfaces/napi/kits/router/js_router.cpp @@ -56,10 +56,10 @@ static void ParseUri(napi_env env, napi_value uriNApi, std::string& uriString) } } -static bool ParseParams(napi_env env, napi_value params, std::string& paramsString) +static void ParseParams(napi_env env, napi_value params, std::string& paramsString) { if (params == nullptr) { - return false; + return; } napi_value globalValue; napi_get_global(env, &globalValue); @@ -70,15 +70,14 @@ static bool ParseParams(napi_env env, napi_value params, std::string& paramsStri napi_value funcArgv[1] = { params }; napi_value returnValue; if (napi_call_function(env, jsonValue, stringifyValue, 1, funcArgv, &returnValue) != napi_ok) { - napi_get_and_clear_last_exception(env, &returnValue); - return false; + TAG_LOGE(AceLogTag::ACE_ROUTER, + "Router parse param failed, probably caused by invalid format of JSON object 'params'"); } size_t len = 0; napi_get_value_string_utf8(env, returnValue, nullptr, 0, &len); std::unique_ptr paramsChar = std::make_unique(len + 1); napi_get_value_string_utf8(env, returnValue, paramsChar.get(), len + 1, &len); paramsString = paramsChar.get(); - return true; } static napi_value ParseJSONParams(napi_env env, const std::string& paramsStr) @@ -146,48 +145,6 @@ struct RouterAsyncContext { } }; -void TriggerCallback(std::shared_ptr asyncContext) -{ - napi_handle_scope scope = nullptr; - napi_open_handle_scope(asyncContext->env, &scope); - if (scope == nullptr) { - return; - } - - if (asyncContext->callbackCode == ERROR_CODE_NO_ERROR) { - napi_value result = nullptr; - napi_get_undefined(asyncContext->env, &result); - if (asyncContext->deferred) { - napi_resolve_deferred(asyncContext->env, asyncContext->deferred, result); - } else { - napi_value callback = nullptr; - napi_get_reference_value(asyncContext->env, asyncContext->callbackRef, &callback); - napi_value ret; - napi_call_function(asyncContext->env, nullptr, callback, 1, &result, &ret); - } - } else { - napi_value code = nullptr; - std::string strCode = std::to_string(asyncContext->callbackCode); - napi_create_string_utf8(asyncContext->env, strCode.c_str(), strCode.length(), &code); - - napi_value msg = nullptr; - std::string strMsg = ErrorToMessage(asyncContext->callbackCode) + asyncContext->callbackMsg; - napi_create_string_utf8(asyncContext->env, strMsg.c_str(), strMsg.length(), &msg); - - napi_value error = nullptr; - napi_create_error(asyncContext->env, code, msg, &error); - if (asyncContext->deferred) { - napi_reject_deferred(asyncContext->env, asyncContext->deferred, error); - } else { - napi_value callback = nullptr; - napi_get_reference_value(asyncContext->env, asyncContext->callbackRef, &callback); - napi_value ret; - napi_call_function(asyncContext->env, nullptr, callback, 1, &error, &ret); - } - } - napi_close_handle_scope(asyncContext->env, scope); -} - using RouterFunc = std::function; static void CommonRouterProcess(napi_env env, napi_callback_info info, const RouterFunc& callback) @@ -267,7 +224,6 @@ bool ParseParamWithCallback(napi_env env, std::shared_ptr as napi_value* argv, napi_value* result) { asyncContext->env = env; - bool parseParamsSuccess = false; for (size_t i = 0; i < argc; i++) { napi_valuetype valueType = napi_undefined; napi_typeof(env, argv[i], &valueType); @@ -287,7 +243,7 @@ bool ParseParamWithCallback(napi_env env, std::shared_ptr as } ParseUri(env, uriNApi, asyncContext->uriString); napi_get_named_property(env, argv[i], "params", ¶ms); - parseParamsSuccess = ParseParams(env, params, asyncContext->paramsString); + ParseParams(env, params, asyncContext->paramsString); napi_get_named_property(env, argv[i], "recoverable", &recoverable); ParseRecoverable(env, recoverable, asyncContext->recoverable); } else if (valueType == napi_number) { @@ -305,20 +261,53 @@ bool ParseParamWithCallback(napi_env env, std::shared_ptr as NapiThrow(env, "The largest number of parameters is 2 in Promise.", ERROR_CODE_PARAM_INVALID); return false; } - if (napi_create_promise(env, &asyncContext->deferred, result) != napi_ok) { - TAG_LOGW(AceLogTag::ACE_ROUTER, "create return promise failed!"); - } - } - - if (!parseParamsSuccess) { - asyncContext->callbackCode = ERROR_CODE_PARAM_INVALID; - asyncContext->callbackMsg = "The 'params' parameter is invalid."; - TriggerCallback(asyncContext); - return false; + napi_create_promise(env, &asyncContext->deferred, result); } return true; } +void TriggerCallback(std::shared_ptr asyncContext) +{ + napi_handle_scope scope = nullptr; + napi_open_handle_scope(asyncContext->env, &scope); + if (scope == nullptr) { + return; + } + + if (asyncContext->callbackCode == ERROR_CODE_NO_ERROR) { + napi_value result = nullptr; + napi_get_undefined(asyncContext->env, &result); + if (asyncContext->deferred) { + napi_resolve_deferred(asyncContext->env, asyncContext->deferred, result); + } else { + napi_value callback = nullptr; + napi_get_reference_value(asyncContext->env, asyncContext->callbackRef, &callback); + napi_value ret; + napi_call_function(asyncContext->env, nullptr, callback, 1, &result, &ret); + } + } else { + napi_value code = nullptr; + std::string strCode = std::to_string(asyncContext->callbackCode); + napi_create_string_utf8(asyncContext->env, strCode.c_str(), strCode.length(), &code); + + napi_value msg = nullptr; + std::string strMsg = ErrorToMessage(asyncContext->callbackCode) + asyncContext->callbackMsg; + napi_create_string_utf8(asyncContext->env, strMsg.c_str(), strMsg.length(), &msg); + + napi_value error = nullptr; + napi_create_error(asyncContext->env, code, msg, &error); + if (asyncContext->deferred) { + napi_reject_deferred(asyncContext->env, asyncContext->deferred, error); + } else { + napi_value callback = nullptr; + napi_get_reference_value(asyncContext->env, asyncContext->callbackRef, &callback); + napi_value ret; + napi_call_function(asyncContext->env, nullptr, callback, 1, &error, &ret); + } + } + napi_close_handle_scope(asyncContext->env, scope); +} + using ErrorCallback = std::function; using RouterWithCallbackFunc = std::function, const ErrorCallback&)>; From 163fadf6751a85b55cf9cd861eae4664b557ac98 Mon Sep 17 00:00:00 2001 From: tomkl123 Date: Sat, 20 Jul 2024 18:48:52 +0800 Subject: [PATCH 104/221] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tomkl123 Change-Id: I3f57beaeeeba91f259225d00998cbaee09c02955 --- .../bridge/declarative_frontend/engine/jsEnumStyle.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js index 6e396cedab5..1953e857cd0 100644 --- a/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js +++ b/frameworks/bridge/declarative_frontend/engine/jsEnumStyle.js @@ -3297,10 +3297,10 @@ var GestureRecognizerState; GestureRecognizerState[GestureRecognizerState["FAILED"] = 5] = "FAILED"; })(GestureRecognizerState || (GestureRecognizerState = {})); -var GridItemAlignment; +let GridItemAlignment; (function (GridItemAlignment) { - GridItemAlignment[GridItemAlignment["DEFAULT"] = 0] = "DEFAULT"; - GridItemAlignment[GridItemAlignment["STRETCH"] = 1] = "STRETCH"; + GridItemAlignment[GridItemAlignment['DEFAULT'] = 0] = 'DEFAULT'; + GridItemAlignment[GridItemAlignment['STRETCH'] = 1] = 'STRETCH'; })(GridItemAlignment || (GridItemAlignment = {})); class ImageAnalyzerController { From 3fde1dd1aad79ee6f4e42a2340d2639fce17a19b Mon Sep 17 00:00:00 2001 From: tsj_2020 Date: Sat, 20 Jul 2024 19:05:40 +0800 Subject: [PATCH 105/221] add page split page observer Signed-off-by: tsj_2020 Change-Id: I414d249d387048e3767853aaa95728a7d78c328a --- .../pattern/stage/page_pattern.cpp | 31 +++++++++++++++++++ .../pattern/stage/page_pattern.h | 4 +++ 2 files changed, 35 insertions(+) diff --git a/frameworks/core/components_ng/pattern/stage/page_pattern.cpp b/frameworks/core/components_ng/pattern/stage/page_pattern.cpp index ff26aa4e769..dc50180f6fe 100644 --- a/frameworks/core/components_ng/pattern/stage/page_pattern.cpp +++ b/frameworks/core/components_ng/pattern/stage/page_pattern.cpp @@ -187,6 +187,11 @@ void PagePattern::ProcessShowState() void PagePattern::OnAttachToMainTree() { +#if defined(ENABLE_SPLIT_MODE) + if (!needFireObserver_) { + return; + } +#endif int32_t index = INVALID_PAGE_INDEX; auto delegate = EngineHelper::GetCurrentDelegate(); if (delegate) { @@ -199,6 +204,11 @@ void PagePattern::OnAttachToMainTree() void PagePattern::OnDetachFromMainTree() { +#if defined(ENABLE_SPLIT_MODE) + if (!needFireObserver_) { + return; + } +#endif state_ = RouterPageState::ABOUT_TO_DISAPPEAR; UIObserverHandler::GetInstance().NotifyRouterPageStateChange(GetPageInfo(), state_); } @@ -224,8 +234,15 @@ void PagePattern::OnShow() CHECK_NULL_VOID(host); host->SetJSViewActive(true); isOnShow_ = true; +#if defined(ENABLE_SPLIT_MODE) + if (needFireObserver_) { + state_ = RouterPageState::ON_PAGE_SHOW; + UIObserverHandler::GetInstance().NotifyRouterPageStateChange(GetPageInfo(), state_); + } +#else state_ = RouterPageState::ON_PAGE_SHOW; UIObserverHandler::GetInstance().NotifyRouterPageStateChange(GetPageInfo(), state_); +#endif JankFrameReport::GetInstance().StartRecord(pageInfo_->GetPageUrl()); auto pageUrlChecker = container->GetPageUrlChecker(); if (pageUrlChecker != nullptr) { @@ -264,8 +281,15 @@ void PagePattern::OnHide() CHECK_NULL_VOID(host); host->SetJSViewActive(false); isOnShow_ = false; +#if defined(ENABLE_SPLIT_MODE) + if (needFireObserver_) { + state_ = RouterPageState::ON_PAGE_HIDE; + UIObserverHandler::GetInstance().NotifyRouterPageStateChange(GetPageInfo(), state_); + } +#else state_ = RouterPageState::ON_PAGE_HIDE; UIObserverHandler::GetInstance().NotifyRouterPageStateChange(GetPageInfo(), state_); +#endif auto container = Container::Current(); if (container) { auto pageUrlChecker = container->GetPageUrlChecker(); @@ -304,8 +328,15 @@ bool PagePattern::OnBackPressed() return true; } // if in page transition, do not set to ON_BACK_PRESS +#if defined(ENABLE_SPLIT_MODE) + if (needFireObserver_) { + state_ = RouterPageState::ON_BACK_PRESS; + UIObserverHandler::GetInstance().NotifyRouterPageStateChange(GetPageInfo(), state_); + } +#else state_ = RouterPageState::ON_BACK_PRESS; UIObserverHandler::GetInstance().NotifyRouterPageStateChange(GetPageInfo(), state_); +#endif if (onBackPressed_) { return onBackPressed_(); } diff --git a/frameworks/core/components_ng/pattern/stage/page_pattern.h b/frameworks/core/components_ng/pattern/stage/page_pattern.h index fcc430300da..d7d3f21d0dd 100644 --- a/frameworks/core/components_ng/pattern/stage/page_pattern.h +++ b/frameworks/core/components_ng/pattern/stage/page_pattern.h @@ -265,6 +265,10 @@ protected: bool isRenderDone_ = false; bool isModalCovered_ = false; +#if defined(ENABLE_SPLIT_MODE) + bool needFireObserver_ = true; +#endif + SharedTransitionMap sharedTransitionMap_; JSAnimatorMap jsAnimatorMap_; RouterPageState state_ = RouterPageState::ABOUT_TO_APPEAR; From a922a890b2539907274443813679d59a16dad1fd Mon Sep 17 00:00:00 2001 From: vincent Date: Sat, 20 Jul 2024 19:06:26 +0800 Subject: [PATCH 106/221] =?UTF-8?q?=E6=89=8B=E6=9F=84=E5=AD=90=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=A8=A1=E5=BC=8F=E4=B8=8B=E5=8F=AA=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=9C=A8=E8=87=AA=E8=BA=AB=E5=86=85=E5=AE=B9=E5=8C=BA=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=8F=AF=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vincent Change-Id: I6e911297ec5840ff4ae3e241bde94cbf4aef691f --- .../core/components_ng/pattern/text/text_select_overlay.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/text/text_select_overlay.cpp b/frameworks/core/components_ng/pattern/text/text_select_overlay.cpp index e6584e7b38b..10896d6b59d 100644 --- a/frameworks/core/components_ng/pattern/text/text_select_overlay.cpp +++ b/frameworks/core/components_ng/pattern/text/text_select_overlay.cpp @@ -105,7 +105,7 @@ bool TextSelectOverlay::CheckAndAdjustHandle(RectF& paintRect) auto textStyle = textPattern->GetTextStyle(); auto handleRadius = pipeline->NormalizeToPx(theme->GetHandleDiameter()); // If the handle is incomplete at the top, not show. - if (LessNotEqual(paintRect.Top() - handleRadius, 0.0f)) { + if (LessNotEqual(paintRect.Top() - handleRadius, 0.0f) && handleLevelMode_ != HandleLevelMode::EMBED) { return false; } auto clip = false; From 2ebe2fbd14902682eeb5c75c58de431d81931d95 Mon Sep 17 00:00:00 2001 From: zhouminghui Date: Sat, 20 Jul 2024 19:11:40 +0800 Subject: [PATCH 107/221] =?UTF-8?q?Description:=E5=A4=8D=E7=94=A8=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=B3=84=E6=BC=8F=E9=97=AE=E9=A2=98=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20Sig:=20SIG=5FApplicationFramework=20Featur?= =?UTF-8?q?e=20or=20Bugfix:Bugfix=20Binary=20Source:No=20TDD:=E8=AF=84?= =?UTF-8?q?=E4=BC=B0=E4=B8=8D=E6=B6=89=E5=8F=8A=20XTS:=E8=AF=84=E4=BC=B0?= =?UTF-8?q?=E4=B8=8D=E6=B6=89=E5=8F=8A=20=E9=A2=84=E6=B5=8B=E8=AF=95:?= =?UTF-8?q?=E8=AF=84=E4=BC=B0=E4=B8=8D=E6=B6=89=E5=8F=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouminghui --- frameworks/bridge/declarative_frontend/engine/stateMgmt.js | 3 +++ .../state_mgmt/src/lib/partial_update/pu_view.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/frameworks/bridge/declarative_frontend/engine/stateMgmt.js b/frameworks/bridge/declarative_frontend/engine/stateMgmt.js index 816c96356b4..8e3784da431 100644 --- a/frameworks/bridge/declarative_frontend/engine/stateMgmt.js +++ b/frameworks/bridge/declarative_frontend/engine/stateMgmt.js @@ -6698,6 +6698,9 @@ class ViewPU extends PUV2ViewBase { return; } const _componentName = (classObject && ('name' in classObject)) ? Reflect.get(classObject, 'name') : 'unspecified UINode'; + if (_componentName === "__Recycle__") { + return; + } const _popFunc = (classObject && 'pop' in classObject) ? classObject.pop : () => { }; const updateFunc = (elmtId, isFirstRender) => { var _a, _b; diff --git a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/partial_update/pu_view.ts b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/partial_update/pu_view.ts index ef1c9d62951..3f6df2b018c 100644 --- a/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/partial_update/pu_view.ts +++ b/frameworks/bridge/declarative_frontend/state_mgmt/src/lib/partial_update/pu_view.ts @@ -674,6 +674,9 @@ abstract class ViewPU extends PUV2ViewBase return; } const _componentName: string = (classObject && ('name' in classObject)) ? Reflect.get(classObject, 'name') as string : 'unspecified UINode'; + if (_componentName === "__Recycle__") { + return; + } const _popFunc: () => void = (classObject && 'pop' in classObject) ? classObject.pop! : (): void => { }; const updateFunc = (elmtId: number, isFirstRender: boolean): void => { this.syncInstanceId(); From 7cb531cfa22f09d9778fa2ddc69e700194029bc9 Mon Sep 17 00:00:00 2001 From: zhangjinyu101 Date: Tue, 16 Jul 2024 17:10:06 +0800 Subject: [PATCH 108/221] =?UTF-8?q?DrawImageNine=20=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E9=80=82=E9=85=8D=E6=96=B0=E7=9A=84=E6=9E=9A=E4=B8=BE=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangjinyu101 Change-Id: If57d12445f34793b841dca8fbc515fe50ceaff92 --- .../components_ng/render/image_painter.cpp | 43 +++++++++++++++++++ .../core/components_ng/render/image_painter.h | 3 ++ 2 files changed, 46 insertions(+) diff --git a/frameworks/core/components_ng/render/image_painter.cpp b/frameworks/core/components_ng/render/image_painter.cpp index bbe3c04156a..e9efed40583 100644 --- a/frameworks/core/components_ng/render/image_painter.cpp +++ b/frameworks/core/components_ng/render/image_painter.cpp @@ -16,6 +16,7 @@ #include "core/components_ng/render/image_painter.h" #include "base/utils/utils.h" +#include "core/common/ace_application_info.h" #include "core/components_ng/render/drawing.h" #include "core/components_ng/render/drawing_prop_convertor.h" #include "core/pipeline_ng/pipeline_context.h" @@ -84,8 +85,34 @@ void ApplyNone(const SizeF& rawPicSize, const SizeF& dstSize, RectF& srcRect, Re dstRect.SetRect(Alignment::GetAlignPosition(dstSize, srcSize, Alignment::CENTER), srcSize); srcRect.SetRect(Alignment::GetAlignPosition(rawPicSize, srcSize, Alignment::CENTER), srcSize); } + +void ApplyAlignment( + const SizeF& rawPicSize, const SizeF& dstSize, RectF& srcRect, RectF& dstRect, const Alignment& alignMent) +{ + SizeF srcSize(std::min(dstSize.Width(), rawPicSize.Width()), std::min(dstSize.Height(), rawPicSize.Height())); + dstRect.SetRect(Alignment::GetAlignPosition(dstSize, srcSize, alignMent), srcSize); + srcRect.SetRect(Alignment::GetAlignPosition(rawPicSize, srcSize, alignMent), srcSize); +} } // namespace +const std::unordered_map> ImagePainter::ALIMENT_OPERATIONS = { + { ImageFit::TOP_LEFT, + [](bool isRightToLeft) { return isRightToLeft ? Alignment::TOP_RIGHT : Alignment::TOP_LEFT; } }, + { ImageFit::TOP, [](bool) { return Alignment::TOP_CENTER; } }, + { ImageFit::TOP_END, + [](bool isRightToLeft) { return isRightToLeft ? Alignment::TOP_LEFT : Alignment::TOP_RIGHT; } }, + { ImageFit::START, + [](bool isRightToLeft) { return isRightToLeft ? Alignment::CENTER_RIGHT : Alignment::CENTER_LEFT; } }, + { ImageFit::CENTER, [](bool) { return Alignment::CENTER; } }, + { ImageFit::END, + [](bool isRightToLeft) { return isRightToLeft ? Alignment::CENTER_LEFT : Alignment::CENTER_RIGHT; } }, + { ImageFit::BOTTOM_START, + [](bool isRightToLeft) { return isRightToLeft ? Alignment::BOTTOM_RIGHT : Alignment::BOTTOM_LEFT; } }, + { ImageFit::BOTTOM, [](bool) { return Alignment::BOTTOM_CENTER; } }, + { ImageFit::BOTTOM_END, + [](bool isRightToLeft) { return isRightToLeft ? Alignment::BOTTOM_LEFT : Alignment::BOTTOM_RIGHT; } } +}; + void ImagePainter::DrawObscuration(RSCanvas& canvas, const OffsetF& offset, const SizeF& contentSize) const { CHECK_NULL_VOID(canvasImage_); @@ -227,6 +254,17 @@ void ImagePainter::DrawImageWithRepeat(RSCanvas& canvas, const RectF& contentRec canvas.Restore(); } +void ImagePainter::ApplyImageAlignmentFit( + ImageFit imageFit, const SizeF& rawPicSize, const SizeF& dstSize, RectF& srcRect, RectF& dstRect) +{ + auto isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft(); + auto itImageFit = ALIMENT_OPERATIONS.find(imageFit); + if (itImageFit != ALIMENT_OPERATIONS.end()) { + Alignment alignment = itImageFit->second(isRightToLeft); + ApplyAlignment(rawPicSize, dstSize, srcRect, dstRect, alignment); + } +} + void ImagePainter::ApplyImageFit( ImageFit imageFit, const SizeF& rawPicSize, const SizeF& dstSize, RectF& srcRect, RectF& dstRect) { @@ -237,6 +275,11 @@ void ImagePainter::ApplyImageFit( srcRect.ApplyScale(1.0 / viewScale); dstRect.SetOffset(OffsetF()); dstRect.SetSize(dstSize); + if (imageFit >= ImageFit::TOP_LEFT && imageFit <= ImageFit::BOTTOM_END) { + ApplyImageAlignmentFit(imageFit, rawPicSize, dstSize, srcRect, dstRect); + srcRect.ApplyScale(viewScale); + return; + } switch (imageFit) { case ImageFit::FILL: break; diff --git a/frameworks/core/components_ng/render/image_painter.h b/frameworks/core/components_ng/render/image_painter.h index d35d44cd3cc..0af377d2072 100644 --- a/frameworks/core/components_ng/render/image_painter.h +++ b/frameworks/core/components_ng/render/image_painter.h @@ -44,6 +44,9 @@ public: private: RefPtr canvasImage_; + static void ApplyImageAlignmentFit( + ImageFit imageFit, const SizeF& rawPicSize, const SizeF& dstSize, RectF& srcRect, RectF& dstRect); + static const std::unordered_map> ALIMENT_OPERATIONS; }; } // namespace OHOS::Ace::NG From fb52449980dfcb66a37165ce3fc91ea43bd96fd5 Mon Sep 17 00:00:00 2001 From: Lby Date: Sat, 20 Jul 2024 19:21:44 +0800 Subject: [PATCH 109/221] frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp codecheck Signed-off-by: Lby --- frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp index a2af2e88f25..12942afdeeb 100644 --- a/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp +++ b/frameworks/bridge/js_frontend/engine/jsi/ark_js_runtime.cpp @@ -459,7 +459,7 @@ Local PandaFunctionData::Callback(panda::JsiRuntimeCallInfo* info) c std::vector> argv; uint32_t length = info->GetArgsNumber(); argv.reserve(length); - for (int32_t i = 0; i < length; ++i) { + for (uint32_t i = 0; i < length; ++i) { argv.emplace_back( std::static_pointer_cast(std::make_shared(runtime, info->GetCallArgRef(i)))); } From 401d798904bbd1d82bbbe2ea9ca2558cffeb0769 Mon Sep 17 00:00:00 2001 From: wlh2624 <1968860844@qq.com> Date: Fri, 19 Jul 2024 15:06:36 +0800 Subject: [PATCH 110/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A0=E9=9A=9C?= =?UTF-8?q?=E7=A2=8D=E6=89=8B=E5=8A=BF=E4=BA=8B=E4=BB=B6=E4=B8=8D=E8=A7=A6?= =?UTF-8?q?=E5=8F=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wlh2624 <1968860844@qq.com> Change-Id: I48c1260dddf04b048e9dde4570a675769d047b21 --- .../components_ng/event/gesture_event_hub.cpp | 75 ++++++++++++------- .../components_ng/event/gesture_event_hub.h | 6 ++ 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/frameworks/core/components_ng/event/gesture_event_hub.cpp b/frameworks/core/components_ng/event/gesture_event_hub.cpp index 2d1ae03fa5b..ec2983792e8 100644 --- a/frameworks/core/components_ng/event/gesture_event_hub.cpp +++ b/frameworks/core/components_ng/event/gesture_event_hub.cpp @@ -1308,6 +1308,46 @@ OnAccessibilityEventFunc GestureEventHub::GetOnAccessibilityEventFunc() return callback; } +template +const RefPtr GestureEventHub::AccessibilityRecursionSearchRecognizer(const RefPtr& recognizer) +{ + auto CheckRecognizer = [](const RefPtr& recognizer) { + const auto re = AceType::DynamicCast(recognizer); + if (re != nullptr && re->GetFingers() == 1 && re->GetCount() == 1) { + return true; + } else if (AceType::DynamicCast(recognizer) != nullptr && + AceType::DynamicCast(recognizer)->GetFingers() == 1) { + return true; + } + return false; + }; + + const auto re = AceType::DynamicCast(recognizer); + if (re != nullptr && CheckRecognizer(recognizer)) { + return re; + } else if (AceType::DynamicCast(recognizer) != nullptr) { + for (const auto& recognizerElement : AceType::DynamicCast(recognizer)->GetGroupRecognizer()) { + const auto& tmpRecognizer = AccessibilityRecursionSearchRecognizer(recognizerElement); + if (tmpRecognizer != nullptr) { + return tmpRecognizer; + } + } + } + return nullptr; +} + +template +const RefPtr GestureEventHub::GetAccessibilityRecognizer() +{ + for (const auto& recognizer : gestureHierarchy_) { + const auto& re = AccessibilityRecursionSearchRecognizer(recognizer); + if (re != nullptr) { + return re; + } + } + return nullptr; +} + bool GestureEventHub::ActClick(std::shared_ptr secComphandle) { auto host = GetFrameNode(); @@ -1340,15 +1380,12 @@ bool GestureEventHub::ActClick(std::shared_ptr secComphandle) click(info); return true; } - RefPtr clickRecognizer; - for (auto gestureRecognizer : gestureHierarchy_) { - clickRecognizer = AceType::DynamicCast(gestureRecognizer); - if (clickRecognizer && clickRecognizer->GetFingers() == 1 && clickRecognizer->GetCount() == 1) { - click = clickRecognizer->GetTapActionFunc(); - click(info); - host->OnAccessibilityEvent(AccessibilityEventType::CLICK); - return true; - } + const RefPtr clickRecognizer = GetAccessibilityRecognizer(); + if (clickRecognizer) { + click = clickRecognizer->GetTapActionFunc(); + click(info); + host->OnAccessibilityEvent(AccessibilityEventType::CLICK); + return true; } return false; } @@ -1482,28 +1519,12 @@ OnDragCallbackCore GestureEventHub::GetDragCallback(const RefPtr& bool GestureEventHub::IsAccessibilityClickable() { - bool ret = IsClickable(); - RefPtr clickRecognizer; - for (auto gestureRecognizer : gestureHierarchy_) { - clickRecognizer = AceType::DynamicCast(gestureRecognizer); - if (clickRecognizer && clickRecognizer->GetFingers() == 1 && clickRecognizer->GetCount() == 1) { - return true; - } - } - return ret; + return IsClickable() || GetAccessibilityRecognizer() != nullptr; } bool GestureEventHub::IsAccessibilityLongClickable() { - bool ret = IsLongClickable(); - RefPtr longPressRecognizer; - for (auto gestureRecognizer : gestureHierarchy_) { - longPressRecognizer = AceType::DynamicCast(gestureRecognizer); - if (longPressRecognizer && longPressRecognizer->GetFingers() == 1) { - return true; - } - } - return ret; + return IsLongClickable() || GetAccessibilityRecognizer() != nullptr; } bool GestureEventHub::GetMonopolizeEvents() const diff --git a/frameworks/core/components_ng/event/gesture_event_hub.h b/frameworks/core/components_ng/event/gesture_event_hub.h index 79458f76f52..abab0e43713 100644 --- a/frameworks/core/components_ng/event/gesture_event_hub.h +++ b/frameworks/core/components_ng/event/gesture_event_hub.h @@ -708,6 +708,12 @@ private: void UpdateExtraInfo(const RefPtr& frameNode, std::unique_ptr& arkExtraInfoJson, float scale); + template + const RefPtr GetAccessibilityRecognizer(); + + template + const RefPtr AccessibilityRecursionSearchRecognizer(const RefPtr& recognizer); + WeakPtr eventHub_; RefPtr scrollableActuator_; RefPtr touchEventActuator_; From b7f7fd5cb2405d914ed100ce7ced4fdc4c2a9f9a Mon Sep 17 00:00:00 2001 From: zhoukechen Date: Sat, 20 Jul 2024 19:41:42 +0800 Subject: [PATCH 111/221] =?UTF-8?q?fix=20=E9=87=8D=E5=A4=8D=E9=81=BF?= =?UTF-8?q?=E8=AE=A9=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=A1=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoukechen Change-Id: Iaad1c51b1803ff57bfeb2f0a6ea7a37921e849b6 --- .../core/pipeline_ng/pipeline_context.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/frameworks/core/pipeline_ng/pipeline_context.cpp b/frameworks/core/pipeline_ng/pipeline_context.cpp index d2dede4f7b0..94394ccf7bf 100644 --- a/frameworks/core/pipeline_ng/pipeline_context.cpp +++ b/frameworks/core/pipeline_ng/pipeline_context.cpp @@ -1748,20 +1748,30 @@ void PipelineContext::OnVirtualKeyboardHeightChange(float keyboardHeight, double float offsetFix = (rootSize.Height() - positionY - height) < keyboardHeight ? keyboardHeight - (rootSize.Height() - positionY - height) : keyboardHeight; + auto lastKeyboardOffset = context->safeAreaManager_->GetKeyboardOffset(); + float newKeyboardOffset = 0.0f; if (NearZero(keyboardHeight)) { - context->safeAreaManager_->UpdateKeyboardOffset(0.0f); + newKeyboardOffset = 0.0f; } else if (positionYWithOffset + height > (rootSize.Height() - keyboardHeight) && offsetFix > 0.0f) { - context->safeAreaManager_->UpdateKeyboardOffset(-offsetFix); + newKeyboardOffset = -offsetFix; } else if (LessOrEqual(rootSize.Height() - positionYWithOffset - height, height) && LessOrEqual(rootSize.Height() - positionYWithOffset, keyboardHeight)) { - context->safeAreaManager_->UpdateKeyboardOffset(-keyboardHeight); + newKeyboardOffset = -keyboardHeight; } else if ((positionYWithOffset + height > rootSize.Height() - keyboardHeight && positionYWithOffset < rootSize.Height() - keyboardHeight && height < keyboardHeight / 2.0f) && NearZero(context->rootNode_->GetGeometryNode()->GetFrameOffset().GetY())) { - context->safeAreaManager_->UpdateKeyboardOffset(-height - offsetFix / 2.0f); + newKeyboardOffset = -height - offsetFix / 2.0f; } else { - context->safeAreaManager_->UpdateKeyboardOffset(0.0f); + newKeyboardOffset = 0.0f; } + + if (NearZero(keyboardHeight) || LessOrEqual(newKeyboardOffset, lastKeyboardOffset)) { + context->safeAreaManager_->UpdateKeyboardOffset(newKeyboardOffset); + } else { + TAG_LOGI(AceLogTag::ACE_KEYBOARD, "Calculated keyboardOffset %{public}f is smaller than current" + "keyboardOffset, so keep current keyboardOffset", newKeyboardOffset); + } + TAG_LOGI(AceLogTag::ACE_KEYBOARD, "keyboardHeight: %{public}f, positionY: %{public}f, textHeight: %{public}f, " "rootSize.Height() %{public}f final calculate keyboard offset is %{public}f", From c4187ec99c96a64e0782fac969a23d7706d5318e Mon Sep 17 00:00:00 2001 From: zhoukechen Date: Sat, 20 Jul 2024 19:48:51 +0800 Subject: [PATCH 112/221] =?UTF-8?q?imeShown=E6=B2=A1=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=97=B6=E5=80=99=E7=9A=84=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhoukechen Change-Id: I3419d36e1e5480eb873fbded2cc0d2132abedc17 --- .../pattern/text_field/text_field_manager.h | 12 +++++++++++- .../pattern/text_field/text_field_pattern.cpp | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_manager.h b/frameworks/core/components_ng/pattern/text_field/text_field_manager.h index 877818b428e..08d44effd33 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_manager.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_manager.h @@ -75,12 +75,21 @@ public: bool GetImeShow() const override { - return imeShow_; + if (!imeShow_ && imeAttachCalled_) { + TAG_LOGI(ACE_KEYBOARD, "imeNotShown but attach called, still consider that as shown"); + } + return imeShow_ || imeAttachCalled_; } void SetImeShow(bool imeShow) { imeShow_ = imeShow; + imeAttachCalled_ = false; + } + + void SetImeAttached(bool imeAttached) + { + imeAttachCalled_ = imeAttached; } void SetUIExtensionImeShow(bool imeShow) override @@ -131,6 +140,7 @@ private: WeakPtr onFocusTextField_; WeakPtr weakNavNode_; int32_t onFocusTextFieldId = -1; + bool imeAttachCalled_ = false; bool needToRequestKeyboard_ = true; }; diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index eef2be31291..a5cd591fe9a 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -3647,6 +3647,11 @@ bool TextFieldPattern::RequestKeyboard(bool isFocusViewChanged, bool needStartTw TAG_LOGI(AceLogTag::ACE_KEYBOARD, "Request Softkeyboard, Close CustomKeyboard."); CloseCustomKeyboard(); } + auto context = tmpHost->GetContextRefPtr(); + if (context && context->GetTextFieldManager()) { + auto textFieldManager = DynamicCast(context->GetTextFieldManager()); + textFieldManager->SetImeAttached(true); + } inputMethod->Attach(textChangeListener_, needShowSoftKeyboard, textConfig); UpdateCaretInfoToController(); if (!fillContentMap_.empty()) { From f6202867bdde399d389895592d0acdb89c9b2856 Mon Sep 17 00:00:00 2001 From: gxjhl Date: Fri, 19 Jul 2024 20:12:05 +0800 Subject: [PATCH 113/221] =?UTF-8?q?=E5=BD=93=E7=A6=81=E7=94=A8pan=E6=89=8B?= =?UTF-8?q?=E5=8A=BF=E6=97=B6=E4=B8=8D=E6=8E=A5=E6=94=B6=E6=89=8B=E5=8A=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gxjhl Change-Id: Ib35b8277833d6ce92d60889479eaa52fd5770dc6 --- .../core/components_ng/pattern/scrollable/scrollable.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/core/components_ng/pattern/scrollable/scrollable.cpp b/frameworks/core/components_ng/pattern/scrollable/scrollable.cpp index 5306c3d7c03..5a6c5824006 100644 --- a/frameworks/core/components_ng/pattern/scrollable/scrollable.cpp +++ b/frameworks/core/components_ng/pattern/scrollable/scrollable.cpp @@ -425,8 +425,8 @@ void Scrollable::HandleDragEnd(const GestureEvent& info) isDragUpdateStop_ = false; touchUp_ = false; scrollPause_ = false; - lastVelocity_ = info.GetMainVelocity(); - double gestureVelocity = info.GetMainVelocity(); + lastVelocity_ = GetPanDirection() == Axis::NONE ? 0.0 : info.GetMainVelocity(); + double gestureVelocity = GetPanDirection() == Axis::NONE ? 0.0 : info.GetMainVelocity(); SetDragEndPosition(GetMainOffset(Offset(info.GetGlobalPoint().GetX(), info.GetGlobalPoint().GetY()))); LayoutDirectionEst(gestureVelocity); // Apply max fling velocity limit, it must be calculated after all fling velocity gain. From f6c112ffd7ca9e826382aa86ee80c4442edd8560 Mon Sep 17 00:00:00 2001 From: wangzhihao Date: Mon, 15 Jul 2024 22:31:35 +0800 Subject: [PATCH 114/221] =?UTF-8?q?=E8=B5=B7=E6=8B=96=E6=97=B6=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=8A=A8=E6=95=88=E8=B5=B7=E5=A7=8B=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhihao --- frameworks/core/components_ng/base/frame_node.cpp | 7 +++++++ frameworks/core/components_ng/base/frame_node.h | 1 + frameworks/core/components_ng/event/gesture_event_hub.cpp | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/base/frame_node.cpp b/frameworks/core/components_ng/base/frame_node.cpp index 36dd75e1a80..1b1bbb928ab 100644 --- a/frameworks/core/components_ng/base/frame_node.cpp +++ b/frameworks/core/components_ng/base/frame_node.cpp @@ -3841,6 +3841,13 @@ OffsetF FrameNode::GetOffsetInScreen() return frameOffset; } +OffsetF FrameNode::GetOffsetInSubwindow(const OffsetF& subwindowOffset) +{ + auto frameOffset = GetOffsetInScreen(); + frameOffset -= subwindowOffset; + return frameOffset; +} + RefPtr FrameNode::GetPixelMap() { auto gestureHub = GetOrCreateGestureEventHub(); diff --git a/frameworks/core/components_ng/base/frame_node.h b/frameworks/core/components_ng/base/frame_node.h index 047fdf1f402..f65f4858f29 100644 --- a/frameworks/core/components_ng/base/frame_node.h +++ b/frameworks/core/components_ng/base/frame_node.h @@ -813,6 +813,7 @@ public: return localMat_; } OffsetF GetOffsetInScreen(); + OffsetF GetOffsetInSubwindow(const OffsetF& subwindowOffset); RefPtr GetPixelMap(); RefPtr GetPageNode(); RefPtr GetFirstAutoFillContainerNode(); diff --git a/frameworks/core/components_ng/event/gesture_event_hub.cpp b/frameworks/core/components_ng/event/gesture_event_hub.cpp index 2d1ae03fa5b..ca7dfaec50f 100644 --- a/frameworks/core/components_ng/event/gesture_event_hub.cpp +++ b/frameworks/core/components_ng/event/gesture_event_hub.cpp @@ -937,7 +937,7 @@ void GestureEventHub::OnDragStart(const GestureEvent& info, const RefPtrMoveDragNode(); if (dragNode) { - auto dragNodeOffset = dragNode->GetOffsetInScreen(); + auto dragNodeOffset = dragNode->GetPaintRectOffset(); DragEventActuator::UpdatePreviewPositionAndScale(imageNode, dragNodeOffset); } } @@ -1032,6 +1032,12 @@ void GestureEventHub::OnDragStart(const GestureEvent& info, const RefPtrGetOffsetInSubwindow(window->GetRect().GetOffset())); + if (textNode) { + DragEventActuator::UpdatePreviewPositionAndScale( + textNode, textNode->GetOffsetInSubwindow(window->GetRect().GetOffset())); + } DragEventActuator::MountPixelMap(subWindowOverlayManager, eventHub->GetGestureEventHub(), imageNode, textNode); pipeline->FlushSyncGeometryNodeTasks(); DragAnimationHelper::ShowBadgeAnimation(textNode); From 539b46a90908e1566fa2bd20eb1fe474975a8107 Mon Sep 17 00:00:00 2001 From: vincent Date: Fri, 19 Jul 2024 17:04:37 +0800 Subject: [PATCH 115/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=8B=E6=9F=84?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=97=B6=E8=A7=A6=E5=8F=91=E5=B8=83=E5=B1=80?= =?UTF-8?q?=E5=90=8E=E6=89=8B=E6=9F=84=E4=BD=8D=E7=BD=AE=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vincent Change-Id: Icc809974616fec43839e6810b1fbdd5dc5115c83 --- .../pattern/text_field/text_field_pattern.cpp | 52 ++++++++++++------- .../pattern/text_field/text_field_pattern.h | 2 +- .../text_input/text_field_pattern_test.cpp | 4 +- .../text_input/text_input_update_test.cpp | 4 +- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp index eef2be31291..f7baed705d4 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.cpp @@ -525,7 +525,7 @@ bool TextFieldPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dir if (hostLayoutProperty) { hostLayoutProperty->ResetTextAlignChanged(); } - ProcessOverlayAfterLayout(oldParentGlobalOffset != parentGlobalOffset_); + ProcessOverlayAfterLayout(oldParentGlobalOffset); if (inlineSelectAllFlag_) { HandleOnSelectAll(false, true); inlineSelectAllFlag_ = false; @@ -638,23 +638,37 @@ void TextFieldPattern::HandleContentSizeChange(const RectF& textRect) } } -void TextFieldPattern::ProcessOverlayAfterLayout(bool isGlobalAreaChanged) +void TextFieldPattern::ProcessOverlayAfterLayout(const OffsetF& prevOffset) { - if (processOverlayDelayTask_) { - CHECK_NULL_VOID(HasFocus()); - processOverlayDelayTask_(); - processOverlayDelayTask_ = nullptr; - return; - } - if (isGlobalAreaChanged) { - HandleParentGlobalOffsetChange(); - return; - } - if (needToRefreshSelectOverlay_ && SelectOverlayIsOn()) { - StopTwinkling(); - ProcessOverlay(); - needToRefreshSelectOverlay_ = false; - } + auto pipeline = PipelineContext::GetCurrentContextSafely(); + CHECK_NULL_VOID(pipeline); + pipeline->AddAfterLayoutTask([weak = WeakClaim(this), prevOffset]() { + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->parentGlobalOffset_ = pattern->GetPaintRectGlobalOffset(); + if (pattern->SelectOverlayIsOn()) { + if (pattern->IsSelected()) { + pattern->selectOverlay_->UpdateAllHandlesOffset(); + } else { + pattern->selectOverlay_->UpdateSecondHandleOffset(); + } + } + if (pattern->processOverlayDelayTask_) { + CHECK_NULL_VOID(pattern->HasFocus()); + pattern->processOverlayDelayTask_(); + pattern->processOverlayDelayTask_ = nullptr; + } else if (prevOffset != pattern->parentGlobalOffset_) { + pattern->HandleParentGlobalOffsetChange(); + } else if (pattern->needToRefreshSelectOverlay_ && pattern->SelectOverlayIsOn()) { + if (pattern->IsSelected()) { + pattern->StopTwinkling(); + } else { + pattern->StartTwinkling(); + } + pattern->ProcessOverlay({ .menuIsShow = pattern->selectOverlay_->IsCurrentMenuVisibile() }); + pattern->needToRefreshSelectOverlay_ = false; + } + }); } bool TextFieldPattern::HasFocus() const @@ -711,9 +725,6 @@ void TextFieldPattern::UpdateCaretRect(bool isEditorValueChanged) if (IsSelected()) { selectController_->MoveFirstHandleToContentRect(selectController_->GetFirstHandleIndex()); selectController_->MoveSecondHandleToContentRect(selectController_->GetSecondHandleIndex()); - if (SelectOverlayIsOn()) { - selectOverlay_->UpdateAllHandlesOffset(); - } return; } if (focusHub && !focusHub->IsCurrentFocus() && !obscuredChange_) { @@ -2789,6 +2800,7 @@ void TextFieldPattern::OnModifyDone() needToRefreshSelectOverlay_ = textWidth > 0; UpdateSelection(std::clamp(selectController_->GetStartIndex(), 0, textWidth), std::clamp(selectController_->GetEndIndex(), 0, textWidth)); + SetIsSingleHandle(!IsSelected()); if (isTextChangedAtCreation_ && textWidth == 0) { CloseSelectOverlay(); StartTwinkling(); diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h index 098f6b855f3..9b1fe271f29 100644 --- a/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h +++ b/frameworks/core/components_ng/pattern/text_field/text_field_pattern.h @@ -1442,7 +1442,7 @@ private: void CursorMoveOnClick(const Offset& offset); void DelayProcessOverlay(const OverlayRequest& request = OverlayRequest()); - void ProcessOverlayAfterLayout(bool isGlobalAreaChanged); + void ProcessOverlayAfterLayout(const OffsetF& prevOffset); void ProcessOverlay(const OverlayRequest& request = OverlayRequest()); bool SelectOverlayIsOn() diff --git a/test/unittest/core/pattern/text_input/text_field_pattern_test.cpp b/test/unittest/core/pattern/text_input/text_field_pattern_test.cpp index c6785286413..14da5f9cf2b 100644 --- a/test/unittest/core/pattern/text_input/text_field_pattern_test.cpp +++ b/test/unittest/core/pattern/text_input/text_field_pattern_test.cpp @@ -1673,10 +1673,10 @@ HWTEST_F(TextFieldPatternTest, TextPattern072, TestSize.Level0) RefPtr pattern = textFieldNode->GetPattern(); ASSERT_NE(pattern, nullptr); pattern->needToRefreshSelectOverlay_ = true; - pattern->ProcessOverlayAfterLayout(false); + pattern->ProcessOverlayAfterLayout(OffsetF()); auto func = [] {}; pattern->processOverlayDelayTask_ = func; - pattern->ProcessOverlayAfterLayout(false); + pattern->ProcessOverlayAfterLayout(OffsetF()); } /** diff --git a/test/unittest/core/pattern/text_input/text_input_update_test.cpp b/test/unittest/core/pattern/text_input/text_input_update_test.cpp index a2e86f9bd1d..c150ae34bb9 100644 --- a/test/unittest/core/pattern/text_input/text_input_update_test.cpp +++ b/test/unittest/core/pattern/text_input/text_input_update_test.cpp @@ -507,11 +507,11 @@ HWTEST_F(TextInputUpdateTestNg, ProcessOverlayAfterLayout, TestSize.Level1) */ CreateTextField(DEFAULT_TEXT); - pattern_->ProcessOverlayAfterLayout(true); + pattern_->ProcessOverlayAfterLayout(OffsetF()); GetFocus(); pattern_->HandleSetSelection(5, 10, true); pattern_->needToRefreshSelectOverlay_ = true; - pattern_->ProcessOverlayAfterLayout(false); + pattern_->ProcessOverlayAfterLayout(OffsetF()); EXPECT_FALSE(pattern_->needToRefreshSelectOverlay_); } From c1000ec10ca9e18c4fd2067d9ed2edf35b2eb111 Mon Sep 17 00:00:00 2001 From: Zhang-Dong-hui Date: Sat, 20 Jul 2024 10:58:26 +0000 Subject: [PATCH 116/221] update default children's position when remove custombuilder Signed-off-by: Zhang-Dong-hui Change-Id: If55541cfdbdf026bc78dc3e7149892d183d65b45 --- .../pattern/refresh/refresh_pattern.cpp | 29 ++++++++++++++----- .../pattern/refresh/refresh_pattern.h | 2 ++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/frameworks/core/components_ng/pattern/refresh/refresh_pattern.cpp b/frameworks/core/components_ng/pattern/refresh/refresh_pattern.cpp index 8731541f6a0..1aa24fea97f 100644 --- a/frameworks/core/components_ng/pattern/refresh/refresh_pattern.cpp +++ b/frameworks/core/components_ng/pattern/refresh/refresh_pattern.cpp @@ -82,6 +82,19 @@ void RefreshPattern::OnAttachToFrameNode() host->GetRenderContext()->UpdateClipEdge(true); } +bool RefreshPattern::OnDirtyLayoutWrapperSwap( + const RefPtr& dirty, const DirtySwapConfig& config) +{ + if (isRemoveCustomBuilder_) { + UpdateFirstChildPlacement(); + if (isRefreshing_) { + UpdateLoadingProgressStatus(RefreshAnimationState::RECYCLE, GetFollowRatio()); + } + isRemoveCustomBuilder_ = false; + } + return false; +} + void RefreshPattern::OnModifyDone() { Pattern::OnModifyDone(); @@ -308,11 +321,8 @@ void RefreshPattern::InitChildNode() if (Container::GreatOrEqualAPIVersion(PlatformVersion::VERSION_ELEVEN)) { auto progressContext = progressChild_->GetRenderContext(); CHECK_NULL_VOID(progressContext); - UpdateFirstChildPlacement(); - if (isRefreshing_) { - UpdateLoadingProgressStatus(RefreshAnimationState::RECYCLE, GetFollowRatio()); - } - UpdateLoadingTextOpacity(1.0f); + progressContext->UpdateOpacity(0.0f); + UpdateLoadingTextOpacity(0.0f); } else { UpdateLoadingProgress(); } @@ -523,9 +533,12 @@ void RefreshPattern::AddCustomBuilderNode(const RefPtr& builder) auto host = GetHost(); CHECK_NULL_VOID(host); if (!builder) { - host->RemoveChild(customBuilder_); - isCustomBuilderExist_ = false; - customBuilder_ = nullptr; + if (isCustomBuilderExist_) { + host->RemoveChild(customBuilder_); + isCustomBuilderExist_ = false; + customBuilder_ = nullptr; + isRemoveCustomBuilder_ = true; + } return; } diff --git a/frameworks/core/components_ng/pattern/refresh/refresh_pattern.h b/frameworks/core/components_ng/pattern/refresh/refresh_pattern.h index 0bea78d4354..ecba459d40e 100644 --- a/frameworks/core/components_ng/pattern/refresh/refresh_pattern.h +++ b/frameworks/core/components_ng/pattern/refresh/refresh_pattern.h @@ -105,6 +105,7 @@ public: } private: + bool OnDirtyLayoutWrapperSwap(const RefPtr& dirty, const DirtySwapConfig& config) override; void InitPanEvent(const RefPtr& gestureHub); void HandleDragStart(bool isDrag = true, float mainSpeed = 0.0f); ScrollResult HandleDragUpdate(float delta, float mainSpeed = 0.0f); @@ -156,6 +157,7 @@ private: bool isRefreshing_ = false; bool isKeyEventRegisted_ = false; bool hasLoadingText_ = false; + bool isRemoveCustomBuilder_ = false; RefPtr progressChild_; RefPtr loadingTextNode_; RefPtr columnNode_; From 9b3954a5bcd2b492b58b006489058ceada2d48ac Mon Sep 17 00:00:00 2001 From: kangshihui Date: Sat, 20 Jul 2024 18:30:16 +0800 Subject: [PATCH 117/221] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E5=88=87=E6=8D=A2=E8=87=B3=E5=B0=8F=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E9=AB=98=E5=BA=A6=E4=B8=8E=E5=9C=A8=E5=B0=8F?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E4=B8=AD=E9=87=8D=E6=96=B0=E6=8B=89=E8=B5=B7?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=AB=98=E5=BA=A6=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=20Signed-off-by:kangshihui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I667aefe8fa81b57d657abd966d943c25aae8e7ed --- .../pattern/overlay/overlay_manager.cpp | 66 +++++++++---------- .../pattern/overlay/overlay_manager.h | 7 ++ 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index 211b3c20ddf..176ba2f08cd 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -4841,25 +4841,10 @@ void OverlayManager::PlayKeyboardTransition(const RefPtr& customKeybo option.SetFillMode(FillMode::FORWARDS); auto context = customKeyboard->GetRenderContext(); CHECK_NULL_VOID(context); - auto pipeline = PipelineContext::GetMainPipelineContext(); - CHECK_NULL_VOID(pipeline); - auto pageNode = pipeline->GetStageManager()->GetLastPage(); - if (pageNode == nullptr) { - auto parent = customKeyboard->GetParent(); - CHECK_NULL_VOID(parent); - parent->RemoveChild(customKeyboard); - return; - } - auto pageHeight = pageNode->GetGeometryNode()->GetFrameSize().Height(); - auto keyboardHeight = customKeyboard->GetGeometryNode()->GetFrameSize().Height(); - auto rootNode = rootNodeWeak_.Upgrade(); - CHECK_NULL_VOID(rootNode); - auto finalOffset = rootNode->GetTag() == "Stack" - ? (pageHeight - keyboardHeight) - (pageHeight - keyboardHeight) / NUM_FLOAT_2 - : 0.0f; + auto keyboardOffsetInfo = CalcCustomKeyboardOffset(customKeyboard); if (isTransitionIn) { - context->OnTransformTranslateUpdate({ 0.0f, pageHeight, 0.0f }); - AnimationUtils::Animate(option, [context, finalOffset]() { + context->OnTransformTranslateUpdate({ 0.0f, keyboardOffsetInfo.inAniStartOffset, 0.0f }); + AnimationUtils::Animate(option, [context, finalOffset = keyboardOffsetInfo.finalOffset]() { if (context) { context->OnTransformTranslateUpdate({ 0.0f, finalOffset, 0.0f }); } @@ -4873,11 +4858,12 @@ void OverlayManager::PlayKeyboardTransition(const RefPtr& customKeybo }); AnimationUtils::Animate( option, - [context, keyboardHeight, finalOffset]() { + [context, outAniEndOffset = keyboardOffsetInfo.outAniEndOffset]() { if (context) { - context->OnTransformTranslateUpdate({ 0.0f, finalOffset + keyboardHeight, 0.0f }); + context->OnTransformTranslateUpdate({ 0.0f, outAniEndOffset, 0.0f }); } - }, option.GetOnFinishEvent()); + }, + option.GetOnFinishEvent()); } } @@ -4894,21 +4880,35 @@ void OverlayManager::UpdateCustomKeyboardPosition() } auto renderContext = customKeyboardNode->GetRenderContext(); CHECK_NULL_VOID(renderContext); - auto pipeline = PipelineContext::GetMainPipelineContext(); - CHECK_NULL_VOID(pipeline); - auto pageNode = pipeline->GetStageManager()->GetLastPage(); - CHECK_NULL_VOID(pageNode); - auto pageHeight = pageNode->GetGeometryNode()->GetFrameSize().Height(); - auto keyboardHeight = customKeyboardNode->GetGeometryNode()->GetFrameSize().Height(); - auto rootNode = rootNodeWeak_.Upgrade(); - CHECK_NULL_VOID(rootNode); - auto finalOffset = rootNode->GetTag() == V2::STACK_ETS_TAG - ? (pageHeight - keyboardHeight) - (pageHeight - keyboardHeight) / NUM_FLOAT_2 - : 0.0f; - renderContext->OnTransformTranslateUpdate({ 0.0f, finalOffset, 0.0f }); + auto keyboardOffsetInfo = CalcCustomKeyboardOffset(customKeyboardNode); + renderContext->OnTransformTranslateUpdate({ 0.0f, keyboardOffsetInfo.finalOffset, 0.0f }); } } +CustomKeyboardOffsetInfo OverlayManager::CalcCustomKeyboardOffset(const RefPtr& customKeyboard) +{ + CustomKeyboardOffsetInfo keyboardOffsetInfo; + CHECK_NULL_RETURN(customKeyboard, keyboardOffsetInfo); + auto pipeline = PipelineContext::GetMainPipelineContext(); + CHECK_NULL_RETURN(pipeline, keyboardOffsetInfo); + auto pageNode = pipeline->GetStageManager()->GetLastPage(); + CHECK_NULL_RETURN(pageNode, keyboardOffsetInfo); + auto pageHeight = pageNode->GetGeometryNode()->GetFrameSize().Height(); + auto keyboardHeight = customKeyboard->GetGeometryNode()->GetFrameSize().Height(); + auto rootNode = rootNodeWeak_.Upgrade(); + CHECK_NULL_RETURN(rootNode, keyboardOffsetInfo); + auto finalOffset = 0.0f; + if (rootNode->GetTag() == V2::STACK_ETS_TAG) { + auto rootNd = AceType::DynamicCast(rootNode); + pageHeight = rootNd->GetGeometryNode()->GetFrameSize().Height(); + finalOffset = (pageHeight - keyboardHeight) - (pageHeight - keyboardHeight) / NUM_FLOAT_2; + } + keyboardOffsetInfo.finalOffset = finalOffset; + keyboardOffsetInfo.inAniStartOffset = pageHeight; + keyboardOffsetInfo.outAniEndOffset = finalOffset + keyboardHeight; + return keyboardOffsetInfo; +} + void OverlayManager::BindKeyboard(const std::function& keyboardBuilder, int32_t targetId) { if (customKeyboardMap_.find(targetId) != customKeyboardMap_.end()) { diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.h b/frameworks/core/components_ng/pattern/overlay/overlay_manager.h index 9bd9241b50e..864108be05d 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.h +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.h @@ -88,6 +88,12 @@ struct DismissTarget { bool targetIsSheet = false; }; +struct CustomKeyboardOffsetInfo { + float finalOffset = 0.0f; + float inAniStartOffset = 0.0f; + float outAniEndOffset = 0.0f; +}; + // StageManager is the base class for root render node to perform page switch. class ACE_FORCE_EXPORT OverlayManager : public virtual AceType { DECLARE_ACE_TYPE(OverlayManager, AceType); @@ -762,6 +768,7 @@ private: RefPtr GetOverlayFrameNode(); void MountToParentWithService(const RefPtr& rootNode, const RefPtr& node); void RemoveChildWithService(const RefPtr& rootNode, const RefPtr& node); + CustomKeyboardOffsetInfo CalcCustomKeyboardOffset(const RefPtr& customKeyboard); RefPtr overlayNode_; // Key: frameNode Id, Value: index From f453e56fab195cca3c8ef45b4d2d7065af5c2a12 Mon Sep 17 00:00:00 2001 From: piggyguy_jdx Date: Sat, 20 Jul 2024 12:46:05 +0000 Subject: [PATCH 118/221] fix tool bug Signed-off-by: piggyguy_jdx --- .../event_tree_to_graph/src/graph/graph_converter.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/tools/event_tree_to_graph/src/graph/graph_converter.py b/test/tools/event_tree_to_graph/src/graph/graph_converter.py index 8e685f11645..a825c4216d6 100644 --- a/test/tools/event_tree_to_graph/src/graph/graph_converter.py +++ b/test/tools/event_tree_to_graph/src/graph/graph_converter.py @@ -15,7 +15,12 @@ # limitations under the License. # -import os.path + +# convert the dump result into graphical representation + +import os +import shutil + from typing import List from graphviz import Digraph from src.beans.event_node import EventNode @@ -32,9 +37,7 @@ edge_colors = ['black', 'blue', 'brown', 'purple', 'yellow', 'pink', 'gray'] def reset_output_dir(): - import os if os.path.exists(output_folder): - import shutil shutil.rmtree(output_folder) os.mkdir(output_folder) From 4a838915c5b73c1c3c93cd7251cf88213e33445c Mon Sep 17 00:00:00 2001 From: shihongjie Date: Sat, 20 Jul 2024 20:44:35 +0800 Subject: [PATCH 119/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlisttiem=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E4=B8=8B=E6=A0=91=E4=BE=9D=E7=84=B6=E8=83=BD=E6=BB=91?= =?UTF-8?q?=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shihongjie Change-Id: Id574e1494487f12a2c97a6b908bc77be5fbacbec --- .../pattern/list/list_item_pattern.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp b/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp index 045d3067e2a..14b60a39fe7 100644 --- a/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp +++ b/frameworks/core/components_ng/pattern/list/list_item_pattern.cpp @@ -153,7 +153,7 @@ void ListItemPattern::SetStartNode(const RefPtr& startNode) host->MarkDirtyNode(PROPERTY_UPDATE_BY_CHILD_REQUEST); } } else if (HasStartNode()) { - if (Positive(curOffset_)) { + if (NonNegative(curOffset_)) { curOffset_ = 0.0f; isDragging_ = false; } @@ -188,7 +188,7 @@ void ListItemPattern::SetEndNode(const RefPtr& endNode) host->MarkDirtyNode(PROPERTY_UPDATE_BY_CHILD_REQUEST); } } else if (HasEndNode()) { - if (Negative(curOffset_)) { + if (NonPositive(curOffset_)) { curOffset_ = 0.0f; isDragging_ = false; } @@ -352,7 +352,6 @@ void ListItemPattern::InitSwiperAction(bool axisChanged) auto weak = AceType::WeakClaim(this); auto actionStartTask = [weak](const GestureEvent& info) { auto pattern = weak.Upgrade(); - pattern->isDragging_ = true; CHECK_NULL_VOID(pattern); auto frameNode = pattern->GetListFrameNode(); CHECK_NULL_VOID(frameNode); @@ -379,13 +378,12 @@ void ListItemPattern::InitSwiperAction(bool axisChanged) auto actionEndTask = [weak](const GestureEvent& info) { auto pattern = weak.Upgrade(); - pattern->isDragging_ = false; CHECK_NULL_VOID(pattern); auto frameNode = pattern->GetListFrameNode(); CHECK_NULL_VOID(frameNode); auto listPattern = frameNode->GetPattern(); CHECK_NULL_VOID(listPattern); - if (!listPattern->IsCurrentSwiperItem(weak)) { + if (!listPattern->IsCurrentSwiperItem(weak) || !pattern->isDragging_) { return; } pattern->HandleDragEnd(info); @@ -393,13 +391,12 @@ void ListItemPattern::InitSwiperAction(bool axisChanged) auto actionCancelTask = [weak]() { auto pattern = weak.Upgrade(); - pattern->isDragging_ = false; CHECK_NULL_VOID(pattern); auto frameNode = pattern->GetListFrameNode(); CHECK_NULL_VOID(frameNode); auto listPattern = frameNode->GetPattern(); CHECK_NULL_VOID(listPattern); - if (!listPattern->IsCurrentSwiperItem(weak)) { + if (!listPattern->IsCurrentSwiperItem(weak) || !pattern->isDragging_) { return; } GestureEvent info; @@ -444,6 +441,7 @@ void ListItemPattern::HandleDragStart(const GestureEvent& info) springController_->ClearStopListeners(); springController_->Stop(); } + isDragging_ = true; SetSwiperItemForList(); } @@ -781,6 +779,7 @@ void ListItemPattern::HandleDragEnd(const GestureEvent& info) float velocity = IsRTLAndVertical() ? -info.GetMainVelocity() : info.GetMainVelocity(); bool reachRightSpeed = velocity > SWIPER_SPEED_TH; bool reachLeftSpeed = -velocity > SWIPER_SPEED_TH; + isDragging_ = false; TAG_LOGI(AceLogTag::ACE_LIST, "ListItem HandleDragEnd, velocity:%{public}f, curPos:%{public}f", velocity, curOffset_); From 1e8c04ffa9bce0d5e3db1b1e1d657fa2227bc7c8 Mon Sep 17 00:00:00 2001 From: huqingyun Date: Sat, 20 Jul 2024 13:23:22 +0000 Subject: [PATCH 120/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8DTDD=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=92=8C=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huqingyun Change-Id: I4652a6e88b269844a500df3fea03ef826822fbf2 --- frameworks/core/components_ng/event/focus_hub.cpp | 1 + test/unittest/core/base/frame_node_test_ng.cpp | 2 +- .../unittest/core/base/view_abstract_model_test_ng.cpp | 8 ++++---- test/unittest/core/event/focus_hub_test_ng_new.cpp | 10 +++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/frameworks/core/components_ng/event/focus_hub.cpp b/frameworks/core/components_ng/event/focus_hub.cpp index 41afb7e48cd..d971f46dad2 100644 --- a/frameworks/core/components_ng/event/focus_hub.cpp +++ b/frameworks/core/components_ng/event/focus_hub.cpp @@ -1683,6 +1683,7 @@ bool FocusHub::CalculateRect(const RefPtr& childNode, RectF& rect) con // Calculate currentNode -> childNode offset auto uiNode = frameNode->GetParent(); + CHECK_NULL_RETURN(uiNode, false); while (uiNode != GetFrameNode()) { auto frameNode = AceType::DynamicCast(uiNode); if (!frameNode) { diff --git a/test/unittest/core/base/frame_node_test_ng.cpp b/test/unittest/core/base/frame_node_test_ng.cpp index 01194ed29e7..73941dd1b92 100644 --- a/test/unittest/core/base/frame_node_test_ng.cpp +++ b/test/unittest/core/base/frame_node_test_ng.cpp @@ -726,7 +726,7 @@ HWTEST_F(FrameNodeTestNg, FrameNodeTriggerVisibleAreaChangeCallback0014, TestSiz FRAME_NODE3->layoutProperty_->UpdateVisibility(VisibleType::VISIBLE); FRAME_NODE2->TriggerVisibleAreaChangeCallback(8); EXPECT_TRUE(context->GetOnShow()); - EXPECT_EQ(FRAME_NODE2->lastVisibleRatio_, 0); + EXPECT_EQ(FRAME_NODE2->lastVisibleRatio_, 1); } /** diff --git a/test/unittest/core/base/view_abstract_model_test_ng.cpp b/test/unittest/core/base/view_abstract_model_test_ng.cpp index b7d74ca00b2..ee36495f31d 100644 --- a/test/unittest/core/base/view_abstract_model_test_ng.cpp +++ b/test/unittest/core/base/view_abstract_model_test_ng.cpp @@ -197,11 +197,11 @@ HWTEST_F(ViewAbstractModelTestNg, GetOverlayFromPageTest, TestSize.Level1) auto navPatern = navDestinaion->GetPattern(); ASSERT_NE(navPatern, nullptr); auto overlay = navPatern->GetOverlayManager(); - EXPECT_NE(overlay, nullptr); - EXPECT_TRUE(!targetNode->RootNodeIsPage()); + EXPECT_EQ(overlay, nullptr); + EXPECT_FALSE(!targetNode->RootNodeIsPage()); EXPECT_EQ(targetNode->GetRootNodeId(), 1); - EXPECT_TRUE(!pageNode->RootNodeIsPage()); - EXPECT_EQ(pageNode->GetRootNodeId(), targetNode->GetRootNodeId()); + EXPECT_FALSE(!pageNode->RootNodeIsPage()); + EXPECT_NE(pageNode->GetRootNodeId(), targetNode->GetRootNodeId()); } /** diff --git a/test/unittest/core/event/focus_hub_test_ng_new.cpp b/test/unittest/core/event/focus_hub_test_ng_new.cpp index 7d71a2ae771..f9010047d10 100644 --- a/test/unittest/core/event/focus_hub_test_ng_new.cpp +++ b/test/unittest/core/event/focus_hub_test_ng_new.cpp @@ -170,10 +170,10 @@ HWTEST_F(FocusHubTestNg, FocusHubTestNg0047, TestSize.Level1) focusHub->PaintAllFocusState(); focusHub->CalculatePosition(); focusHub->lastWeakFocusNode_ = AceType::WeakClaim(AceType::RawPtr(focusHub1)); - EXPECT_TRUE(focusHub->CalculatePosition()); + EXPECT_FALSE(focusHub->CalculatePosition()); focusHub1->focusType_ = FocusType::NODE; EXPECT_FALSE(focusHub->PaintAllFocusState()); - EXPECT_TRUE(focusHub->CalculatePosition()); + EXPECT_FALSE(focusHub->CalculatePosition()); } /** @@ -752,9 +752,9 @@ HWTEST_F(FocusHubTestNg, FocusHubTestNg0066, TestSize.Level1) frameNode->children_.push_back(frameNode4); auto res = focusHub->AcceptFocusByRectOfLastFocusScope(RectF(0, 0, -1, -1)); - ASSERT_TRUE(res); + ASSERT_FALSE(res); focusHub->AcceptFocusByRectOfLastFocusScope(RectF()); - ASSERT_TRUE(res); + ASSERT_FALSE(res); } /** @@ -1173,7 +1173,7 @@ HWTEST_F(FocusHubTestNg, FocusHubTestNg0079, TestSize.Level1) frameNode1->GetOrCreateFocusHub(); auto focusHub1 = frameNode1->GetFocusHub(); auto res = focusHub->TryRequestFocus(focusHub1, RectF(), FocusStep::LEFT); - ASSERT_TRUE(res); + ASSERT_FALSE(res); } /** From 5de38fe5abc76201b344b38a11bc8d207737ba0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=8D=A0=E6=B1=9F?= Date: Sat, 20 Jul 2024 13:39:02 +0000 Subject: [PATCH 121/221] =?UTF-8?q?=E3=80=90popup=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dpopup=E6=97=8B=E8=BD=AC=E5=90=8E=E7=AE=AD=E5=A4=B4?= =?UTF-8?q?=E4=BC=9A=E6=97=8B=E8=BD=AC=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 胡占江 Change-Id: Ia41e592f438e5f21cd13b8abb3daa0fb409c76f2 --- .../pattern/bubble/bubble_layout_algorithm.cpp | 3 +++ .../core/components_ng/pattern/bubble/bubble_pattern.cpp | 8 +++++++- .../core/components_ng/pattern/bubble/bubble_pattern.h | 1 + .../components_ng/pattern/overlay/overlay_manager.cpp | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp index 32c5cca48f8..85d267e83af 100644 --- a/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp @@ -440,6 +440,9 @@ void BubbleLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) CHECK_NULL_VOID(frameNode); auto bubblePattern = frameNode->GetPattern(); CHECK_NULL_VOID(bubblePattern); + if (bubblePattern->IsExiting()) { + return; + } const auto& children = layoutWrapper->GetAllChildrenWithBuild(); if (children.empty()) { return; diff --git a/frameworks/core/components_ng/pattern/bubble/bubble_pattern.cpp b/frameworks/core/components_ng/pattern/bubble/bubble_pattern.cpp index 8881f1701fe..8cb2768cb69 100644 --- a/frameworks/core/components_ng/pattern/bubble/bubble_pattern.cpp +++ b/frameworks/core/components_ng/pattern/bubble/bubble_pattern.cpp @@ -94,7 +94,7 @@ void BubblePattern::OnModifyDone() RegisterButtonOnTouch(); } -void BubblePattern::OnAttachToFrameNode() +void BubblePattern::AddPipelineCallBack() { auto host = GetHost(); CHECK_NULL_VOID(host); @@ -102,6 +102,12 @@ void BubblePattern::OnAttachToFrameNode() CHECK_NULL_VOID(pipelineContext); pipelineContext->AddWindowSizeChangeCallback(host->GetId()); pipelineContext->AddWindowStateChangedCallback(host->GetId()); +} + +void BubblePattern::OnAttachToFrameNode() +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); host->GetRenderContext()->SetClipToFrame(true); auto targetNode = FrameNode::GetFrameNode(targetTag_, targetNodeId_); diff --git a/frameworks/core/components_ng/pattern/bubble/bubble_pattern.h b/frameworks/core/components_ng/pattern/bubble/bubble_pattern.h index a61fc9edbec..141c4302f9d 100644 --- a/frameworks/core/components_ng/pattern/bubble/bubble_pattern.h +++ b/frameworks/core/components_ng/pattern/bubble/bubble_pattern.h @@ -135,6 +135,7 @@ public: void OnColorConfigurationUpdate() override; void UpdateBubbleText(); void UpdateText(const RefPtr& node, const RefPtr& popupTheme); + void AddPipelineCallBack(); void SetMessageColor(bool isSetMessageColor) { diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index d394c7dbab8..2cfbf828f16 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -1480,6 +1480,7 @@ void OverlayManager::MountPopup(int32_t targetId, const PopupInfo& popupInfo, auto popupPattern = popupNode->GetPattern(); CHECK_NULL_VOID(popupPattern); + popupPattern->AddPipelineCallBack(); popupPattern->SetInteractiveDismiss(interactiveDismiss); popupPattern->UpdateOnWillDismiss(move(onWillDismiss)); if ((isTypeWithOption && !isShowInSubWindow) || From 5e18e4a4de57ac037398ef33faa33f9dc1c7d972 Mon Sep 17 00:00:00 2001 From: bizhenhang Date: Sat, 20 Jul 2024 13:56:37 +0000 Subject: [PATCH 122/221] fix warning Signed-off-by: bizhenhang Change-Id: Ia681b83891ad2a305c38d2930120cc493d213de9 --- frameworks/core/components/box/render_box.cpp | 2 +- .../common/layout/grid_column_info.h | 18 +++++++++--------- .../core/components/video/resource/player.cpp | 11 ++++++----- .../core/components/video/video_element.cpp | 6 +++--- .../native_interface_xcomponent_impl.h | 2 +- .../components/xcomponent/render_xcomponent.h | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/frameworks/core/components/box/render_box.cpp b/frameworks/core/components/box/render_box.cpp index 8e307e34687..4a2afd5d7fd 100644 --- a/frameworks/core/components/box/render_box.cpp +++ b/frameworks/core/components/box/render_box.cpp @@ -1108,7 +1108,7 @@ bool RenderBox::HandleMouseEvent(const MouseEvent& event) #else LOGI("RenderBox::HandleMouseEvent: Do mouse callback with mouse event{ Global(%{public}f,%{public}f), " "Local(%{public}f,%{public}f)}, Button(%{public}d), Action(%{public}d), Time(%{public}lld), " - "DeviceId(%{public}" PRId64 ", SourceType(%{public}d) }. Return: %{public}d", + "DeviceId(%{private}" PRId64 ", SourceType(%{public}d) }. Return: %{public}d", info.GetGlobalLocation().GetX(), info.GetGlobalLocation().GetY(), info.GetLocalLocation().GetX(), info.GetLocalLocation().GetY(), info.GetButton(), info.GetAction(), info.GetTimeStamp().time_since_epoch().count(), info.GetDeviceId(), info.GetSourceDevice(), diff --git a/frameworks/core/components/common/layout/grid_column_info.h b/frameworks/core/components/common/layout/grid_column_info.h index 1af51abdc6a..34b056c28dd 100644 --- a/frameworks/core/components/common/layout/grid_column_info.h +++ b/frameworks/core/components/common/layout/grid_column_info.h @@ -36,50 +36,50 @@ public: } void SetXsSizeColumn(uint32_t xsSizeColumn, const Dimension& offset = UNDEFINED_DIMENSION) { - columnInfo_->columns_[ScreenSizeType::XS] = xsSizeColumn; + columnInfo_->columns_[ScreenSizeType::XS] = static_cast(xsSizeColumn); columnInfo_->dimOffsets_[ScreenSizeType::XS] = offset; } void SetSmSizeColumn(uint32_t smSizeColumn, const Dimension& offset = UNDEFINED_DIMENSION) { - columnInfo_->columns_[ScreenSizeType::SM] = smSizeColumn; + columnInfo_->columns_[ScreenSizeType::SM] = static_cast(smSizeColumn); columnInfo_->dimOffsets_[ScreenSizeType::SM] = offset; } void SetMdSizeColumn(uint32_t mdSizeColumn, const Dimension& offset = UNDEFINED_DIMENSION) { - columnInfo_->columns_[ScreenSizeType::MD] = mdSizeColumn; + columnInfo_->columns_[ScreenSizeType::MD] = static_cast(mdSizeColumn); columnInfo_->dimOffsets_[ScreenSizeType::MD] = offset; } void SetLgSizeColumn(uint32_t lgSizeColumn, const Dimension& offset = UNDEFINED_DIMENSION) { - columnInfo_->columns_[ScreenSizeType::LG] = lgSizeColumn; + columnInfo_->columns_[ScreenSizeType::LG] = static_cast(lgSizeColumn); columnInfo_->dimOffsets_[ScreenSizeType::LG] = offset; } void SetSizeColumn(GridSizeType type, uint32_t column, const Dimension& offset = UNDEFINED_DIMENSION) { - columnInfo_->columns_[type] = column; + columnInfo_->columns_[type] = static_cast(column); columnInfo_->dimOffsets_[type] = offset; } void SetSmSizeMaxColumn(uint32_t smSizeMaxColumn) { - columnInfo_->maxColumns_[ScreenSizeType::SM] = smSizeMaxColumn; + columnInfo_->maxColumns_[ScreenSizeType::SM] = static_cast(smSizeMaxColumn); } void SetMdSizeMaxColumn(uint32_t mdSizeMaxColumn) { - columnInfo_->maxColumns_[ScreenSizeType::MD] = mdSizeMaxColumn; + columnInfo_->maxColumns_[ScreenSizeType::MD] = static_cast(mdSizeMaxColumn); } void SetLgSizeMaxColumn(uint32_t lgSizeMaxColumn) { - columnInfo_->maxColumns_[ScreenSizeType::LG] = lgSizeMaxColumn; + columnInfo_->maxColumns_[ScreenSizeType::LG] = static_cast(lgSizeMaxColumn); } void SetColumns(uint32_t columns) { - columnInfo_->columns_[ScreenSizeType::UNDEFINED] = columns; + columnInfo_->columns_[ScreenSizeType::UNDEFINED] = static_cast(columns); } void ACE_EXPORT SetOffset(int32_t offset, GridSizeType type = GridSizeType::UNDEFINED); diff --git a/frameworks/core/components/video/resource/player.cpp b/frameworks/core/components/video/resource/player.cpp index 512615b7b24..90a56b878cd 100644 --- a/frameworks/core/components/video/resource/player.cpp +++ b/frameworks/core/components/video/resource/player.cpp @@ -61,6 +61,7 @@ const char PLAYER_ERROR_CODE_CREATEFAIL[] = "error_video_000001"; const char PLAYER_ERROR_MSG_CREATEFAIL[] = "Create player failed."; const char PLAYER_ERROR_CODE_FILEINVALID[] = "error_video_000002"; const char PLAYER_ERROR_MSG_FILEINVALID[] = "File invalid."; +const int32_t DURATION_THOUSAND = 1000; void Player::Create(const std::function& onCreate) { @@ -201,9 +202,9 @@ void Player::SetSurfaceId(int64_t id, bool isTexture) void Player::OnPrepared(const std::string& param) { currentPos_ = 0; - width_ = GetIntParam(param, PLAYER_PARAM_WIDTH); - height_ = GetIntParam(param, PLAYER_PARAM_HEIGHT); - duration_ = GetIntParam(param, PLAYER_PARAM_DURATION) / 1000; + width_ = static_cast(GetIntParam(param, PLAYER_PARAM_WIDTH)); + height_ = static_cast(GetIntParam(param, PLAYER_PARAM_HEIGHT)); + duration_ = static_cast(GetIntParam(param, PLAYER_PARAM_DURATION) / DURATION_THOUSAND); isPlaying_ = GetIntParam(param, PLAYER_PARAM_ISPLAYING) == 1; isNeedFreshForce_ = GetIntParam(param, PLAYER_PARAM_NEEDFRESHFORCE) == 1; isPrepared_ = true; @@ -246,7 +247,7 @@ void Player::OnCompletion(const std::string& param) void Player::OnSeekComplete(const std::string& param) { - currentPos_ = GetIntParam(param, PLAYER_PARAM_CURRENTPOS); + currentPos_ = static_cast(GetIntParam(param, PLAYER_PARAM_CURRENTPOS)); if (!onCurrentPosListener_.empty()) { onCurrentPosListener_.back()(currentPos_); } @@ -304,7 +305,7 @@ void Player::GetCurrentTime() void Player::OnTimeGetted(const std::string& result) { - currentPos_ = GetIntParam(result, PLAYER_PARAM_CURRENTPOS); + currentPos_ = static_cast(GetIntParam(result, PLAYER_PARAM_CURRENTPOS)); if (!onCurrentPosListener_.empty()) { onCurrentPosListener_.back()(currentPos_); } diff --git a/frameworks/core/components/video/video_element.cpp b/frameworks/core/components/video/video_element.cpp index 41224b76563..c985af90c3d 100644 --- a/frameworks/core/components/video/video_element.cpp +++ b/frameworks/core/components/video/video_element.cpp @@ -200,7 +200,7 @@ void VideoElement::InitStatus(const RefPtr& videoComponent) if (isMediaPlayerFullStatus_) { pastPlayingStatus_ = videoComponent->GetPastPlayingStatus(); if (startTime_ != 0) { - currentPos_ = startTime_; + currentPos_ = static_cast(startTime_); IntTimeToText(currentPos_, currentPosText_); } } @@ -1347,7 +1347,7 @@ void VideoElement::OnCurrentTimeChange(uint32_t currentPos) #ifdef OHOS_STANDARD_SYSTEM if (isMediaPlayerFullStatus_ && startTime_ != 0) { if (GreatNotEqual(startTime_, currentPos)) { - currentPos = startTime_; + currentPos = static_cast(startTime_); } } if (currentPos == currentPos_ || isStop_) { @@ -1356,7 +1356,7 @@ void VideoElement::OnCurrentTimeChange(uint32_t currentPos) if (duration_ == 0) { int32_t duration = 0; if (mediaPlayer_->GetDuration(duration) == 0) { - duration_ = duration / MILLISECONDS_TO_SECONDS; + duration_ = static_cast(duration / MILLISECONDS_TO_SECONDS); IntTimeToText(duration_, durationText_); } } diff --git a/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h b/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h index e6e7cd8f889..faf8fb1e60c 100644 --- a/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h +++ b/frameworks/core/components/xcomponent/native_interface_xcomponent_impl.h @@ -431,7 +431,7 @@ private: double x_ = 0.0; double y_ = 0.0; OH_NativeXComponent_TouchEvent touchEvent_; - OH_NativeXComponent_MouseEvent mouseEvent_; + OH_NativeXComponent_MouseEvent mouseEvent_ { .x = 0, .y = 0 }; OH_NativeXComponent_KeyEvent keyEvent_; OH_NativeXComponent_Callback* callback_ = nullptr; OH_NativeXComponent_MouseEvent_Callback* mouseEventCallback_ = nullptr; diff --git a/frameworks/core/components/xcomponent/render_xcomponent.h b/frameworks/core/components/xcomponent/render_xcomponent.h index 3275c9d480b..793cc5ae295 100644 --- a/frameworks/core/components/xcomponent/render_xcomponent.h +++ b/frameworks/core/components/xcomponent/render_xcomponent.h @@ -127,7 +127,7 @@ private: void SetTouchPoint( const std::list& touchInfoList, const int64_t timeStamp, const TouchType& touchType); OH_NativeXComponent_TouchEventType ConvertNativeXComponentTouchEvent(const TouchType& touchType); - OH_NativeXComponent_TouchEvent touchEventPoint_; + OH_NativeXComponent_TouchEvent touchEventPoint_ { .screenX = 0, .screenY = 0 }; std::vector nativeXComponentTouchPoints_; #ifdef OHOS_PLATFORM int64_t startIncreaseTime_ = 0; From 626fe2bd50a44162b96000a3be3e2bdc767a98d1 Mon Sep 17 00:00:00 2001 From: wangzhihao Date: Sat, 20 Jul 2024 22:16:12 +0800 Subject: [PATCH 123/221] =?UTF-8?q?EventColumn=E5=A2=9E=E5=8A=A0=E7=BB=B4?= =?UTF-8?q?=E6=B5=8B=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhihao --- frameworks/core/components_ng/event/drag_event.cpp | 6 ++++-- .../pattern/overlay/overlay_manager.cpp | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/frameworks/core/components_ng/event/drag_event.cpp b/frameworks/core/components_ng/event/drag_event.cpp index 1ec2b564d27..135c8512105 100644 --- a/frameworks/core/components_ng/event/drag_event.cpp +++ b/frameworks/core/components_ng/event/drag_event.cpp @@ -1252,7 +1252,7 @@ void DragEventActuator::ApplyNewestOptionExecutedFromModifierToNode( void DragEventActuator::SetEventColumn(const RefPtr& actuator) { - TAG_LOGD(AceLogTag::ACE_DRAG, "DragEvent start set eventColumn."); + TAG_LOGI(AceLogTag::ACE_DRAG, "DragEvent start set eventColumn."); auto pipelineContext = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipelineContext); auto manager = pipelineContext->GetOverlayManager(); @@ -1285,7 +1285,8 @@ void DragEventActuator::SetEventColumn(const RefPtr& actuator } else { manager->MountEventToRootNode(columnNode); } - TAG_LOGD(AceLogTag::ACE_DRAG, "DragEvent set eventColumn success."); + TAG_LOGI(AceLogTag::ACE_DRAG, "DragEvent set eventColumn success. depth %{public}d, id %{public}d.", + columnNode->GetDepth(), columnNode->GetId()); } void DragEventActuator::HideFilter() @@ -1364,6 +1365,7 @@ void DragEventActuator::HideEventColumn() void DragEventActuator::BindClickEvent(const RefPtr& columnNode) { auto callback = [weak = WeakClaim(this)](GestureEvent& /* info */) { + TAG_LOGI(AceLogTag::ACE_DRAG, "start click event callback"); auto actuator = weak.Upgrade(); CHECK_NULL_VOID(actuator); auto gestureHub = actuator->gestureEventHub_.Upgrade(); diff --git a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp index a261f8396ad..39f921dd525 100644 --- a/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp +++ b/frameworks/core/components_ng/pattern/overlay/overlay_manager.cpp @@ -5268,14 +5268,22 @@ void OverlayManager::RemoveFilter() void OverlayManager::RemoveEventColumn() { if (!hasEvent_) { + TAG_LOGI(AceLogTag::ACE_DRAG, "remove eventColumn, hasEvent is false."); return; } auto columnNode = eventColumnNodeWeak_.Upgrade(); - CHECK_NULL_VOID(columnNode); + if (!columnNode) { + TAG_LOGI(AceLogTag::ACE_DRAG, "remove eventColumn, columnNode is null."); + return; + } auto rootNode = columnNode->GetParent(); - CHECK_NULL_VOID(rootNode); + if (!rootNode) { + TAG_LOGI(AceLogTag::ACE_DRAG, "remove eventColumn, cannot find rootNode."); + return; + } rootNode->RemoveChild(columnNode); hasEvent_ = false; + TAG_LOGI(AceLogTag::ACE_DRAG, "remove eventColumn success, id %{public}d.", columnNode->GetId()); } void OverlayManager::ResetRootNode(int32_t sessionId) From abd9e863dd3dcee82cc87bb2e8a5dca3ece6b69c Mon Sep 17 00:00:00 2001 From: quchongchong Date: Sat, 20 Jul 2024 23:28:13 +0800 Subject: [PATCH 124/221] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmenu=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E8=8F=9C=E5=8D=95=E5=85=B3=E9=97=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: quchongchong Change-Id: Ie3059e163662ac523bf4ca758225ebe55ea44aaa --- .../menu/wrapper/menu_wrapper_pattern.cpp | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.cpp b/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.cpp index af00d7e73a3..ec213cfd0bd 100644 --- a/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.cpp +++ b/frameworks/core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.cpp @@ -25,6 +25,7 @@ #include "core/components_ng/event/click_event.h" #include "core/components_ng/event/gesture_event_hub.h" #include "core/components_ng/pattern/menu/menu_item/menu_item_pattern.h" +#include "core/components_ng/pattern/menu/preview/menu_preview_pattern.h" #include "core/event/touch_event.h" #include "core/pipeline_ng/pipeline_context.h" @@ -308,17 +309,18 @@ RefPtr MenuWrapperPattern::MenuFocusViewShow() auto iter = host->GetChildren().begin(); int32_t focusNodeId = 2; std::advance(iter, host->GetChildren().size() - focusNodeId); - auto focusMenu = *iter; - if (focusMenu) { - auto menuHub = DynamicCast(focusMenu); - CHECK_NULL_RETURN(menuHub, nullptr); - // SelectOverlay's custom menu does not need to be focused. - auto isCustomMenu = IsSelectOverlayCustomMenu(menuHub); - if (!isCustomMenu) { - auto menuPattern = menuHub->GetPattern(); - CHECK_NULL_RETURN(menuPattern, nullptr); - menuPattern->FocusViewShow(); - } + auto focusMenu = DynamicCast(*iter); + CHECK_NULL_RETURN(focusMenu, nullptr); + if (focusMenu->GetPattern()) { + focusMenu = DynamicCast(host->GetChildAtIndex(0)); + CHECK_NULL_RETURN(focusMenu, nullptr); + } + // SelectOverlay's custom menu does not need to be focused. + auto isCustomMenu = IsSelectOverlayCustomMenu(focusMenu); + if (!isCustomMenu) { + auto menuPattern = focusMenu->GetPattern(); + CHECK_NULL_RETURN(menuPattern, nullptr); + menuPattern->FocusViewShow(); } return DynamicCast(focusMenu); } From 436a1d399692d96818feb956786787752aa5bcc7 Mon Sep 17 00:00:00 2001 From: tomkl123 Date: Sun, 21 Jul 2024 09:35:07 +0800 Subject: [PATCH 125/221] =?UTF-8?q?grid=E6=96=B0=E5=A2=9E=E5=B8=83?= =?UTF-8?q?=E5=B1=80=E6=97=B6=E8=A1=8C=E9=AB=98=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tomkl123 Change-Id: I59d05421358417e7bdbb0894d3c45b2cdc1a8eda --- .../grid/grid_scroll/grid_scroll_layout_algorithm.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp index 1a0423b5330..2fedda56935 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp @@ -1416,8 +1416,9 @@ void GridScrollLayoutAlgorithm::AddForwardLines( decltype(gridLayoutInfo_.lineHeightMap_) gridLineHeightMap(std::move(gridLayoutInfo_.lineHeightMap_)); decltype(gridLayoutInfo_.gridMatrix_) gridMatrix(std::move(gridLayoutInfo_.gridMatrix_)); bool addLine = false; + float newLineHeight = -1.0f; while (gridLayoutInfo_.endIndex_ < currentIndex - 1 || mainSpan > measureNumber) { - auto newLineHeight = FillNewLineBackward(crossSize, mainSize, layoutWrapper, true); + newLineHeight = FillNewLineBackward(crossSize, mainSize, layoutWrapper, true); measureNumber++; if (LessNotEqual(newLineHeight, 0.0)) { gridLayoutInfo_.reachEnd_ = true; @@ -1456,8 +1457,10 @@ void GridScrollLayoutAlgorithm::AddForwardLines( gridLayoutInfo_.startMainLineIndex_ = gridLayoutInfo_.endMainLineIndex_ - (forwardLines > 0 ? forwardLines : 0); gridLayoutInfo_.endMainLineIndex_ = endMainLineIndex + (forwardLines < 0 ? forwardLines : 0); gridLayoutInfo_.endIndex_ = endIndex; - TAG_LOGI(AceLogTag::ACE_GRID, "after load forward:start main line %{public}d end main line %{public}d", - gridLayoutInfo_.startMainLineIndex_, gridLayoutInfo_.endMainLineIndex_); + TAG_LOGI(AceLogTag::ACE_GRID, + "after load forward:start main line %{public}d end main line %{public}d, new line height:%{public}f, " + "gridMainSize:%{public}f", + gridLayoutInfo_.startMainLineIndex_, gridLayoutInfo_.endMainLineIndex_, newLineHeight, mainSize); } float GridScrollLayoutAlgorithm::FillNewLineBackward( From d0574cc719ae41dde42d6e8b7891e713c997d6c2 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Sun, 21 Jul 2024 10:58:36 +0800 Subject: [PATCH 126/221] =?UTF-8?q?text=E7=BB=84=E4=BB=B6TDD=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangzhijun8 --- .../core/pattern/text/text_testfive_ng.cpp | 910 +++++++++++++++++- 1 file changed, 905 insertions(+), 5 deletions(-) diff --git a/test/unittest/core/pattern/text/text_testfive_ng.cpp b/test/unittest/core/pattern/text/text_testfive_ng.cpp index a56926ed71e..6934f4498c7 100644 --- a/test/unittest/core/pattern/text/text_testfive_ng.cpp +++ b/test/unittest/core/pattern/text/text_testfive_ng.cpp @@ -16,6 +16,9 @@ #include "text_base.h" #include "test/mock/core/render/mock_canvas_image.h" #include "core/components_ng/render/adapter/pixelmap_image.h" +#include "test/mock/core/pattern/mock_nestable_scroll_container.h" +#include "test/mock/core/common/mock_font_manager.h" +#include "core/components/hyperlink/hyperlink_theme.h" namespace OHOS::Ace::NG { @@ -700,11 +703,11 @@ HWTEST_F(TextTestFiveNg, DrawImage001, TestSize.Level1) pattern->altImage_ = AceType::MakeRefPtr(); ASSERT_NE(pattern->altImage_, nullptr); - EXPECT_EQ(textContentModifier->DrawImage(frameNode, canvas, 0, 0, rect), false); + EXPECT_EQ(textContentModifier->DrawImage(frameNode, canvas, 0, 0, rect), true); pattern->image_ = AceType::MakeRefPtr(); ASSERT_NE(pattern->image_, nullptr); - EXPECT_EQ(textContentModifier->DrawImage(frameNode, canvas, 0, 0, rect), false); + EXPECT_EQ(textContentModifier->DrawImage(frameNode, canvas, 0, 0, rect), true); auto geometryNode = frameNode->geometryNode_; frameNode->geometryNode_ = nullptr; @@ -772,15 +775,19 @@ HWTEST_F(TextTestFiveNg, InheritParentProperties001, TestSize.Level1) pattern->AttachToFrameNode(frameNode); auto pipeline = PipelineContext::GetCurrentContext(); auto theme = AceType::MakeRefPtr(); - pipeline->SetThemeManager(theme); EXPECT_CALL(*theme, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); + auto oldTheme = pipeline->themeManager_; + pipeline->themeManager_ = theme; + auto spanNode = AceType::MakeRefPtr(1); ASSERT_NE(spanNode, nullptr); auto spanItem = spanNode->GetSpanItem(); - ASSERT_NE(spanNode, nullptr); + ASSERT_NE(spanItem, nullptr); EXPECT_EQ(spanItem->InheritParentProperties(frameNode, true), TextStyle()); + + pipeline->themeManager_ = oldTheme; } /** @@ -815,7 +822,7 @@ HWTEST_F(TextTestFiveNg, AdaptMinFontSize001, TestSize.Level1) contentConstraint.maxSize.SetHeight(-1.0); EXPECT_EQ(textAdaptFontSizer->AdaptMinFontSize( - textStyle, content, stepUnit, contentConstraint, layoutWrapper.GetRawPtr()), false); + textStyle, content, stepUnit, contentConstraint, layoutWrapper.GetRawPtr()), true); contentConstraint.maxSize.SetWidth(1.0); contentConstraint.maxSize.SetHeight(1.0); @@ -949,4 +956,897 @@ HWTEST_F(TextTestFiveNg, EncodeTlv001, TestSize.Level1) newImageSpanItem = imageSpanItem->DecodeTlv(buff, cursor); EXPECT_NE(newImageSpanItem, nullptr); } + +/** + * @tc.name: OnHandleLevelModeChanged001 + * @tc.desc: test text_select_overlay.cpp OnHandleLevelModeChanged function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, OnHandleLevelModeChanged001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + + textSelectOverlay->OnAncestorNodeChanged(FRAME_NODE_CHANGE_GEOMETRY_CHANGE); + + textSelectOverlay->handleLevelMode_ = HandleLevelMode::EMBED; + textSelectOverlay->OnHandleLevelModeChanged(HandleLevelMode::OVERLAY); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::OVERLAY); + + textSelectOverlay->handleLevelMode_ = HandleLevelMode::OVERLAY; + textSelectOverlay->OnHandleLevelModeChanged(HandleLevelMode::EMBED); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::EMBED); + + textSelectOverlay->handleLevelMode_ = HandleLevelMode::EMBED; + textSelectOverlay->OnHandleLevelModeChanged(HandleLevelMode::EMBED); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::EMBED); + + textSelectOverlay->handleLevelMode_ = HandleLevelMode::OVERLAY; + textSelectOverlay->OnHandleLevelModeChanged(HandleLevelMode::OVERLAY); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::OVERLAY); +} + +/** + * @tc.name: CreateParagraph001 + * @tc.desc: test text_layout_algorithm.cpp CreateParagraph function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, CreateParagraph001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + pattern->selectOverlayProxy_ = nullptr; + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + + TextStyle textStyle; + LayoutConstraintF contentConstraint; + auto maxSize = MultipleParagraphLayoutAlgorithm::GetMaxMeasureSize(contentConstraint); + + ParagraphStyle externalParagraphStyle; + RefPtr externalParagraph = Paragraph::Create(externalParagraphStyle, FontCollection::Current()); + ASSERT_NE(externalParagraph, nullptr); + pattern->SetExternalParagraph(AceType::RawPtr(externalParagraph)); + + EXPECT_EQ(textLayoutAlgorithm->CreateParagraph(textStyle, "", AceType::RawPtr(frameNode), maxSize.Width()), true); + + pattern->textDetectEnable_ = true; + pattern->copyOption_ = CopyOptions::InApp; + pattern->dataDetectorAdapter_->aiSpanMap_.insert(std::make_pair(0, AISpan())); + + EXPECT_EQ(textLayoutAlgorithm->CreateParagraph(textStyle, "", AceType::RawPtr(frameNode), maxSize.Width()), true); + + pattern->SetExternalParagraphStyle(externalParagraphStyle); + + EXPECT_EQ(textLayoutAlgorithm->CreateParagraph(textStyle, "", AceType::RawPtr(frameNode), maxSize.Width()), true); +} + +/** + * @tc.name: UpdateSymbolTextStyle001 + * @tc.desc: test text_layout_algorithm.cpp UpdateSymbolTextStyle function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, UpdateSymbolTextStyle001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + pattern->selectOverlayProxy_ = nullptr; + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + + auto layoutProperty = AceType::DynamicCast(frameNode->GetLayoutProperty()); + ASSERT_NE(layoutProperty, nullptr); + layoutProperty->UpdateSymbolSourceInfo(SymbolSourceInfo()); + + TextStyle textStyle; + ParagraphStyle paragraphStyle; + NG::SymbolEffectOptions symbolEffectOptions; + + EXPECT_EQ(textLayoutAlgorithm->UpdateSymbolTextStyle( + textStyle, paragraphStyle, AceType::RawPtr(frameNode), frameNode), true); + + textStyle.SetRenderStrategy(-1); + textStyle.SetEffectStrategy(-1); + textStyle.SetSymbolEffectOptions(symbolEffectOptions); + EXPECT_EQ(textLayoutAlgorithm->UpdateSymbolTextStyle( + textStyle, paragraphStyle, AceType::RawPtr(frameNode), frameNode), true); +} + +/** + * @tc.name: AdaptMinTextSize001 + * @tc.desc: test text_layout_algorithm.cpp AdaptMinTextSize function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, AdaptMinTextSize001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + pattern->selectOverlayProxy_ = nullptr; + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + + TextStyle textStyle; + std::string content; + LayoutConstraintF contentConstraint; + + frameNode->pattern_ = nullptr; + EXPECT_EQ(textLayoutAlgorithm->AdaptMinTextSize( + textStyle, content, contentConstraint, AceType::RawPtr(frameNode)), false); + + textStyle.SetAdaptTextSize(Dimension(100, DimensionUnit::PX), + Dimension(10, DimensionUnit::PX), Dimension(10, DimensionUnit::PX)); + EXPECT_EQ(textLayoutAlgorithm->AdaptMinTextSize( + textStyle, content, contentConstraint, AceType::RawPtr(frameNode)), false); + frameNode->pattern_ = pattern; + + textStyle.SetAdaptTextSize(Dimension(100, DimensionUnit::PERCENT), + Dimension(10, DimensionUnit::PERCENT), Dimension(10, DimensionUnit::PERCENT)); + contentConstraint.maxSize.SetHeight(-1.0); + contentConstraint.maxSize.SetWidth(-1.0); + EXPECT_EQ(textLayoutAlgorithm->AdaptMinTextSize( + textStyle, content, contentConstraint, AceType::RawPtr(frameNode)), true); + + auto paragraph = MockParagraph::GetOrCreateMockParagraph(); + std::vector rects { RectF(0, 0, 5, 5) }; + EXPECT_CALL(*paragraph, GetRectsForRange(_, _, _)).WillRepeatedly(SetArgReferee<2>(rects)); + EXPECT_CALL(*paragraph, GetLineCount()).WillRepeatedly(Return(2)); + EXPECT_CALL(*paragraph, GetHeight()).WillRepeatedly(Return(2)); + EXPECT_CALL(*paragraph, GetLongestLine()).WillRepeatedly(Return(2)); + pattern->pManager_->AddParagraph( + { .paragraph = paragraph, .start = 0, .end = 2 }); + + contentConstraint.maxSize.SetHeight(1.0); + contentConstraint.maxSize.SetWidth(1.0); + EXPECT_EQ(textLayoutAlgorithm->AdaptMinTextSize( + textStyle, content, contentConstraint, AceType::RawPtr(frameNode)), true); +} + +/** + * @tc.name: GetGraphemeClusterLength001 + * @tc.desc: test text_base.cpp GetGraphemeClusterLength function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, GetGraphemeClusterLength001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + + std::wstring text; + + EXPECT_EQ(pattern->GetGraphemeClusterLength(text, 0, false), 1); + + text = L"Test"; + + EXPECT_EQ(pattern->GetGraphemeClusterLength(text, 0, true), 1); + EXPECT_EQ(pattern->GetGraphemeClusterLength(text, 10, true), 1); + EXPECT_EQ(pattern->GetGraphemeClusterLength(text, 0, false), 1); + EXPECT_EQ(pattern->GetGraphemeClusterLength(text, 10, false), 1); +} + +/** + * @tc.name: CalculateSelectedRect001 + * @tc.desc: test text_base.cpp CalculateSelectedRect function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, CalculateSelectedRect001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + + std::vector selectedRect; + + selectedRect.emplace_back(RectF(0, 0, 0, 0)); + pattern->CalculateSelectedRect(selectedRect, 0); + EXPECT_EQ(selectedRect.size(), 1); + + selectedRect.emplace_back(RectF(0, 0, 1, 1)); + pattern->CalculateSelectedRect(selectedRect, 1); + EXPECT_EQ(selectedRect.size(), 1); + + selectedRect.emplace_back(RectF(0, 0, 2, 2)); + pattern->CalculateSelectedRect(selectedRect, 2); + EXPECT_EQ(selectedRect.size(), 1); + + selectedRect.emplace_back(RectF(10, 10, 20, 20)); + pattern->CalculateSelectedRect(selectedRect, 10); + EXPECT_EQ(selectedRect.size(), 2); +} + +/** + * @tc.name: GetVisibleRect001 + * @tc.desc: test base_text_select_overlay.cpp GetVisibleRect function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, GetVisibleRect001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + auto parentPattern = AceType::MakeRefPtr(); + ASSERT_NE(parentPattern, nullptr); + auto parentFrameNode = FrameNode::CreateFrameNode("ParentTest", 1, parentPattern); + ASSERT_NE(parentFrameNode, nullptr); + ASSERT_NE(pattern->GetHost(), nullptr); + pattern->GetHost()->SetParent(parentFrameNode); + + RectF visibleRect; + visibleRect.SetRect(0, 0, 10, 10); + + EXPECT_NE(textSelectOverlay->GetVisibleRect(pattern->GetHost(), visibleRect), visibleRect); + + parentFrameNode = FrameNode::CreateFrameNode(V2::PAGE_ETS_TAG, 1, parentPattern); + ASSERT_NE(parentFrameNode, nullptr); + pattern->GetHost()->SetParent(parentFrameNode); + + EXPECT_EQ(textSelectOverlay->GetVisibleRect(pattern->GetHost(), visibleRect), visibleRect); + + auto parentPattern1 = AceType::MakeRefPtr(); + ASSERT_NE(parentPattern1, nullptr); + parentFrameNode = FrameNode::CreateFrameNode("ParentTest", 1, parentPattern1); + ASSERT_NE(parentFrameNode, nullptr); + pattern->GetHost()->SetParent(parentFrameNode); + + EXPECT_EQ(textSelectOverlay->GetVisibleRect(pattern->GetHost(), visibleRect), visibleRect); +} + +/** + * @tc.name: GetLocalPointsWithTransform001 + * @tc.desc: test base_text_select_overlay.cpp GetLocalPointsWithTransform function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, GetLocalPointsWithTransform001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + + textSelectOverlay->hasTransform_ = true; + + std::vector localPoints; + + textSelectOverlay->GetLocalPointsWithTransform(localPoints); + EXPECT_EQ(localPoints.size(), 0); + + localPoints.emplace_back(OffsetF(0, 0)); + localPoints.emplace_back(OffsetF(1, 1)); + textSelectOverlay->GetLocalPointsWithTransform(localPoints); + EXPECT_EQ(localPoints.size(), 2); + EXPECT_EQ(localPoints[0].GetX(), 0); + EXPECT_EQ(localPoints[0].GetY(), 0); + EXPECT_EQ(localPoints[1].GetX(), 1); + EXPECT_EQ(localPoints[1].GetY(), 1); +} + +/** + * @tc.name: GetAncestorNodeViewPort001 + * @tc.desc: test base_text_select_overlay.cpp GetAncestorNodeViewPort function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, GetAncestorNodeViewPort001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + + auto parentPattern1 = AceType::MakeRefPtr(); + ASSERT_NE(parentPattern1, nullptr); + auto parentFrameNode1 = FrameNode::CreateFrameNode("ParentTest", 1, parentPattern1); + ASSERT_NE(parentFrameNode1, nullptr); + ASSERT_NE(pattern->GetHost(), nullptr); + pattern->GetHost()->SetParent(parentFrameNode1); + + EXPECT_EQ(textSelectOverlay->GetAncestorNodeViewPort(), std::nullopt); +} + +/** + * @tc.name: IsAcceptResetSelectionEvent001 + * @tc.desc: test base_text_select_overlay.cpp IsAcceptResetSelectionEvent function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, IsAcceptResetSelectionEvent001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + + EXPECT_EQ(textSelectOverlay->IsAcceptResetSelectionEvent(SourceType::MOUSE, TouchType::DOWN), true); + EXPECT_EQ(textSelectOverlay->IsAcceptResetSelectionEvent(SourceType::MOUSE, TouchType::UP), false); + EXPECT_EQ(textSelectOverlay->IsAcceptResetSelectionEvent(SourceType::TOUCH, TouchType::DOWN), true); + EXPECT_EQ(textSelectOverlay->IsAcceptResetSelectionEvent(SourceType::TOUCH, TouchType::UP), false); + EXPECT_EQ(textSelectOverlay->IsAcceptResetSelectionEvent(SourceType::KEYBOARD, TouchType::DOWN), false); + EXPECT_EQ(textSelectOverlay->IsAcceptResetSelectionEvent(SourceType::KEYBOARD, TouchType::UP), false); +} + +/** + * @tc.name: RevertLocalPointWithTransform001 + * @tc.desc: test base_text_select_overlay.cpp RevertLocalPointWithTransform function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, RevertLocalPointWithTransform001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + + auto parentPattern1 = AceType::MakeRefPtr(); + ASSERT_NE(parentPattern1, nullptr); + auto parentFrameNode1 = FrameNode::CreateFrameNode("ParentTest", 1, parentPattern1); + ASSERT_NE(parentFrameNode1, nullptr); + ASSERT_NE(pattern->GetHost(), nullptr); + pattern->GetHost()->SetParent(parentFrameNode1); + + OffsetF point(10, 10); + + textSelectOverlay->hasTransform_ = true; + textSelectOverlay->RevertLocalPointWithTransform(point); + EXPECT_EQ(point.GetX(), 10); + EXPECT_EQ(point.GetY(), 10); +} + +/** + * @tc.name: HasUnsupportedTransform001 + * @tc.desc: test base_text_select_overlay.cpp HasUnsupportedTransform function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, HasUnsupportedTransform001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + auto renderContext = frameNode->GetRenderContext(); + ASSERT_NE(renderContext, nullptr); + + auto parentPattern = AceType::MakeRefPtr(); + ASSERT_NE(parentPattern, nullptr); + auto parentFrameNode = FrameNode::CreateFrameNode(V2::WINDOW_SCENE_ETS_TAG, 1, parentPattern); + ASSERT_NE(parentFrameNode, nullptr); + ASSERT_NE(pattern->GetHost(), nullptr); + pattern->GetHost()->SetParent(parentFrameNode); + EXPECT_EQ(textSelectOverlay->HasUnsupportedTransform(), false); + pattern->GetHost()->SetParent(nullptr); + + renderContext->UpdateTransformRotate(Vector5F(0, 0, 0, 0, 0)); + EXPECT_EQ(textSelectOverlay->HasUnsupportedTransform(), false); + + renderContext->UpdateTransformRotate(Vector5F(10, 0, 0, 0, 0)); + EXPECT_EQ(textSelectOverlay->HasUnsupportedTransform(), false); + + renderContext->UpdateTransformRotate(Vector5F(0, 10, 0, 0, 0)); + EXPECT_EQ(textSelectOverlay->HasUnsupportedTransform(), false); + + renderContext->UpdateTransformRotate(Vector5F(0, 0, 0, 0, 10)); + EXPECT_EQ(textSelectOverlay->HasUnsupportedTransform(), false); + + renderContext->UpdateTransformMatrix(Matrix4()); + EXPECT_EQ(textSelectOverlay->HasUnsupportedTransform(), false); +} + +/** + * @tc.name: CalcHandleLevelMode001 + * @tc.desc: test base_text_select_overlay.cpp CalcHandleLevelMode function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, CalcHandleLevelMode001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + ASSERT_NE(frameNode->GetGeometryNode(), nullptr); + + frameNode->GetGeometryNode()->SetFrameSize(SizeF(10, 10)); + textSelectOverlay->isChangeToOverlayModeAtEdge_ = false; + + RectF firstRect(3, 3, 5, 5); + RectF secondRect(4, 4, 6, 6); + + textSelectOverlay->CalcHandleLevelMode(firstRect, secondRect); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::EMBED); + + firstRect.SetRect(3, 3, 5, 5); + secondRect.SetRect(11, 11, 15, 15); + + textSelectOverlay->CalcHandleLevelMode(firstRect, secondRect); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::OVERLAY); +} + +/** + * @tc.name: OnAncestorNodeChanged001 + * @tc.desc: test base_text_select_overlay.cpp OnAncestorNodeChanged function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, OnAncestorNodeChanged001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textSelectOverlay = pattern->selectOverlay_; + ASSERT_NE(textSelectOverlay, nullptr); + + FrameNodeChangeInfoFlag frameNodeChangeInfoFlag = 0; + textSelectOverlay->OnAncestorNodeChanged(frameNodeChangeInfoFlag); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::OVERLAY); + + frameNodeChangeInfoFlag = FRAME_NODE_CHANGE_START_SCROLL; + textSelectOverlay->OnAncestorNodeChanged(frameNodeChangeInfoFlag); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::OVERLAY); + + frameNodeChangeInfoFlag = FRAME_NODE_CHANGE_START_ANIMATION; + textSelectOverlay->OnAncestorNodeChanged(frameNodeChangeInfoFlag); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::OVERLAY); + + frameNodeChangeInfoFlag = FRAME_NODE_CHANGE_TRANSFORM_CHANGE; + textSelectOverlay->OnAncestorNodeChanged(frameNodeChangeInfoFlag); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::OVERLAY); + + frameNodeChangeInfoFlag = FRAME_NODE_CHANGE_GEOMETRY_CHANGE; + textSelectOverlay->OnAncestorNodeChanged(frameNodeChangeInfoFlag); + EXPECT_EQ(textSelectOverlay->handleLevelMode_, HandleLevelMode::OVERLAY); +} + +/** + * @tc.name: GetSpanParagraphStyle001 + * @tc.desc: test multiple_paragraph_layout_algorithm.cpp GetSpanParagraphStyle function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, GetSpanParagraphStyle001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + + std::unique_ptr lineStyle = std::make_unique(); + ParagraphStyle pStyle; + + lineStyle->UpdateMaxLines(1024); + lineStyle->UpdateEllipsisMode(EllipsisMode::HEAD); + lineStyle->UpdateLineBreakStrategy(LineBreakStrategy::GREEDY); + lineStyle->UpdateLeadingMargin(LeadingMargin()); + textLayoutAlgorithm->GetSpanParagraphStyle(lineStyle, pStyle); + EXPECT_EQ(pStyle.maxLines, 1024); + EXPECT_EQ(pStyle.ellipsisMode, EllipsisMode::HEAD); + EXPECT_EQ(pStyle.lineBreakStrategy, LineBreakStrategy::GREEDY); +} + +/** + * @tc.name: FontRegisterCallback001 + * @tc.desc: test multiple_paragraph_layout_algorithm.cpp FontRegisterCallback function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, FontRegisterCallback001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + + auto pipeline = frameNode->GetContext(); + ASSERT_NE(pipeline, nullptr); + + auto oldFontManager = pipeline->fontManager_; + pipeline->fontManager_ = AceType::MakeRefPtr(); + + TextStyle textStyle; + std::vector fontFamilies; + + fontFamilies.emplace_back("Arial"); + fontFamilies.emplace_back("Calibri"); + textStyle.SetFontFamilies(fontFamilies); + + textLayoutAlgorithm->FontRegisterCallback(frameNode, textStyle); + EXPECT_EQ(pattern->GetIsCustomFont(), false); + + pipeline->fontManager_ = oldFontManager; +} + +/** + * @tc.name: UpdateTextColorIfForeground001 + * @tc.desc: test multiple_paragraph_layout_algorithm.cpp UpdateTextColorIfForeground function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, UpdateTextColorIfForeground001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + auto renderContext = frameNode->GetRenderContext(); + ASSERT_NE(renderContext, nullptr); + + TextStyle textStyle; + + renderContext->UpdateForegroundColorStrategy(ForegroundColorStrategy::INVERT); + textLayoutAlgorithm->UpdateTextColorIfForeground(frameNode, textStyle); + EXPECT_EQ(textStyle.GetTextColor(), Color::FOREGROUND); + + textStyle.SetTextColor(Color::BLACK); + renderContext->UpdateForegroundColor(Color::BLACK); + textLayoutAlgorithm->UpdateTextColorIfForeground(frameNode, textStyle); + EXPECT_NE(textStyle.GetTextColor(), Color::FOREGROUND); + + textStyle.SetTextColor(Color::WHITE); + renderContext->UpdateForegroundColor(Color::BLACK); + textLayoutAlgorithm->UpdateTextColorIfForeground(frameNode, textStyle); + EXPECT_EQ(textStyle.GetTextColor(), Color::FOREGROUND); +} + +/** + * @tc.name: SetPropertyToModifier001 + * @tc.desc: test multiple_paragraph_layout_algorithm.cpp SetPropertyToModifier function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, SetPropertyToModifier001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + + TextStyle textStyle; + + auto layoutProperty = AceType::DynamicCast(frameNode->GetLayoutProperty()); + ASSERT_NE(layoutProperty, nullptr); + auto modifier = AceType::MakeRefPtr(std::optional(textStyle), pattern); + ASSERT_NE(modifier, nullptr); + + std::vector fontFamilies; + fontFamilies.emplace_back("Arial"); + fontFamilies.emplace_back("Calibri"); + layoutProperty->UpdateFontFamily(fontFamilies); + layoutProperty->UpdateAdaptMaxFontSize(Dimension(1.0)); + layoutProperty->UpdateTextDecorationStyle(TextDecorationStyle::SOLID); + textLayoutAlgorithm->SetPropertyToModifier(layoutProperty, modifier, textStyle); + EXPECT_EQ(modifier->textDecorationStyle_, TextDecorationStyle::SOLID); +} + +/** + * @tc.name: UpdateParagraphBySpan001 + * @tc.desc: test multiple_paragraph_layout_algorithm.cpp UpdateParagraphBySpan function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, UpdateParagraphBySpan001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + + auto layoutWrapper = frameNode->CreateLayoutWrapper(true, true); + ASSERT_NE(layoutWrapper, nullptr); + + auto spanNode = AceType::MakeRefPtr("Test1", 1, pattern); + ASSERT_NE(spanNode, nullptr); + auto spanItem = spanNode->GetSpanItem(); + ASSERT_NE(spanItem, nullptr); + textLayoutAlgorithm->spans_.emplace_back(spanItem); + + ParagraphStyle paraStyle; + TextStyle textStyle; + + paraStyle.maxLines = 1024; + EXPECT_EQ(textLayoutAlgorithm->UpdateParagraphBySpan( + AceType::RawPtr(layoutWrapper), paraStyle, 100, textStyle), true); + + textLayoutAlgorithm->spanStringHasMaxLines_ = true; + EXPECT_EQ(textLayoutAlgorithm->UpdateParagraphBySpan( + AceType::RawPtr(layoutWrapper), paraStyle, 100, textStyle), true); + + textLayoutAlgorithm->spanStringHasMaxLines_ = false; + textLayoutAlgorithm->isSpanStringMode_ = true; + EXPECT_EQ(textLayoutAlgorithm->UpdateParagraphBySpan( + AceType::RawPtr(layoutWrapper), paraStyle, 100, textStyle), true); + + auto paragraph = MockParagraph::GetOrCreateMockParagraph(); + std::vector rects { RectF(0, 0, 5, 5) }; + textLayoutAlgorithm->paragraphManager_->AddParagraph( + { .paragraph = paragraph, .start = 0, .end = 2 }); + EXPECT_EQ(textLayoutAlgorithm->UpdateParagraphBySpan( + AceType::RawPtr(layoutWrapper), paraStyle, 100, textStyle), true); + + std::list> group; + spanNode = AceType::MakeRefPtr("Test2", 2, pattern); + ASSERT_NE(spanNode, nullptr); + spanItem = spanNode->GetSpanItem(); + ASSERT_NE(spanItem, nullptr); + group.emplace_back(spanItem); + auto spanNode1 = AceType::MakeRefPtr("Test", 3, pattern); + ASSERT_NE(spanNode1, nullptr); + auto spanItem1 = spanNode1->GetSpanItem(); + ASSERT_NE(spanItem1, nullptr); + group.emplace_back(spanItem1); + textLayoutAlgorithm->spans_.emplace_back(group); + EXPECT_EQ(textLayoutAlgorithm->UpdateParagraphBySpan( + AceType::RawPtr(layoutWrapper), paraStyle, 100, textStyle), true); +} + +/** + * @tc.name: UpdateParagraphByCustomSpan001 + * @tc.desc: test multiple_paragraph_layout_algorithm.cpp UpdateParagraphByCustomSpan function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, UpdateParagraphByCustomSpan001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + auto textLayoutAlgorithm = AceType::DynamicCast(pattern->CreateLayoutAlgorithm()); + ASSERT_NE(textLayoutAlgorithm, nullptr); + + auto pipeline = PipelineContext::GetCurrentContext(); + auto theme = AceType::MakeRefPtr(); + EXPECT_CALL(*theme, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); + + auto oldTheme = pipeline->themeManager_; + pipeline->themeManager_ = theme; + + auto customSpanItem = AceType::MakeRefPtr(); + ASSERT_NE(customSpanItem, nullptr); + auto layoutWrapper = frameNode->CreateLayoutWrapper(true, true); + ASSERT_NE(layoutWrapper, nullptr); + auto paragraph = MockParagraph::GetOrCreateMockParagraph(); + ASSERT_NE(paragraph, nullptr); + int32_t spanTextLength; + CustomSpanPlaceholderInfo customSpanPlaceholder; + + textLayoutAlgorithm->UpdateParagraphByCustomSpan( + customSpanItem, AceType::RawPtr(layoutWrapper), paragraph, spanTextLength, customSpanPlaceholder); + EXPECT_EQ(customSpanPlaceholder.onDraw, nullptr); + + auto layoutProperty = layoutWrapper->GetLayoutProperty(); + ASSERT_NE(layoutProperty, nullptr); + auto textLayoutProperty = AceType::DynamicCast(layoutProperty); + ASSERT_NE(textLayoutProperty, nullptr); + textLayoutProperty->UpdateFontSize(Dimension(10.0)); + customSpanItem->onMeasure = [](CustomSpanMeasureInfo info)->CustomSpanMetrics { + return CustomSpanMetrics(); + }; + customSpanItem->onDraw = [](NG::DrawingContext& context, CustomSpanOptions options) { + }; + + textLayoutAlgorithm->UpdateParagraphByCustomSpan( + customSpanItem, AceType::RawPtr(layoutWrapper), paragraph, spanTextLength, customSpanPlaceholder); + EXPECT_NE(customSpanPlaceholder.onDraw, nullptr); + + pipeline->themeManager_ = oldTheme; +} + +/** + * @tc.name: UpdateParagraph001 + * @tc.desc: test span_node.cpp UpdateParagraph function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, UpdateParagraph001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + + auto paragraph = MockParagraph::GetOrCreateMockParagraph(); + ASSERT_NE(paragraph, nullptr); + auto fontManager = AceType::MakeRefPtr(); + ASSERT_NE(fontManager, nullptr); + auto pipeline = PipelineContext::GetCurrentContext(); + ASSERT_NE(pipeline, nullptr); + + auto oldFontManager = pipeline->fontManager_; + pipeline->fontManager_ = fontManager; + + auto spanItem = AceType::MakeRefPtr(); + ASSERT_NE(spanItem, nullptr); + + spanItem->UpdateParagraph(frameNode, paragraph, true); + + pattern->textDetectEnable_ = true; + pattern->copyOption_ = CopyOptions::InApp; + pattern->dataDetectorAdapter_->aiSpanMap_.insert(std::make_pair(0, AISpan())); + + EXPECT_EQ(spanItem->UpdateParagraph(frameNode, paragraph, true), -1); + + spanItem->aiSpanMap.insert(std::make_pair(0, AISpan())); + + EXPECT_EQ(spanItem->UpdateParagraph(frameNode, paragraph, true), -1); + + pipeline->fontManager_ = oldFontManager; +} + +/** + * @tc.name: UpdateSymbolSpanParagraph001 + * @tc.desc: test span_node.cpp UpdateSymbolSpanParagraph function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, UpdateSymbolSpanParagraph001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + + auto spanItem = AceType::MakeRefPtr(); + ASSERT_NE(spanItem, nullptr); + auto paragraph = MockParagraph::GetOrCreateMockParagraph(); + ASSERT_NE(paragraph, nullptr); + int32_t callPushStyleCount = 0; + EXPECT_CALL(*paragraph, PushStyle(_)).WillRepeatedly([&callPushStyleCount](){ callPushStyleCount++; }); + + EXPECT_EQ(callPushStyleCount, 0); + + spanItem->fontStyle->UpdateFontSize(Dimension(0)); + spanItem->UpdateSymbolSpanParagraph(nullptr, paragraph); + EXPECT_EQ(callPushStyleCount, 0); + + std::unique_ptr oldFontStyle = std::move(spanItem->fontStyle); + std::unique_ptr oldTextLineStyle = std::move(spanItem->textLineStyle); + spanItem->UpdateSymbolSpanParagraph(frameNode, paragraph); + spanItem->textLineStyle = std::move(oldTextLineStyle); + spanItem->UpdateSymbolSpanParagraph(frameNode, paragraph); + spanItem->fontStyle = std::move(oldFontStyle); + spanItem->UpdateSymbolSpanParagraph(frameNode, paragraph); + EXPECT_EQ(callPushStyleCount, 1); +} + +/** + * @tc.name: UpdateSymbolSpanColor001 + * @tc.desc: test span_node.cpp UpdateSymbolSpanColor function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, UpdateSymbolSpanColor001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + + auto spanItem = AceType::MakeRefPtr(); + ASSERT_NE(spanItem, nullptr); + + TextStyle symbolSpanStyle; + + auto layoutProperty = frameNode->GetLayoutProperty(); + ASSERT_NE(layoutProperty, nullptr); + auto textLayoutProperty = AceType::DynamicCast(layoutProperty); + ASSERT_NE(textLayoutProperty, nullptr); + textLayoutProperty->UpdateTextColor(Color::BLACK); + + spanItem->SetIsParentText(true); + symbolSpanStyle.renderColors_.clear(); + spanItem->UpdateSymbolSpanColor(frameNode, symbolSpanStyle); + EXPECT_EQ(symbolSpanStyle.GetSymbolColorList().size(), 1); + + spanItem->UpdateSymbolSpanColor(frameNode, symbolSpanStyle); + EXPECT_EQ(symbolSpanStyle.GetSymbolColorList().size(), 1); + + spanItem->SetIsParentText(false); + spanItem->UpdateSymbolSpanColor(frameNode, symbolSpanStyle); + EXPECT_EQ(symbolSpanStyle.GetSymbolColorList().size(), 1); +} + +/** + * @tc.name: SetAiSpanTextStyle001 + * @tc.desc: test span_node.cpp SetAiSpanTextStyle function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, SetAiSpanTextStyle001, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + + auto spanItem = AceType::MakeRefPtr(); + ASSERT_NE(spanItem, nullptr); + + std::optional aiSpanTextStyle = std::nullopt; + + spanItem->fontStyle->UpdateFontSize(Dimension(0)); + spanItem->SetAiSpanTextStyle(aiSpanTextStyle); + EXPECT_EQ(aiSpanTextStyle, std::nullopt); + + spanItem->fontStyle->UpdateFontSize(Dimension(10)); + spanItem->SetAiSpanTextStyle(aiSpanTextStyle); + EXPECT_NE(aiSpanTextStyle, std::nullopt); +} + +/** + * @tc.name: FontRegisterCallback001 + * @tc.desc: test span_node.cpp FontRegisterCallback function + * @tc.type: FUNC + */ +HWTEST_F(TextTestFiveNg, FontRegisterCallback002, TestSize.Level1) +{ + auto pattern = AceType::MakeRefPtr(); + ASSERT_NE(pattern, nullptr); + auto frameNode = FrameNode::CreateFrameNode("Test", 1, pattern); + ASSERT_NE(frameNode, nullptr); + pattern->AttachToFrameNode(frameNode); + + auto spanItem = AceType::MakeRefPtr(); + ASSERT_NE(spanItem, nullptr); + + TextStyle textStyle; + std::vector fontFamilies; + + spanItem->FontRegisterCallback(frameNode, textStyle); + + auto pipeline = frameNode->GetContext(); + ASSERT_NE(pipeline, nullptr); + + auto oldFontManager = pipeline->fontManager_; + pipeline->fontManager_ = AceType::MakeRefPtr(); + + fontFamilies.emplace_back("Arial"); + fontFamilies.emplace_back("Calibri"); + textStyle.SetFontFamilies(fontFamilies); + + spanItem->FontRegisterCallback(frameNode, textStyle); + EXPECT_EQ(pattern->GetIsCustomFont(), false); + + pipeline->fontManager_ = oldFontManager; +} } // namespace OHOS::Ace::NG From 1a4267c1aef29fecec762640fc5da9980c1a88ce Mon Sep 17 00:00:00 2001 From: tomkl123 Date: Sun, 21 Jul 2024 10:54:27 +0800 Subject: [PATCH 127/221] =?UTF-8?q?grid=E6=96=B0=E5=A2=9EalignItems?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tomkl123 Change-Id: I4bc1e84b9480d95fc2b25421cbec439a3fadb43e --- .../core/components_ng/pattern/grid/grid_pattern.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp b/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp index adf63ec3498..9967ec1f9e0 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp @@ -1721,6 +1721,16 @@ void GridPattern::DumpAdvanceInfo() property->GetScrollEnabled().has_value() ? DumpLog::GetInstance().AddDesc("ScrollEnabled:" + std::to_string(property->GetScrollEnabled().value())) : DumpLog::GetInstance().AddDesc("ScrollEnabled:null"); + switch (property->GetAlignItems().value_or(GridItemAlignment::DEFAULT)) { + case GridItemAlignment::STRETCH: { + DumpLog::GetInstance().AddDesc("AlignItems:GridItemAlignment.STRETCH"); + break; + } + default: { + DumpLog::GetInstance().AddDesc("AlignItems:GridItemAlignment.DEFAULT"); + break; + } + } switch (gridLayoutInfo_.scrollAlign_) { case ScrollAlign::NONE: { DumpLog::GetInstance().AddDesc("ScrollAlign:NONE"); From 00d76c51c55f50772672d19c6d13230b20ccc05d Mon Sep 17 00:00:00 2001 From: xiehd Date: Sat, 20 Jul 2024 00:22:31 +0800 Subject: [PATCH 128/221] Bugfix: fix accessibility unable to distinguish page/pop event Signed-off-by: xiehd --- .../ohos/osal/js_accessibility_manager.cpp | 21 +++++++++++++------ .../accessibility/accessibility_manager.h | 1 + .../core/accessibility/accessibility_utils.h | 2 ++ .../core/components_ng/base/frame_node.cpp | 15 +++++++++++++ .../core/components_ng/base/frame_node.h | 3 +++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/adapter/ohos/osal/js_accessibility_manager.cpp b/adapter/ohos/osal/js_accessibility_manager.cpp index d162847d168..70bb66cea75 100644 --- a/adapter/ohos/osal/js_accessibility_manager.cpp +++ b/adapter/ohos/osal/js_accessibility_manager.cpp @@ -74,6 +74,11 @@ struct ActionTable { ActionType action; }; +struct FillEventInfoParam { + int64_t elementId; + int64_t stackNodeId; +}; + struct AccessibilityActionParam { RefPtr accessibilityProperty; std::string setTextArgument = ""; @@ -199,6 +204,8 @@ Accessibility::EventType ConvertAceEventType(AccessibilityEventType type) { AccessibilityEventType::HOVER_EXIT_EVENT, Accessibility::EventType::TYPE_VIEW_HOVER_EXIT_EVENT }, { AccessibilityEventType::CHANGE, Accessibility::EventType::TYPE_PAGE_CONTENT_UPDATE }, { AccessibilityEventType::COMPONENT_CHANGE, Accessibility::EventType::TYPE_VIEW_TEXT_UPDATE_EVENT }, + { AccessibilityEventType::PAGE_OPEN, Accessibility::EventType::TYPE_PAGE_OPEN }, + { AccessibilityEventType::PAGE_CLOSE, Accessibility::EventType::TYPE_PAGE_CLOSE }, { AccessibilityEventType::SCROLL_END, Accessibility::EventType::TYPE_VIEW_SCROLLED_EVENT }, { AccessibilityEventType::TEXT_SELECTION_UPDATE, Accessibility::EventType::TYPE_VIEW_TEXT_SELECTION_UPDATE_EVENT }, @@ -1050,8 +1057,8 @@ void FillElementInfo(int64_t elementId, AccessibilityElementInfo& elementInfo, void FillEventInfo(const RefPtr& node, AccessibilityEventInfo& eventInfo, const RefPtr& context, - int64_t elementId, - const RefPtr& jsAccessibilityManager) + const RefPtr& jsAccessibilityManager, + const FillEventInfoParam& param) { CHECK_NULL_VOID(node); if (node->GetTag() == V2::WEB_CORE_TAG) { @@ -1061,7 +1068,7 @@ void FillEventInfo(const RefPtr& node, eventInfo.SetPageId(webAccessibilityNode->GetPageId()); eventInfo.AddContent(webAccessibilityNode->GetContent()); AccessibilityElementInfo elementInfo; - FillElementInfo(elementId, elementInfo, context, jsAccessibilityManager); + FillElementInfo(param.elementId, elementInfo, context, jsAccessibilityManager); eventInfo.SetElementInfo(elementInfo); return; } @@ -1074,7 +1081,8 @@ void FillEventInfo(const RefPtr& node, eventInfo.SetBeginIndex(accessibilityProperty->GetBeginIndex()); eventInfo.SetEndIndex(accessibilityProperty->GetEndIndex()); AccessibilityElementInfo elementInfo; - FillElementInfo(elementId, elementInfo, context, jsAccessibilityManager); + FillElementInfo(param.elementId, elementInfo, context, jsAccessibilityManager); + elementInfo.SetNavDestinationId(param.stackNodeId); eventInfo.SetElementInfo(elementInfo); } @@ -2328,7 +2336,7 @@ void JsAccessibilityManager::FillEventInfoWithNode( { CHECK_NULL_VOID(node); if (node->GetTag() == V2::WEB_CORE_TAG) { - FillEventInfo(node, eventInfo, context, elementId, Claim(this)); + FillEventInfo(node, eventInfo, context, Claim(this), FillEventInfoParam { elementId, -1 }); return; } eventInfo.SetComponentType(node->GetTag()); @@ -2413,7 +2421,8 @@ void JsAccessibilityManager::SendAccessibilityAsyncEvent(const AccessibilityEven ngPipeline = FindPipelineByElementId(accessibilityEvent.nodeId, node); CHECK_NULL_VOID(ngPipeline); CHECK_NULL_VOID(node); - FillEventInfo(node, eventInfo, ngPipeline, accessibilityEvent.nodeId, Claim(this)); + FillEventInfo(node, eventInfo, ngPipeline, Claim(this), + FillEventInfoParam { accessibilityEvent.nodeId, accessibilityEvent.stackNodeId }); eventInfo.SetWindowId(ngPipeline->GetFocusWindowId()); } else { ngPipeline = AceType::DynamicCast(context); diff --git a/frameworks/core/accessibility/accessibility_manager.h b/frameworks/core/accessibility/accessibility_manager.h index 06e3bab59e7..ea22eca947e 100644 --- a/frameworks/core/accessibility/accessibility_manager.h +++ b/frameworks/core/accessibility/accessibility_manager.h @@ -30,6 +30,7 @@ namespace OHOS::Ace { struct AccessibilityEvent { int64_t nodeId = 0; + int64_t stackNodeId = -1; uint32_t windowId = 0; WindowsContentChangeTypes windowContentChangeTypes = CONTENT_CHANGE_TYPE_INVALID; WindowUpdateType windowChangeTypes = WINDOW_UPDATE_INVALID; diff --git a/frameworks/core/accessibility/accessibility_utils.h b/frameworks/core/accessibility/accessibility_utils.h index af086f2dbf5..424d8805b89 100644 --- a/frameworks/core/accessibility/accessibility_utils.h +++ b/frameworks/core/accessibility/accessibility_utils.h @@ -107,6 +107,8 @@ enum class AccessibilityEventType : size_t { ACCESSIBILITY_FOCUS_CLEARED = 0x00010000, TEXT_MOVE_UNIT = 0x00020000, SCROLL_START = 0x01000000, + PAGE_OPEN = 0x20000000, + PAGE_CLOSE = 0x08000000, UNKNOWN, }; diff --git a/frameworks/core/components_ng/base/frame_node.cpp b/frameworks/core/components_ng/base/frame_node.cpp index cb7ae9ae2ce..6c1f5a9bc83 100644 --- a/frameworks/core/components_ng/base/frame_node.cpp +++ b/frameworks/core/components_ng/base/frame_node.cpp @@ -3022,6 +3022,21 @@ void FrameNode::OnAccessibilityEvent( } } +void FrameNode::OnAccessibilityEvent( + AccessibilityEventType eventType, int64_t stackNodeId, WindowsContentChangeTypes windowsContentChangeType) +{ + if (AceApplicationInfo::GetInstance().IsAccessibilityEnabled()) { + AccessibilityEvent event; + event.type = eventType; + event.windowContentChangeTypes = windowsContentChangeType; + event.nodeId = GetAccessibilityId(); + event.stackNodeId = stackNodeId; + auto pipeline = GetContext(); + CHECK_NULL_VOID(pipeline); + pipeline->SendEventToAccessibility(event); + } +} + void FrameNode::OnRecycle() { for (const auto& destroyCallback : destroyCallbacks_) { diff --git a/frameworks/core/components_ng/base/frame_node.h b/frameworks/core/components_ng/base/frame_node.h index 909ab34efe4..7c5633665d7 100644 --- a/frameworks/core/components_ng/base/frame_node.h +++ b/frameworks/core/components_ng/base/frame_node.h @@ -465,6 +465,9 @@ public: void OnAccessibilityEvent( AccessibilityEventType eventType, std::string beforeText, std::string latestContent); + void OnAccessibilityEvent( + AccessibilityEventType eventType, int64_t stackNodeId, WindowsContentChangeTypes windowsContentChangeType); + void MarkNeedRenderOnly(); void OnDetachFromMainTree(bool recursive) override; From 72f68cf3bf3571af72bdbe960fc92ae2e75f96a5 Mon Sep 17 00:00:00 2001 From: carnivore233 Date: Sat, 20 Jul 2024 20:13:17 +0800 Subject: [PATCH 129/221] =?UTF-8?q?=E3=80=90RichEditor=E3=80=91=E9=80=82?= =?UTF-8?q?=E9=85=8D=E6=96=87=E6=9C=AC=E5=BC=95=E6=93=8E=E7=A9=BA=E6=AE=B5?= =?UTF-8?q?=E8=90=BD=E6=97=A0=E6=B3=95=E8=BF=94=E5=9B=9E=E5=AE=9E=E9=99=85?= =?UTF-8?q?=E8=A1=8C=E9=AB=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: carnivore233 --- .../rich_editor_layout_algorithm.cpp | 28 ++++++++++++++++++- .../rich_editor_layout_algorithm.h | 2 ++ .../multiple_paragraph_layout_algorithm.cpp | 10 ++++--- .../multiple_paragraph_layout_algorithm.h | 7 +++++ 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.cpp index 50f17eceb70..f78f27d53b0 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.cpp @@ -67,7 +67,7 @@ void RichEditorLayoutAlgorithm::AppendNewLineSpan() if (StringUtils::ToWstring(lastSpan->content).back() == L'\n') { std::list> newGroup; auto tailNewLineSpan = AceType::MakeRefPtr(); - tailNewLineSpan->content = " \n"; + tailNewLineSpan->content = "\n"; tailNewLineSpan->SetNeedRemoveNewLine(true); CopySpanStyle(lastSpan, tailNewLineSpan); newGroup.push_back(tailNewLineSpan); @@ -285,4 +285,30 @@ void RichEditorLayoutAlgorithm::GetSpanParagraphStyle( { MultipleParagraphLayoutAlgorithm::GetSpanParagraphStyle(lineStyle, pStyle); } + +void RichEditorLayoutAlgorithm::HandleEmptyParagraph(RefPtr paragraph, + const std::list>& spanGroup) +{ + CHECK_NULL_VOID(paragraph && spanGroup.size() == 1); + auto spanItem = spanGroup.front(); + CHECK_NULL_VOID(spanItem); + auto content = spanItem->GetSpanContent(spanItem->GetSpanContent()); + CHECK_NULL_VOID(content.empty()); + auto textStyle = spanItem->GetTextStyle(); + CHECK_NULL_VOID(textStyle); + paragraph->PushStyle(textStyle.value()); +} + +RefPtr RichEditorLayoutAlgorithm::GetParagraphStyleSpanItem(const std::list>& spanGroup) +{ + auto it = spanGroup.begin(); + while (it != spanGroup.end()) { + if (!AceType::DynamicCast(*it)) { + return *it; + } + ++it; + } + return *spanGroup.begin(); +} + } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.h b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.h index f070342a183..575c21c90e4 100644 --- a/frameworks/core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/rich_editor/rich_editor_layout_algorithm.h @@ -44,6 +44,8 @@ public: protected: void GetSpanParagraphStyle(const std::unique_ptr& lineStyle, ParagraphStyle& pStyle) override; + void HandleEmptyParagraph(RefPtr paragraph, const std::list>& spanGroup) override; + RefPtr GetParagraphStyleSpanItem(const std::list>& spanGroup) override; private: OffsetF GetContentOffset(LayoutWrapper* layoutWrapper) override; diff --git a/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.cpp index abc7a51a918..5f8b284b4aa 100644 --- a/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.cpp @@ -432,10 +432,11 @@ bool MultipleParagraphLayoutAlgorithm::UpdateParagraphBySpan(LayoutWrapper* layo auto maxLines = static_cast(paraStyle.maxLines); for (auto && group : spans_) { ParagraphStyle spanParagraphStyle = paraStyle; - if (group.front()) { - GetSpanParagraphStyle(group.front()->textLineStyle, spanParagraphStyle); - if (group.front()->fontStyle->HasFontSize()) { - auto fontSize = group.front()->fontStyle->GetFontSizeValue(); + RefPtr paraStyleSpanItem = GetParagraphStyleSpanItem(group); + if (paraStyleSpanItem) { + GetSpanParagraphStyle(paraStyleSpanItem->textLineStyle, spanParagraphStyle); + if (paraStyleSpanItem->fontStyle->HasFontSize()) { + auto fontSize = paraStyleSpanItem->fontStyle->GetFontSizeValue(); spanParagraphStyle.fontSize = fontSize.ConvertToPxDistribute(textStyle.GetMinFontScale(), textStyle.GetMaxFontScale()); } @@ -492,6 +493,7 @@ bool MultipleParagraphLayoutAlgorithm::UpdateParagraphBySpan(LayoutWrapper* layo preParagraphsPlaceholderCount_ += currentParagraphPlaceholderCount_; currentParagraphPlaceholderCount_ = 0; shadowOffset_ += GetShadowOffset(group); + HandleEmptyParagraph(paragraph, group); paragraph->Build(); ApplyIndent(spanParagraphStyle, paragraph, maxWidth, textStyle); UpdateSymbolSpanEffect(frameNode, paragraph, group); diff --git a/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.h b/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.h index 128a4d7e7c7..41f327a5f1d 100644 --- a/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/text/multiple_paragraph_layout_algorithm.h @@ -57,6 +57,13 @@ protected: const TextStyle& textStyle, const std::string& content, LayoutWrapper* layoutWrapper) const; virtual bool CreateParagraph( const TextStyle& textStyle, std::string content, LayoutWrapper* layoutWrapper, double maxWidth = 0.0) = 0; + virtual void HandleEmptyParagraph(RefPtr paragraph, const std::list>& spanGroup) {} + virtual RefPtr GetParagraphStyleSpanItem(const std::list>& spanGroup) + { + CHECK_NULL_RETURN(!spanGroup.empty(), nullptr); + return spanGroup.front(); + } + void ApplyIndent(ParagraphStyle& paragraphStyle, const RefPtr& paragraph, double width, const TextStyle& textStyle); void ConstructTextStyles( From a1ad6d5f65a5d5d7cb8d088f7c6ba3c1c57531db Mon Sep 17 00:00:00 2001 From: carnivore233 Date: Sat, 20 Jul 2024 20:45:08 +0800 Subject: [PATCH 130/221] =?UTF-8?q?=E3=80=90RichEditor=E3=80=91=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=B7=A8=E7=AB=AF=E6=8B=8D=E7=85=A7=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: carnivore233 --- build/libace.map | 5 + frameworks/base/log/dump_log.h | 2 +- .../components_ng/base/inspector_filter.h | 2 +- .../core/components_ng/pattern/BUILD.gn | 1 + .../menu/menu_item/menu_item_pattern.h | 1 + .../expanded_menu_plugin_loader.h | 83 ++ .../select_overlay/select_overlay_node.cpp | 2 + .../service_collaboration_menu_ace_helper.cpp | 760 ++++++++++++++++++ .../service_collaboration_menu_ace_helper.h | 137 ++++ 9 files changed, 991 insertions(+), 2 deletions(-) create mode 100644 frameworks/core/components_ng/pattern/select_overlay/expanded_menu_plugin_loader.h create mode 100644 frameworks/core/components_ng/pattern/select_overlay/service_collaboration_menu_ace_helper.cpp create mode 100644 frameworks/core/components_ng/pattern/select_overlay/service_collaboration_menu_ace_helper.h diff --git a/build/libace.map b/build/libace.map index f550138a8b0..58d913b1b61 100644 --- a/build/libace.map +++ b/build/libace.map @@ -246,6 +246,11 @@ "OHOS::Ace::NG::CustomNode::FlushReload()"; "OHOS::Ace::CanvasModel::GetInstance()"; + OHOS::Ace::NG::InspectorFilter::*; + OHOS::Ace::NG::ServiceCollaborationMenuAceHelper::*; + OHOS::Ace::NG::ServiceCollaborationAceCallback::*; + OHOS::Ace::DumpLog::*; + virtual?thunk?to?OHOS::Ace::Animator::~Animator??; virtual?thunk?to?OHOS::Ace::Frontend::MaybeRelease*; virtual?thunk?to?OHOS::Ace::Frontend::~Frontend*; diff --git a/frameworks/base/log/dump_log.h b/frameworks/base/log/dump_log.h index 2dac7f97d1f..ef80503fce6 100644 --- a/frameworks/base/log/dump_log.h +++ b/frameworks/base/log/dump_log.h @@ -29,7 +29,7 @@ namespace OHOS::Ace { -class DumpLog : public Singleton { +class ACE_FORCE_EXPORT DumpLog : public Singleton { DECLARE_SINGLETON(DumpLog); public: diff --git a/frameworks/core/components_ng/base/inspector_filter.h b/frameworks/core/components_ng/base/inspector_filter.h index dd064f85703..c99a6da6237 100644 --- a/frameworks/core/components_ng/base/inspector_filter.h +++ b/frameworks/core/components_ng/base/inspector_filter.h @@ -36,7 +36,7 @@ enum FixedAttrBit : uint64_t { FIXED_ATTR_FOCUSED = 7, /* "focused" */ }; -class ACE_EXPORT InspectorFilter { +class ACE_FORCE_EXPORT InspectorFilter { public: InspectorFilter() {} bool CheckFixedAttr(const FixedAttrBit attrBit) const; diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index c14bd822f5d..523fdde88e5 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -397,6 +397,7 @@ build_component_ng("pattern_ng") { "select_overlay/select_overlay_paint_method.cpp", "select_overlay/select_overlay_pattern.cpp", "select_overlay/select_overlay_property.cpp", + "select_overlay/service_collaboration_menu_ace_helper.cpp", "shape/circle_model_ng.cpp", "shape/ellipse_model_ng.cpp", "shape/line_layout_algorithm.cpp", diff --git a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_pattern.h b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_pattern.h index 480ce3699e3..08780f43811 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_pattern.h +++ b/frameworks/core/components_ng/pattern/menu/menu_item/menu_item_pattern.h @@ -232,6 +232,7 @@ protected: RefPtr GetMenuWrapper(); private: + friend class ServiceCollaborationMenuAceHelper; // register menu item's callback void RegisterOnClick(); void RegisterOnHover(); diff --git a/frameworks/core/components_ng/pattern/select_overlay/expanded_menu_plugin_loader.h b/frameworks/core/components_ng/pattern/select_overlay/expanded_menu_plugin_loader.h new file mode 100644 index 00000000000..53eea6d639d --- /dev/null +++ b/frameworks/core/components_ng/pattern/select_overlay/expanded_menu_plugin_loader.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2024 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_CORE_COMPONENTS_NG_PATTERNS_EXPANDED_MENU_PLUGIN_LOADER_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_EXPANDED_MENU_PLUGIN_LOADER_H + +#ifndef WINDOWS_PLATFORM +#include +#endif + +namespace OHOS::Ace::NG { + +class ExpandedMenuPluginLoader { +#if (defined(__aarch64__) || defined(__x86_64__)) + const std::string EXPANDED_MENU_PLUGIN_SO_PATH = "/system/lib64/expanded_menu/libexpanded_menu.z.so"; +#else + const std::string EXPANDED_MENU_PLUGIN_SO_PATH = "/system/lib/expanded_menu/libexpanded_menu.z.so"; +#endif + typedef void (*CreateDeviceMenuFunc)( + const RefPtr& menuWrapper, + const std::shared_ptr& info + ); + +public: + static ExpandedMenuPluginLoader& GetInstance() + { + static ExpandedMenuPluginLoader instance; + return instance; + } + + bool LoadPlugin() + { +#ifndef WINDOWS_PLATFORM + CHECK_NULL_RETURN(!createDeviceMenu, true); + expandedMenuPluginHandle = dlopen(EXPANDED_MENU_PLUGIN_SO_PATH.c_str(), RTLD_LAZY); + if (!expandedMenuPluginHandle) { + TAG_LOGI(AceLogTag::ACE_MENU, "dlopen lib %{public}s Fail", EXPANDED_MENU_PLUGIN_SO_PATH.c_str()); + return false; + } + TAG_LOGI(AceLogTag::ACE_MENU, "dlopen lib %{public}s success", EXPANDED_MENU_PLUGIN_SO_PATH.c_str()); + createDeviceMenu = (CreateDeviceMenuFunc)(dlsym(expandedMenuPluginHandle, "CreateDeviceMenu")); + if (!createDeviceMenu) { + TAG_LOGI(AceLogTag::ACE_MENU, "CreateDeviceMenu func load failed"); + return false; + } + return true; +#endif + } + + void CreateServiceCollaborationMenu(const RefPtr& menuWrapper, + const std::shared_ptr& info) + { +#ifndef WINDOWS_PLATFORM + CHECK_NULL_VOID(menuWrapper); + CHECK_NULL_VOID(info); + CHECK_NULL_VOID(LoadPlugin()); + if (!createDeviceMenu) { + TAG_LOGI(AceLogTag::ACE_MENU, "dynamic create expended menu failed"); + return; + } + TAG_LOGI(AceLogTag::ACE_MENU, "dynamic create expended menu"); + createDeviceMenu(menuWrapper, info); + menuWrapper->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD); +#endif + } + + void *expandedMenuPluginHandle; + CreateDeviceMenuFunc createDeviceMenu; +}; +} // namespace OHOS::Ace::NG +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_EXPANDED_MENU_PLUGIN_LOADER_H \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/select_overlay/select_overlay_node.cpp b/frameworks/core/components_ng/pattern/select_overlay/select_overlay_node.cpp index 1004229eef0..1da76b5e73e 100644 --- a/frameworks/core/components_ng/pattern/select_overlay/select_overlay_node.cpp +++ b/frameworks/core/components_ng/pattern/select_overlay/select_overlay_node.cpp @@ -46,6 +46,7 @@ #include "core/components_ng/pattern/security_component/paste_button/paste_button_model_ng.h" #include "core/components_ng/pattern/security_component/security_component_pattern.h" #include "core/components_ng/pattern/select_content_overlay/select_content_overlay_pattern.h" +#include "core/components_ng/pattern/select_overlay/expanded_menu_plugin_loader.h" #include "core/components_ng/pattern/select_overlay/select_overlay_property.h" #include "core/components_ng/pattern/text/text_pattern.h" #include "core/components_ng/property/calc_length.h" @@ -1761,6 +1762,7 @@ RefPtr SelectOverlayNode::CreateMenuNode(const std::shared_ptr