From 197fb6d8c29bcb09376241ccef639bc968eb8809 Mon Sep 17 00:00:00 2001 From: zcdqs Date: Thu, 12 Jan 2023 05:43:28 +0000 Subject: [PATCH] fix griditem multiselect Signed-off-by: zcdqs Change-Id: Ibb40bfd9dde1f20a88f0b6d664dfc01b84ddd2d9 --- .../core/components_ng/pattern/BUILD.gn | 3 +- .../pattern/grid/grid_item_pattern.cpp | 29 +++++++++++++++++++ .../pattern/grid/grid_item_pattern.h | 15 +++++----- .../pattern/grid/grid_pattern.cpp | 12 +++----- .../components_ng/test/pattern/grid/BUILD.gn | 1 + 5 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 frameworks/core/components_ng/pattern/grid/grid_item_pattern.cpp diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index e7498606a7b..60bc6e16fdc 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. +# Copyright (c) 2022-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 @@ -88,6 +88,7 @@ build_component_ng("pattern_ng") { "grid/grid_event_hub.cpp", "grid/grid_item_layout_property.cpp", "grid/grid_item_model_ng.cpp", + "grid/grid_item_pattern.cpp", "grid/grid_layout/grid_layout_algorithm.cpp", "grid/grid_layout_property.cpp", "grid/grid_model_ng.cpp", diff --git a/frameworks/core/components_ng/pattern/grid/grid_item_pattern.cpp b/frameworks/core/components_ng/pattern/grid/grid_item_pattern.cpp new file mode 100644 index 00000000000..e6cbb661b48 --- /dev/null +++ b/frameworks/core/components_ng/pattern/grid/grid_item_pattern.cpp @@ -0,0 +1,29 @@ +/* + * 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 "core/components_ng/pattern/grid/grid_item_pattern.h" + +#include "base/utils/utils.h" +namespace OHOS::Ace::NG { +void GridItemPattern::MarkIsSelected(bool isSelected) +{ + if (isSelected_ != isSelected) { + isSelected_ = isSelected; + auto eventHub = GetEventHub(); + CHECK_NULL_VOID(eventHub); + eventHub->FireOnSelect(isSelected); + } +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/grid/grid_item_pattern.h b/frameworks/core/components_ng/pattern/grid/grid_item_pattern.h index 876e71dcc71..9b9d6e7fb0b 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_item_pattern.h +++ b/frameworks/core/components_ng/pattern/grid/grid_item_pattern.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -16,8 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GRID_GRID_ITEM_PATTERN_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_GRID_GRID_ITEM_PATTERN_H -#include "base/memory/referenced.h" -#include "base/utils/noncopyable.h" +#include "core/components_ng/pattern/grid/grid_item_event_hub.h" #include "core/components_ng/pattern/grid/grid_item_layout_property.h" #include "core/components_ng/pattern/pattern.h" #include "core/components_ng/syntax/shallow_builder.h" @@ -40,6 +39,11 @@ public: return MakeRefPtr(); } + RefPtr CreateEventHub() override + { + return MakeRefPtr(); + } + void BeforeCreateLayoutWrapper() override { if (shallowBuilder_ && !shallowBuilder_->IsExecuteDeepRenderDone()) { @@ -99,10 +103,7 @@ public: json->Put("selectable", selectable_ ? "true" : "false"); } - void MarkIsSelected(bool isSelected) - { - isSelected_ = isSelected; - } + void MarkIsSelected(bool isSelected); bool IsSelected() const { diff --git a/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp b/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp index a04f82941e3..e2d58a3fd7c 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_pattern.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -151,13 +151,9 @@ void GridPattern::MultiSelectWithoutKeyboard(const RectF& selectedZone) { auto host = GetHost(); CHECK_NULL_VOID(host); - - for (const auto& item : host->GetChildren()) { - if (!AceType::InstanceOf(item)) { - continue; - } - - auto itemFrameNode = AceType::DynamicCast(item); + std::list> children; + host->GenerateOneDepthVisibleFrame(children); + for (const auto& itemFrameNode : children) { auto itemPattern = itemFrameNode->GetPattern(); CHECK_NULL_VOID(itemPattern); diff --git a/frameworks/core/components_ng/test/pattern/grid/BUILD.gn b/frameworks/core/components_ng/test/pattern/grid/BUILD.gn index 0efba871578..1b00ab38531 100644 --- a/frameworks/core/components_ng/test/pattern/grid/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/grid/BUILD.gn @@ -52,6 +52,7 @@ ohos_unittest("grid_pattern_test_ng") { "$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_item_pattern.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", -- Gitee