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_NG_EVENT_FOCUS_HUB_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_FOCUS_HUB_H 18 19 #include "base/memory/ace_type.h" 20 #include "core/components_ng/base/geometry_node.h" 21 #include "core/components_ng/event/focus_box.h" 22 #include "core/components_ng/event/touch_event.h" 23 #include "core/event/key_event.h" 24 #include "core/gestures/gesture_event.h" 25 26 namespace OHOS::Ace::NG { 27 28 class FrameNode; 29 class FocusHub; 30 class EventHub; 31 class FocusView; 32 class FocusManager; 33 34 using TabIndexNodeList = std::list<std::pair<int32_t, WeakPtr<FocusHub>>>; 35 constexpr int32_t DEFAULT_TAB_FOCUSED_INDEX = -2; 36 constexpr int32_t NONE_TAB_FOCUSED_INDEX = -1; 37 constexpr int32_t MASK_FOCUS_STEP_FORWARD = 0x10; 38 constexpr int32_t MASK_FOCUS_STEP_TAB = 0x5; 39 40 enum class FocusType : int32_t { 41 DISABLE = 0, 42 NODE = 1, 43 SCOPE = 2, 44 }; 45 enum class FocusNodeType : int32_t { 46 DEFAULT = 0, 47 GROUP_DEFAULT = 1, 48 }; 49 enum class ScopeType : int32_t { 50 OTHERS = 0, 51 FLEX = 1, 52 PROJECT_AREA = 2, 53 }; 54 enum class FocusStep : int32_t { 55 NONE = 0x0, 56 LEFT = 0x1, 57 UP = 0x2, 58 RIGHT = 0x11, 59 DOWN = 0x12, 60 LEFT_END = 0x3, 61 UP_END = 0x4, 62 RIGHT_END = 0X13, 63 DOWN_END = 0x14, 64 SHIFT_TAB = 0x5, 65 TAB = 0x15, 66 }; 67 enum class RequestFocusResult : int32_t { 68 DEFAULT = 0, 69 NON_FOCUSABLE = 1, 70 NON_FOCUSABLE_ANCESTOR = 2, 71 NON_EXIST = 3, 72 NON_FOCUSABLE_BY_TAB = 4, 73 }; 74 enum class SwitchingStartReason : int32_t { 75 DEFAULT = 0, 76 WINDOW_FOCUS = 1, 77 REQUEST_FOCUS = 2, 78 LOST_FOCUS_TO_VIEW_ROOT = 3, 79 REMOVE_SELF = 4, 80 REMOVE_CHILD = 5, 81 LOST_FOCUS_TO_TABSTOP = 6, 82 }; 83 enum class SwitchingEndReason : int32_t { 84 DEFAULT = 0, 85 FOCUS_GUARD_DESTROY = 1, 86 DEPENDENCE_SELF = 2, 87 NO_FOCUSABLE_CHILD = 3, 88 NODE_FOCUS = 4, 89 TAB_STOP = 5, 90 }; 91 enum class SwitchingUpdateReason : int32_t { 92 DEFAULT = 0, 93 SWITCH_FOCUS = 1, 94 ON_FOCUS_NODE = 2, 95 }; 96 97 using GetNextFocusNodeFunc = std::function<void(FocusStep, const WeakPtr<FocusHub>&, WeakPtr<FocusHub>&)>; 98 99 enum class FocusStyleType : int32_t { 100 NONE = -1, 101 INNER_BORDER = 0, 102 OUTER_BORDER = 1, 103 CUSTOM_BORDER = 2, 104 CUSTOM_REGION = 3, 105 FORCE_BORDER = 4, 106 FORCE_NONE = 5, 107 }; 108 109 enum class OnKeyEventType : int32_t { 110 DEFAULT = 0, 111 CONTEXT_MENU = 1, 112 }; 113 114 enum class FocusDependence : int32_t { 115 CHILD = 0, 116 SELF = 1, 117 AUTO = 2, 118 }; 119 120 enum class FocusPriority : int32_t { 121 AUTO = 0, 122 PRIOR = 2000, 123 PREVIOUS = 3000, 124 }; 125 126 class ACE_EXPORT FocusPaintParam : public virtual AceType { 127 DECLARE_ACE_TYPE(FocusPaintParam, AceType) 128 129 public: 130 FocusPaintParam() = default; 131 ~FocusPaintParam() override = default; 132 HasPaintRect()133 bool HasPaintRect() const 134 { 135 return paintRect.has_value(); 136 } GetPaintRect()137 const RoundRect& GetPaintRect() const 138 { 139 return paintRect.value(); 140 } 141 HasPaintColor()142 bool HasPaintColor() const 143 { 144 return paintColor.has_value(); 145 } GetPaintColor()146 const Color& GetPaintColor() const 147 { 148 return paintColor.value(); 149 } 150 HasPaintWidth()151 bool HasPaintWidth() const 152 { 153 return paintWidth.has_value(); 154 } GetPaintWidth()155 const Dimension& GetPaintWidth() const 156 { 157 return paintWidth.value(); 158 } 159 HasFocusPadding()160 bool HasFocusPadding() const 161 { 162 return focusPadding.has_value(); 163 } GetFocusPadding()164 const Dimension& GetFocusPadding() const 165 { 166 return focusPadding.value(); 167 } SetPaintRect(const RoundRect & rect)168 void SetPaintRect(const RoundRect& rect) 169 { 170 paintRect = rect; 171 } SetPaintColor(const Color & color)172 void SetPaintColor(const Color& color) 173 { 174 paintColor = color; 175 } SetPaintWidth(const Dimension & width)176 void SetPaintWidth(const Dimension& width) 177 { 178 paintWidth = width; 179 } SetFocusPadding(const Dimension & padding)180 void SetFocusPadding(const Dimension& padding) 181 { 182 focusPadding = padding; 183 } 184 185 private: 186 std::optional<RoundRect> paintRect; 187 std::optional<Color> paintColor; 188 std::optional<Dimension> paintWidth; 189 std::optional<Dimension> focusPadding; 190 }; 191 192 class ACE_EXPORT FocusPattern : public virtual AceType { 193 DECLARE_ACE_TYPE(FocusPattern, AceType) 194 195 public: 196 FocusPattern() = default; FocusPattern(FocusType focusType,bool focusable)197 FocusPattern(FocusType focusType, bool focusable) : focusType_(focusType), focusable_(focusable) {} FocusPattern(FocusType focusType,bool focusable,FocusStyleType styleType)198 FocusPattern(FocusType focusType, bool focusable, FocusStyleType styleType) 199 : focusType_(focusType), focusable_(focusable), styleType_(styleType) 200 {} FocusPattern(FocusType focusType,bool focusable,FocusStyleType styleType,const FocusPaintParam & paintParams)201 FocusPattern(FocusType focusType, bool focusable, FocusStyleType styleType, const FocusPaintParam& paintParams) 202 : focusType_(focusType), focusable_(focusable), styleType_(styleType) 203 { 204 if (!paintParams_) { 205 paintParams_ = std::make_unique<FocusPaintParam>(); 206 } 207 if (paintParams.HasPaintRect()) { 208 paintParams_->SetPaintRect(paintParams.GetPaintRect()); 209 } 210 if (paintParams.HasPaintColor()) { 211 paintParams_->SetPaintColor(paintParams.GetPaintColor()); 212 } 213 if (paintParams.HasPaintWidth()) { 214 paintParams_->SetPaintWidth(paintParams.GetPaintWidth()); 215 } 216 if (paintParams.HasFocusPadding()) { 217 paintParams_->SetFocusPadding(paintParams.GetFocusPadding()); 218 } 219 } FocusPattern(const FocusPattern & focusPattern)220 FocusPattern(const FocusPattern& focusPattern) 221 { 222 focusType_ = focusPattern.GetFocusType(); 223 focusable_ = focusPattern.GetFocusable(); 224 styleType_ = focusPattern.GetStyleType(); 225 if (focusPattern.GetFocusPaintParams()) { 226 SetFocusPaintParams(*focusPattern.GetFocusPaintParams()); 227 } 228 isFocusActiveWhenFocused_ = focusPattern.GetIsFocusActiveWhenFocused(); 229 } 230 ~FocusPattern() override = default; 231 GetFocusType()232 FocusType GetFocusType() const 233 { 234 return focusType_; 235 } SetFocusType(FocusType type)236 void SetFocusType(FocusType type) 237 { 238 focusType_ = type; 239 } 240 GetFocusable()241 bool GetFocusable() const 242 { 243 return focusable_; 244 } SetFocusable(bool focusable)245 void SetFocusable(bool focusable) 246 { 247 focusable_ = focusable; 248 } 249 GetStyleType()250 FocusStyleType GetStyleType() const 251 { 252 return styleType_; 253 } SetStyleType(FocusStyleType styleType)254 void SetStyleType(FocusStyleType styleType) 255 { 256 styleType_ = styleType; 257 } 258 GetFocusPaintParams()259 const std::unique_ptr<FocusPaintParam>& GetFocusPaintParams() const 260 { 261 return paintParams_; 262 } SetFocusPaintParams(const FocusPaintParam & paintParams)263 void SetFocusPaintParams(const FocusPaintParam& paintParams) 264 { 265 if (!paintParams_) { 266 paintParams_ = std::make_unique<FocusPaintParam>(); 267 } 268 if (paintParams.HasPaintRect()) { 269 paintParams_->SetPaintRect(paintParams.GetPaintRect()); 270 } 271 if (paintParams.HasPaintColor()) { 272 paintParams_->SetPaintColor(paintParams.GetPaintColor()); 273 } 274 if (paintParams.HasPaintWidth()) { 275 paintParams_->SetPaintWidth(paintParams.GetPaintWidth()); 276 } 277 if (paintParams.HasFocusPadding()) { 278 paintParams_->SetFocusPadding(paintParams.GetFocusPadding()); 279 } 280 } 281 GetIsFocusActiveWhenFocused()282 bool GetIsFocusActiveWhenFocused() const 283 { 284 return isFocusActiveWhenFocused_; 285 } SetIsFocusActiveWhenFocused(bool value)286 void SetIsFocusActiveWhenFocused(bool value) 287 { 288 isFocusActiveWhenFocused_ = value; 289 } 290 291 private: 292 FocusType focusType_ = FocusType::DISABLE; 293 bool focusable_ = false; 294 FocusStyleType styleType_ = FocusStyleType::NONE; 295 std::unique_ptr<FocusPaintParam> paintParams_ = nullptr; 296 bool isFocusActiveWhenFocused_ = false; 297 }; 298 299 enum class ScopeFocusDirection { 300 VERTICAL = 0, 301 HORIZONTAL, 302 UNIVERSAL, 303 }; 304 305 struct ScopeFocusAlgorithm final { 306 ScopeFocusAlgorithm() = default; ScopeFocusAlgorithmfinal307 ScopeFocusAlgorithm(bool isVertical, bool isLeftToRight, ScopeType scopeType) 308 : isVertical(isVertical), isLeftToRight(isLeftToRight), scopeType(scopeType) 309 {} ScopeFocusAlgorithmfinal310 ScopeFocusAlgorithm(bool isVertical, bool isLeftToRight, ScopeType scopeType, GetNextFocusNodeFunc&& function) 311 : isVertical(isVertical), isLeftToRight(isLeftToRight), scopeType(scopeType), 312 getNextFocusNode(std::move(function)) 313 {} ScopeFocusAlgorithmfinal314 ScopeFocusAlgorithm(ScopeFocusDirection direction, bool isVertical, bool isLeftToRight, ScopeType scopeType) 315 : direction(direction), isVertical(isVertical), isLeftToRight(isLeftToRight), scopeType(scopeType) 316 {} ScopeFocusAlgorithmfinal317 ScopeFocusAlgorithm(ScopeFocusDirection direction, bool isVertical, bool isLeftToRight, ScopeType scopeType, 318 GetNextFocusNodeFunc&& function) 319 : direction(direction), isVertical(isVertical), isLeftToRight(isLeftToRight), scopeType(scopeType), 320 getNextFocusNode(std::move(function)) 321 {} 322 ~ScopeFocusAlgorithm() = default; 323 324 // isVertical will be deleted 325 ScopeFocusDirection direction { ScopeFocusDirection::VERTICAL }; 326 bool isVertical { true }; 327 bool isLeftToRight { true }; 328 ScopeType scopeType { ScopeType::OTHERS }; 329 GetNextFocusNodeFunc getNextFocusNode; 330 }; 331 332 class ACE_EXPORT FocusCallbackEvents : public virtual AceType { 333 DECLARE_ACE_TYPE(FocusCallbackEvents, AceType) 334 public: 335 FocusCallbackEvents() = default; 336 ~FocusCallbackEvents() override = default; 337 338 OnFocusFunc onFocusCallback_; 339 OnFocusFunc onJSFrameNodeFocusCallback_; 340 OnBlurFunc onBlurCallback_; 341 OnBlurFunc onJSFrameNodeBlurCallback_; 342 OnKeyConsumeFunc onKeyEventCallback_; 343 OnKeyCallbackFunc onJSFrameNodeKeyEventCallback_; 344 OnKeyConsumeFunc onKeyPreImeCallback_; 345 GestureEventFunc onClickEventCallback_; 346 347 WeakPtr<FocusHub> defaultFocusNode_; 348 349 std::optional<bool> isFocusOnTouch_; 350 bool isDefaultFocus_ = { false }; 351 bool isDefaultHasFocused_ = { false }; 352 bool isDefaultGroupFocus_ = { false }; 353 bool isDefaultGroupHasFocused_ { false }; 354 355 int32_t tabIndex_ = 0; 356 }; 357 358 class ACE_EXPORT FocusHub : public virtual AceType { DECLARE_ACE_TYPE(FocusHub,AceType)359 DECLARE_ACE_TYPE(FocusHub, AceType) 360 public: 361 explicit FocusHub(const WeakPtr<EventHub>& eventHub, FocusType type = FocusType::DISABLE, bool focusable = false) 362 : eventHub_(eventHub), focusable_(focusable), focusType_(type) 363 {} FocusHub(const WeakPtr<EventHub> & eventHub,const FocusPattern & focusPattern)364 explicit FocusHub(const WeakPtr<EventHub>& eventHub, const FocusPattern& focusPattern) 365 { 366 eventHub_ = eventHub; 367 focusable_ = focusPattern.GetFocusable(); 368 focusType_ = focusPattern.GetFocusType(); 369 focusStyleType_ = focusPattern.GetStyleType(); 370 if (focusPattern.GetFocusPaintParams()) { 371 SetFocusPaintParamsPtr(focusPattern.GetFocusPaintParams()); 372 } 373 isFocusActiveWhenFocused_ = focusPattern.GetIsFocusActiveWhenFocused(); 374 } 375 ~FocusHub() override = default; 376 377 static constexpr int32_t SCROLL_TO_HEAD = -1; 378 static constexpr int32_t SCROLL_TO_TAIL = -2; 379 SetFocusStyleType(FocusStyleType type)380 void SetFocusStyleType(FocusStyleType type) 381 { 382 focusStyleType_ = type; 383 } GetFocusStyleType()384 FocusStyleType GetFocusStyleType() const 385 { 386 return focusStyleType_; 387 } 388 GetBlurReason()389 BlurReason GetBlurReason() const 390 { 391 return blurReason_; 392 } 393 SetFocusPaintParamsPtr(const std::unique_ptr<FocusPaintParam> & paramsPtr)394 void SetFocusPaintParamsPtr(const std::unique_ptr<FocusPaintParam>& paramsPtr) 395 { 396 CHECK_NULL_VOID(paramsPtr); 397 if (!focusPaintParamsPtr_) { 398 focusPaintParamsPtr_ = std::make_unique<FocusPaintParam>(); 399 } 400 if (paramsPtr->HasPaintRect()) { 401 focusPaintParamsPtr_->SetPaintRect(paramsPtr->GetPaintRect()); 402 } 403 if (paramsPtr->HasPaintColor()) { 404 focusPaintParamsPtr_->SetPaintColor(paramsPtr->GetPaintColor()); 405 } 406 if (paramsPtr->HasPaintWidth()) { 407 focusPaintParamsPtr_->SetPaintWidth(paramsPtr->GetPaintWidth()); 408 } 409 if (paramsPtr->HasFocusPadding()) { 410 focusPaintParamsPtr_->SetFocusPadding(paramsPtr->GetFocusPadding()); 411 } 412 } 413 HasPaintRect()414 bool HasPaintRect() const 415 { 416 return focusPaintParamsPtr_ ? focusPaintParamsPtr_->HasPaintRect() : false; 417 } GetPaintRect()418 RoundRect GetPaintRect() const 419 { 420 CHECK_NULL_RETURN(focusPaintParamsPtr_, RoundRect()); 421 return focusPaintParamsPtr_->GetPaintRect(); 422 } 423 HasPaintColor()424 bool HasPaintColor() const 425 { 426 return focusPaintParamsPtr_ ? focusPaintParamsPtr_->HasPaintColor() : false; 427 } GetPaintColor()428 const Color& GetPaintColor() const 429 { 430 CHECK_NULL_RETURN(focusPaintParamsPtr_, Color::TRANSPARENT); 431 return focusPaintParamsPtr_->GetPaintColor(); 432 } 433 HasPaintWidth()434 bool HasPaintWidth() const 435 { 436 return focusPaintParamsPtr_ ? focusPaintParamsPtr_->HasPaintWidth() : false; 437 } GetPaintWidth()438 Dimension GetPaintWidth() const 439 { 440 CHECK_NULL_RETURN(focusPaintParamsPtr_, Dimension()); 441 return focusPaintParamsPtr_->GetPaintWidth(); 442 } 443 HasFocusPadding()444 bool HasFocusPadding() const 445 { 446 return focusPaintParamsPtr_ ? focusPaintParamsPtr_->HasFocusPadding() : false; 447 } 448 HasBackwardFocusMovement()449 bool HasBackwardFocusMovement() const 450 { 451 return hasBackwardMovement_; 452 } 453 HasForwardFocusMovement()454 bool HasForwardFocusMovement() const 455 { 456 return hasForwardMovement_; 457 } 458 ClearFocusMovementFlags()459 void ClearFocusMovementFlags() 460 { 461 hasBackwardMovement_ = false; 462 hasForwardMovement_ = false; 463 } 464 465 bool HasBackwardFocusMovementInChildren(); 466 bool HasForwardFocusMovementInChildren(); 467 void ClearFocusMovementFlagsInChildren(); 468 GetFocusPadding()469 Dimension GetFocusPadding() const 470 { 471 CHECK_NULL_RETURN(focusPaintParamsPtr_, Dimension()); 472 return focusPaintParamsPtr_->GetFocusPadding(); 473 } SetPaintRect(const RoundRect & rect)474 void SetPaintRect(const RoundRect& rect) 475 { 476 if (!focusPaintParamsPtr_) { 477 focusPaintParamsPtr_ = std::make_unique<FocusPaintParam>(); 478 } 479 CHECK_NULL_VOID(focusPaintParamsPtr_); 480 focusPaintParamsPtr_->SetPaintRect(rect); 481 } SetPaintColor(const Color & color)482 void SetPaintColor(const Color& color) 483 { 484 if (!focusPaintParamsPtr_) { 485 focusPaintParamsPtr_ = std::make_unique<FocusPaintParam>(); 486 } 487 CHECK_NULL_VOID(focusPaintParamsPtr_); 488 focusPaintParamsPtr_->SetPaintColor(color); 489 } SetPaintWidth(const Dimension & width)490 void SetPaintWidth(const Dimension& width) 491 { 492 if (!focusPaintParamsPtr_) { 493 focusPaintParamsPtr_ = std::make_unique<FocusPaintParam>(); 494 } 495 CHECK_NULL_VOID(focusPaintParamsPtr_); 496 focusPaintParamsPtr_->SetPaintWidth(width); 497 } SetFocusPadding(const Dimension & padding)498 void SetFocusPadding(const Dimension& padding) 499 { 500 if (!focusPaintParamsPtr_) { 501 focusPaintParamsPtr_ = std::make_unique<FocusPaintParam>(); 502 } 503 CHECK_NULL_VOID(focusPaintParamsPtr_); 504 focusPaintParamsPtr_->SetFocusPadding(padding); 505 } 506 507 RefPtr<FocusManager> GetFocusManager() const; 508 RefPtr<FrameNode> GetFrameNode() const; 509 RefPtr<GeometryNode> GetGeometryNode() const; 510 RefPtr<FocusHub> GetParentFocusHub() const; 511 RefPtr<FocusHub> GetRootFocusHub(); 512 RefPtr<FocusHub> GetFocusLeaf(); 513 std::string GetFrameName() const; 514 int32_t GetFrameId() const; 515 516 bool HandleKeyEvent(const KeyEvent& keyEvent); 517 bool RequestFocusImmediately(bool isJudgeRootTree = false); 518 void RequestFocus() const; 519 void SwitchFocus(const RefPtr<FocusHub>& focusNode); 520 521 static void LostFocusToViewRoot(); 522 void LostFocusToTabStop(const RefPtr<FocusHub>& focusNode); 523 524 bool IsViewRootScope(); 525 void LostFocus(BlurReason reason = BlurReason::FOCUS_SWITCH); 526 void LostSelfFocus(); 527 void RemoveSelf(BlurReason reason = BlurReason::FRAME_DESTROY); 528 void RemoveChild(const RefPtr<FocusHub>& focusNode, BlurReason reason = BlurReason::FRAME_DESTROY); 529 bool GoToNextFocusLinear(FocusStep step, const RectF& rect = RectF()); 530 bool TryRequestFocus(const RefPtr<FocusHub>& focusNode, const RectF& rect, FocusStep step = FocusStep::NONE); InheritFocus()531 void InheritFocus() 532 { 533 OnFocusScope(true); 534 } 535 536 void CollectTabIndexNodes(TabIndexNodeList& tabIndexNodes); 537 bool GoToFocusByTabNodeIdx(TabIndexNodeList& tabIndexNodes, int32_t tabNodeIdx); 538 bool HandleFocusByTabIndex(const KeyEvent& event); 539 RefPtr<FocusHub> GetChildFocusNodeByType(FocusNodeType nodeType = FocusNodeType::DEFAULT); 540 RefPtr<FocusHub> GetChildFocusNodeById(const std::string& id); 541 bool TriggerFocusScroll(); 542 int32_t GetFocusingTabNodeIdx(TabIndexNodeList& tabIndexNodes) const; 543 bool RequestFocusImmediatelyById(const std::string& id, bool isSyncRequest = false); 544 RefPtr<FocusView> GetFirstChildFocusView(); 545 546 bool IsFocusableByTab(); 547 bool IsFocusableNodeByTab(); 548 bool IsFocusableScopeByTab(); 549 550 bool IsFocusableWholePath(); 551 bool IsSelfFocusableWholePath(); 552 bool IsOnRootTree() const; 553 554 bool IsFocusable(); 555 bool IsFocusableNode(); 556 bool IsFocusableScope(); 557 558 bool IsSyncRequestFocusable(); 559 bool IsSyncRequestFocusableNode(); 560 bool IsSyncRequestFocusableScope(); 561 IsParentFocusable()562 bool IsParentFocusable() const 563 { 564 return parentFocusable_; 565 } 566 void SetParentFocusable(bool parentFocusable); 567 568 void SetFocusable(bool focusable, bool isExplicit = true); 569 SetTabStop(bool tabStop)570 void SetTabStop(bool tabStop) 571 { 572 tabStop_ = tabStop; 573 } 574 GetFocusable()575 bool GetFocusable() const 576 { 577 return focusable_; 578 } 579 580 void SetShow(bool show); 581 void SetEnabled(bool enabled); 582 583 bool IsShow() const; 584 585 bool IsEnabled() const; 586 IsCurrentFocus()587 bool IsCurrentFocus() const 588 { 589 return currentFocus_; 590 } 591 IsTabStop()592 bool IsTabStop() const 593 { 594 return tabStop_; 595 } 596 bool IsCurrentFocusWholePath(); 597 598 bool HasFocusedChild(); 599 ClearUserOnFocus()600 void ClearUserOnFocus() 601 { 602 if (focusCallbackEvents_ && focusCallbackEvents_->onFocusCallback_) { 603 focusCallbackEvents_->onFocusCallback_ = nullptr; 604 } 605 } 606 SetOnFocusCallback(OnFocusFunc && onFocusCallback)607 void SetOnFocusCallback(OnFocusFunc&& onFocusCallback) 608 { 609 if (!focusCallbackEvents_) { 610 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 611 } 612 focusCallbackEvents_->onFocusCallback_ = std::move(onFocusCallback); 613 } GetOnFocusCallback()614 OnFocusFunc GetOnFocusCallback() 615 { 616 return focusCallbackEvents_ ? focusCallbackEvents_->onFocusCallback_ : nullptr; 617 } 618 ClearJSFrameNodeOnFocusCallback()619 void ClearJSFrameNodeOnFocusCallback() 620 { 621 if (focusCallbackEvents_) { 622 focusCallbackEvents_->onJSFrameNodeFocusCallback_ = nullptr; 623 } 624 } SetJSFrameNodeOnFocusCallback(OnFocusFunc && onFocusCallback)625 void SetJSFrameNodeOnFocusCallback(OnFocusFunc&& onFocusCallback) 626 { 627 if (!focusCallbackEvents_) { 628 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 629 } 630 focusCallbackEvents_->onJSFrameNodeFocusCallback_ = std::move(onFocusCallback); 631 } GetOnJSFrameNodeFocusCallback()632 OnFocusFunc GetOnJSFrameNodeFocusCallback() 633 { 634 return focusCallbackEvents_ ? focusCallbackEvents_->onJSFrameNodeFocusCallback_ : nullptr; 635 } 636 ClearUserOnBlur()637 void ClearUserOnBlur() 638 { 639 if (focusCallbackEvents_ && focusCallbackEvents_->onBlurCallback_) { 640 focusCallbackEvents_->onBlurCallback_ = nullptr; 641 } 642 } 643 SetOnBlurCallback(OnBlurFunc && onBlurCallback)644 void SetOnBlurCallback(OnBlurFunc&& onBlurCallback) 645 { 646 if (!focusCallbackEvents_) { 647 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 648 } 649 focusCallbackEvents_->onBlurCallback_ = std::move(onBlurCallback); 650 } 651 GetOnBlurCallback()652 OnBlurFunc GetOnBlurCallback() 653 { 654 return focusCallbackEvents_ ? focusCallbackEvents_->onBlurCallback_ : nullptr; 655 } 656 ClearJSFrameNodeOnBlurCallback()657 void ClearJSFrameNodeOnBlurCallback() 658 { 659 if (focusCallbackEvents_) { 660 focusCallbackEvents_->onJSFrameNodeBlurCallback_ = nullptr; 661 } 662 } SetJSFrameNodeOnBlurCallback(OnBlurFunc && onBlurCallback)663 void SetJSFrameNodeOnBlurCallback(OnBlurFunc&& onBlurCallback) 664 { 665 if (!focusCallbackEvents_) { 666 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 667 } 668 focusCallbackEvents_->onJSFrameNodeBlurCallback_ = std::move(onBlurCallback); 669 } GetOnJSFrameNodeBlurCallback()670 OnBlurFunc GetOnJSFrameNodeBlurCallback() 671 { 672 return focusCallbackEvents_ ? focusCallbackEvents_->onJSFrameNodeBlurCallback_ : nullptr; 673 } 674 SetOnKeyCallback(OnKeyConsumeFunc && onKeyCallback)675 void SetOnKeyCallback(OnKeyConsumeFunc&& onKeyCallback) 676 { 677 if (!focusCallbackEvents_) { 678 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 679 } 680 focusCallbackEvents_->onKeyEventCallback_ = std::move(onKeyCallback); 681 } 682 ClearUserOnKey()683 void ClearUserOnKey() 684 { 685 if (focusCallbackEvents_ && focusCallbackEvents_->onKeyEventCallback_) { 686 focusCallbackEvents_->onKeyEventCallback_ = nullptr; 687 } 688 } 689 GetOnKeyCallback()690 OnKeyConsumeFunc GetOnKeyCallback() 691 { 692 return focusCallbackEvents_ ? focusCallbackEvents_->onKeyEventCallback_ : nullptr; 693 } 694 SetOnKeyPreImeCallback(OnKeyConsumeFunc && onKeyCallback)695 void SetOnKeyPreImeCallback(OnKeyConsumeFunc&& onKeyCallback) 696 { 697 if (!focusCallbackEvents_) { 698 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 699 } 700 focusCallbackEvents_->onKeyPreImeCallback_ = std::move(onKeyCallback); 701 } 702 ClearOnKeyPreIme()703 void ClearOnKeyPreIme() 704 { 705 if (focusCallbackEvents_ && focusCallbackEvents_->onKeyPreImeCallback_) { 706 focusCallbackEvents_->onKeyPreImeCallback_ = nullptr; 707 } 708 } 709 GetOnKeyPreIme()710 OnKeyConsumeFunc GetOnKeyPreIme() 711 { 712 return focusCallbackEvents_ ? focusCallbackEvents_->onKeyPreImeCallback_ : nullptr; 713 } 714 ClearJSFrameNodeOnKeyCallback()715 void ClearJSFrameNodeOnKeyCallback() 716 { 717 if (focusCallbackEvents_) { 718 focusCallbackEvents_->onJSFrameNodeKeyEventCallback_ = nullptr; 719 } 720 } 721 SetJSFrameNodeOnKeyCallback(OnKeyCallbackFunc && onKeyCallback)722 void SetJSFrameNodeOnKeyCallback(OnKeyCallbackFunc&& onKeyCallback) 723 { 724 if (!focusCallbackEvents_) { 725 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 726 } 727 focusCallbackEvents_->onJSFrameNodeKeyEventCallback_ = std::move(onKeyCallback); 728 } 729 GetOnJSFrameNodeKeyCallback()730 OnKeyCallbackFunc GetOnJSFrameNodeKeyCallback() 731 { 732 return focusCallbackEvents_ ? focusCallbackEvents_->onJSFrameNodeKeyEventCallback_ : nullptr; 733 } 734 SetOnClickCallback(GestureEventFunc && onClickCallback)735 void SetOnClickCallback(GestureEventFunc&& onClickCallback) 736 { 737 if (!focusCallbackEvents_) { 738 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 739 } 740 focusCallbackEvents_->onClickEventCallback_ = std::move(onClickCallback); 741 } GetOnClickCallback()742 GestureEventFunc GetOnClickCallback() 743 { 744 return focusCallbackEvents_ ? focusCallbackEvents_->onClickEventCallback_ : nullptr; 745 } 746 SetOnFocusInternal(OnFocusFunc && onFocusInternal)747 void SetOnFocusInternal(OnFocusFunc&& onFocusInternal) 748 { 749 onFocusInternal_ = std::move(onFocusInternal); 750 } SetOnBlurInternal(OnBlurFunc && onBlurInternal)751 void SetOnBlurInternal(OnBlurFunc&& onBlurInternal) 752 { 753 onBlurInternal_ = std::move(onBlurInternal); 754 } SetOnBlurReasonInternal(OnBlurReasonFunc && onBlurReasonInternal)755 void SetOnBlurReasonInternal(OnBlurReasonFunc&& onBlurReasonInternal) 756 { 757 onBlurReasonInternal_ = std::move(onBlurReasonInternal); 758 } SetOnPreFocusCallback(OnPreFocusFunc && onPreFocusCallback)759 void SetOnPreFocusCallback(OnPreFocusFunc&& onPreFocusCallback) 760 { 761 onPreFocusCallback_ = std::move(onPreFocusCallback); 762 } 763 SetOnClearFocusStateInternal(OnClearFocusStateFunc && onClearFocusCallback)764 void SetOnClearFocusStateInternal(OnClearFocusStateFunc&& onClearFocusCallback) 765 { 766 onClearFocusStateCallback_ = std::move(onClearFocusCallback); 767 } 768 SetOnPaintFocusStateInternal(OnPaintFocusStateFunc && onPaintFocusCallback)769 void SetOnPaintFocusStateInternal(OnPaintFocusStateFunc&& onPaintFocusCallback) 770 { 771 onPaintFocusStateCallback_ = std::move(onPaintFocusCallback); 772 } 773 774 void SetOnKeyEventInternal(OnKeyEventFunc&& onKeyEvent, OnKeyEventType type = OnKeyEventType::DEFAULT) 775 { 776 onKeyEventsInternal_[type] = std::move(onKeyEvent); 777 } 778 FindContextMenuOnKeyEvent(OnKeyEventType type)779 bool FindContextMenuOnKeyEvent(OnKeyEventType type) 780 { 781 return (onKeyEventsInternal_.find(type) != onKeyEventsInternal_.end()); 782 } 783 ProcessOnKeyEventInternal(const KeyEvent & event)784 bool ProcessOnKeyEventInternal(const KeyEvent& event) 785 { 786 bool result = false; 787 for (const auto& onKeyEvent : onKeyEventsInternal_) { 788 auto callback = onKeyEvent.second; 789 if (callback && callback(event)) { 790 result = true; 791 } 792 } 793 return result; 794 } 795 796 std::list<RefPtr<FocusHub>>::iterator FlushChildrenFocusHub(std::list<RefPtr<FocusHub>>& focusNodes); 797 /* Manipulation on node-tree is forbidden in operation. */ 798 template <bool isReverse = false> 799 bool AnyChildFocusHub(const std::function<bool(const RefPtr<FocusHub>&)>& operation); 800 bool AnyChildFocusHub(bool isReverse, const std::function<bool(const RefPtr<FocusHub>&)>& operation); 801 template <bool isReverse = false> 802 void AllChildFocusHub(const std::function<void(const RefPtr<FocusHub>&)>& operation); 803 IsChild()804 bool IsChild() const 805 { 806 return focusType_ == FocusType::NODE; 807 } 808 SetRect(const RectF & rect)809 void SetRect(const RectF& rect) 810 { 811 rectFromOrigin_ = rect; 812 } GetRect()813 const RectF& GetRect() const 814 { 815 return rectFromOrigin_; 816 } 817 818 void DumpFocusTree(int32_t depth); 819 void DumpFocusNodeTree(int32_t depth); 820 void DumpFocusScopeTree(int32_t depth); 821 void DumpFocusUie(); 822 void DumpFocusUieInJson(std::unique_ptr<JsonValue>& json); 823 824 bool OnClick(const KeyEvent& event); 825 SetFocusType(FocusType type)826 void SetFocusType(FocusType type) 827 { 828 if (focusType_ != type && type == FocusType::DISABLE) { 829 RemoveSelf(BlurReason::FOCUS_SWITCH); 830 } 831 focusType_ = type; 832 833 if (IsImplicitFocusableScope() && focusDepend_ == FocusDependence::CHILD) { 834 focusDepend_ = FocusDependence::AUTO; 835 } 836 } GetFocusType()837 FocusType GetFocusType() const 838 { 839 return focusType_; 840 } 841 GetTabIndex()842 int32_t GetTabIndex() const 843 { 844 return focusCallbackEvents_ ? focusCallbackEvents_->tabIndex_ : 0; 845 } SetTabIndex(int32_t tabIndex)846 void SetTabIndex(int32_t tabIndex) 847 { 848 if (!focusCallbackEvents_) { 849 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 850 } 851 focusCallbackEvents_->tabIndex_ = tabIndex; 852 } 853 IsDefaultFocus()854 bool IsDefaultFocus() const 855 { 856 return focusCallbackEvents_ ? focusCallbackEvents_->isDefaultFocus_ : false; 857 } 858 SetIsDefaultFocus(bool isDefaultFocus)859 void SetIsDefaultFocus(bool isDefaultFocus) 860 { 861 if (!focusCallbackEvents_) { 862 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 863 } 864 focusCallbackEvents_->isDefaultFocus_ = isDefaultFocus; 865 } 866 IsDefaultGroupFocus()867 bool IsDefaultGroupFocus() const 868 { 869 return focusCallbackEvents_ ? focusCallbackEvents_->isDefaultGroupFocus_ : false; 870 } 871 SetIsDefaultGroupFocus(bool isDefaultGroupFocus)872 void SetIsDefaultGroupFocus(bool isDefaultGroupFocus) 873 { 874 if (!focusCallbackEvents_) { 875 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 876 } 877 focusCallbackEvents_->isDefaultGroupFocus_ = isDefaultGroupFocus; 878 } 879 GetDefaultFocusNode()880 WeakPtr<FocusHub> GetDefaultFocusNode() const 881 { 882 return focusCallbackEvents_ ? focusCallbackEvents_->defaultFocusNode_ : nullptr; 883 } 884 SetDefaultFocusNode(const WeakPtr<FocusHub> & node)885 void SetDefaultFocusNode(const WeakPtr<FocusHub>& node) 886 { 887 if (!focusCallbackEvents_) { 888 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 889 } 890 focusCallbackEvents_->defaultFocusNode_ = node; 891 } 892 IsFocusOnTouch()893 std::optional<bool> IsFocusOnTouch() const 894 { 895 return focusCallbackEvents_ ? focusCallbackEvents_->isFocusOnTouch_ : std::nullopt; 896 } 897 898 void SetIsFocusOnTouch(bool isFocusOnTouch); 899 SetIsDefaultHasFocused(bool isDefaultHasFocused)900 void SetIsDefaultHasFocused(bool isDefaultHasFocused) 901 { 902 if (!focusCallbackEvents_) { 903 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 904 } 905 focusCallbackEvents_->isDefaultHasFocused_ = isDefaultHasFocused; 906 } 907 IsDefaultHasFocused()908 bool IsDefaultHasFocused() const 909 { 910 return focusCallbackEvents_ ? focusCallbackEvents_->isDefaultHasFocused_ : false; 911 } 912 SetIsDefaultGroupHasFocused(bool isDefaultGroupHasFocused)913 void SetIsDefaultGroupHasFocused(bool isDefaultGroupHasFocused) 914 { 915 if (!focusCallbackEvents_) { 916 focusCallbackEvents_ = MakeRefPtr<FocusCallbackEvents>(); 917 } 918 focusCallbackEvents_->isDefaultGroupHasFocused_ = isDefaultGroupHasFocused; 919 } 920 IsDefaultGroupHasFocused()921 bool IsDefaultGroupHasFocused() const 922 { 923 return focusCallbackEvents_ ? focusCallbackEvents_->isDefaultGroupHasFocused_ : false; 924 } 925 IsImplicitFocusableScope()926 bool IsImplicitFocusableScope() const 927 { 928 return (focusType_ == FocusType::SCOPE) && focusable_ && implicitFocusable_; 929 } 930 931 std::optional<std::string> GetInspectorKey() const; 932 933 bool PaintFocusState(bool isNeedStateStyles = true); 934 bool PaintAllFocusState(); 935 bool PaintInnerFocusState(const RoundRect& paintRect, bool forceUpdate = false); 936 void ClearFocusState(bool isNeedStateStyles = true); 937 void ClearAllFocusState(); 938 void PrintOnKeyEventUserInfo(const KeyEvent& keyEvent, bool retCallback); 939 SetInnerFocusPaintRectCallback(const std::function<void (RoundRect &)> & callback)940 void SetInnerFocusPaintRectCallback(const std::function<void(RoundRect&)>& callback) 941 { 942 getInnerFocusRectFunc_ = callback; 943 } 944 SetLastWeakFocusNode(const WeakPtr<FocusHub> & focusHub)945 void SetLastWeakFocusNode(const WeakPtr<FocusHub>& focusHub) 946 { 947 lastWeakFocusNode_ = focusHub; 948 } GetLastWeakFocusNode()949 WeakPtr<FocusHub> GetLastWeakFocusNode() const 950 { 951 return lastWeakFocusNode_; 952 } 953 SetIsFocusUnit(bool isFocusUnit)954 void SetIsFocusUnit(bool isFocusUnit) 955 { 956 isFocusUnit_ = isFocusUnit; 957 } 958 GetFocusDependence()959 FocusDependence GetFocusDependence() const 960 { 961 return focusDepend_; 962 } SetFocusDependence(FocusDependence focusDepend)963 void SetFocusDependence(FocusDependence focusDepend) 964 { 965 focusDepend_ = focusDepend; 966 } 967 GetFocusableCount()968 size_t GetFocusableCount() 969 { 970 size_t count = 0; 971 AllChildFocusHub([&count](const RefPtr<FocusHub>& child) { 972 if (child->IsFocusable()) { 973 count++; 974 } 975 }); 976 return count; 977 } 978 SetIsFocusActiveWhenFocused(bool value)979 void SetIsFocusActiveWhenFocused(bool value) 980 { 981 isFocusActiveWhenFocused_ = value; 982 } GetIsFocusActiveWhenFocused()983 bool GetIsFocusActiveWhenFocused() const 984 { 985 return isFocusActiveWhenFocused_; 986 } 987 IsFocusStepVertical(FocusStep step)988 static inline bool IsFocusStepVertical(FocusStep step) 989 { 990 return (static_cast<uint32_t>(step) & 0x1) == 0; 991 } 992 993 static inline bool IsFocusStepForward(FocusStep step, bool isRtl = false) 994 { 995 bool isForward = (static_cast<uint32_t>(step) & MASK_FOCUS_STEP_FORWARD) != 0; 996 if (isRtl && (step == FocusStep::RIGHT || step == FocusStep::LEFT)) { 997 isForward = !isForward; 998 } 999 return isForward; 1000 } 1001 IsFocusStepTab(FocusStep step)1002 static inline bool IsFocusStepTab(FocusStep step) 1003 { 1004 return (static_cast<uint32_t>(step) & MASK_FOCUS_STEP_TAB) == MASK_FOCUS_STEP_TAB; 1005 } 1006 1007 static inline FocusStep GetRealFocusStepByTab(FocusStep moveStep, bool isRtl = false) 1008 { 1009 if (isRtl) { 1010 return moveStep == FocusStep::TAB ? FocusStep::LEFT : FocusStep::RIGHT; 1011 } else { 1012 return moveStep == FocusStep::TAB ? FocusStep::RIGHT : FocusStep::LEFT; 1013 } 1014 } 1015 1016 static double GetProjectAreaOnRect(const RectF& rect, const RectF& projectRect, FocusStep step); 1017 1018 void SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut = true); 1019 void SetFocusScopePriority(const std::string& focusScopeId, const uint32_t focusPriority); 1020 void RemoveFocusScopeIdAndPriority(); 1021 bool AcceptFocusOfPriorityChild(); 1022 bool SetLastWeakFocusNodeToPreviousNode(); 1023 void SetLastWeakFocusToPreviousInFocusView(); GetIsFocusGroup()1024 bool GetIsFocusGroup() const 1025 { 1026 return isGroup_; 1027 } 1028 GetIsFocusScope()1029 bool GetIsFocusScope() const 1030 { 1031 return isFocusScope_; 1032 } 1033 GetFocusScopeId()1034 std::string GetFocusScopeId() const 1035 { 1036 return focusScopeId_; 1037 } 1038 GetFocusBox()1039 FocusBox& GetFocusBox() 1040 { 1041 return box_; 1042 } 1043 GetFocusPriority()1044 FocusPriority GetFocusPriority() const 1045 { 1046 return focusPriority_; 1047 } 1048 1049 static void ToJsonValue( 1050 const RefPtr<FocusHub>& hub, std::unique_ptr<JsonValue>& json, const InspectorFilter& filter); 1051 1052 bool FocusToHeadOrTailChild(bool isHead); 1053 1054 WeakPtr<FocusHub> GetUnfocusableParentFocusNode(); 1055 protected: 1056 bool OnKeyEvent(const KeyEvent& keyEvent); 1057 bool OnKeyEventNode(const KeyEvent& keyEvent); 1058 bool OnKeyEventScope(const KeyEvent& keyEvent); 1059 bool RequestNextFocusOfKeyTab(const KeyEvent& keyEvent); 1060 bool RequestNextFocusOfKeyEnter(); 1061 bool RequestNextFocusOfKeyEsc(); 1062 bool OnKeyPreIme(KeyEventInfo& info, const KeyEvent& keyEvent); 1063 1064 bool AcceptFocusOfSpecifyChild(FocusStep step); 1065 bool AcceptFocusOfLastFocus(); 1066 bool AcceptFocusByRectOfLastFocus(const RectF& rect); 1067 bool AcceptFocusByRectOfLastFocusNode(const RectF& rect); 1068 bool AcceptFocusByRectOfLastFocusFlex(const RectF& rect); 1069 1070 bool CalculateRect(const RefPtr<FocusHub>& childNode, RectF& rect) const; 1071 bool RequestNextFocus(FocusStep moveStep, const RectF& rect); 1072 1073 void OnFocus(); 1074 void OnFocusNode(); 1075 void OnFocusScope(bool currentHasFocused = false); 1076 void OnBlur(); 1077 void OnBlurNode(); 1078 void OnBlurScope(); 1079 HandleFocus()1080 void HandleFocus() 1081 { 1082 // Need update: void RenderNode::MoveWhenOutOfViewPort(bool hasEffect) 1083 OnFocus(); 1084 } 1085 1086 private: 1087 friend class FocusView; 1088 friend class FocusManager; 1089 1090 bool CalculatePosition(); 1091 1092 bool IsLeafFocusScope(); 1093 1094 void ClearLastFocusNode(); 1095 1096 void SetScopeFocusAlgorithm(); 1097 1098 void SetLastFocusNodeIndex(const RefPtr<FocusHub>& focusNode); 1099 1100 void ScrollToLastFocusIndex() const; 1101 1102 void CheckFocusStateStyle(bool onFocus); 1103 bool HasFocusStateStyle(); 1104 1105 bool IsNeedPaintFocusState(); 1106 1107 bool ScrollByOffset(); 1108 bool ScrollByOffsetToParent(const RefPtr<FrameNode>& parentFrameNode) const; 1109 1110 RefPtr<FocusHub> GetNearestNodeByProjectArea(const std::list<RefPtr<FocusHub>>& allNodes, FocusStep step); 1111 1112 bool UpdateFocusView(); 1113 1114 bool IsFocusAbleChildOf(const RefPtr<FocusHub>& parentFocusHub); 1115 WeakPtr<FocusHub> GetChildPriorfocusNode(const std::string& focusScopeId); 1116 bool RequestFocusByPriorityInScope(); 1117 bool IsInFocusGroup(); 1118 bool IsNestingFocusGroup(); 1119 void SetLastWeakFocusNodeWholeScope(const std::string &focusScopeId); 1120 1121 void RaiseZIndex(); // Recover z-index in ClearFocusState 1122 1123 bool RequestFocusImmediatelyInner(bool isJudgeRootTree = false); 1124 bool OnKeyEventNodeInternal(const KeyEvent& keyEvent); 1125 bool OnKeyEventNodeUser(KeyEventInfo& info, const KeyEvent& keyEvent); 1126 bool RequestNextFocusByKey(const KeyEvent& keyEvent); 1127 1128 // donot move focus before detach if has focus view child 1129 bool SkipFocusMoveBeforeRemove() const; 1130 1131 bool IsArrowKeyStepOut(FocusStep moveStep); 1132 1133 OnFocusFunc onFocusInternal_; 1134 OnBlurFunc onBlurInternal_; 1135 OnBlurReasonFunc onBlurReasonInternal_; 1136 std::unordered_map<OnKeyEventType, OnKeyEventFunc> onKeyEventsInternal_; 1137 OnPreFocusFunc onPreFocusCallback_; 1138 OnClearFocusStateFunc onClearFocusStateCallback_; 1139 OnPaintFocusStateFunc onPaintFocusStateCallback_; 1140 1141 RefPtr<FocusCallbackEvents> focusCallbackEvents_; 1142 1143 RefPtr<TouchEventImpl> focusOnTouchListener_; 1144 1145 WeakPtr<EventHub> eventHub_; 1146 1147 WeakPtr<FocusHub> lastWeakFocusNode_ { nullptr }; 1148 int32_t lastFocusNodeIndex_ { -1 }; 1149 int32_t lastTabIndexNodeId_ { DEFAULT_TAB_FOCUSED_INDEX }; 1150 1151 bool focusable_ { true }; 1152 bool isFocusableExplicit_ { false }; 1153 bool implicitFocusable_ { false }; 1154 bool parentFocusable_ { true }; 1155 bool currentFocus_ { false }; 1156 bool isFocusUnit_ { false }; 1157 bool hasForwardMovement_ { false }; 1158 bool hasBackwardMovement_ { false }; 1159 bool isFocusActiveWhenFocused_ { false }; 1160 bool isRaisedZIndex_ { false }; 1161 1162 FocusType focusType_ = FocusType::DISABLE; 1163 FocusStyleType focusStyleType_ = FocusStyleType::NONE; 1164 std::unique_ptr<FocusPaintParam> focusPaintParamsPtr_; 1165 std::function<void(RoundRect&)> getInnerFocusRectFunc_; 1166 FocusBox box_; 1167 1168 RectF rectFromOrigin_; 1169 ScopeFocusAlgorithm focusAlgorithm_; 1170 BlurReason blurReason_ = BlurReason::FOCUS_SWITCH; 1171 FocusDependence focusDepend_ = FocusDependence::CHILD; 1172 1173 std::string focusScopeId_; 1174 bool isFocusScope_ { false }; 1175 bool isGroup_ { false }; 1176 FocusPriority focusPriority_ = FocusPriority::AUTO; 1177 bool arrowKeyStepOut_ { true }; 1178 bool tabStop_ { false }; 1179 bool isSwitchByEnter_ { false }; 1180 }; 1181 } // namespace OHOS::Ace::NG 1182 1183 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_FOCUS_HUB_H 1184