diff --git a/frameworks/bridge/declarative_frontend/jsview/js_button.cpp b/frameworks/bridge/declarative_frontend/jsview/js_button.cpp index ac0623bd..d474fc62 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_button.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_button.cpp @@ -222,6 +222,7 @@ void JSButton::CreateWithLabel(const JSCallbackInfo& info) SetTypeAndStateEffect(JSRef::Cast(info[1]), buttonComponent); } ViewStackProcessor::GetInstance()->Push(buttonComponent); + JSInteractableView::SetFocusable(true); JSInteractableView::SetFocusNode(true); buttonComponent->SetMouseAnimationType(HoverAnimationType::SCALE); @@ -238,6 +239,7 @@ void JSButton::CreateWithChild(const JSCallbackInfo& info) SetTypeAndStateEffect(obj, buttonComponent); } ViewStackProcessor::GetInstance()->Push(buttonComponent); + JSInteractableView::SetFocusable(true); JSInteractableView::SetFocusNode(true); buttonComponent->SetMouseAnimationType(HoverAnimationType::SCALE); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_hyperlink.cpp b/frameworks/bridge/declarative_frontend/jsview/js_hyperlink.cpp index 6f877ad8..2c5df01a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_hyperlink.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_hyperlink.cpp @@ -48,6 +48,7 @@ void JSHyperlink::Create(const JSCallbackInfo& args) } ViewStackProcessor::GetInstance()->Push(component); + JSInteractableView::SetFocusable(false); JSInteractableView::SetFocusNode(true); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_image.cpp b/frameworks/bridge/declarative_frontend/jsview/js_image.cpp index 8cf38ce9..2ee7cee1 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_image.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_image.cpp @@ -290,7 +290,7 @@ void JSImage::Create(const JSCallbackInfo& info) RefPtr imageComponent = AceType::MakeRefPtr(src); imageComponent->SetUseSkiaSvg(false); ViewStackProcessor::GetInstance()->Push(imageComponent); - JSInteractableView::SetFocusable(true); + JSInteractableView::SetFocusable(false); JSInteractableView::SetFocusNode(false); if (noPixMap) { return; diff --git a/frameworks/bridge/declarative_frontend/jsview/js_indexer.cpp b/frameworks/bridge/declarative_frontend/jsview/js_indexer.cpp index 15fccc36..57de7977 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_indexer.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_indexer.cpp @@ -62,6 +62,7 @@ void JSIndexer::Create(const JSCallbackInfo& args) auto indexerComponent = AceType::MakeRefPtr(indexerArray, selectedVal); ViewStackProcessor::GetInstance()->Push(indexerComponent); + JSInteractableView::SetFocusable(true); JSInteractableView::SetFocusNode(true); args.ReturnSelf(); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_list.cpp b/frameworks/bridge/declarative_frontend/jsview/js_list.cpp index d9f473b2..66ae84d7 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_list.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_list.cpp @@ -95,6 +95,7 @@ void JSList::Create(const JSCallbackInfo& args) } ViewStackProcessor::GetInstance()->Push(listComponent); + JSInteractableView::SetFocusable(true); JSInteractableView::SetFocusNode(true); args.ReturnSelf(); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_list_item.cpp b/frameworks/bridge/declarative_frontend/jsview/js_list_item.cpp index 64ee73a7..f396cbda 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_list_item.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_list_item.cpp @@ -33,6 +33,7 @@ void JSListItem::Create(const JSCallbackInfo& args) listItemComponent->SetType(args[0]->ToString()); } ViewStackProcessor::GetInstance()->Push(listItemComponent); + JSInteractableView::SetFocusable(true); JSInteractableView::SetFocusNode(true); args.ReturnSelf(); } diff --git a/frameworks/bridge/declarative_frontend/jsview/js_side_bar.cpp b/frameworks/bridge/declarative_frontend/jsview/js_side_bar.cpp index 843c3b02..b4bacbd2 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_side_bar.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_side_bar.cpp @@ -1,201 +1,202 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "frameworks/bridge/declarative_frontend/jsview/js_side_bar.h" - -#include "base/geometry/dimension.h" -#include "core/components/button/button_component.h" -#include "core/components/side_bar/render_side_bar_container.h" -#include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h" -#include "frameworks/bridge/declarative_frontend/view_stack_processor.h" - -namespace OHOS::Ace::Framework { -void JSSideBar::Create(const JSCallbackInfo& info) -{ - if (info.Length() < 1) { - LOGE("The arg is wrong, it is supposed to have at least 1 arguments"); - return; - } - - SideBarContainerType style = SideBarContainerType::EMBED; - if (!info[0]->IsNull()) { - if (info[0]->IsBoolean()) { - style = static_cast(info[0]->ToBoolean()); - } else if (info[0]->IsNumber()) { - style = static_cast(info[0]->ToNumber()); - } else { - LOGE("The arg is wrong"); - return; - } - } - - std::list> children; - auto sideBarContainer = AceType::MakeRefPtr(children); - sideBarContainer->SetMainStackSize(MainStackSize::MAX); - sideBarContainer->SetSideBarContainerType(style); - - auto stack = ViewStackProcessor::GetInstance(); - stack->Push(sideBarContainer); - JSInteractableView::SetFocusNode(true); -} - -void JSSideBar::SetShowControlButton(bool isShow) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto component = AceType::DynamicCast(stack->GetMainComponent()); - if (!component) { - LOGE("side bar is null"); - return; - } - - component->SetShowControlButton(isShow); -} - -void JSSideBar::JSBind(BindingTarget globalObj) -{ - JSClass::Declare("SideBarContainer"); - MethodOptions opt = MethodOptions::NONE; - JSClass::StaticMethod("create", &JSSideBar::Create, opt); - JSClass::StaticMethod("showSideBar", &JSSideBar::JsShowSideBar); - JSClass::StaticMethod("controlButton", &JSSideBar::JsControlButton); - JSClass::StaticMethod("showControlButton", &JSSideBar::SetShowControlButton); - JSClass::StaticMethod("onChange", &JSSideBar::OnChange); - JSClass::StaticMethod("sideBarWidth", &JSSideBar::JsSideBarWidth); - JSClass::StaticMethod("minSideBarWidth", &JSSideBar::JsMinSideBarWidth); - JSClass::StaticMethod("maxSideBarWidth", &JSSideBar::JsMaxSideBarWidth); - JSClass::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); - JSClass::StaticMethod("width", SetWidth); - JSClass::StaticMethod("height", SetHeight); - JSClass::StaticMethod("size", SetSize); - JSClass::StaticMethod("width", &JSStack::SetWidth); - JSClass::StaticMethod("height", &JSStack::SetHeight); - JSClass::StaticMethod("size", &JSStack::SetSize); - JSClass::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey); - JSClass::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete); - JSClass::StaticMethod("onClick", &JSInteractableView::JsOnClick); - JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); - JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); - JSClass::Inherit(); - JSClass::Inherit(); - JSClass::Bind(globalObj); -} - -void JSSideBar::OnChange(const JSCallbackInfo& info) -{ - if (!JSViewBindEvent(&SideBarContainerComponent::SetOnChange, info)) { - LOGE("Failed to bind event"); - } - info.ReturnSelf(); -} - -void JSSideBar::JsSideBarWidth(double length) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto component = AceType::DynamicCast(stack->GetMainComponent()); - if (!component) { - LOGE("side bar is null"); - return; - } - component->SetSideBarWidth(Dimension(length, DimensionUnit::VP)); -} - -void JSSideBar::JsMaxSideBarWidth(double length) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto component = AceType::DynamicCast(stack->GetMainComponent()); - if (!component) { - LOGE("side bar is null"); - return; - } - component->SetSideBarMaxWidth(Dimension(length, DimensionUnit::VP)); -} - -void JSSideBar::JsMinSideBarWidth(double length) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto component = AceType::DynamicCast(stack->GetMainComponent()); - if (!component) { - LOGE("side bar is null"); - return; - } - component->SetSideBarMinWidth(Dimension(length, DimensionUnit::VP)); -} - -void JSSideBar::JsShowSideBar(bool isShow) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto component = AceType::DynamicCast(stack->GetMainComponent()); - if (!component) { - LOGE("side bar is null"); - return; - } - component->SetShowSideBar(isShow); -} - -void JSSideBar::JsControlButton(const JSCallbackInfo& info) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto component = AceType::DynamicCast(stack->GetMainComponent()); - if (!component) { - LOGE("side bar is null"); - return; - } - - if (!info[0]->IsNull() && info[0]->IsObject()) { - JSRef value = JSRef::Cast(info[0]); - JSRef width = value->GetProperty("width"); - JSRef height = value->GetProperty("height"); - JSRef left = value->GetProperty("left"); - JSRef top = value->GetProperty("top"); - JSRef icons = value->GetProperty("icons"); - - if (!width->IsNull() && width->IsNumber()) { - component->SetButtonWidth(width->ToNumber()); - } - - if (!height->IsNull() && height->IsNumber()) { - component->SetButtonHeight(height->ToNumber()); - } - - if (!left->IsNull() && left->IsNumber()) { - component->SetButtonLeft(left->ToNumber()); - } - - if (!top->IsNull() && top->IsNumber()) { - component->SetButtonTop(top->ToNumber()); - } - - if (!icons->IsNull() && icons->IsObject()) { - JSRef iconsVal = JSRef::Cast(icons); - JSRef showIcon = iconsVal->GetProperty("shown"); - JSRef switchingIcon = iconsVal->GetProperty("switching"); - JSRef hiddenIcon = iconsVal->GetProperty("hidden"); - std::string showIconStr; - if (!showIcon->IsNull() && ParseJsMedia(showIcon, showIconStr)) { - component->SetShowIcon(showIconStr); - } - std::string hiddenIconStr; - if (!hiddenIcon->IsNull() && ParseJsMedia(hiddenIcon, hiddenIconStr)) { - component->SetHiddenIcon(hiddenIconStr); - } - std::string switchingIconStr; - if (!switchingIcon->IsNull() && ParseJsMedia(switchingIcon, switchingIconStr)) { - component->SetSwitchIcon(switchingIconStr); - } - } - } -} - -} // namespace OHOS::Ace::Framework \ No newline at end of file +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "frameworks/bridge/declarative_frontend/jsview/js_side_bar.h" + +#include "base/geometry/dimension.h" +#include "core/components/button/button_component.h" +#include "core/components/side_bar/render_side_bar_container.h" +#include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h" +#include "frameworks/bridge/declarative_frontend/view_stack_processor.h" + +namespace OHOS::Ace::Framework { +void JSSideBar::Create(const JSCallbackInfo& info) +{ + if (info.Length() < 1) { + LOGE("The arg is wrong, it is supposed to have at least 1 arguments"); + return; + } + + SideBarContainerType style = SideBarContainerType::EMBED; + if (!info[0]->IsNull()) { + if (info[0]->IsBoolean()) { + style = static_cast(info[0]->ToBoolean()); + } else if (info[0]->IsNumber()) { + style = static_cast(info[0]->ToNumber()); + } else { + LOGE("The arg is wrong"); + return; + } + } + + std::list> children; + auto sideBarContainer = AceType::MakeRefPtr(children); + sideBarContainer->SetMainStackSize(MainStackSize::MAX); + sideBarContainer->SetSideBarContainerType(style); + + auto stack = ViewStackProcessor::GetInstance(); + stack->Push(sideBarContainer); + JSInteractableView::SetFocusable(false); + JSInteractableView::SetFocusNode(true); +} + +void JSSideBar::SetShowControlButton(bool isShow) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto component = AceType::DynamicCast(stack->GetMainComponent()); + if (!component) { + LOGE("side bar is null"); + return; + } + + component->SetShowControlButton(isShow); +} + +void JSSideBar::JSBind(BindingTarget globalObj) +{ + JSClass::Declare("SideBarContainer"); + MethodOptions opt = MethodOptions::NONE; + JSClass::StaticMethod("create", &JSSideBar::Create, opt); + JSClass::StaticMethod("showSideBar", &JSSideBar::JsShowSideBar); + JSClass::StaticMethod("controlButton", &JSSideBar::JsControlButton); + JSClass::StaticMethod("showControlButton", &JSSideBar::SetShowControlButton); + JSClass::StaticMethod("onChange", &JSSideBar::OnChange); + JSClass::StaticMethod("sideBarWidth", &JSSideBar::JsSideBarWidth); + JSClass::StaticMethod("minSideBarWidth", &JSSideBar::JsMinSideBarWidth); + JSClass::StaticMethod("maxSideBarWidth", &JSSideBar::JsMaxSideBarWidth); + JSClass::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); + JSClass::StaticMethod("width", SetWidth); + JSClass::StaticMethod("height", SetHeight); + JSClass::StaticMethod("size", SetSize); + JSClass::StaticMethod("width", &JSStack::SetWidth); + JSClass::StaticMethod("height", &JSStack::SetHeight); + JSClass::StaticMethod("size", &JSStack::SetSize); + JSClass::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey); + JSClass::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete); + JSClass::StaticMethod("onClick", &JSInteractableView::JsOnClick); + JSClass::StaticMethod("onAppear", &JSInteractableView::JsOnAppear); + JSClass::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear); + JSClass::Inherit(); + JSClass::Inherit(); + JSClass::Bind(globalObj); +} + +void JSSideBar::OnChange(const JSCallbackInfo& info) +{ + if (!JSViewBindEvent(&SideBarContainerComponent::SetOnChange, info)) { + LOGE("Failed to bind event"); + } + info.ReturnSelf(); +} + +void JSSideBar::JsSideBarWidth(double length) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto component = AceType::DynamicCast(stack->GetMainComponent()); + if (!component) { + LOGE("side bar is null"); + return; + } + component->SetSideBarWidth(Dimension(length, DimensionUnit::VP)); +} + +void JSSideBar::JsMaxSideBarWidth(double length) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto component = AceType::DynamicCast(stack->GetMainComponent()); + if (!component) { + LOGE("side bar is null"); + return; + } + component->SetSideBarMaxWidth(Dimension(length, DimensionUnit::VP)); +} + +void JSSideBar::JsMinSideBarWidth(double length) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto component = AceType::DynamicCast(stack->GetMainComponent()); + if (!component) { + LOGE("side bar is null"); + return; + } + component->SetSideBarMinWidth(Dimension(length, DimensionUnit::VP)); +} + +void JSSideBar::JsShowSideBar(bool isShow) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto component = AceType::DynamicCast(stack->GetMainComponent()); + if (!component) { + LOGE("side bar is null"); + return; + } + component->SetShowSideBar(isShow); +} + +void JSSideBar::JsControlButton(const JSCallbackInfo& info) +{ + auto stack = ViewStackProcessor::GetInstance(); + auto component = AceType::DynamicCast(stack->GetMainComponent()); + if (!component) { + LOGE("side bar is null"); + return; + } + + if (!info[0]->IsNull() && info[0]->IsObject()) { + JSRef value = JSRef::Cast(info[0]); + JSRef width = value->GetProperty("width"); + JSRef height = value->GetProperty("height"); + JSRef left = value->GetProperty("left"); + JSRef top = value->GetProperty("top"); + JSRef icons = value->GetProperty("icons"); + + if (!width->IsNull() && width->IsNumber()) { + component->SetButtonWidth(width->ToNumber()); + } + + if (!height->IsNull() && height->IsNumber()) { + component->SetButtonHeight(height->ToNumber()); + } + + if (!left->IsNull() && left->IsNumber()) { + component->SetButtonLeft(left->ToNumber()); + } + + if (!top->IsNull() && top->IsNumber()) { + component->SetButtonTop(top->ToNumber()); + } + + if (!icons->IsNull() && icons->IsObject()) { + JSRef iconsVal = JSRef::Cast(icons); + JSRef showIcon = iconsVal->GetProperty("shown"); + JSRef switchingIcon = iconsVal->GetProperty("switching"); + JSRef hiddenIcon = iconsVal->GetProperty("hidden"); + std::string showIconStr; + if (!showIcon->IsNull() && ParseJsMedia(showIcon, showIconStr)) { + component->SetShowIcon(showIconStr); + } + std::string hiddenIconStr; + if (!hiddenIcon->IsNull() && ParseJsMedia(hiddenIcon, hiddenIconStr)) { + component->SetHiddenIcon(hiddenIconStr); + } + std::string switchingIconStr; + if (!switchingIcon->IsNull() && ParseJsMedia(switchingIcon, switchingIconStr)) { + component->SetSwitchIcon(switchingIconStr); + } + } + } +} + +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp index 989eaba7..176bee2a 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_text.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_text.cpp @@ -452,7 +452,7 @@ void JSText::Create(const JSCallbackInfo& info) auto textComponent = AceType::MakeRefPtr(data); ViewStackProcessor::GetInstance()->Push(textComponent); - JSInteractableView::SetFocusable(true); + JSInteractableView::SetFocusable(false); JSInteractableView::SetFocusNode(false); // Init text style, allowScale is not supported in declarative. diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textinput.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textinput.cpp index d7e0cdc9..e7c5cb75 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textinput.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textinput.cpp @@ -184,6 +184,8 @@ void JSTextInput::Create(const JSCallbackInfo& info) } else { LOGI("controller is nullptr"); } + JSInteractableView::SetFocusable(true); + JSInteractableView::SetFocusNode(true); } void JSTextInput::SetBackgroundColor(const JSCallbackInfo& info) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp b/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp index 874107da..a1970f78 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_textpicker.cpp @@ -73,6 +73,7 @@ void JSTextPicker::Create(const JSCallbackInfo& info) RefPtr pickerTextComponent = AceType::MakeRefPtr(); ViewStackProcessor::GetInstance()->Push(pickerTextComponent); + JSInteractableView::SetFocusable(false); JSInteractableView::SetFocusNode(true); auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); diff --git a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp index fa05c2fc..9d4fe014 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_web.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_web.cpp @@ -580,6 +580,7 @@ void JSWeb::Create(const JSCallbackInfo& info) webComponent->SetWebController(controller->GetController()); } ViewStackProcessor::GetInstance()->Push(webComponent); + JSInteractableView::SetFocusable(false); JSInteractableView::SetFocusNode(true); } diff --git a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp index 7d5fb777..26e9a78f 100644 --- a/frameworks/bridge/declarative_frontend/view_stack_processor.cpp +++ b/frameworks/bridge/declarative_frontend/view_stack_processor.cpp @@ -326,7 +326,6 @@ RefPtr ViewStackProcessor::GetFocusableComponent(bool create } if (createIfNotExist) { RefPtr focusableComponent = AceType::MakeRefPtr(); - focusableComponent->SetFocusable(true); wrappingComponentsMap.emplace("focusable", focusableComponent); return focusableComponent; } diff --git a/frameworks/core/components_v2/list/list_element.cpp b/frameworks/core/components_v2/list/list_element.cpp index 81e9706f..5afc562f 100644 --- a/frameworks/core/components_v2/list/list_element.cpp +++ b/frameworks/core/components_v2/list/list_element.cpp @@ -100,11 +100,17 @@ bool ListElement::RequestNextFocus(bool vertical, bool reverse, const Rect& rect return false; } LOGI("RequestNextFocus vertical:%{public}d reverse:%{public}d.", vertical, reverse); + if (!UpdateFocusIndex()) { + LOGE("Update focus index failed"); + return false; + } bool ret = false; while (!ret) { int32_t focusIndex = list->RequestNextFocus(vertical, reverse); + LOGI("Request next focus index = %{public}d", focusIndex); int32_t size = static_cast(GetChildrenList().size()); if (focusIndex < 0 || focusIndex >= size) { + LOGW("Invalid next focus index"); return false; } auto iter = GetChildrenList().begin(); @@ -120,6 +126,24 @@ bool ListElement::RequestNextFocus(bool vertical, bool reverse, const Rect& rect return ret; } +bool ListElement::UpdateFocusIndex() +{ + RefPtr list = AceType::DynamicCast(renderNode_); + if (!list) { + LOGE("Render grid is null."); + return false; + } + int32_t index = 0; + for (const auto& iter : GetChildrenList()) { + if (iter->IsCurrentFocus()) { + list->SetFocusIndex(index); + return true; + } + ++index; + } + return false; +} + RefPtr ListElement::OnUpdateElement(const RefPtr& element, const RefPtr& component) { return UpdateChild(element, component); diff --git a/frameworks/core/components_v2/list/list_element.h b/frameworks/core/components_v2/list/list_element.h index 00fd5e84..ac334072 100644 --- a/frameworks/core/components_v2/list/list_element.h +++ b/frameworks/core/components_v2/list/list_element.h @@ -44,6 +44,8 @@ public: size_t FindPreviousStickyListItem(size_t index) override; bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override; + bool UpdateFocusIndex(); + void OnPostFlush() override; private: diff --git a/frameworks/core/components_v2/list/render_list.h b/frameworks/core/components_v2/list/render_list.h index 42451b78..445b72dc 100644 --- a/frameworks/core/components_v2/list/render_list.h +++ b/frameworks/core/components_v2/list/render_list.h @@ -225,6 +225,11 @@ public: std::string ProvideRestoreInfo() override; + void SetFocusIndex(int32_t focusIndex) + { + focusIndex_ = focusIndex; + } + protected: void UpdateAccessibilityAttr(); bool HandleActionScroll(bool forward); diff --git a/frameworks/core/event/axis_event.h b/frameworks/core/event/axis_event.h index 7567dd07..912425ac 100644 --- a/frameworks/core/event/axis_event.h +++ b/frameworks/core/event/axis_event.h @@ -101,19 +101,19 @@ struct AxisEvent final { } static bool IsDirectionUp(AxisDirection direction) { - return (static_cast(direction) & static_cast(AxisDirection::UP)); + return (static_cast(direction) & static_cast(AxisDirection::UP)); } static bool IsDirectionDown(AxisDirection direction) { - return (static_cast(direction) & static_cast(AxisDirection::DOWN)); + return (static_cast(direction) & static_cast(AxisDirection::DOWN)); } static bool IsDirectionLeft(AxisDirection direction) { - return (static_cast(direction) & static_cast(AxisDirection::LEFT)); + return (static_cast(direction) & static_cast(AxisDirection::LEFT)); } static bool IsDirectionRight(AxisDirection direction) { - return (static_cast(direction) & static_cast(AxisDirection::RIGHT)); + return (static_cast(direction) & static_cast(AxisDirection::RIGHT)); } }; diff --git a/frameworks/core/focus/focus_node.cpp b/frameworks/core/focus/focus_node.cpp index 1fd00eab..7b1bcea6 100644 --- a/frameworks/core/focus/focus_node.cpp +++ b/frameworks/core/focus/focus_node.cpp @@ -395,12 +395,8 @@ bool FocusGroup::IsFocusable() const if (!FocusNode::IsFocusable()) { return false; } - if (focusNodes_.size() > 0) { - return std::any_of(focusNodes_.begin(), focusNodes_.end(), - [](const RefPtr& focusNode) { return focusNode->IsFocusable(); }); - } else { - return true; - } + return std::any_of(focusNodes_.begin(), focusNodes_.end(), + [](const RefPtr& focusNode) { return focusNode->IsFocusable(); }); } bool FocusGroup::GoToNextFocus(bool reverse, const Rect& rect) @@ -470,23 +466,23 @@ bool FocusGroup::OnKeyEvent(const KeyEvent& keyEvent) OnFocusMove(keyEvent.code); switch (keyEvent.code) { case KeyCode::TV_CONTROL_UP: - LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'UP' by KeyCode(%{public}d)", keyEvent.code); + LOGI("RequestNextFocus 'UP' by KeyCode(%{public}d)", keyEvent.code); return RequestNextFocus(true, true, GetRect()); case KeyCode::TV_CONTROL_DOWN: - LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'DOWN' by KeyCode(%{public}d)", keyEvent.code); + LOGI("RequestNextFocus 'DOWN' by KeyCode(%{public}d)", keyEvent.code); return RequestNextFocus(true, false, GetRect()); case KeyCode::TV_CONTROL_LEFT: - LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'LEFT' by KeyCode(%{public}d)", keyEvent.code); + LOGI("RequestNextFocus 'LEFT' by KeyCode(%{public}d)", keyEvent.code); return RequestNextFocus(false, !AceApplicationInfo::GetInstance().IsRightToLeft(), GetRect()); case KeyCode::TV_CONTROL_RIGHT: - LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'RIGHT' by KeyCode(%{public}d)", keyEvent.code); + LOGI("RequestNextFocus 'RIGHT' by KeyCode(%{public}d)", keyEvent.code); return RequestNextFocus(false, AceApplicationInfo::GetInstance().IsRightToLeft(), GetRect()); case KeyCode::KEY_TAB: if (keyEvent.pressedCodes.size() == 1) { - LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'TAB' by KeyCode(%{public}d)", keyEvent.code); + LOGI("RequestNextFocus 'TAB' by KeyCode(%{public}d)", keyEvent.code); return RequestNextFocus(false, false, GetRect()) || RequestNextFocus(true, false, GetRect()); } else { - LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'SHIFT-TAB' by KeyCode(%{public}d)", keyEvent.code); + LOGI("RequestNextFocus 'SHIFT-TAB' by KeyCode(%{public}d)", keyEvent.code); if (keyEvent.IsKey({ KeyCode::KEY_SHIFT_LEFT, KeyCode::KEY_TAB }) || keyEvent.IsKey({ KeyCode::KEY_SHIFT_RIGHT, KeyCode::KEY_TAB })) { return RequestNextFocus(false, true, GetRect()) || RequestNextFocus(true, true, GetRect());