• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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/pattern/linear_indicator/linear_indicator_accessibility_property.h"
17 
18 #include "core/components_ng/pattern/linear_indicator/linear_indicator_pattern.h"
19 
20 namespace OHOS::Ace::NG {
GetCurrentIndex() const21 int32_t LinearIndicatorAccessibilityProperty::GetCurrentIndex() const
22 {
23     auto pattern = GetLinearIndicatorPattern();
24     CHECK_NULL_RETURN(pattern, 0);
25     auto controller = pattern->GetController();
26     CHECK_NULL_RETURN(controller, 0);
27     return controller->Index();
28 }
29 
GetBeginIndex() const30 int32_t LinearIndicatorAccessibilityProperty::GetBeginIndex() const
31 {
32     return 0;
33 }
34 
GetEndIndex() const35 int32_t LinearIndicatorAccessibilityProperty::GetEndIndex() const
36 {
37     int32_t count = GetCollectionItemCounts();
38     if (count > 0) {
39         return count - 1;
40     } else {
41         return 0;
42     }
43 }
44 
GetCollectionItemCounts() const45 int32_t LinearIndicatorAccessibilityProperty::GetCollectionItemCounts() const
46 {
47     auto pattern = GetLinearIndicatorPattern();
48     CHECK_NULL_RETURN(pattern, 0);
49     auto layoutProperty = pattern->GetLayoutProperty<LinearIndicatorLayoutProperty>();
50     CHECK_NULL_RETURN(layoutProperty, 0);
51     return layoutProperty->GetProgressCount().value_or(0);
52 }
53 
GetAccessibilityValue() const54 AccessibilityValue LinearIndicatorAccessibilityProperty::GetAccessibilityValue() const
55 {
56     AccessibilityValue result;
57     result.min = GetBeginIndex();
58     result.max = GetEndIndex();
59     result.current = GetCurrentIndex();
60     return result;
61 }
62 
GetLinearIndicatorPattern() const63 RefPtr<LinearIndicatorPattern> LinearIndicatorAccessibilityProperty::GetLinearIndicatorPattern() const
64 {
65     auto frameNode = host_.Upgrade();
66     CHECK_NULL_RETURN(frameNode, nullptr);
67     return frameNode->GetPattern<LinearIndicatorPattern>();
68 }
69 
70 } // namespace OHOS::Ace::NG
71