mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 01:03:08 +00:00
commit
357b1055c7
@ -1486,12 +1486,15 @@ class ArkRelativeContainerBarrier {
|
||||
class ArkFocusScopeId {
|
||||
id: string | undefined;
|
||||
isGroup: boolean | undefined;
|
||||
arrowStepOut: boolean | undefined;
|
||||
constructor() {
|
||||
this.id = undefined;
|
||||
this.isGroup = undefined;
|
||||
this.arrowStepOut = undefined;
|
||||
}
|
||||
isEqual(another: ArkFocusScopeId): boolean {
|
||||
return (this.id === another.id) && (this.isGroup === another.isGroup);
|
||||
return ((this.id === another.id) && (this.isGroup === another.isGroup) &&
|
||||
(this.arrowStepOut === another.arrowStepOut));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3079,7 +3079,7 @@ class FocusScopeIdModifier extends ModifierWithKey<ArkFocusScopeId> {
|
||||
if (reset) {
|
||||
getUINativeModule().common.resetFocusScopeId(node);
|
||||
} else {
|
||||
getUINativeModule().common.setFocusScopeId(node, this.value.id, this.value.isGroup);
|
||||
getUINativeModule().common.setFocusScopeId(node, this.value.id, this.value.isGroup, this.value.arrowStepOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4501,7 +4501,7 @@ class ArkComponent implements CommonMethod<CommonAttribute> {
|
||||
return this;
|
||||
}
|
||||
|
||||
focusScopeId(id: string, isGroup?: boolean): this {
|
||||
focusScopeId(id: string, isGroup?: boolean, arrowStepOut?: boolean): this {
|
||||
let arkFocusScopeId = new ArkFocusScopeId();
|
||||
if (isString(id)) {
|
||||
arkFocusScopeId.id = id;
|
||||
@ -4509,6 +4509,9 @@ class ArkComponent implements CommonMethod<CommonAttribute> {
|
||||
if (typeof isGroup === 'boolean') {
|
||||
arkFocusScopeId.isGroup = isGroup;
|
||||
}
|
||||
if (typeof arrowStepOut === 'boolean') {
|
||||
arkFocusScopeId.arrowStepOut = arrowStepOut;
|
||||
}
|
||||
modifierWithKey(
|
||||
this._modifiersWithKeys, FocusScopeIdModifier.identity, FocusScopeIdModifier, arkFocusScopeId);
|
||||
return this;
|
||||
|
@ -2891,7 +2891,7 @@ class FocusScopeIdModifier extends ModifierWithKey {
|
||||
getUINativeModule().common.resetFocusScopeId(node);
|
||||
}
|
||||
else {
|
||||
getUINativeModule().common.setFocusScopeId(node, this.value.id, this.value.isGroup);
|
||||
getUINativeModule().common.setFocusScopeId(node, this.value.id, this.value.isGroup, this.value.arrowStepOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4268,7 +4268,7 @@ class ArkComponent {
|
||||
modifierWithKey(this._modifiersWithKeys, SystemBarEffectModifier.identity, SystemBarEffectModifier, null);
|
||||
return this;
|
||||
}
|
||||
focusScopeId(id, isGroup) {
|
||||
focusScopeId(id, isGroup, arrowStepOut) {
|
||||
let arkFocusScopeId = new ArkFocusScopeId();
|
||||
if (isString(id)) {
|
||||
arkFocusScopeId.id = id;
|
||||
@ -4276,6 +4276,9 @@ class ArkComponent {
|
||||
if (typeof isGroup === 'boolean') {
|
||||
arkFocusScopeId.isGroup = isGroup;
|
||||
}
|
||||
if (typeof arrowStepOut === 'boolean') {
|
||||
arkFocusScopeId.arrowStepOut = arrowStepOut;
|
||||
}
|
||||
modifierWithKey(this._modifiersWithKeys, FocusScopeIdModifier.identity, FocusScopeIdModifier, arkFocusScopeId);
|
||||
return this;
|
||||
}
|
||||
@ -16125,9 +16128,11 @@ class ArkFocusScopeId {
|
||||
constructor() {
|
||||
this.id = undefined;
|
||||
this.isGroup = undefined;
|
||||
this.arrowStepOut = undefined;
|
||||
}
|
||||
isEqual(another) {
|
||||
return (this.id === another.id) && (this.isGroup === another.isGroup);
|
||||
return ((this.id === another.id) && (this.isGroup === another.isGroup) &&
|
||||
(this.arrowStepOut === another.arrowStepOut));
|
||||
}
|
||||
}
|
||||
class ArkFocusScopePriority {
|
||||
|
@ -803,6 +803,19 @@ class FocusController {
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
return result;
|
||||
}
|
||||
|
||||
activate(isActive, autoInactive) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
if (arguments.length === 2) {
|
||||
let result = this.ohos_focusController.activate(isActive, autoInactive);
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
return result;
|
||||
} else {
|
||||
let result = this.ohos_focusController.activate(isActive);
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CursorController {
|
||||
|
@ -7629,6 +7629,7 @@ ArkUINativeModuleValue CommonBridge::SetFocusScopeId(ArkUIRuntimeCallInfo* runti
|
||||
CHECK_NULL_RETURN(nativeNode, panda::JSValueRef::Undefined(vm));
|
||||
Local<JSValueRef> idArg = runtimeCallInfo->GetCallArgRef(NUM_1);
|
||||
Local<JSValueRef> isGroupArg = runtimeCallInfo->GetCallArgRef(NUM_2);
|
||||
Local<JSValueRef> arrowKeyStepOutArg = runtimeCallInfo->GetCallArgRef(NUM_3);
|
||||
if (!idArg->IsString(vm)) {
|
||||
return panda::JSValueRef::Undefined(vm);
|
||||
}
|
||||
@ -7637,7 +7638,11 @@ ArkUINativeModuleValue CommonBridge::SetFocusScopeId(ArkUIRuntimeCallInfo* runti
|
||||
if (isGroupArg->IsBoolean()) {
|
||||
isGroup = isGroupArg->ToBoolean(vm)->Value();
|
||||
}
|
||||
GetArkUINodeModifiers()->getCommonModifier()->setFocusScopeId(nativeNode, id.c_str(), isGroup);
|
||||
bool arrowKeyStepOut = true;
|
||||
if (arrowKeyStepOutArg->IsBoolean()) {
|
||||
arrowKeyStepOut = arrowKeyStepOutArg->ToBoolean(vm)->Value();
|
||||
}
|
||||
GetArkUINodeModifiers()->getCommonModifier()->setFocusScopeId(nativeNode, id.c_str(), isGroup, arrowKeyStepOut);
|
||||
return panda::JSValueRef::Undefined(vm);
|
||||
}
|
||||
|
||||
|
@ -10708,11 +10708,16 @@ void JSViewAbstract::JsFocusScopeId(const JSCallbackInfo& info)
|
||||
}
|
||||
|
||||
bool isGroup = false;
|
||||
if (info.Length() == PARAMETER_LENGTH_SECOND && !info[0]->IsNull() && !info[0]->IsUndefined() &&
|
||||
if (info.Length() >= PARAMETER_LENGTH_SECOND && !info[1]->IsNull() && !info[1]->IsUndefined() &&
|
||||
info[1]->IsBoolean()) {
|
||||
isGroup = info[1]->ToBoolean();
|
||||
}
|
||||
ViewAbstractModel::GetInstance()->SetFocusScopeId(focusScopeId, isGroup);
|
||||
bool arrowKeyStepOut = true;
|
||||
if (info.Length() >= PARAMETER_LENGTH_THIRD && !info[2]->IsNull() && !info[2]->IsUndefined() &&
|
||||
info[2]->IsBoolean()) {
|
||||
arrowKeyStepOut = info[2]->ToBoolean();
|
||||
}
|
||||
ViewAbstractModel::GetInstance()->SetFocusScopeId(focusScopeId, isGroup, arrowKeyStepOut);
|
||||
}
|
||||
|
||||
void JSViewAbstract::JsFocusScopePriority(const JSCallbackInfo& info)
|
||||
|
@ -150,6 +150,13 @@ void FrontendDelegate::ResetRequestFocusCallback()
|
||||
focusManager->ResetRequestFocusCallback();
|
||||
}
|
||||
|
||||
bool FrontendDelegate::Activate(bool isActive, bool autoInactive)
|
||||
{
|
||||
auto pipeline = NG::PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_RETURN(pipeline, false);
|
||||
return pipeline->SetIsFocusActive(isActive, NG::FocusActiveReason::USE_API, autoInactive);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool FrontendDelegate::GetResourceData(const std::string& fileUri, T& content, std::string& ami)
|
||||
{
|
||||
|
@ -134,6 +134,8 @@ public:
|
||||
|
||||
virtual void ResetRequestFocusCallback();
|
||||
|
||||
virtual bool Activate(bool isActive, bool autoInactive = true);
|
||||
|
||||
// restore
|
||||
virtual std::pair<RouterRecoverRecord, UIContentErrorCode> RestoreRouterStack(
|
||||
const std::string& contentInfo, ContentInfoType type)
|
||||
|
@ -4886,11 +4886,11 @@ bool ViewAbstract::GetFocusOnTouch(FrameNode* frameNode)
|
||||
return focusHub->IsFocusOnTouch().value_or(false);
|
||||
}
|
||||
|
||||
void ViewAbstract::SetFocusScopeId(const std::string& focusScopeId, bool isGroup)
|
||||
void ViewAbstract::SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut)
|
||||
{
|
||||
auto focusHub = ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub();
|
||||
CHECK_NULL_VOID(focusHub);
|
||||
focusHub->SetFocusScopeId(focusScopeId, isGroup);
|
||||
focusHub->SetFocusScopeId(focusScopeId, isGroup, arrowKeyStepOut);
|
||||
}
|
||||
|
||||
void ViewAbstract::SetFocusScopePriority(const std::string& focusScopeId, const uint32_t focusPriority)
|
||||
@ -4900,12 +4900,13 @@ void ViewAbstract::SetFocusScopePriority(const std::string& focusScopeId, const
|
||||
focusHub->SetFocusScopePriority(focusScopeId, focusPriority);
|
||||
}
|
||||
|
||||
void ViewAbstract::SetFocusScopeId(FrameNode* frameNode, const std::string& focusScopeId, bool isGroup)
|
||||
void ViewAbstract::SetFocusScopeId(FrameNode* frameNode, const std::string& focusScopeId, bool isGroup,
|
||||
bool arrowKeyStepOut)
|
||||
{
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto focusHub = frameNode->GetOrCreateFocusHub();
|
||||
CHECK_NULL_VOID(focusHub);
|
||||
focusHub->SetFocusScopeId(focusScopeId, isGroup);
|
||||
focusHub->SetFocusScopeId(focusScopeId, isGroup, arrowKeyStepOut);
|
||||
}
|
||||
|
||||
void ViewAbstract::SetFocusScopePriority(FrameNode* frameNode, const std::string& focusScopeId,
|
||||
|
@ -740,9 +740,10 @@ public:
|
||||
static RenderFit GetRenderFit(FrameNode* frameNode);
|
||||
static BorderColorProperty GetOuterBorderColor(FrameNode* frameNode);
|
||||
static bool GetRenderGroup(FrameNode* frameNode);
|
||||
static void SetFocusScopeId(const std::string& focusScopeId, bool isGroup);
|
||||
static void SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut);
|
||||
static void SetFocusScopePriority(const std::string& focusScopeId, const uint32_t focusPriority);
|
||||
static void SetFocusScopeId(FrameNode* frameNode, const std::string& focusScopeId, bool isGroup);
|
||||
static void SetFocusScopeId(FrameNode* frameNode, const std::string& focusScopeId, bool isGroup,
|
||||
bool arrowKeyStepOut);
|
||||
static void SetFocusScopePriority(FrameNode* frameNode, const std::string& focusScopeId,
|
||||
const uint32_t focusPriority);
|
||||
static void ResetBias(FrameNode* frameNode);
|
||||
|
@ -326,7 +326,7 @@ public:
|
||||
virtual void SetDefaultFocus(bool isSet) = 0;
|
||||
virtual void SetGroupDefaultFocus(bool isSet) = 0;
|
||||
virtual void SetFocusBoxStyle(const NG::FocusBoxStyle& style) {}
|
||||
virtual void SetFocusScopeId(const std::string& focusScopeId, bool isGroup) {}
|
||||
virtual void SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut) {}
|
||||
virtual void SetFocusScopePriority(const std::string& focusScopeId, const uint32_t focusPriority) {}
|
||||
virtual void SetInspectorId(const std::string& inspectorId) = 0;
|
||||
virtual void SetAutoEventParam(const std::string& param) {}
|
||||
|
@ -1420,9 +1420,9 @@ public:
|
||||
ViewAbstract::SetDragEventStrictReportingEnabled(dragEventStrictReportingEnabled);
|
||||
}
|
||||
|
||||
void SetFocusScopeId(const std::string& focusScopeId, bool isGroup) override
|
||||
void SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut) override
|
||||
{
|
||||
ViewAbstract::SetFocusScopeId(focusScopeId, isGroup);
|
||||
ViewAbstract::SetFocusScopeId(focusScopeId, isGroup, arrowKeyStepOut);
|
||||
}
|
||||
|
||||
void SetFocusScopePriority(const std::string& focusScopeId, const uint32_t focusPriority) override
|
||||
|
@ -251,6 +251,7 @@ void FocusHub::DumpFocusScopeTree(int32_t depth)
|
||||
if (isFocusScope_ && !focusScopeId_.empty()) {
|
||||
information += GetIsFocusGroup() ? " GroupId:" : " ScopeId:";
|
||||
information += focusScopeId_;
|
||||
information += arrowKeyStepOut_ ? "" : " ArrowKeyStepOut:false";
|
||||
}
|
||||
bool isPrior = (!focusScopeId_.empty() && (focusPriority_ == FocusPriority::PRIOR));
|
||||
if (isPrior) {
|
||||
@ -942,27 +943,39 @@ bool FocusHub::RequestNextFocus(FocusStep moveStep, const RectF& rect)
|
||||
TAG_LOGI(AceLogTag::ACE_FOCUS,
|
||||
"Request next focus failed because direction of node(%{public}d) is different with step(%{public}d).",
|
||||
focusAlgorithm_.isVertical, moveStep);
|
||||
return false;
|
||||
return IsArrowKeyStepOut(moveStep);
|
||||
}
|
||||
auto ret = GoToNextFocusLinear(moveStep, rect);
|
||||
TAG_LOGI(AceLogTag::ACE_FOCUS, "Request next focus by default linear algorithm. Return %{public}d.", ret);
|
||||
return ret;
|
||||
return (ret || IsArrowKeyStepOut(moveStep));
|
||||
}
|
||||
if (!lastWeakFocusNode_.Upgrade()) {
|
||||
return false;
|
||||
return IsArrowKeyStepOut(moveStep);
|
||||
}
|
||||
WeakPtr<FocusHub> nextFocusHubWeak;
|
||||
focusAlgorithm_.getNextFocusNode(moveStep, lastWeakFocusNode_, nextFocusHubWeak);
|
||||
auto nextFocusHub = nextFocusHubWeak.Upgrade();
|
||||
if (!nextFocusHub || nextFocusHub == lastWeakFocusNode_.Upgrade()) {
|
||||
TAG_LOGI(AceLogTag::ACE_FOCUS, "Request next focus failed by custom focus algorithm.");
|
||||
return false;
|
||||
return IsArrowKeyStepOut(moveStep);
|
||||
}
|
||||
auto ret = TryRequestFocus(nextFocusHub, rect, moveStep);
|
||||
TAG_LOGI(AceLogTag::ACE_FOCUS,
|
||||
"Request next focus by custom focus algorithm. Next focus node is %{public}s/%{public}d. Return %{public}d",
|
||||
nextFocusHub->GetFrameName().c_str(), nextFocusHub->GetFrameId(), ret);
|
||||
return ret;
|
||||
return (ret || IsArrowKeyStepOut(moveStep));
|
||||
}
|
||||
|
||||
bool FocusHub::IsArrowKeyStepOut(FocusStep moveStep)
|
||||
{
|
||||
if (!IsFocusStepTab(moveStep) && GetIsFocusGroup() && !arrowKeyStepOut_) {
|
||||
TAG_LOGI(AceLogTag::ACE_FOCUS,
|
||||
"IsArrowKeyStepOut Node(%{public}s/%{public}d), step(%{public}d),"
|
||||
"this node is focus group and set can not step out!",
|
||||
GetFrameName().c_str(), GetFrameId(), moveStep);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FocusHub::FocusToHeadOrTailChild(bool isHead)
|
||||
@ -2341,7 +2354,7 @@ bool FocusHub::UpdateFocusView()
|
||||
return true;
|
||||
}
|
||||
|
||||
void FocusHub::SetFocusScopeId(const std::string& focusScopeId, bool isGroup)
|
||||
void FocusHub::SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut)
|
||||
{
|
||||
if (focusType_ != FocusType::SCOPE) {
|
||||
return;
|
||||
@ -2354,6 +2367,7 @@ void FocusHub::SetFocusScopeId(const std::string& focusScopeId, bool isGroup)
|
||||
focusScopeId_ = focusScopeId;
|
||||
isFocusScope_ = false;
|
||||
isGroup_ = false;
|
||||
arrowKeyStepOut_ = true;
|
||||
return;
|
||||
}
|
||||
if (focusManager && !focusManager->AddFocusScope(focusScopeId, AceType::Claim(this))) {
|
||||
@ -2362,12 +2376,14 @@ void FocusHub::SetFocusScopeId(const std::string& focusScopeId, bool isGroup)
|
||||
bool isValidFocusScope = (isFocusScope_ && !focusScopeId_.empty());
|
||||
if (isValidFocusScope) {
|
||||
isGroup_ = isGroup;
|
||||
arrowKeyStepOut_ = arrowKeyStepOut;
|
||||
}
|
||||
return;
|
||||
}
|
||||
focusScopeId_ = focusScopeId;
|
||||
isFocusScope_ = true;
|
||||
isGroup_ = isGroup;
|
||||
arrowKeyStepOut_ = arrowKeyStepOut;
|
||||
}
|
||||
|
||||
void FocusHub::RemoveFocusScopeIdAndPriority()
|
||||
|
@ -1007,7 +1007,7 @@ public:
|
||||
|
||||
static double GetProjectAreaOnRect(const RectF& rect, const RectF& projectRect, FocusStep step);
|
||||
|
||||
void SetFocusScopeId(const std::string& focusScopeId, bool isGroup);
|
||||
void SetFocusScopeId(const std::string& focusScopeId, bool isGroup, bool arrowKeyStepOut = true);
|
||||
void SetFocusScopePriority(const std::string& focusScopeId, const uint32_t focusPriority);
|
||||
void RemoveFocusScopeIdAndPriority();
|
||||
bool AcceptFocusOfPriorityChild();
|
||||
@ -1122,6 +1122,8 @@ private:
|
||||
|
||||
bool SkipFocusMoveBeforeRemove();
|
||||
|
||||
bool IsArrowKeyStepOut(FocusStep moveStep);
|
||||
|
||||
OnFocusFunc onFocusInternal_;
|
||||
OnBlurFunc onBlurInternal_;
|
||||
OnBlurReasonFunc onBlurReasonInternal_;
|
||||
@ -1166,6 +1168,7 @@ private:
|
||||
bool isFocusScope_ { false };
|
||||
bool isGroup_ { false };
|
||||
FocusPriority focusPriority_ = FocusPriority::AUTO;
|
||||
bool arrowKeyStepOut_ { true };
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
|
@ -32,6 +32,12 @@ using RequestFocusCallback = std::function<void(NG::RequestFocusResult result)>;
|
||||
using FocusHubScopeMap = std::unordered_map<std::string, std::pair<WeakPtr<FocusHub>, std::list<WeakPtr<FocusHub>>>>;
|
||||
using FocusChangeCallback = std::function<void(const WeakPtr<FocusHub>& last, const RefPtr<FocusHub>& current)>;
|
||||
|
||||
enum class FocusActiveReason : int32_t {
|
||||
POINTER_EVENT = 0,
|
||||
KEYBOARD_EVENT = 1,
|
||||
USE_API = 2,
|
||||
};
|
||||
|
||||
class FocusManager : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(FocusManager, AceType);
|
||||
|
||||
|
@ -1905,7 +1905,7 @@ struct ArkUICommonModifier {
|
||||
void (*setAccessibilityRole)(ArkUINodeHandle node, ArkUI_CharPtr role);
|
||||
void (*resetAccessibilityRole)(ArkUINodeHandle node);
|
||||
ArkUI_CharPtr (*getAccessibilityRole)(ArkUINodeHandle node);
|
||||
void (*setFocusScopeId)(ArkUINodeHandle node, ArkUI_CharPtr id, ArkUI_Bool isGroup);
|
||||
void (*setFocusScopeId)(ArkUINodeHandle node, ArkUI_CharPtr id, ArkUI_Bool isGroup, ArkUI_Bool arrowKeyStepOut);
|
||||
void (*resetFocusScopeId)(ArkUINodeHandle node);
|
||||
void (*setFocusScopePriority)(ArkUINodeHandle node, ArkUI_CharPtr scopeId, ArkUI_Int32 priority);
|
||||
void (*resetFocusScopePriority)(ArkUINodeHandle node);
|
||||
|
@ -452,7 +452,7 @@ struct CJUICommonModifier {
|
||||
void (*setAccessibilityRole)(ArkUINodeHandle node, ArkUI_CharPtr role);
|
||||
void (*resetAccessibilityRole)(ArkUINodeHandle node);
|
||||
ArkUI_CharPtr (*getAccessibilityRole)(ArkUINodeHandle node);
|
||||
void (*setFocusScopeId)(ArkUINodeHandle node, ArkUI_CharPtr id, ArkUI_Bool isGroup);
|
||||
void (*setFocusScopeId)(ArkUINodeHandle node, ArkUI_CharPtr id, ArkUI_Bool isGroup, ArkUI_Bool arrowKeyStepOut);
|
||||
void (*resetFocusScopeId)(ArkUINodeHandle node);
|
||||
void (*setFocusScopePriority)(ArkUINodeHandle node, ArkUI_CharPtr scopeId, ArkUI_Int32 priority);
|
||||
void (*resetFocusScopePriority)(ArkUINodeHandle node);
|
||||
|
@ -5833,12 +5833,12 @@ ArkUI_CharPtr GetAccessibilityRole(ArkUINodeHandle node)
|
||||
return g_strValue.c_str();
|
||||
}
|
||||
|
||||
void SetFocusScopeId(ArkUINodeHandle node, ArkUI_CharPtr id, ArkUI_Bool isGroup)
|
||||
void SetFocusScopeId(ArkUINodeHandle node, ArkUI_CharPtr id, ArkUI_Bool isGroup, ArkUI_Bool arrowKeyStepOut)
|
||||
{
|
||||
auto* frameNode = reinterpret_cast<FrameNode*>(node);
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
std::string idStr = id;
|
||||
ViewAbstract::SetFocusScopeId(frameNode, idStr, isGroup);
|
||||
ViewAbstract::SetFocusScopeId(frameNode, idStr, isGroup, arrowKeyStepOut);
|
||||
}
|
||||
|
||||
void ResetFocusScopeId(ArkUINodeHandle node)
|
||||
@ -5847,7 +5847,8 @@ void ResetFocusScopeId(ArkUINodeHandle node)
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
std::string id = "";
|
||||
bool isGroup = false;
|
||||
ViewAbstract::SetFocusScopeId(frameNode, id, isGroup);
|
||||
bool arrowKeyStepOut = true;
|
||||
ViewAbstract::SetFocusScopeId(frameNode, id, isGroup, arrowKeyStepOut);
|
||||
}
|
||||
|
||||
void SetFocusScopePriority(ArkUINodeHandle node, ArkUI_CharPtr scopeId, ArkUI_Int32 priority)
|
||||
|
@ -2328,8 +2328,17 @@ RefPtr<FrameNode> PipelineContext::FindNavigationNodeToHandleBack(const RefPtr<U
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PipelineContext::SetIsFocusActive(bool isFocusActive)
|
||||
bool PipelineContext::SetIsFocusActive(bool isFocusActive, FocusActiveReason reason, bool autoFocusInactive)
|
||||
{
|
||||
if (reason == FocusActiveReason::USE_API) {
|
||||
TAG_LOGI(AceLogTag::ACE_FOCUS, "autoFocusInactive turns to %{public}d", autoFocusInactive);
|
||||
autoFocusInactive_ = autoFocusInactive;
|
||||
}
|
||||
if (!isFocusActive && reason == FocusActiveReason::POINTER_EVENT && !autoFocusInactive_) {
|
||||
TAG_LOGI(AceLogTag::ACE_FOCUS, "focus cannot be deactived automaticly by pointer event");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isFocusActive_ == isFocusActive) {
|
||||
return false;
|
||||
}
|
||||
@ -2426,7 +2435,7 @@ void PipelineContext::OnTouchEvent(const TouchEvent& point, const RefPtr<FrameNo
|
||||
}
|
||||
if (scalePoint.type == TouchType::DOWN) {
|
||||
// Set focus state inactive while touch down event received
|
||||
SetIsFocusActive(false);
|
||||
SetIsFocusActive(false, FocusActiveReason::POINTER_EVENT);
|
||||
TouchRestrict touchRestrict { TouchRestrict::NONE };
|
||||
touchRestrict.sourceType = point.sourceType;
|
||||
touchRestrict.touchEvent = point;
|
||||
@ -3082,7 +3091,7 @@ void PipelineContext::OnMouseEvent(const MouseEvent& event, const RefPtr<FrameNo
|
||||
if (event.button == MouseButton::RIGHT_BUTTON && event.action == MouseAction::PRESS) {
|
||||
// Mouse right button press event set focus inactive here.
|
||||
// Mouse left button press event will set focus inactive in touch process.
|
||||
SetIsFocusActive(false);
|
||||
SetIsFocusActive(false, FocusActiveReason::POINTER_EVENT);
|
||||
}
|
||||
|
||||
auto manager = GetDragDropManager();
|
||||
|
@ -453,7 +453,8 @@ public:
|
||||
return isFocusActive_;
|
||||
}
|
||||
|
||||
bool SetIsFocusActive(bool isFocusActive);
|
||||
bool SetIsFocusActive(bool isFocusActive,
|
||||
FocusActiveReason reason = FocusActiveReason::KEYBOARD_EVENT, bool autoFocusInactive = true);
|
||||
|
||||
void AddIsFocusActiveUpdateEvent(const RefPtr<FrameNode>& node, const std::function<void(bool)>& eventCallback);
|
||||
void RemoveIsFocusActiveUpdateEvent(const RefPtr<FrameNode>& node);
|
||||
@ -1215,6 +1216,7 @@ private:
|
||||
CancelableCallback<void()> foldStatusDelayTask_;
|
||||
bool isFirstRootLayout_ = true;
|
||||
bool isFirstFlushMessages_ = true;
|
||||
bool autoFocusInactive_ = true;
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
namespace OHOS::Ace::Napi {
|
||||
namespace {
|
||||
constexpr size_t STR_BUFFER_SIZE = 1024;
|
||||
constexpr size_t ARGC_ACTIVATE_PARAMTER = 2;
|
||||
}
|
||||
|
||||
static napi_value JSClearFocus(napi_env env, napi_callback_info info)
|
||||
@ -80,11 +81,44 @@ static napi_value JSRequestFocus(napi_env env, napi_callback_info info)
|
||||
return obj;
|
||||
}
|
||||
|
||||
static napi_value JSActivate(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_ACTIVATE_PARAMTER;
|
||||
napi_value argv[ARGC_ACTIVATE_PARAMTER] = { nullptr };
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data);
|
||||
NAPI_ASSERT(env, argc >= 1, "requires at least 1 parameter");
|
||||
napi_valuetype type = napi_undefined;
|
||||
napi_typeof(env, argv[0], &type);
|
||||
NAPI_ASSERT(env, type == napi_boolean, "the type of argv[0] is not bool");
|
||||
bool isActive = false;
|
||||
napi_get_value_bool(env, argv[0], &isActive);
|
||||
|
||||
bool autoInactive = true;
|
||||
if (argc == ARGC_ACTIVATE_PARAMTER) {
|
||||
napi_typeof(env, argv[1], &type);
|
||||
NAPI_ASSERT(env, type == napi_boolean, "the type of argv[1] is not bool");
|
||||
napi_get_value_bool(env, argv[1], &autoInactive);
|
||||
}
|
||||
|
||||
napi_value obj = nullptr;
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (!delegate) {
|
||||
napi_get_boolean(env, false, &obj);
|
||||
return obj;
|
||||
}
|
||||
delegate->Activate(isActive, autoInactive);
|
||||
napi_get_null(env, &obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
static napi_value registerFunc(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor animatorDesc[] = {
|
||||
DECLARE_NAPI_FUNCTION("clearFocus", JSClearFocus),
|
||||
DECLARE_NAPI_FUNCTION("requestFocus", JSRequestFocus),
|
||||
DECLARE_NAPI_FUNCTION("activate", JSActivate),
|
||||
};
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(animatorDesc) / sizeof(animatorDesc[0]), animatorDesc));
|
||||
return exports;
|
||||
|
@ -734,7 +734,7 @@ RefPtr<FrameNode> PipelineContext::FindNavigationNodeToHandleBack(const RefPtr<U
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool PipelineContext::SetIsFocusActive(bool isFocusActive)
|
||||
bool PipelineContext::SetIsFocusActive(bool isFocusActive, FocusActiveReason reason, bool autoFocusInactive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -614,7 +614,7 @@ HWTEST_F(ViewAbstractTestNg, ViewAbstractFocusScopeId001, TestSize.Level1)
|
||||
std::string focusScopeId = "focusScope1";
|
||||
bool isGroup = true;
|
||||
ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub()->focusType_ = FocusType::SCOPE;
|
||||
ViewAbstract::SetFocusScopeId(focusScopeId, isGroup);
|
||||
ViewAbstract::SetFocusScopeId(focusScopeId, isGroup, true);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Verify that the focus scope ID has been set.
|
||||
@ -675,7 +675,7 @@ HWTEST_F(ViewAbstractTestNg, ViewAbstractFocusScopeIdWithFrameNode001, TestSize.
|
||||
std::string focusScopeId = "focusScope2";
|
||||
bool isGroup = true;
|
||||
ViewStackProcessor::GetInstance()->GetOrCreateMainFrameNodeFocusHub()->focusType_ = FocusType::SCOPE;
|
||||
ViewAbstract::SetFocusScopeId(AceType::RawPtr(frameNode), focusScopeId, isGroup);
|
||||
ViewAbstract::SetFocusScopeId(AceType::RawPtr(frameNode), focusScopeId, isGroup, true);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Verify that the focus scope ID has been set.
|
||||
|
Loading…
Reference in New Issue
Block a user