• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "mouse_style_ohos.h"
17 
18 #include "input_manager.h"
19 #include "struct_multimodal.h"
20 
21 #include "base/log/log_wrapper.h"
22 #include "base/utils/linear_map.h"
23 #include "base/utils/utils.h"
24 
25 namespace OHOS::Ace {
26 
CreateMouseStyle()27 RefPtr<MouseStyle> MouseStyle::CreateMouseStyle()
28 {
29     return AceType::MakeRefPtr<MouseStyleOhos>();
30 }
31 
SetPointerStyle(int32_t windowId,MouseFormat pointerStyle) const32 bool MouseStyleOhos::SetPointerStyle(int32_t windowId, MouseFormat pointerStyle) const
33 {
34     auto inputManager = MMI::InputManager::GetInstance();
35     CHECK_NULL_RETURN(inputManager, false);
36     static const LinearEnumMapNode<MouseFormat, int32_t> mouseFormatMap[] = {
37         { MouseFormat::DEFAULT, MMI::DEFAULT },
38         { MouseFormat::WEST_EAST, MMI::WEST_EAST },
39         { MouseFormat::NORTH_SOUTH, MMI::NORTH_SOUTH },
40         { MouseFormat::NORTH_EAST_SOUTH_WEST, MMI::NORTH_EAST_SOUTH_WEST },
41         { MouseFormat::NORTH_WEST_SOUTH_EAST, MMI::NORTH_WEST_SOUTH_EAST },
42         { MouseFormat::CROSS, MMI::CROSS },
43         { MouseFormat::CURSOR_COPY, MMI::CURSOR_COPY },
44         { MouseFormat::CURSOR_FORBID, MMI::CURSOR_FORBID },
45         { MouseFormat::HAND_GRABBING, MMI::HAND_GRABBING },
46         { MouseFormat::HAND_POINTING, MMI::HAND_POINTING },
47         { MouseFormat::HELP, MMI::HELP },
48         { MouseFormat::CURSOR_MOVE, MMI::CURSOR_MOVE },
49         { MouseFormat::RESIZE_LEFT_RIGHT, MMI::RESIZE_LEFT_RIGHT },
50         { MouseFormat::RESIZE_UP_DOWN, MMI::RESIZE_UP_DOWN },
51         { MouseFormat::TEXT_CURSOR, MMI::TEXT_CURSOR },
52         { MouseFormat::ZOOM_IN, MMI::ZOOM_IN },
53         { MouseFormat::ZOOM_OUT, MMI::ZOOM_OUT },
54     };
55     int32_t MMIPointStyle = MMI::DEFAULT;
56     int64_t idx = BinarySearchFindIndex(mouseFormatMap, ArraySize(mouseFormatMap), pointerStyle);
57     if (idx >= 0) {
58         MMIPointStyle = mouseFormatMap[idx].value;
59     }
60     int32_t setResult = inputManager->SetPointerStyle(windowId, MMIPointStyle);
61     if (setResult == -1) {
62         LOGE("SetPointerStyle result is false");
63         return false;
64     }
65     return true;
66 }
67 
GetPointerStyle(int32_t windowId,int32_t & pointerStyle) const68 int32_t MouseStyleOhos::GetPointerStyle(int32_t windowId, int32_t& pointerStyle) const
69 {
70     auto inputManager = MMI::InputManager::GetInstance();
71     CHECK_NULL_RETURN(inputManager, -1);
72     int32_t getResult = inputManager->GetPointerStyle(windowId, pointerStyle);
73     if (getResult == -1) {
74         LOGE("GetPointerStyle result is false");
75         return -1;
76     }
77     return getResult;
78 }
79 
ChangePointerStyle(int32_t windowId,MouseFormat mouseFormat) const80 bool MouseStyleOhos::ChangePointerStyle(int32_t windowId, MouseFormat mouseFormat) const
81 {
82     int32_t curPointerStyle = -1;
83     if (GetPointerStyle(windowId, curPointerStyle) == -1) {
84         LOGE("ChangePointerStyle: GetPointerStyle return failed");
85         return false;
86     }
87     if (curPointerStyle == static_cast<int32_t>(mouseFormat)) {
88         return true;
89     }
90 
91     LOGD("ChangePointerStyle do SetPointerStyle: %{public}d", mouseFormat);
92     return SetPointerStyle(windowId, mouseFormat);
93 }
94 
95 } // namespace OHOS::Ace