1 /*
2 * Copyright (c) 2023 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 #include "bridge/declarative_frontend/jsview/models/scroll_bar_model_impl.h"
16
17 #include "base/geometry/axis.h"
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19
20 namespace OHOS::Ace::Framework {
21 namespace {
22 const std::vector<DisplayMode> DISPLAY_MODE = { DisplayMode::OFF, DisplayMode::AUTO, DisplayMode::ON };
23 const std::vector<Axis> AXIS = { Axis::VERTICAL, Axis::HORIZONTAL, Axis::NONE };
24 }
25
GetScrollBarProxy(const RefPtr<ScrollProxy> & scrollProxy)26 RefPtr<ScrollProxy> ScrollBarModelImpl::GetScrollBarProxy(const RefPtr<ScrollProxy>& scrollProxy)
27 {
28 auto proxy = AceType::DynamicCast<ScrollBarProxy>(scrollProxy);
29 if (!proxy) {
30 proxy = AceType::MakeRefPtr<ScrollBarProxy>();
31 }
32
33 return proxy;
34 }
35
Create(const RefPtr<ScrollProxy> & proxy,bool infoflag,bool proxyFlag,int directionValue,int stateValue,bool isCreateArc)36 void ScrollBarModelImpl::Create(const RefPtr<ScrollProxy>& proxy, bool infoflag, bool proxyFlag,
37 int directionValue, int stateValue, bool isCreateArc)
38 {
39 RefPtr<Component> child;
40 auto scrollBarComponent = AceType::MakeRefPtr<OHOS::Ace::ScrollBarComponent>(child);
41
42 if (infoflag) {
43 if (proxyFlag) {
44 auto scrollBarProxy = AceType::DynamicCast<ScrollBarProxy>(proxy);
45 scrollBarComponent->SetScrollBarProxy(scrollBarProxy);
46 }
47
48 if (directionValue > -1 && directionValue < static_cast<int>(AXIS.size())) {
49 scrollBarComponent->SetAxis(AXIS[directionValue]);
50 }
51
52 if (stateValue > -1 && stateValue < static_cast<int>(DISPLAY_MODE.size())) {
53 scrollBarComponent->SetDisplayMode(DISPLAY_MODE[stateValue]);
54 }
55 }
56
57 ViewStackProcessor::GetInstance()->ClaimElementId(scrollBarComponent);
58 ViewStackProcessor::GetInstance()->Push(scrollBarComponent);
59 ViewStackProcessor::GetInstance()->GetDisplayComponent();
60 }
61 } // namespace OHOS::Ace::Framework
62