• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
17 
18 #include "core/components_ng/manager/drag_drop/drag_drop_related_configuration.h"
19 #include "ui/base/utils/utils.h"
20 
21 namespace OHOS::Ace::NG {
22 
GetOrCreateDragSpringLoadingConfiguration()23 RefPtr<DragSpringLoadingConfiguration> DragDropRelatedConfigurations::GetOrCreateDragSpringLoadingConfiguration()
24 {
25     if (dragSpringLoadingConfiguration_) {
26         return dragSpringLoadingConfiguration_;
27     }
28     dragSpringLoadingConfiguration_ = MakeRefPtr<DragSpringLoadingConfiguration>();
29     return dragSpringLoadingConfiguration_;
30 }
31 
SetDragSpringLoadingConfiguration(const RefPtr<DragSpringLoadingConfiguration> & dragSpringLoadingConfiguration)32 void DragDropRelatedConfigurations::SetDragSpringLoadingConfiguration(
33     const RefPtr<DragSpringLoadingConfiguration>& dragSpringLoadingConfiguration)
34 {
35     CHECK_NULL_VOID(dragSpringLoadingConfiguration);
36     dragSpringLoadingConfiguration_ = std::move(dragSpringLoadingConfiguration);
37 }
38 
GetOrCreateDragPreviewOption()39 DragPreviewOption DragDropRelatedConfigurations::GetOrCreateDragPreviewOption()
40 {
41     if (previewOption_) {
42         return *previewOption_;
43     }
44     previewOption_ = std::make_unique<DragPreviewOption>();
45     CHECK_NULL_RETURN(previewOption_, DragPreviewOption());
46     return *previewOption_;
47 }
48 
SetOptionsAfterApplied(const OptionsAfterApplied & optionsAfterApplied)49 void DragDropRelatedConfigurations::SetOptionsAfterApplied(const OptionsAfterApplied& optionsAfterApplied)
50 {
51     if (!previewOption_) {
52         previewOption_ = std::make_unique<DragPreviewOption>();
53     }
54     CHECK_NULL_VOID(previewOption_);
55     previewOption_->options = optionsAfterApplied;
56 }
57 
SetDragPreviewOption(const DragPreviewOption & previewOption,bool isResetOptions)58 void DragDropRelatedConfigurations::SetDragPreviewOption(const DragPreviewOption& previewOption, bool isResetOptions)
59 {
60     if (isResetOptions) {
61         previewOption_ = std::make_unique<DragPreviewOption>(previewOption);
62         CHECK_NULL_VOID(previewOption_);
63         previewOption_->onApply = std::move(previewOption.onApply);
64         return;
65     }
66     OptionsAfterApplied options = previewOption_ ? previewOption_->options : OptionsAfterApplied();
67     previewOption_ = std::make_unique<DragPreviewOption>(previewOption);
68     CHECK_NULL_VOID(previewOption_);
69     previewOption_->options = options;
70     previewOption_->onApply = std::move(previewOption.onApply);
71 }
72 } // namespace OHOS::Ace::NG