1 /* 2 * Copyright (C) 2025-2025 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 MAGNIFICATION_WINDOW_H 17 #define MAGNIFICATION_WINDOW_H 18 19 #include "hilog_wrapper.h" 20 #include "wm/window.h" 21 #include "window_option.h" 22 #include <ui/rs_canvas_node.h> 23 #include <ui/rs_surface_node.h> 24 #include <transaction/rs_transaction.h> 25 #include "ui/rs_ui_context.h" 26 #include "ui/rs_ui_director.h" 27 #include "ui/rs_root_node.h" 28 #include "recording/recording_canvas.h" 29 #include "magnification_def.h" 30 #include "display_manager.h" 31 #include "ext_utils.h" 32 33 namespace OHOS { 34 namespace Accessibility { 35 class MagnificationWindow { 36 public: 37 // common 38 PointerPos GetSourceCenter(); 39 PointerPos ConvertCoordinates(int32_t posX, int32_t posY); GetScale()40 inline float GetScale() 41 { 42 return scale_; 43 } 44 InitMagnificationParam(float scale)45 inline void InitMagnificationParam(float scale) 46 { 47 scale_ = scale; 48 } 49 50 // full magnification 51 void EnableMagnificationFull(int32_t centerX, int32_t centerY); 52 void DisableMagnificationFull(bool needClear = false); 53 void SetScaleFull(float scaleSpan); 54 void MoveMagnificationFull(int32_t deltaX, int32_t deltaY); 55 PointerPos ConvertGesture(uint32_t type, PointerPos coordinates); 56 uint32_t CheckTapOnHotArea(int32_t posX, int32_t posY); 57 void FollowFocuseElementFull(int32_t centerX, int32_t centerY); 58 void ShowMagnificationFull(); 59 void RefreshWindowParamFull(RotationType type); 60 bool IsMagnificationShowFull(); 61 62 // window magnification 63 void EnableMagnificationPart(int32_t centerX, int32_t centerY); 64 void DisableMagnificationPart(bool needClear = false); 65 void SetScalePart(float scaleSpan); 66 void MoveMagnificationPart(int32_t deltaX, int32_t deltaY); 67 bool IsTapOnHotArea(int32_t posX, int32_t posY); 68 bool IsTapOnMagnificationWindow(int32_t posX, int32_t posY); 69 void FixSourceCenter(bool needFix); 70 void FollowFocuseElementPart(int32_t centerX, int32_t centerY); 71 void ShowMagnificationPart(); 72 void RefreshWindowParamPart(RotationType type); 73 bool IsMagnificationShowPart(); 74 75 private: 76 // common 77 void CreateMagnificationWindow(); 78 void GetWindowParam(); 79 PointerPos GetRectCenter(Rosen::Rect rect); 80 void FlushImplicitTransaction(); 81 void DisableMagnification(bool needClear = false); 82 PointerPos TransferCenter(RotationType type, PointerPos center); 83 84 // full magnification 85 Rosen::Rect GetSourceRectFromPointer(int32_t centerX, int32_t centerY); 86 void UpdateAnchor(); 87 void DrawRuoundRectFrameFull(); 88 89 // window magnification 90 Rosen::Rect GetWindowRectFromPointer(int32_t centerX, int32_t centerY); 91 void DrawRuoundRectFramePart(); 92 void CalculateAnchorOffset(); 93 void UpdateRelativeRect(); 94 void AdjustMagnificationWindowPosition(); 95 void AdjustSourceWindowPosition(); 96 97 // common 98 sptr<Rosen::Window> window_ = nullptr; 99 std::shared_ptr<Rosen::RSSurfaceNode> surfaceNode_ = nullptr; 100 std::shared_ptr<Rosen::RSCanvasNode> canvasNode_ = nullptr; 101 std::shared_ptr<Rosen::RSUIContext> rsUIContext_ = nullptr; 102 Rosen::Rect sourceRect_ = {0, 0, 0, 0}; 103 Rosen::Rect windowRect_ = {0, 0, 0, 0}; 104 Rosen::Rect screenRect_ = {0, 0, 0, 0}; 105 Rosen::Rect relativeRect_ = {0, 0, 0, 0}; //The relative position of sourceRect_ in windowRect_ 106 uint32_t screenWidth_ = 0; 107 uint32_t screenHeight_ = 0; 108 float screenSpan_ = 0.0f; 109 uint64_t screenId_ = 0; 110 int32_t centerX_ = 0; 111 int32_t centerY_ = 0; 112 float scale_ = DEFAULT_SCALE; 113 114 uint32_t windowWidth_ = MAGNIFY_WINDOW_WIDTH; 115 uint32_t windowHeight_ = MAGNIFY_WINDOW_HEIGHT; 116 uint32_t barMargin_ = BAR_MARGIN; 117 118 uint32_t hotAreaWidth_ = HOT_AREA_WIDTH; 119 int32_t anchorOffsetX_ = 0; // windowRect_'s centerX - sourceRect_'s centerX 120 int32_t anchorOffsetY_ = 0; // windowRect_'s centerY - sourceRect_'s centerY 121 122 bool isFixSourceCenter_ = false; 123 PointerPos fixedSourceCenter_ = {0, 0}; 124 bool isMagnificationShowPart_ = false; 125 bool isMagnificationShowFull_ = false; 126 }; 127 } // namespace Accessibility 128 } // namespace OHOS 129 #endif // MAGNIFICATION_WINDOW_H