1 /* 2 * Copyright (c) 2022 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_MANAGER_H 18 19 #include "base/geometry/offset.h" 20 #include "base/memory/ace_type.h" 21 #include "base/utils/macros.h" 22 #include "core/common/manager_interface.h" 23 #include "core/components_ng/pattern/pattern.h" 24 #include "core/components_ng/property/safe_area_insets.h" 25 26 namespace OHOS::Ace::NG { 27 class ACE_EXPORT TextFieldManagerNG : public ManagerInterface { 28 DECLARE_ACE_TYPE(TextFieldManagerNG, ManagerInterface); 29 30 public: 31 TextFieldManagerNG() = default; 32 ~TextFieldManagerNG() override = default; 33 SetClickPosition(const Offset & position)34 void SetClickPosition(const Offset& position) override 35 { 36 position_ = position; 37 } GetClickPosition()38 const Offset& GetClickPosition() override 39 { 40 return position_; 41 } MovePage(int32_t pageId,const Offset & rootRect,double offsetHeight)42 void MovePage(int32_t pageId, const Offset& rootRect, double offsetHeight) override {} RemovePageId(int32_t pageId)43 void RemovePageId(int32_t pageId) override {} 44 GetOnFocusTextField()45 WeakPtr<Pattern>& GetOnFocusTextField() 46 { 47 return onFocusTextField_; 48 } 49 SetOnFocusTextField(const WeakPtr<Pattern> & onFocusTextField)50 void SetOnFocusTextField(const WeakPtr<Pattern>& onFocusTextField) 51 { 52 onFocusTextField_ = onFocusTextField; 53 } 54 55 void ScrollTextFieldToSafeArea(); 56 57 void ClearOnFocusTextField(); 58 59 bool ResetSlidingPanelParentHeight(); 60 61 bool UpdatePanelForVirtualKeyboard(double offsetY, double fullHeight); 62 void SetHeight(float height); 63 void ProcessNavKeyboard(); 64 GetHeight()65 float GetHeight() const 66 { 67 return height_; 68 } 69 70 bool OnBackPressed(); 71 72 void UpdateScrollableParentViewPort(const RefPtr<FrameNode>& node); 73 GetImeShow()74 bool GetImeShow() const override 75 { 76 return imeShow_; 77 } 78 SetImeShow(bool imeShow)79 void SetImeShow(bool imeShow) 80 { 81 imeShow_ = imeShow; 82 } 83 SetUIExtensionImeShow(bool imeShow)84 void SetUIExtensionImeShow(bool imeShow) override 85 { 86 uiExtensionImeShow_ = imeShow; 87 } 88 PrevHasTextFieldPattern()89 bool PrevHasTextFieldPattern() const 90 { 91 return prevHasTextFieldPattern_; 92 } 93 UpdatePrevHasTextFieldPattern()94 void UpdatePrevHasTextFieldPattern() 95 { 96 if (onFocusTextField_.Upgrade()) { 97 prevHasTextFieldPattern_ = true; 98 } else { 99 prevHasTextFieldPattern_ = false; 100 } 101 } 102 103 private: 104 void ScrollToSafeAreaHelper(const SafeAreaInsets::Inset& bottomInset, bool isShowKeyboard); 105 RefPtr<FrameNode> FindScrollableOfFocusedTextField(const RefPtr<FrameNode>& textField); 106 107 bool hasMove_ = false; 108 bool imeShow_ = false; 109 bool uiExtensionImeShow_ = false; 110 bool prevHasTextFieldPattern_ = true; 111 Offset position_; 112 float height_ = 0.0f; 113 WeakPtr<Pattern> onFocusTextField_; 114 }; 115 116 } // namespace OHOS::Ace::NG 117 118 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_FIELD_TEXT_FIELD_MANAGER_H 119