From b87e5e819f0ad0472c3478cadd8901ac77ccad5d Mon Sep 17 00:00:00 2001 From: zcdqs Date: Sat, 18 Mar 2023 16:01:17 +0800 Subject: [PATCH] add accessiblity for TextInput and TextArea Signed-off-by: zcdqs Change-Id: Ie4296e76eb271c89bfad4d7e5a6e0d94fb9b5a84 --- .../components_ng/pattern/text_field/BUILD.gn | 1 + .../text_field_accessibility_property.cpp | 72 +++++++++++++++++++ .../text_field_accessibility_property.h | 49 +++++++++++++ 3 files changed, 122 insertions(+) create mode 100755 frameworks/core/components_ng/pattern/text_field/text_field_accessibility_property.cpp create mode 100755 frameworks/core/components_ng/pattern/text_field/text_field_accessibility_property.h diff --git a/frameworks/core/components_ng/pattern/text_field/BUILD.gn b/frameworks/core/components_ng/pattern/text_field/BUILD.gn index 25607e351ca..c54a204f52f 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 00000000000..062faea8dff --- /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 00000000000..b628bfd6268 --- /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 -- Gitee