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 #ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_MOUSESTYLE_MOUSE_STYLE_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_MOUSESTYLE_MOUSE_STYLE_MANAGER_H 18 19 #include <list> 20 21 #include "base/memory/ace_type.h" 22 #include "base/image/pixel_map.h" 23 24 namespace OHOS::Ace { 25 26 enum class MouseFormat : int32_t { 27 DEFAULT = 0, // Default mouse style 28 EAST = 1, // Eastwards arrow 29 WEST = 2, // Westwards arrow 30 SOUTH = 3, // Southwards arrow 31 NORTH = 4, // Northwards arrow 32 WEST_EAST = 5, // Drag left-right mouse style 33 NORTH_SOUTH = 6, // Drag up-down mouse style 34 NORTH_EAST = 7, 35 NORTH_WEST = 8, 36 SOUTH_EAST = 9, 37 SOUTH_WEST = 10, 38 NORTH_EAST_SOUTH_WEST = 11, 39 NORTH_WEST_SOUTH_EAST = 12, 40 CROSS = 13, 41 CURSOR_COPY = 14, 42 CURSOR_FORBID = 15, 43 COLOR_SUCKER = 16, 44 HAND_GRABBING = 17, 45 HAND_OPEN = 18, 46 HAND_POINTING = 19, // Hyperlink mouse style 47 HELP = 20, 48 CURSOR_MOVE = 21, 49 RESIZE_LEFT_RIGHT = 22, 50 RESIZE_UP_DOWN = 23, 51 SCREENSHOT_CHOOSE = 24, 52 SCREENSHOT_CURSOR = 25, 53 TEXT_CURSOR = 26, // Text editing mouse style 54 ZOOM_IN = 27, 55 ZOOM_OUT = 28, 56 MIDDLE_BTN_EAST = 29, 57 MIDDLE_BTN_WEST = 30, 58 MIDDLE_BTN_SOUTH = 31, 59 MIDDLE_BTN_NORTH = 32, 60 MIDDLE_BTN_NORTH_SOUTH = 33, 61 MIDDLE_BTN_NORTH_EAST = 34, 62 MIDDLE_BTN_NORTH_WEST = 35, 63 MIDDLE_BTN_SOUTH_EAST = 36, 64 MIDDLE_BTN_SOUTH_WEST = 37, 65 MIDDLE_BTN_NORTH_SOUTH_WEST_EAST = 38, 66 HORIZONTAL_TEXT_CURSOR = 39, 67 CURSOR_CROSS = 40, 68 CURSOR_CIRCLE = 41, 69 LOADING = 42, 70 RUNNING = 43, 71 CURSOR_NONE = 46, 72 CONTEXT_MENU = 47, 73 ALIAS = 48, 74 }; 75 76 class ACE_EXPORT MouseStyle : public AceType { 77 DECLARE_ACE_TYPE(MouseStyle, AceType); 78 79 public: 80 static RefPtr<MouseStyle> CreateMouseStyle(); 81 82 virtual bool SetPointerStyle(int32_t windowId, MouseFormat pointerStyle) const = 0; 83 virtual int32_t GetPointerStyle(int32_t windowId, int32_t& pointerStyle) const = 0; SetMouseIcon(int32_t windowId,MouseFormat pointerStyle,std::shared_ptr<Media::PixelMap> pixelMap)84 virtual void SetMouseIcon( 85 int32_t windowId, MouseFormat pointerStyle, std::shared_ptr<Media::PixelMap> pixelMap) const {}; SetCustomCursor(int32_t windowId,int32_t focusX,int32_t focusY,std::shared_ptr<Media::PixelMap> pixelMap)86 virtual void SetCustomCursor( 87 int32_t windowId, int32_t focusX, int32_t focusY, std::shared_ptr<Media::PixelMap> pixelMap) const {}; SetPointerVisible(MouseFormat pointerStyle)88 virtual void SetPointerVisible(MouseFormat pointerStyle) const {}; 89 }; 90 91 enum class MouseStyleChangeReason { 92 INNER_SET_MOUSESTYLE = 0, // inner frameNode call mouseStyle change 93 USER_SET_MOUSESTYLE = 1, // user call setCursor change mouseStyle 94 CONTAINER_DESTROY_RESET_MOUSESTYLE = 2, // container is destroyed, reset mouse style 95 WINDOW_LOST_FOCUS_RESET_MOUSESTYLE = 3, // window lost focus, reset mouse style 96 WINDOW_SCENE_LOST_FOCUS_RESET_MOUSESTYLE = 4, // window_scene lost focus, reset mouse style 97 }; 98 99 struct MouseStyleChangeLog { 100 int32_t windowId; // the id of window which change mouseStyle 101 int32_t changeNodeId; // the id of node which change mouseStyle 102 MouseFormat beforeMouseStyle; // before this change, the mouseFormat of mouseStyle 103 MouseFormat afterMouseStyle; // after this change, the mouseFormat of mouseStyle 104 MouseStyleChangeReason reason; // the reason of this mouseStyle change 105 }; 106 107 class ACE_EXPORT MouseStyleManager : public AceType { 108 DECLARE_ACE_TYPE(MouseStyleManager, AceType); 109 110 public: 111 MouseStyleManager() = default; 112 113 bool SetMouseFormat(int32_t windowId, int32_t nodeId, MouseFormat mouseFormat, 114 bool isByPass, MouseStyleChangeReason reason); 115 116 void VsyncMouseFormat(); 117 void DumpMouseStyleChangeLog(); 118 SetMouseStyleHoldNode(int32_t id)119 bool SetMouseStyleHoldNode(int32_t id) 120 { 121 if (!mouseStyleNodeId_.has_value()) { 122 mouseStyleNodeId_ = id; 123 return true; 124 } else { 125 return false; 126 } 127 } 128 FreeMouseStyleHoldNode(int32_t id)129 bool FreeMouseStyleHoldNode(int32_t id) 130 { 131 if (mouseStyleNodeId_.has_value() && mouseStyleNodeId_.value() == id) { 132 mouseStyleNodeId_.reset(); 133 return true; 134 } else { 135 return false; 136 } 137 } 138 FreeMouseStyleHoldNode()139 bool FreeMouseStyleHoldNode() 140 { 141 CHECK_NULL_RETURN(mouseStyleNodeId_.has_value(), false); 142 mouseStyleNodeId_.reset(); 143 return true; 144 } 145 SetUserSetCursor(bool userSetCursor)146 void SetUserSetCursor(bool userSetCursor) 147 { 148 userSetCursor_ = userSetCursor; 149 } 150 GetCurrentMouseStyle()151 MouseFormat GetCurrentMouseStyle() const 152 { 153 return mouseFormat_; 154 } 155 156 private: 157 bool userSetCursor_ = false; 158 std::optional<int32_t> mouseStyleNodeId_; 159 MouseFormat lastVsyncMouseFormat_ = MouseFormat::DEFAULT; 160 MouseFormat mouseFormat_ = MouseFormat::DEFAULT; 161 std::list<MouseStyleChangeLog> vsyncMouseStyleChanges_; 162 std::list<MouseStyleChangeLog> mouseStyleChangeLogs_; 163 }; 164 } // namespace OHOS::Ace 165 166 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_MOUSESTYLE_MOUSE_STYLE_MANAGER_H