1 /* 2 * Copyright (c) 2021 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_TAB_BAR_TAB_BAR_ITEM_ELEMENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_BAR_ITEM_ELEMENT_H 18 19 #include "core/components/box/box_element.h" 20 #include "core/focus/focus_node.h" 21 #include "core/components/tab_bar/render_tab_bar_item.h" 22 23 namespace OHOS::Ace { 24 25 class TabBarItemElement : public BoxElement, public FocusGroup { 26 DECLARE_ACE_TYPE(TabBarItemElement, BoxElement, FocusGroup); 27 28 public: OnFocus()29 void OnFocus() override 30 { 31 if (renderNode_) { 32 renderNode_->ChangeStatus(RenderStatus::FOCUS); 33 } 34 FocusGroup::OnFocus(); 35 } 36 OnBlur()37 void OnBlur() override 38 { 39 if (renderNode_) { 40 renderNode_->ChangeStatus(RenderStatus::BLUR); 41 } 42 FocusGroup::OnBlur(); 43 } 44 RequestNextFocus(bool vertical,bool reverse,const Rect & rect)45 bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override 46 { 47 return false; 48 } 49 IsFocusable()50 bool IsFocusable() const override 51 { 52 return FocusNode::IsFocusable(); 53 } 54 AcceptFocusByRectOfLastFocus(const Rect & rect)55 bool AcceptFocusByRectOfLastFocus(const Rect& rect) override 56 { 57 return FocusNode::AcceptFocusByRectOfLastFocus(rect); 58 } 59 CreateRenderNode()60 RefPtr<RenderNode> CreateRenderNode() override 61 { 62 auto tabBarItemComponent = AceType::DynamicCast<TabBarItemComponent>(component_); 63 if (!tabBarItemComponent) { 64 return nullptr; 65 } 66 auto renderTabBarItem = AceType::DynamicCast<RenderTabBarItem>(tabBarItemComponent->CreateRenderNode()); 67 if (renderTabBarItem && tabBarItemComponent->GetEnableDebugBoundary()) { 68 renderTabBarItem->SetEnableDebugBoundary(true); 69 } 70 return renderTabBarItem; 71 } 72 }; 73 74 } // namespace OHOS::Ace 75 76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TAB_BAR_TAB_BAR_ITEM_ELEMENT_H 77