diff --git a/adapter/ohos/osal/js_accessibility_manager.cpp b/adapter/ohos/osal/js_accessibility_manager.cpp index 5fffbb94af3ce9c1140209105a75fec5ddd41156..0774c19c962b2bfca56fdcbf76eda1cb59b8ed44 100644 --- a/adapter/ohos/osal/js_accessibility_manager.cpp +++ b/adapter/ohos/osal/js_accessibility_manager.cpp @@ -2122,6 +2122,7 @@ std::string JsAccessibilityManager::GetPagePath() CHECK_NULL_RETURN(context, ""); auto frontend = context->GetFrontend(); CHECK_NULL_RETURN(frontend, ""); + ContainerScope scope(context->GetInstanceId()); return frontend->GetPagePath(); } diff --git a/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp index c75da6ec4fe57f37171d2d1ffd6ad1a8cd29d317..885b4f9ee8935449a3d2a7fa7146b24fb871c263 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp @@ -34,7 +34,7 @@ void GridAdaptiveLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper) { auto gridLayoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_VOID(gridLayoutProperty); - auto layoutDirection = gridLayoutProperty->GetLayoutDirection().value_or(FlexDirection::ROW); + auto layoutDirection = gridLayoutProperty->GetGridDirection().value_or(FlexDirection::ROW); auto axis = (layoutDirection == FlexDirection::ROW || layoutDirection == FlexDirection::ROW_REVERSE) ? Axis::HORIZONTAL : Axis::VERTICAL; @@ -156,7 +156,7 @@ OffsetF GridAdaptiveLayoutAlgorithm::CalculateChildOffset(int32_t index, LayoutW auto layoutProperty = AceType::DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_RETURN(layoutProperty, OffsetF()); auto padding = layoutProperty->CreatePaddingAndBorder(); - auto layoutDirection = layoutProperty->GetLayoutDirection().value_or(FlexDirection::ROW); + auto layoutDirection = layoutProperty->GetGridDirection().value_or(FlexDirection::ROW); auto scale = layoutProperty->GetLayoutConstraint()->scaleProperty; auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); auto columnsGap = diff --git a/frameworks/core/components_ng/pattern/grid/grid_layout_property.cpp b/frameworks/core/components_ng/pattern/grid/grid_layout_property.cpp index 4ce87b6b5aa0fa3f2ce885a8ed9e34a6d153f111..fd527118a0205d104957b425cb98f6e66a480fbe 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_layout_property.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_layout_property.cpp @@ -43,16 +43,16 @@ void GridLayoutProperty::ToJsonValue(std::unique_ptr& json) const json->Put("rowsGap", propRowsGap_.value_or(0.0_vp).ToString().c_str()); json->Put("cachedCount", propCachedCount_.value_or(1)); json->Put("editMode ", propEditable_.value_or(false) ? "true" : "false"); - json->Put("layoutDirection ", GetLayoutDirectionStr().c_str()); + json->Put("layoutDirection ", GetGridDirectionStr().c_str()); json->Put("maxCount ", propMaxCount_.value_or(Infinity())); json->Put("minCount ", propMinCount_.value_or(1)); json->Put("cellLength ", propCellLength_.value_or(0)); } -std::string GridLayoutProperty::GetLayoutDirectionStr() const +std::string GridLayoutProperty::GetGridDirectionStr() const { - auto layoutDirection = propLayoutDirection_.value_or(FlexDirection::ROW); - switch (layoutDirection) { + auto gridDirection = propGridDirection_.value_or(FlexDirection::ROW); + switch (gridDirection) { case FlexDirection::ROW: return "GridDirection.Row"; case FlexDirection::ROW_REVERSE: @@ -62,7 +62,7 @@ std::string GridLayoutProperty::GetLayoutDirectionStr() const case FlexDirection::COLUMN_REVERSE: return "GridDirection.ColumnReverse"; default: - LOGE("layout direction %{public}d is not valid", layoutDirection); + LOGE("grid direction %{public}d is not valid", gridDirection); break; } return "GridDirection.Row"; diff --git a/frameworks/core/components_ng/pattern/grid/grid_layout_property.h b/frameworks/core/components_ng/pattern/grid/grid_layout_property.h index 70d1aa680dd6e0f2ca2823515815cf890cd58b99..fed2c96c604b6ff67a2e83ca705f0421cab38cbf 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_layout_property.h +++ b/frameworks/core/components_ng/pattern/grid/grid_layout_property.h @@ -44,7 +44,7 @@ public: value->propRowsGap_ = CloneRowsGap(); value->propColumnsGap_ = CloneColumnsGap(); value->propCachedCount_ = CloneCachedCount(); - value->propLayoutDirection_ = CloneLayoutDirection(); + value->propGridDirection_ = CloneGridDirection(); value->propMaxCount_ = CloneMaxCount(); value->propMinCount_ = CloneMinCount(); value->propCellLength_ = CloneCellLength(); @@ -59,7 +59,7 @@ public: ResetColumnsGap(); ResetRowsGap(); ResetCachedCount(); - ResetLayoutDirection(); + ResetGridDirection(); ResetMaxCount(); ResetMinCount(); ResetCellLength(); @@ -105,8 +105,8 @@ public: ResetGridLayoutInfoAndMeasure(); } - ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(LayoutDirection, FlexDirection); - void OnLayoutDirectionUpdate(FlexDirection /*layoutDirection*/) const + ACE_DEFINE_PROPERTY_ITEM_FUNC_WITHOUT_GROUP(GridDirection, FlexDirection); + void OnGridDirectionUpdate(FlexDirection /*gridDirection*/) const { ResetGridLayoutInfoAndMeasure(); } @@ -136,7 +136,7 @@ private: void ResetGridLayoutInfoAndMeasure() const; std::string GetBarStateString() const; - std::string GetLayoutDirectionStr() const; + std::string GetGridDirectionStr() const; Color GetBarColor() const; Dimension GetBarWidth() const; }; diff --git a/frameworks/core/components_ng/pattern/grid/grid_model_ng.cpp b/frameworks/core/components_ng/pattern/grid/grid_model_ng.cpp index 0160819d9c802368d30bc733fb9cc91fe179a65e..cda62ea4cc27beb3215fe8a91f5d5185ec680b05 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_model_ng.cpp @@ -124,7 +124,7 @@ void GridModelNG::SetIsRTL(bool rightToLeft) {} void GridModelNG::SetLayoutDirection(FlexDirection value) { - ACE_UPDATE_LAYOUT_PROPERTY(GridLayoutProperty, LayoutDirection, value); + ACE_UPDATE_LAYOUT_PROPERTY(GridLayoutProperty, GridDirection, value); } void GridModelNG::SetMaxCount(int32_t value) 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 1a08912d1f81904a1c2e5e40d9262e068318d1a2..2f7e0594430eefb67b0e4144c88c4e954c882406 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 @@ -288,10 +288,9 @@ void GridScrollLayoutAlgorithm::ModifyCurrentOffsetWhenReachEnd(float mainSize) gridLayoutInfo_.reachEnd_ = false; return; } - // Step1. Calculate total length of all items with cross gap in viewport. + // Step1. Calculate total length of all items with main gap in viewport. // [lengthOfItemsInViewport] must be greater than or equal to viewport height float lengthOfItemsInViewport = gridLayoutInfo_.GetTotalHeightOfItemsInView(mainGap_); - // Step2. Calculate real offset that items can only be moved up by. // Hint: [prevOffset_] is a non-positive value if (LessNotEqual(lengthOfItemsInViewport, mainSize) && gridLayoutInfo_.startIndex_ == 0) { diff --git a/frameworks/core/components_ng/test/mock/base/mock_view_abstract.cpp b/frameworks/core/components_ng/test/mock/base/mock_view_abstract.cpp new file mode 100644 index 0000000000000000000000000000000000000000..df3dc82976b4966fa6623b606eef0815547214fb --- /dev/null +++ b/frameworks/core/components_ng/test/mock/base/mock_view_abstract.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 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 "core/components_ng/base/view_abstract.h" +#include "core/components_ng/base/view_stack_processor.h" + +namespace OHOS::Ace::NG { +void ViewAbstract::SetHeight(const CalcLength& height) +{ + if (!ViewStackProcessor::GetInstance()->IsCurrentVisualStateProcess()) { + return; + } + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNode); + auto layoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_VOID(layoutProperty); + layoutProperty->UpdateUserDefinedIdealSize(CalcSize(std::nullopt, height)); +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/test/mock/rosen/testing_pen.h b/frameworks/core/components_ng/test/mock/rosen/testing_pen.h index e137e29ba4b02ab15a98bdb9e5e315cc45691195..adfe5c2c376e60502a91df366a83ab9409bbaae5 100644 --- a/frameworks/core/components_ng/test/mock/rosen/testing_pen.h +++ b/frameworks/core/components_ng/test/mock/rosen/testing_pen.h @@ -36,6 +36,7 @@ public: ~TestingPen() = default; virtual void SetAntiAlias(bool aa) {} + virtual void SetBlendMode(BlendMode mode) {} virtual void SetWidth(float width) {} virtual void SetCapStyle(CapStyle cap) {} virtual void SetColor(const TestingColor& color) {} diff --git a/frameworks/core/components_ng/test/pattern/grid/BUILD.gn b/frameworks/core/components_ng/test/pattern/grid/BUILD.gn index edc00c680276f9aacd14fc2b12b76d8fc019ae89..f27e2fe0a66a3b0198563095d179e1cc72b39eb8 100644 --- a/frameworks/core/components_ng/test/pattern/grid/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/grid/BUILD.gn @@ -19,25 +19,137 @@ import( ohos_unittest("grid_test_ng") { module_out_path = "$test_output_path/grid" - sources = [ "grid_test_ng.cpp" ] + include_dirs = [ + "//commonlibrary/c_utils/base/include", + "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/include", + ] - deps = [ - "$ace_root/build:ace_ohos_unittest_base", - "$ace_root/frameworks/core/components_ng/base:ace_core_components_base_ng_ohos", + sources = [ + # inner + "$ace_root/frameworks/base/geometry/animatable_dimension.cpp", + "$ace_root/frameworks/base/geometry/dimension.cpp", + "$ace_root/frameworks/base/geometry/least_square_impl.cpp", + "$ace_root/frameworks/base/geometry/matrix3.cpp", + "$ace_root/frameworks/base/geometry/matrix4.cpp", + "$ace_root/frameworks/base/json/json_util.cpp", + "$ace_root/frameworks/base/log/dump_log.cpp", + "$ace_root/frameworks/base/utils/base_id.cpp", + "$ace_root/frameworks/base/utils/string_expression.cpp", + "$ace_root/frameworks/base/utils/string_utils.cpp", + "$ace_root/frameworks/core/animation/anticipate_curve.cpp", + "$ace_root/frameworks/core/animation/cubic_curve.cpp", + "$ace_root/frameworks/core/animation/curves.cpp", + "$ace_root/frameworks/core/animation/friction_motion.cpp", + "$ace_root/frameworks/core/components/common/layout/grid_column_info.cpp", + "$ace_root/frameworks/core/components/common/layout/grid_container_info.cpp", + "$ace_root/frameworks/core/components/common/layout/grid_system_manager.cpp", + "$ace_root/frameworks/core/components/common/layout/screen_system_manager.cpp", + "$ace_root/frameworks/core/components/common/properties/alignment.cpp", + "$ace_root/frameworks/core/components/common/properties/color.cpp", + "$ace_root/frameworks/core/components_v2/grid/grid_event.cpp", + "$ace_root/frameworks/core/components_v2/inspector/inspector_constants.cpp", + "$ace_root/frameworks/core/gestures/velocity_tracker.cpp", + "$ace_root/frameworks/core/pipeline/base/constants.cpp", + "$ace_root/frameworks/core/pipeline/base/related_node.cpp", + + # components_ng_base + "$ace_root/frameworks/core/components_ng/base/frame_node.cpp", + "$ace_root/frameworks/core/components_ng/base/geometry_node.cpp", + "$ace_root/frameworks/core/components_ng/base/ui_node.cpp", + "$ace_root/frameworks/core/components_ng/base/view_stack_processor.cpp", + "$ace_root/frameworks/core/components_ng/manager/drag_drop/drag_drop_manager.cpp", + "$ace_root/frameworks/core/components_ng/manager/drag_drop/drag_drop_proxy.cpp", + "$ace_root/frameworks/core/components_ng/render/paint_wrapper.cpp", + + # components_ng_layout + "$ace_root/frameworks/core/components_ng/layout/box_layout_algorithm.cpp", + "$ace_root/frameworks/core/components_ng/layout/layout_property.cpp", + "$ace_root/frameworks/core/components_ng/layout/layout_wrapper.cpp", + "$ace_root/frameworks/core/components_ng/layout/layout_wrapper_builder.cpp", + + # components_ng_property + "$ace_root/frameworks/core/components_ng/property/calc_length.cpp", + "$ace_root/frameworks/core/components_ng/property/grid_property.cpp", + "$ace_root/frameworks/core/components_ng/property/measure_utils.cpp", + "$ace_root/frameworks/core/components_ng/property/property.cpp", + + # components_ng_pattern + "$ace_root/frameworks/core/components_ng/pattern/grid_container/grid_container_layout_property.cpp", + "$ace_root/frameworks/core/components_ng/pattern/list/list_event_hub.cpp", + "$ace_root/frameworks/core/components_ng/pattern/scroll/inner/scroll_bar.cpp", + "$ace_root/frameworks/core/components_ng/pattern/scroll_bar/proxy/scroll_bar_proxy.cpp", + + # components_ng_syntax + "$ace_root/frameworks/core/components_ng/syntax/for_each_node.cpp", + + # components_ng_event + "$ace_root/frameworks/core/components_ng/event/drag_event.cpp", + "$ace_root/frameworks/core/components_ng/event/event_hub.cpp", + "$ace_root/frameworks/core/components_ng/event/focus_hub.cpp", + "$ace_root/frameworks/core/components_ng/event/gesture_event_hub.cpp", + "$ace_root/frameworks/core/components_ng/event/input_event.cpp", + "$ace_root/frameworks/core/components_ng/event/input_event_hub.cpp", + "$ace_root/frameworks/core/components_ng/event/scrollable_event.cpp", + "$ace_root/frameworks/core/components_ng/event/state_style_manager.cpp", + "$ace_root/frameworks/core/components_ng/event/touch_event.cpp", + + # components_ng_gestures + "$ace_root/frameworks/core/components_ng/gestures/gesture_referee.cpp", + "$ace_root/frameworks/core/components_ng/gestures/recognizers/exclusive_recognizer.cpp", + "$ace_root/frameworks/core/components_ng/gestures/recognizers/gesture_recognizer.cpp", + "$ace_root/frameworks/core/components_ng/gestures/recognizers/long_press_recognizer.cpp", + "$ace_root/frameworks/core/components_ng/gestures/recognizers/multi_fingers_recognizer.cpp", + "$ace_root/frameworks/core/components_ng/gestures/recognizers/pan_recognizer.cpp", + "$ace_root/frameworks/core/components_ng/gestures/recognizers/parallel_recognizer.cpp", + "$ace_root/frameworks/core/components_ng/gestures/recognizers/recognizer_group.cpp", + "$ace_root/frameworks/core/components_ng/gestures/recognizers/sequenced_recognizer.cpp", + + # mock + "$ace_root/frameworks/base/test/mock/mock_drag_window.cpp", + "$ace_root/frameworks/base/test/mock/mock_system_properties.cpp", + "$ace_root/frameworks/core/animation/test/mock/mock_animator.cpp", + "$ace_root/frameworks/core/animation/test/mock/mock_scheduler.cpp", + "$ace_root/frameworks/core/common/test/mock/mock_clipboard.cpp", + "$ace_root/frameworks/core/common/test/mock/mock_container.cpp", + "$ace_root/frameworks/core/common/test/mock/mock_layout_inspector.cpp", + "$ace_root/frameworks/core/components_ng/test/event/scrollable_event/mock_scrollable.cpp", + "$ace_root/frameworks/core/components_ng/test/mock/base/mock_view_abstract.cpp", + "$ace_root/frameworks/core/components_ng/test/mock/pattern/scroll/mock_scroll_bar_painter.cpp", + "$ace_root/frameworks/core/components_ng/test/mock/render/mock_animation_utils.cpp", + "$ace_root/frameworks/core/components_ng/test/mock/render/mock_drawing_convertor.cpp", + "$ace_root/frameworks/core/components_ng/test/mock/render/mock_render_context.cpp", + "$ace_root/frameworks/core/components_ng/test/mock/render/mock_render_context_creator.cpp", + "$ace_root/frameworks/core/components_ng/test/mock/render/mock_rosen_modier_adapter.cpp", + "$ace_root/frameworks/core/pipeline_ng/test/mock/mock_element_register.cpp", + "$ace_root/frameworks/core/pipeline_ng/test/mock/mock_pipeline_base.cpp", + "$ace_root/frameworks/core/pipeline_ng/test/mock/mock_pipeline_context.cpp", + + # self + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_event_hub.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_item_layout_property.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_item_model_ng.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_layout/grid_layout_algorithm.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_layout_property.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_model_ng.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_paint_method.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_paint_property.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_position_controller.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_scroll_bar.cpp", + "$ace_root/frameworks/core/components_ng/pattern/grid/grid_utils.cpp", + "grid_test_ng.cpp", ] - configs = [ - ":config_grid_test", - "$ace_root:ace_config", + deps = [ + "$ace_root:ace_test_log", + "$cjson_root:cjson_static", + "//third_party/googletest:gmock_main", ] - configs += [ "$ace_root:ace_test_coverage_config" ] -} -config("config_grid_test") { - visibility = [ ":*" ] - include_dirs = [ - "//commonlibrary/c_utils/base/include", - "$ace_root", - "$ace_root/frameworks", + configs = [ + "$ace_root:ace_unittest_config", + "$ace_root:ace_test_coverage_config", ] } diff --git a/frameworks/core/components_ng/test/pattern/grid/grid_test_ng.cpp b/frameworks/core/components_ng/test/pattern/grid/grid_test_ng.cpp index 916a95c6ffef21e9c9d90c31e9833512064e2ed8..2575e227cf0e7eb2fa8204faf40019293c1d3f68 100644 --- a/frameworks/core/components_ng/test/pattern/grid/grid_test_ng.cpp +++ b/frameworks/core/components_ng/test/pattern/grid/grid_test_ng.cpp @@ -22,13 +22,10 @@ #include "base/geometry/ng/size_t.h" #include "base/geometry/offset.h" #include "base/utils/utils.h" -#include "core/components_ng/base/view_abstract.h" -#include "core/components_ng/base/view_abstract_model_ng.h" #include "core/components_ng/base/view_stack_processor.h" #include "core/components_ng/pattern/grid/grid_item_model_ng.h" #include "core/components_ng/pattern/grid/grid_model_ng.h" #include "core/components_ng/pattern/grid/grid_pattern.h" -#include "core/components_ng/pattern/text/text_model_ng.h" #include "core/pipeline/base/constants.h" using namespace testing; @@ -72,28 +69,16 @@ HWTEST_F(GridTestNg, GridTest001, TestSize.Level1) RefPtr scrollBarProxy; GridModelNG grid; grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("70%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); grid.SetColumnsTemplate("1fr 1fr 1fr"); grid.SetRowsTemplate("1fr 1fr 1fr"); /** - * @tc.steps: step2. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step2. Create the child nodes gridItem of the grid. */ GridItemModelNG gridItem; - TextModelNG text; const int32_t ITEM_COUNT = 9; for (int32_t i = 0; i < ITEM_COUNT; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("50%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); ViewStackProcessor::GetInstance()->Pop(); } @@ -108,6 +93,7 @@ HWTEST_F(GridTestNg, GridTest001, TestSize.Level1) OptionalSizeF size; constexpr float DEFAULT_WIDTH = 800.0f; size.SetWidth(DEFAULT_WIDTH); + size.SetHeight(DEFAULT_WIDTH); constraint.UpdateIllegalSelfIdealSizeWithCheck(size); /** @@ -139,11 +125,6 @@ HWTEST_F(GridTestNg, GridTest002, TestSize.Level1) RefPtr positionController; RefPtr scrollBarProxy; grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("70%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); /** * @tc.steps: step2. initialize ColumnsTemplate, ColumnsGap and MultiSelectable properties. @@ -153,19 +134,12 @@ HWTEST_F(GridTestNg, GridTest002, TestSize.Level1) grid.SetMultiSelectable(true); /** - * @tc.steps: step2. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step2. Create the child nodes gridItem of the grid. */ - TextModelNG text; GridItemModelNG gridItem; const int32_t ITEM_COUNT = 10; for (int32_t i = 0; i < ITEM_COUNT; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("50%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); ViewStackProcessor::GetInstance()->Pop(); } @@ -254,11 +228,6 @@ HWTEST_F(GridTestNg, GridTest003, TestSize.Level1) RefPtr scrollBarProxy; RefPtr positionController; grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("70%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); /** * @tc.steps: step2. initialize RowsTemplate, RowsGap and MultiSelectable properties. @@ -268,19 +237,12 @@ HWTEST_F(GridTestNg, GridTest003, TestSize.Level1) grid.SetMultiSelectable(true); /** - * @tc.steps: step3. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step3. Create the child nodes gridItem of the grid. */ - TextModelNG text; GridItemModelNG gridItem; const int32_t ITEM_COUNT = 10; for (int32_t i = 0; i < ITEM_COUNT; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("50%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); ViewStackProcessor::GetInstance()->Pop(); } @@ -375,11 +337,6 @@ HWTEST_F(GridTestNg, GridTest004, TestSize.Level1) RefPtr scrollBarProxy; auto positionController = grid.CreatePositionController(); grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("70%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); /** * @tc.steps: step2. initialize properties such as ColumnsGap, RowsGap, LayoutDirection, MaxCount, MinCount, @@ -394,19 +351,12 @@ HWTEST_F(GridTestNg, GridTest004, TestSize.Level1) grid.SetCellLength(GRID_CELL_LENGTH); /** - * @tc.steps: step3. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step3. Create the child nodes gridItem of the grid. */ - TextModelNG text; GridItemModelNG gridItem; const int32_t ITEM_COUNT = 10; for (int32_t i = 0; i < ITEM_COUNT; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("50%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); ViewStackProcessor::GetInstance()->Pop(); } @@ -433,10 +383,8 @@ HWTEST_F(GridTestNg, GridTest004, TestSize.Level1) * @tc.expected: step6. Check whether the updated properties is correct. */ auto layoutProperty = frameNode->GetLayoutProperty(); - auto layoutDirectionStr = layoutProperty->GetLayoutDirectionStr(); + auto layoutDirectionStr = layoutProperty->GetGridDirectionStr(); EXPECT_EQ(layoutDirectionStr, GRID_DIRECTION_ROW); - // auto barStateStr = layoutProperty->GetBarStateString(); - // EXPECT_EQ(barStateStr, GRID_SCROLL_BAR_OFF); /** * @tc.steps: step7. Get the pattern to call the related functions in the positionController. @@ -491,11 +439,6 @@ HWTEST_F(GridTestNg, GridTest005, TestSize.Level1) RefPtr scrollBarProxy; auto positionController = grid.CreatePositionController(); grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("70%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); /** * @tc.steps: step2. initialize properties such as ColumnsGap, RowsGap, LayoutDirection, MaxCount, MinCount, @@ -511,19 +454,12 @@ HWTEST_F(GridTestNg, GridTest005, TestSize.Level1) grid.SetScrollBarMode(static_cast(NG::DisplayMode::AUTO)); /** - * @tc.steps: step3. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step3. Create the child nodes gridItem of the grid. */ - TextModelNG text; GridItemModelNG gridItem; const int32_t ITEM_COUNT = 10; for (int32_t i = 0; i < ITEM_COUNT; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("50%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); ViewStackProcessor::GetInstance()->Pop(); } @@ -551,10 +487,8 @@ HWTEST_F(GridTestNg, GridTest005, TestSize.Level1) */ auto layoutProperty = frameNode->GetLayoutProperty(); EXPECT_NE(layoutProperty, nullptr); - auto layoutDirectionStr = layoutProperty->GetLayoutDirectionStr(); + auto layoutDirectionStr = layoutProperty->GetGridDirectionStr(); EXPECT_EQ(layoutDirectionStr, GRID_DIRECTION_ROW_REVERSE); - // auto barStateStr = layoutProperty->GetBarStateString(); - // EXPECT_EQ(barStateStr, GRID_SCROLL_BAR_AUTO); } /** @@ -571,11 +505,6 @@ HWTEST_F(GridTestNg, GridTest006, TestSize.Level1) RefPtr scrollBarProxy; auto positionController = grid.CreatePositionController(); grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("70%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); /** * @tc.steps: step2. initialize properties such as ColumnsGap, RowsGap, LayoutDirection, MaxCount, MinCount, @@ -591,19 +520,12 @@ HWTEST_F(GridTestNg, GridTest006, TestSize.Level1) grid.SetScrollBarMode(static_cast(NG::DisplayMode::ON)); /** - * @tc.steps: step3. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step3. Create the child nodes gridItem of the grid. */ - TextModelNG text; GridItemModelNG gridItem; const int32_t ITEM_COUNT = 10; for (int32_t i = 0; i < ITEM_COUNT; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("50%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); ViewStackProcessor::GetInstance()->Pop(); } @@ -631,10 +553,8 @@ HWTEST_F(GridTestNg, GridTest006, TestSize.Level1) */ auto layoutProperty = frameNode->GetLayoutProperty(); EXPECT_NE(layoutProperty, nullptr); - auto layoutDirectionStr = layoutProperty->GetLayoutDirectionStr(); + auto layoutDirectionStr = layoutProperty->GetGridDirectionStr(); EXPECT_EQ(layoutDirectionStr, GRID_DIRECTION_COLUMN); - // auto barStateStr = layoutProperty->GetBarStateString(); - // EXPECT_EQ(barStateStr, GRID_SCROLL_BAR_ON); } /** @@ -651,11 +571,6 @@ HWTEST_F(GridTestNg, GridTest007, TestSize.Level1) RefPtr scrollBarProxy; auto positionController = grid.CreatePositionController(); grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("70%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); /** * @tc.steps: step2. initialize properties such as ColumnsGap, RowsGap, LayoutDirection, MaxCount, MinCount, @@ -671,19 +586,12 @@ HWTEST_F(GridTestNg, GridTest007, TestSize.Level1) grid.SetScrollBarMode(static_cast(NG::DisplayMode::OFF)); /** - * @tc.steps: step3. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step3. Create the child nodes gridItem of the grid. */ - TextModelNG text; GridItemModelNG gridItem; const int32_t ITEM_COUNT = 10; for (int32_t i = 0; i < ITEM_COUNT; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("50%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); ViewStackProcessor::GetInstance()->Pop(); } @@ -711,10 +619,8 @@ HWTEST_F(GridTestNg, GridTest007, TestSize.Level1) */ auto layoutProperty = frameNode->GetLayoutProperty(); EXPECT_NE(layoutProperty, nullptr); - auto layoutDirectionStr = layoutProperty->GetLayoutDirectionStr(); + auto layoutDirectionStr = layoutProperty->GetGridDirectionStr(); EXPECT_EQ(layoutDirectionStr, GRID_DIRECTION_COLUMN_REVERSE); - // auto barStateStr = layoutProperty->GetBarStateString(); - // EXPECT_EQ(barStateStr, GRID_SCROLL_BAR_OFF); /** * @tc.steps: step7. Get grid EventHub to call related function. @@ -753,11 +659,6 @@ HWTEST_F(GridTestNg, GridTest008, TestSize.Level1) RefPtr scrollBarProxy; auto positionController = grid.CreatePositionController(); grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); /** * @tc.steps: step2. initialize properties such as RowsTemplate, RowsGap, Editable and MultiSelectable. @@ -768,19 +669,12 @@ HWTEST_F(GridTestNg, GridTest008, TestSize.Level1) grid.SetEditable(true); /** - * @tc.steps: step3. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step3. Create the child nodes gridItem of the grid. */ - TextModelNG text; GridItemModelNG gridItem; const int32_t ITEM_COUNT = 10; for (int32_t i = 0; i < ITEM_COUNT; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("80%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); ViewStackProcessor::GetInstance()->Pop(); } @@ -847,27 +741,19 @@ RefPtr TestScrollGrid(OptionalSizeF gridSize, double gridItemHeight, RefPtr scrollBarProxy; GridModelNG grid; grid.Create(positionController, scrollBarProxy); - std::unique_ptr instance = std::make_unique(); - auto height = StringUtils::StringToDimensionWithUnit("70%"); - instance->SetHeight(height); - auto width = StringUtils::StringToDimensionWithUnit("90%"); - instance->SetWidth(width); grid.SetColumnsTemplate("1fr 1fr 1fr"); /** - * @tc.steps: step2. Create the child nodes gridItem and text of the grid, and set the width and height of text. + * @tc.steps: step2. Create the child nodes gridItem of the grid. */ GridItemModelNG gridItem; - TextModelNG text; for (int32_t i = 0; i < totalItemCount; ++i) { gridItem.Create(); - text.Create("test"); - auto textHeight = StringUtils::StringToDimensionWithUnit("50%"); - instance->SetHeight(textHeight); - auto textWidth = StringUtils::StringToDimensionWithUnit("100%"); - instance->SetWidth(textWidth); - ViewStackProcessor::GetInstance()->Pop(); - instance->SetHeight(Dimension(gridItemHeight)); + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_RETURN(frameNode, nullptr); + auto layoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_RETURN(layoutProperty, frameNode); + layoutProperty->UpdateUserDefinedIdealSize(CalcSize(std::nullopt, NG::CalcLength(Dimension(gridItemHeight)))); ViewStackProcessor::GetInstance()->Pop(); } @@ -900,7 +786,7 @@ RefPtr TestScrollGrid(OptionalSizeF gridSize, double gridItemHeight, // save current grid info to grid pattern for next operation DirtySwapConfig config { false, false, false, false }; - auto layoutAlgorithmWrapper = layoutWrapper->GetLayoutAlgorithm(); + auto layoutAlgorithmWrapper = AceType::DynamicCast(layoutWrapper->GetLayoutAlgorithm()); CHECK_NULL_RETURN(layoutAlgorithmWrapper, frameNode); config.skipMeasure = layoutAlgorithmWrapper->SkipMeasure() || layoutWrapper->SkipMeasureContent(); config.skipLayout = layoutAlgorithmWrapper->SkipLayout();