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 WINDOW_DESTROY_RESET_MOUSESTYLE = 2, // window is destroyed, reset mouse style 95 }; 96 97 struct MouseStyleChangeLog { 98 int32_t windowId; // the id of window which change mouseStyle 99 int32_t changeNodeId; // the id of node which change mouseStyle 100 MouseFormat beforeMouseStyle; // before this change, the mouseFormat of mouseStyle 101 MouseFormat afterMouseStyle; // after this change, the mouseFormat of mouseStyle 102 MouseStyleChangeReason reason; // the reason of this mouseStyle change 103 }; 104 105 class ACE_EXPORT MouseStyleManager : public AceType { 106 DECLARE_ACE_TYPE(MouseStyleManager, AceType) 107 108 public: 109 MouseStyleManager() = default; 110 111 bool SetMouseFormat(int32_t windowId, int32_t nodeId, MouseFormat mouseFormat, 112 bool isByPass, MouseStyleChangeReason reason); 113 114 void VsyncMouseFormat(); 115 void DumpMouseStyleChangeLog(); 116 SetMouseStyleHoldNode(int32_t id)117 void SetMouseStyleHoldNode(int32_t id) 118 { 119 if (!mouseStyleNodeId_.has_value()) { 120 mouseStyleNodeId_ = id; 121 } 122 } 123 FreeMouseStyleHoldNode(int32_t id)124 void FreeMouseStyleHoldNode(int32_t id) 125 { 126 if (mouseStyleNodeId_.has_value() && mouseStyleNodeId_.value() == id) { 127 mouseStyleNodeId_.reset(); 128 } 129 } 130 FreeMouseStyleHoldNode()131 void FreeMouseStyleHoldNode() 132 { 133 CHECK_NULL_VOID(mouseStyleNodeId_.has_value()); 134 mouseStyleNodeId_.reset(); 135 } 136 SetUserSetCursor(bool userSetCursor)137 void SetUserSetCursor(bool userSetCursor) 138 { 139 userSetCursor_ = userSetCursor; 140 } 141 142 private: 143 bool userSetCursor_ = false; 144 std::optional<int32_t> mouseStyleNodeId_; 145 MouseFormat lastVsyncMouseFormat_ = MouseFormat::DEFAULT; 146 MouseFormat mouseFormat_ = MouseFormat::DEFAULT; 147 std::list<MouseStyleChangeLog> vsyncMouseStyleChanges_; 148 std::list<MouseStyleChangeLog> mouseStyleChangeLogs_; 149 }; 150 } // namespace OHOS::Ace 151 152 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_MOUSESTYLE_MOUSE_STYLE_MANAGER_H