diff --git a/frameworks/core/components_ng/pattern/text_field/BUILD.gn b/frameworks/core/components_ng/pattern/text_field/BUILD.gn index 25607e351ca8ca9da9a27801c8e46ca8f24e05e6..c54a204f52f5ed160e49b22a54c1da4d384638b1 100644 --- a/frameworks/core/components_ng/pattern/text_field/BUILD.gn +++ b/frameworks/core/components_ng/pattern/text_field/BUILD.gn @@ -16,6 +16,7 @@ import( build_component_ng("text_field_pattern_ng") { sources = [ + "text_field_accessibility_property.cpp", "text_field_controller.cpp", "text_field_layout_algorithm.cpp", "text_field_model_ng.cpp", diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_accessibility_property.cpp b/frameworks/core/components_ng/pattern/text_field/text_field_accessibility_property.cpp new file mode 100755 index 0000000000000000000000000000000000000000..062faea8dff2849cde188cceb9dac244cf9b2621 --- /dev/null +++ b/frameworks/core/components_ng/pattern/text_field/text_field_accessibility_property.cpp @@ -0,0 +1,72 @@ +/* + * 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/text_field/text_field_accessibility_property.h" + +#include "core/components_ng/base/frame_node.h" +#include "core/components_ng/pattern/text_field/text_field_pattern.h" + +namespace OHOS::Ace::NG { +static const std::string DEFAULT_PASSWORD = "******"; + +bool TextFieldAccessibilityProperty::IsPassword() const +{ + auto frameNode = host_.Upgrade(); + CHECK_NULL_RETURN(frameNode, false); + auto textFieldLayoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_RETURN(textFieldLayoutProperty, false); + return textFieldLayoutProperty->GetTextInputType() == TextInputType::VISIBLE_PASSWORD; +} + +bool TextFieldAccessibilityProperty::IsEditable() const +{ + return true; +} + +bool TextFieldAccessibilityProperty::IsMultiLine() const +{ + auto frameNode = host_.Upgrade(); + CHECK_NULL_RETURN(frameNode, false); + auto textFieldPattern = frameNode->GetPattern(); + CHECK_NULL_RETURN(textFieldPattern, false); + return textFieldPattern->IsTextArea(); +} + +std::string TextFieldAccessibilityProperty::GetText() const +{ + auto frameNode = host_.Upgrade(); + CHECK_NULL_RETURN(frameNode, ""); + auto textFieldLayoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_RETURN(textFieldLayoutProperty, ""); + std::string text = textFieldLayoutProperty->GetValueValue(""); + if (IsPassword() && !text.empty()) { + text = DEFAULT_PASSWORD; + } + return text; +} + +bool TextFieldAccessibilityProperty::IsHint() const +{ + auto frameNode = host_.Upgrade(); + CHECK_NULL_RETURN(frameNode, false); + auto textFieldLayoutProperty = frameNode->GetLayoutProperty(); + CHECK_NULL_RETURN(textFieldLayoutProperty, false); + if (!textFieldLayoutProperty->GetValueValue("").empty() || + textFieldLayoutProperty->GetPlaceholderValue("").empty()) { + return false; + } + return true; +} +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/text_field/text_field_accessibility_property.h b/frameworks/core/components_ng/pattern/text_field/text_field_accessibility_property.h new file mode 100755 index 0000000000000000000000000000000000000000..b628bfd6268e95bacafa720a4f81cc978ad5f367 --- /dev/null +++ b/frameworks/core/components_ng/pattern/text_field/text_field_accessibility_property.h @@ -0,0 +1,49 @@ +/* + * 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. + */ + +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_FIELD_TEXT_FIELD_ACCESSIBILITY_PROPERTY_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_FIELD_TEXT_FIELD_ACCESSIBILITY_PROPERTY_H + +#include + +#include "base/utils/utils.h" +#include "core/components_ng/property/accessibility_property.h" + +namespace OHOS::Ace::NG { +class TextFieldAccessibilityProperty : public AccessibilityProperty { + DECLARE_ACE_TYPE(TextFieldAccessibilityProperty, AccessibilityProperty); + +public: + TextFieldAccessibilityProperty() = default; + + ~TextFieldAccessibilityProperty() override = default; + + bool IsPassword() const override; + + bool IsEditable() const override; + + bool IsMultiLine() const override; + + std::string GetText() const override; + + bool IsHint() const override; + +private: + + ACE_DISALLOW_COPY_AND_MOVE(TextFieldAccessibilityProperty); +}; +} // namespace OHOS::Ace::NG + +#endif