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