1 /* 2 * Copyright (c) 2021-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_CORE_COMPONENTS_GRID_LAYOUT_RENDER_GRID_LAYOUT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_GRID_LAYOUT_RENDER_GRID_LAYOUT_H 18 19 #include <atomic> 20 #include <functional> 21 #include <map> 22 #include <mutex> 23 #include <vector> 24 25 #include "core/animation/animation.h" 26 #include "core/animation/animator.h" 27 #include "core/animation/scroll_motion.h" 28 #include "core/animation/spring_motion.h" 29 #include "core/components/common/layout/constants.h" 30 #include "core/components/common/properties/scroll_bar.h" 31 #include "core/components/grid_layout/grid_layout_component.h" 32 #include "core/components/grid_layout/render_grid_layout_item.h" 33 #include "core/components/positioned/positioned_component.h" 34 #include "core/components/stack/stack_element.h" 35 #include "core/gestures/drag_recognizer.h" 36 #include "core/gestures/raw_recognizer.h" 37 #include "core/pipeline/base/render_node.h" 38 39 namespace OHOS::Ace { 40 namespace { 41 42 constexpr int32_t DEFAULT_FINGERS = 1; 43 constexpr int32_t DEFAULT_DURATION = 150; 44 constexpr int32_t DEFAULT_DISTANCE = 0; 45 46 constexpr int32_t DRAG_LEAVE = -1; 47 constexpr int32_t DRAG_ENTER = 1; 48 constexpr int32_t NONE = 0; 49 constexpr double ITEM_ANIMATION_DURATION = 300.0; 50 constexpr double ITEM_ANIMATION_DURATION_NO = 40.0; 51 52 constexpr double GRID_SPRING_MASS = 1.0; 53 constexpr double GRID_SPRING_STIFF = 228.0; 54 constexpr double GRID_SPRING_DAMP = 30.0; 55 constexpr double GRID_SPRING_DAMP_INC = 0; 56 constexpr double GRID_SPRING_SLIDE_LIMIT = 20.0; 57 58 }; // namespace 59 60 enum class GridLayoutAnimationAct { 61 ANIMATION_NONE = 0, 62 ANIMATION_DRAG_MOVE, 63 ANIMATION_DRAG_DROP, 64 ANIMATION_RESTORE_SCENE, 65 }; 66 67 enum class GridSpringGravitationDirect { 68 SPRING_NONE = 0, 69 SPRING_TO_LEFT, 70 SPRING_TO_RIGHT, 71 SPRING_TO_UP, 72 SPRING_TO_DOWN, 73 }; 74 75 enum class GridSlideDirect { 76 SLIDE_NODE = 0, 77 SLIDE_HORIZON, 78 SLIDE_VERTICAL, 79 }; 80 81 enum class GridSlideStatus { 82 SLIDE_NONE = 0, 83 SLIDE_START, 84 SLIDE_SLIDING, 85 SLIDE_SPRING_START, 86 }; 87 88 class GridItemIndexPosition { 89 public: GridItemIndexPosition(int32_t rowIndex,int32_t colIndex)90 GridItemIndexPosition(int32_t rowIndex, int32_t colIndex) : rowIndex_(rowIndex), colIndex_(colIndex) {} 91 ~GridItemIndexPosition() = default; GridItemIndexPosition(const GridItemIndexPosition & r)92 GridItemIndexPosition(const GridItemIndexPosition& r) 93 { 94 rowIndex_ = r.rowIndex_; 95 colIndex_ = r.colIndex_; 96 } 97 GridItemIndexPosition operator=(const GridItemIndexPosition& r) 98 { 99 if (this != &r) { 100 rowIndex_ = r.rowIndex_; 101 colIndex_ = r.colIndex_; 102 } 103 return *this; 104 } 105 bool operator==(const GridItemIndexPosition& data) 106 { 107 return (data.rowIndex_ == rowIndex_) && (data.colIndex_ == colIndex_); 108 } 109 bool operator!=(const GridItemIndexPosition& data) 110 { 111 return !(*this == data); 112 } 113 114 int32_t rowIndex_; 115 int32_t colIndex_; 116 }; 117 118 using OnItemDragFunc = std::function<void(const Dimension&, const Dimension&)>; 119 using OnAnimationCallJSFunc = std::function<void()>; 120 using OnCallJSDropFunc = std::function<void()>; 121 122 class RenderGridLayout : public RenderNode { 123 DECLARE_ACE_TYPE(RenderGridLayout, RenderNode); 124 125 public: 126 static RefPtr<RenderNode> Create(); 127 128 void Update(const RefPtr<Component>& component) override; 129 130 void PerformLayout() override; 131 bool IsUseOnly() override; 132 133 void OnTouchTestHit( 134 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 135 136 // Adjust focus index when grid_item request focus itself. 137 void UpdateFocusInfo(int32_t focusIndex); 138 139 // Support to grid element response focus event. 140 int32_t RequestNextFocus(bool vertical, bool reverse); 141 GetColumnsTemplate()142 const std::string& GetColumnsTemplate() const 143 { 144 return colsArgs_; 145 } 146 GetRowTemplate()147 const std::string& GetRowTemplate() const 148 { 149 return rowsArgs_; 150 } 151 GetColumnsGap()152 double GetColumnsGap() const 153 { 154 return colGap_; 155 } 156 GetRowGaps()157 double GetRowGaps() const 158 { 159 return rowGap_; 160 } 161 GetColumns()162 Dimension GetColumns() const 163 { 164 return userColGap_; 165 } 166 GetRows()167 Dimension GetRows() const 168 { 169 return userRowGap_; 170 } 171 GetScrollBarWidth()172 const std::string& GetScrollBarWidth() const 173 { 174 return scrollBarWidth_; 175 } 176 GetScrollBarColor()177 const std::string& GetScrollBarColor() const 178 { 179 return scrollBarColor_; 180 } 181 GetScrollBar()182 DisplayMode GetScrollBar() const 183 { 184 return displayMode_; 185 } 186 GetUpdatePositionId()187 const OnItemDragFunc& GetUpdatePositionId() const 188 { 189 return updatePosition_; 190 } 191 SetUpdatePositionId(const OnItemDragFunc & updatePosition)192 void SetUpdatePositionId(const OnItemDragFunc& updatePosition) 193 { 194 updatePosition_ = updatePosition; 195 } 196 GetEditMode()197 bool GetEditMode() const 198 { 199 return editMode_; 200 } 201 GetMaxCount()202 int32_t GetMaxCount() const 203 { 204 return mainCountMax_; 205 } 206 GetMinCount()207 int32_t GetMinCount() const 208 { 209 return mainCountMin_; 210 } 211 GetCellLength()212 int32_t GetCellLength() const 213 { 214 return cellLength_; 215 } 216 GetSupportAnimation()217 bool GetSupportAnimation() const 218 { 219 return supportAnimation_; 220 } 221 GetMultiSelectable()222 bool GetMultiSelectable() const 223 { 224 return isMultiSelectable_; 225 } 226 227 protected: 228 virtual LayoutParam MakeInnerLayoutParam( 229 int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan, bool itemIsPercentUnit = false) const; 230 231 void SetItemIndex(const RefPtr<RenderNode>& child, int32_t index); 232 233 int32_t GetItemRowIndex(const RefPtr<RenderNode>& child) const; 234 235 int32_t GetItemColumnIndex(const RefPtr<RenderNode>& child) const; 236 237 int32_t GetItemSpan(const RefPtr<RenderNode>& child, bool isRow) const; 238 239 virtual void GetNextGrid(int32_t& curRow, int32_t& curCol) const; 240 241 virtual void GetPreviousGird(int32_t& curRow, int32_t& curCol) const; 242 243 virtual bool CheckGridPlaced(int32_t index, int32_t row, int32_t col, int32_t& rowSpan, int32_t& colSpan); 244 245 int32_t GetIndexByGrid(int32_t row, int32_t column) const; 246 247 // Sets child position, the mainAxis does not contain the offset. 248 virtual void SetChildPosition( 249 const RefPtr<RenderNode>& child, int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan); 250 251 void DisableChild(const RefPtr<RenderNode>& child, int32_t index); 252 253 void ConvertRepeatArgs(std::string& args); 254 255 // Handle direction key move 256 int32_t focusMove(KeyDirection direction); 257 258 Size GetTargetLayoutSize(int32_t row, int32_t col); 259 260 std::string PreParseArgs(const std::string& args); 261 262 std::string PreParseRows(); 263 264 std::string PreParseCols(); 265 266 virtual void InitialGridProp(); 267 268 void UpdateAccessibilityAttr(); 269 270 std::vector<double> ParseArgs(const std::string& args, double size, double gap); 271 272 std::vector<double> ParseAutoFill(const std::vector<std::string>& strs, double size, double gap); 273 SetPreTargetRenderGrid(const RefPtr<RenderGridLayout> & preTargetRenderGrid)274 void SetPreTargetRenderGrid(const RefPtr<RenderGridLayout>& preTargetRenderGrid) 275 { 276 preTargetRenderGrid_ = preTargetRenderGrid; 277 } 278 GetPreTargetRenderGrid()279 const RefPtr<RenderGridLayout> GetPreTargetRenderGrid() const 280 { 281 return preTargetRenderGrid_.Upgrade(); 282 } 283 SetMainTargetRenderGrid(const RefPtr<RenderGridLayout> & mainTargetRenderGrid)284 void SetMainTargetRenderGrid(const RefPtr<RenderGridLayout>& mainTargetRenderGrid) 285 { 286 mainTargetRenderGrid_ = mainTargetRenderGrid; 287 } 288 GetMainTargetRenderGrid()289 const RefPtr<RenderGridLayout> GetMainTargetRenderGrid() const 290 { 291 return mainTargetRenderGrid_.Upgrade(); 292 } 293 SetLongPressPoint(const Point & lastLongPressPoint)294 void SetLongPressPoint(const Point& lastLongPressPoint) 295 { 296 lastLongPressPoint_ = lastLongPressPoint; 297 } 298 GetLongPressPoint()299 const Point GetLongPressPoint() const 300 { 301 return lastLongPressPoint_; 302 } 303 304 void ClearPartDragInfo(); 305 void ClearAllDragInfo(); 306 void CalIsVertical(); 307 void RegisterLongPressedForItems(); 308 void CreateDragDropRecognizer(); 309 void ActionStart(const ItemDragInfo& info, RefPtr<Component> customComponent); 310 void PanOnActionUpdate(const GestureEvent& info); 311 void PanOnActionEnd(const GestureEvent& info); 312 void OnDragEnter(const ItemDragInfo& info); 313 void OnDragLeave(const ItemDragInfo& info); 314 void OnDragMove(const ItemDragInfo& info); 315 bool OnDrop(const ItemDragInfo& info); 316 void ImpDragStart(const ItemDragInfo& info); 317 bool ImpDropInGrid(const ItemDragInfo& info); 318 319 void ImpDragMove(const ItemDragInfo& info); 320 void ImpDragLeaveMainGrid(const ItemDragInfo& info); 321 void ImpDragLeaveSubGrid(const ItemDragInfo& info); 322 void ImpDragEnterMainGrid(const ItemDragInfo& info); 323 void ImpDragEnterSubGrid(const ItemDragInfo& info); 324 void ImpDragEnterMainGridUpdate(); 325 void OnCallSubDragEnter(const ItemDragInfo& info); 326 void OnCallSubDragLeave(const ItemDragInfo& info); 327 328 // Check whether the item is currently allowed to be inserted 329 bool CouldBeInserted(); 330 bool NeedBeLarger(); 331 bool NeedBeSmaller(); 332 void BackGridMatrix(); 333 void RestoreScene(const ItemDragInfo& info); 334 335 int32_t CountItemInGrid(); 336 int32_t CountItemInRow(const std::map<int32_t, std::map<int32_t, int32_t>>::iterator& rowGrid); 337 void ResetItemPosition(); 338 void InitialDynamicGridProp(int32_t dragLeaveOrEnter = NONE); 339 void PerformLayoutForEditGrid(); 340 void PerformLayoutForStaticGrid(); 341 bool CalDragCell(const ItemDragInfo& info); 342 bool CalDragRowIndex(double dragRelativelyY, int32_t& dragRowIndex); 343 bool CalDragColumIndex(double dragRelativelyX, int32_t& dragColIndex); 344 void MoveItems(); 345 346 // These functions cannot be called independently, they must be called by MoveItems() 347 void MoveWhenNoInsertCell(); 348 void MoveWhenNoInsertCellAndNoItemInDragCell(); 349 void MoveWhenNoInsertCellButWithItemInDragCell(); 350 void MoveWhenNoInsertCellButWithItemInDragCellAndDragEnter(); 351 void MoveWhenNoInsertCellButWithItemInDragCellAndDragStart(); 352 void MoveWhenWithInsertCell(); 353 354 void MoveWhenWithInsertCellAndNoItemInDragCell(); 355 void MoveWhenWithInsertCellButWithItemInDragCell(); 356 void MoveWhenWithInsertCellButWithItemInDragCellDragBeforeInsert(); 357 void MoveWhenWithInsertCellButWithItemInDragCellDragAfterInsert(); 358 359 void FakeRemoveDragItem(); 360 void FakeRemoveDragItemUpdate(); 361 // it should be cells which has item in 362 bool MoveItemsForward(int32_t fromRow, int32_t fromColum, int32_t toRow, int32_t toColum); 363 364 // it should be cells which has item in 365 bool MoveItemsBackward(int32_t fromRow, int32_t fromColum, int32_t toRow, int32_t toColum); 366 void UpdateMatrixByIndexStrong(int32_t index, int32_t row, int32_t column); 367 void UpdateCurInsertPos(int32_t curInsertRow, int32_t curInsertColum); 368 int32_t CalIndexForItemByRowAndColum(int32_t row, int32_t column); 369 370 // If the first is equal the second, return true, else return false. 371 bool SortCellIndex(int32_t rowFirst, int32_t columFirst, int32_t rowSecond, int32_t columSecond, bool& firstIsPre); 372 373 // if there is no empty in the cell return false, else return true. 374 bool CalTheFirstEmptyCell(int32_t& rowIndex, int32_t& columIndex, bool ignoreInsert); 375 376 void SetGridLayoutParam(); 377 void CalculateVerticalSize(std::vector<double>& cols, std::vector<double>& rows, int32_t dragLeaveOrEnter); 378 void CalculateHorizontalSize(std::vector<double>& cols, std::vector<double>& rows, int32_t dragLeaveOrEnter); 379 void UpdateCollectionInfo(std::vector<double> cols, std::vector<double> rows); 380 void ClearSpringSlideData(); 381 void CreateSlideRecognizer(); 382 void HandleSlideStart(const TouchEventInfo& info); 383 void HandleSlideUpdate(const TouchEventInfo& info); 384 void HandleSlideEnd(const TouchEventInfo& info); 385 bool CheckLongPress(); 386 bool MayStartToSlide(const TouchEventInfo& info); 387 void UpdateSlideStatus(GridSlideStatus status); 388 GridSlideStatus GetSlideStatus(); 389 GridSlideDirect GetSlideDirect(); 390 Point GetPointFromTouchInfo(const TouchEventInfo& info); 391 void MoveRelativeDistance(double& dx, double& dy); 392 void CreateSpringController(); 393 Point GetSpringStartPoint(); 394 Point GetSpringEndPoint(); 395 void StartSpringAnimation(const Point& startPoint, const Point& endPoint); 396 void FinishedSpringAnimation(); 397 void UpdateSprintAnimationPosition(double offset); 398 void BackupSpringItemsData(); 399 void GetMotionPosition(const Point& startPoint, const Point& endPoint, double& start, double& end); 400 void CalcSlideDirect(const Point& curPos); 401 void CalcSpringGravitationDirect(); 402 403 void TriggerMoveEventForJS(const ItemDragInfo& info); 404 void TriggerDropEventForJS(const ItemDragInfo& info, int32_t insertIndex, bool success); 405 void InitAnimationController(const WeakPtr<PipelineContext>& context); 406 bool AddNodeAnimationToController(int32_t itemIndex, int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan); 407 void AddNodeAnimationToControllerForDrop( 408 const RefPtr<RenderNode>& item, const Point& startPoint, const Point& endPoint); 409 void PrepareAnimationController(const std::string& key); 410 void StartAnimationController(GridLayoutAnimationAct animationAct, const OnAnimationCallJSFunc& func); 411 void StopAnimationController(); 412 Point CalcChildPosition( 413 const RefPtr<RenderNode>& child, int32_t row, int32_t col, int32_t rowSpan, int32_t colSpan); 414 Point CalcDragChildStartPosition(const ItemDragInfo& info); 415 Point CalcDragChildEndPosition(int32_t rowIndex, int32_t colIndex); 416 void FinishedAnimationController(const std::string& key); 417 void RegisterAnimationFinishedFunc(const std::string& key, std::function<void()> func); 418 void CalcRestoreScenePosition(const ItemDragInfo& info); 419 void ParseRestoreScenePosition( 420 const std::map<int32_t, std::map<int32_t, int32_t>>& data, std::map<int32_t, GridItemIndexPosition>& info); GetDragPosRowIndex()421 int32_t GetDragPosRowIndex() 422 { 423 return dragPosRowIndex_; 424 } GetDragPosColumnIndex()425 int32_t GetDragPosColumnIndex() 426 { 427 return dragPosColumnIndex_; 428 } 429 void StartFlexController(const Point& endPoint, bool includeSubGrid = false); 430 void FinishedFlexController(); 431 void FinishedFlexControllerForSubGrid(); 432 void CloseFlexComponent(); 433 void UpdateFlexComponentPosition(const Point& pos); 434 void RegisterDropJSEvent(const ItemDragInfo& info, int32_t insertIndex, bool success); 435 void RegisterDropJSFunc(const OnCallJSDropFunc& func); 436 void CallDropJSFunc(); 437 bool CheckAnimation(); 438 bool CheckNeedShrink() const; 439 void RefreshAllocatedRowSizes(int32_t rowIndex, int32_t itemRowSpan, const RefPtr<RenderNode>& item); 440 441 bool isVertical_ = false; 442 bool updateFlag_ = false; 443 bool isDeclarative_ = false; 444 bool needShrink_ = false; 445 std::vector<double> allocatedRowSizes_; 446 FlexDirection direction_ = FlexDirection::ROW; 447 FlexAlign crossAxisAlign_ = FlexAlign::CENTER; 448 449 int32_t focusRow_ = -1; 450 int32_t focusCol_ = -1; 451 int32_t focusIndex_ = 0; 452 453 double colSize_ = 0.0; 454 double rowSize_ = 0.0; 455 double gridWidth_ = -1.0; 456 double gridHeight_ = -1.0; 457 int32_t colCount_ = 0; 458 int32_t rowCount_ = 0; 459 Dimension userColGap_ = 0.0_px; 460 Dimension userRowGap_ = 0.0_px; 461 double colGap_ = 0.0; 462 double rowGap_ = 0.0; 463 std::string colsArgs_; 464 std::string rowsArgs_; 465 std::string scrollBarWidth_; 466 std::string scrollBarColor_; 467 DisplayMode displayMode_ = DisplayMode::OFF; 468 bool rightToLeft_ = false; 469 bool needResetItemPosition_ = false; 470 // Map structure: [rowIndex - (columnIndex, index)] 471 std::map<int32_t, std::map<int32_t, int32_t>> gridMatrix_; 472 // Map structure: [rowIndex - columnIndex - (width, height)] 473 std::map<int32_t, std::map<int32_t, Size>> gridCells_; 474 475 RefPtr<GestureRecognizer> dragDropGesture_; 476 WeakPtr<RenderGridLayout> preTargetRenderGrid_ = nullptr; 477 WeakPtr<RenderGridLayout> mainTargetRenderGrid_ = nullptr; 478 479 // The list of renderNodes of items in the grid 480 std::vector<RefPtr<RenderNode>> itemsInGrid_; 481 482 // back for gridMatrix_ 483 std::map<int32_t, std::map<int32_t, int32_t>> gridMatrixBack_; 484 485 // The maximum number of items that the grid can hold 486 int32_t itemCountMax_ = -1; 487 488 // The grid length in the main axis direction 489 int32_t cellLength_ = 0; 490 491 // The maximum number of rows (columns) that can be accommodated in a variable direction. 492 // (only for dynamic limited grid) 493 int32_t mainCountMax_ = -1; 494 495 // The minimum number of rows (columns) that must be accommodated in the variable direction. 496 // (only for dynamic limited grid) 497 int32_t mainCountMin_ = -1; 498 499 // The maximum number of items that the grid can hold. 500 // (Only the dynamic grid needs to be used to determine whether the main sequence needs to be increased.) 501 int32_t curItemCountMax_ = -1; 502 503 // The rowIndex of the grid currently to be inserted 504 int32_t curInsertRowIndex_ = -1; 505 506 // The columnIndex of the grid currently to be inserted 507 int32_t curInsertColumnIndex_ = -1; 508 509 // The rowIndex of the grid where the Drag coordinates are located 510 int32_t dragPosRowIndex_ = -1; 511 512 // The columnIndex of the grid where the Drag coordinates are located 513 int32_t dragPosColumnIndex_ = -1; 514 515 // The index of the item currently being dragged. 516 int32_t draggingItemIndex_ = -1; 517 518 // Whether to send changes to the grid where the drag coordinate is located 519 bool dragPosChanged_ = false; 520 521 bool isDynamicGrid_ = false; 522 523 bool editMode_ = false; 524 525 bool itemLongPressed_ = false; 526 527 bool itemDragEntered_ = false; 528 529 bool itemDragStarted_ = false; 530 531 bool isDragChangeLayout_ = false; 532 533 bool needRestoreScene_ = false; 534 535 bool isInMainGrid_ = false; 536 537 bool isMainGrid_ = false; 538 539 bool reEnter_ = false; 540 541 WeakPtr<RenderNode> draggingItemRenderNode_; 542 WeakPtr<RenderGridLayout> subGrid_; 543 WeakPtr<RenderGridLayout> mainGrid_; 544 RefPtr<GridLayoutComponent> component_; 545 546 OnGridDragEnterFunc OnGridDragEnterFunc_; 547 OnGridDragMoveFunc onGridDragMoveFunc_; 548 OnGridDragLeaveFunc onGridDragLeaveFunc_; 549 OnGridDragStartFunc onGridDragStartFunc_; 550 OnGridDropFunc onGridDropFunc_; 551 552 OnItemDragFunc updatePosition_; 553 Point lastGlobalPoint_; 554 Point lastLongPressPoint_; 555 Point startGlobalPoint_; 556 bool isExistComponent_ = false; 557 std::atomic<bool> isDragging_; 558 559 GridLayoutAnimationAct animationAct_ = GridLayoutAnimationAct::ANIMATION_NONE; 560 RefPtr<Animator> animationController_; 561 RefPtr<Animator> flexController_; 562 bool supportAnimation_ = false; 563 bool dragAnimation_ = false; 564 EdgeEffect edgeEffect_ = EdgeEffect::NONE; 565 std::atomic<bool> needRunAnimation_; 566 std::map<std::string, std::function<void()>> animationFinishedFuncList_; 567 std::mutex animationLock_; 568 OnAnimationCallJSFunc jsMoveFunc_ = nullptr; 569 OnAnimationCallJSFunc jsDropFunc_ = nullptr; 570 OnAnimationCallJSFunc restoreSceneFunc_ = nullptr; 571 std::map<int32_t, Point> gridItemPosition_; 572 std::list<RefPtr<RenderNode>> animationItemList_; 573 std::atomic<bool> runFlexAnimation_; 574 std::atomic<bool> triggerJSDrop_; 575 std::vector<OnCallJSDropFunc> dropJSFuncList_; 576 std::mutex dropJSFuncListLock_; 577 578 RefPtr<RawRecognizer> slideRecognizer_; 579 GridSpringGravitationDirect gravitationDirect_ = GridSpringGravitationDirect::SPRING_NONE; 580 GridSlideDirect slideDirect_ = GridSlideDirect::SLIDE_NODE; 581 std::atomic<GridSlideStatus> slideStatus_; 582 Point slideStartPoint_; 583 Point slidePriPoint_; 584 Point slideCurPoint_; 585 Point slideDistance_; 586 RefPtr<Animator> springController_; 587 RefPtr<SpringMotion> springMotion_; 588 std::vector<Offset> springStartPosition_; 589 590 Offset mouseStartOffset_; 591 Offset mouseEndOffset_; 592 bool HandleMouseEvent(const MouseEvent& event) override; 593 bool isMultiSelectable_ = false; 594 void ClearMultiSelect(); 595 596 void MultiSelectWithoutKeyboard(const Rect& selectedZone); 597 void HandleMouseEventWithoutKeyboard(const MouseEvent& event); 598 599 void MultiSelectWhenCtrlDown(const Rect& selectedZone); 600 void HandleMouseEventWhenCtrlDown(const MouseEvent& event); 601 void CollectSelectedItems(); 602 std::set<RefPtr<RenderGridLayoutItem>> selectedItemsWithCtrl_; 603 604 void MultiSelectWhenShiftDown(const Rect& selectedZone); 605 RefPtr<RenderGridLayoutItem> GetPressItemWhenShiftDown(const Rect& selectedZone); 606 void HandleMouseEventWhenShiftDown(const MouseEvent& event); 607 void MultiSelectAllInRange(const RefPtr<RenderGridLayoutItem>& firstItem, 608 const RefPtr<RenderGridLayoutItem>& secondItem); 609 RefPtr<RenderGridLayoutItem> firstItemWithShift_; 610 RefPtr<RenderGridLayoutItem> secondItemWithShift_; 611 612 void MultiSelectAllWhenCtrlA(); 613 614 private: 615 typedef struct { 616 std::string str; 617 bool isRepeat = false; 618 } Value; 619 620 std::vector<double> ParseArgsWithAutoFill(const std::string& args, double size, double gap); 621 std::vector<double> ParseArgsInner(const std::string& args, double size, double gap); 622 void RTrim(std::string& str); 623 std::string TrimTemplate(std::string& str); 624 std::string GetRepeat(const std::string& str); 625 double ParseUnit(const Value& val); 626 bool CheckAutoFillParameter( 627 const std::string& args, double size, std::vector<double>& out, std::vector<Value>& resultvec); 628 double ConvertVirtualSize(const std::string& size, const DimensionUnit& unit); 629 bool SplitTemplate(const std::string& str, std::vector<Value>& vec, bool isRepeat = false); 630 bool CheckRepeatAndSplitString( 631 std::vector<std::string>& vec, std::string& repeat, std::vector<Value>& resultvec); 632 }; 633 634 } // namespace OHOS::Ace 635 636 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_GRID_LAYOUT_RENDER_GRID_LAYOUT_H 637