1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "core/components_ng/manager/drag_drop/drag_drop_spring_loading/drag_drop_spring_loading_state_base.h" 17 18 #include "core/components_ng/manager/drag_drop/drag_drop_spring_loading/drag_drop_spring_loading_state_machine.h" 19 #include "core/pipeline_ng/pipeline_context.h" 20 21 namespace OHOS::Ace::NG { ConvertDragSpringLoadingState(DragDropSpringLoadingState state) const22DragSpringLoadingState DragDropSpringLoadingStateBase::ConvertDragSpringLoadingState( 23 DragDropSpringLoadingState state) const 24 { 25 switch (state) { 26 case DragDropSpringLoadingState::BEGIN: 27 return DragSpringLoadingState::BEGIN; 28 case DragDropSpringLoadingState::UPDATE: 29 return DragSpringLoadingState::UPDATE; 30 case DragDropSpringLoadingState::END: 31 return DragSpringLoadingState::END; 32 case DragDropSpringLoadingState::CANCEL: 33 return DragSpringLoadingState::CANCEL; 34 default: 35 return DragSpringLoadingState::CANCEL; 36 } 37 } 38 UpdateDragSpringLoadingContext(RefPtr<OHOS::Ace::DragSpringLoadingContext> & context,std::string_view extraInfo)39void DragDropSpringLoadingStateBase::UpdateDragSpringLoadingContext( 40 RefPtr<OHOS::Ace::DragSpringLoadingContext>& context, std::string_view extraInfo) 41 { 42 CHECK_NULL_VOID(context); 43 auto stateMachine = GetStateMachine(); 44 CHECK_NULL_VOID(stateMachine); 45 stateMachine->IncrementCurrentNotifySequence(); 46 context->SetCurrentNotifySequence(stateMachine->GetCurrentNotifySequence()); 47 auto frameNode = stateMachine->GetFrameNode(); 48 CHECK_NULL_VOID(frameNode); 49 auto eventHub = frameNode->GetEventHub<EventHub>(); 50 CHECK_NULL_VOID(eventHub); 51 auto pipeline = frameNode->GetContextWithCheck(); 52 CHECK_NULL_VOID(pipeline); 53 auto dragManager = pipeline->GetDragDropManager(); 54 CHECK_NULL_VOID(dragManager); 55 context->SetExtraInfos( 56 eventHub->GetDragExtraParams(extraInfo.data(), stateMachine->GetPoint(), DragEventType::MOVE)); 57 context->SetSummary(dragManager->GetSummaryMap()); 58 context->SetState(ConvertDragSpringLoadingState(stateMachine->GetCurrentState())); 59 context->SetDragSpringLoadingConfiguration(stateMachine->GetUserConfig()); 60 } 61 } // namespace OHOS::Ace::NG